@@ -331,8 +331,28 @@ public enum TRAIN_CONTROL
331331 UNDEFINED
332332 }
333333
334- public TRAIN_CONTROL ControlMode = TRAIN_CONTROL.UNDEFINED; // train control mode
335- public TRAIN_CONTROL PreviousControlMode = TRAIN_CONTROL.UNDEFINED; // set when train is out of control
334+ private TRAIN_CONTROL controlMode = TRAIN_CONTROL.UNDEFINED;
335+
336+ /// <summary>
337+ /// Train control mode
338+ /// </summary>
339+ public TRAIN_CONTROL ControlMode
340+ {
341+ get => controlMode;
342+ set
343+ {
344+ if (value == TRAIN_CONTROL.OUT_OF_CONTROL && controlMode != TRAIN_CONTROL.OUT_OF_CONTROL)
345+ ControlModeBeforeOutOfControl = controlMode;
346+ else
347+ ControlModeBeforeOutOfControl = TRAIN_CONTROL.UNDEFINED;
348+ controlMode = value;
349+ }
350+ }
351+
352+ /// <summary>
353+ /// Set when the train is out of control
354+ /// </summary>
355+ private TRAIN_CONTROL ControlModeBeforeOutOfControl = TRAIN_CONTROL.UNDEFINED;
336356
337357 public enum OUTOFCONTROL
338358 {
@@ -9683,7 +9703,6 @@ public void ToggleToExplorerMode()
96839703 // set explorer mode
96849704
96859705 ControlMode = TRAIN_CONTROL.EXPLORER;
9686- PreviousControlMode = TRAIN_CONTROL.UNDEFINED;
96879706
96889707 // reset routes and check sections either end of train
96899708
@@ -9722,7 +9741,6 @@ public virtual void SwitchToSignalControl(SignalObject thisSignal)
97229741 // in auto mode, use forward direction only
97239742
97249743 ControlMode = TRAIN_CONTROL.AUTO_SIGNAL;
9725- PreviousControlMode = TRAIN_CONTROL.UNDEFINED;
97269744 thisSignal.requestClearSignal(ValidRoute[0], routedForward, 0, false, null);
97279745
97289746 // enable any none-NORMAL signals between front of train and first NORMAL signal
@@ -9798,7 +9816,6 @@ public virtual void SwitchToNodeControl(int thisSectionIndex)
97989816 int endListIndex = -1;
97999817
98009818 ControlMode = TRAIN_CONTROL.AUTO_NODE;
9801- PreviousControlMode = TRAIN_CONTROL.UNDEFINED;
98029819 EndAuthorityType[0] = END_AUTHORITY.NO_PATH_RESERVED;
98039820 IndexNextSignal = -1; // no next signal in Node Control
98049821
@@ -9961,7 +9978,6 @@ public void ToggleToManualMode()
99619978 // set manual mode
99629979
99639980 ControlMode = TRAIN_CONTROL.MANUAL;
9964- PreviousControlMode = TRAIN_CONTROL.UNDEFINED;
99659981
99669982 // reset routes and check sections either end of train
99679983
@@ -10404,7 +10420,6 @@ public void SetTrainOutOfControl(OUTOFCONTROL reason)
1040410420
1040510421 // set control state and issue warning
1040610422
10407- PreviousControlMode = ControlMode;
1040810423 ControlMode = TRAIN_CONTROL.OUT_OF_CONTROL;
1040910424
1041010425 var report = string.Format("Train {0} is out of control and will be stopped. Reason : ", Number.ToString());
@@ -10474,7 +10489,7 @@ public void ManualResetOutOfControlMode()
1047410489 case OUTOFCONTROL.SPAD:
1047510490 case OUTOFCONTROL.SPAD_REAR:
1047610491 case OUTOFCONTROL.MISALIGNED_SWITCH:
10477- switch (PreviousControlMode )
10492+ switch (ControlModeBeforeOutOfControl )
1047810493 {
1047910494 case TRAIN_CONTROL.AUTO_NODE:
1048010495 SwitchToNodeControl(PresentPosition[0].TCSectionIndex);
0 commit comments