Skip to content

Commit

Permalink
Fix rounding errors in non-standard gauge stock definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Sep 29, 2023
1 parent e1e19a1 commit 3913730
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class CarFreightDefinition extends FreightDefinition {

private int numSlots;
private int width;
private double numSlots;
private double width;
private List<String> validCargo;

public CarFreightDefinition(Class<? extends CarFreight> cls, String defID, DataBlock data) throws Exception {
Expand All @@ -33,8 +33,8 @@ protected Identifier defaultDataLocation() {
public void loadData(DataBlock data) throws Exception {
super.loadData(data);
DataBlock freight = data.getBlock("freight");
this.numSlots = (int) Math.ceil(freight.getValue("slots").asInteger() * internal_inv_scale);
this.width = (int) Math.ceil(freight.getValue("width").asInteger() * internal_inv_scale);
this.numSlots = freight.getValue("slots").asInteger() * internal_inv_scale;
this.width = freight.getValue("width").asInteger() * internal_inv_scale;
List<DataBlock.Value> cargo = freight.getValues("cargo");
this.validCargo = cargo == null ? null : cargo.stream().map(DataBlock.Value::asString).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class CarTankDefinition extends FreightDefinition {

private List<Fluid> fluidFilter; // null == no filter
private FluidQuantity capacity;
private double capacity_l;

public CarTankDefinition(String defID, DataBlock data) throws Exception {
this(CarTank.class, defID, data);
Expand All @@ -36,7 +36,7 @@ protected Identifier defaultDataLocation() {
public void loadData(DataBlock data) throws Exception {
super.loadData(data);
DataBlock tank = data.getBlock("tank");
capacity = FluidQuantity.FromLiters((int) Math.ceil(tank.getValue("capacity_l").asInteger() * internal_inv_scale));
capacity_l = tank.getValue("capacity_l").asInteger() * internal_inv_scale;
List<DataBlock.Value> whitelist = tank.getValues("whitelist");
if (whitelist != null) {
fluidFilter = new ArrayList<>();
Expand All @@ -59,7 +59,7 @@ public List<String> getTooltip(Gauge gauge) {
}

public FluidQuantity getTankCapaity(Gauge gauge) {
return this.capacity.scale(gauge.scale()).min(FluidQuantity.FromBuckets(1)).roundBuckets();
return FluidQuantity.FromLiters((int) Math.ceil(capacity_l * gauge.scale())).min(FluidQuantity.FromBuckets(1)).roundBuckets();
}

public List<Fluid> getFluidFilter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public abstract class EntityRollingStockDefinition {
private double widthBounds;
private double passengerCompartmentLength;
private double passengerCompartmentWidth;
private int weight;
private double weight;
private int maxPassengers;
private float interiorLightLevel;
private boolean hasIndependentBrake;
Expand Down Expand Up @@ -390,7 +390,7 @@ public void loadData(DataBlock data) throws Exception {
couplerSlackRear = couplers.getValue("rear_slack").asFloat() * (float) internal_model_scale;

DataBlock properties = data.getBlock("properties");
weight = (int) Math.ceil(properties.getValue("weight_kg").asInteger() * internal_inv_scale);
weight = properties.getValue("weight_kg").asInteger() * internal_inv_scale;
valveGear = ValveGearConfig.get(properties, "valve_gear");
hasIndependentBrake = properties.getValue("independent_brake").asBoolean();
hasPressureBrake = properties.getValue("pressure_brake").asBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public abstract class LocomotiveDefinition extends FreightDefinition {
public boolean toggleBell;
public SoundDefinition bell;
private String works;
private int power;
private int traction;
private double power;
private double traction;
private Speed maxSpeed;
private boolean hasRadioEquipment;
public boolean muliUnitCapable;
Expand Down Expand Up @@ -53,8 +53,8 @@ public void loadData(DataBlock data) throws Exception {
muliUnitCapable = true;
factorOfAdhesion = 0;
} else {
power = (int) Math.ceil(properties.getValue("horsepower").asInteger() * internal_inv_scale);
traction = (int) Math.ceil(properties.getValue("tractive_effort_lbf").asInteger() * internal_inv_scale);
power = properties.getValue("horsepower").asInteger() * internal_inv_scale;
traction = properties.getValue("tractive_effort_lbf").asInteger() * internal_inv_scale;
factorOfAdhesion = properties.getValue("factor_of_adhesion").asDouble(4);
maxSpeed = Speed.fromMetric(properties.getValue("max_speed_kmh").asDouble() * internal_inv_scale);
muliUnitCapable = properties.getValue("multi_unit_capable").asBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LocomotiveDieselDefinition extends LocomotiveDefinition {
public SoundDefinition idle;
public SoundDefinition running;
public SoundDefinition horn;
private FluidQuantity fuelCapacity;
private double fuelCapacity_l;
private int fuelEfficiency;
private boolean hornSus;
private int notches;
Expand All @@ -38,10 +38,10 @@ public void loadData(DataBlock data) throws Exception {

DataBlock properties = data.getBlock("properties");
if (!isCabCar()) {
fuelCapacity = FluidQuantity.FromLiters((int) Math.ceil(properties.getValue("fuel_capacity_l").asInteger() * internal_inv_scale * 10));
fuelCapacity_l = properties.getValue("fuel_capacity_l").asInteger() * internal_inv_scale * 10;
fuelEfficiency = properties.getValue("fuel_efficiency_%").asInteger();
} else {
fuelCapacity = FluidQuantity.ZERO;
fuelCapacity_l = 0;
}
notches = properties.getValue("throttle_notches").asInteger();

Expand Down Expand Up @@ -78,7 +78,7 @@ public boolean getHornSus() {
}

public FluidQuantity getFuelCapacity(Gauge gauge) {
return this.fuelCapacity.scale(gauge.scale()).min(FluidQuantity.FromBuckets(1)).roundBuckets();
return FluidQuantity.FromLiters((int) Math.ceil(this.fuelCapacity_l * gauge.scale())).min(FluidQuantity.FromBuckets(1)).roundBuckets();
}

public int getFuelEfficiency() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class LocomotiveSteamDefinition extends LocomotiveDefinition {
public Identifier chuff;
public Identifier pressure;
public Identifier cylinder_drain;
private FluidQuantity tankCapacity;
private int maxPSI;
private int numSlots;
private int width;
private double tankCapacity_l;
private double maxPSI;
private double numSlots;
private double width;
public boolean tender_auto_feed;
public boolean cab_forward;

Expand All @@ -41,18 +41,18 @@ public void loadData(DataBlock data) throws Exception {
super.loadData(data);
DataBlock properties = data.getBlock("properties");
if (isCabCar()) {
tankCapacity = FluidQuantity.ZERO;
tankCapacity_l = 0;
maxPSI = 0;
numSlots = 0;
width = 0;
tender_auto_feed = false;
} else {
DataBlock firebox = data.getBlock("firebox");

tankCapacity = FluidQuantity.FromLiters((int) Math.ceil(properties.getValue("water_capacity_l").asInteger() * internal_inv_scale));
maxPSI = (int) Math.ceil(properties.getValue("max_psi").asInteger() * internal_inv_scale);
numSlots = (int) Math.ceil(firebox.getValue("slots").asInteger() * internal_inv_scale);
width = (int) Math.ceil(firebox.getValue("width").asInteger() * internal_inv_scale);
tankCapacity_l = properties.getValue("water_capacity_l").asInteger() * internal_inv_scale;
maxPSI = Math.ceil(properties.getValue("max_psi").asInteger() * internal_inv_scale);
numSlots = Math.ceil(firebox.getValue("slots").asInteger() * internal_inv_scale);
width = Math.ceil(firebox.getValue("width").asInteger() * internal_inv_scale);
tender_auto_feed = properties.getValue("tender_auto_feed").asBoolean(true);
}
cab_forward = properties.getValue("cab_forward").asBoolean(false);
Expand Down Expand Up @@ -92,7 +92,7 @@ protected GuiBuilder getDefaultOverlay(DataBlock data) throws IOException {
}

public FluidQuantity getTankCapacity(Gauge gauge) {
return this.tankCapacity.scale(gauge.scale()).min(FluidQuantity.FromBuckets(1)).roundBuckets();
return FluidQuantity.FromLiters((int) Math.ceil(this.tankCapacity_l * gauge.scale())).min(FluidQuantity.FromBuckets(1)).roundBuckets();
}

public int getMaxPSI(Gauge gauge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.util.List;

public class TenderDefinition extends CarTankDefinition {
private int numSlots;
private int width;
private double numSlots;
private double width;
private boolean showCurrentLoadOnly;

public TenderDefinition(String defID, DataBlock data) throws Exception {
Expand All @@ -30,8 +30,8 @@ public void loadData(DataBlock data) throws Exception {
super.loadData(data);

DataBlock tender = data.getBlock("tender");
this.numSlots = (int) Math.ceil(tender.getValue("slots").asInteger() * internal_inv_scale);
this.width = (int) Math.ceil(tender.getValue("width").asInteger() * internal_inv_scale);
this.numSlots = tender.getValue("slots").asInteger() * internal_inv_scale;
this.width = tender.getValue("width").asInteger() * internal_inv_scale;
this.showCurrentLoadOnly = tender.getValue("show_current_load_only").asBoolean(false);
}

Expand Down

0 comments on commit 3913730

Please sign in to comment.