Skip to content

Commit aac9b67

Browse files
committed
Split EP special tokens
1 parent 06985f4 commit aac9b67

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4087,7 +4087,8 @@ public override void InitializeBrakes()
40874087
float fullServReductionPSI = -5;
40884088
float max = maxPressurePSI;
40894089
float fullServ = fullServPressurePSI;
4090-
BrakeLine3PressurePSI = BrakeLine4 = 0;
4090+
BrakeLine3PressurePSI = 0;
4091+
BrakeLine4 = -1;
40914092
if (FirstCar != null && FirstCar.BrakeSystem is VacuumSinglePipe)
40924093
{
40934094
max = maxPressurePSIVacuum;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public TrainCar LastCar
134134
// but Class VacuumSinglePipe uses it for vacuum in InHg.
135135
public float BrakeLine2PressurePSI; // extra line for dual line systems, main reservoir
136136
public float BrakeLine3PressurePSI; // extra line just in case, engine brake pressure
137-
public float BrakeLine4 = -1; // extra line just in case, ep brake control line. -1: release/inactive, 0: hold, 0 < value <=1: apply
137+
public float BrakeLine4 = -1; // extra line just in case, ep brake control line. -2: hold, -1: inactive, 0: release, 0 < value <=1: apply
138138
public RetainerSetting RetainerSetting = RetainerSetting.Exhaust;
139139
public int RetainerPercent = 100;
140140
public float TotalTrainBrakePipeVolumeM3; // Total volume of train brake pipe
@@ -4012,6 +4012,8 @@ public void UnconditionalInitializeBrakes()
40124012
fullServPressurePSI = lead.BrakeSystem is VacuumSinglePipe ? 16 : maxPressurePSI - lead.TrainBrakeController.FullServReductionPSI;
40134013
EqualReservoirPressurePSIorInHg = Math.Min(maxPressurePSI, EqualReservoirPressurePSIorInHg);
40144014
lead.TrainBrakeController.UpdatePressure(ref EqualReservoirPressurePSIorInHg, 1000, ref BrakeLine4);
4015+
if (!(lead.BrakeSystem is EPBrakeSystem))
4016+
BrakeLine4 = -1;
40154017
EqualReservoirPressurePSIorInHg =
40164018
MathHelper.Max(EqualReservoirPressurePSIorInHg, fullServPressurePSI);
40174019
}
@@ -4218,7 +4220,11 @@ public void PropagateBrakePressure(float elapsedClockSeconds)
42184220
if (LeadLocomotive is MSTSLocomotive lead)
42194221
{
42204222
if (lead.TrainBrakeController != null)
4223+
{
42214224
lead.TrainBrakeController.UpdatePressure(ref EqualReservoirPressurePSIorInHg, elapsedClockSeconds, ref BrakeLine4);
4225+
if (!(lead.BrakeSystem is EPBrakeSystem))
4226+
BrakeLine4 = -1;
4227+
}
42224228
if (lead.EngineBrakeController != null)
42234229
lead.EngineBrakeController.UpdateEngineBrakePressure(ref BrakeLine3PressurePSI, elapsedClockSeconds);
42244230
lead.BrakeSystem.PropagateBrakePressure(elapsedClockSeconds);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/EPBrakeSystem.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ public EPBrakeSystem(TrainCar car)
3737

3838
public override void Update(float elapsedClockSeconds)
3939
{
40-
MSTSLocomotive lead = (MSTSLocomotive)Car.Train.LeadLocomotive;
41-
float demandedAutoCylPressurePSI = 0;
40+
MSTSLocomotive lead = Car.Train.LeadLocomotive as MSTSLocomotive;
4241

4342
// Only allow EP brake tokens to operate if car is connected to an EP system
44-
if (lead == null || !(lead.BrakeSystem is EPBrakeSystem))
43+
if (lead == null || !(lead.BrakeSystem is EPBrakeSystem) || Car.Train.BrakeLine4 == -1)
4544
{
4645
HoldingValve = ValveState.Release;
4746
base.Update(elapsedClockSeconds);
@@ -50,14 +49,14 @@ public override void Update(float elapsedClockSeconds)
5049

5150
if (EPBrakeControlsBrakePipe)
5251
{
53-
if (Car.Train.BrakeLine4 != 0)
52+
if (Car.Train.BrakeLine4 >= 0)
5453
{
5554
float targetPressurePSI = 0;
56-
if (Car.Train.BrakeLine4 < 0)
55+
if (Car.Train.BrakeLine4 == 0)
5756
{
5857
targetPressurePSI = lead.TrainBrakeController.MaxPressurePSI;
5958
}
60-
else
59+
else if (Car.Train.BrakeLine4 > 0)
6160
{
6261
float x = Math.Min(Car.Train.BrakeLine4, 1);
6362
targetPressurePSI = lead.TrainBrakeController.MaxPressurePSI - lead.TrainBrakeController.MinReductionPSI * (1 - x) - lead.TrainBrakeController.FullServReductionPSI * x;
@@ -83,24 +82,27 @@ public override void Update(float elapsedClockSeconds)
8382
}
8483
else
8584
{
86-
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
85+
float demandedAutoCylPressurePSI = 0;
86+
if (BrakeLine3PressurePSI >= 1000f)
8787
{
8888
HoldingValve = ValveState.Release;
8989
}
90-
else if (Car.Train.BrakeLine4 == 0)
90+
else if (Car.Train.BrakeLine4 == -2) // Holding wire on
9191
{
9292
HoldingValve = ValveState.Lap;
9393
}
94+
else if (Car.Train.BrakeLine4 == 0)
95+
{
96+
HoldingValve = ValveState.Release;
97+
}
9498
else
9599
{
96100
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
97101
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
98102
}
99103

100-
101104
base.Update(elapsedClockSeconds); // Allow processing of other valid tokens
102105

103-
104106
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
105107
{
106108
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/SMEBrakeSystem.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public override void Update(float elapsedClockSeconds)
4141
float demandedAutoCylPressurePSI = 0;
4242

4343
// Only allow SME brake tokens to operate if car is connected to an SME system
44-
if (lead == null || !(lead.BrakeSystem is SMEBrakeSystem))
44+
if (lead == null || !(lead.BrakeSystem is SMEBrakeSystem) || Car.Train.BrakeLine4 < 0)
4545
{
4646
HoldingValve = ValveState.Release;
4747
base.Update(elapsedClockSeconds);
@@ -50,21 +50,17 @@ public override void Update(float elapsedClockSeconds)
5050

5151
// process valid SME brake tokens
5252

53-
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
53+
if (BrakeLine3PressurePSI >= 1000f)
5454
{
5555
HoldingValve = ValveState.Release;
5656
}
57-
else if (Car.Train.BrakeLine4 == 0)
58-
{
59-
HoldingValve = ValveState.Lap;
60-
}
6157
else
6258
{
6359
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
6460
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
6561
}
6662

67-
base.Update(elapsedClockSeconds); // Allow processing of other valid tokens
63+
base.Update(elapsedClockSeconds); // Allow processing of other valid tokens
6864

6965

7066
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/MSTSBrakeController.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public override float Update(float elapsedSeconds)
7676
// Train Brake Controllers
7777
public override void UpdatePressure(ref float pressureBar, float elapsedClockSeconds, ref float epControllerState)
7878
{
79-
float epState = 0;
79+
float epState = -2; // EP Holding wire on. For tokens that do not operate EP brakes
8080

8181
if (EmergencyBrakingPushButton() || TCSEmergencyBraking())
8282
{
@@ -104,7 +104,6 @@ public override void UpdatePressure(ref float pressureBar, float elapsedClockSec
104104
{
105105
pressureBar = MaxPressureBar() - FullServReductionBar() * CurrentValue();
106106
epState = CurrentValue();
107-
if (epState == 0) epState = -1;
108107
}
109108
else
110109
{
@@ -131,17 +130,17 @@ public override void UpdatePressure(ref float pressureBar, float elapsedClockSec
131130
case ControllerState.Release:
132131
IncreasePressure(ref pressureBar, Math.Min(MaxPressureBar(), MainReservoirPressureBar()), ReleaseRateBarpS(), elapsedClockSeconds);
133132
DecreasePressure(ref pressureBar, MaxPressureBar(), OverchargeEliminationRateBarpS(), elapsedClockSeconds);
134-
epState = -1;
133+
epState = 0;
135134
break;
136135
case ControllerState.FullQuickRelease:
137136
case ControllerState.SMEReleaseStart:
138137
IncreasePressure(ref pressureBar, Math.Min(MaxPressureBar(), MainReservoirPressureBar()), QuickReleaseRateBarpS(), elapsedClockSeconds);
139138
DecreasePressure(ref pressureBar, MaxPressureBar(), OverchargeEliminationRateBarpS(), elapsedClockSeconds);
140-
epState = -1;
139+
epState = 0;
141140
break;
142141
case ControllerState.Overcharge:
143142
IncreasePressure(ref pressureBar, Math.Min(MaxOverchargePressureBar(), MainReservoirPressureBar()), QuickReleaseRateBarpS(), elapsedClockSeconds);
144-
epState = -1;
143+
epState = 0;
145144
break;
146145
case ControllerState.SlowService:
147146
DecreasePressure(ref pressureBar, MaxPressureBar() - FullServReductionBar(), SlowApplicationRateBarpS(), elapsedClockSeconds);

0 commit comments

Comments
 (0)