Beispiel #1
0
 internal WotContext(GameInstallation installation, GameVersionConfig versionConfig, List <string> warnings, string defaultAuthor)
 {
     Installation    = installation;
     VersionConfig   = versionConfig;
     Warnings        = warnings;
     Tanks           = new List <WotTank>();
     ExtraProperties = new List <ExtraPropertyInfo>();
     DefaultAuthor   = defaultAuthor;
 }
Beispiel #2
0
        public WdData(GameInstallation installation, GameVersionConfig versionConfig)
        {
            Countries     = new Dictionary <string, WdCountry>();
            Warnings      = new List <string>();
            Installation  = installation;
            VersionConfig = versionConfig;

            IList <string> countries = new[] { "ussr", "germany", "usa", "france", "china", "uk", "japan", "czech", "sweden", "poland" };

            countries =
                countries.Where(
                    c =>
                    WotFileExporter.Exists(WotFileExporter.CombinePaths(installation.Path,
                                                                        versionConfig.PathVehicleList.Replace(@"""Country""", c)))).ToList();

            string scriptsFolder = string.IsNullOrEmpty(versionConfig.PathSourceScripts) ? @"res\scripts" : versionConfig.PathSourceScripts;

            foreach (var country in countries)
            {
                JsonDict tanks, engines, guns, radios, shells;
                string   path;

                path = WotFileExporter.CombinePaths(installation.Path, versionConfig.PathVehicleList.Replace(@"""Country""", country));
                try
                {
                    using (var stream = WotFileExporter.GetFileStream(path))
                    {
                        tanks = BxmlReader.ReadFile(stream);
                    }
                }
                catch (Exception e) { throw new WotDataException("Couldn't read vehicle list for country \"{0}\" from file \"{1}\"".Fmt(country, path), e); }

                path = WotFileExporter.CombinePaths(installation.Path, scriptsFolder, @"item_defs\vehicles\{0}\components\engines.xml").Fmt(country);
                try
                {
                    using (var stream = WotFileExporter.GetFileStream(path))
                    {
                        engines = BxmlReader.ReadFile(stream);
                    }
                }
                catch (Exception e) { throw new WotDataException("Couldn't read engines data for country \"{0}\" from file \"{1}\"".Fmt(country, path), e); }

                path = WotFileExporter.CombinePaths(installation.Path, scriptsFolder, @"item_defs\vehicles\{0}\components\guns.xml").Fmt(country);
                try
                {
                    using (var stream = WotFileExporter.GetFileStream(path))
                    {
                        guns = BxmlReader.ReadFile(stream);
                    }
                }
                catch (Exception e) { throw new WotDataException("Couldn't read guns data for country \"{0}\" from file \"{1}\"".Fmt(country, path), e); }

                path = WotFileExporter.CombinePaths(installation.Path, scriptsFolder, @"item_defs\vehicles\{0}\components\radios.xml").Fmt(country);
                try
                {
                    using (var stream = WotFileExporter.GetFileStream(path))
                    {
                        radios = BxmlReader.ReadFile(stream);
                    }
                }
                catch (Exception e) { throw new WotDataException("Couldn't read radios data for country \"{0}\" from file \"{1}\"".Fmt(country, path), e); }

                path = WotFileExporter.CombinePaths(installation.Path, scriptsFolder, @"item_defs\vehicles\{0}\components\shells.xml").Fmt(country);
                try
                {
                    using (var stream = WotFileExporter.GetFileStream(path))
                    {
                        shells = BxmlReader.ReadFile(stream);
                    }
                }
                catch (Exception e) { throw new WotDataException("Couldn't read shells data for country \"{0}\" from file \"{1}\"".Fmt(country, path), e); }

                // Nothing interesting in these:
                //chassis = BxmlReader.ReadFile(ZipFileExporter.CombinePaths(installation.Path, scriptsFolder, @"item_defs\vehicles\{0}\components\chassis.xml").Fmt(country));
                //turrets = BxmlReader.ReadFile(ZipFileExporter.CombinePaths(installation.Path, scriptsFolder, @"item_defs\vehicles\{0}\components\turrets.xml").Fmt(country));
                // Observe that these are the exact same pieces of information that are available directly in the vehicle definition (parsed in WdTank)

                try
                {
                    Countries.Add(country, new WdCountry(country, this, tanks, engines, guns, radios, shells));
                }
                catch (Exception e)
                {
                    throw new WotDataException("Could not parse game data for country \"{0}\"".Fmt(country), e);
                }
            }

            foreach (var country in Countries.Values)
            {
                // Link all the modules to each tank
                foreach (var tank in country.Tanks.Values)
                {
                    foreach (var key in tank.RawExtra["chassis"].GetDict().Keys)
                    {
                        tank.Chassis.Add(country.Chassis[key]);
                    }
                    foreach (var key in tank.RawExtra["turrets0"].GetDict().Keys)
                    {
                        tank.Turrets.Add(country.Turrets[key]);
                    }
                    foreach (var key in tank.RawExtra["engines"].GetDict().Keys)
                    {
                        tank.Engines.Add(country.Engines[key]);
                    }
                    foreach (var key in tank.RawExtra["radios"].GetDict().Keys)
                    {
                        if (key != "")
                        {
                            tank.Radios.Add(country.Radios[key]);
                        }
                    }
                }
                // Guns are a bit weird; it appears that there's a base definition + turret-specific overrides.
                foreach (var turret in country.Turrets.Values)
                {
                    foreach (var kvp in turret.Raw["guns"].GetDict())
                    {
                        if (!country.Guns.ContainsKey(kvp.Key))
                        {
                            Warnings.Add("Could not complete gun loading for turret “{0}”, gun “{1}”.".Fmt(turret.Id, kvp.Key));
                            continue;
                        }
                        var gun = country.Guns[kvp.Key].Clone();
                        gun.UpdateFrom(kvp.Value.GetDict(), country);
                        if (turret.Raw.ContainsKey("yawLimits")) // earlier game versions have this data in the turret record
                        {
                            var parts = turret.Raw["yawLimits"].WdString().Split(' ').Select(x => decimal.Parse(x, NumberStyles.Float, CultureInfo.InvariantCulture)).ToArray();
                            gun.YawLeftLimit  = parts[0]; // not too sure about which is which
                            gun.YawRightLimit = parts[1];
                        }
                        turret.Guns.Add(gun);
                    }
                }
                // Validate that the guns loaded fully
                foreach (var gun in country.Guns.Values)
                {
                    try { gun.Validate(); }
                    catch (Exception e) { Warnings.Add("Incomplete data for gun “{0}”: {1}".Fmt(gun.Id, e.Message)); }
                }
            }

            // Clear the string data, since it's no longer needed
            _moFiles.Clear();
            _moFiles = null;
        }