示例#1
0
        private static IDictionary <string, LightTexture> ReadLightTextures(STFReader stf)
        {
            stf.MustMatch("(");
            int count = stf.ReadInt(null);
            Dictionary <string, LightTexture> lightTextures = new Dictionary <string, LightTexture>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("lighttex", () => {
                    if (lightTextures.Count >= count)
                    {
                        STFException.TraceWarning(stf, "Skipped extra LightTex");
                    }
                    else
                    {
                        LightTexture lightTexture = new LightTexture(stf);
                        if (lightTextures.ContainsKey(lightTexture.Name))
                        {
                            STFException.TraceWarning(stf, "Skipped duplicate LightTex " + lightTexture.Name);
                        }
                        else
                        {
                            lightTextures.Add(lightTexture.Name, lightTexture);
                        }
                    }
                }),
            });
            if (lightTextures.Count < count)
            {
                STFException.TraceWarning(stf, (count - lightTextures.Count).ToString() + " missing LightTex(s)");
            }
            return(lightTextures);
        }
示例#2
0
        public virtual void Parse(string lowercasetoken, STFReader stf)
        {
            switch (lowercasetoken)
            {
            case "engine(ortsbattery(mode":
            case "wagon(ortsbattery(mode":
                string text = stf.ReadStringBlock("").ToLower();
                if (text == "alwayson")
                {
                    Mode = ModeType.AlwaysOn;
                }
                else if (text == "switch")
                {
                    Mode = ModeType.Switch;
                }
                else if (text == "pushbuttons")
                {
                    Mode = ModeType.PushButtons;
                }
                else
                {
                    STFException.TraceWarning(stf, "Skipped invalid battery switch mode");
                }
                break;

            case "engine(ortsbattery(delay":
            case "wagon(ortsbattery(delay":
                DelayS = stf.ReadFloatBlock(STFReader.UNITS.Time, 0f);
                break;
            }
        }
示例#3
0
        private static IDictionary <string, SignalShape> ReadSignalShapes(STFReader stf)
        {
            stf.MustMatch("(");
            int count = stf.ReadInt(null);
            Dictionary <string, SignalShape> signalShapes = new Dictionary <string, SignalShape>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("signalshape", () => {
                    if (signalShapes.Count >= count)
                    {
                        STFException.TraceWarning(stf, "Skipped extra SignalShape");
                    }
                    else
                    {
                        SignalShape signalShape = new SignalShape(stf);
                        if (signalShapes.ContainsKey(signalShape.ShapeFileName))
                        {
                            STFException.TraceWarning(stf, "Skipped duplicate SignalShape " + signalShape.ShapeFileName);
                        }
                        else
                        {
                            signalShapes.Add(signalShape.ShapeFileName, signalShape);
                        }
                    }
                }),
            });
            if (signalShapes.Count < count)
            {
                STFException.TraceWarning(stf, (count - signalShapes.Count).ToString() + " missing SignalShape(s)");
            }
            return(signalShapes);
        }
示例#4
0
        static IDictionary <string, SignalDrawState> ReadDrawStates(STFReader stf)
        {
            stf.MustMatch("(");
            int count = stf.ReadInt(null);
            Dictionary <string, SignalDrawState> drawStates = new Dictionary <string, SignalDrawState>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("signaldrawstate", () => {
                    if (drawStates.Count >= count)
                    {
                        STFException.TraceWarning(stf, "Skipped extra SignalDrawState");
                    }
                    else
                    {
                        SignalDrawState drawState = new SignalDrawState(stf);
                        if (drawStates.ContainsKey(drawState.Name))
                        {
                            string TempNew = String.Copy("DST");
                            TempNew        = String.Concat(TempNew, drawStates.Count.ToString());
                            drawStates.Add(TempNew, drawState);
                            STFException.TraceInformation(stf, "Duplicate SignalDrawState name \'" + drawState.Name + "\', using name \'" + TempNew + "\' instead");
                        }
                        else
                        {
                            drawStates.Add(drawState.Name, drawState);
                        }
                    }
                }),
            });
            if (drawStates.Count < count)
            {
                STFException.TraceWarning(stf, (count - drawStates.Count).ToString() + " missing SignalDrawState(s)");
            }
            return(drawStates);
        }
