Esempio n. 1
0
        public override IEnumerable <IModObject> Load(Mod mod)
        {
            foreach (var rec in DataFile.Records)
            {
                var m = new Mount();
                m.TemplateParameters = rec.Parameters;
                mod.Mounts.Add(m);

                m.ModID                   = rec.Get <string>("ID", m);
                m.Name                    = rec.Get <string>("Long Name", m);
                m.ShortName               = rec.Get <string>("Short Name", m) ?? m.Name;  // default to long name
                m.Description             = rec.Get <string>("Description", m);
                m.Code                    = rec.Get <string>("Code", m);
                m.PictureName             = rec.Get <string>("Pic", m);
                m.CostPercent             = rec.Get <int>("Cost Percent", m) ?? 100;
                m.SizePercent             = rec.Get <int>("Tonnage Percent", m) ?? 100;
                m.DurabilityPercent       = rec.Get <int>("Tonnage Structure Percent", m) ?? 100;
                m.WeaponDamagePercent     = rec.Get <int>("Damage Percent", m) ?? 100;
                m.SupplyUsagePercent      = rec.Get <int>("Supply Percent", m) ?? 100;
                m.WeaponRangeModifier     = rec.Get <int>("Range Modifier", m) ?? 0;
                m.WeaponAccuracyModifier  = rec.Get <int>("Weapon To Hit Modifier", m) ?? 0;
                m.MinimumVehicleSize      = rec.Get <int>("Vehicle Size Minimum", m);
                m.MaximumVehicleSize      = rec.Get <int>("Vehicle Size Maximum", m);
                m.RequiredComponentFamily = rec.Get <string>(new string[] { "Comp Family Requirement", "Component Family Requirement", "Comp Family", "Component Family" }, m);
                var wtstring = rec.Get <string>(new string[] { "Weapon Type Requirement", "Weapon Type" }, m);
                if (wtstring == null)
                {
                    m.WeaponTypes = WeaponTypes.AnyComponent;
                }
                else
                {
                    m.WeaponTypes = wtstring.Value.Capitalize().ParseEnum <WeaponTypes>();
                }
                var vtstring = rec.Get <string>(new string[] { "Vehicle Type", "Vehicle Type Requirement" }, m);
                if (vtstring == null)
                {
                    m.VehicleTypes = VehicleTypes.All;
                }
                else
                {
                    m.VehicleTypes = vtstring.Value.Capitalize().ParseEnum <VehicleTypes>();
                }
                m.AbilityPercentages = AbilityLoader.LoadPercentagesOrModifiers(rec, "Percent", m);
                m.AbilityModifiers   = AbilityLoader.LoadPercentagesOrModifiers(rec, "Modifier", m);
                m.UnlockRequirements = RequirementLoader.LoadEmpireRequirements(rec, m, RequirementType.Unlock).ToList();
                // TODO - build and use requirements

                yield return(m);
            }
        }
Esempio n. 2
0
        public override IEnumerable <IModObject> Load(Mod mod)
        {
            foreach (var rec in DataFile.Records)
            {
                var f = new FacilityTemplate();
                f.TemplateParameters = rec.Parameters;
                mod.FacilityTemplates.Add(f);

                int index = -1;

                f.ModID        = rec.Get <string>("ID", f);
                f.Name         = rec.Get <string>("Name", f);
                f.Description  = rec.Get <string>("Description", f);
                f.Group        = rec.Get <string>("Facility Group", f);
                f.Family       = rec.Get <string>("Facility Family", f);
                f.RomanNumeral = rec.Get <int>("Roman Numeral", f);
                var picfield = rec.FindField("Pic", ref index, false, 0, true);
                if (picfield != null)
                {
                    f.PictureName = picfield.Value;
                }
                else
                {
                    f.PictureName = "Facil_" + rec.Get <int>("Pic Num", f).Value.ToString("000");                    // for compatibility with SE4
                }
                foreach (var costfield in rec.Fields.Where(cf => cf.Name.StartsWith("Cost ")))
                {
                    f.Cost[Resource.Find(costfield.Name.Substring("Cost ".Length))] = costfield.CreateFormula <int>(f);
                }

                foreach (var tr in RequirementLoader.LoadEmpireRequirements(rec, f, RequirementType.Unlock))
                {
                    f.UnlockRequirements.Add(tr);
                }

                // TODO - build and use requirements

                foreach (var abil in AbilityLoader.Load(Filename, rec, f).ToArray())
                {
                    f.Abilities.Add(abil);
                }

                yield return(f);
            }
        }
