Skip to content

Commit f1405fb

Browse files
committed
Dynamic brake availability is now managed by power supply scripts
(related to https://bugs.launchpad.net/or/+bug/1620802)
1 parent b3f26c8 commit f1405fb

File tree

7 files changed

+20
-1
lines changed

7 files changed

+20
-1
lines changed

Source/Orts.Simulation/Common/Scripting/PowerSupply/LocomotivePowerSupply.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public abstract class LocomotivePowerSupply : PowerSupply
3636
/// </summary>
3737
public Func<PowerSupplyState> CurrentCabPowerSupplyState;
3838
/// <summary>
39+
/// Current availability of the dynamic brake
40+
/// </summary>
41+
public Func<bool> CurrentDynamicBrakeAvailability;
42+
/// <summary>
3943
/// Main supply power on delay
4044
/// </summary>
4145
public Func<float> PowerOnDelayS;
@@ -76,6 +80,10 @@ public abstract class LocomotivePowerSupply : PowerSupply
7680
/// </summary>
7781
public Action<PowerSupplyState> SetCurrentElectricTrainSupplyState;
7882
/// <summary>
83+
/// Sets the current availability of the dynamic brake
84+
/// </summary>
85+
public Action<bool> SetCurrentDynamicBrakeAvailability;
86+
/// <summary>
7987
/// Sends an event to the master switch
8088
/// </summary>
8189
public Action<PowerSupplyEvent> SignalEventToMasterKey;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ public override void Update(float elapsedClockSeconds)
16281628
if (DynamicBrakePercent > 0 && DynamicBrakeForceCurves != null && AbsSpeedMpS > 0)
16291629
{
16301630
float f = DynamicBrakeForceCurves.Get(.01f * DynamicBrakePercent, AbsTractionSpeedMpS);
1631-
if (f > 0 && LocomotivePowerSupply.MainPowerSupplyOn)
1631+
if (f > 0 && LocomotivePowerSupply.DynamicBrakeAvailable)
16321632
{
16331633
DynamicBrakeForceN = f * (1 - PowerReduction);
16341634
MotiveForceN -= (SpeedMpS > 0 ? 1 : SpeedMpS < 0 ? -1 : Direction == Direction.Reverse ? -1 : 1) * DynamicBrakeForceN;

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/DieselPowerSupply.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ public override void Update(float elapsedClockSeconds)
247247
break;
248248
}
249249

250+
// By default, on diesel locomotives, dynamic brake is available only if main power is available.
251+
SetCurrentDynamicBrakeAvailability(CurrentMainPowerSupplyState() == PowerSupplyState.PowerOn);
252+
250253
if (ElectricTrainSupplyUnfitted())
251254
{
252255
SetCurrentElectricTrainSupplyState(PowerSupplyState.Unavailable);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/ElectricPowerSupply.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ public override void Update(float elapsedClockSeconds)
244244
break;
245245
}
246246

247+
// By default, on electric locomotives, dynamic brake is always available (rheostatic brake is always available).
248+
SetCurrentDynamicBrakeAvailability(true);
249+
247250
if (ElectricTrainSupplyUnfitted())
248251
{
249252
SetCurrentElectricTrainSupplyState(PowerSupplyState.Unavailable);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/ILocomotivePowerSupply.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public interface ILocomotivePowerSupply : IPowerSupply
2828

2929
PowerSupplyState MainPowerSupplyState { get; }
3030
bool MainPowerSupplyOn { get; }
31+
bool DynamicBrakeAvailable { get; }
3132

3233
PowerSupplyState AuxiliaryPowerSupplyState { get; }
3334
bool AuxiliaryPowerSupplyOn { get; }

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/LocomotivePowerSupply.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public abstract class ScriptedLocomotivePowerSupply : ILocomotivePowerSupply, IS
4242

4343
public PowerSupplyState MainPowerSupplyState { get; protected set; } = PowerSupplyState.PowerOff;
4444
public bool MainPowerSupplyOn => MainPowerSupplyState == PowerSupplyState.PowerOn;
45+
public bool DynamicBrakeAvailable { get; protected set; } = false;
4546

4647
public PowerSupplyState AuxiliaryPowerSupplyState { get; protected set; } = PowerSupplyState.PowerOff;
4748
public bool AuxiliaryPowerSupplyOn => AuxiliaryPowerSupplyState == PowerSupplyState.PowerOn;
@@ -277,6 +278,7 @@ protected virtual void AssignScriptFunctions()
277278
AbstractScript.CurrentLowVoltagePowerSupplyState = () => LowVoltagePowerSupplyState;
278279
AbstractScript.CurrentBatteryState = () => BatteryState;
279280
AbstractScript.CurrentCabPowerSupplyState = () => CabPowerSupplyState;
281+
AbstractScript.CurrentDynamicBrakeAvailability = () => DynamicBrakeAvailable;
280282
AbstractScript.PowerOnDelayS = () => PowerOnDelayS;
281283
AbstractScript.AuxPowerOnDelayS = () => AuxPowerOnDelayS;
282284
AbstractScript.BatterySwitchOn = () => BatterySwitch.On;
@@ -291,6 +293,7 @@ protected virtual void AssignScriptFunctions()
291293
AbstractScript.SetCurrentLowVoltagePowerSupplyState = (value) => LowVoltagePowerSupplyState = value;
292294
AbstractScript.SetCurrentBatteryState = (value) => BatteryState = value;
293295
AbstractScript.SetCurrentCabPowerSupplyState = (value) => CabPowerSupplyState = value;
296+
AbstractScript.SetCurrentDynamicBrakeAvailability = (value) => DynamicBrakeAvailable = value;
294297
AbstractScript.SignalEventToBatterySwitch = (evt) => BatterySwitch.HandleEvent(evt);
295298
AbstractScript.SignalEventToMasterKey = (evt) => MasterKey.HandleEvent(evt);
296299
AbstractScript.SignalEventToElectricTrainSupplySwitch = (evt) => ElectricTrainSupplySwitch.HandleEvent(evt);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/SteamPowerSupply.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class SteamPowerSupply : ILocomotivePowerSupply, ISubSystem<SteamPowerSup
2020

2121
public PowerSupplyState MainPowerSupplyState => PowerSupplyState.PowerOn;
2222
public bool MainPowerSupplyOn => true;
23+
public bool DynamicBrakeAvailable => false;
2324

2425
public PowerSupplyState AuxiliaryPowerSupplyState => PowerSupplyState.PowerOn;
2526
public bool AuxiliaryPowerSupplyOn => true;

0 commit comments

Comments
 (0)