Skip to content

Commit 6559a09

Browse files
committed
Add information about available power
1 parent 00a89a0 commit 6559a09

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public DieselEngineState CurrentDieselEngineState(int id)
5050
return DieselEngineState.Unavailable;
5151
}
5252
}
53+
protected float DieselEngineOutputPowerW => DieselEngines.MaxOutputPowerW;
5354

5455
public float DieselEngineMinRpmForElectricTrainSupply => DpsHost.DieselEngineMinRpmForElectricTrainSupply;
5556

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ protected float MaximumPowerW
9898
set => LpsHost.MaximumPowerW = value;
9999
}
100100

101+
/// <summary>
102+
/// Power limit for traction motors
103+
/// </summary>
104+
protected float AvailableTractionPowerW
105+
{
106+
get => LpsHost.AvailableTractionPowerW;
107+
set => LpsHost.AvailableTractionPowerW = value;
108+
}
109+
101110
/// <summary>
102111
/// Current availability of the dynamic brake
103112
/// </summary>

Source/Orts.Simulation/Simulation/RollingStocks/MSTSDieselLocomotive.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,13 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
683683
}
684684
}
685685

686+
float supplyPowerLimitW = float.MaxValue;
687+
if (!DieselEngines.HasGearBox)
688+
{
689+
supplyPowerLimitW = DieselPowerSupply.AvailableTractionPowerW;
690+
if (DieselPowerSupply.MaximumPowerW > 0)
691+
supplyPowerLimitW = Math.Min(supplyPowerLimitW, DieselPowerSupply.MaximumPowerW * t);
692+
}
686693
if (TractiveForceCurves == null)
687694
{
688695
if (DieselEngines.HasGearBox)
@@ -697,8 +704,7 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
697704
// Maximum rail power is reduced by apparent throttle factor and the number of engines running (power ratio)
698705
float maxPowerW = LocomotiveMaxRailOutputPowerW * DieselEngineFractionPower * LocomotiveApparentThrottleSetting;
699706

700-
if (DieselPowerSupply.MaximumPowerW > 0)
701-
maxPowerW = Math.Min(maxPowerW, DieselPowerSupply.MaximumPowerW * LocomotiveApparentThrottleSetting);
707+
maxPowerW = Math.Min(maxPowerW, supplyPowerLimitW);
702708

703709
// If unloading speed is in ENG file, and locomotive speed is greater then unloading speed, and less then max speed, then apply a decay factor to the power/force
704710
if (UnloadingSpeedMpS != 0 && AbsTractionSpeedMpS > UnloadingSpeedMpS && AbsTractionSpeedMpS < MaxSpeedMpS && !WheelSlip)
@@ -726,13 +732,9 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
726732
else
727733
{
728734
// Tractive force is read from Table using the apparent throttle setting, and then reduced by the number of engines running (power ratio)
729-
TractiveForceN = TractiveForceCurves.Get(LocomotiveApparentThrottleSetting, AbsTractionSpeedMpS) * DieselEngineFractionPower * (1 - PowerReduction);
730-
if (DieselPowerSupply.MaximumPowerW > 0)
731-
{
732-
float maxPowerW = DieselPowerSupply.MaximumPowerW * t;
733-
if (TractiveForceN * AbsTractionSpeedMpS > maxPowerW)
734-
TractiveForceN = maxPowerW / AbsTractionSpeedMpS;
735-
}
735+
TractiveForceN = TractiveForceCurves.Get(LocomotiveApparentThrottleSetting, AbsTractionSpeedMpS) * DieselEngineFractionPower * (1 - PowerReduction);
736+
if (TractiveForceN * AbsTractionSpeedMpS > supplyPowerLimitW)
737+
TractiveForceN = supplyPowerLimitW / AbsTractionSpeedMpS;
736738
}
737739

738740
if (TractiveForceN < 0 && !TractiveForceCurves.AcceptsNegativeValues())

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,14 +2508,21 @@ protected virtual void UpdateTractiveForce(float elapsedClockSeconds, float t, f
25082508
AbsTractionSpeedMpS = AbsSpeedMpS;
25092509
}
25102510
}
2511+
2512+
float supplyPowerLimitW = float.MaxValue;
2513+
if (this is MSTSElectricLocomotive electric)
2514+
{
2515+
supplyPowerLimitW = electric.ElectricPowerSupply.AvailableTractionPowerW;
2516+
if (electric.ElectricPowerSupply.MaximumPowerW > 0)
2517+
supplyPowerLimitW = Math.Min(supplyPowerLimitW, electric.ElectricPowerSupply.MaximumPowerW * t);
2518+
}
25112519

25122520
if (TractiveForceCurves == null)
25132521
{
25142522
float maxForceN = MaxForceN * t * (1 - PowerReduction);
25152523
float maxPowerW = MaxPowerW;
25162524
maxPowerW *= t * t * (1 - PowerReduction);
2517-
if (this is MSTSElectricLocomotive electric && electric.ElectricPowerSupply.MaximumPowerW > 0)
2518-
maxPowerW = Math.Min(maxPowerW, electric.ElectricPowerSupply.MaximumPowerW * t);
2525+
maxPowerW = Math.Min(maxPowerW, supplyPowerLimitW);
25192526

25202527
if (maxForceN * AbsTractionSpeedMpS > maxPowerW)
25212528
maxForceN = maxPowerW / AbsTractionSpeedMpS;
@@ -2530,12 +2537,8 @@ protected virtual void UpdateTractiveForce(float elapsedClockSeconds, float t, f
25302537
else
25312538
{
25322539
TractiveForceN = TractiveForceCurves.Get(t, AbsTractionSpeedMpS) * (1 - PowerReduction);
2533-
if (this is MSTSElectricLocomotive electric && electric.ElectricPowerSupply.MaximumPowerW > 0)
2534-
{
2535-
float maxPowerW = electric.ElectricPowerSupply.MaximumPowerW * t;
2536-
if (TractiveForceN * AbsTractionSpeedMpS > maxPowerW)
2537-
TractiveForceN = maxPowerW / AbsTractionSpeedMpS;
2538-
}
2540+
if (TractiveForceN * AbsTractionSpeedMpS > supplyPowerLimitW)
2541+
TractiveForceN = supplyPowerLimitW / AbsTractionSpeedMpS;
25392542
if (TractiveForceN < 0 && !TractiveForceCurves.AcceptsNegativeValues())
25402543
TractiveForceN = 0;
25412544
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public abstract class ScriptedLocomotivePowerSupply : ILocomotivePowerSupply
4747
public PowerSupplyState MainPowerSupplyState { get; set; } = PowerSupplyState.PowerOff;
4848
public bool MainPowerSupplyOn => MainPowerSupplyState == PowerSupplyState.PowerOn;
4949
public float MaximumPowerW;
50+
public float AvailableTractionPowerW = float.MaxValue;
5051
public bool DynamicBrakeAvailable { get; set; } = false;
5152
public float PowerSupplyDynamicBrakePercent { get; set; } = -1;
5253
public float MaximumDynamicBrakePowerW { get; set; } = 0;

0 commit comments

Comments
 (0)