示例#5
0
            // SigSubJnLinkIf is not supported

            /// <summary>
            /// Default constructor used during file parsing.
            /// </summary>
            /// <param name="stf">The STFreader containing the file stream</param>
            public SignalSubObj(STFReader stf)
            {
                SignalSubType = -1; // not (yet) specified
                stf.MustMatch("(");
                Index       = stf.ReadInt(null);
                MatrixName  = stf.ReadString().ToUpper();
                Description = stf.ReadString();
                stf.ParseBlock(new STFReader.TokenProcessor[] {
                    new STFReader.TokenProcessor("sigsubtype", () => { SignalSubType = SignalSubTypes.IndexOf(stf.ReadStringBlock(null).ToUpper()); }),
                    new STFReader.TokenProcessor("sigsubstype", () => { SignalSubSignalType = stf.ReadStringBlock(null).ToLowerInvariant(); }),
                    new STFReader.TokenProcessor("signalflags", () => {
                        stf.MustMatch("(");
                        while (!stf.EndOfBlock())
                        {
                            switch (stf.ReadString().ToLower())
                            {
                            case "optional": Optional = true; break;

                            case "default": Default = true; break;

                            case "back_facing": BackFacing = true; break;

                            case "jn_link": JunctionLink = true; break;

                            default: stf.StepBackOneItem(); STFException.TraceInformation(stf, "Skipped unknown SignalSubObj flag " + stf.ReadString()); break;
                            }
                        }
                    }),
                });
            }
示例#6
0
        private static IDictionary <string, LightTableEntry> ReadLightsTable(STFReader stf)
        {
            stf.MustMatch("(");
            int count = stf.ReadInt(null);
            Dictionary <string, LightTableEntry> lightsTable = new Dictionary <string, LightTableEntry>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("lightstabentry", () => {
                    if (lightsTable.Count >= count)
                    {
                        STFException.TraceWarning(stf, "Skipped extra LightsTabEntry");
                    }
                    else
                    {
                        LightTableEntry lightsTableEntry = new LightTableEntry(stf);
                        if (lightsTable.ContainsKey(lightsTableEntry.Name))
                        {
                            STFException.TraceWarning(stf, "Skipped duplicate LightsTabEntry " + lightsTableEntry.Name);
                        }
                        else
                        {
                            lightsTable.Add(lightsTableEntry.Name, lightsTableEntry);
                        }
                    }
                }),
            });
            if (lightsTable.Count < count)
            {
                STFException.TraceWarning(stf, (count - lightsTable.Count).ToString() + " missing LightsTabEntry(s)");
            }
            return(lightsTable);
        }
示例#7
0
 public TurntableFile(string filePath, string shapePath, List <MovingTable> movingTables, Simulator simulator)
 {
     using (STFReader stf = new STFReader(filePath, false))
     {
         var count = stf.ReadInt(null);
         stf.ParseBlock(new STFReader.TokenProcessor[] {
             new STFReader.TokenProcessor("turntable", () => {
                 if (--count < 0)
                 {
                     STFException.TraceWarning(stf, "Skipped extra Turntable");
                 }
                 else
                 {
                     movingTables.Add(new Turntable(stf, simulator));
                 }
             }),
             new STFReader.TokenProcessor("transfertable", () => {
                 if (--count < 0)
                 {
                     STFException.TraceWarning(stf, "Skipped extra Transfertable");
                 }
                 else
                 {
                     movingTables.Add(new Transfertable(stf, simulator));
                 }
             }),
         });
         if (count > 0)
         {
             STFException.TraceWarning(stf, count + " missing Turntable(s)");
         }
     }
 }
