ATC: AI and brake application for door opening

main
Marc Riera 2024-10-18 00:00:58 +02:00
parent f1e9c3e654
commit 08f7043282
1 changed files with 43 additions and 18 deletions

View File

@ -75,6 +75,24 @@ namespace OpenbveFcmbTrainPlugin
DeviceState = DeviceStates.Initializing; DeviceState = DeviceStates.Initializing;
} }
// Brake application
if (DeviceState != DeviceStates.Override)
{
switch (AtcBrakeState)
{
case AtcBrakeStates.Released:
RequestedBrakeNotch = -1;
break;
case AtcBrakeStates.Service:
case AtcBrakeStates.ServiceNoRelease:
RequestedBrakeNotch = train.ServiceBrakeNotch;
break;
case AtcBrakeStates.Emergency:
RequestedBrakeNotch = train.Specs.BrakeNotches + 1;
break;
}
}
switch (DeviceState) switch (DeviceState)
{ {
// ATC device is disabled (also called "Special Mode") // ATC device is disabled (also called "Special Mode")
@ -129,6 +147,11 @@ namespace OpenbveFcmbTrainPlugin
{ {
AtcBrakeState = AtcBrakeStates.Released; AtcBrakeState = AtcBrakeStates.Released;
} }
// Apply brake if any door opens
if (train.DoorState != DoorStates.None)
{
RequestedBrakeNotch = train.State.Speed.KilometersPerHour < 0.05 ? train.Specs.BrakeNotches + 1 : train.ServiceBrakeNotch;
}
break; break;
// ATC device is in ATP (M+ATP) driving mode // ATC device is in ATP (M+ATP) driving mode
case DeviceStates.ATP: case DeviceStates.ATP:
@ -142,23 +165,6 @@ namespace OpenbveFcmbTrainPlugin
break; break;
} }
if (DeviceState != DeviceStates.Override)
{
// Brake application
switch (AtcBrakeState)
{
case AtcBrakeStates.Released:
RequestedBrakeNotch = -1;
break;
case AtcBrakeStates.Service:
case AtcBrakeStates.ServiceNoRelease:
RequestedBrakeNotch = train.ServiceBrakeNotch;
break;
case AtcBrakeStates.Emergency:
RequestedBrakeNotch = train.Specs.BrakeNotches + 1;
break;
}
}
// Blinking light animation // Blinking light animation
BlinkCounter += elapsedTime.Milliseconds; BlinkCounter += elapsedTime.Milliseconds;
bool blink = BlinkCounter >= BlinkTime; bool blink = BlinkCounter >= BlinkTime;
@ -280,7 +286,26 @@ namespace OpenbveFcmbTrainPlugin
/// <param name="route">The current route.</param> /// <param name="route">The current route.</param>
internal override void PerformAI(AIData data, Train train, Route route) internal override void PerformAI(AIData data, Train train, Route route)
{ {
switch (DeviceState)
{
case DeviceStates.Initializing:
data.Handles.BrakeNotch = train.Specs.BrakeNotches;
data.Response = AIResponse.Short;
break;
case DeviceStates.Initialized:
// Apply brake
data.Handles.BrakeNotch = train.Specs.BrakeNotches;
data.Response = AIResponse.Short;
// If the train is stopped, select YARD (M+25) mode
if (train.State.Speed.KilometersPerHour < 0.05)
{
data.Response = AIResponse.Long;
KeyChange(VirtualKeys.I, true, train);
data.Response = AIResponse.Short;
KeyChange(VirtualKeys.I, false, train);
}
break;
}
} }
} }