diff --git a/src/Devices/AtcDimetronic.cs b/src/Devices/AtcDimetronic.cs
index f5490a2..32428b9 100644
--- a/src/Devices/AtcDimetronic.cs
+++ b/src/Devices/AtcDimetronic.cs
@@ -83,6 +83,12 @@ namespace OpenbveFcmbTrainPlugin
/// Whether ATO is available or not on the train.
private readonly bool AtoAvailable;
+ /// The delay before ATO changes notches.
+ private readonly double AtoNotchDelay = 500;
+
+ /// The counter for the ATO notch delay.
+ private double AtoNotchDelayCounter;
+
/// The current position of the train.
private double TrainLocation;
@@ -383,7 +389,7 @@ namespace OpenbveFcmbTrainPlugin
train.ContinuousProtection = true;
train.VigilanceOverride = true;
CurrentSpeedCode = GetSpeedCodeFromAspect();
- ProcessAto(train, route);
+ ProcessAto(train, route, elapsedTime);
// If reverser is not forward or emergency brake is applied, unselect mode
if (train.PhysicalHandles.Reverser != 1 || train.PhysicalHandles.BrakeNotch > train.Specs.BrakeNotches)
{
@@ -691,7 +697,7 @@ namespace OpenbveFcmbTrainPlugin
}
/// Processes ATO orders.
- private void ProcessAto(Train train, Route route)
+ private void ProcessAto(Train train, Route route, Time elapsedTime)
{
double speed = train.State.Speed.KilometersPerHour;
bool stopped = speed < 0.05;
@@ -700,6 +706,9 @@ namespace OpenbveFcmbTrainPlugin
Speed target = CurrentSpeedCode.TargetLimit;
double distance = CurrentSpeedCode.TargetPosition - TrainLocation;
+ // Update notch delay counter
+ AtoNotchDelayCounter += elapsedTime.Milliseconds;
+
// Calculate notches according to state
switch (AtoState)
{
@@ -724,10 +733,29 @@ namespace OpenbveFcmbTrainPlugin
break;
case AtoStates.IncreaseSpeed:
AtoBrakeNotch = 0;
- if (train.Acceleration < 0.2 && AtoPowerNotch < train.Specs.PowerNotches)
+ if (train.Acceleration < 0.2 && AtoPowerNotch < train.Specs.PowerNotches && AtoNotchDelayCounter >= AtoNotchDelay)
{
- // TODO: Add delay
AtoPowerNotch++;
+ AtoNotchDelayCounter = 0;
+ }
+ if (train.State.Speed.KilometersPerHour >= target.KilometersPerHour - 5)
+ {
+ AtoState = AtoStates.MaintainSpeed;
+ }
+ break;
+ case AtoStates.MaintainSpeed:
+ AtoBrakeNotch = 0;
+ if (train.Acceleration > 0 && AtoNotchDelayCounter >= AtoNotchDelay)
+ {
+ if (AtoPowerNotch > 0)
+ {
+ AtoPowerNotch--;
+ }
+ else if (AtoBrakeNotch < train.Specs.BrakeNotches)
+ {
+ AtoBrakeNotch++;
+ }
+ AtoNotchDelayCounter = 0;
}
break;
}