示例#8
0
        static IList <SignalSubObj> ReadSignalSubObjects(STFReader stf)
        {
            stf.MustMatch("(");
            int count = stf.ReadInt(null);
            List <SignalSubObj> signalSubObjects = new List <SignalSubObj>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("signalsubobj", () => {
                    if (signalSubObjects.Count >= count)
                    {
                        STFException.TraceWarning(stf, "Skipped extra SignalSubObj");
                    }
                    else
                    {
                        SignalSubObj signalSubObject = new SignalSubObj(stf);
                        if (signalSubObject.Index != signalSubObjects.Count)
                        {
                            STFException.TraceWarning(stf, "Invalid SignalSubObj index; expected " + signalSubObjects.Count + ", got " + signalSubObject.Index);
                        }
                        signalSubObjects.Add(signalSubObject);
                    }
                }),
            });
            if (signalSubObjects.Count < count)
            {
                STFException.TraceWarning(stf, (count - signalSubObjects.Count).ToString() + " missing SignalSubObj(s)");
            }
            return(signalSubObjects);
        }
示例#9
0
        public ClockList(STFReader stf, string shapePath)
        {
            var count = stf.ReadInt(null);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("clockitem", () => {
                    if (--count < 0)
                    {
                        STFException.TraceWarning(stf, "Skipped extra ClockItem");
                    }
                    else
                    {
                        var dataItem = new Clock(stf, shapePath);
                        if (File.Exists(dataItem.Name))
                        {
                            Add(dataItem);
                        }
                        else
                        {
                            STFException.TraceWarning(stf, $"Non-existent shape file {dataItem.Name} referenced");
                        }
                    }
                }),
            });
            if (count > 0)
            {
                STFException.TraceWarning(stf, count + " missing ClockItem(s)");
            }
        }
示例#10
0
 internal WorldSoundRegion(STFReader stf, TrackItem[] trItems)
 {
     TrackNodes = new List <int>();
     stf.MustMatchBlockStart();
     stf.ParseBlock(new STFReader.TokenProcessor[] {
         new STFReader.TokenProcessor("soundregiontracktype", () => { TrackType = stf.ReadIntBlock(-1); }),
         new STFReader.TokenProcessor("soundregionroty", () => { RotY = stf.ReadFloatBlock(STFReader.Units.None, float.MaxValue); }),
         new STFReader.TokenProcessor("tritemid", () => {
             stf.MustMatchBlockStart();
             stf.ReadInt(0);//dummy read
             int trItemId = stf.ReadInt(-1);
             if (trItemId != -1)
             {
                 if (trItemId >= trItems.Length)
                 {
                     STFException.TraceWarning(stf, $"Ignored invalid TrItemId {trItemId}");
                 }
                 else
                 {
                     TrackNodes.Add(trItemId);
                 }
             }
             stf.SkipRestOfBlock();
         }),
     });
 }
