Esempio n. 1
0
 T NextSignalItem <T>(int forsight,ref List <T> list,Train.TrainObjectItem.TRAINOBJECTTYPE type)
 {
     if (forsight < 0)
     {
         forsight = 0;
     }
     if (forsight >= list.Count)
     {
         SearchTrainInfo(forsight,type);
     }
     return(list[forsight < list.Count ? forsight : list.Count - 1]);
 }
Esempio n. 2
0
        void SearchTrainInfo(float forsight,Train.TrainObjectItem.TRAINOBJECTTYPE searchFor)
        {
            if (SignalSpeedLimits.Count == 0)
            {
                TrainInfo = Locomotive.Train.GetTrainInfo();
            }

            var signalsFound = 0;
            var postsFound   = 0;

            foreach (var foundItem in Locomotive.Train.MUDirection == Direction.Reverse ? TrainInfo.ObjectInfoBackward : TrainInfo.ObjectInfoForward)
            {
                switch (foundItem.ItemType)
                {
                case Train.TrainObjectItem.TRAINOBJECTTYPE.SIGNAL:
                    signalsFound++;
                    if (signalsFound > SignalSpeedLimits.Count)
                    {
                        SignalSpeedLimits.Add(foundItem.AllowedSpeedMpS);
                        SignalAspects.Add((Aspect)foundItem.SignalState);
                        SignalDistances.Add(foundItem.DistanceToTrainM);
                    }
                    break;

                case Train.TrainObjectItem.TRAINOBJECTTYPE.SPEEDPOST:
                    postsFound++;
                    if (postsFound > PostSpeedLimits.Count)
                    {
                        PostSpeedLimits.Add(foundItem.AllowedSpeedMpS);
                        PostDistances.Add(foundItem.DistanceToTrainM);
                    }
                    break;

                case Train.TrainObjectItem.TRAINOBJECTTYPE.AUTHORITY:
                    signalsFound++;
                    if (signalsFound > SignalSpeedLimits.Count)
                    {
                        SignalSpeedLimits.Add(0f);
                        SignalAspects.Add(Aspect.Stop);
                        SignalDistances.Add(foundItem.DistanceToTrainM);
                    }
                    break;
                }

                if (searchFor == Train.TrainObjectItem.TRAINOBJECTTYPE.SIGNAL && signalsFound > forsight ||
                    searchFor == Train.TrainObjectItem.TRAINOBJECTTYPE.SPEEDPOST && postsFound > forsight)
                {
                    break;
                }
            }

            if (searchFor == Train.TrainObjectItem.TRAINOBJECTTYPE.SIGNAL && signalsFound == 0)
            {
                SignalSpeedLimits.Add(-1);
                SignalAspects.Add(Aspect.None);
                SignalDistances.Add(float.MaxValue);
            }
            if (searchFor == Train.TrainObjectItem.TRAINOBJECTTYPE.SPEEDPOST && postsFound == 0)
            {
                PostSpeedLimits.Add(-1);
                PostDistances.Add(float.MaxValue);
            }
        }