Esempio n. 3
0
        public override IEnumerable <IModObject> Load(Mod mod)
        {
            foreach (var rec in DataFile.Records)
            {
                var tech = new Technology();
                tech.TemplateParameters = rec.Parameters;
                string temp;
                int    index = -1;

                tech.ModID = rec.Get <string>("ID", tech);
                rec.TryFindFieldValue("Name", out temp, ref index, Mod.Errors, 0, true);
                tech.Name = temp;
                mod.Technologies.Add(tech);

                rec.TryFindFieldValue("Group", out temp, ref index, Mod.Errors, 0, true);
                tech.Group = temp;

                rec.TryFindFieldValue("Description", out temp, ref index, Mod.Errors, 0, true);
                tech.Description = temp;

                tech.MaximumLevel = rec.Get <int>("Maximum Level", tech);
                tech.LevelCost    = rec.Get <int>("Level Cost", tech);
                tech.StartLevel   = rec.Get <int>("Start Level", tech);
                tech.RaiseLevel   = rec.Get <int>("Raise Level", tech);
                tech.RacialTechID = rec.Get <string>("Racial Area", tech);
                tech.UniqueTechID = rec.Get <string>("Unique Area", tech);
                tech.CanBeRemoved = rec.Get <bool>("Can Be Removed", tech);

                yield return(tech);
            }

            foreach (var tech in mod.Technologies)
            {
                // find this tech's record
                var rec = DataFile.Records.First(r => r.Get <string>("Name", null) == tech.Name);

                // load its tech reqs
                // couldn't do it before because some early techs can reference later techs
                foreach (var tr in RequirementLoader.LoadEmpireRequirements(rec, tech, RequirementType.Unlock))
                {
                    tech.UnlockRequirements.Add(tr);
                }
            }
        }
Esempio n. 4
0
        public override IEnumerable <IModObject> Load(Mod mod)
        {
            foreach (var rec in DataFile.Records)
            {
                IHull <IVehicle> hull;
                var hullname = rec.Get <string>("Name", null);
                var hulltype = rec.Get <string>("Vehicle Type", null);
                switch (hulltype)
                {
                case "Ship":
                    hull = new Hull <Ship>();
                    break;

                case "Base":
                    hull = new Hull <Base>();
                    break;

                case "Fighter":
                    hull = new Hull <Fighter>();
                    break;

                case "Satellite":
                    hull = new Hull <Satellite>();
                    break;

                case "Troop":
                    hull = new Hull <Troop>();
                    break;

                case "Drone":
                    hull = new Hull <Drone>();
                    break;

                case "Mine":
                    hull = new Hull <Mine>();
                    break;

                case "Weapon Platform":
                    hull = new Hull <WeaponPlatform>();
                    break;

                default:
                    Mod.Errors.Add(new DataParsingException("Invalid vehicle type \"" + hulltype + "\" specified for " + hullname + " hull.", Mod.CurrentFileName, rec));
                    continue;
                }
                hull.TemplateParameters = rec.Parameters;
                hull.ModID = rec.Get <string>("ID", hull);
                hull.Name  = hullname;
                mod.Hulls.Add(hull);

                hull.ShortName   = rec.Get <string>("Short Name", hull);
                hull.Description = rec.Get <string>("Description", hull);
                hull.Code        = rec.Get <string>("Code", hull);

                var bitmapfields = rec.Fields.Where(f => f.Name.EndsWith("Bitmap Name"));
                foreach (var f in bitmapfields)
                {
                    hull.PictureNames.Add(f.Value);
                }

                hull.Size = rec.Get <int>("Tonnage", hull);

                foreach (var costfield in rec.Fields.Where(cf => cf.Name.StartsWith("Cost ")))
                {
                    hull.Cost[Resource.Find(costfield.Name.Substring("Cost ".Length))] = costfield.CreateFormula <int>(hull);
                }

                hull.ThrustPerMove = rec.Get <int>("Engines Per Move", hull);

                foreach (var tr in RequirementLoader.LoadEmpireRequirements(rec, hull, RequirementType.Unlock))
                {
                    hull.UnlockRequirements.Add(tr);
                }

                // TODO - build and use requirements

                foreach (var abil in AbilityLoader.Load(Filename, rec, hull))
                {
                    hull.Abilities.Add(abil);
                }

                hull.NeedsBridge             = rec.Get <bool>("Requirement Must Have Bridge", hull);
                hull.CanUseAuxiliaryControl  = rec.Get <bool>("Requirement Can Have Aux Con", hull);
                hull.MinLifeSupport          = rec.Get <int>("Requirement Min Life Support", hull);
                hull.MinCrewQuarters         = rec.Get <int>("Requirement Min Crew Quarters", hull);
                hull.MaxEngines              = rec.Get <int>("Requirement Max Engines", hull);
                hull.MinPercentFighterBays   = rec.Get <int>("Requirement Pct Fighter Bays", hull);
                hull.MinPercentColonyModules = rec.Get <int>("Requirement Pct Colony Mods", hull);
                hull.MinPercentCargoBays     = rec.Get <int>("Requirement Pct Cargo", hull);

                yield return(hull);
            }
        }
