Esempio n. 1
0
        /// <summary>
        /// Restores the general variable parameters
        /// Called from within the Simulator class.
        /// </summary>
        public virtual void Restore(BinaryReader inf, Simulator simulator)
        {
            Continuous         = 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);
            var trainsOnMovingTable = inf.ReadInt32();

            while (trainsOnMovingTable > 0)
            {
                TrainOnMovingTable trainOnMovingTable = new TrainOnMovingTable(simulator);
                trainOnMovingTable.Restore(inf);
                trainsOnMovingTable--;
                TrainsOnMovingTable.Add(trainOnMovingTable);
            }

            int trainsInQ = inf.ReadInt32();

            for (int iQ = 0; iQ < trainsInQ - 1; iQ++)
            {
                Q.Enqueue(iQ);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Restores the general variable parameters
        /// Called from within the Simulator class.
        /// </summary>
        public virtual void Restore(BinaryReader inf, Simulator simulator)
        {
            Continuous        = inf.ReadBoolean();
            GoToTarget        = inf.ReadBoolean();
            ConnectedTrackEnd = inf.ReadInt32();
            RelativeFrontTravellerXNALocation = RestoreVector(inf);
            RelativeRearTravellerXNALocation  = RestoreVector(inf);
            FinalFrontTravellerXNALocation    = RestoreVector(inf);
            FinalRearTravellerXNALocation     = RestoreVector(inf);
            var trainsOnMovingTable = inf.ReadInt32();

            while (trainsOnMovingTable > 0)
            {
                TrainOnMovingTable trainOnMovingTable = new TrainOnMovingTable(simulator);
                trainOnMovingTable.Restore(inf);
                trainsOnMovingTable--;
                TrainsOnMovingTable.Add(trainOnMovingTable);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// CheckTrainOnTurntable: checks if actual player train is on turntable
        /// </summary>
        ///
        public bool CheckTrainOnMovingTable(Train train)
        {
            var thisTableType = this is Turntable?Simulator.Catalog.GetString("turntable") : Simulator.Catalog.GetString("transfertable");

            var trainIndex = TrainsOnMovingTable.FindIndex(x => x.Train.Number == train.Number);

            if (WorldLocation.Within(train.FrontTDBTraveller.WorldLocation, WorldPosition.WorldLocation, Length / 2))
            {
                if (trainIndex == -1 || !TrainsOnMovingTable[trainIndex].FrontOnBoard)
                {
                    if (trainIndex == -1)
                    {
                        var trainOnTurntable = new TrainOnMovingTable(train, Simulator);
                        trainIndex = TrainsOnMovingTable.Count;
                        TrainsOnMovingTable.Add(trainOnTurntable);
                    }
                    if (!TrainsOnMovingTable[trainIndex].BackOnBoard)
                    {
                        // check if turntable aligned with train
                        var isAligned = CheckMovingTableAligned(train, true);
                        if (!isAligned)
                        {
                            TrainsOnMovingTable[trainIndex].SetFrontState(true);
                            Simulator.Confirmer.Warning(Simulator.Catalog.GetStringFmt("Train slipped into non aligned {0}", thisTableType));
                            train.SetTrainOutOfControl(Train.OUTOFCONTROL.SLIPPED_INTO_TURNTABLE);
                            train.SpeedMpS = 0;
                            foreach (var car in train.Cars)
                            {
                                car.SpeedMpS = 0;
                            }
                            return(false);
                        }
                    }
                    if (SendNotifications)
                    {
                        Simulator.Confirmer.Information(Simulator.Catalog.GetStringFmt("Train front on {0}", thisTableType));
                    }
                }
                TrainsOnMovingTable[trainIndex].SetFrontState(true);
            }
            else
            {
                if (trainIndex != -1 && TrainsOnMovingTable[trainIndex].FrontOnBoard)
                {
                    if (SendNotifications)
                    {
                        Simulator.Confirmer.Information(Simulator.Catalog.GetStringFmt("Train front outside {0}", thisTableType));
                    }
                    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)
                    {
                        var trainOnTurntable = new TrainOnMovingTable(train, Simulator);
                        trainIndex = TrainsOnMovingTable.Count;
                        TrainsOnMovingTable.Add(trainOnTurntable);
                    }
                    if (!TrainsOnMovingTable[trainIndex].FrontOnBoard)
                    {
                        // check if turntable aligned with train
                        var isAligned = CheckMovingTableAligned(train, false);
                        if (!isAligned)
                        {
                            TrainsOnMovingTable[trainIndex].SetBackState(true);
                            Simulator.Confirmer.Warning(Simulator.Catalog.GetStringFmt("Train slipped into non aligned {0}", thisTableType));
                            train.SetTrainOutOfControl(Train.OUTOFCONTROL.SLIPPED_INTO_TURNTABLE);
                            train.SpeedMpS = 0;
                            foreach (var car in train.Cars)
                            {
                                car.SpeedMpS = 0;
                            }
                            return(false);
                        }
                    }
                    Simulator.Confirmer.Information(Simulator.Catalog.GetStringFmt("Train rear on {0}", thisTableType));
                }
                TrainsOnMovingTable[trainIndex].SetBackState(true);
            }
            else
            {
                if (trainIndex != -1 && TrainsOnMovingTable[trainIndex].BackOnBoard)
                {
                    if (SendNotifications)
                    {
                        Simulator.Confirmer.Information(Simulator.Catalog.GetStringFmt("Train rear outside {0}", thisTableType));
                    }
                    if (TrainsOnMovingTable[trainIndex].FrontOnBoard)
                    {
                        TrainsOnMovingTable[trainIndex].SetBackState(false);
                    }
                    else
                    {
                        TrainsOnMovingTable.RemoveAt(trainIndex);
                        trainIndex = -1;
                    }
                }
            }
            if (Simulator.ActivityRun != null && !train.IsPathless && train.TrainType != Train.TRAINTYPE.STATIC && trainIndex != -1 &&
                TrainsOnMovingTable[trainIndex].FrontOnBoard && TrainsOnMovingTable[trainIndex].BackOnBoard && train.SpeedMpS <= 0.1f && train.ControlMode != Train.TRAIN_CONTROL.MANUAL &&
                train.TCRoute.activeSubpath == train.TCRoute.TCRouteSubpaths.Count - 1 && train.TCRoute.TCRouteSubpaths[train.TCRoute.activeSubpath].Count > 1 &&
                (train.PresentPosition[0].RouteListIndex == train.TCRoute.TCRouteSubpaths[train.TCRoute.activeSubpath].Count - 2 ||
                 train.PresentPosition[1].RouteListIndex == train.TCRoute.TCRouteSubpaths[train.TCRoute.activeSubpath].Count - 2))
            // Activity mode, train with path is at end of it and is being rotated on the turntable
            {
                train.IsPathless = true;
            }
            return(false);
        }