Skip to content

Commit e4cb540

Browse files
authored
Merge pull request #701 from cesarBLG/explorer-ooc
Prevent train from going to manual mode from an explorer activity
2 parents aa5f4ac + 757b1be commit e4cb540

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

Source/Orts.Simulation/Common/Scripting/TrainControlSystem.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ public abstract class TrainControlSystem : AbstractTrainScriptClass
487487
/// </summary>
488488
public Action RequestToggleManualMode;
489489
/// <summary>
490+
/// Requests reset of Out of Control Mode.
491+
/// </summary>
492+
public Action ResetOutOfControlMode;
493+
/// <summary>
490494
/// Get bool parameter in the INI file.
491495
/// </summary>
492496
public Func<string, string, bool, bool> GetBoolParameter;

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public TRAIN_CONTROL ControlMode
348348
/// <summary>
349349
/// Set when the train is out of control
350350
/// </summary>
351-
private TRAIN_CONTROL ControlModeBeforeOutOfControl = TRAIN_CONTROL.UNDEFINED;
351+
public TRAIN_CONTROL ControlModeBeforeOutOfControl = TRAIN_CONTROL.UNDEFINED;
352352

353353
public enum OUTOFCONTROL
354354
{
@@ -10193,16 +10193,14 @@ public void RequestToggleManualMode()
1019310193
}
1019410194
else if (ControlMode == TRAIN_CONTROL.EXPLORER)
1019510195
{
10196-
if (LeadLocomotive is MSTSLocomotive locomotive &&
10197-
(locomotive.TrainBrakeController.TCSEmergencyBraking || locomotive.TrainBrakeController.TCSFullServiceBraking))
10198-
{
10199-
locomotive.TrainControlSystem.HandleEvent(TCSEvent.EmergencyBrakingReleasedBySimulator);
10200-
ResetExplorerMode();
10201-
return;
10202-
}
10203-
else if (Simulator.Confirmer != null) // As Confirmer may not be created until after a restore.
10196+
if (Simulator.Confirmer != null) // As Confirmer may not be created until after a restore.
1020410197
Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("Cannot change to Manual Mode while in Explorer Mode"));
1020510198
}
10199+
else if (ControlMode == TRAIN_CONTROL.OUT_OF_CONTROL && ControlModeBeforeOutOfControl == TRAIN_CONTROL.EXPLORER)
10200+
{
10201+
if (Simulator.Confirmer != null) // As Confirmer may not be created until after a restore.
10202+
Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("Cannot change to Manual Mode. Use the Reset Out Of Control Mode command to release brakes"));
10203+
}
1020610204
else
1020710205
{
1020810206
ToggleToManualMode();

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/TrainControlSystem.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,16 @@ public void Initialize()
539539
CustomizedCabviewControlNames[id] = value;
540540
}
541541
};
542-
Script.RequestToggleManualMode = () => Locomotive.Train.RequestToggleManualMode();
542+
Script.RequestToggleManualMode = () =>
543+
{
544+
if (Locomotive.Train.ControlMode == Train.TRAIN_CONTROL.OUT_OF_CONTROL && Locomotive.Train.ControlModeBeforeOutOfControl == Train.TRAIN_CONTROL.EXPLORER)
545+
{
546+
Trace.TraceWarning("RequestToggleManualMode() is deprecated for explorer mode. Please use ResetOutOfControlMode() instead");
547+
Locomotive.Train.ManualResetOutOfControlMode();
548+
}
549+
else Locomotive.Train.RequestToggleManualMode();
550+
};
551+
Script.ResetOutOfControlMode = () => Locomotive.Train.ManualResetOutOfControlMode();
543552

544553
// TrainControlSystem INI configuration file
545554
Script.GetBoolParameter = (arg1, arg2, arg3) => LoadParameter<bool>(arg1, arg2, arg3);

Source/Orts.Simulation/Simulation/Signalling/SignalObject.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,9 @@ private void propagateRequest()
25222522
// no. of next signals to clear : as passed on -1 if signal has normal clear ahead
25232523
// if passed on < 0, use this signals num to clear
25242524

2525+
// Do not propagate the request in explorer mode, as it is handled elsewhere
2526+
if (enabledTrain != null && enabledTrain.Train.ControlMode == Train.TRAIN_CONTROL.EXPLORER) return;
2527+
25252528
// sections not available
25262529
bool validPropagationRequest = true;
25272530
if (internalBlockState > InternalBlockstate.Reservable)

0 commit comments

Comments
 (0)