示例#11
0
 internal ActivitySound(STFReader stf)
 {
     stf.MustMatchBlockStart();
     stf.ParseBlock(new STFReader.TokenProcessor[] {
         new STFReader.TokenProcessor("ortsactsoundfile", () =>
         {
             stf.MustMatchBlockStart();
             string soundFile = stf.ReadString();
             SoundFile        = Path.Combine(FolderStructure.RouteFromActivity(stf.FileName).SoundFile(soundFile));
             if (!EnumExtension.GetValue(stf.ReadString(), out OrtsActivitySoundFileType soundFileType))
             {
                 stf.StepBackOneItem();
                 STFException.TraceInformation(stf, "Skipped unknown activity sound file type " + stf.ReadString());
                 SoundFileType = OrtsActivitySoundFileType.None;
             }
             else
             {
                 SoundFileType = soundFileType;
             }
             stf.MustMatchBlockEnd();
         }),
         new STFReader.TokenProcessor("ortssoundlocation", () => {
             stf.MustMatchBlockStart();
             location = new WorldLocation(stf.ReadInt(null), stf.ReadInt(null),
                                          stf.ReadFloat(STFReader.Units.None, null), stf.ReadFloat(STFReader.Units.None, null), stf.ReadFloat(STFReader.Units.None, null));
             stf.MustMatchBlockEnd();
         }),
     });
 public virtual void Parse(string lowercasetoken, STFReader stf)
 {
     switch (lowercasetoken)
     {
     case "engine(ortselectrictrainsupply(mode":
         string text = stf.ReadStringBlock("").ToLower();
         if (text == "automatic")
         {
             Mode = ModeType.Automatic;
         }
         else if (text == "unfitted")
         {
             Mode = ModeType.Unfitted;
         }
         else if (text == "switch")
         {
             Mode = ModeType.Switch;
         }
         else
         {
             STFException.TraceWarning(stf, "Skipped invalid electric train supply switch mode");
         }
         break;
     }
 }
示例#13
0
        public Interpolator(STFReader stf)
        {
            List <float> list = new List <float>();

            stf.MustMatch("(");
            while (!stf.EndOfBlock())
            {
                list.Add(stf.ReadFloat(STFReader.UNITS.Any, null));
            }
            if (list.Count % 2 == 1)
            {
                STFException.TraceWarning(stf, "Ignoring extra odd value in Interpolator list.");
            }
            int n = list.Count / 2;

            if (n < 2)
            {
                STFException.TraceWarning(stf, "Interpolator must have at least two value pairs.");
            }
            X    = new float[n];
            Y    = new float[n];
            Size = n;
            for (int i = 0; i < n; i++)
            {
                X[i] = list[2 * i];
                Y[i] = list[2 * i + 1];
                if (i > 0 && X[i - 1] >= X[i])
                {
                    STFException.TraceWarning(stf, "Interpolator x values must be increasing.");
                }
            }
        }
示例#14
0
        public CabViewControls(STFReader stf, string basePath)
        {
            stf.MustMatchBlockStart();
            int count = stf.ReadInt(null);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("dial", () => { Add(new CabViewDialControl(stf, basePath)); }),
                new STFReader.TokenProcessor("gauge", () => { Add(new CabViewGaugeControl(stf, basePath)); }),
                new STFReader.TokenProcessor("lever", () => { Add(new CabViewDiscreteControl(stf, basePath)); }),
                new STFReader.TokenProcessor("twostate", () => { Add(new CabViewDiscreteControl(stf, basePath)); }),
                new STFReader.TokenProcessor("tristate", () => { Add(new CabViewDiscreteControl(stf, basePath)); }),
                new STFReader.TokenProcessor("multistate", () => { Add(new CabViewDiscreteControl(stf, basePath)); }),
                new STFReader.TokenProcessor("multistatedisplay", () => { Add(new CabViewMultiStateDisplayControl(stf, basePath)); }),
                new STFReader.TokenProcessor("cabsignaldisplay", () => { Add(new CabViewSignalControl(stf, basePath)); }),
                new STFReader.TokenProcessor("digital", () => { Add(new CabViewDigitalControl(stf, basePath)); }),
                new STFReader.TokenProcessor("combinedcontrol", () => { Add(new CabViewDiscreteControl(stf, basePath)); }),
                new STFReader.TokenProcessor("firebox", () => { Add(new CabViewFireboxControl(stf, basePath)); }),
                new STFReader.TokenProcessor("dialclock", () => { ProcessDialClock(stf, basePath); }),
                new STFReader.TokenProcessor("digitalclock", () => { Add(new CabViewDigitalClockControl(stf, basePath)); })
            });

            if (count != Count)
            {
                STFException.TraceInformation(stf, $"CabViewControl count mismatch  - expected {count} but found {Count} controls.");
            }
        }
示例#15
0
        }                                                // true for humans

        public CarSpawnerList(STFReader stf, string shapePath, string listName)
        {
            ListName = listName;
            var count = stf.ReadInt(null);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("ignorexrotation", () => { IgnoreXRotation = stf.ReadBoolBlock(true); }),
                new STFReader.TokenProcessor("carspawneritem", () => {
                    if (--count < 0)
                    {
                        STFException.TraceWarning(stf, "Skipped extra CarSpawnerItem");
                    }
                    else
                    {
                        CarSpawner dataItem = new CarSpawner(stf, shapePath);
                        if (File.Exists(dataItem.Name))
                        {
                            Add(dataItem);
                        }
                        else
                        {
                            STFException.TraceWarning(stf, $"Non-existent shape file {dataItem.Name} referenced");
                        }
                    }
                }),
            });
            if (count > 0)
            {
                STFException.TraceWarning(stf, count + " missing CarSpawnerItem(s)");
            }
        }
