public static void newmap() { JArray jarray = JArray.Parse(File.ReadAllText(@"C:\Program Files (x86)\Steam\steamapps\common\BATTLETECH\mods\OldData\systems.json")); string newdata = File.ReadAllText(@"C:\Program Files (x86)\Steam\steamapps\common\BATTLETECH\mods\OldData\planetstest.json"); JArray newdataArray = JArray.Parse(newdata); foreach (JObject system in jarray) { if (!((string)system["affiliation"]).Equals("Clans") && !((string)system["affiliation"]).Equals("Inhabited system") && !((string)system["affiliation"]).Equals("No record") && !((string)system["affiliation"]).Equals("Clan") && !((string)system["affiliation"]).Equals("New Delphi Compact") && !((string)system["affiliation"]).Equals("Alexandrian Covenant") && !((string)system["affiliation"]).Equals("Society of St.Andreas") && !((string)system["affiliation"]).Equals("Hidden system") && !((string)system["affiliation"]).Equals("Society of St. Andreas") && !((string)system["affiliation"]).Equals("Tortuga Dominions") && !((string)system["affiliation"]).Equals("Fiefdom of Randis") && !((string)system["name"]).Equals("New St. Andrews") && !((string)system["name"]).Equals("Mica I") && !((string)system["name"]).Equals("Mica V") && !((string)system["name"]).Equals("Novo Franklin") && !((string)system["name"]).Equals("New Vandenberg") && !((string)system["name"]).Equals("Mica VII")) { FakeVector3 vector = new FakeVector3(); vector.x = (float)system["x"]; vector.y = (float)system["y"]; vector.z = 0; Faction faction; string folder = ""; TagSet tags = new TagSet(); int maxspecials = 0; switch ((string)system["affiliation"]) { case "Lyran Commonwealth": maxspecials++; faction = Faction.Steiner; folder = "Steiner"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_steiner"); break; case "Free Worlds League": maxspecials++; faction = Faction.Marik; folder = "Marik"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_marik"); break; case "Draconis Combine": maxspecials++; faction = Faction.Kurita; folder = "Kurita"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_kurita"); break; case "Federated Suns": maxspecials++; faction = Faction.Davion; folder = "Davion"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_davion"); break; case "Capellan Confederation": maxspecials++; faction = Faction.Liao; folder = "Liao"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_liao"); break; case "Aurigan Coalition": faction = Faction.AuriganRestoration; folder = "Aurigan"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_restoration"); break; case "ComStar": maxspecials++; faction = Faction.ComStar; folder = "ComStar"; tags.Add("planet_civ_innersphere"); break; case "Magistracy of Canopus": faction = Faction.MagistracyOfCanopus; folder = "Magistracy"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_magistracy"); break; case "Taurian Concordat": faction = Faction.TaurianConcordat; folder = "Taurian"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_taurian"); break; case "Outworlds Alliance": faction = Faction.Betrayers; folder = "Outworld"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_outworlds"); break; case "Marian Hegemony": faction = Faction.AuriganDirectorate; folder = "Hegemony"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_marian"); break; case "Oberon Confederation": faction = Faction.MagistracyCentrella; folder = "Oberon"; maxspecials++; tags.Add("planet_civ_periphery"); tags.Add("planet_other_pirate"); tags.Add("planet_other_blackmarket"); tags.Add("planet_faction_oberon"); break; case "Lothian League": faction = Faction.MajestyMetals; folder = "Lothian"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_lothian"); break; case "Circinus Federation": faction = Faction.Nautilus; folder = "Circinus"; maxspecials++; tags.Add("planet_civ_periphery"); tags.Add("planet_other_pirate"); tags.Add("planet_other_blackmarket"); tags.Add("planet_faction_circinus"); break; case "Illyrian Palatinate": faction = Faction.AuriganMercenaries; folder = "Illyrian"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_illyrian"); break; default: faction = Faction.Locals; folder = "Locals"; tags.Add("planet_civ_periphery"); break; } if (((string)system["name"]).Equals("Galatea")) { faction = Faction.MercenaryReviewBoard; folder = "MRB"; tags.Remove("planet_faction_steiner"); } string beginjson = File.ReadAllText("C:/Users/morph/Desktop/Neuer Ordner (4)/starsystemdef_Detroit.json"); string name = (string)system["name"]; StarSystemDef def = new StarSystemDef(); def.FromJSON(beginjson); bool fueling = false; string details = " "; List <Biome.BIOMESKIN> biomes = new List <Biome.BIOMESKIN>();; bool newdatafound = false; foreach (JObject newdataObject in newdataArray) { biomes = new List <Biome.BIOMESKIN>(); if (system["name"].Equals(newdataObject["Planet_Name"])) { newdatafound = true; if (!string.IsNullOrEmpty((string)newdataObject["Description"])) { details = ((string)newdataObject["Description"]).Replace("\t", "").Replace("\\", "").Replace("</P>", "").Replace("<P>", "").Replace("\r", "").Replace("\n", "").Replace("</p>", "").Replace("<p>", ""); if (details.Length > 255) { details = details.Substring(0, 255); } } if ((int)newdataObject["Industry"] != 0) { tags.Add("planet_industry_mining"); if ((int)newdataObject["Industry"] >= 100000000) { maxspecials++; tags.Add("planet_industry_rich"); } else { tags.Add("planet_industry_recreation"); } } else { tags.Add("planet_industry_agriculture"); tags.Add("planet_industry_aquaculture"); tags.Add("planet_industry_poor"); } if (!string.IsNullOrEmpty((string)newdataObject["comstar_facility"]) && !((string)newdataObject["comstar_facility"]).Equals("None")) { tags.Add("planet_industry_research"); tags.Add("planet_other_comstar"); tags.Add("planet_other_starleague"); maxspecials++; } if ((int)newdataObject["Capital_Planet"] == 1) { tags.Add("planet_other_capital"); maxspecials++; } if ((long)newdataObject["population"] > 1000000000) { tags.Add("planet_pop_large"); maxspecials++; maxspecials++; if ((long)newdataObject["population"] > 5000000000) { tags.Add("planet_other_megacity"); maxspecials++; } } else if ((int)newdataObject["population"] > 100000000) { tags.Add("planet_pop_medium"); maxspecials++; } else if ((int)newdataObject["population"] > 1000000) { tags.Add("planet_pop_small"); } else { tags.Add("planet_pop_none"); } if ((int)newdataObject["Charge_Station"] == 1) { fueling = true; } if ((int)newdataObject["Factory"] == 123) { tags.Add("planet_industry_manufacturing"); maxspecials++; maxspecials++; } if ((int)newdataObject["hiringhall"] == 1) { tags.Add("planet_other_hub"); } switch ((int)newdataObject["terrain_class_ID"]) { case 1: { tags.Add("planet_climate_terran"); tags.Add("planet_other_megaforest"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); biomes.Add(Biome.BIOMESKIN.badlandsParched); break; } case 2: { tags.Add("planet_climate_lunar"); tags.Add("planet_other_moon"); biomes.Add(Biome.BIOMESKIN.martianVacuum); biomes.Add(Biome.BIOMESKIN.lunarVacuum); break; } case 3: { tags.Add("planet_climate_desert"); tags.Add("planet_other_storms"); biomes.Add(Biome.BIOMESKIN.desertParched); break; } case 4: { tags.Add("planet_climate_arid"); tags.Add("planet_other_mudflats"); tags.Add("planet_other_fungus"); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.badlandsParched); break; } case 5: { tags.Add("planet_climate_arctic"); biomes.Add(Biome.BIOMESKIN.polarFrozen); biomes.Add(Biome.BIOMESKIN.tundraFrozen); break; } case 6: { tags.Add("planet_climate_tropical"); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); break; } case 7: { tags.Add("planet_climate_rocky"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); break; } case 8: { tags.Add("planet_climate_mars"); tags.Add("planet_other_volcanic"); biomes.Add(Biome.BIOMESKIN.martianVacuum); biomes.Add(Biome.BIOMESKIN.badlandsParched); break; } case 10: { tags.Add("planet_climate_terran"); tags.Add("planet_other_megaforest"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); break; } case 18: { tags.Add("planet_climate_water"); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.highlandsSpring); break; } default: { tags.Add("planet_climate_terran"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); biomes.Add(Biome.BIOMESKIN.desertParched); biomes.Add(Biome.BIOMESKIN.badlandsParched); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.lunarVacuum); biomes.Add(Biome.BIOMESKIN.martianVacuum); biomes.Add(Biome.BIOMESKIN.polarFrozen); biomes.Add(Biome.BIOMESKIN.tundraFrozen); break; } } break; } } if (newdatafound) { tags.Add("planet_size_medium"); } else { tags.Add("planet_climate_terran"); tags.Add("planet_size_medium"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); biomes.Add(Biome.BIOMESKIN.desertParched); biomes.Add(Biome.BIOMESKIN.badlandsParched); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.lunarVacuum); biomes.Add(Biome.BIOMESKIN.martianVacuum); biomes.Add(Biome.BIOMESKIN.polarFrozen); biomes.Add(Biome.BIOMESKIN.tundraFrozen); } DescriptionDef desc = new DescriptionDef(("starsystemdef_" + system["name"]).Replace(" ", string.Empty).Replace("'", string.Empty), (string)system["name"], details, "", 0, 0, false, "", "", ""); StarSystemDef def2 = new StarSystemDef(desc, vector, tags, false, 7, faction, getAllies(faction), getEnemies(faction), def.SystemInfluence, def.TravelRequirements); foreach (JObject newdataObject in newdataArray) { if (system["name"].Equals(newdataObject["Planet_Name"])) { break; } } ReflectionHelper.InvokePrivateMethode(def2, "set_FuelingStation", new object[] { fueling }); ReflectionHelper.InvokePrivateMethode(def2, "set_Difficulty", new object[] { 5 }); ReflectionHelper.InvokePrivateMethode(def2, "set_StarType", new object[] { StarType.G }); ReflectionHelper.InvokePrivateMethode(def2, "set_JumpDistance", new object[] { 7 }); ReflectionHelper.InvokePrivateMethode(def2, "set_ShopMaxSpecials", new object[] { maxspecials }); ReflectionHelper.InvokePrivateMethode(def2, "set_SupportedBiomes", new object[] { biomes }); foreach (JObject newdataObject in newdataArray) { if (system["name"].Equals(newdataObject["Planet_Name"])) { ReflectionHelper.InvokePrivateMethode(def2, "set_StarType", new object[] { getStartype((string)newdataObject["SpecClass"]) }); if ((float)newdataObject["travel_time"] != 0f) { ReflectionHelper.InvokePrivateMethode(def2, "set_JumpDistance", new object[] { (int)newdataObject["travel_time"] }); } break; } } string json = def2.ToJSON(); JObject jsonObject = JObject.Parse(json); JObject descriptionjson = (JObject)jsonObject["Description"]; descriptionjson.Add("Id", "starsystemdef_" + ((string)system["name"]).Replace(" ", string.Empty).Replace("'", string.Empty)); descriptionjson.Add("Name", (string)system["name"]); descriptionjson.Add("Details", details); // string json = JsonConvert.SerializeObject(def2, new Newtonsoft.Json.Converters.StringEnumConverter()); string path = "C:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/mods/OldData/" + folder + "/starsystemdef_" + ((string)system["name"]).Replace(" ", string.Empty).Replace("'", string.Empty) + ".json"; (new FileInfo(path)).Directory.Create(); File.WriteAllText(path, jsonObject.ToString()); } } }
public static (StarSystem, FactionValue) getAttackerAndLocation(string type) { Settings s = WIIC.settings; var weightedLocations = new Dictionary <(StarSystem, FactionValue), double>(); var reputations = new Dictionary <FactionValue, double>(); var aggressions = new Dictionary <FactionValue, double>(); var hatred = new Dictionary <(FactionValue, FactionValue), double>(); FactionValue mag = FactionEnumeration.GetFactionByName("MagistracyOfCanopus"); bool allied = WIIC.sim.IsFactionAlly(mag); WIIC.modLog.Debug?.Write($"Mag: {mag.Name}, allied: {allied}"); foreach (StarSystem system in WIIC.sim.StarSystems) { FactionValue defender = system.OwnerValue; if (WIIC.flareups.ContainsKey(system.ID) || Utilities.flashpointInSystem(system)) { continue; } if (s.ignoreFactions.Contains(defender.Name) || s.cantBeAttacked.Contains(defender.Name)) { continue; } if (system.Tags.ContainsAny(cantBeAttackedTags, false)) { continue; } if (!reputations.ContainsKey(defender)) { SimGameReputation reputation = WIIC.sim.GetReputation(defender); reputations[defender] = s.reputationMultiplier[reputation.ToString()]; // The enum for "ALLIED" is the same as "HONORED". HBS_why. if (WIIC.sim.IsFactionAlly(defender)) { reputations[defender] = s.reputationMultiplier["ALLIED"]; } } FakeVector3 p1 = system.Def.Position; FakeVector3 p2 = WIIC.sim.CurSystem.Def.Position; double distanceMult = 1 / (s.distanceFactor + Math.Sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y))); Action <FactionValue> considerAttacker = (FactionValue attacker) => { if (s.ignoreFactions.Contains(attacker.Name)) { return; } // Factions only attack themselves if they are their own enemy (eg, extremely fractured factions). if ((s.limitTargetsToFactionEnemies || attacker == system.OwnerValue) && !attacker.FactionDef.Enemies.Contains(defender.Name)) { return; } if (!reputations.ContainsKey(attacker)) { SimGameReputation reputation = WIIC.sim.GetReputation(attacker); reputations[attacker] = s.reputationMultiplier[reputation.ToString()]; // The enum for "ALLIED" is the same as "HONORED". HBS_why. if (WIIC.sim.IsFactionAlly(defender)) { reputations[attacker] = s.reputationMultiplier["ALLIED"]; } } if (!aggressions.ContainsKey(attacker)) { double aggression = s.aggression.ContainsKey(attacker.Name) ? s.aggression[attacker.Name] : 1; aggressions[attacker] = Utilities.statOrDefault($"WIIC_{attacker.Name}_aggression", aggression); } if (!hatred.ContainsKey((attacker, defender))) { double hate = s.hatred.ContainsKey(attacker.Name) && s.hatred[attacker.Name].ContainsKey(defender.Name) ? s.hatred[attacker.Name][defender.Name] : 1; hatred[(attacker, defender)] = Utilities.statOrDefault($"WIIC_{attacker.Name}_hates_{defender.Name}", hate); } if (!weightedLocations.ContainsKey((system, attacker))) { weightedLocations[(system, attacker)] = 0; } weightedLocations[(system, attacker)] += aggressions[attacker] * (reputations[attacker] + reputations[defender]) * distanceMult * hatred[(attacker, defender)];