From a3a6c55275d34777c190cd223cf24d73fcde19f8 Mon Sep 17 00:00:00 2001 From: pyure Date: Wed, 12 Aug 2015 14:47:33 -0400 Subject: [PATCH 1/6] remove getAverage() We now do gradual output changes depending on the difference in current and target output level --- .../multi/GT_MetaTileEntity_LargeTurbine.java | 76 ++++++++++--------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java index 461bf159..03509dd9 100644 --- a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java +++ b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java @@ -110,57 +110,59 @@ public abstract class GT_MetaTileEntity_LargeTurbine extends GT_MetaTileEntity_M return ((addMaintenanceToMachineList(tTileEntity, getCasingTextureIndex())) || (addInputToMachineList(tTileEntity, getCasingTextureIndex())) || (addOutputToMachineList(tTileEntity, getCasingTextureIndex()))|| (addMufflerToMachineList(tTileEntity, getCasingTextureIndex()))); } - private int[] mLastTicks = new int[256]; - private int mCurrentTick; - private long mOverall; - - public int getAverage(int aCurrent){ - ++mCurrentTick; - mCurrentTick = mCurrentTick % 256; - mOverall = mOverall - mLastTicks[mCurrentTick]; - mOverall = mOverall + aCurrent; - mLastTicks[mCurrentTick] = aCurrent; - return (int) (mOverall/256); - } + @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); - aNBT.setLong("mOverall", mOverall); } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - mOverall = aNBT.getLong("mOverall"); - mOverall = mOverall - mOverall%256; - int tAverage = (int) (mOverall <<7); - for(int i = 0;i<256;i++){ - mLastTicks[i]=tAverage; - } } @Override public boolean checkRecipe(ItemStack aStack) { ArrayList tFluids = getStoredFluids(); - if (tFluids.size()>0){ - if(baseEff==0 || optFlow == 0 || counter >= 1000 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled() || this.getBaseMetaTileEntity().hasInventoryBeenModified()){ - counter = 0; - baseEff = (int) ((50.0F+(10.0F*((GT_MetaGenerated_Tool)aStack.getItem()).getToolCombatDamage(aStack)))*100); - optFlow = (int) Math.max(Float.MIN_NORMAL, ((GT_MetaGenerated_Tool)aStack.getItem()).getToolStats(aStack).getSpeedMultiplier() * ((GT_MetaGenerated_Tool)aStack.getItem()).getPrimaryMaterial(aStack).mToolSpeed*50); - }else{ - counter++;}} - this.mEUt = fluidIntoPower(tFluids, optFlow, baseEff); - this.mMaxProgresstime = 1; - this.mEfficiencyIncrease = (10); - if(mEUt<=0){ - mEfficiency=0; - mOverall=0; - mLastTicks = new int[256]; - stopMachine(); - return false; - }else{ - return true;} + if (tFluids.size() > 0) { + if (baseEff == 0 || optFlow == 0 || counter >= 1000 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled() + || this.getBaseMetaTileEntity().hasInventoryBeenModified()) { + counter = 0; + baseEff = (int) ((50.0F + + (10.0F * ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack))) * 100); + optFlow = (int) Math.max(Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolStats(aStack).getSpeedMultiplier() + * ((GT_MetaGenerated_Tool) aStack.getItem()).getPrimaryMaterial(aStack).mToolSpeed + * 50); + } else { + counter++; + } + } + + int newPower = fluidIntoPower(tFluids, optFlow, baseEff); // How much the turbine should be producing with this flow + int difference = newPower - this.mEUt; // difference between current output and new output + + // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the difference in power level (per tick) + // This is how much the turbine can actually change during this tick + int maxChangeAllowed = Math.max(10, (int) Math.ceil(Math.abs(difference) * 0.01)); + + if (Math.abs(difference) > maxChangeAllowed) { // If this difference is too big, use the maximum allowed change + int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. + this.mEUt += change; // Apply the change + } + else + this.mEUt = newPower; + + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = (10); + if (mEUt <= 0) { + mEfficiency = 0; + stopMachine(); + return false; + } else { + return true; + } } abstract int fluidIntoPower(ArrayList aFluids, int aOptFlow, int aBaseEff); From 6d61dead98d854698a89af20554d843be97158bc Mon Sep 17 00:00:00 2001 From: pyure Date: Wed, 12 Aug 2015 15:11:57 -0400 Subject: [PATCH 2/6] Gas turbine fixes * Math fixes (no more crazy output numbers) * getAverage() references removed * multiple input hatch support (first fluid-type handled only in case user tries to fuel with methane + hydrogen simultaneously) * 125% maximum overflow inefficiency --- .../GT_MetaTileEntity_LargeTurbine_Gas.java | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java index 010f05a0..2f750ab9 100644 --- a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java +++ b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java @@ -69,22 +69,48 @@ public class GT_MetaTileEntity_LargeTurbine_Gas extends GT_MetaTileEntity_LargeT return 10; } - @Override - int fluidIntoPower(ArrayList aFluids, int aOptFlow, int aBaseEff) { - int tEU=0; - int tOut=0; - int tOptFlow = aOptFlow; - boolean b = false; - for(int i=0;i0&&depleteInput(new FluidStack(aFluids.get(i),Math.max(tOptFlow/(fuelValue*2),1)))){ - tEU += tOptFlow/2;} - } - if(tEU>0)b=true; - tEU = getAverage(tEU); - if(b&&tEU<=0)tEU=3; - return tEU * aBaseEff / 10000; - } + @Override + int fluidIntoPower(ArrayList aFluids, int aOptFlow, int aBaseEff) { + int tEU = 0; + + int actualOptimalFlow = 0; + + if (aFluids.size() >= 1) { + FluidStack firstFuelType = new FluidStack(aFluids.get(0), 0); // Identify a SINGLE type of fluid to process. Doesn't matter which one. Ignore the rest! + int fuelValue = getFuelValue(firstFuelType); + actualOptimalFlow = (int) (aOptFlow / fuelValue); + + int remainingFlow = (int) (actualOptimalFlow * 1.25f); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + int flow = 0; + int totalFlow = 0; + + for (int i = 0; i < aFluids.size(); i++) { + if (aFluids.get(i).isFluidEqual(firstFuelType)) { + flow = aFluids.get(i).amount; // Get all (steam) in hatch + flow = Math.min(flow, Math.min(remainingFlow, (int) (actualOptimalFlow * 1.25f))); // try to use up to 125% of optimal flow w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + } + } + + tEU = (int) (Math.min((float) actualOptimalFlow, totalFlow) * fuelValue); + + if (totalFlow != actualOptimalFlow) { + float efficiency = 1.0f - Math.abs(((totalFlow - (float) actualOptimalFlow) / actualOptimalFlow)); + if (efficiency < 0) + efficiency = 0; // Can happen with really ludicrously poor inefficiency. + tEU *= efficiency; + tEU = Math.max(1, tEU * aBaseEff / 10000); + } else { + tEU = tEU * aBaseEff / 10000; + } + + return tEU; + + } + return 0; + } } From 27da7acbb3988fb2e4d47a83e7df7b833945ce63 Mon Sep 17 00:00:00 2001 From: pyure Date: Wed, 12 Aug 2015 15:14:06 -0400 Subject: [PATCH 3/6] HP Steam turbine fixes * Math fixes (no more crazy output numbers) * getAverage() references removed * multiple input hatch support (no more exploits by feeding HP Steam to multiple hatches) * 125% maximum overflow inefficiency * Output ties directly to actual HP Steam consumed --- ...T_MetaTileEntity_LargeTurbine_HPSteam.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_HPSteam.java b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_HPSteam.java index 4acae119..cc881a19 100644 --- a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_HPSteam.java +++ b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_HPSteam.java @@ -56,24 +56,35 @@ public class GT_MetaTileEntity_LargeTurbine_HPSteam extends GT_MetaTileEntity_La return 0; } - @Override - int fluidIntoPower(ArrayList aFluids, int aOptFlow, int aBaseEff) { - int tEU=0; - int tOut=0; - for(int i=0;i0&&tOut aFluids, int aOptFlow, int aBaseEff) { + int tEU = 0; + int totalFlow = 0; // Byproducts are based on actual flow + int flow = 0; + int remainingFlow = (int) (aOptFlow * 1.25f); // Allowed to use up to 125% of optimal flow + + for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { + if (aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)).equals("ic2.fluidSuperheatedSteam")) { + flow = aFluids.get(i).amount; // Get all (steam) in hatch + flow = Math.min(flow, Math.min(remainingFlow, (int) (aOptFlow * 1.25f))); // try to use up to 125% of optimal flow w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + remainingFlow -= flow; // track amount we're allowed to keep depleting from hatches + totalFlow += flow; // track total used + } + } + + tEU = (int) (Math.min((float) aOptFlow, totalFlow)); + addOutput(GT_ModHandler.getSteam(totalFlow)); + if (totalFlow > 0 && totalFlow != aOptFlow) { + float efficiency = 1.0f - Math.abs(((totalFlow - (float) aOptFlow) / aOptFlow)); + tEU *= efficiency; + tEU = Math.max(1, tEU * aBaseEff / 10000); + } else { + tEU = tEU * aBaseEff / 10000; + } + + return tEU; + } } From 0c7b825e7ebcece7d780e4a96f79c319ccfe6c5f Mon Sep 17 00:00:00 2001 From: pyure Date: Wed, 12 Aug 2015 15:15:45 -0400 Subject: [PATCH 4/6] Plasma turbine fixes * Math fixes (no more crazy output numbers) * getAverage() references removed * multiple input hatch support (first fluid-type handled only in case user tries to fuel with different-valued plasma types simultaneously) * 125% maximum overflow inefficiency --- ...GT_MetaTileEntity_LargeTurbine_Plasma.java | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java index b1916b43..ceed528b 100644 --- a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java +++ b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java @@ -68,22 +68,50 @@ public class GT_MetaTileEntity_LargeTurbine_Plasma extends GT_MetaTileEntity_Lar return 0; } - @Override - int fluidIntoPower(ArrayList aFluids, int aOptFlow, int aBaseEff) { - int tEU=0; - int tOut=0; - int tOptFlow = aOptFlow * 40; - boolean b = false; - for(int i=0;i0&&depleteInput(new FluidStack(aFluids.get(i),Math.max(tOptFlow/(fuelValue*2),1)))){ - tEU += tOptFlow/2;} - } - if(tEU>0)b=true; - tEU = getAverage(tEU); - if(b&&tEU<=0)tEU=3; - return tEU * aBaseEff / 10000; - } + @Override + int fluidIntoPower(ArrayList aFluids, int aOptFlow, int aBaseEff) { + + aOptFlow *= 40; + int tEU = 0; + + int actualOptimalFlow = 0; + + if (aFluids.size() >= 1) { + FluidStack firstFuelType = new FluidStack(aFluids.get(0), 0); // Identify a SINGLE type of fluid to process. Doesn't matter which one. Ignore the rest! + int fuelValue = getFuelValue(firstFuelType); + actualOptimalFlow = (int) (aOptFlow / fuelValue); + + int remainingFlow = (int) (actualOptimalFlow * 1.25f); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + int flow = 0; + int totalFlow = 0; + + for (int i = 0; i < aFluids.size(); i++) { + if (aFluids.get(i).isFluidEqual(firstFuelType)) { + flow = aFluids.get(i).amount; // Get all (steam) in hatch + flow = Math.min(flow, Math.min(remainingFlow, (int) (actualOptimalFlow * 1.25f))); // try to use up to 125% of optimal flow w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + } + } + + tEU = (int) (Math.min((float) actualOptimalFlow, totalFlow) * fuelValue); + + if (totalFlow != actualOptimalFlow) { + float efficiency = 1.0f - Math.abs(((totalFlow - (float) actualOptimalFlow) / actualOptimalFlow)); + if (efficiency < 0) + efficiency = 0; // Can happen with really ludicrously poor inefficiency. + tEU *= efficiency; + tEU = Math.max(1, tEU * aBaseEff / 10000); + } else { + tEU = tEU * aBaseEff / 10000; + } + + return tEU; + + } + return 0; + } } From e41504b920e88a814e9045e82cc013570bc333aa Mon Sep 17 00:00:00 2001 From: pyure Date: Wed, 12 Aug 2015 15:17:31 -0400 Subject: [PATCH 5/6] Steam turbine getAverage() disabled Removed requirement of getAverage() --- .../GT_MetaTileEntity_LargeTurbine_Steam.java | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java index 46f15130..2ec88a19 100644 --- a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java +++ b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java @@ -64,35 +64,34 @@ public class GT_MetaTileEntity_LargeTurbine_Steam extends GT_MetaTileEntity_Larg return usage; } - @Override - int fluidIntoPower(ArrayList aFluids, int aOptFlow, int aBaseEff) { - int tEU=0; - int averageFlow = 0; // To prevent closed water loops from breaking. EU is based on average flow - int totalFlow = 0; // Byproducts are based on actual flow - int flow = 0; - int remainingFlow = (int)(aOptFlow * 1.25f); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. + @Override + int fluidIntoPower(ArrayList aFluids, int aOptFlow, int aBaseEff) { + int tEU = 0; + int totalFlow = 0; // Byproducts are based on actual flow + int flow = 0; + int remainingFlow = (int) (aOptFlow * 1.25f); // Allowed to use up to 125% of optimal flow. Variable required outside of loop for multi-hatch scenarios. - for(int i=0;i 0;i++){ // loop through each hatch; extract inputs and track totals. - if(aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)).equals("fluid.steam")||aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)).equals("ic2.fluidSteam")){ - flow = aFluids.get(i).amount; // Get all (steam) in hatch - flow = Math.min(flow, Math.min(remainingFlow, (int)( aOptFlow * 1.25f))); // try to use up to 125% of optimal flow w/o exceeding remainingFlow - depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount - remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches - totalFlow += flow; // track total input used - } - } - averageFlow = getAverage(totalFlow); // calculate recent average usage for power output purposes but NOT byproduct generation. We used what we used, and get byproducts from that. - - tEU = Math.min(aOptFlow, averageFlow); - addOutput(GT_ModHandler.getDistilledWater(useWater(totalFlow/160.0f))); - if(averageFlow > 0 && averageFlow != aOptFlow){ - float efficiency = 1.0f - Math.abs(((averageFlow - (float)aOptFlow) / aOptFlow)); - tEU *= efficiency; - tEU = Math.max(1, tEU * aBaseEff / 20000); - } - else { - tEU = tEU * aBaseEff / 20000; - } - return tEU; - } + for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { // loop through each hatch; extract inputs and track totals. + if (aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)).equals("fluid.steam") + || aFluids.get(i).getFluid().getUnlocalizedName(aFluids.get(i)).equals("ic2.fluidSteam")) { + flow = aFluids.get(i).amount; // Get all (steam) in hatch + flow = Math.min(flow, Math.min(remainingFlow, (int) (aOptFlow * 1.25f))); // try to use up to 125% of optimal flow w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + } + } + + tEU = (int) (Math.min((float) aOptFlow, totalFlow)); + addOutput(GT_ModHandler.getDistilledWater(useWater(totalFlow / 160.0f))); + if (totalFlow > 0 && totalFlow != aOptFlow) { + float efficiency = 1.0f - Math.abs(((totalFlow - (float) aOptFlow) / aOptFlow)); + tEU *= efficiency; + tEU = Math.max(1, tEU * aBaseEff / 20000); + } else { + tEU = tEU * aBaseEff / 20000; + } + + return tEU; + } } From b0e064bf2845289415eddf1ba9a9995f867d2768 Mon Sep 17 00:00:00 2001 From: pyure Date: Wed, 12 Aug 2015 15:39:42 -0400 Subject: [PATCH 6/6] Steam Turbine fixes Removed requirement for getAverage() --- .../machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java index 2ec88a19..535069b3 100644 --- a/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java +++ b/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java @@ -83,7 +83,8 @@ public class GT_MetaTileEntity_LargeTurbine_Steam extends GT_MetaTileEntity_Larg } tEU = (int) (Math.min((float) aOptFlow, totalFlow)); - addOutput(GT_ModHandler.getDistilledWater(useWater(totalFlow / 160.0f))); + int waterToOutput = useWater(totalFlow / 160.0f); + addOutput(GT_ModHandler.getDistilledWater(waterToOutput)); if (totalFlow > 0 && totalFlow != aOptFlow) { float efficiency = 1.0f - Math.abs(((totalFlow - (float) aOptFlow) / aOptFlow)); tEU *= efficiency;