Skip to content

Commit

Permalink
Fix drain remainder (ceil and floor are important)
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Mar 26, 2020
1 parent 04ae795 commit 690a76f
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class LocomotiveSteam extends Locomotive {
private final static String BURN_TIME = "BURN_TIME";
private final static String BURN_MAX = "BURN_MAX";
private double driverDiameter;
private float drainRemainder;

public LocomotiveSteam() {
sync.setFloat(BOILER_PRESSURE, 0f);
Expand Down Expand Up @@ -642,7 +643,7 @@ public void onTick() {
int maxPSI = this.getDefinition().getMaxPSI(gauge);
sync.setBoolean(PRESSURE_VALVE, boilerPressure > maxPSI);
if (boilerPressure > maxPSI) {
waterUsed += boilerPressure - maxPSI;
waterUsed += boilerPressure - maxPSI;
boilerPressure = maxPSI;
}
} else {
Expand Down Expand Up @@ -670,13 +671,10 @@ public void onTick() {

if (waterUsed != 0) {
waterUsed *= Config.ConfigBalance.locoWaterUsage;
waterUsed += drainRemainder;
if (waterUsed > 0) {
theTank.drain(new FluidStack(Fluid.WATER, (int) Math.ceil(waterUsed)), false);
waterUsed = waterUsed % 1;
}
// handle remainder
if (Math.random() <= waterUsed) {
theTank.drain(new FluidStack(Fluid.WATER, 1), false);
theTank.drain(new FluidStack(Fluid.WATER, (int) Math.floor(waterUsed)), false);
drainRemainder = waterUsed % 1;
}
}

Expand Down

0 comments on commit 690a76f

Please sign in to comment.