Example #1
0
        /// <summary>
        /// Gets a reference to the CTC Controller singleton
        /// </summary>
        /// <returns>Singleton reference</returns>
        public static CTCController GetCTCController()
        {
            if (m_singleton == null)
            {
                m_singleton = new CTCController();
            }

            return(m_singleton);
        }
Example #2
0
        /// <summary>
        /// Creates a new train on the track
        ///
        /// </summary>
        /// <param name="initialBlock">Starting block of the train</param>
        /// <param name="name">Name of the train</param>
        public void SpawnNewTrain(TrackBlock initialBlock, string name)
        {
            if (initialBlock != null)
            {
                if (initialBlock.HasTransponder)
                {
                    string start = initialBlock.Transponder.StationName;
                    if (start.Contains(Constants.TRAINYARD)) //Can only spawn trains from stations
                    {
                        if (m_startingDirections.ContainsKey(start))
                        {
                            m_log.LogInfoFormat("Spawning new train \"{0}\" at start {1}", name, start);
                            //Create the new train and train controller
                            ITrain train = new TrainLib.Train(name, initialBlock, m_startingDirections[start]);
                            train.TrainEnteredNewBlock += OnTrainEnteredNewBlock;
                            TrainController trainController = new TrainController(train);
                            m_trainControllerList.Add(trainController);
                            m_trainControllerTable[train] = trainController;
                            CTCController.GetCTCController().AddTrainToList(train);

                            //Set the train schedule
                            if (start == Constants.REDYARD)
                            {
                                m_log.LogInfoFormat("Setting schedule of {0} to red line", name);
                                trainController.Schedule = CTCController.GetCTCController().GetRedlineSchedule();
                            }
                            else if (start == Constants.GREENYARDOUT)
                            {
                                m_log.LogInfoFormat("Setting schedule of {0} to green line", name);
                                trainController.Schedule = CTCController.GetCTCController().GetGreenlineSchedule();
                            }
                        }
                    }
                }
            }
        }