@@ -51,6 +51,9 @@ public class AirSinglePipe : MSTSBrakeSystem
5151 protected float MaxAuxilaryChargingRatePSIpS = 1.684f ;
5252 protected float BrakeInsensitivityPSIpS = 0.07f ;
5353 protected float EmergencyValveActuationRatePSIpS = 0 ;
54+ protected float EmergencyDumpValveRatePSIpS = 0 ;
55+ protected float EmergencyDumpValveTimerS = 120 ;
56+ protected float ? EmergencyDumpStartTime ;
5457 protected float EmergResChargingRatePSIpS = 1.684f ;
5558 protected float EmergAuxVolumeRatio = 1.4f ;
5659 protected string DebugType = string . Empty ;
@@ -116,6 +119,8 @@ public override void InitializeFromCopy(BrakeSystem copy)
116119 MaxAuxilaryChargingRatePSIpS = thiscopy . MaxAuxilaryChargingRatePSIpS ;
117120 BrakeInsensitivityPSIpS = thiscopy . BrakeInsensitivityPSIpS ;
118121 EmergencyValveActuationRatePSIpS = thiscopy . EmergencyValveActuationRatePSIpS ;
122+ EmergencyDumpValveRatePSIpS = thiscopy . EmergencyDumpValveRatePSIpS ;
123+ EmergencyDumpValveTimerS = thiscopy . EmergencyDumpValveTimerS ;
119124 EmergResChargingRatePSIpS = thiscopy . EmergResChargingRatePSIpS ;
120125 EmergAuxVolumeRatio = thiscopy . EmergAuxVolumeRatio ;
121126 TwoPipes = thiscopy . TwoPipes ;
@@ -232,6 +237,8 @@ public override void Parse(string lowercasetoken, STFReader stf)
232237 case "wagon(brakepipevolume" : BrakePipeVolumeM3 = Me3 . FromFt3 ( stf . ReadFloatBlock ( STFReader . UNITS . VolumeDefaultFT3 , null ) ) ; break ;
233238 case "wagon(ortsbrakeinsensitivity" : BrakeInsensitivityPSIpS = stf . ReadFloatBlock ( STFReader . UNITS . PressureRateDefaultPSIpS , 0.07f ) ; break ;
234239 case "wagon(ortsemergencyvalveactuationrate" : EmergencyValveActuationRatePSIpS = stf . ReadFloatBlock ( STFReader . UNITS . PressureRateDefaultPSIpS , 15f ) ; break ;
240+ case "wagon(ortsemergencydumpvalverate" : EmergencyDumpValveRatePSIpS = stf . ReadFloatBlock ( STFReader . UNITS . PressureRateDefaultPSIpS , 15f ) ; break ;
241+ case "wagon(ortsemergencydumpvalvetimer" : EmergencyDumpValveTimerS = stf . ReadFloatBlock ( STFReader . UNITS . Time , 120.0f ) ; break ;
235242 case "wagon(ortsmainrespipeauxrescharging" : MRPAuxResCharging = this is AirTwinPipe && stf . ReadBoolBlock ( true ) ; break ;
236243 }
237244 }
@@ -307,7 +314,10 @@ public override void Initialize(bool handbrakeOn, float maxPressurePSI, float fu
307314 CylPressurePSI = AutoCylPressurePSI = immediateRelease ? 0 : Math . Min ( ( maxPressurePSI - BrakeLine1PressurePSI ) * AuxCylVolumeRatio , MaxCylPressurePSI ) ;
308315 AuxResPressurePSI = Math . Max ( TwoPipes ? maxPressurePSI : maxPressurePSI - AutoCylPressurePSI / AuxCylVolumeRatio , BrakeLine1PressurePSI ) ;
309316 if ( ( Car as MSTSWagon ) . EmergencyReservoirPresent )
317+ {
310318 EmergResPressurePSI = Math . Max ( AuxResPressurePSI , maxPressurePSI ) ;
319+ if ( EmergencyValveActuationRatePSIpS == 0 ) EmergencyValveActuationRatePSIpS = 15 ;
320+ }
311321 TripleValveState = AutoCylPressurePSI < 1 ? ValveState . Release : ValveState . Lap ;
312322 HoldingValve = ValveState . Release ;
313323 HandbrakePercent = handbrakeOn & ( Car as MSTSWagon ) . HandBrakePresent ? 100 : 0 ;
@@ -340,23 +350,25 @@ public override void LocoInitializeMoving() // starting conditions when starting
340350
341351 public void UpdateTripleValveState ( float elapsedClockSeconds )
342352 {
353+ var prevState = TripleValveState ;
343354 var valveType = ( Car as MSTSWagon ) . BrakeValve ;
355+ bool disableGradient = ! ( Car . Train . LeadLocomotive is MSTSLocomotive ) && Car . Train . TrainType != Orts . Simulation . Physics . Train . TRAINTYPE . STATIC ;
344356 if ( valveType == MSTSWagon . BrakeValveType . Distributor )
345357 {
346358 float targetPressurePSI = ( ControlResPressurePSI - BrakeLine1PressurePSI ) * AuxCylVolumeRatio ;
347- if ( targetPressurePSI > AutoCylPressurePSI && EmergencyValveActuationRatePSIpS > 0 && ( prevBrakePipePressurePSI - BrakeLine1PressurePSI ) > Math . Max ( elapsedClockSeconds , 0.0001f ) * EmergencyValveActuationRatePSIpS )
359+ if ( ! disableGradient && targetPressurePSI > AutoCylPressurePSI && EmergencyValveActuationRatePSIpS > 0 && ( prevBrakePipePressurePSI - BrakeLine1PressurePSI ) > Math . Max ( elapsedClockSeconds , 0.0001f ) * EmergencyValveActuationRatePSIpS )
348360 TripleValveState = ValveState . Emergency ;
349361 else if ( targetPressurePSI < AutoCylPressurePSI - ( TripleValveState != ValveState . Release ? 2.2f : 0f )
350362 || targetPressurePSI < 2.2f ) // The latter is a UIC regulation (0.15 bar)
351363 TripleValveState = ValveState . Release ;
352364 else if ( TripleValveState != ValveState . Emergency && targetPressurePSI > AutoCylPressurePSI + ( TripleValveState != ValveState . Apply ? 2.2f : 0f ) )
353365 TripleValveState = ValveState . Apply ;
354- else
366+ else if ( TripleValveState != ValveState . Emergency )
355367 TripleValveState = ValveState . Lap ;
356368 }
357369 else if ( valveType == MSTSWagon . BrakeValveType . TripleValve || valveType == MSTSWagon . BrakeValveType . DistributingValve )
358370 {
359- if ( BrakeLine1PressurePSI < AuxResPressurePSI - 1 && EmergencyValveActuationRatePSIpS > 0 && ( prevBrakePipePressurePSI - BrakeLine1PressurePSI ) > Math . Max ( elapsedClockSeconds , 0.0001f ) * EmergencyValveActuationRatePSIpS )
371+ if ( ! disableGradient && BrakeLine1PressurePSI < AuxResPressurePSI - 1 && EmergencyValveActuationRatePSIpS > 0 && ( prevBrakePipePressurePSI - BrakeLine1PressurePSI ) > Math . Max ( elapsedClockSeconds , 0.0001f ) * EmergencyValveActuationRatePSIpS )
360372 TripleValveState = ValveState . Emergency ;
361373 else if ( BrakeLine1PressurePSI > AuxResPressurePSI + 1 )
362374 TripleValveState = ValveState . Release ;
@@ -371,6 +383,15 @@ public void UpdateTripleValveState(float elapsedClockSeconds)
371383 {
372384 TripleValveState = ValveState . Release ;
373385 }
386+ if ( TripleValveState == ValveState . Emergency )
387+ {
388+ if ( prevState != ValveState . Emergency )
389+ {
390+ EmergencyDumpStartTime = ( float ) Car . Simulator . GameTime ;
391+ Car . SignalEvent ( Event . EmergencyVentValveOn ) ;
392+ }
393+ }
394+ else EmergencyDumpStartTime = null ;
374395 prevBrakePipePressurePSI = BrakeLine1PressurePSI ;
375396 }
376397
@@ -440,6 +461,20 @@ public override void Update(float elapsedClockSeconds)
440461 EmergResPressurePSI -= dp ;
441462 AuxResPressurePSI += dp * EmergAuxVolumeRatio ;
442463 }
464+ if ( EmergencyDumpValveTimerS == 0 )
465+ {
466+ if ( BrakeLine1PressurePSI < 1 ) EmergencyDumpStartTime = null ;
467+ }
468+ else if ( Car . Simulator . GameTime - EmergencyDumpStartTime > EmergencyDumpValveTimerS )
469+ {
470+ EmergencyDumpStartTime = null ;
471+ }
472+ if ( EmergencyDumpValveRatePSIpS > 0 && EmergencyDumpStartTime != null )
473+ {
474+ BrakeLine1PressurePSI -= elapsedClockSeconds * EmergencyDumpValveRatePSIpS ;
475+ if ( BrakeLine1PressurePSI < 0 )
476+ BrakeLine1PressurePSI = 0 ;
477+ }
443478 }
444479 }
445480
0 commit comments