diff --git a/src/Devices/AtcBombardier.cs b/src/Devices/AtcBombardier.cs
index f399635..73dda96 100644
--- a/src/Devices/AtcBombardier.cs
+++ b/src/Devices/AtcBombardier.cs
@@ -269,7 +269,7 @@ namespace OpenbveFcmbTrainPlugin
train.Panel[26] = DeviceState == DeviceStates.YARD ? 1 : 0;
train.Panel[26] += DeviceState == DeviceStates.Initialized && stopped && blink ? 1 : 0;
train.Panel[27] = DeviceState == DeviceStates.ATP ? 1 : 0;
- train.Panel[28] = DeviceState == DeviceStates.ATP ? 1 : 0;
+ train.Panel[28] = DeviceState == DeviceStates.ATO ? 1 : 0;
switch (AtcControlState)
{
case AtcControlStates.Released:
diff --git a/src/Devices/AtcDimetronic.cs b/src/Devices/AtcDimetronic.cs
index 0dd2068..9f6c5d5 100644
--- a/src/Devices/AtcDimetronic.cs
+++ b/src/Devices/AtcDimetronic.cs
@@ -49,8 +49,17 @@ namespace OpenbveFcmbTrainPlugin
/// The current state of the track.
private TrackStates TrackState;
- /// The maximum speed in YARD mode, in km/h.
- private readonly double YardMaximumSpeed;
+ /// The upcoming signals in the route.
+ private SignalData[] Signals;
+
+ /// The maximum speed in YARD mode.
+ private readonly Speed YardMaximumSpeed;
+
+ /// The speed limit for each signal aspect.
+ private readonly Speed[] AspectLimit = { new Speed(0), new Speed(25 / 3.6), new Speed(25 / 3.6), new Speed(25 / 3.6), new Speed(25 / 3.6), new Speed(45 / 3.6), new Speed(45 / 3.6), new Speed(45 / 3.6), new Speed(45 / 3.6), new Speed(70 / 3.6), new Speed(70 / 3.6), new Speed(70 / 3.6), new Speed(70 / 3.6) };
+
+ /// The target speed limit for each signal aspect.
+ private readonly Speed[] AspectTargetLimit = { new Speed(0), new Speed(0), new Speed(0), new Speed(25 / 3.6), new Speed(25 / 3.6), new Speed(0), new Speed(0), new Speed(45 / 3.6), new Speed(45 / 3.6), new Speed(0), new Speed(0), new Speed(70 / 3.6), new Speed(70 / 3.6) };
/// Whether ATO is available or not on the train.
private readonly bool AtoAvailable;
@@ -63,24 +72,31 @@ namespace OpenbveFcmbTrainPlugin
internal Speed WarningOn { get; private set; }
internal Speed WarningOff { get; private set; }
internal Speed TargetLimit { get; private set; }
+ internal double TargetLocation { get; private set; }
- internal SpeedCode(Speed limit, Speed target)
+ internal SpeedCode(Speed limit, Speed target, double location)
{
CurrentLimit = limit;
TargetLimit = target;
+ TargetLocation = location;
if (limit == target)
{
// Constant speed
- WarningOn = new Speed(limit.MetersPerSecond - 3 / 3.6);
- WarningOff = new Speed(limit.MetersPerSecond - 5 / 3.6);
+ WarningOn = new Speed((limit.KilometersPerHour - 3) / 3.6);
+ WarningOff = new Speed((limit.KilometersPerHour - 5) / 3.6);
}
else
{
// Reduce speed
WarningOn = target;
- WarningOff = new Speed(target.MetersPerSecond - 2 / 3.6);
+ WarningOff = new Speed((target.KilometersPerHour - 2) / 3.6);
}
}
+
+ internal SpeedCode(Speed limit, Speed target) : this(limit, target, 0)
+ {
+ }
+
}
/// The current speed code received by the train.
@@ -95,7 +111,7 @@ namespace OpenbveFcmbTrainPlugin
/// Creates an instance of the Bombardier ATC device.
/// The maximum speed in YARD mode, in km/h.
/// Whether ATO is available or not.
- internal AtcDimetronic(double yardMaxSpeed, bool atoAvailable)
+ internal AtcDimetronic(Speed yardMaxSpeed, bool atoAvailable)
{
YardMaximumSpeed = yardMaxSpeed;
AtoAvailable = atoAvailable;
@@ -114,9 +130,6 @@ namespace OpenbveFcmbTrainPlugin
DeviceState = DeviceStates.NoMode;
}
- // Update ATC movement permission
- UpdateSpeedCode();
-
double speed = train.State.Speed.KilometersPerHour;
bool stopped = speed < 0.05;
@@ -172,7 +185,7 @@ namespace OpenbveFcmbTrainPlugin
train.VigilanceOverride = false;
// Apply service/emergency brake while no driving mode is selected
AtcControlState = AtcControlStates.BrakeEmergency;
- // ATC movement permission
+ // Update ATC speed code
CurrentSpeedCode = new SpeedCode(new Speed(0), new Speed(0));
break;
// ATC device is in YARD (M+25) driving mode
@@ -206,7 +219,10 @@ namespace OpenbveFcmbTrainPlugin
train.Panel[25] = DeviceState == DeviceStates.Override ? 1 : 0;
train.Panel[26] = DeviceState == DeviceStates.YARD ? 1 : 0;
train.Panel[27] = DeviceState == DeviceStates.ATP ? 1 : 0;
+ train.Panel[28] = DeviceState == DeviceStates.ATO ? 1 : 0;
train.Panel[34] = (int)CurrentSpeedCode.CurrentLimit.KilometersPerHour * 1000;
+ train.Panel[33] = 1;
+ train.Panel[35] = (int)CurrentSpeedCode.TargetLimit.KilometersPerHour * 1000;
}
@@ -228,11 +244,13 @@ namespace OpenbveFcmbTrainPlugin
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
{
// 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 ((DeviceState >= DeviceStates.NoMode && stopped) || (DeviceState == DeviceStates.ATP && train.State.Speed.KilometersPerHour < YardMaximumSpeed.KilometersPerHour))
{
if (train.PhysicalHandles.Reverser == 1 || train.PhysicalHandles.Reverser == -1)
{
DeviceState = DeviceStates.YARD;
+ // Update ATC speed code
+ CurrentSpeedCode = new SpeedCode(YardMaximumSpeed, YardMaximumSpeed);
}
}
}
@@ -247,6 +265,8 @@ namespace OpenbveFcmbTrainPlugin
if (train.PhysicalHandles.Reverser == 1 && TrackState > TrackStates.Unprotected)
{
DeviceState = DeviceStates.ATP;
+ // Update ATC speed code
+ CurrentSpeedCode = new SpeedCode(AspectLimit[Signals[0].Aspect], AspectLimit[Signals[0].Aspect]);
}
}
}
@@ -261,6 +281,8 @@ namespace OpenbveFcmbTrainPlugin
if (train.PhysicalHandles.Reverser == 1 && TrackState > TrackStates.Unprotected)
{
DeviceState = DeviceStates.ATO;
+ // Update ATC speed code
+ CurrentSpeedCode = new SpeedCode(AspectLimit[Signals[0].Aspect], AspectLimit[Signals[0].Aspect]);
}
}
}
@@ -309,7 +331,12 @@ namespace OpenbveFcmbTrainPlugin
/// The signal data.
internal override void SetSignal(SignalData[] signal)
{
+ Signals = signal;
+ if (DeviceState == DeviceStates.ATP || DeviceState == DeviceStates.ATO)
+ {
+ CurrentSpeedCode = new SpeedCode(AspectLimit[signal[0].Aspect], AspectLimit[signal[0].Aspect]);
+ }
}
/// Is called when a beacon is passed.
@@ -400,37 +427,5 @@ namespace OpenbveFcmbTrainPlugin
break;
}
}
-
- /// Updates the data for the current speed code.
- internal void UpdateSpeedCode()
- {
- Speed zero = new Speed(0);
- Speed yard = new Speed(YardMaximumSpeed / 3.6);
-
- switch (DeviceState)
- {
- case DeviceStates.Override:
- case DeviceStates.NoMode:
- if (CurrentSpeedCode == null || CurrentSpeedCode.CurrentLimit != zero || CurrentSpeedCode.TargetLimit != zero)
- {
- CurrentSpeedCode = new SpeedCode(zero, zero);
- }
- break;
- case DeviceStates.YARD:
- if (CurrentSpeedCode == null || CurrentSpeedCode.CurrentLimit != yard || CurrentSpeedCode.TargetLimit != yard)
- {
- CurrentSpeedCode = new SpeedCode(yard, yard);
- }
- break;
- case DeviceStates.ATP:
- case DeviceStates.ATO:
- if (CurrentSpeedCode == null || CurrentSpeedCode.CurrentLimit != zero || CurrentSpeedCode.TargetLimit != zero)
- {
- CurrentSpeedCode = new SpeedCode(zero, zero);
- }
- break;
- }
- }
-
}
}
diff --git a/src/Managers/ConfigManager.cs b/src/Managers/ConfigManager.cs
index 7b27c85..50a1d77 100644
--- a/src/Managers/ConfigManager.cs
+++ b/src/Managers/ConfigManager.cs
@@ -1,4 +1,5 @@
using System;
+using OpenBveApi.Runtime;
namespace OpenbveFcmbTrainPlugin
{
@@ -29,7 +30,7 @@ namespace OpenbveFcmbTrainPlugin
internal int AtcBombardierYardSpeedLimit = 20;
internal int AtcBombardierBlinkTime = 500;
- internal int AtcDimetronicYardSpeedLimit = 25;
+ internal Speed AtcDimetronicYardSpeedLimit = new Speed(25 / 3.6);
internal bool AtcDimetronicAtoAvailable;
}
@@ -199,7 +200,7 @@ namespace OpenbveFcmbTrainPlugin
{
if (int.TryParse(Value, out int a))
{
- PluginSettings.AtcDimetronicYardSpeedLimit = a;
+ PluginSettings.AtcDimetronicYardSpeedLimit = new Speed(a / 3.6);
}
}
break;