Skip to content

Commit 520ac64

Browse files
committed
Allow discrete speeds even when using throttle as speed selector
1 parent ac323a2 commit 520ac64

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public CruiseControl(CruiseControl other, MSTSLocomotive locomotive)
252252
SpeedRegulatorOptions = other.SpeedRegulatorOptions;
253253
CruiseControlLogic = other.CruiseControlLogic;
254254
SpeedDeltaFunctionMode = other.SpeedDeltaFunctionMode;
255-
SpeedRegulatorNominalSpeedStepMpS = other.SpeedRegulatorNominalSpeedStepMpS;
255+
SelectedSpeedPrecisionMpS = other.SelectedSpeedPrecisionMpS;
256256
MaxAccelerationMpSS = other.MaxAccelerationMpSS;
257257
MaxDecelerationMpSS = other.MaxDecelerationMpSS;
258258
StartReducingSpeedDelta = other.StartReducingSpeedDelta;
@@ -1541,7 +1541,12 @@ protected float ControllerValueToSelectedSpeedMpS(float val)
15411541
return 0;
15421542
float min = MinimumSpeedForCCEffectMpS;
15431543
float max = Locomotive.MaxSpeedMpS;
1544-
return val * (max - min) + min;
1544+
float speed = val * (max - min) + min;
1545+
if (SpeedSelectorIsDiscrete && SpeedRegulatorNominalSpeedStepMpS > 0)
1546+
{
1547+
speed = (int)(speed / SpeedRegulatorNominalSpeedStepMpS) * SpeedRegulatorNominalSpeedStepMpS;
1548+
}
1549+
return speed;
15451550
}
15461551

15471552
public string GetCruiseControlStatus()

0 commit comments

Comments
 (0)