From 261c1fa9c179b09dd01a0bd99366c97cc6b38147 Mon Sep 17 00:00:00 2001 From: Marc Riera Date: Fri, 13 Dec 2024 00:17:13 +0100 Subject: [PATCH] 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.