Example #1
0
        private void CheckForAvailablePatch(string FileName, ref RouteData Data, ref Expression[] Expressions, bool PreviewOnly)
        {
            if (Plugin.CurrentOptions.EnableBveTsHacks == false)
            {
                return;
            }

            string fileHash = GetChecksum(FileName);

            if (availableRoutefilePatches.ContainsKey(fileHash))
            {
                RoutefilePatch patch = availableRoutefilePatches[fileHash];
                Data.LineEndingFix   = patch.LineEndingFix;
                Data.IgnorePitchRoll = patch.IgnorePitchRoll;
                if (!string.IsNullOrEmpty(patch.LogMessage))
                {
                    Plugin.CurrentHost.AddMessage(MessageType.Warning, false, patch.LogMessage);
                }

                EnabledHacks.CylinderHack = patch.CylinderHack;
                EnabledHacks.DisableSemiTransparentFaces = patch.DisableSemiTransparentFaces;
                Data.AccurateObjectDisposal = patch.AccurateObjectDisposal;
                for (int i = 0; i < patch.ExpressionFixes.Count; i++)
                {
                    Expressions[patch.ExpressionFixes.ElementAt(i).Key].Text = patch.ExpressionFixes.ElementAt(i).Value;
                }

                if (patch.XParser != null)
                {
                    Plugin.CurrentOptions.CurrentXParser = (XParsers)patch.XParser;
                }

                Plugin.CurrentOptions.Derailments = patch.Derailments;
                Plugin.CurrentOptions.Toppling    = patch.Toppling;
                SplitLineHack = patch.SplitLineHack;
                AllowTrackPositionArguments = patch.AllowTrackPositionArguments;
                foreach (int i in patch.DummyRailTypes)
                {
                    if (Data.Structure.RailObjects == null)
                    {
                        Data.Structure.RailObjects = new ObjectDictionary();
                    }
                    Data.Structure.RailObjects.Add(i, new StaticObject(Plugin.CurrentHost));
                }
                foreach (int i in patch.DummyGroundTypes)
                {
                    if (Data.Structure.Ground == null)
                    {
                        Data.Structure.Ground = new ObjectDictionary();
                    }
                    Data.Structure.Ground.Add(i, new StaticObject(Plugin.CurrentHost));
                }

                if (!string.IsNullOrEmpty(patch.CompatibilitySignalSet) && !PreviewOnly)
                {
                    CompatibilitySignalObject.ReadCompatibilitySignalXML(Plugin.CurrentHost, patch.CompatibilitySignalSet, out Data.CompatibilitySignals, out CompatibilityObjects.SignalPost, out Data.SignalSpeeds);
                }
            }
        }
