diff --git a/src/Devices/AtcDimetronic.cs b/src/Devices/AtcDimetronic.cs index ae59c1d..0dd2068 100644 --- a/src/Devices/AtcDimetronic.cs +++ b/src/Devices/AtcDimetronic.cs @@ -52,6 +52,10 @@ namespace OpenbveFcmbTrainPlugin /// The maximum speed in YARD mode, in km/h. private readonly double YardMaximumSpeed; + /// Whether ATO is available or not on the train. + private readonly bool AtoAvailable; + + /// Represents an ATC speed code. private class SpeedCode { @@ -90,9 +94,11 @@ namespace OpenbveFcmbTrainPlugin /// Creates an instance of the Bombardier ATC device. /// The maximum speed in YARD mode, in km/h. - internal AtcDimetronic(double yardMaxSpeed) + /// Whether ATO is available or not. + internal AtcDimetronic(double yardMaxSpeed, bool atoAvailable) { YardMaximumSpeed = yardMaxSpeed; + AtoAvailable = atoAvailable; } /// Is called when the device state should be updated. @@ -221,9 +227,13 @@ namespace OpenbveFcmbTrainPlugin // YARD (M+25) mode selection button if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key]) { - if (DeviceState == DeviceStates.NoMode && stopped) + // Allow change anytime the train is stopped or from ATP mode below YARD speed limit + if ((DeviceState >= DeviceStates.NoMode && stopped) || (DeviceState == DeviceStates.ATP && train.State.Speed.KilometersPerHour < YardMaximumSpeed)) { - DeviceState = DeviceStates.YARD; + if (train.PhysicalHandles.Reverser == 1 || train.PhysicalHandles.Reverser == -1) + { + DeviceState = DeviceStates.YARD; + } } } break; @@ -231,12 +241,28 @@ namespace OpenbveFcmbTrainPlugin // ATP (M+ATP) mode selection button if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key]) { + // Allow change anytime the train is stopped or from ATO mode when running + if ((DeviceState >= DeviceStates.NoMode && DeviceState <= DeviceStates.ATO && stopped) || DeviceState == DeviceStates.ATO) + { + if (train.PhysicalHandles.Reverser == 1 && TrackState > TrackStates.Unprotected) + { + DeviceState = DeviceStates.ATP; + } + } } break; case VirtualKeys.K: // ATO mode selection button if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key]) { + // Allow change when the train is stopped in ATP mode + if (DeviceState == DeviceStates.ATP && stopped && AtoAvailable) + { + if (train.PhysicalHandles.Reverser == 1 && TrackState > TrackStates.Unprotected) + { + DeviceState = DeviceStates.ATO; + } + } } break; case VirtualKeys.L: diff --git a/src/Managers/ConfigManager.cs b/src/Managers/ConfigManager.cs index 7ecd3e1..7b27c85 100644 --- a/src/Managers/ConfigManager.cs +++ b/src/Managers/ConfigManager.cs @@ -30,6 +30,7 @@ namespace OpenbveFcmbTrainPlugin internal int AtcBombardierBlinkTime = 500; internal int AtcDimetronicYardSpeedLimit = 25; + internal bool AtcDimetronicAtoAvailable; } /// Represents the plugin settings. @@ -202,6 +203,9 @@ namespace OpenbveFcmbTrainPlugin } } break; + case "atoavailable": + PluginSettings.AtcDimetronicAtoAvailable = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0; + break; } break; } diff --git a/src/Train/Train.cs b/src/Train/Train.cs index 1131cd8..d7d17e1 100644 --- a/src/Train/Train.cs +++ b/src/Train/Train.cs @@ -98,7 +98,7 @@ namespace OpenbveFcmbTrainPlugin } if (settings.AtcDimetronicDeviceEnabled) { - Devices.Add(new AtcDimetronic(settings.AtcDimetronicYardSpeedLimit)); + Devices.Add(new AtcDimetronic(settings.AtcDimetronicYardSpeedLimit, settings.AtcDimetronicAtoAvailable)); } }