@@ -315,6 +315,7 @@ public bool IsPlayerDriven
315315 }
316316 }
317317
318+ public bool Autopilot; // true if autopiloted
318319 public bool IsPlayable = false;
319320 public bool IsPathless = false;
320321
@@ -574,7 +575,7 @@ public Train(Simulator simulator)
574575 {
575576 Init(simulator);
576577
577- if (Simulator.IsAutopilotMode && TotalNumber == 1 && Simulator.TrainDictionary.Count == 0) TotalNumber = 0; //The autopiloted train has number 0
578+ if (Simulator.IsAutopilotMode && TotalNumber == 1 && Simulator.TrainDictionary.Count == 0 && !Simulator.TimetableMode ) TotalNumber = 0; //The autopiloted train has number 0
578579 Number = TotalNumber;
579580 TotalNumber++;
580581 SignalObjectItems = new List<ObjectItemInfo>();
@@ -893,6 +894,7 @@ public Train(Simulator simulator, BinaryReader inf)
893894 PreviousPosition[0] = new TCPosition();
894895 PreviousPosition[0].RestorePreviousPositionDummy(inf);
895896 }
897+ Autopilot = inf.ReadBoolean();
896898 travelled = DistanceTravelledM;
897899 int activeActions = inf.ReadInt32();
898900 for (int iAction = 0; iAction < activeActions; iAction++)
@@ -1200,6 +1202,7 @@ public virtual void Save(BinaryWriter outf)
12001202 PresentPosition[0].Save(outf);
12011203 PresentPosition[1].Save(outf);
12021204 PreviousPosition[0].Save(outf);
1205+ outf.Write(Autopilot);
12031206 // Save requiredAction, the original actions
12041207 outf.Write(requiredActions.Count);
12051208 foreach (DistanceTravelledItem thisAction in requiredActions)
@@ -1291,9 +1294,6 @@ public TrainCar GetNextCab()
12911294 // negative numbers used if rear cab selected
12921295 // because '0' has no negative, all indices are shifted by 1!!!!
12931296
1294- int presentIndex = LeadLocomotiveIndex + 1;
1295- if (((MSTSLocomotive)LeadLocomotive).UsingRearCab) presentIndex = -presentIndex;
1296-
12971297 List<int> cabList = new List<int>();
12981298
12991299 for (int i = 0; i < Cars.Count; i++)
@@ -1312,8 +1312,13 @@ public TrainCar GetNextCab()
13121312 if (hasFrontCab) cabList.Add(i + 1);
13131313 if (hasRearCab) cabList.Add(-(i + 1));
13141314 }
1315+ if (LeadLocomotiveIndex == -1 && Simulator.PlayerLocomotive == Cars[i])
1316+ LeadLocomotiveIndex = i;
13151317 }
13161318
1319+ int presentIndex = LeadLocomotiveIndex + 1;
1320+ if (((MSTSLocomotive)LeadLocomotive).UsingRearCab) presentIndex = -presentIndex;
1321+
13171322 int lastIndex = cabList.IndexOf(presentIndex);
13181323 if (lastIndex >= cabList.Count - 1) lastIndex = -1;
13191324
@@ -1339,6 +1344,8 @@ public TrainCar GetNextCab()
13391344 if (Simulator.PlayerLocomotive != null && Simulator.PlayerLocomotive.Train == this)
13401345
13411346 Simulator.PlayerLocomotive = newLead;
1347+ if (Autopilot || TrainType == TRAINTYPE.AI_PLAYERHOSTING)
1348+ LeadLocomotiveIndex = -1;
13421349
13431350 return newLead;
13441351 }
@@ -10373,7 +10380,7 @@ public virtual void SwitchToNodeControl(int thisSectionIndex)
1037310380
1037410381 public void RequestToggleManualMode()
1037510382 {
10376- if (TrainType == TRAINTYPE.AI_PLAYERHOSTING)
10383+ if (TrainType == TRAINTYPE.AI_PLAYERHOSTING || Autopilot )
1037710384 {
1037810385 if (Simulator.Confirmer != null) // As Confirmer may not be created until after a restore.
1037910386 Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("You cannot enter manual mode when autopiloted"));
@@ -21201,7 +21208,7 @@ public int ComputeStationBoardingTime(Train stopTrain)
2120121208 if (passengerCarsWithinPlatform > 0)
2120221209 {
2120321210 var actualNumPassengersWaiting = PlatformItem.NumPassengersWaiting;
21204- if (stopTrain.TrainType != TRAINTYPE.AI_PLAYERHOSTING) RandomizePassengersWaiting(ref actualNumPassengersWaiting, stopTrain);
21211+ if (stopTrain.TrainType != TRAINTYPE.AI_PLAYERHOSTING && !stopTrain.Autopilot ) RandomizePassengersWaiting(ref actualNumPassengersWaiting, stopTrain);
2120521212 stopTime = Math.Max(NumSecPerPass * actualNumPassengersWaiting / passengerCarsWithinPlatform, DefaultFreightStopTime);
2120621213 }
2120721214 else stopTime = 0; // no passenger car stopped within platform: sorry, no countdown starts
0 commit comments