From e71bc5a672b9f50de2254cd3919a1bbdba9b9af9 Mon Sep 17 00:00:00 2001 From: Phillip Schlichting Date: Tue, 5 Sep 2023 19:03:28 -0500 Subject: [PATCH] Improve backwards compatibility --- .../SubSystems/Brakes/MSTS/AirSinglePipe.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/AirSinglePipe.cs b/Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/AirSinglePipe.cs index bc5d7db39f..b8ed2c37e2 100644 --- a/Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/AirSinglePipe.cs +++ b/Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/AirSinglePipe.cs @@ -53,6 +53,7 @@ public class AirSinglePipe : MSTSBrakeSystem protected float MaxAuxilaryChargingRatePSIpS = 1.684f; protected float BrakeInsensitivityPSIpS = 0.07f; protected float EmergencyValveActuationRatePSIpS = 0; + protected bool LegacyEmergencyValve = false; protected float EmergencyDumpValveRatePSIpS = 0; protected float EmergencyDumpValveTimerS = 120; protected float? EmergencyDumpStartTime; @@ -173,6 +174,7 @@ public override void InitializeFromCopy(BrakeSystem copy) TripleValveSensitivityPSI = thiscopy.TripleValveSensitivityPSI; BrakeCylinderSpringPressurePSI = thiscopy.BrakeCylinderSpringPressurePSI; ServiceMaxCylPressurePSI = thiscopy.ServiceMaxCylPressurePSI; + LegacyEmergencyValve = thiscopy.LegacyEmergencyValve; } // Get the brake BC & BP for EOT conditions @@ -341,6 +343,7 @@ public override void Save(BinaryWriter outf) outf.Write((int)HoldingValve); outf.Write(UniformChargingActive); outf.Write(QuickServiceActive); + outf.Write(LegacyEmergencyValve); } public override void Restore(BinaryReader inf) @@ -366,6 +369,7 @@ public override void Restore(BinaryReader inf) HoldingValve = (ValveState)inf.ReadInt32(); UniformChargingActive = inf.ReadBoolean(); QuickServiceActive = inf.ReadBoolean(); + LegacyEmergencyValve = inf.ReadBoolean(); } public override void Initialize(bool handbrakeOn, float maxPressurePSI, float fullServPressurePSI, bool immediateRelease) @@ -422,7 +426,10 @@ public override void Initialize() if (EngineRelayValveRatio == 0) EngineRelayValveRatio = RelayValveRatio; if ((Car as MSTSWagon).EmergencyReservoirPresent && EmergencyValveActuationRatePSIpS == 0) + { EmergencyValveActuationRatePSIpS = 15; + LegacyEmergencyValve = true; + } if (InitialApplicationThresholdPSI == 0) { @@ -473,8 +480,8 @@ public void UpdateTripleValveState(float elapsedClockSeconds) var prevState = TripleValveState; var valveType = (Car as MSTSWagon).BrakeValve; bool disableGradient = !(Car.Train.LeadLocomotive is MSTSLocomotive) && Car.Train.TrainType != Orts.Simulation.Physics.Train.TRAINTYPE.STATIC; - // Small workaround to allow trains to more reliably go into emergency after uncoupling - bool emergencyTripped = (Car.Train.TrainType == Orts.Simulation.Physics.Train.TRAINTYPE.STATIC) ? + // Legacy cars and static cars use a simpler check for emergency applications to ensure emergency applications occur despite simplified physics + bool emergencyTripped = (Car.Train.TrainType == Orts.Simulation.Physics.Train.TRAINTYPE.STATIC || LegacyEmergencyValve) ? BrakeLine1PressurePSI <= 0.75f * EmergResPressurePSI * AuxCylVolumeRatio / (AuxCylVolumeRatio + 1) : Math.Max(-SmoothedBrakePipeChangePSIpS.SmoothedValue, 0) > EmergencyValveActuationRatePSIpS; if (valveType == MSTSWagon.BrakeValveType.Distributor)