Example #2
0
        // parse route
        internal void ParseRoute(string FileName, bool isRW, System.Text.Encoding Encoding, string trainPath, string objectPath, string soundPath, bool PreviewOnly, Plugin hostPlugin)
        {
            Plugin       = hostPlugin;
            CurrentRoute = Plugin.CurrentRoute;

            /*
             * Store paths for later use
             */
            ObjectPath = objectPath;
            SoundPath  = soundPath;
            TrainPath  = trainPath;
            IsRW       = isRW;
            if (!PreviewOnly)
            {
                for (int i = 0; i < Plugin.CurrentHost.Plugins.Length; i++)
                {
                    if (Plugin.CurrentHost.Plugins[i].Object != null)
                    {
                        Plugin.CurrentHost.Plugins[i].Object.SetObjectParser(SoundPath);                         //HACK: Pass out the sound folder path to those plugins which consume it
                    }
                }
            }
            freeObjCount  = 0;
            railtypeCount = 0;
            Plugin.CurrentOptions.UnitOfSpeed           = "km/h";
            Plugin.CurrentOptions.SpeedConversionFactor = 0.0;
            CompatibilityFolder = Plugin.FileSystem.GetDataFolder("Compatibility");
            if (!PreviewOnly)
            {
                CompatibilityObjects.LoadCompatibilityObjects(Path.CombineFile(CompatibilityFolder, "CompatibilityObjects.xml"));
            }

            RoutePatchDatabaseParser.LoadRoutePatchDatabase(ref availableRoutefilePatches);

            RouteData Data = new RouteData
            {
                BlockInterval          = 25.0,
                AccurateObjectDisposal = false,
                FirstUsedBlock         = -1,
                Blocks = new List <Block>()
            };

            Data.Blocks.Add(new Block(PreviewOnly));
            Data.Blocks[0].Rails.Add(0, new Rail {
                RailStarted = true
            });
            Data.Blocks[0].RailType           = new[] { 0 };
            Data.Blocks[0].Accuracy           = 2.0;
            Data.Blocks[0].AdhesionMultiplier = 1.0;
            Data.Blocks[0].CurrentTrackState  = new TrackElement(0.0);
            if (!PreviewOnly)
            {
                Data.Blocks[0].Background = 0;
                Data.Blocks[0].Fog        = new Fog(CurrentRoute.NoFogStart, CurrentRoute.NoFogEnd, Color24.Grey, 0);
                Data.Blocks[0].Cycle      = new[] { -1 };
                Data.Blocks[0].RailCycles = new RailCycle[1];
                Data.Blocks[0].RailCycles[0].RailCycleIndex = -1;
                Data.Blocks[0].Height        = IsRW ? 0.3 : 0.0;
                Data.Blocks[0].RailFreeObj   = new Dictionary <int, List <FreeObj> >();
                Data.Blocks[0].GroundFreeObj = new List <FreeObj>();
                Data.Blocks[0].RailWall      = new Dictionary <int, WallDike>();
                Data.Blocks[0].RailDike      = new Dictionary <int, WallDike>();
                Data.Blocks[0].RailPole      = new Pole[] {};
                Data.Markers      = new Marker[] {};
                Data.RequestStops = new StopRequest[] { };
                string PoleFolder = Path.CombineDirectory(CompatibilityFolder, "Poles");
                Data.Structure.Poles = new PoleDictionary
                {
                    { 0, new ObjectDictionary() },
                    { 1, new ObjectDictionary() },
                    { 2, new ObjectDictionary() },
                    { 3, new ObjectDictionary() }
                };
                Data.Structure.Poles[0].Add(0, LoadStaticObject(Path.CombineFile(PoleFolder, "pole_1.csv"), System.Text.Encoding.UTF8, false));
                Data.Structure.Poles[1].Add(0, LoadStaticObject(Path.CombineFile(PoleFolder, "pole_2.csv"), System.Text.Encoding.UTF8, false));
                Data.Structure.Poles[2].Add(0, LoadStaticObject(Path.CombineFile(PoleFolder, "pole_3.csv"), System.Text.Encoding.UTF8, false));
                Data.Structure.Poles[3].Add(0, LoadStaticObject(Path.CombineFile(PoleFolder, "pole_4.csv"), System.Text.Encoding.UTF8, false));

                Data.Structure.RailObjects    = new ObjectDictionary();
                Data.Structure.RailObjects    = new ObjectDictionary();
                Data.Structure.Ground         = new ObjectDictionary();
                Data.Structure.WallL          = new ObjectDictionary();
                Data.Structure.WallR          = new ObjectDictionary();
                Data.Structure.DikeL          = new ObjectDictionary();
                Data.Structure.DikeR          = new ObjectDictionary();
                Data.Structure.FormL          = new ObjectDictionary();
                Data.Structure.FormR          = new ObjectDictionary();
                Data.Structure.FormCL         = new ObjectDictionary();
                Data.Structure.FormCR         = new ObjectDictionary();
                Data.Structure.RoofL          = new ObjectDictionary();
                Data.Structure.RoofR          = new ObjectDictionary();
                Data.Structure.RoofCL         = new ObjectDictionary();
                Data.Structure.RoofCR         = new ObjectDictionary();
                Data.Structure.CrackL         = new ObjectDictionary();
                Data.Structure.CrackR         = new ObjectDictionary();
                Data.Structure.FreeObjects    = new ObjectDictionary();
                Data.Structure.Beacon         = new ObjectDictionary();
                Data.Structure.Cycles         = new int[][] {};
                Data.Structure.RailCycles     = new int[][] { };
                Data.Structure.Run            = new int[] {};
                Data.Structure.Flange         = new int[] {};
                Data.Backgrounds              = new BackgroundDictionary();
                Data.TimetableDaytime         = new OpenBveApi.Textures.Texture[] { null, null, null, null };
                Data.TimetableNighttime       = new OpenBveApi.Textures.Texture[] { null, null, null, null };
                Data.Structure.WeatherObjects = new ObjectDictionary();
                // signals
                Data.Signals = new SignalDictionary();
                if (Plugin.CurrentOptions.CurrentCompatibilitySignalSet == null)                 //not selected via main form
                {
                    Plugin.CurrentOptions.CurrentCompatibilitySignalSet = Path.CombineFile(Plugin.FileSystem.GetDataFolder("Compatibility"), "Signals\\Japanese.xml");
                }
                CompatibilitySignalObject.ReadCompatibilitySignalXML(Plugin.CurrentHost, Plugin.CurrentOptions.CurrentCompatibilitySignalSet, out Data.CompatibilitySignals, out CompatibilityObjects.SignalPost, out Data.SignalSpeeds);
                // game data
                CurrentRoute.Sections = new[]
                {
                    new RouteManager2.SignalManager.Section(0, new[] { new SectionAspect(0, 0.0), new SectionAspect(4, double.PositiveInfinity) }, SectionType.IndexBased)
                };

                CurrentRoute.Sections[0].CurrentAspect = 0;
                CurrentRoute.Sections[0].StationIndex  = -1;
            }
            ParseRouteForData(FileName, Encoding, ref Data, PreviewOnly);
            if (Plugin.Cancel)
            {
                Plugin.IsLoading = false;
                return;
            }
            ApplyRouteData(FileName, ref Data, PreviewOnly);
        }