示例#16
0
 public ORCarSpawnerFile(string fileName, string shapePath)
 {
     using (STFReader stf = new STFReader(fileName, false))
     {
         var    listCount = stf.ReadInt(null);
         string listName  = null;
         stf.ParseBlock(new STFReader.TokenProcessor[] {
             new STFReader.TokenProcessor("carspawnerlist", () => {
                 if (--listCount < 0)
                 {
                     STFException.TraceWarning(stf, "Skipped extra CarSpawner List");
                 }
                 else
                 {
                     stf.MustMatchBlockStart();
                     stf.MustMatch("ListName");
                     listName = stf.ReadStringBlock(null);
                     CarSpawners.Add(new CarSpawnerList(stf, shapePath, listName));
                 }
             }),
         });
         if (listCount > 0)
         {
             STFException.TraceWarning(stf, listCount + " missing CarSpawner List(s)");
         }
     }
 }
示例#17
0
        public CarSpawnerBlock(STFReader stf, string shapePath, List <CarSpawnerList> carSpawnerLists, string listName)
        {
            var spawnerDataItems = new List <CarSpawnerItemData>();
            {
                var count = stf.ReadInt(null);
                stf.ParseBlock(new STFReader.TokenProcessor[] {
                    new STFReader.TokenProcessor("carspawneritem", () => {
                        if (--count < 0)
                        {
                            STFException.TraceWarning(stf, "Skipped extra CarSpawnerItem");
                        }
                        else
                        {
                            var dataItem = new CarSpawnerItemData(stf, shapePath);
                            if (File.Exists(dataItem.name))
                            {
                                spawnerDataItems.Add(dataItem);
                            }
                            else
                            {
                                STFException.TraceWarning(stf, String.Format("Non-existent shape file {0} referenced", dataItem.name));
                            }
                        }
                    }),
                });
                if (count > 0)
                {
                    STFException.TraceWarning(stf, count + " missing CarSpawnerItem(s)");
                }
            }

            CarSpawnerList carSpawnerList = new CarSpawnerList(spawnerDataItems, listName);

            carSpawnerLists.Add(carSpawnerList);
        }
示例#18
0
        static List <SignalSubObject> ReadSignalSubObjects(STFReader stf)
        {
            stf.MustMatchBlockStart();
            int count = stf.ReadInt(null);
            List <SignalSubObject> signalSubObjects = new List <SignalSubObject>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("signalsubobj", () => {
                    if (signalSubObjects.Count >= count)
                    {
                        STFException.TraceWarning(stf, "Skipped extra SignalSubObj");
                    }
                    else
                    {
                        SignalSubObject signalSubObject = new SignalSubObject(stf);
                        if (signalSubObject.Index != signalSubObjects.Count)
                        {
                            STFException.TraceWarning(stf, $"Invalid SignalSubObj index; expected {signalSubObjects.Count}, got {signalSubObject.Index}");
                        }
                        signalSubObjects.Add(signalSubObject);
                    }
                }),
            });
            if (signalSubObjects.Count < count)
            {
                STFException.TraceWarning(stf, $"{(count - signalSubObjects.Count)} missing SignalSubObj(s)");
            }
            return(signalSubObjects);
        }
        public MSTSNotch(float v, int s, string type, STFReader stf)
        {
            Value  = v;
            Smooth = s == 0 ? false : true;
            Type   = ControllerState.Dummy;
            string lower = type.ToLower();

            if (lower.StartsWith("trainbrakescontroller"))
            {
                lower = lower.Substring(21);
            }
            if (lower.StartsWith("enginebrakescontroller"))
            {
                lower = lower.Substring(22);
            }
            switch (lower)
            {
            case "dummy": break;

            case ")": break;

            case "releasestart": Type = ControllerState.Release; break;

            case "fullquickreleasestart": Type = ControllerState.FullQuickRelease; break;

            case "runningstart": Type = ControllerState.Running; break;

            case "selflapstart": Type = ControllerState.SelfLap; break;

            case "holdstart": Type = ControllerState.Lap; break;

            case "holdlappedstart": Type = ControllerState.Lap; break;

            case "neutralhandleoffstart": Type = ControllerState.Neutral; break;

            case "graduatedselflaplimitedstart": Type = ControllerState.GSelfLap; break;

            case "graduatedselflaplimitedholdingstart": Type = ControllerState.GSelfLapH; break;

            case "applystart": Type = ControllerState.Apply; break;

            case "continuousservicestart": Type = ControllerState.ContServ; break;

            case "suppressionstart": Type = ControllerState.Suppression; break;

            case "fullservicestart": Type = ControllerState.FullServ; break;

            case "emergencystart": Type = ControllerState.Emergency; break;

            case "epapplystart": Type = ControllerState.EPApply; break;

            case "epholdstart": Type = ControllerState.Lap; break;

            case "minimalreductionstart": Type = ControllerState.Lap; break;

            default:
                STFException.TraceInformation(stf, "Skipped unknown notch type " + type);
                break;
            }
        }
