From 261c1fa9c179b09dd01a0bd99366c97cc6b38147 Mon Sep 17 00:00:00 2001 From: Marc Riera Date: Fri, 13 Dec 2024 00:17:13 +0100 Subject: [PATCH 1/2] Door closing sound: fix AI stuck between stations and lock doors when opening --- src/Devices/DoorClosingSound.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Devices/DoorClosingSound.cs b/src/Devices/DoorClosingSound.cs index e3b5527..eb13768 100644 --- a/src/Devices/DoorClosingSound.cs +++ b/src/Devices/DoorClosingSound.cs @@ -118,11 +118,18 @@ namespace OpenbveFcmbTrainPlugin // Use departure time - door closing sound duration AiTriggerDoorClosingSound |= CurrentTime.Seconds >= route.CurrentStation.DepartureTime - DoorClosingSoundDuration; } - // TODO: AI gets stuck if doors open between stations, check distance to stop point } else { - AiTriggerDoorClosingSound = false; + // The doors have been opened between stations + if (route.CurrentStation.StopPosition - route.CurrentStation.BackwardTolerance > train.State.Location) + { + AiTriggerDoorClosingSound = true; + } + else + { + AiTriggerDoorClosingSound = false; + } } } else @@ -166,6 +173,10 @@ namespace OpenbveFcmbTrainPlugin { DoorOpenTime = CurrentTime; } + + // Set door closing counter to value higher than maximum where doors are allowed to close + // This effectively locks the doors when they open + DoorClosingSoundCounter = DoorClosingSoundDuration + DoorClosingSoundTimeout; } /// Is called when the device should perform the AI. From 6bd560d93a2f1c83a3d4cd9cfc1fec4c25d77ed6 Mon Sep 17 00:00:00 2001 From: Marc Riera Date: Fri, 13 Dec 2024 00:17:36 +0100 Subject: [PATCH 2/2] Make properties read-only --- src/Devices/AtcBombardier.cs | 8 ++++---- src/Devices/AtcDimetronic.cs | 2 +- src/Devices/Deadman.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Devices/AtcBombardier.cs b/src/Devices/AtcBombardier.cs index f988743..f399635 100644 --- a/src/Devices/AtcBombardier.cs +++ b/src/Devices/AtcBombardier.cs @@ -58,25 +58,25 @@ namespace OpenbveFcmbTrainPlugin private TrackStates TrackState; /// The time needed by the ATC device to initialize, in seconds. - private double InitializationTime; + private readonly double InitializationTime; /// A counter to keep track of initialization time, in seconds. private double InitializationCounter; /// The blinking time for lamps, in milliseconds. - private double BlinkTime; + private readonly double BlinkTime; /// A counter to keep track of blink time, in milliseconds. private double BlinkCounter; /// The time after which YARD mode enters idle state and engages the service brake, in seconds. - private double YardIdleTime; + private readonly double YardIdleTime; /// A counter to keep track of YARD mode idle time, in seconds. private double YardIdleCounter; /// The maximum speed in YARD mode, in km/h. - private double YardMaximumSpeed; + private readonly double YardMaximumSpeed; /// Represents an ATC movement permission order. private class MovementPermission diff --git a/src/Devices/AtcDimetronic.cs b/src/Devices/AtcDimetronic.cs index 3f834f8..ae59c1d 100644 --- a/src/Devices/AtcDimetronic.cs +++ b/src/Devices/AtcDimetronic.cs @@ -50,7 +50,7 @@ namespace OpenbveFcmbTrainPlugin private TrackStates TrackState; /// The maximum speed in YARD mode, in km/h. - private double YardMaximumSpeed; + private readonly double YardMaximumSpeed; /// Represents an ATC speed code. private class SpeedCode diff --git a/src/Devices/Deadman.cs b/src/Devices/Deadman.cs index 13cb93a..5800cda 100644 --- a/src/Devices/Deadman.cs +++ b/src/Devices/Deadman.cs @@ -24,10 +24,10 @@ namespace OpenbveFcmbTrainPlugin private double Counter; /// The delay time until the service brake is applied, in seconds. - private double BrakeDelay = 5.0; + private readonly double BrakeDelay = 5.0; /// Whether the train must be completely stopped to release the brakes. - private bool FullReset; + private readonly bool FullReset; /// Creates an instance of the Deadman device. /// The delay before the brakes are applied, in seconds.