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>
|
/// <summary>Whether the right doors are closing.</summary>
|
||||||
private bool RightDoorsClosing;
|
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>
|
/// <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>
|
||||||
/// <param name="route">The current route.</param>
|
/// <param name="route">The current route.</param>
|
||||||
|
@ -21,28 +40,74 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
{
|
{
|
||||||
if (init)
|
if (init)
|
||||||
{
|
{
|
||||||
// Set the selection state of the doors during initialization
|
if (!RequireDoorClosingSound)
|
||||||
switch (train.DoorState)
|
|
||||||
{
|
{
|
||||||
case DoorStates.None:
|
// Set the selection state of the doors during initialization
|
||||||
RequestedDoorInterlock = DoorInterlockStates.Locked;
|
switch (train.DoorState)
|
||||||
break;
|
{
|
||||||
case DoorStates.Both:
|
case DoorStates.None:
|
||||||
RequestedDoorInterlock = DoorInterlockStates.Unlocked;
|
RequestedDoorInterlock = DoorInterlockStates.Locked;
|
||||||
break;
|
break;
|
||||||
case DoorStates.Left:
|
case DoorStates.Both:
|
||||||
case DoorStates.Right:
|
RequestedDoorInterlock = DoorInterlockStates.Unlocked;
|
||||||
RequestedDoorInterlock = (DoorInterlockStates)train.DoorState;
|
break;
|
||||||
break;
|
case DoorStates.Left:
|
||||||
|
case DoorStates.Right:
|
||||||
|
RequestedDoorInterlock = (DoorInterlockStates)train.DoorState;
|
||||||
|
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
|
// Cut power when the doors are open
|
||||||
RequestedPowerNotch = (train.DoorState != DoorStates.None) ? 0 : -1;
|
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
|
// Update panel variables for door selection state
|
||||||
train.Panel[50] = (RequestedDoorInterlock == DoorInterlockStates.Left || 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) ? 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>
|
/// <summary>Is called when the state of a key changes.</summary>
|
||||||
|
@ -55,6 +120,14 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
{
|
{
|
||||||
switch (key)
|
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:
|
case VirtualKeys.G:
|
||||||
// Change the selection state of the left doors
|
// Change the selection state of the left doors
|
||||||
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
|
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
|
||||||
|
@ -123,7 +196,7 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
if ((train.DoorState & DoorStates.Right) > 0 && (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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -141,13 +214,30 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
{
|
{
|
||||||
LeftDoorsClosing = false;
|
LeftDoorsClosing = false;
|
||||||
// Unselect doors automatically when closed, just in case
|
// 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))
|
if ((oldState == DoorStates.Both || oldState == DoorStates.Right) && (newState == DoorStates.None || newState == DoorStates.Left))
|
||||||
{
|
{
|
||||||
RightDoorsClosing = false;
|
RightDoorsClosing = false;
|
||||||
// Unselect doors automatically when closed, just in case
|
// 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