示例#20
0
        private List <SignalAspect> ReadAspects(STFReader stf)
        {
            stf.MustMatchBlockStart();
            int count = stf.ReadInt(null);
            List <SignalAspect> aspects = new List <SignalAspect>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("signalaspect", () => {
                    if (aspects.Count >= aspects.Capacity)
                    {
                        STFException.TraceWarning(stf, "Skipped extra SignalAspect");
                    }
                    else
                    {
                        SignalAspect aspect = new SignalAspect(stf);
                        if (aspects.Any(sa => sa.Aspect == aspect.Aspect))
                        {
                            STFException.TraceWarning(stf, "Skipped duplicate SignalAspect " + aspect.Aspect);
                        }
                        else
                        {
                            aspects.Add(aspect);
                        }
                    }
                }),
            });
            return(aspects);
        }
示例#21
0
        /// <summary>
        /// Default constructor used during file parsing.
        /// </summary>
        /// <param name="stf">The STFreader containing the file stream</param>
        public SignalLight(STFReader stf)
        {
            stf.MustMatchBlockStart();
            Index = stf.ReadInt(null);
            Name  = stf.ReadString().ToLowerInvariant();
            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("radius", () => { Radius = stf.ReadFloatBlock(STFReader.Units.None, null); }),
                new STFReader.TokenProcessor("position", () => {
                    stf.MustMatchBlockStart();
                    position = new Vector3(stf.ReadFloat(null), stf.ReadFloat(null), stf.ReadFloat(null));
                    stf.SkipRestOfBlock();
                }),
                new STFReader.TokenProcessor("signalflags", () => {
                    stf.MustMatchBlockStart();
                    while (!stf.EndOfBlock())
                    {
                        switch (stf.ReadString().ToLower())
                        {
                        case "semaphore_change":
                            SemaphoreChange = true;
                            break;

                        default:
                            stf.StepBackOneItem();
                            STFException.TraceInformation(stf, "Skipped unknown SignalLight flag " + stf.ReadString());
                            break;
                        }
                    }
                }),
            });
        }
示例#22
0
        static List <SignalLight> ReadLights(STFReader stf)
        {
            stf.MustMatchBlockStart();
            int count = stf.ReadInt(null);
            List <SignalLight> lights = new List <SignalLight>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("signallight", () => {
                    if (lights.Count >= lights.Capacity)
                    {
                        STFException.TraceWarning(stf, "Skipped extra SignalLight");
                    }
                    else
                    {
                        lights.Add(new SignalLight(stf));
                    }
                }),
            });
            lights.Sort(SignalLight.Comparer);
            for (int i = 0; i < lights.Count; i++)
            {
                if (lights[i].Index != i)
                {
                    STFException.TraceWarning(stf, $"Invalid SignalLight index; expected {i}, got {lights[i].Index}");
                }
            }
            return(lights);
        }
