ATC Dimetronic: Overspeed alarm

This commit is contained in:
Marc Riera 2024-12-23 17:30:48 +01:00
parent fa6235cfb2
commit 7f3388b24a
3 changed files with 37 additions and 5 deletions

View file

@ -32,6 +32,8 @@ namespace OpenbveFcmbTrainPlugin
Released,
/// <summary>The power is cut.</summary>
NoPower,
/// <summary>The power is cut and an alarm plays.</summary>
NoPowerAlarm,
/// <summary>The emergency brake is applied.</summary>
BrakeEmergency,
}
@ -78,6 +80,9 @@ namespace OpenbveFcmbTrainPlugin
/// <summary>Whether ATO is available or not on the train.</summary>
private readonly bool AtoAvailable;
/// <summary>The index of the alarm sound.</summary>
private readonly int AlarmSoundIndex;
/// <summary>Represents an ATC speed code.</summary>
private class SpeedCode
{
@ -190,14 +195,16 @@ namespace OpenbveFcmbTrainPlugin
/// <param name="runbackDistance">The distance after which the runback protection is triggered, in meters.</param>
/// <param name="rollforwardDistance">The distance after which the rollforward protection is triggered, in meters.</param>
/// <param name="signalCodes">The list of signal codes recognised by the device.</param>
/// <param name="alarmSoundIndex">The index of the alarm sound.</param>
/// <param name="atoAvailable">Whether ATO is available or not.</param>
internal AtcDimetronic(double trainLength, Speed yardMaxSpeed, double runbackDistance, double rollforwardDistance, List<SignalCode> signalCodes, bool atoAvailable)
internal AtcDimetronic(double trainLength, Speed yardMaxSpeed, double runbackDistance, double rollforwardDistance, List<SignalCode> signalCodes, int alarmSoundIndex, bool atoAvailable)
{
TrainLength = trainLength;
YardMaximumSpeed = yardMaxSpeed;
RunbackDistance = runbackDistance;
RollforwardDistance = rollforwardDistance;
SignalCodes = signalCodes;
AlarmSoundIndex = alarmSoundIndex;
AtoAvailable = atoAvailable;
}
@ -228,10 +235,10 @@ namespace OpenbveFcmbTrainPlugin
// Speed limit enforcement
if (AtcControlState == AtcControlStates.Released && speed > CurrentSpeedCode.WarningOn.KilometersPerHour)
{
// Cut power above warning on threshold
AtcControlState = AtcControlStates.NoPower;
// Cut power above warning on threshold and play alarm
AtcControlState = AtcControlStates.NoPowerAlarm;
}
if (AtcControlState == AtcControlStates.NoPower && speed < CurrentSpeedCode.WarningOff.KilometersPerHour)
if ((AtcControlState == AtcControlStates.NoPower || AtcControlState == AtcControlStates.NoPowerAlarm) && speed < CurrentSpeedCode.WarningOff.KilometersPerHour)
{
// Stop cutting power below warning off threshold
AtcControlState = AtcControlStates.Released;
@ -281,6 +288,7 @@ namespace OpenbveFcmbTrainPlugin
RequestedPowerNotch = -1;
break;
case AtcControlStates.NoPower:
case AtcControlStates.NoPowerAlarm:
RequestedBrakeNotch = -1;
RequestedPowerNotch = 0;
break;
@ -345,6 +353,17 @@ namespace OpenbveFcmbTrainPlugin
train.Panel[34] = (int)CurrentSpeedCode.CurrentLimit.KilometersPerHour * 1000;
train.Panel[33] = 1;
train.Panel[35] = (int)CurrentSpeedCode.TargetLimit.KilometersPerHour * 1000;
// Play alarm sound
if (AtcControlState == AtcControlStates.NoPowerAlarm)
{
SoundManager.Play(AlarmSoundIndex, 1.0, 1.0, true);
}
// Stop alarm sound
if (AtcControlState != AtcControlStates.NoPowerAlarm && SoundManager.Playing(AlarmSoundIndex))
{
SoundManager.Stop(AlarmSoundIndex);
}
}
@ -415,6 +434,10 @@ namespace OpenbveFcmbTrainPlugin
// ATC alarm acknowledge
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
{
if (AtcControlState == AtcControlStates.NoPowerAlarm)
{
AtcControlState = AtcControlStates.NoPower;
}
}
break;
case VirtualKeys.C1:

View file

@ -38,6 +38,7 @@ namespace OpenbveFcmbTrainPlugin
internal double AtcDimetronicRunbackDistance = 3;
internal double AtcDimetronicRollforwardDistance = 100;
internal bool AtcDimetronicAtoAvailable;
internal int AtcDimetronicAlarmSoundIndex = 11;
internal List<AtcDimetronic.SignalCode> AtcDimetronicSignalCodes = new List<AtcDimetronic.SignalCode>();
}
@ -240,6 +241,14 @@ namespace OpenbveFcmbTrainPlugin
}
}
break;
case "alarmsoundindex":
{
if (int.TryParse(Value, out int a))
{
PluginSettings.AtcDimetronicAlarmSoundIndex = a;
}
}
break;
case "atoavailable":
PluginSettings.AtcDimetronicAtoAvailable = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
break;

View file

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