Compare commits

..

No commits in common. "bcc0f1d4b91e2e45fd2ccc70ed8da04799d82563" and "7574de93ab644505eace6b2c2b7847d6d6d07c8c" have entirely different histories.

4 changed files with 10 additions and 75 deletions

View File

@ -33,21 +33,6 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>Whether the AI should trigger the door closing sound.</summary> /// <summary>Whether the AI should trigger the door closing sound.</summary>
private bool AiTriggerDoorClosingSound; private bool AiTriggerDoorClosingSound;
/// <summary>The timeout after which the AI needs to close doors if they become stuck, in seconds.</summary>
private double AiDoorStuckTimeout = 10;
/// <summary>The counter for the AI to close doors if they become stuck.</summary>
private double AiDoorStuckCounter;
/// <summary>The index of the door closing sound.</summary>
private int DoorClosingSoundIndex = 10;
/// <summary>The current time.</summary>
private Time CurrentTime = new Time(0);
/// <summary>The time when the doors last opened.</summary>
private Time DoorOpenTime = new Time(0);
/// <summary>Is called when the device state should be updated.</summary> /// <summary>Is called when the device state should be updated.</summary>
/// <param name="train">The current train.</param> /// <param name="train">The current train.</param>
@ -56,9 +41,6 @@ namespace OpenbveFcmbTrainPlugin
/// <param name="elapsedTime">The time elapsed since the previous call.</param> /// <param name="elapsedTime">The time elapsed since the previous call.</param>
internal override void Update(Train train, Route route, bool init, Time elapsedTime) internal override void Update(Train train, Route route, bool init, Time elapsedTime)
{ {
// Update current time
CurrentTime = route.CurrentTime;
if (init) if (init)
{ {
if (!RequireDoorClosingSound) if (!RequireDoorClosingSound)
@ -127,32 +109,8 @@ namespace OpenbveFcmbTrainPlugin
} }
// Check if AI needs to trigger the door closing sound // Check if AI needs to trigger the door closing sound
if (train.DoorState != DoorStates.None && DoorClosingSoundCounter > DoorClosingSoundDuration + DoorClosingSoundTimeout) // TODO: check departure time
{ AiTriggerDoorClosingSound |= (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;
}
// Update panel variables for door selection state // Update panel variables for door selection state
train.Panel[50] = (RequestedDoorInterlock == DoorInterlockStates.Left || RequestedDoorInterlock == DoorInterlockStates.Unlocked) || (((train.DoorState & DoorStates.Left) != 0) && !LeftDoorsClosing) ? 1 : 0; 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 // Play the door closing sound and reset timeout
DoorClosingSoundCounter = 0; DoorClosingSoundCounter = 0;
TriggerDoorUnlock = true; TriggerDoorUnlock = true;
if (!SoundManager.Playing(DoorClosingSoundIndex))
{
SoundManager.Play(DoorClosingSoundIndex, 1, 1, false);
}
} }
break; break;
case VirtualKeys.G: case VirtualKeys.G:
@ -235,30 +189,22 @@ namespace OpenbveFcmbTrainPlugin
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key]) if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
{ {
// Unselect doors automatically when closing // 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; LeftDoorsClosing = true;
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Left ? DoorInterlockStates.Locked : DoorInterlockStates.Right; RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Left ? DoorInterlockStates.Locked : DoorInterlockStates.Right;
} }
else
{
LeftDoorsClosing = false;
}
} }
break; break;
case VirtualKeys.RightDoors: case VirtualKeys.RightDoors:
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key]) if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
{ {
// Unselect doors automatically when closing // 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; RightDoorsClosing = true;
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Locked : DoorInterlockStates.Left; RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Locked : DoorInterlockStates.Left;
} }
else
{
RightDoorsClosing = false;
}
} }
break; break;
} }
@ -300,12 +246,6 @@ namespace OpenbveFcmbTrainPlugin
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Right : DoorInterlockStates.Locked; RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Right : DoorInterlockStates.Locked;
} }
} }
// Set arrival time when doors open
if (oldState == DoorStates.None && newState != DoorStates.None)
{
DoorOpenTime = CurrentTime;
}
} }
/// <summary>Is called when the device should perform the AI.</summary> /// <summary>Is called when the device should perform the AI.</summary>