示例#23
0
        private Dictionary <string, SignalDrawState> ReadDrawStates(STFReader stf)
        {
            stf.MustMatchBlockStart();
            int count = stf.ReadInt(null);
            Dictionary <string, SignalDrawState> drawStates = new Dictionary <string, SignalDrawState>(count);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("signaldrawstate", () => {
                    if (drawStates.Count >= count)
                    {
                        STFException.TraceWarning(stf, "Skipped extra SignalDrawState");
                    }
                    else
                    {
                        SignalDrawState drawState = new SignalDrawState(stf);
                        if (drawStates.ContainsKey(drawState.Name))
                        {
                            string newState = $"DST{drawStates.Count}";
                            drawStates.Add(newState, drawState);
                            STFException.TraceInformation(stf, $"Duplicate SignalDrawState name \'{drawState.Name}\', using name \'{newState}\' instead");
                        }
                        else
                        {
                            drawStates.Add(drawState.Name, drawState);
                        }
                    }
                }),
            });
            if (drawStates.Count < count)
            {
                STFException.TraceWarning(stf, (count - drawStates.Count).ToString() + " missing SignalDrawState(s)");
            }
            return(drawStates);
        }
示例#24
0
        public static Interpolator CreateInterpolator(this STFReader reader)
        {
            List <double> list = new List <double>();

            reader.MustMatchBlockStart();
            while (!reader.EndOfBlock())
            {
                list.Add(reader.ReadFloat(STFReader.Units.Any, null));
            }
            if (list.Count % 2 == 1)
            {
                STFException.TraceWarning(reader, "Ignoring extra odd value in Interpolator list.");
            }
            int n = list.Count / 2;

            if (n < 2)
            {
                STFException.TraceWarning(reader, "Interpolator must have at least two value pairs.");
            }
            double[] xArray = new double[n];
            double[] yArray = new double[n];
            for (int i = 0; i < n; i++)
            {
                xArray[i] = list[2 * i];
                yArray[i] = list[2 * i + 1];
                if (i > 0 && xArray[i - 1] >= xArray[i])
                {
                    STFException.TraceWarning(reader, "Interpolator x values must be increasing.");
                }
            }
            return(new Interpolator(xArray, yArray));
        }
示例#25
0
 public WorldSoundRegion(STFReader stf, TrItem[] trItems)
 {
     TrackNodes = new List <int>();
     stf.MustMatch("(");
     stf.ParseBlock(new STFReader.TokenProcessor[] {
         new STFReader.TokenProcessor("soundregiontracktype", () => { SoundRegionTrackType = stf.ReadIntBlock(-1); }),
         new STFReader.TokenProcessor("soundregionroty", () => { ROTy = stf.ReadFloatBlock(STFReader.UNITS.None, float.MaxValue); }),
         new STFReader.TokenProcessor("tritemid", () => {
             stf.MustMatch("(");
             var dummy    = stf.ReadInt(0);
             var trItemId = stf.ReadInt(-1);
             if (trItemId != -1)
             {
                 if (trItemId >= trItems.Length)
                 {
                     STFException.TraceWarning(stf, string.Format("Ignored invalid TrItemId {0}", trItemId));
                 }
                 else
                 {
                     TrackNodes.Add(trItemId);
                 }
             }
             stf.SkipRestOfBlock();
         }),
     });
 }
示例#26
0
        public static Interpolator2D CreateInterpolator2D(this STFReader stf)
        {
            List <double>       xlist = new List <double>();
            List <Interpolator> ilist = new List <Interpolator>();

            stf.MustMatchBlockStart();
            while (!stf.EndOfBlock())
            {
                xlist.Add(stf.ReadFloat(STFReader.Units.Any, null));
                ilist.Add(stf.CreateInterpolator());
            }
            stf.SkipRestOfBlock();
            int n = xlist.Count;

            if (n < 2)
            {
                STFException.TraceWarning(stf, "Interpolator must have at least two x values.");
            }
            double[]       xArray = new double[n];
            Interpolator[] yArray = new Interpolator[n];
            for (int i = 0; i < n; i++)
            {
                xArray[i] = xlist[i];
                yArray[i] = ilist[i];
                if (i > 0 && xArray[i - 1] >= xArray[i])
                {
                    STFException.TraceWarning(stf, " Interpolator x values must be increasing.");
                }
            }
            return(new Interpolator2D(xArray, yArray));
        }
