Doors: Add mode where closing sound is required
parent
126cb3f381
commit
fe26296daa
|
@ -12,6 +12,25 @@ namespace OpenbveFcmbTrainPlugin
|
|||
/// <summary>Whether the right doors are closing.</summary>
|
||||
private bool RightDoorsClosing;
|
||||
|
||||
/// <summary>Whether the door closing sound is required to be played to close the doors.</summary>
|
||||
private bool RequireDoorClosingSound;
|
||||
|
||||
/// <summary>The duration of the door closing sound, in seconds.</summary>
|
||||
private double DoorClosingSoundDuration = 5;
|
||||
|
||||
/// <summary>The timeout after which the door closing sound needs to be played again, in seconds.</summary>
|
||||
private double DoorClosingSoundTimeout = 15;
|
||||
|
||||
/// <summary>The counter for the door closing sound.</summary>
|
||||
private double DoorClosingSoundCounter;
|
||||
|
||||
/// <summary>Whether to trigger a door unlock.</summary>
|
||||
private bool TriggerDoorUnlock;
|
||||
|
||||
/// <summary>Whether to trigger a door lock.</summary>
|
||||
private bool TriggerDoorLock;
|
||||
|
||||
|
||||
/// <summary>Is called when the device state should be updated.</summary>
|
||||
/// <param name="train">The current train.</param>
|
||||
/// <param name="route">The current route.</param>
|
||||
|
@ -20,6 +39,8 @@ namespace OpenbveFcmbTrainPlugin
|
|||
internal override void Update(Train train, Route route, bool init, Time elapsedTime)
|
||||
{
|
||||
if (init)
|
||||
{
|
||||
if (!RequireDoorClosingSound)
|
||||
{
|
||||
// Set the selection state of the doors during initialization
|
||||
switch (train.DoorState)
|
||||
|
@ -36,13 +57,57 @@ namespace OpenbveFcmbTrainPlugin
|
|||
break;
|
||||
}
|
||||
}
|
||||
// Set door closing counter to value higher than maximum where doors are allowed to close
|
||||
DoorClosingSoundCounter = DoorClosingSoundDuration + DoorClosingSoundTimeout;
|
||||
}
|
||||
|
||||
// Cut power when the doors are open
|
||||
RequestedPowerNotch = (train.DoorState != DoorStates.None) ? 0 : -1;
|
||||
|
||||
// Update door closing sound counter
|
||||
DoorClosingSoundCounter += elapsedTime.Seconds;
|
||||
|
||||
// Unlock doors for closing if the door closing sound has been played
|
||||
if (RequireDoorClosingSound)
|
||||
{
|
||||
if (DoorClosingSoundCounter > DoorClosingSoundDuration && TriggerDoorUnlock)
|
||||
{
|
||||
switch (train.DoorState)
|
||||
{
|
||||
case DoorStates.Both:
|
||||
RequestedDoorInterlock = DoorInterlockStates.Unlocked;
|
||||
break;
|
||||
case DoorStates.Left:
|
||||
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Unlocked : DoorInterlockStates.Left;
|
||||
break;
|
||||
case DoorStates.Right:
|
||||
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Left ? DoorInterlockStates.Unlocked : DoorInterlockStates.Right;
|
||||
break;
|
||||
}
|
||||
TriggerDoorUnlock = false;
|
||||
TriggerDoorLock = true;
|
||||
}
|
||||
else if (DoorClosingSoundCounter > DoorClosingSoundDuration + DoorClosingSoundTimeout && TriggerDoorLock)
|
||||
{
|
||||
switch (train.DoorState)
|
||||
{
|
||||
case DoorStates.Both:
|
||||
RequestedDoorInterlock = DoorInterlockStates.Locked;
|
||||
break;
|
||||
case DoorStates.Left:
|
||||
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Unlocked ? DoorInterlockStates.Right : DoorInterlockStates.Locked;
|
||||
break;
|
||||
case DoorStates.Right:
|
||||
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Unlocked ? DoorInterlockStates.Left : DoorInterlockStates.Locked;
|
||||
break;
|
||||
}
|
||||
TriggerDoorLock = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update panel variables for door selection state
|
||||
train.Panel[50] = (RequestedDoorInterlock == DoorInterlockStates.Left || RequestedDoorInterlock == DoorInterlockStates.Unlocked) ? 1 : 0;
|
||||
train.Panel[51] = (RequestedDoorInterlock == DoorInterlockStates.Right || RequestedDoorInterlock == DoorInterlockStates.Unlocked) ? 1 : 0;
|
||||
train.Panel[50] = (RequestedDoorInterlock == DoorInterlockStates.Left || RequestedDoorInterlock == DoorInterlockStates.Unlocked) || (((train.DoorState & DoorStates.Left) != 0) && !LeftDoorsClosing) ? 1 : 0;
|
||||
train.Panel[51] = (RequestedDoorInterlock == DoorInterlockStates.Right || RequestedDoorInterlock == DoorInterlockStates.Unlocked) || (((train.DoorState & DoorStates.Right) != 0) && !RightDoorsClosing) ? 1 : 0;
|
||||
}
|
||||
|
||||
/// <summary>Is called when the state of a key changes.</summary>
|
||||
|
@ -55,6 +120,14 @@ namespace OpenbveFcmbTrainPlugin
|
|||
{
|
||||
switch (key)
|
||||
{
|
||||
case VirtualKeys.F:
|
||||
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
|
||||
{
|
||||
// Play the door closing sound and reset timeout
|
||||
DoorClosingSoundCounter = 0;
|
||||
TriggerDoorUnlock = true;
|
||||
}
|
||||
break;
|
||||
case VirtualKeys.G:
|
||||
// Change the selection state of the left doors
|
||||
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
|
||||
|
@ -141,13 +214,30 @@ namespace OpenbveFcmbTrainPlugin
|
|||
{
|
||||
LeftDoorsClosing = false;
|
||||
// Unselect doors automatically when closed, just in case
|
||||
RequestedDoorInterlock = newState == DoorStates.None ? DoorInterlockStates.Locked : DoorInterlockStates.Right;
|
||||
if (RequestedDoorInterlock == DoorInterlockStates.Unlocked || RequestedDoorInterlock == DoorInterlockStates.Left)
|
||||
{
|
||||
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Left ? DoorInterlockStates.Locked : DoorInterlockStates.Right;
|
||||
}
|
||||
}
|
||||
if ((oldState == DoorStates.Both || oldState == DoorStates.Right) && (newState == DoorStates.None || newState == DoorStates.Left))
|
||||
{
|
||||
RightDoorsClosing = false;
|
||||
// Unselect doors automatically when closed, just in case
|
||||
RequestedDoorInterlock = newState == DoorStates.None ? DoorInterlockStates.Locked : DoorInterlockStates.Left;
|
||||
if (RequestedDoorInterlock == DoorInterlockStates.Unlocked || RequestedDoorInterlock == DoorInterlockStates.Right)
|
||||
{
|
||||
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Locked : DoorInterlockStates.Left;
|
||||
}
|
||||
}
|
||||
if (RequireDoorClosingSound)
|
||||
{
|
||||
if ((oldState == DoorStates.None || oldState == DoorStates.Left) && (newState == DoorStates.Both || newState == DoorStates.Right))
|
||||
{
|
||||
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Left ? DoorInterlockStates.Left : DoorInterlockStates.Locked;
|
||||
}
|
||||
if ((oldState == DoorStates.None || oldState == DoorStates.Right) && (newState == DoorStates.Both || newState == DoorStates.Left))
|
||||
{
|
||||
RequestedDoorInterlock = RequestedDoorInterlock == DoorInterlockStates.Right ? DoorInterlockStates.Right : DoorInterlockStates.Locked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue