Skip to content

Commit 0748070

Browse files
authored
Merge pull request #454 from Sharpe49/power-supply-fix-nan-values
Fix NaN values for diesel output power and load during engine shut-down https://bugs.launchpad.net/or/+bug/1940164
2 parents 22a5780 + bb25fcb commit 0748070

File tree

1 file changed

+6
-3
lines changed
  • Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public float LoadPercent
801801
{
802802
get
803803
{
804-
return (CurrentDieselOutputPowerW <= 0f ? 0f : ((OutputPowerW + Locomotive.LocomotivePowerSupply.ElectricTrainSupplyPowerW / Locomotive.DieselEngines.NumOfActiveEngines) * 100f / CurrentDieselOutputPowerW)) ;
804+
return CurrentDieselOutputPowerW <= 0f ? 0f : ((OutputPowerW + (Locomotive.DieselEngines.NumOfActiveEngines > 0 ? Locomotive.LocomotivePowerSupply.ElectricTrainSupplyPowerW / Locomotive.DieselEngines.NumOfActiveEngines : 0f)) * 100f / CurrentDieselOutputPowerW);
805805
}
806806
}
807807
/// <summary>
@@ -1034,8 +1034,11 @@ public void Update(float elapsedClockSeconds)
10341034
CurrentDieselOutputPowerW = (RealRPM - IdleRPM) / (MaxRPM - IdleRPM) * MaximumDieselPowerW * (1 - Locomotive.PowerReduction);
10351035
}
10361036

1037-
CurrentDieselOutputPowerW -= Locomotive.DieselPowerSupply.ElectricTrainSupplyPowerW / Locomotive.DieselEngines.NumOfActiveEngines;
1038-
CurrentDieselOutputPowerW = CurrentDieselOutputPowerW < 0f ? 0f : CurrentDieselOutputPowerW;
1037+
if (Locomotive.DieselEngines.NumOfActiveEngines > 0)
1038+
{
1039+
CurrentDieselOutputPowerW -= Locomotive.DieselPowerSupply.ElectricTrainSupplyPowerW / Locomotive.DieselEngines.NumOfActiveEngines;
1040+
CurrentDieselOutputPowerW = CurrentDieselOutputPowerW < 0f ? 0f : CurrentDieselOutputPowerW;
1041+
}
10391042

10401043
if (State == DieselEngineState.Starting)
10411044
{

0 commit comments

Comments
 (0)