예제 #1
0
        public Turntable(STFReader stf, Simulator simulator)
            : base(stf, simulator)
        {
            signalRef = Simulator.SignalEnvironment;
            string animation;
            Matrix position = Matrix.Identity;

            position.M44 = 100000000; //WorlPosition not yet defined, will be loaded when loading related tile;
            stf.MustMatch("(");
            stf.ParseBlock(new[] {
                new STFReader.TokenProcessor("wfile", () => {
                    WFile         = stf.ReadStringBlock(null);
                    WorldPosition = new WorldPosition(int.Parse(WFile.Substring(1, 7)), int.Parse(WFile.Substring(8, 7)), position);
                }),
                new STFReader.TokenProcessor("uid", () => { UID = stf.ReadIntBlock(-1); }),
                new STFReader.TokenProcessor("animation", () => { animation = stf.ReadStringBlock(null);
                                                                  Animations.Add(animation.ToLower()); }),
                new STFReader.TokenProcessor("diameter", () => { Length = stf.ReadFloatBlock(STFReader.Units.None, null); }),
                new STFReader.TokenProcessor("xoffset", () => { CenterOffset.X = stf.ReadFloatBlock(STFReader.Units.None, null); }),
                new STFReader.TokenProcessor("zoffset", () => { CenterOffset.Z = -stf.ReadFloatBlock(STFReader.Units.None, null); }),
                new STFReader.TokenProcessor("trackshapeindex", () =>
                {
                    TrackShapeIndex = stf.ReadIntBlock(-1);
                    InitializeAnglesAndTrackNodes();
                }),
            });
        }
예제 #2
0
        //================================================================================================//
        /// <summary>
        /// Reset train references after restore
        /// </summary>
        public void RestoreTrains(List <Train> trains, int sectionIndex)
        {
            // Occupy
            Dictionary <int[], int> tempTrains = new Dictionary <int[], int>();

            foreach (KeyValuePair <Train.TrainRouted, int> thisOccupy in OccupationState)
            {
                int[] trainKey = new int[2];
                trainKey[0] = thisOccupy.Key.Train.Number;
                trainKey[1] = thisOccupy.Key.TrainRouteDirectionIndex;
                int direction = thisOccupy.Value;
                tempTrains.Add(trainKey, direction);
            }

            OccupationState.Clear();

            foreach (KeyValuePair <int[], int> thisTemp in tempTrains)
            {
                int[] trainKey   = thisTemp.Key;
                int   number     = trainKey[0];
                int   routeIndex = trainKey[1];
                int   direction  = thisTemp.Value;
                Train thisTrain  = SignalEnvironment.FindTrain(number, trains);
                if (thisTrain != null)
                {
                    Train.TrainRouted thisTrainRouted = routeIndex == 0 ? thisTrain.RoutedForward : thisTrain.RoutedBackward;
                    OccupationState.Add(thisTrainRouted, direction);
                }
            }

            // Reserved

            if (TrainReserved != null)
            {
                int   number        = TrainReserved.Train.Number;
                Train reservedTrain = SignalEnvironment.FindTrain(number, trains);
                if (reservedTrain != null)
                {
                    int  reservedDirection = TrainReserved.TrainRouteDirectionIndex;
                    bool validreserve      = true;

                    // check if reserved section is on train's route except when train is in explorer or manual mode
                    if (reservedTrain.ValidRoute[reservedDirection].Count > 0 && reservedTrain.ControlMode != TrainControlMode.Explorer && reservedTrain.ControlMode != TrainControlMode.Manual)
                    {
                        _            = reservedTrain.ValidRoute[reservedDirection].GetRouteIndex(sectionIndex, reservedTrain.PresentPosition[Direction.Forward].RouteListIndex);
                        validreserve = reservedTrain.ValidRoute[reservedDirection].GetRouteIndex(sectionIndex, reservedTrain.PresentPosition[Direction.Forward].RouteListIndex) >= 0;
                    }

                    if (validreserve || reservedTrain.ControlMode == TrainControlMode.Explorer)
                    {
                        TrainReserved = reservedDirection == 0 ? reservedTrain.RoutedForward : reservedTrain.RoutedBackward;
                    }
                    else
                    {
                        Trace.TraceInformation("Invalid reservation for train : {0} [{1}], section : {2} not restored", reservedTrain.Name, reservedDirection, sectionIndex);
                    }
                }
                else
                {
                    TrainReserved = null;
                }
            }

            // PreReserved
            Queue <Train.TrainRouted> queue = new Queue <Train.TrainRouted>(TrainPreReserved);

            TrainPreReserved.Clear();

            foreach (Train.TrainRouted trainRouted in queue)
            {
                Train train      = SignalEnvironment.FindTrain(trainRouted.Train.Number, trains);
                int   routeIndex = trainRouted.TrainRouteDirectionIndex;
                if (train != null)
                {
                    TrainPreReserved.Enqueue(routeIndex == 0 ? train.RoutedForward : train.RoutedBackward);
                }
            }

            // Claimed
            queue = new Queue <Train.TrainRouted>(TrainClaimed);
            TrainClaimed.Clear();

            foreach (Train.TrainRouted trainRouted in queue)
            {
                Train train      = SignalEnvironment.FindTrain(trainRouted.Train.Number, trains);
                int   routeIndex = trainRouted.TrainRouteDirectionIndex;
                if (train != null)
                {
                    TrainClaimed.Enqueue(routeIndex == 0 ? train.RoutedForward : train.RoutedBackward);
                }
            }
        }