@@ -311,6 +311,7 @@ public bool IsPlayerDriven
311311 }
312312 }
313313
314+ public bool Autopilot; // true if autopiloted
314315 public bool IsPlayable = false;
315316 public bool IsPathless = false;
316317
@@ -567,7 +568,7 @@ public Train(Simulator simulator)
567568 {
568569 Init(simulator);
569570
570- if (Simulator.IsAutopilotMode && TotalNumber == 1 && Simulator.TrainDictionary.Count == 0) TotalNumber = 0; //The autopiloted train has number 0
571+ if (Simulator.IsAutopilotMode && TotalNumber == 1 && Simulator.TrainDictionary.Count == 0 && !Simulator.TimetableMode ) TotalNumber = 0; //The autopiloted train has number 0
571572 Number = TotalNumber;
572573 TotalNumber++;
573574 SignalObjectItems = new List<ObjectItemInfo>();
@@ -885,6 +886,7 @@ public Train(Simulator simulator, BinaryReader inf)
885886 PreviousPosition[0] = new TCPosition();
886887 PreviousPosition[0].RestorePreviousPositionDummy(inf);
887888 }
889+ Autopilot = inf.ReadBoolean();
888890 travelled = DistanceTravelledM;
889891 int activeActions = inf.ReadInt32();
890892 for (int iAction = 0; iAction < activeActions; iAction++)
@@ -1191,6 +1193,7 @@ public virtual void Save(BinaryWriter outf)
11911193 PresentPosition[0].Save(outf);
11921194 PresentPosition[1].Save(outf);
11931195 PreviousPosition[0].Save(outf);
1196+ outf.Write(Autopilot);
11941197 // Save requiredAction, the original actions
11951198 outf.Write(requiredActions.Count);
11961199 foreach (DistanceTravelledItem thisAction in requiredActions)
@@ -1282,9 +1285,6 @@ public TrainCar GetNextCab()
12821285 // negative numbers used if rear cab selected
12831286 // because '0' has no negative, all indices are shifted by 1!!!!
12841287
1285- int presentIndex = LeadLocomotiveIndex + 1;
1286- if (((MSTSLocomotive)LeadLocomotive).UsingRearCab) presentIndex = -presentIndex;
1287-
12881288 List<int> cabList = new List<int>();
12891289
12901290 for (int i = 0; i < Cars.Count; i++)
@@ -1303,8 +1303,13 @@ public TrainCar GetNextCab()
13031303 if (hasFrontCab) cabList.Add(i + 1);
13041304 if (hasRearCab) cabList.Add(-(i + 1));
13051305 }
1306+ if (LeadLocomotiveIndex == -1 && Simulator.PlayerLocomotive == Cars[i])
1307+ LeadLocomotiveIndex = i;
13061308 }
13071309
1310+ int presentIndex = LeadLocomotiveIndex + 1;
1311+ if (((MSTSLocomotive)LeadLocomotive).UsingRearCab) presentIndex = -presentIndex;
1312+
13081313 int lastIndex = cabList.IndexOf(presentIndex);
13091314 if (lastIndex >= cabList.Count - 1) lastIndex = -1;
13101315
@@ -1329,6 +1334,8 @@ public TrainCar GetNextCab()
13291334 if (Simulator.PlayerLocomotive != null && Simulator.PlayerLocomotive.Train == this)
13301335
13311336 Simulator.PlayerLocomotive = newLead;
1337+ if (Autopilot || TrainType == TRAINTYPE.AI_PLAYERHOSTING)
1338+ LeadLocomotiveIndex = -1;
13321339
13331340 return newLead;
13341341 }
@@ -10181,7 +10188,7 @@ public virtual void SwitchToNodeControl(int thisSectionIndex)
1018110188
1018210189 public void RequestToggleManualMode()
1018310190 {
10184- if (TrainType == TRAINTYPE.AI_PLAYERHOSTING)
10191+ if (TrainType == TRAINTYPE.AI_PLAYERHOSTING || Autopilot )
1018510192 {
1018610193 if (Simulator.Confirmer != null) // As Confirmer may not be created until after a restore.
1018710194 Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("You cannot enter manual mode when autopiloted"));
@@ -21009,7 +21016,7 @@ public int ComputeStationBoardingTime(Train stopTrain)
2100921016 if (passengerCarsWithinPlatform > 0)
2101021017 {
2101121018 var actualNumPassengersWaiting = PlatformItem.NumPassengersWaiting;
21012- if (stopTrain.TrainType != TRAINTYPE.AI_PLAYERHOSTING) RandomizePassengersWaiting(ref actualNumPassengersWaiting, stopTrain);
21019+ if (stopTrain.TrainType != TRAINTYPE.AI_PLAYERHOSTING && !stopTrain.Autopilot ) RandomizePassengersWaiting(ref actualNumPassengersWaiting, stopTrain);
2101321020 stopTime = Math.Max(NumSecPerPass * actualNumPassengersWaiting / passengerCarsWithinPlatform, DefaultFreightStopTime);
2101421021 }
2101521022 else stopTime = 0; // no passenger car stopped within platform: sorry, no countdown starts
0 commit comments