Skip to content

Commit 8566519

Browse files
committed
Switchable brake system
1 parent 72674c9 commit 8566519

22 files changed

+860
-612
lines changed

Source/Orts.Common/Conversions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static class Kg
189189
/// <summary>Convert from kilograms to UK Tons</summary>
190190
public static float ToTUK(float kg) { return kg * (1.0f / 1016.047f); }
191191
/// <summary>Convert from kilogram to metric tonnes</summary>
192-
public static float ToTonne(float kg) { return kg * (1.0f / 1000.0f); }
192+
public static float ToTonne(float kg) { return kg / 1000.0f; }
193193
/// <summary>Convert from metrix tonnes to kilogram</summary>
194194
public static float FromTonne(float tonne) { return tonne * 1000.0f; }
195195
}

Source/Orts.Parsers.Msts/STFReader.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,10 @@ public float ReadFloat(UNITS validUnits, float? defaultValue)
609609
// However, some values (mostly "time" ones) may be followed by text. Therefore that approach cannot be used consistently
610610
// and has been abandoned. </CJComment>
611611

612-
float val;
613-
double scale = ParseUnitSuffix(ref item, validUnits);
614612
if (item.Length == 0) return 0.0f;
615613
if (item[item.Length - 1] == ',') item = item.TrimEnd(',');
616-
if (float.TryParse(item, parseNum, parseNFI, out val)) return (scale == 1) ? val : (float)(scale * val);
614+
double scale = ParseUnitSuffix(ref item, validUnits); // must be after TrimEnd(','), otherwise the unit parsed becomes invalid
615+
if (float.TryParse(item, parseNum, parseNFI, out float val)) return (scale == 1) ? val : (float)(scale * val);
617616
STFException.TraceWarning(this, "Cannot parse the constant number " + item);
618617
if (item == ")") StepBackOneItem();
619618
return defaultValue.GetValueOrDefault(0);

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4059,33 +4059,14 @@ public void UnconditionalInitializeBrakes()
40594059
MSTSLocomotive lead = (MSTSLocomotive)Cars[LeadLocomotiveIndex];
40604060
if (lead.TrainBrakeController != null)
40614061
{
4062-
foreach (MSTSWagon car in Cars)
4062+
foreach (var car in Cars)
40634063
{
4064-
if (lead.CarBrakeSystemType != car.CarBrakeSystemType) // Test to see if car brake system is the same as the locomotive
4064+
if (lead.BrakeSystem.GetType() != car.BrakeSystem.GetType())
40654065
{
4066-
// If not, change so that they are compatible
4067-
car.CarBrakeSystemType = lead.CarBrakeSystemType;
4068-
if (lead.BrakeSystem is VacuumSinglePipe)
4069-
car.MSTSBrakeSystem = new VacuumSinglePipe(car);
4070-
else if (lead.BrakeSystem is AirTwinPipe)
4071-
car.MSTSBrakeSystem = new AirTwinPipe(car);
4072-
else if (lead.BrakeSystem is AirSinglePipe leadAir)
4073-
{
4074-
car.MSTSBrakeSystem = new AirSinglePipe(car);
4075-
// if emergency reservoir has been set on lead locomotive then also set on trailing cars
4076-
if (leadAir.EmergencyReservoirPresent)
4077-
{
4078-
(car.BrakeSystem as AirSinglePipe).EmergencyReservoirPresent = leadAir.EmergencyReservoirPresent;
4079-
}
4080-
}
4081-
else if (lead.BrakeSystem is EPBrakeSystem ep)
4082-
car.MSTSBrakeSystem = new EPBrakeSystem(car, ep.TwoPipes);
4083-
else if (lead.BrakeSystem is SingleTransferPipe)
4084-
car.MSTSBrakeSystem = new SingleTransferPipe(car);
4085-
else
4086-
throw new Exception("Unknown brake type");
4087-
4088-
car.MSTSBrakeSystem.InitializeFromCopy(lead.BrakeSystem);
4066+
car.BrakeSystem = BrakeSystem.CreateNewLike(lead.BrakeSystem, car);
4067+
car.BrakeSystem.InitializeFromCopy(lead.BrakeSystem, false);
4068+
if (car.BrakeSystem is AirSinglePipe carAir && lead.BrakeSystem is AirSinglePipe leadAir)
4069+
carAir.EmergencyReservoirPresent = leadAir.EmergencyReservoirPresent;
40894070
Trace.TraceInformation("Car and Locomotive Brake System Types Incompatible on Car {0} - Car brakesystem type changed to {1}", car.CarID, car.CarBrakeSystemType);
40904071
}
40914072
}

0 commit comments

Comments
 (0)