Skip to content

Commit b79f408

Browse files
committed
Max throttle percent allowed by power supply
1 parent b5d21b4 commit b79f408

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected float MaximumDynamicBrakePowerW
103103
set => LpsHost.MaximumDynamicBrakePowerW = value;
104104
}
105105

106+
/// <summary>
106107
/// Dynamic brake percent demanded by power supply
107108
/// </summary>
108109
protected float PowerSupplyDynamicBrakePercent
@@ -113,7 +114,23 @@ protected float PowerSupplyDynamicBrakePercent
113114
}
114115
set
115116
{
116-
LpsHost.PowerSupplyDynamicBrakePercent = value;
117+
if (value < 0) LpsHost.PowerSupplyDynamicBrakePercent = -1;
118+
else LpsHost.PowerSupplyDynamicBrakePercent = Math.Min(value, 100);
119+
}
120+
}
121+
122+
/// <summary>
123+
/// Maximum throttle percent allowed by power supply
124+
/// </summary>
125+
protected float MaxThrottlePercent
126+
{
127+
get
128+
{
129+
return LpsHost.MaxThrottlePercent;
130+
}
131+
set
132+
{
133+
LpsHost.MaxThrottlePercent = Math.Max(Math.Min(value, 100), 0);
117134
}
118135
}
119136

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public interface ILocomotivePowerSupply : IPowerSupply
3434
bool DynamicBrakeAvailable { get; set; }
3535
float PowerSupplyDynamicBrakePercent { get; set; }
3636
float MaximumDynamicBrakePowerW { get; set; }
37+
float MaxThrottlePercent { get; set; }
3738

3839
PowerSupplyState AuxiliaryPowerSupplyState { get; set; }
3940
bool AuxiliaryPowerSupplyOn { get; }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public abstract class ScriptedLocomotivePowerSupply : ILocomotivePowerSupply
4949
public bool DynamicBrakeAvailable { get; set; } = false;
5050
public float PowerSupplyDynamicBrakePercent { get; set; } = -1;
5151
public float MaximumDynamicBrakePowerW { get; set; } = 0;
52+
public float MaxThrottlePercent { get; set; } = 100;
5253

5354
public PowerSupplyState AuxiliaryPowerSupplyState { get; set; } = PowerSupplyState.PowerOff;
5455
public bool AuxiliaryPowerSupplyOn => AuxiliaryPowerSupplyState == PowerSupplyState.PowerOn;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public bool DynamicBrakeAvailable
5656
}
5757
public float PowerSupplyDynamicBrakePercent { get; set; } = -1;
5858
public float MaximumDynamicBrakePowerW { get; set; } = 0;
59+
public float MaxThrottlePercent { get; set; } = 100;
5960

6061
public PowerSupplyState AuxiliaryPowerSupplyState
6162
{

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,31 +431,36 @@ public float ThrottlePercent
431431
{
432432
get
433433
{
434+
float percent;
434435
if (RemoteControlGroup == 0 && Train != null)
435436
{
437+
percent = Train.MUThrottlePercent;
436438
if (Train.LeadLocomotive is MSTSLocomotive locomotive)
437439
{
438440
if (!locomotive.TrainControlSystem.TractionAuthorization
439-
|| Train.MUThrottlePercent <= 0)
441+
|| percent <= 0)
440442
{
441-
return 0;
443+
percent = 0;
442444
}
443-
else if (Train.MUThrottlePercent > locomotive.TrainControlSystem.MaxThrottlePercent)
445+
else if (percent > locomotive.TrainControlSystem.MaxThrottlePercent)
444446
{
445-
return Math.Max(locomotive.TrainControlSystem.MaxThrottlePercent, 0);
447+
percent = Math.Max(locomotive.TrainControlSystem.MaxThrottlePercent, 0);
446448
}
447449
}
448-
449-
return Train.MUThrottlePercent;
450450
}
451451
else if (RemoteControlGroup == 1 && Train != null)
452452
{
453-
return Train.DPThrottlePercent;
453+
percent = Train.DPThrottlePercent;
454454
}
455455
else
456456
{
457-
return LocalThrottlePercent;
457+
percent = LocalThrottlePercent;
458458
}
459+
if (this is MSTSLocomotive loco)
460+
{
461+
if (loco.LocomotivePowerSupply.MaxThrottlePercent < percent) percent = Math.Max(loco.LocomotivePowerSupply.MaxThrottlePercent, 0);
462+
}
463+
return percent;
459464
}
460465
set
461466
{

0 commit comments

Comments
 (0)