Recipe and upgrade fixes.

This commit is contained in:
Ben Spiers 2015-03-21 17:21:02 +00:00
parent 84a1fa95ae
commit 9936c05da7
5 changed files with 60 additions and 57 deletions

View file

@ -201,7 +201,7 @@ public interface IFactory
return usesFuel;
}
public boolean fuelSpeedUpgrade()
public boolean fuelEnergyUpgrades()
{
return fuelSpeed;
}

View file

@ -48,9 +48,12 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
/** How much secondary energy this machine uses per tick, including upgrades. */
public double secondaryEnergyPerTick;
public static int MAX_GAS = 200;
public int secondaryEnergyThisTick;
public static int MAX_GAS = 210;
public GasTank gasTank;
public Gas prevGas;
/**
* Advanced Electric Machine -- a machine like this has a total of 4 slots. Input slot (0), fuel slot (1), output slot (2),
@ -168,11 +171,13 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
handleSecondaryFuel();
boolean changed = false;
boolean inactive = false;
RECIPE recipe = getRecipe();
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick)
secondaryEnergyThisTick = useStatisticalMechanics() ? StatUtils.inversePoisson(secondaryEnergyPerTick) : (int)Math.ceil(secondaryEnergyPerTick);
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyThisTick)
{
setActive(true);
@ -185,23 +190,24 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
operatingTicks = 0;
}
gasTank.draw((int)secondaryEnergyPerTick, true);
gasTank.draw(secondaryEnergyThisTick, true);
electricityStored -= energyPerTick;
}
else {
if(prevEnergy >= getEnergy())
{
changed = true;
setActive(false);
}
inactive = true;
setActive(false);
}
if(changed && !canOperate(recipe) && getRecipe() == null)
if(inactive && getRecipe() == null)
{
operatingTicks = 0;
}
prevEnergy = getEnergy();
if(!(gasTank.getGasType() == null || gasTank.getStored() == 0))
{
prevGas = gasTank.getGasType();
}
}
}
@ -266,26 +272,26 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
@Override
public AdvancedMachineInput getInput()
{
return new AdvancedMachineInput(inventory[0], gasTank.getGasType());
return new AdvancedMachineInput(inventory[0], prevGas);
}
@Override
public RECIPE getRecipe()
{
AdvancedMachineInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{
cachedRecipe = RecipeHandler.getRecipe(input, getRecipes());
}
return cachedRecipe;
}
@Override
public void operate(RECIPE recipe)
{
recipe.operate(inventory, 0, 2, gasTank, (int)secondaryEnergyPerTick);
recipe.operate(inventory, 0, 2, gasTank, secondaryEnergyThisTick);
markDirty();
ejectorComponent.onOutput();
@ -294,7 +300,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
@Override
public boolean canOperate(RECIPE recipe)
{
return recipe != null && recipe.canOperate(inventory, 0, 2, gasTank, (int)secondaryEnergyPerTick);
return recipe != null && recipe.canOperate(inventory, 0, 2, gasTank, secondaryEnergyThisTick);
}
@Override
@ -335,6 +341,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
super.readFromNBT(nbtTags);
gasTank.read(nbtTags.getCompoundTag("gasTank"));
gasTank.setMaxGas(MAX_GAS);
}
@Override
@ -407,19 +414,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
if(upgrade == Upgrade.SPEED)
{
double secondaryToUse = BASE_SECONDARY_ENERGY_PER_TICK;
if(upgradeableSecondaryEfficiency())
{
secondaryToUse = MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_SECONDARY_ENERGY_PER_TICK);
}
secondaryEnergyPerTick = (int)Math.ceil(secondaryToUse);
if(useStatisticalMechanics())
{
secondaryEnergyPerTick = StatUtils.inversePoisson(secondaryToUse);
}
secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_SECONDARY_ENERGY_PER_TICK, upgradeableSecondaryEfficiency());
}
}

View file

@ -45,7 +45,9 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
public static final int BASE_INJECT_USAGE = 1;
public int injectUsage = 1;
public double injectUsage = 1;
public int injectUsageThisTick;
public int updateDelay;
@ -121,7 +123,9 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
DissolutionRecipe recipe = getRecipe();
if(canOperate(recipe) && getEnergy() >= energyUsage && injectTank.getStored() >= injectUsage && MekanismUtils.canFunction(this))
injectUsageThisTick = StatUtils.inversePoisson(injectUsage);
if(canOperate(recipe) && getEnergy() >= energyUsage && injectTank.getStored() >= injectUsageThisTick && MekanismUtils.canFunction(this))
{
setActive(true);
setEnergy(getEnergy() - energyUsage);
@ -249,7 +253,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
public void minorOperate()
{
injectTank.draw(injectUsage, true);
injectTank.draw(injectUsageThisTick, true);
}
@Override
@ -463,7 +467,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
switch(upgrade)
{
case SPEED:
injectUsage = StatUtils.inversePoisson(MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_INJECT_USAGE));
injectUsage = MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_INJECT_USAGE, true);
ticksRequired = MekanismUtils.getTicks(this, BASE_TICKS_REQUIRED);
case ENERGY:
energyUsage = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_USAGE);

View file

@ -80,6 +80,8 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
/** How much secondary energy each operation consumes per tick */
public double secondaryEnergyPerTick = 0;
public int secondaryEnergyThisTick;
/** How long it takes this factory to switch recipe types. */
public int RECIPE_TICKS_REQUIRED = 40;
@ -317,14 +319,15 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
recipeTicks = 0;
}
secondaryEnergyThisTick = recipeType.fuelEnergyUpgrades() ? StatUtils.inversePoisson(secondaryEnergyPerTick) : (int)Math.ceil(secondaryEnergyPerTick);
for(int process = 0; process < tier.processes; process++)
{
if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick)
if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyThisTick)
{
if((progress[process]+1) < ticksRequired)
{
progress[process]++;
gasTank.draw((int)secondaryEnergyPerTick, true);
gasTank.draw(secondaryEnergyThisTick, true);
electricityStored -= energyPerTick;
}
else if((progress[process]+1) >= ticksRequired)
@ -332,14 +335,14 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
operate(getInputSlot(process), getOutputSlot(process));
progress[process] = 0;
gasTank.draw((int)secondaryEnergyPerTick, true);
gasTank.draw(secondaryEnergyThisTick, true);
electricityStored -= energyPerTick;
}
}
if(!canOperate(getInputSlot(process), getOutputSlot(process)))
{
if(!recipeType.usesFuel() || !recipeType.hasRecipe(inventory[getInputSlot(process)]))
if(!(recipeType.usesFuel() && recipeType.hasRecipe(inventory[getInputSlot(process)])))
{
progress[process] = 0;
}
@ -357,7 +360,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
}
}
if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick)
if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyThisTick)
{
setActive(true);
}
@ -456,18 +459,9 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
}
}
public int getSecondaryEnergyPerTick(RecipeType type)
public double getSecondaryEnergyPerTick(RecipeType type)
{
double secondaryToUse = type.getSecondaryEnergyPerTick();
if(type.fuelSpeedUpgrade())
{
secondaryToUse = MekanismUtils.getSecondaryEnergyPerTickMean(this, type.getSecondaryEnergyPerTick());
return StatUtils.inversePoisson(secondaryToUse);
}
else {
return (int)Math.ceil(secondaryToUse);
}
return MekanismUtils.getSecondaryEnergyPerTickMean(this, type.getSecondaryEnergyPerTick(), type.fuelEnergyUpgrades());
}
public void handleSecondaryFuel()
@ -616,7 +610,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
return false;
}
return recipe.canOperate(inventory, inputSlot, outputSlot, gasTank, (int)secondaryEnergyPerTick);
return recipe.canOperate(inventory, inputSlot, outputSlot, gasTank, secondaryEnergyThisTick);
}
BasicMachineRecipe<?> recipe = recipeType.getRecipe(inventory[inputSlot]);
@ -640,7 +634,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
{
AdvancedMachineRecipe<?> recipe = recipeType.getRecipe(inventory[inputSlot], gasTank.getGasType());
recipe.operate(inventory, inputSlot, outputSlot, gasTank, (int)secondaryEnergyPerTick);
recipe.operate(inventory, inputSlot, outputSlot, gasTank, secondaryEnergyThisTick);
}
else
{

View file

@ -576,6 +576,11 @@ public final class MekanismUtils
tile.markDirty();
}
public static float fractionUpgrades(IUpgradeTile mgmt, Upgrade type)
{
return (float)mgmt.getComponent().getUpgrades(type)/(float)type.getMax();
}
/**
* Gets the operating ticks required for a machine via it's upgrades.
* @param mgmt - tile containing upgrades
@ -584,7 +589,7 @@ public final class MekanismUtils
*/
public static int getTicks(IUpgradeTile mgmt, int def)
{
return (int)(def * Math.pow(general.maxUpgradeMultiplier, (float)-mgmt.getComponent().getUpgrades(Upgrade.SPEED)/(float)Upgrade.SPEED.getMax()));
return (int)(def * Math.pow(general.maxUpgradeMultiplier, -fractionUpgrades(mgmt, Upgrade.SPEED)));
}
/**
@ -595,7 +600,7 @@ public final class MekanismUtils
*/
public static double getEnergyPerTick(IUpgradeTile mgmt, double def)
{
return def * Math.pow(general.maxUpgradeMultiplier, (2*mgmt.getComponent().getUpgrades(Upgrade.SPEED)-(float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY))/(float)Upgrade.ENERGY.getMax());
return def * Math.pow(general.maxUpgradeMultiplier, 2*fractionUpgrades(mgmt, Upgrade.SPEED)-fractionUpgrades(mgmt, Upgrade.ENERGY));
}
/**
@ -606,7 +611,7 @@ public final class MekanismUtils
*/
public static double getBaseEnergyPerTick(IUpgradeTile mgmt, double def)
{
return def * Math.pow(general.maxUpgradeMultiplier, -(float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY)/(float)Upgrade.ENERGY.getMax());
return def * Math.pow(general.maxUpgradeMultiplier, -fractionUpgrades(mgmt, Upgrade.ENERGY));
}
/**
@ -615,9 +620,14 @@ public final class MekanismUtils
* @param def - the original, default secondary energy required
* @return max secondary energy per tick
*/
public static double getSecondaryEnergyPerTickMean(IUpgradeTile mgmt, int def)
public static double getSecondaryEnergyPerTickMean(IUpgradeTile mgmt, int def, boolean energyUpgrades)
{
return (def * Math.pow(general.maxUpgradeMultiplier, mgmt.getComponent().getUpgrades(Upgrade.SPEED)/(float)Upgrade.SPEED.getMax()));
if(energyUpgrades)
{
return def * Math.pow(general.maxUpgradeMultiplier, 2 * fractionUpgrades(mgmt, Upgrade.SPEED) - fractionUpgrades(mgmt, Upgrade.ENERGY));
}
return def * Math.pow(general.maxUpgradeMultiplier, fractionUpgrades(mgmt, Upgrade.SPEED));
}
/**
@ -628,7 +638,7 @@ public final class MekanismUtils
*/
public static double getMaxEnergy(IUpgradeTile mgmt, double def)
{
return def * Math.pow(general.maxUpgradeMultiplier, (float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY)/(float)Upgrade.ENERGY.getMax());
return def * Math.pow(general.maxUpgradeMultiplier, fractionUpgrades(mgmt, Upgrade.ENERGY));
}
/**