Improve upgrade behaviour

This commit is contained in:
Ben Spiers 2013-05-29 01:37:14 +01:00
parent 124d4a5998
commit b8a79f7a85
4 changed files with 45 additions and 21 deletions

View file

@ -507,24 +507,48 @@ public final class MekanismUtils
/** /**
* Gets the operating ticks required for a machine via it's upgrades. * Gets the operating ticks required for a machine via it's upgrades.
* @param multiplier - speed multiplier * @param speedUpgrade - number of speed upgrades
* @param def - the original, default ticks required * @param def - the original, default ticks required
* @return max operating ticks * @return max operating ticks
*/ */
public static int getTicks(int multiplier, int def) public static int getTicks(int speedUpgrade, int def)
{ {
return def/(multiplier+1); return (int) (def * Math.pow(10, (-speedUpgrade/9.0)));
}
/**
* Gets the energy required per tick for a machine via it's upgrades.
* @param speedUpgrade - number of speed upgrades
* @param energyUpgrade - number of energy upgrades
* @param def - the original, default energy required
* @return max energy per tick
*/
public static int getEnergyPerTick(int speedUpgrade, int energyUpgrade, int def)
{
return (int) (def * Math.pow(10, ((speedUpgrade-energyUpgrade)/9.0)));
}
/**
* Gets the energy required per tick for a machine via it's upgrades.
* @param speedUpgrade - number of speed upgrades
* @param energyUpgrade - number of energy upgrades
* @param def - the original, default energy required
* @return max energy per tick
*/
public static double getEnergyPerTick(int speedUpgrade, int energyUpgrade, double def)
{
return (def * Math.pow(10, ((speedUpgrade-energyUpgrade)/9.0)));
} }
/** /**
* Gets the maximum energy for a machine via it's upgrades. * Gets the maximum energy for a machine via it's upgrades.
* @param multiplier - energy multiplier * @param energyUpgrade - number of energy upgrades
* @param def - original, default max energy * @param def - original, default max energy
* @return max energy * @return max energy
*/ */
public static double getEnergy(int multiplier, double def) public static double getEnergy(int energyUpgrade, double def)
{ {
return def*(multiplier+1); return (int) (def * Math.pow(10, (energyUpgrade/9.0)));
} }
/** /**

View file

@ -126,21 +126,21 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
handleSecondaryFuel(); handleSecondaryFuel();
if(electricityStored >= ENERGY_PER_TICK && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK) if(electricityStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK) && secondaryEnergyStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, SECONDARY_ENERGY_PER_TICK))
{ {
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED) && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK) if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED) && secondaryEnergyStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, SECONDARY_ENERGY_PER_TICK))
{ {
operatingTicks++; operatingTicks++;
secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK; secondaryEnergyStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, SECONDARY_ENERGY_PER_TICK);
electricityStored -= ENERGY_PER_TICK; electricityStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK);
} }
else if((operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) else if((operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operate(); operate();
operatingTicks = 0; operatingTicks = 0;
secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK; secondaryEnergyStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, SECONDARY_ENERGY_PER_TICK);
electricityStored -= ENERGY_PER_TICK; electricityStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK);
} }
} }
@ -149,7 +149,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
operatingTicks = 0; operatingTicks = 0;
} }
if(canOperate() && electricityStored >= ENERGY_PER_TICK && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK) if(canOperate() && electricityStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK) && secondaryEnergyStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, SECONDARY_ENERGY_PER_TICK))
{ {
setActive(true); setActive(true);
} }

View file

@ -93,19 +93,19 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
upgradeTicks = 0; upgradeTicks = 0;
} }
if(electricityStored >= ENERGY_PER_TICK) if(electricityStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK))
{ {
if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) if(canOperate() && (operatingTicks+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operatingTicks++; operatingTicks++;
electricityStored -= ENERGY_PER_TICK; electricityStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK);
} }
else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) else if(canOperate() && (operatingTicks+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operate(); operate();
operatingTicks = 0; operatingTicks = 0;
electricityStored -= ENERGY_PER_TICK; electricityStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK);
} }
} }
@ -114,7 +114,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
operatingTicks = 0; operatingTicks = 0;
} }
if(canOperate() && electricityStored >= ENERGY_PER_TICK) if(canOperate() && electricityStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK))
{ {
setActive(true); setActive(true);
} }

View file

@ -218,19 +218,19 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
for(int process = 0; process < tier.processes; process++) for(int process = 0; process < tier.processes; process++)
{ {
if(electricityStored >= ENERGY_PER_TICK) if(electricityStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK))
{ {
if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) < MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
progress[process]++; progress[process]++;
electricityStored -= ENERGY_PER_TICK; electricityStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK);
} }
else if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED)) else if(canOperate(getInputSlot(process), getOutputSlot(process)) && (progress[process]+1) >= MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED))
{ {
operate(getInputSlot(process), getOutputSlot(process)); operate(getInputSlot(process), getOutputSlot(process));
progress[process] = 0; progress[process] = 0;
electricityStored -= ENERGY_PER_TICK; electricityStored -= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK);
} }
} }
@ -253,7 +253,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
} }
} }
if(hasOperation && electricityStored >= ENERGY_PER_TICK) if(hasOperation && electricityStored >= MekanismUtils.getEnergyPerTick(speedMultiplier, energyMultiplier, ENERGY_PER_TICK))
{ {
setActive(true); setActive(true);
} }