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>
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>
/// <param name="train">The current train.</param>
@ -56,9 +41,6 @@ namespace OpenbveFcmbTrainPlugin
/// <param name="elapsedTime">The time elapsed since the previous call.</param>
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;
}
}
/// <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>
/// <param name="message">The message to be shown.</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)
{
MessageDelegate(message, color, time);
@ -31,7 +31,7 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>Shows a message to the player.</summary>
/// <param name="message">The message to be shown.</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>
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
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
/// <param name="soundIndex">The index of the sound to be stopped.</param>
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();

View File

@ -28,9 +28,6 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>The next station in the route.</summary>
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>
private DoorStates DoorState;
@ -41,9 +38,6 @@ namespace OpenbveFcmbTrainPlugin
/// <param name="data">The data passed to the plugin.</param>
internal void Elapse(ElapseData data)
{
// Update current time
CurrentTime = data.TotalTime;
if (OpenbveFcmbTrainPlugin.Initializing)
{
// Get the list of stations and set the current station