/// <summary> /// Restores the general variable parameters /// Called from within the Simulator class. /// </summary> internal virtual void Restore(BinaryReader inf, Simulator simulator) { ContinuousMotion = inf.ReadBoolean(); GoToTarget = inf.ReadBoolean(); GoToAutoTarget = inf.ReadBoolean(); TurntableFrameRate = null; if (inf.ReadBoolean()) { TurntableFrameRate = inf.ReadInt32(); } ConnectedTrackEnd = inf.ReadInt32(); SendNotifications = inf.ReadBoolean(); InUse = inf.ReadBoolean(); relativeFrontTravellerXNALocation = RestoreVector(inf); relativeRearTravellerXNALocation = RestoreVector(inf); finalFrontTravellerXNALocation = RestoreVector(inf); finalRearTravellerXNALocation = RestoreVector(inf); int trainsOnMovingTable = inf.ReadInt32(); while (trainsOnMovingTable > 0) { TrainOnMovingTable trainOnMovingTable = new TrainOnMovingTable(null); trainOnMovingTable.Restore(inf); trainsOnMovingTable--; TrainsOnMovingTable.Add(trainOnMovingTable); } int trainsWaiting = inf.ReadInt32(); for (int waitingTrain = 0; waitingTrain < trainsWaiting - 1; waitingTrain++) { WaitingTrains.Enqueue(waitingTrain); } }
/// <summary> /// CheckTrainOnTurntable: checks if actual player train is on turntable /// </summary> public bool CheckTrainOnMovingTable(Train train) { if (train == null) { return(false); } string tableType = this is TurnTable?Simulator.Catalog.GetString("turntable") : Simulator.Catalog.GetString("transfertable"); int trainIndex = (TrainsOnMovingTable as List <TrainOnMovingTable>)?.FindIndex(x => x.Train.Number == train.Number) ?? -1; if (WorldLocation.Within(train.FrontTDBTraveller.WorldLocation, WorldPosition.WorldLocation, Length / 2)) { if (trainIndex == -1 || !TrainsOnMovingTable[trainIndex].FrontOnBoard) { if (trainIndex == -1) { TrainOnMovingTable trainOnTurntable = new TrainOnMovingTable(train); trainIndex = TrainsOnMovingTable.Count; TrainsOnMovingTable.Add(trainOnTurntable); } if (!TrainsOnMovingTable[trainIndex].BackOnBoard) { // check if turntable aligned with train bool aligned = CheckMovingTableAligned(train, true); if (!aligned) { TrainsOnMovingTable[trainIndex].SetFrontState(true); Simulator.Instance.Confirmer.Warning(Simulator.Catalog.GetString("Train slipped into non aligned {0}", tableType)); train.SetTrainOutOfControl(OutOfControlReason.SlippedIntoTurnTable); train.SpeedMpS = 0; foreach (TrainCar car in train.Cars) { car.SpeedMpS = 0; } return(false); } } if (SendNotifications) { Simulator.Instance.Confirmer.Information(Simulator.Catalog.GetString("Train front on {0}", tableType)); } } TrainsOnMovingTable[trainIndex].SetFrontState(true); } else if (trainIndex != -1 && TrainsOnMovingTable[trainIndex].FrontOnBoard) { if (SendNotifications) { Simulator.Instance.Confirmer.Information(Simulator.Catalog.GetString("Train front outside {0}", tableType)); } if (TrainsOnMovingTable[trainIndex].BackOnBoard) { TrainsOnMovingTable[trainIndex].SetFrontState(false); } else { TrainsOnMovingTable.RemoveAt(trainIndex); trainIndex = -1; } } if (WorldLocation.Within(train.RearTDBTraveller.WorldLocation, WorldPosition.WorldLocation, Length / 2)) { if (trainIndex == -1 || !TrainsOnMovingTable[trainIndex].BackOnBoard) { if (trainIndex == -1) { TrainOnMovingTable trainOnTurntable = new TrainOnMovingTable(train); trainIndex = TrainsOnMovingTable.Count; TrainsOnMovingTable.Add(trainOnTurntable); } if (!TrainsOnMovingTable[trainIndex].FrontOnBoard) { // check if turntable aligned with train bool aligned = CheckMovingTableAligned(train, false); if (!aligned) { TrainsOnMovingTable[trainIndex].SetBackState(true); Simulator.Instance.Confirmer.Warning(Simulator.Catalog.GetString("Train slipped into non aligned {0}", tableType)); train.SetTrainOutOfControl(OutOfControlReason.SlippedIntoTurnTable); train.SpeedMpS = 0; foreach (TrainCar car in train.Cars) { car.SpeedMpS = 0; } return(false); } } Simulator.Instance.Confirmer.Information(Simulator.Catalog.GetString("Train rear on {0}", tableType)); } TrainsOnMovingTable[trainIndex].SetBackState(true); } else if (trainIndex != -1 && TrainsOnMovingTable[trainIndex].BackOnBoard) { if (SendNotifications) { Simulator.Instance.Confirmer.Information(Simulator.Catalog.GetString("Train rear outside {0}", tableType)); } if (TrainsOnMovingTable[trainIndex].FrontOnBoard) { TrainsOnMovingTable[trainIndex].SetBackState(false); } else { TrainsOnMovingTable.RemoveAt(trainIndex); trainIndex = -1; } } if (Simulator.Instance.ActivityRun != null && !train.IsPathless && train.TrainType != TrainType.Static && trainIndex != -1 && TrainsOnMovingTable[trainIndex].FrontOnBoard && TrainsOnMovingTable[trainIndex].BackOnBoard && train.SpeedMpS <= 0.1f && train.ControlMode != TrainControlMode.Manual && train.TCRoute.ActiveSubPath == train.TCRoute.TCRouteSubpaths.Count - 1 && train.TCRoute.TCRouteSubpaths[train.TCRoute.ActiveSubPath].Count > 1 && (train.PresentPosition[Direction.Forward].RouteListIndex == train.TCRoute.TCRouteSubpaths[train.TCRoute.ActiveSubPath].Count - 2 || train.PresentPosition[Direction.Backward].RouteListIndex == train.TCRoute.TCRouteSubpaths[train.TCRoute.ActiveSubPath].Count - 2)) { train.IsPathless = true; } return(false); }