remove getAverage()

We now do gradual output changes depending on the difference in current and target output level
This commit is contained in:
pyure 2015-08-12 14:47:33 -04:00
parent 1b3e6ef291
commit a3a6c55275

View file

@ -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()))); 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 @Override
public void saveNBTData(NBTTagCompound aNBT) { public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT); super.saveNBTData(aNBT);
aNBT.setLong("mOverall", mOverall);
} }
@Override @Override
public void loadNBTData(NBTTagCompound aNBT) { public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(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 @Override
public boolean checkRecipe(ItemStack aStack) { public boolean checkRecipe(ItemStack aStack) {
ArrayList<FluidStack> tFluids = getStoredFluids(); ArrayList<FluidStack> tFluids = getStoredFluids();
if (tFluids.size()>0){ if (tFluids.size() > 0) {
if(baseEff==0 || optFlow == 0 || counter >= 1000 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled() || this.getBaseMetaTileEntity().hasInventoryBeenModified()){ if (baseEff == 0 || optFlow == 0 || counter >= 1000 || this.getBaseMetaTileEntity().hasWorkJustBeenEnabled()
counter = 0; || this.getBaseMetaTileEntity().hasInventoryBeenModified()) {
baseEff = (int) ((50.0F+(10.0F*((GT_MetaGenerated_Tool)aStack.getItem()).getToolCombatDamage(aStack)))*100); counter = 0;
optFlow = (int) Math.max(Float.MIN_NORMAL, ((GT_MetaGenerated_Tool)aStack.getItem()).getToolStats(aStack).getSpeedMultiplier() * ((GT_MetaGenerated_Tool)aStack.getItem()).getPrimaryMaterial(aStack).mToolSpeed*50); baseEff = (int) ((50.0F
}else{ + (10.0F * ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack))) * 100);
counter++;}} optFlow = (int) Math.max(Float.MIN_NORMAL,
this.mEUt = fluidIntoPower(tFluids, optFlow, baseEff); ((GT_MetaGenerated_Tool) aStack.getItem()).getToolStats(aStack).getSpeedMultiplier()
this.mMaxProgresstime = 1; * ((GT_MetaGenerated_Tool) aStack.getItem()).getPrimaryMaterial(aStack).mToolSpeed
this.mEfficiencyIncrease = (10); * 50);
if(mEUt<=0){ } else {
mEfficiency=0; counter++;
mOverall=0; }
mLastTicks = new int[256]; }
stopMachine();
return false; int newPower = fluidIntoPower(tFluids, optFlow, baseEff); // How much the turbine should be producing with this flow
}else{ int difference = newPower - this.mEUt; // difference between current output and new output
return true;}
// 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<FluidStack> aFluids, int aOptFlow, int aBaseEff); abstract int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff);