Skip to content

Commit e2338fd

Browse files
authored
Merge pull request #984 from Csantucci/timetable-player-train-switching-official
Player train switching for timetable mode
2 parents b9b863c + 0f8122e commit e2338fd

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

Source/Documentation/Manual/driving.rst

+13-14
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,8 @@ Changing the Train Driven by the Player
14111411
General
14121412
-------
14131413

1414-
This function only works in activity mode, and allows the player to select
1414+
This function works in activity mode as well as in timetable mode,
1415+
and allows the player to select
14151416
another (existing) train from a list and to start driving it.
14161417

14171418
This function can be called more than once. A new information window has
@@ -1453,17 +1454,20 @@ completely appeared on the screen - if it is far away from the player train
14531454
this can require several seconds to load the *world* around the train) the
14541455
switch of control occurs.
14551456

1456-
The AI train string now becomes red and is moved to the first position.The
1457-
train can be driven, or set to autopilot mode. The former player train
1458-
becomes an AI train.
1457+
The AI train string now becomes red and is moved to the first position.
1458+
In timetable mode the new player train is automatically set to autopilot mode,
1459+
while this does not apply to activity mode. However in both timetable and
1460+
activity mode the player can switch forth and back to autopilot mode.
1461+
The former player train becomes an AI train.
14591462

14601463
Here is the final situation:
14611464

14621465
.. image:: images/driving-train-list-3.png
14631466
:align: center
14641467
:scale: 80%
14651468

1466-
If the second left-click was performed with the Shift key down, the former
1469+
In activity mode only, if the second left-click was performed with the Shift
1470+
key down, the former
14671471
player train still becomes an AI train, but it is put in a suspended mode
14681472
(only if its speed is 0). It won't move until it becomes a player train
14691473
again. A suspended train is shown in orange color on the Train List window.
@@ -1472,7 +1476,8 @@ The new player train can can be switched to manual mode, can also request to
14721476
pass signals at danger with the ``<Tab>`` command, and can be moved outside
14731477
of its original path. However before switching control to still another train,
14741478
the new player train must be returned to the original path or put in suspend
1475-
mode; or else it will disappear, as occurs for AI trains running outside their
1479+
mode (last is possible only in activity mode); or else it will disappear,
1480+
as occurs for AI trains running outside their
14761481
path.
14771482

14781483
The sequence may be restarted to switch to a new train or to switch back to
@@ -1482,15 +1487,9 @@ Train switching also works in activity mode together with multiplayer mode,
14821487
in the sense that the dispatcher player can switch its played train, and
14831488
the related information is sent to the client players.
14841489

1485-
The Train List window is also available in
1486-
:ref:`Timetable mode <start-timetable>`. In this case the
1487-
names of all trains except the player train are shown in white (they can't
1488-
be driven), however with a single click on a train in the window the
1489-
external view cameras become linked to that train, as occurs with the Alt-9
1490-
command described :ref:`further below <driving-changing-view>`.
14911490

1492-
Switching to a static train
1493-
---------------------------
1491+
Switching to a static train (only activity mode)
1492+
------------------------------------------------
14941493

14951494
In the Train List window the drivable static consists (that is the ones
14961495
that have at least an engine provided with a cab) are also listed (in

Source/Orts.Simulation/Simulation/Simulator.cs

+29-4
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,13 @@ private void StartSwitchPlayerTrain()
19211921
var playerTrain = PlayerLocomotive.Train as AITrain;
19221922
if (playerTrain != null)
19231923
{
1924+
if (TimetableMode && playerTrain.ControlMode == Train.TRAIN_CONTROL.MANUAL)
1925+
{
1926+
Confirmer.Message(ConfirmLevel.Warning, Catalog.GetString("Train can't be switched if in manual mode"));
1927+
TrainSwitcher.SuspendOldPlayer = false;
1928+
TrainSwitcher.ClickedSelectedAsPlayer = false;
1929+
return;
1930+
}
19241931
if (playerTrain.ControlMode == Train.TRAIN_CONTROL.MANUAL) TrainSwitcher.SuspendOldPlayer = true; // force suspend state to avoid disappearing of train;
19251932
if (TrainSwitcher.SuspendOldPlayer &&
19261933
(playerTrain.SpeedMpS < -0.025 || playerTrain.SpeedMpS > 0.025 || playerTrain.PresentPosition[0].TCOffset != playerTrain.PreviousPosition[0].TCOffset))
@@ -1930,14 +1937,14 @@ private void StartSwitchPlayerTrain()
19301937
TrainSwitcher.ClickedSelectedAsPlayer = false;
19311938
return;
19321939
}
1933-
if (playerTrain.TrainType == Train.TRAINTYPE.AI_PLAYERDRIVEN)
1940+
if (playerTrain.TrainType == Train.TRAINTYPE.AI_PLAYERDRIVEN || !playerTrain.Autopilot)
19341941
{
19351942
// it must be autopiloted first
19361943
playerTrain.SwitchToAutopilotControl();
19371944
}
19381945
// and now switch!
19391946
playerTrain.TrainType = Train.TRAINTYPE.AI;
1940-
AI.AITrains.Add(playerTrain);
1947+
playerTrain.Autopilot = false;
19411948
if (TrainSwitcher.SuspendOldPlayer)
19421949
{
19431950
playerTrain.MovementState = AITrain.AI_MOVEMENT_STATE.SUSPENDED;
@@ -2089,6 +2096,18 @@ private void StartSwitchPlayerTrain()
20892096
PlayerLocomotive = SetPlayerLocomotive(pathlessPlayerTrain);
20902097
if (oldPlayerTrain != null) oldPlayerTrain.LeadLocomotiveIndex = -1;
20912098
}
2099+
if (TimetableMode)
2100+
{
2101+
// In timetable mode player train must have number 0
2102+
(PlayerLocomotive.Train.Number, oldPlayerTrain.Number) = (oldPlayerTrain.Number, PlayerLocomotive.Train.Number);
2103+
var oldPlayerTrainIndex = Trains.IndexOf(oldPlayerTrain);
2104+
var playerTrainIndex = Trains.IndexOf(PlayerLocomotive.Train);
2105+
(Trains[oldPlayerTrainIndex], Trains[playerTrainIndex]) = (Trains[playerTrainIndex], Trains[oldPlayerTrainIndex]);
2106+
var index = AI.AITrains.IndexOf(PlayerLocomotive.Train as AITrain);
2107+
(AI.AITrains[0], AI.AITrains[index]) = (AI.AITrains[index], AI.AITrains[0]);
2108+
AI.aiListChanged = true;
2109+
PlayerLocomotive.Train.Autopilot = true;
2110+
}
20922111
playerSwitchOngoing = true;
20932112
if (MPManager.IsMultiPlayer())
20942113
{
@@ -2107,19 +2126,25 @@ private void CompleteSwitchPlayerTrain()
21072126
{
21082127
if (PlayerLocomotive.Train.TrainType != Train.TRAINTYPE.STATIC)
21092128
{
2110-
AI.AITrains.Remove(PlayerLocomotive.Train as AITrain);
2129+
if (!TimetableMode)
2130+
AI.AITrains.Remove(PlayerLocomotive.Train as AITrain);
21112131
if ((PlayerLocomotive.Train as AITrain).MovementState == AITrain.AI_MOVEMENT_STATE.SUSPENDED)
21122132
{
21132133
PlayerLocomotive.Train.Reinitialize();
21142134
(PlayerLocomotive.Train as AITrain).MovementState = Math.Abs(PlayerLocomotive.Train.SpeedMpS) <= MaxStoppedMpS ?
21152135
AITrain.AI_MOVEMENT_STATE.INIT : AITrain.AI_MOVEMENT_STATE.BRAKING;
21162136
}
2117-
(PlayerLocomotive.Train as AITrain).SwitchToPlayerControl();
2137+
if (!TimetableMode)
2138+
(PlayerLocomotive.Train as AITrain).SwitchToPlayerControl();
2139+
else
2140+
PlayerLocomotive.Train.DisplayMessage = "";
21182141
}
21192142
else
21202143
{
21212144
PlayerLocomotive.Train.CreatePathlessPlayerTrain();
21222145
}
2146+
var playerLocomotive = PlayerLocomotive as MSTSLocomotive;
2147+
playerLocomotive.UsingRearCab = (PlayerLocomotive.Flipped ^ PlayerLocomotive.Train.MUDirection == Direction.Reverse) && (playerLocomotive.HasRearCab || playerLocomotive.HasRear3DCab);
21232148
OnPlayerLocomotiveChanged();
21242149
playerSwitchOngoing = false;
21252150
TrainSwitcher.ClickedSelectedAsPlayer = false;

Source/RunActivity/Viewer3D/Popups/TrainListWindow.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected override ControlLayout Layout(ControlLayout layout)
9191
line.Add(viewed = new TrainLabel(Owner.TextFontDefault.Height, line.RemainingHeight, Owner.Viewer, thisTrain, "*", LabelAlignment.Right));
9292
viewed.Color = Color.Red;
9393
}
94-
if (Owner.Viewer.Simulator.IsAutopilotMode && !Owner.Viewer.Simulator.TimetableMode)
94+
if (Owner.Viewer.Simulator.IsAutopilotMode)
9595
{
9696
number.Color = thisTrain.IsPlayable ? Color.LightGreen : Color.White;
9797
name.Color = thisTrain.IsPlayable ? Color.LightGreen : Color.White;
@@ -110,7 +110,7 @@ protected override ControlLayout Layout(ControlLayout layout)
110110
}
111111

112112
// Now list static trains with loco and cab
113-
if (Owner.Viewer.Simulator.IsAutopilotMode && !Owner.Viewer.Simulator.TimetableMode)
113+
if (Owner.Viewer.Simulator.IsAutopilotMode)
114114
{
115115
foreach (var thisTrain in Owner.Viewer.Simulator.Trains)
116116
{
@@ -181,7 +181,7 @@ void TrainListLabel_Click(Control arg1, Point arg2)
181181
}
182182
if (PickedTrainFromList != null && (PickedTrainFromList == Viewer.SelectedTrain || (PickedTrainFromList.TrainType == Train.TRAINTYPE.AI_INCORPORATED &&
183183
(PickedTrainFromList as AITrain).IncorporatingTrain.IsPathless && (PickedTrainFromList as AITrain).IncorporatingTrain == Viewer.SelectedTrain)) && !PickedTrainFromList.IsActualPlayerTrain &&
184-
Viewer.Simulator.IsAutopilotMode && PickedTrainFromList.IsPlayable && !Viewer.Simulator.TimetableMode)
184+
Viewer.Simulator.IsAutopilotMode && PickedTrainFromList.IsPlayable && !(Viewer.Simulator.TimetableMode && (Viewer.PlayerTrain as AITrain).MovementState == AITrain.AI_MOVEMENT_STATE.AI_STATIC))
185185
{
186186
if (UserInput.IsDown(UserCommand.GameSuspendOldPlayer) && !Viewer.Simulator.TimetableMode)
187187
Viewer.Simulator.TrainSwitcher.SuspendOldPlayer = true;

Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ void InitSimulator(UserSettings settings, string[] args, string mode, string act
11451145
// for resume and replay : set timetable file and selected train info
11461146
Simulator.TimetableFileName = System.IO.Path.GetFileNameWithoutExtension(args[0]);
11471147
Simulator.PathName = args[1];
1148+
Simulator.IsAutopilotMode = true;
11481149
}
11491150
break;
11501151
}

0 commit comments

Comments
 (0)