View File

@ -22,7 +22,7 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>Shows a message to the player.</summary> /// <summary>Shows a message to the player.</summary>
/// <param name="message">The message to be shown.</param> /// <param name="message">The message to be shown.</param>
/// <param name="color">The color of the message.</param> /// <param name="color">The color of the message.</param>
/// <param name="time">The time to show the message, in seconds.</param> /// <param name="time">The time to show the message.</param>
internal static void ShowMessage(string message, OpenBveApi.Colors.MessageColor color, double time) internal static void ShowMessage(string message, OpenBveApi.Colors.MessageColor color, double time)
{ {
MessageDelegate(message, color, time); MessageDelegate(message, color, time);
@ -31,7 +31,7 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>Shows a message to the player.</summary> /// <summary>Shows a message to the player.</summary>
/// <param name="message">The message to be shown.</param> /// <param name="message">The message to be shown.</param>
/// <param name="color">The color of the message.</param> /// <param name="color">The color of the message.</param>
/// <param name="time">The time to show the message, in seconds.</param> /// <param name="time">The time to show the message.</param>
/// <param name="score">The score for the player.</param> /// <param name="score">The score for the player.</param>
internal static void ShowMessage( string message, OpenBveApi.Colors.MessageColor color, double time, int score) internal static void ShowMessage( string message, OpenBveApi.Colors.MessageColor color, double time, int score)
{ {

View File

@ -39,7 +39,7 @@ namespace OpenbveFcmbTrainPlugin
// Validate index before doing anything // Validate index before doing anything
if (soundIndex < Sounds.Length && soundIndex >= 0) if (soundIndex < Sounds.Length && soundIndex >= 0)
{ {
if (Playing(soundIndex)) if (Sounds[soundIndex].Playing)
{ {
// The sound is still playing, update volume and pitch // The sound is still playing, update volume and pitch
Sounds[soundIndex].Volume = volume; Sounds[soundIndex].Volume = volume;
@ -64,7 +64,7 @@ namespace OpenbveFcmbTrainPlugin
// Validate index before doing anything // Validate index before doing anything
if (soundIndex < Sounds.Length && soundIndex >= 0) if (soundIndex < Sounds.Length && soundIndex >= 0)
{ {
if (Playing(soundIndex)) if (Sounds[soundIndex].Playing)
{ {
// The sound is still playing, update volume and pitch // The sound is still playing, update volume and pitch
Sounds[soundIndex].Volume = volume; Sounds[soundIndex].Volume = volume;
@ -82,7 +82,8 @@ namespace OpenbveFcmbTrainPlugin
/// <param name="soundIndex">The index of the sound to be stopped.</param> /// <param name="soundIndex">The index of the sound to be stopped.</param>
internal static void Stop(int soundIndex) 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 // Stop sound
Sounds[soundIndex].Stop(); Sounds[soundIndex].Stop();

View File

@ -28,9 +28,6 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>The next station in the route.</summary> /// <summary>The next station in the route.</summary>
internal Station NextStation; internal Station NextStation;
/// <summary>The current time in the route.</summary>
internal Time CurrentTime { get; private set; } = new Time(0);
/// <summary>The current state of the train doors.</summary> /// <summary>The current state of the train doors.</summary>
private DoorStates DoorState; private DoorStates DoorState;
@ -41,9 +38,6 @@ namespace OpenbveFcmbTrainPlugin
/// <param name="data">The data passed to the plugin.</param> /// <param name="data">The data passed to the plugin.</param>
internal void Elapse(ElapseData data) internal void Elapse(ElapseData data)
{ {
// Update current time
CurrentTime = data.TotalTime;
if (OpenbveFcmbTrainPlugin.Initializing) if (OpenbveFcmbTrainPlugin.Initializing)
{ {
// Get the list of stations and set the current station // Get the list of stations and set the current station