Skip to content

Commit 71283ab

Browse files
committed
Dynamic brake authorization by TCS
1 parent a5be129 commit 71283ab

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

Source/Orts.Simulation/Common/Scripting/TrainControlSystem.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ internal void AttachToHost(ScriptedTrainControlSystem host)
249249
/// </summary>
250250
public Func<bool> TractionAuthorization;
251251
/// <summary>
252+
/// True if dynamic braking is authorized.
253+
/// </summary>
254+
public Func<bool> DynamicBrakingAuthorization;
255+
/// <summary>
252256
/// Train brake pipe pressure. Returns float.MaxValue if no data is available.
253257
/// </summary>
254258
public Func<float> BrakePipePressureBar;
@@ -387,6 +391,10 @@ internal void AttachToHost(ScriptedTrainControlSystem host)
387391
/// </summary>
388392
public Action<bool> SetTractionAuthorization;
389393
/// <summary>
394+
/// Set the dynamic braking authorization.
395+
/// </summary>
396+
public Action<bool> SetDynamicBrakingAuthorization;
397+
/// <summary>
390398
/// Set the maximum throttle percent
391399
/// Range: 0 to 100
392400
/// </summary>

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,7 @@ protected virtual void UpdateDynamicBrakeForce(float elapsedClockSeconds)
26772677
DynamicBrake = false;
26782678
DynamicBrakeCommandStartTime = null;
26792679
}
2680-
float maxdynamic = DynamicBrake ? 1 : 0;
2680+
float maxdynamic = DynamicBrake ? MaxDynamicBrakePercent / 100 : 0;
26812681
float d = DynamicBrakePercent / 100;
26822682
bool dynamicLimited = d > maxdynamic;
26832683
if (dynamicLimited) d = maxdynamic;

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/TrainControlSystem.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ protected set
150150
public bool CircuitBreakerClosingOrder { get; private set; }
151151
public bool CircuitBreakerOpeningOrder { get; private set; }
152152
public bool TractionAuthorization { get; private set; }
153+
public bool DynamicBrakingAuthorization { get; private set; }
153154
public float MaxThrottlePercent { get; private set; } = 100f;
154155
public bool FullDynamicBrakingOrder { get; private set; }
155156

@@ -187,6 +188,7 @@ public ScriptedTrainControlSystem(MSTSLocomotive locomotive)
187188
CircuitBreakerClosingOrder = false;
188189
CircuitBreakerOpeningOrder = false;
189190
TractionAuthorization = true;
191+
DynamicBrakingAuthorization = true;
190192
FullDynamicBrakingOrder = false;
191193
}
192194

@@ -363,6 +365,7 @@ public void Initialize()
363365
Script.MaxThrottlePercent = () => MaxThrottlePercent;
364366
Script.DynamicBrakePercent = () => Locomotive.DynamicBrakeController == null ? 0 : Locomotive.DynamicBrakeController.CurrentValue * 100;
365367
Script.TractionAuthorization = () => TractionAuthorization;
368+
Script.DynamicBrakingAuthorization = () => DynamicBrakingAuthorization;
366369
Script.BrakePipePressureBar = () => Locomotive.BrakeSystem != null ? Bar.FromPSI(Locomotive.BrakeSystem.BrakeLine1PressurePSI) : float.MaxValue;
367370
Script.LocomotiveBrakeCylinderPressureBar = () => Locomotive.BrakeSystem != null ? Bar.FromPSI(Locomotive.BrakeSystem.GetCylPressurePSI()) : float.MaxValue;
368371
Script.DoesBrakeCutPower = () => Locomotive.DoesBrakeCutPower;
@@ -457,6 +460,7 @@ public void Initialize()
457460
Script.SetCircuitBreakerClosingOrder = (value) => CircuitBreakerClosingOrder = value;
458461
Script.SetCircuitBreakerOpeningOrder = (value) => CircuitBreakerOpeningOrder = value;
459462
Script.SetTractionAuthorization = (value) => TractionAuthorization = value;
463+
Script.SetDynamicBrakingAuthorization = (value) => DynamicBrakingAuthorization = value;
460464
Script.SetMaxThrottlePercent = (value) =>
461465
{
462466
if (value >= 0 && value <= 100f)

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,21 @@ public int GearboxGearIndex
500500
}
501501

502502
public float LocalDynamicBrakePercent = -1;
503+
public float MaxDynamicBrakePercent
504+
{
505+
get
506+
{
507+
float percent = 100;
508+
if (RemoteControlGroup == 0 && Train != null && Train.LeadLocomotive is MSTSLocomotive locomotive)
509+
{
510+
if (!locomotive.TrainControlSystem.DynamicBrakingAuthorization)
511+
{
512+
percent = 0;
513+
}
514+
}
515+
return percent;
516+
}
517+
}
503518
public float DynamicBrakePercent
504519
{
505520
get

0 commit comments

Comments
 (0)