Doors
This commit is contained in:
parent
8d9c08276a
commit
b32c1aafeb
7 changed files with 215 additions and 31 deletions
|
@ -31,9 +31,10 @@ namespace OpenbveFcmbTrainPlugin
|
|||
|
||||
/// <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>
|
||||
/// <param name="init">Whether the device should initialize.</param>
|
||||
/// <param name="elapsedTime">The time elapsed since the previous call.</param>
|
||||
internal override void Update(Train train, bool init, Time elapsedTime)
|
||||
internal override void Update(Train train, Route route, bool init, Time elapsedTime)
|
||||
{
|
||||
if (train.VigilanceOverride)
|
||||
{
|
||||
|
@ -100,7 +101,8 @@ namespace OpenbveFcmbTrainPlugin
|
|||
/// <summary>Is called when the plugin should perform the AI.</summary>
|
||||
/// <param name="data">The AI data.</param>
|
||||
/// <param name="train">The current train.</param>
|
||||
internal override void PerformAI(AIData data, Train train)
|
||||
/// <param name="route">The current route.</param>
|
||||
internal override void PerformAI(AIData data, Train train, Route route)
|
||||
{
|
||||
if (DeviceState != DeviceStates.Inactive)
|
||||
{
|
||||
|
|
|
@ -17,9 +17,10 @@ namespace OpenbveFcmbTrainPlugin
|
|||
|
||||
/// <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>
|
||||
/// <param name="init">Whether the device should initialize.</param>
|
||||
/// <param name="elapsedTime">The time elapsed since the previous call.</param>
|
||||
internal virtual void Update(Train train, bool init, Time elapsedTime) { }
|
||||
internal virtual void Update(Train train, Route route, bool init, Time elapsedTime) { }
|
||||
|
||||
/// <summary>Is called when the driver changes the reverser.</summary>
|
||||
/// <param name="reverser">The new reverser position.</param>
|
||||
|
@ -59,6 +60,7 @@ namespace OpenbveFcmbTrainPlugin
|
|||
/// <summary>Is called when the plugin should perform the AI.</summary>
|
||||
/// <param name="data">The AI data.</param>
|
||||
/// <param name="train">The current train.</param>
|
||||
internal virtual void PerformAI(AIData data, Train train) { }
|
||||
/// <param name="route">The current route.</param>
|
||||
internal virtual void PerformAI(AIData data, Train train, Route route) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,10 @@ namespace OpenbveFcmbTrainPlugin
|
|||
|
||||
/// <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>
|
||||
/// <param name="init">Whether the device should initialize.</param>
|
||||
/// <param name="elapsedTime">The time elapsed since the previous call.</param>
|
||||
internal override void Update(Train train, bool init, Time elapsedTime)
|
||||
internal override void Update(Train train, Route route, bool init, Time elapsedTime)
|
||||
{
|
||||
if (init)
|
||||
{
|
||||
|
@ -136,31 +137,89 @@ namespace OpenbveFcmbTrainPlugin
|
|||
/// <param name="newState">The new state of the doors.</param>
|
||||
internal override void DoorChange(DoorStates oldState, DoorStates newState)
|
||||
{
|
||||
LeftDoorsClosing = false;
|
||||
RightDoorsClosing = false;
|
||||
if ((oldState == DoorStates.Both || oldState == DoorStates.Left) && (newState == DoorStates.None || newState == DoorStates.Right))
|
||||
{
|
||||
LeftDoorsClosing = false;
|
||||
// Unselect doors automatically when closed, just in case
|
||||
RequestedDoorInterlock = newState == DoorStates.None ? 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Is called when the device should perform the AI.</summary>
|
||||
/// <param name="data">The AI data.</param>
|
||||
/// <param name="train">The current train.</param>
|
||||
internal override void PerformAI(AIData data, Train train)
|
||||
/// <param name="route">The current route.</param>
|
||||
internal override void PerformAI(AIData data, Train train, Route route)
|
||||
{
|
||||
//// Select the correct doors for the current station
|
||||
//if (Stations.State != Stations.StationStates.Completed)
|
||||
//{
|
||||
// if (((Stations.Current.OpenLeftDoors && !LeftDoorsSelected) || (!Stations.Current.OpenLeftDoors && LeftDoorsSelected)) && !LeftDoorsClosing)
|
||||
// {
|
||||
// // Select or unselect the doors on the left.
|
||||
// KeyDown(VirtualKeys.G);
|
||||
// data.Response = AIResponse.Short;
|
||||
// }
|
||||
// if (((Stations.Current.OpenRightDoors && !RightDoorsSelected) || (!Stations.Current.OpenRightDoors && RightDoorsSelected)) && !RightDoorsClosing)
|
||||
// {
|
||||
// // Select or unselect the doors on the right.
|
||||
// KeyDown(VirtualKeys.H);
|
||||
// data.Response = AIResponse.Short;
|
||||
// }
|
||||
//}
|
||||
// Select doors to be opened on the current stop, at least 200 meters before the stop point.
|
||||
if (route.CurrentStation.PlayerStops() && train.State.Location >= route.CurrentStation.StopPosition - 200 && route.StationState == Route.StationStates.Pending)
|
||||
{
|
||||
switch (RequestedDoorInterlock)
|
||||
{
|
||||
case DoorInterlockStates.Unlocked:
|
||||
if (!route.CurrentStation.OpenLeftDoors)
|
||||
{
|
||||
KeyChange(VirtualKeys.G, true, train);
|
||||
data.Response = AIResponse.Short;
|
||||
KeyChange(VirtualKeys.G, false, train);
|
||||
}
|
||||
if (!route.CurrentStation.OpenRightDoors)
|
||||
{
|
||||
KeyChange(VirtualKeys.H, true, train);
|
||||
data.Response = AIResponse.Short;
|
||||
KeyChange(VirtualKeys.H, false, train);
|
||||
}
|
||||
break;
|
||||
case DoorInterlockStates.Left:
|
||||
if (!route.CurrentStation.OpenLeftDoors)
|
||||
{
|
||||
KeyChange(VirtualKeys.G, true, train);
|
||||
data.Response = AIResponse.Short;
|
||||
KeyChange(VirtualKeys.G, false, train);
|
||||
}
|
||||
if (route.CurrentStation.OpenRightDoors)
|
||||
{
|
||||
KeyChange(VirtualKeys.H, true, train);
|
||||
data.Response = AIResponse.Short;
|
||||
KeyChange(VirtualKeys.H, false, train);
|
||||
}
|
||||
break;
|
||||
case DoorInterlockStates.Right:
|
||||
if (route.CurrentStation.OpenLeftDoors)
|
||||
{
|
||||
KeyChange(VirtualKeys.G, true, train);
|
||||
data.Response = AIResponse.Short;
|
||||
KeyChange(VirtualKeys.G, false, train);
|
||||
}
|
||||
if (!route.CurrentStation.OpenRightDoors)
|
||||
{
|
||||
KeyChange(VirtualKeys.H, true, train);
|
||||
data.Response = AIResponse.Short;
|
||||
KeyChange(VirtualKeys.H, false, train);
|
||||
}
|
||||
break;
|
||||
case DoorInterlockStates.Locked:
|
||||
if (route.CurrentStation.OpenLeftDoors)
|
||||
{
|
||||
KeyChange(VirtualKeys.G, true, train);
|
||||
data.Response = AIResponse.Short;
|
||||
KeyChange(VirtualKeys.G, false, train);
|
||||
}
|
||||
if (route.CurrentStation.OpenRightDoors)
|
||||
{
|
||||
KeyChange(VirtualKeys.H, true, train);
|
||||
data.Response = AIResponse.Short;
|
||||
KeyChange(VirtualKeys.H, false, train);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue