ATC Dimetronic: mode switch

This commit is contained in:
Marc Riera 2024-12-15 22:39:40 +01:00
parent 0d696fb381
commit b95775e6c9
3 changed files with 34 additions and 5 deletions

View file

@ -50,7 +50,10 @@ namespace OpenbveFcmbTrainPlugin
private TrackStates TrackState;
/// <summary>The maximum speed in YARD mode, in km/h.</summary>
private double YardMaximumSpeed;
private readonly double YardMaximumSpeed;
/// <summary>Whether ATO is available or not on the train.</summary>
private readonly bool AtoAvailable;
/// <summary>Represents an ATC speed code.</summary>
private class SpeedCode
@ -90,9 +93,11 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>Creates an instance of the Bombardier ATC device.</summary>
/// <param name="yardMaxSpeed">The maximum speed in YARD mode, in km/h.</param>
internal AtcDimetronic(double yardMaxSpeed)
/// <param name="atoAvailable">Whether ATO is available or not.</param>
internal AtcDimetronic(double yardMaxSpeed, bool atoAvailable)
{
YardMaximumSpeed = yardMaxSpeed;
AtoAvailable = atoAvailable;
}
/// <summary>Is called when the device state should be updated.</summary>
@ -221,22 +226,42 @@ namespace OpenbveFcmbTrainPlugin
// YARD (M+25) mode selection button
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
{
if (DeviceState == DeviceStates.NoMode && stopped)
// Allow change anytime the train is stopped or from ATP mode below YARD speed limit
if ((DeviceState >= DeviceStates.NoMode && stopped) || (DeviceState == DeviceStates.ATP && train.State.Speed.KilometersPerHour < YardMaximumSpeed))
{
if (train.PhysicalHandles.Reverser == 1 || train.PhysicalHandles.Reverser == -1)
{
DeviceState = DeviceStates.YARD;
}
}
}
break;
case VirtualKeys.J:
// ATP (M+ATP) mode selection button
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
{
// Allow change anytime the train is stopped or from ATO mode when running
if ((DeviceState >= DeviceStates.NoMode && DeviceState <= DeviceStates.ATO && stopped) || DeviceState == DeviceStates.ATO)
{
if (train.PhysicalHandles.Reverser == 1 && TrackState > TrackStates.Unprotected)
{
DeviceState = DeviceStates.ATP;
}
}
}
break;
case VirtualKeys.K:
// ATO mode selection button
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
{
// Allow change when the train is stopped in ATP mode
if (DeviceState == DeviceStates.ATP && stopped && AtoAvailable)
{
if (train.PhysicalHandles.Reverser == 1 && TrackState > TrackStates.Unprotected)
{
DeviceState = DeviceStates.ATO;
}
}
}
break;
case VirtualKeys.L:

View file

@ -30,6 +30,7 @@ namespace OpenbveFcmbTrainPlugin
internal int AtcBombardierBlinkTime = 500;
internal int AtcDimetronicYardSpeedLimit = 25;
internal bool AtcDimetronicAtoAvailable;
}
/// <summary>Represents the plugin settings.</summary>
@ -202,6 +203,9 @@ namespace OpenbveFcmbTrainPlugin
}
}
break;
case "atoavailable":
PluginSettings.AtcDimetronicAtoAvailable = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;
}
break;
}

View file

@ -98,7 +98,7 @@ namespace OpenbveFcmbTrainPlugin
}
if (settings.AtcDimetronicDeviceEnabled)
{
Devices.Add(new AtcDimetronic(settings.AtcDimetronicYardSpeedLimit));
Devices.Add(new AtcDimetronic(settings.AtcDimetronicYardSpeedLimit, settings.AtcDimetronicAtoAvailable));
}
}