示例#27
0
        public virtual void Parse(string lowercasetoken, STFReader stf)
        {
            switch (lowercasetoken)
            {
            case "engine(ortsmasterkey(mode":
                string text = stf.ReadStringBlock("").ToLower();
                if (text == "alwayson")
                {
                    Mode = ModeType.AlwaysOn;
                }
                else if (text == "manual")
                {
                    Mode = ModeType.Manual;
                }
                else
                {
                    STFException.TraceWarning(stf, "Skipped invalid master key mode");
                }
                break;

            case "engine(ortsmasterkey(delayoff":
                DelayS = stf.ReadFloatBlock(STFReader.UNITS.Time, 0f);
                break;

            case "engine(ortsmasterkey(headlightcontrol":
                HeadlightControl = stf.ReadBoolBlock(false);
                break;
            }
        }
示例#28
0
        public Interpolator2D(STFReader stf)
        {
            List <float>        xlist = new List <float>();
            List <Interpolator> ilist = new List <Interpolator>();

            stf.MustMatch("(");
            while (!stf.EndOfBlock())
            {
                xlist.Add(stf.ReadFloat(STFReader.UNITS.Any, null));
                ilist.Add(new Interpolator(stf));
            }
            stf.SkipRestOfBlock();
            int n = xlist.Count;

            if (n < 2)
            {
                STFException.TraceWarning(stf, "Interpolator must have at least two x values.");
            }
            X    = new float[n];
            Y    = new Interpolator[n];
            Size = n;
            for (int i = 0; i < n; i++)
            {
                X[i] = xlist[i];
                Y[i] = ilist[i];
                if (i > 0 && X[i - 1] >= X[i])
                {
                    STFException.TraceWarning(stf, " Interpolator x values must be increasing.");
                }
            }
        }
示例#29
0
        public ClockBlock(STFReader stf, string shapePath, List <ClockList> clockLists, string listName)
        {
            var clockDataItems = new List <ClockShape>();
            var count          = stf.ReadInt(null);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("clockitem", () => {
                    if (--count < 0)
                    {
                        STFException.TraceWarning(stf, "Skipped extra ClockItem");
                    }
                    else
                    {
                        var dataItem = new ClockShape(stf, shapePath);
                        if (File.Exists(shapePath + dataItem.Name))
                        {
                            clockDataItems.Add(dataItem);
                        }
                        else
                        {
                            STFException.TraceWarning(stf, String.Format("Non-existent shape file {0} referenced", dataItem.Name));
                        }
                    }
                }),
            });
            if (count > 0)
            {
                STFException.TraceWarning(stf, count + " missing ClockItem(s)");
            }
            ClockList clockList = new ClockList(clockDataItems, listName);

            clockLists.Add(clockList);
        }
示例#30
0
 public SpeedpostDatFile(string filePath, string shapePath)
 {
     using (STFReader stf = new STFReader(filePath, false))
     {
         stf.ParseBlock(new STFReader.TokenProcessor[] {
             new STFReader.TokenProcessor("speed_warning_sign_shape", () =>
             {
                 var dataItem = stf.ReadStringBlock(null);
                 if (dataItem != null)
                 {
                     dataItem = shapePath + dataItem;
                     if (File.Exists(dataItem))
                     {
                         TempSpeedShapeNames[0] = dataItem;
                     }
                     else
                     {
                         STFException.TraceWarning(stf, String.Format("Non-existent shape file {0} referenced", dataItem));
                     }
                 }
             }
                                          ),
             new STFReader.TokenProcessor("restricted_shape", () =>
             {
                 var dataItem = stf.ReadStringBlock(null);
                 if (dataItem != null)
                 {
                     dataItem = shapePath + dataItem;
                     if (File.Exists(dataItem))
                     {
                         TempSpeedShapeNames[1] = dataItem;
                     }
                     else
                     {
                         STFException.TraceWarning(stf, String.Format("Non-existent shape file {0} referenced", dataItem));
                     }
                 }
             }
                                          ),
             new STFReader.TokenProcessor("end_restricted_shape", () =>
             {
                 var dataItem = stf.ReadStringBlock(null);
                 if (dataItem != null)
                 {
                     dataItem = shapePath + dataItem;
                     if (File.Exists(dataItem))
                     {
                         TempSpeedShapeNames[2] = dataItem;
                     }
                     else
                     {
                         STFException.TraceWarning(stf, String.Format("Non-existent shape file {0} referenced", dataItem));
                     }
                 }
             }
                                          ),
         });
     }
 }