diff --git a/src/Devices/AtcBombardier.cs b/src/Devices/AtcBombardier.cs index 832bfa2..719bedd 100644 --- a/src/Devices/AtcBombardier.cs +++ b/src/Devices/AtcBombardier.cs @@ -75,6 +75,24 @@ namespace OpenbveFcmbTrainPlugin 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) { // ATC device is disabled (also called "Special Mode") @@ -129,6 +147,11 @@ namespace OpenbveFcmbTrainPlugin { 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; // ATC device is in ATP (M+ATP) driving mode case DeviceStates.ATP: @@ -142,23 +165,6 @@ namespace OpenbveFcmbTrainPlugin 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 BlinkCounter += elapsedTime.Milliseconds; bool blink = BlinkCounter >= BlinkTime; @@ -280,7 +286,26 @@ namespace OpenbveFcmbTrainPlugin /// The current 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; + } } }