diff --git a/src/Devices/AtcDimetronic.cs b/src/Devices/AtcDimetronic.cs index f7cf37d..eff70bc 100644 --- a/src/Devices/AtcDimetronic.cs +++ b/src/Devices/AtcDimetronic.cs @@ -32,6 +32,8 @@ namespace OpenbveFcmbTrainPlugin Released, /// The power is cut. NoPower, + /// The power is cut and an alarm plays. + NoPowerAlarm, /// The emergency brake is applied. BrakeEmergency, } @@ -78,6 +80,9 @@ namespace OpenbveFcmbTrainPlugin /// Whether ATO is available or not on the train. private readonly bool AtoAvailable; + /// The index of the alarm sound. + private readonly int AlarmSoundIndex; + /// Represents an ATC speed code. private class SpeedCode { @@ -190,14 +195,16 @@ namespace OpenbveFcmbTrainPlugin /// The distance after which the runback protection is triggered, in meters. /// The distance after which the rollforward protection is triggered, in meters. /// The list of signal codes recognised by the device. + /// The index of the alarm sound. /// Whether ATO is available or not. - internal AtcDimetronic(double trainLength, Speed yardMaxSpeed, double runbackDistance, double rollforwardDistance, List signalCodes, bool atoAvailable) + internal AtcDimetronic(double trainLength, Speed yardMaxSpeed, double runbackDistance, double rollforwardDistance, List 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: diff --git a/src/Managers/ConfigManager.cs b/src/Managers/ConfigManager.cs index 82ba676..1f13eb2 100644 --- a/src/Managers/ConfigManager.cs +++ b/src/Managers/ConfigManager.cs @@ -38,6 +38,7 @@ namespace OpenbveFcmbTrainPlugin internal double AtcDimetronicRunbackDistance = 3; internal double AtcDimetronicRollforwardDistance = 100; internal bool AtcDimetronicAtoAvailable; + internal int AtcDimetronicAlarmSoundIndex = 11; internal List AtcDimetronicSignalCodes = new List(); } @@ -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; diff --git a/src/Train/Train.cs b/src/Train/Train.cs index 1d0ff1c..3bcd09c 100644 --- a/src/Train/Train.cs +++ b/src/Train/Train.cs @@ -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)); } }