diff --git a/src/Devices/Doors.cs b/src/Devices/Doors.cs index d943dca..26ed1e4 100644 --- a/src/Devices/Doors.cs +++ b/src/Devices/Doors.cs @@ -33,21 +33,6 @@ namespace OpenbveFcmbTrainPlugin /// Whether the AI should trigger the door closing sound. private bool AiTriggerDoorClosingSound; - /// The timeout after which the AI needs to close doors if they become stuck, in seconds. - private double AiDoorStuckTimeout = 10; - - /// The counter for the AI to close doors if they become stuck. - private double AiDoorStuckCounter; - - /// The index of the door closing sound. - private int DoorClosingSoundIndex = 10; - - /// The current time. - private Time CurrentTime = new Time(0); - - /// The time when the doors last opened. - private Time DoorOpenTime = new Time(0); - /// Is called when the device state should be updated. /// The current train. @@ -56,9 +41,6 @@ namespace OpenbveFcmbTrainPlugin /// The time elapsed since the previous call. internal override void Update(Train train, Route route, bool init, Time elapsedTime) { - // Update current time - CurrentTime = route.CurrentTime; - if (init) { if (!RequireDoorClosingSound) @@ -127,32 +109,8 @@ namespace OpenbveFcmbTrainPlugin } // Check if AI needs to trigger the door closing sound - if (train.DoorState != DoorStates.None && DoorClosingSoundCounter > DoorClosingSoundDuration + DoorClosingSoundTimeout) - { - if (route.CurrentStation.Type == StationType.Normal || route.CurrentStation.Type == StationType.RequestStop) - { - // The current station is an intermediate stop - if (route.CurrentStation.DepartureTime < 0) - { - // The current station has dwell time, not a specific departure time - // Calculate departure time from the time when the doors opened - AiTriggerDoorClosingSound |= CurrentTime.Seconds >= DoorOpenTime.Seconds + (route.CurrentStation.StopTime - DoorClosingSoundDuration); - } - else - { - // Use departure time - door closing sound duration - AiTriggerDoorClosingSound |= CurrentTime.Seconds >= route.CurrentStation.DepartureTime - DoorClosingSoundDuration; - } - } - else - { - AiTriggerDoorClosingSound = false; - } - } - else - { - AiTriggerDoorClosingSound = false; - } + // TODO: check departure time + AiTriggerDoorClosingSound |= (train.DoorState != DoorStates.None && DoorClosingSoundCounter > DoorClosingSoundDuration + DoorClosingSoundTimeout); // Update panel variables for door selection state train.Panel[50] = (RequestedDoorInterlock == DoorInterlockStates.Left || RequestedDoorInterlock == DoorInterlockStates.Unlocked) || (((train.DoorState & DoorStates.Left) != 0) && !LeftDoorsClosing) ? 1 : 0; @@ -175,10 +133,6 @@ namespace OpenbveFcmbTrainPlugin // Play the door closing sound and reset timeout DoorClosingSoundCounter = 0; TriggerDoorUnlock = true; - if (!SoundManager.Playing(DoorClosingSoundIndex)) - { - SoundManager.Play(DoorClosingSoundIndex, 1, 1, false); - } } break; case VirtualKeys.G: @@ -235,30 +189,22 @@ namespace OpenbveFcmbTrainPlugin if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key]) { // Unselect doors automatically when closing - if ((train.DoorState & DoorStates.Left) > 0 && !LeftDoorsClosing && (RequestedDoorInterlock == DoorInterlockStates.Left || RequestedDoorInterlock == DoorInterlockStates.Unlocked)) + if ((train.DoorState & DoorStates.Left) > 0 && (RequestedDoorInterlock == DoorInterlockStates.Left || RequestedDoorInterlock == DoorInterlockStates.Unlocked)) { LeftDoorsClosing = true; RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Left ? DoorInterlockStates.Locked : DoorInterlockStates.Right; } - else - { - LeftDoorsClosing = false; - } } break; case VirtualKeys.RightDoors: if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key]) { // Unselect doors automatically when closing - if ((train.DoorState & DoorStates.Right) > 0 && !RightDoorsClosing && (RequestedDoorInterlock == DoorInterlockStates.Right || RequestedDoorInterlock == DoorInterlockStates.Unlocked)) + if ((train.DoorState & DoorStates.Right) > 0 && (RequestedDoorInterlock == DoorInterlockStates.Right || RequestedDoorInterlock == DoorInterlockStates.Unlocked)) { RightDoorsClosing = true; RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Locked : DoorInterlockStates.Left; } - else - { - RightDoorsClosing = false; - } } break; } @@ -300,12 +246,6 @@ namespace OpenbveFcmbTrainPlugin RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Right : DoorInterlockStates.Locked; } } - - // Set arrival time when doors open - if (oldState == DoorStates.None && newState != DoorStates.None) - { - DoorOpenTime = CurrentTime; - } } /// Is called when the device should perform the AI. diff --git a/src/Managers/MessageManager.cs b/src/Managers/MessageManager.cs index ee716a3..6024b30 100644 --- a/src/Managers/MessageManager.cs +++ b/src/Managers/MessageManager.cs @@ -22,7 +22,7 @@ namespace OpenbveFcmbTrainPlugin /// Shows a message to the player. /// The message to be shown. /// The color of the message. - /// The time to show the message, in seconds. + /// The time to show the message. internal static void ShowMessage(string message, OpenBveApi.Colors.MessageColor color, double time) { MessageDelegate(message, color, time); @@ -31,7 +31,7 @@ namespace OpenbveFcmbTrainPlugin /// Shows a message to the player. /// The message to be shown. /// The color of the message. - /// The time to show the message, in seconds. + /// The time to show the message. /// The score for the player. internal static void ShowMessage( string message, OpenBveApi.Colors.MessageColor color, double time, int score) { diff --git a/src/Managers/SoundManager.cs b/src/Managers/SoundManager.cs index f1a3a42..ba1dc03 100644 --- a/src/Managers/SoundManager.cs +++ b/src/Managers/SoundManager.cs @@ -39,7 +39,7 @@ namespace OpenbveFcmbTrainPlugin // Validate index before doing anything if (soundIndex < Sounds.Length && soundIndex >= 0) { - if (Playing(soundIndex)) + if (Sounds[soundIndex].Playing) { // The sound is still playing, update volume and pitch Sounds[soundIndex].Volume = volume; @@ -64,7 +64,7 @@ namespace OpenbveFcmbTrainPlugin // Validate index before doing anything if (soundIndex < Sounds.Length && soundIndex >= 0) { - if (Playing(soundIndex)) + if (Sounds[soundIndex].Playing) { // The sound is still playing, update volume and pitch Sounds[soundIndex].Volume = volume; @@ -82,7 +82,8 @@ namespace OpenbveFcmbTrainPlugin /// The index of the sound to be stopped. internal static void Stop(int soundIndex) { - if (Playing(soundIndex)) + // Validate index before doing anything + if (soundIndex < Sounds.Length && soundIndex >= 0 && Sounds[soundIndex] != null) { // Stop sound Sounds[soundIndex].Stop(); diff --git a/src/Route/Route.cs b/src/Route/Route.cs index 9db13b2..0602f7c 100644 --- a/src/Route/Route.cs +++ b/src/Route/Route.cs @@ -28,9 +28,6 @@ namespace OpenbveFcmbTrainPlugin /// The next station in the route. internal Station NextStation; - /// The current time in the route. - internal Time CurrentTime { get; private set; } = new Time(0); - /// The current state of the train doors. private DoorStates DoorState; @@ -41,9 +38,6 @@ namespace OpenbveFcmbTrainPlugin /// The data passed to the plugin. internal void Elapse(ElapseData data) { - // Update current time - CurrentTime = data.TotalTime; - if (OpenbveFcmbTrainPlugin.Initializing) { // Get the list of stations and set the current station