Exemplo n.º 1
0
        /// <summary>
        /// Restores the general variable parameters
        /// Called from within the Simulator class.
        /// </summary>
        public void Restore(BinaryReader inf, Simulator simulator)
        {
            Continuous             = inf.ReadBoolean();
            Clockwise              = inf.ReadBoolean();
            Counterclockwise       = inf.ReadBoolean();
            YAngle                 = inf.ReadSingle();
            ForwardConnected       = inf.ReadBoolean();
            RearConnected          = inf.ReadBoolean();
            SaveForwardConnected   = inf.ReadBoolean();
            SaveRearConnected      = inf.ReadBoolean();
            ConnectedTrackEnd      = inf.ReadInt32();
            ForwardConnectedTarget = inf.ReadInt32();
            RearConnectedTarget    = inf.ReadInt32();
            GoToTarget             = inf.ReadBoolean();
            TargetY                = inf.ReadSingle();
            var trainsOnTurntable = inf.ReadInt32();

            while (trainsOnTurntable > 0)
            {
                TrainOnTurntable trainOnTurntable = new TrainOnTurntable(Simulator);
                trainOnTurntable.Restore(inf);
                trainsOnTurntable--;
            }

            RelativeFrontTravellerXNALocation = RestoreVector(inf);
            RelativeRearTravellerXNALocation  = RestoreVector(inf);
            FinalFrontTravellerXNALocation    = RestoreVector(inf);
            FinalRearTravellerXNALocation     = RestoreVector(inf);
            LastConnection    = inf.ReadBoolean();
            ConnectionToggled = inf.ReadBoolean();
        }
Exemplo n.º 2
0
        /// <summary>
        /// CheckTrainOnTurntable: checks if actual player train is on turntable
        /// </summary>
        ///
        public bool CheckTrainOnTurntable(Train train)
        {
            var trainIndex = TrainsOnTurntable.FindIndex(x => x.Train.Number == train.Number);

            if (WorldLocation.Within(train.FrontTDBTraveller.WorldLocation, WorldPosition.WorldLocation, Diameter / 2))
            {
                if (trainIndex == -1 || !TrainsOnTurntable[trainIndex].FrontOnBoard)
                {
                    if (trainIndex == -1)
                    {
                        var trainOnTurntable = new TrainOnTurntable(train, Simulator);
                        trainIndex = TrainsOnTurntable.Count;
                        TrainsOnTurntable.Add(trainOnTurntable);
                    }
                    if (!TrainsOnTurntable[trainIndex].BackOnBoard)
                    {
                        // check if turntable aligned with train
                        var isAligned = CheckTurntableAligned(train, true);
                        if (!isAligned)
                        {
                            TrainsOnTurntable[trainIndex].SetFrontState(true);
                            Simulator.Confirmer.Warning(Simulator.Catalog.GetStringFmt("Train slipped into non aligned turntable"));
                            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 front on turntable"));
                }
                TrainsOnTurntable[trainIndex].SetFrontState(true);
            }
            else
            {
                if (trainIndex != -1 && TrainsOnTurntable[trainIndex].FrontOnBoard)
                {
                    Simulator.Confirmer.Information(Simulator.Catalog.GetStringFmt("Train front outside turntable"));
                    if (TrainsOnTurntable[trainIndex].BackOnBoard)
                    {
                        TrainsOnTurntable[trainIndex].SetFrontState(false);
                    }
                    else
                    {
                        TrainsOnTurntable.RemoveAt(trainIndex);
                        trainIndex = -1;
                    }
                }
            }
            if (WorldLocation.Within(train.RearTDBTraveller.WorldLocation, WorldPosition.WorldLocation, Diameter / 2))
            {
                if (trainIndex == -1 || !TrainsOnTurntable[trainIndex].BackOnBoard)
                {
                    if (trainIndex == -1)
                    {
                        var trainOnTurntable = new TrainOnTurntable(train, Simulator);
                        trainIndex = TrainsOnTurntable.Count;
                        TrainsOnTurntable.Add(trainOnTurntable);
                    }
                    if (!TrainsOnTurntable[trainIndex].FrontOnBoard)
                    {
                        // check if turntable aligned with train
                        var isAligned = CheckTurntableAligned(train, false);
                        if (!isAligned)
                        {
                            TrainsOnTurntable[trainIndex].SetBackState(true);
                            Simulator.Confirmer.Warning(Simulator.Catalog.GetStringFmt("Train slipped into non aligned turntable"));
                            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 turntable"));
                }
                TrainsOnTurntable[trainIndex].SetBackState(true);
            }
            else
            {
                if (trainIndex != -1 && TrainsOnTurntable[trainIndex].BackOnBoard)
                {
                    Simulator.Confirmer.Information(Simulator.Catalog.GetStringFmt("Train rear outside turntable"));
                    if (TrainsOnTurntable[trainIndex].FrontOnBoard)
                    {
                        TrainsOnTurntable[trainIndex].SetBackState(false);
                    }
                    else
                    {
                        TrainsOnTurntable.RemoveAt(trainIndex);
                        trainIndex = -1;
                    }
                }
            }
            if (Simulator.ActivityRun != null && !train.IsPathless && train.TrainType != Train.TRAINTYPE.STATIC && trainIndex != -1 &&
                TrainsOnTurntable[trainIndex].FrontOnBoard && TrainsOnTurntable[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);
        }