Esempio n. 5
0
        public override IEnumerable <IModObject> Load(Mod mod)
        {
            foreach (var rec in DataFile.Records)
            {
                var c = new ComponentTemplate();
                c.TemplateParameters = rec.Parameters;
                mod.ComponentTemplates.Add(c);

                int index = -1;

                c.ModID       = rec.Get <string>("ID", c);
                c.Name        = rec.Get <string>("Name", c);
                c.Description = rec.Get <string>("Description", c);

                var picfield = rec.FindField("Pic", ref index, false, 0, true);
                if (picfield != null)
                {
                    c.PictureName = picfield.CreateFormula <string>(c);
                }
                else
                {
                    c.PictureName = "Comp_" + rec.Get <int>("Pic Num", c).Value.ToString("000");                    // for compatibility with SE4
                }
                c.Size       = rec.Get <int>("Tonnage Space Taken", c);
                c.Durability = rec.Get <int>("Tonnage Structure", c);

                foreach (var costfield in rec.Fields.Where(cf => cf.Name.StartsWith("Cost ")))
                {
                    c.Cost[Resource.Find(costfield.Name.Substring("Cost ".Length))] = costfield.CreateFormula <int>(c);
                }

                var vtoverridefield = rec.FindField(new string[] { "Vehicle List Type Override", "Vechicle List Type Override" }, ref index, false, 0, true);                 // silly Aaron can't spell "vehicle"
                if (vtoverridefield != null)
                {
                    c.VehicleTypes = ParseVehicleTypes(vtoverridefield.Value, ",", rec);
                }
                else
                {
                    c.VehicleTypes = ParseVehicleTypes(rec.Get <string>("Vehicle Type", c), @"\", rec);
                }

                c.SupplyUsage = rec.Get <int>("Supply Amount Used", c);

                var restrictions = rec.Get <string>("Restrictions", c);
                if (!string.IsNullOrEmpty(restrictions) && restrictions != "None")
                {
                    var word = restrictions.Value.Split(' ').First();
                    int num;
                    if (numbers.Contains(word))
                    {
                        c.MaxPerVehicle = numbers.IndexOf(word);
                    }
                    else if (int.TryParse(word, out num))
                    {
                        c.MaxPerVehicle = num;
                    }
                    else
                    {
                        Mod.Errors.Add(new DataParsingException("Can't parse \"" + word + "\" as a max-per-vehicle restriction.", Mod.CurrentFileName, rec));
                    }
                }

                c.Group                    = rec.Get <string>("General Group", c);
                c.Family                   = rec.Get <string>("Family", c);
                c.RomanNumeral             = rec.Get <int>("Roman Numeral", c);
                c.StellarConstructionGroup = rec.Get <string>("Custom Group", c);

                foreach (var tr in RequirementLoader.LoadEmpireRequirements(rec, c, RequirementType.Unlock))
                {
                    c.UnlockRequirements.Add(tr);
                }

                // TODO - build and use requirements

                foreach (var abil in AbilityLoader.Load(Filename, rec, c))
                {
                    c.Abilities.Add(abil);
                }

                var wfield = rec.FindField("Weapon Type", ref index, false, 0, true);
                if (wfield != null)
                {
                    WeaponInfo w = null;
                    if (wfield.Value == "Seeking" || wfield.Value == "Seeking Point-Defense")
                    {
                        var sw = new SeekingWeaponInfo();
                        sw.SeekerSpeed      = rec.Get <int>("Weapon Seeker Speed", c);
                        sw.SeekerDurability = rec.Get <int>("Weapon Seeker Dmg Res", c);
                        w = sw;
                    }
                    else if (wfield.Value == "Direct Fire" || wfield.Value == "Point-Defense")
                    {
                        var dfw = new DirectFireWeaponInfo();
                        dfw.AccuracyModifier = rec.Get <int>("Weapon Modifier", c);
                        w = dfw;
                    }
                    else if (wfield.Value == "Warhead" || wfield.Value == "Warhead Point-Defense")
                    {
                        var ww = new WarheadWeaponInfo();
                        w = ww;
                    }
                    else if (string.IsNullOrEmpty(wfield.Value) || wfield.Value == "None")
                    {
                        w = null;
                    }
                    else
                    {
                        Mod.Errors.Add(new DataParsingException("Invalid weapon type \"" + wfield.Value + "\".", Mod.CurrentFileName, rec, wfield));
                    }
                    if (w != null)
                    {
                        if (wfield.Value.EndsWith("Point-Defense"))
                        {
                            w.IsPointDefense = true;
                        }

                        var wtoverridefield = rec.FindField("Weapon List Target Override", ref index, false, 0, true);
                        if (wtoverridefield != null)
                        {
                            w.Targets = ParseWeaponTargets(wtoverridefield.Value, ",", rec);
                        }
                        else
                        {
                            w.Targets = ParseWeaponTargets(rec.Get <string>("Weapon Target", c), @"\", rec);
                        }

                        w.MinRange = rec.Get <int>(new string[] { "Min Range", "Minimum Range", "Weapon Min Range", "Weapon Minimum Range" }, c) ?? 0;
                        w.MaxRange = rec.Get <int>(new string[] { "Max Range", "Maximum Range", "Weapon Max Range", "Weapon Maximum Range" }, c) ?? 20;
                        var dmgfield = rec.FindField(new string[] { "Damage", "Weapon Damage", "Damage At Rng", "Weapon Damage At Rng", "Damage At Range", "Weapon Damage At Range" }, ref index);
                        if (dmgfield.Value.StartsWith("="))
                        {
                            w.Damage = dmgfield.CreateFormula <int>(c);
                        }
                        else
                        {
                            string dmgstr = null;
                            try
                            {
                                var dict  = new SafeDictionary <int, int>();
                                var split = dmgfield.Value.Split(' ');
                                for (var i = 0; i < split.Length; i++)
                                {
                                    if (split[i].ToInt() == 0)
                                    {
                                        continue;
                                    }
                                    dict[i + 1] = split[i].ToInt();
                                }

                                // HACK - SE4 doesn't explicitly specify damage at range zero so copy the damage at range one value
                                if (dict[1] != 0)
                                {
                                    dict[0]    = dict[1];
                                    w.MinRange = 0;
                                }

                                w.MinRange = dict.Keys.Min();
                                w.MaxRange = dict.Keys.Max();

                                w.Damage = dict.BuildMultiConditionalLessThanOrEqual(c, "range", 0);
                            }
                            catch (Exception ex)
                            {
                                Mod.Errors.Add(new DataParsingException("Can't parse \"" + dmgstr + "\" as a damage string: " + ex.Message, Mod.CurrentFileName, rec));
                            }
                        }

                        var damTypeName = rec.Get <string>("Weapon Damage Type", c);
                        w.DamageType = Mod.Current.DamageTypes.FindByName(damTypeName);

                        if (w.DamageType == null)
                        {
                            // no valid damage type? then make it normal damage and log a warning
                            w.DamageType = DamageType.Normal;
                            Mod.Errors.Add(new DataParsingException("Unknown damage type \"" + damTypeName + "\"; setting " + c + "'s damage type to Normal.", Mod.CurrentFileName, rec));
                        }

                        w.ReloadRate = rec.Get <double>("Weapon Reload Rate", c);

                        var wdisptype = rec.Get <string>("Weapon Display Type", c);
                        var wdispname = rec.Get <string>("Weapon Display", c);
                        if (wdisptype == "Beam")
                        {
                            w.DisplayEffect = new BeamWeaponDisplayEffect(wdispname);
                        }
                        else if (wdisptype == "Torp" || wdisptype == "Torpedo" || wdisptype == "Projectile")
                        {
                            w.DisplayEffect = new ProjectileWeaponDisplayEffect(wdispname);
                        }
                        else if (wdisptype == "Seeker")
                        {
                            w.DisplayEffect = new SeekerWeaponDisplayEffect(wdispname);
                        }
                        else
                        {
                            Mod.Errors.Add(new DataParsingException("Invalid weapon display effect type \"" + wdisptype + "\".", Mod.CurrentFileName, rec));
                        }

                        // sanity check
                        if (wdisptype == "Beam" && w is SeekingWeaponInfo)
                        {
                            Mod.Errors.Add(new DataParsingException("A seeking weapon cannot use a beam display effect.", Mod.CurrentFileName, rec));
                        }

                        w.Sound  = rec.Get <string>("Weapon Sound", c);
                        w.Family = rec.Get <string>("Weapon Family", c);
                    }
                    c.WeaponInfo = w;

                    yield return(c);
                }
            }
        }