From 06bb2e2ee0a3e7e1e1fc19de908ae6c5c66b228c Mon Sep 17 00:00:00 2001 From: Marc Riera Date: Sun, 3 Nov 2024 22:47:50 +0100 Subject: [PATCH] Fixes --- src/Devices/Deadman.cs | 5 ++++- src/Devices/TrainStop.cs | 12 ++++++------ src/OpenbveFcmbTrainPlugin.cs | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Devices/Deadman.cs b/src/Devices/Deadman.cs index 1d4955c..d7a7e8a 100644 --- a/src/Devices/Deadman.cs +++ b/src/Devices/Deadman.cs @@ -76,6 +76,9 @@ namespace OpenbveFcmbTrainPlugin /// The current train. internal override void KeyChange(VirtualKeys key, bool pressed, Train train) { + double speed = train.State.Speed.KilometersPerHour; + bool stopped = speed < 0.05; + if (pressed) { switch (key) @@ -87,7 +90,7 @@ namespace OpenbveFcmbTrainPlugin Counter = 0; DeviceState = DeviceStates.Active; } - else if (DeviceState == DeviceStates.Emergency & Math.Abs(train.State.Speed.KilometersPerHour) < 0.01) + else if (DeviceState == DeviceStates.Emergency && stopped) { // Reset the counter after the train has stopped Counter = 0; diff --git a/src/Devices/TrainStop.cs b/src/Devices/TrainStop.cs index a56b083..fe9488f 100644 --- a/src/Devices/TrainStop.cs +++ b/src/Devices/TrainStop.cs @@ -94,12 +94,9 @@ namespace OpenbveFcmbTrainPlugin // Accidental departure beacon/transponder case 2: // Check if there is a potential SPAD and change to emergency mode - if (beacon.Signal.Aspect == 0) + if (beacon.Signal.Aspect == 0 && DeviceState == DeviceStates.Active) { - if (DeviceState == DeviceStates.Active) - { - DeviceState = DeviceStates.Emergency; - } + DeviceState = DeviceStates.Emergency; } break; } @@ -112,8 +109,11 @@ namespace OpenbveFcmbTrainPlugin /// The current route. internal override void PerformAI(AIData data, Train train, Route route) { + double speed = train.State.Speed.KilometersPerHour; + bool stopped = speed < 0.05; + // Reset device in case of emergency, once the train has stopped - if (DeviceState == DeviceStates.Emergency && train.State.Speed.KilometersPerHour < 0.05) + if (DeviceState == DeviceStates.Emergency && stopped) { data.Handles.BrakeNotch = train.Specs.BrakeNotches; KeyChange(VirtualKeys.C2, true, train); diff --git a/src/OpenbveFcmbTrainPlugin.cs b/src/OpenbveFcmbTrainPlugin.cs index 951de53..a0ded43 100644 --- a/src/OpenbveFcmbTrainPlugin.cs +++ b/src/OpenbveFcmbTrainPlugin.cs @@ -124,6 +124,7 @@ namespace OpenbveFcmbTrainPlugin /// The beacon data. public void SetBeacon(BeaconData beacon) { + Train.SetBeacon(beacon); } /// Is called when the plugin should perform the AI.