1919using System . Collections . Generic ;
2020using ORTS . Common ;
2121using Orts . Parsers . Msts ;
22- using ORTS . Scripting . Api ;
2322
2423namespace Orts . Simulation . RollingStocks . SubSystems . Brakes . MSTS
2524{
2625
27- public class EPBrakeSystem : AirTwinPipe
26+ public class EPBrakeSystem : AirSinglePipe
2827 {
2928 bool EPBrakeControlsBrakePipe ;
3029 bool EPBrakeActiveInhibitsTripleValve ;
3130
32- public EPBrakeSystem ( TrainCar car )
31+ public EPBrakeSystem ( TrainCar car , bool twoPipes = true )
3332 : base ( car )
3433 {
3534 DebugType = "EP" ;
35+ TwoPipes = twoPipes ;
36+ MRPAuxResCharging = TwoPipes ;
3637 }
3738
3839
@@ -69,17 +70,45 @@ public override void Update(float elapsedClockSeconds)
6970 dp = BrakeLine1PressurePSI - targetPressurePSI ;
7071 BrakeLine1PressurePSI -= dp ;
7172 }
72- else if ( targetPressurePSI > BrakeLine1PressurePSI + 1 && BrakeLine2PressurePSI > targetPressurePSI && Car . Train . BrakeLine4 < 1 )
73+ else if ( targetPressurePSI > BrakeLine1PressurePSI + 1 && Car . Train . BrakeLine4 < 1 )
7374 {
7475 float dp = elapsedClockSeconds * MaxReleaseRatePSIpS / AuxCylVolumeRatio ;
7576 if ( dp > targetPressurePSI - BrakeLine1PressurePSI )
7677 dp = targetPressurePSI - BrakeLine1PressurePSI ;
77- BrakeLine1PressurePSI += dp ;
78- BrakeLine2PressurePSI -= dp ;
78+ if ( SupplyReservoirPresent )
79+ {
80+ float ratio = BrakePipeVolumeM3 / SupplyResVolumeM3 ;
81+ if ( BrakeLine1PressurePSI + dp > SupplyResPressurePSI - dp * ratio )
82+ dp = ( SupplyResPressurePSI - BrakeLine1PressurePSI ) / ( 1 + ratio ) ;
83+ if ( dp < 0 )
84+ dp = 0 ;
85+ SupplyResPressurePSI -= dp * ratio ;
86+ BrakeLine1PressurePSI += dp ;
87+ }
88+ else if ( BrakeValve == BrakeValveType . Distributor && TwoPipes && MRPAuxResCharging )
89+ {
90+ float ratio = 1 / AuxBrakeLineVolumeRatio ;
91+ if ( BrakeLine1PressurePSI + dp > AuxResPressurePSI - dp * ratio )
92+ dp = ( AuxResPressurePSI - BrakeLine1PressurePSI ) / ( 1 + ratio ) ;
93+ if ( dp < 0 )
94+ dp = 0 ;
95+ AuxResPressurePSI -= dp * ratio ;
96+ BrakeLine1PressurePSI += dp ;
97+ }
98+ else if ( TwoPipes )
99+ {
100+ if ( BrakeLine1PressurePSI + dp > BrakeLine2PressurePSI - dp )
101+ dp = ( BrakeLine2PressurePSI - BrakeLine1PressurePSI ) / 2 ;
102+ if ( dp < 0 )
103+ dp = 0 ;
104+ BrakeLine2PressurePSI -= dp ;
105+ BrakeLine1PressurePSI += dp ;
106+ }
79107 }
80108 }
81109 base . Update ( elapsedClockSeconds ) ;
82110 HoldingValve = ValveState . Release ;
111+ IsolationValve = ValveState . Release ;
83112 }
84113 else
85114 {
@@ -114,12 +143,40 @@ public override void Update(float elapsedClockSeconds)
114143 if ( AutoCylPressurePSI < demandedAutoCylPressurePSI && ! Car . WheelBrakeSlideProtectionActive )
115144 {
116145 float dp = elapsedClockSeconds * ServiceApplicationRatePSIpS ;
117- if ( BrakeLine2PressurePSI - ( dp * CylBrakeLineVolumeRatio ) < AutoCylPressurePSI + dp )
118- dp = ( BrakeLine2PressurePSI - AutoCylPressurePSI ) / ( 1 + CylBrakeLineVolumeRatio ) ;
119146 if ( dp > demandedAutoCylPressurePSI - AutoCylPressurePSI )
120147 dp = demandedAutoCylPressurePSI - AutoCylPressurePSI ;
121- BrakeLine2PressurePSI -= dp * CylBrakeLineVolumeRatio ;
122- AutoCylPressurePSI += dp ;
148+ if ( SupplyReservoirPresent )
149+ {
150+ float displacementSupplyVolumeRatio = AuxResVolumeM3 / AuxCylVolumeRatio / SupplyResVolumeM3 ;
151+
152+ if ( AutoCylPressurePSI + dp > SupplyResPressurePSI - ( dp * displacementSupplyVolumeRatio ) )
153+ dp = ( SupplyResPressurePSI - AutoCylPressurePSI ) / ( 1 + displacementSupplyVolumeRatio ) ;
154+ if ( dp < 0 )
155+ dp = 0 ;
156+
157+ SupplyResPressurePSI -= dp * displacementSupplyVolumeRatio ;
158+ AutoCylPressurePSI += dp ;
159+ }
160+ else if ( TwoPipes && ! MRPAuxResCharging )
161+ {
162+ if ( BrakeLine2PressurePSI - ( dp * CylBrakeLineVolumeRatio ) < AutoCylPressurePSI + dp )
163+ dp = ( BrakeLine2PressurePSI - AutoCylPressurePSI ) / ( 1 + CylBrakeLineVolumeRatio ) ;
164+ if ( dp < 0 )
165+ dp = 0 ;
166+
167+ BrakeLine2PressurePSI -= dp * CylBrakeLineVolumeRatio ;
168+ AutoCylPressurePSI += dp ;
169+ }
170+ else
171+ {
172+ if ( AuxResPressurePSI - dp / AuxCylVolumeRatio < AutoCylPressurePSI + dp )
173+ dp = ( AuxResPressurePSI - AutoCylPressurePSI ) * AuxCylVolumeRatio / ( 1 + AuxCylVolumeRatio ) ;
174+ if ( dp < 0 )
175+ dp = 0 ;
176+
177+ AuxResPressurePSI -= dp / AuxCylVolumeRatio ;
178+ AutoCylPressurePSI += dp ;
179+ }
123180 }
124181 else if ( EPBrakeActiveInhibitsTripleValve && AutoCylPressurePSI > demandedAutoCylPressurePSI )
125182 {
@@ -129,7 +186,6 @@ public override void Update(float elapsedClockSeconds)
129186 AutoCylPressurePSI -= dp ;
130187 }
131188 }
132-
133189 }
134190
135191 public override void Parse ( string lowercasetoken , STFReader stf )
@@ -158,7 +214,9 @@ public override void InitializeFromCopy(BrakeSystem copy)
158214
159215 public override string GetFullStatus ( BrakeSystem lastCarBrakeSystem , Dictionary < BrakeSystemComponent , PressureUnit > units )
160216 {
161- var s = $ " { Simulator . Catalog . GetString ( "BC" ) } { FormatStrings . FormatPressure ( Car . Train . HUDWagonBrakeCylinderPSI , PressureUnit . PSI , units [ BrakeSystemComponent . BrakeCylinder ] , true ) } ";
217+ string s = "" ;
218+ if ( EPBrakeControlsBrakePipe ) s += $ " { Simulator . Catalog . GetString ( "EQ" ) } { FormatStrings . FormatPressure ( Car . Train . EqualReservoirPressurePSIorInHg , PressureUnit . PSI , units [ BrakeSystemComponent . EqualizingReservoir ] , true ) } ";
219+ s += $ " { Simulator . Catalog . GetString ( "BC" ) } { FormatStrings . FormatPressure ( Car . Train . HUDWagonBrakeCylinderPSI , PressureUnit . PSI , units [ BrakeSystemComponent . BrakeCylinder ] , true ) } ";
162220 if ( HandbrakePercent > 0 )
163221 s += $ " { Simulator . Catalog . GetString ( "Handbrake" ) } { HandbrakePercent : F0} %";
164222 return s ;
@@ -167,7 +225,7 @@ public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<
167225 public override void Initialize ( bool handbrakeOn , float maxPressurePSI , float fullServPressurePSI , bool immediateRelease )
168226 {
169227 base . Initialize ( handbrakeOn , maxPressurePSI , fullServPressurePSI , immediateRelease ) ;
170- AutoCylPressurePSI = Math . Max ( AutoCylPressurePSI , Math . Min ( Math . Max ( Car . Train . BrakeLine4 , 0 ) , 1 ) * MaxCylPressurePSI ) ;
228+ if ( ! EPBrakeControlsBrakePipe ) AutoCylPressurePSI = Math . Max ( AutoCylPressurePSI , Math . Min ( Math . Max ( Car . Train . BrakeLine4 , 0 ) , 1 ) * ServiceMaxCylPressurePSI ) ;
171229 CylPressurePSI = ForceBrakeCylinderPressure ( ref CylAirPSIM3 , AutoCylPressurePSI ) ;
172230 }
173231 }
0 commit comments