From b95775e6c92faecf40c567fe5b6d5e076a49577e Mon Sep 17 00:00:00 2001 From: Marc Riera Date: Sun, 15 Dec 2024 22:39:40 +0100 Subject: [PATCH] ATC Dimetronic: mode switch --- src/Devices/AtcDimetronic.cs | 33 +++++++++++++++++++++++++++++---- src/Managers/ConfigManager.cs | 4 ++++ src/Train/Train.cs | 2 +- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Devices/AtcDimetronic.cs b/src/Devices/AtcDimetronic.cs index 3f834f8..5d879af 100644 --- a/src/Devices/AtcDimetronic.cs +++ b/src/Devices/AtcDimetronic.cs @@ -50,7 +50,10 @@ namespace OpenbveFcmbTrainPlugin private TrackStates TrackState; /// The maximum speed in YARD mode, in km/h. - private double YardMaximumSpeed; + 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 +93,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 +226,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 +240,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)); } }