private void RunExpansionPlannerORIG() { int numColonyGoals = 0; foreach (Goal g in this.Goals) { if (g.type != GoalType.Colonize) { continue; } numColonyGoals++; } if (numColonyGoals < this.desired_ColonyGoals + (this.empire.data.EconomicPersonality != null ? this.empire.data.EconomicPersonality.ColonyGoalsPlus : 0)) { Planet toMark = null; Vector2 WeightedCenter = new Vector2(); int numPlanets = 0; foreach (Planet p in this.empire.GetPlanets()) { for (int i = 0; (float)i < p.Population / 1000f; i++) { WeightedCenter = WeightedCenter + p.Position; numPlanets++; } } WeightedCenter = WeightedCenter / (float)numPlanets; List<Goal.PlanetRanker> ranker = new List<Goal.PlanetRanker>(); List<Goal.PlanetRanker> allPlanetsRanker = new List<Goal.PlanetRanker>(); foreach (SolarSystem s in UniverseScreen.SolarSystemList) { if (!s.ExploredDict[this.empire]) { continue; } foreach (Planet planetList in s.PlanetList) { bool ok = true; foreach (Goal g in this.Goals) { if (g.type != GoalType.Colonize || g.GetMarkedPlanet() != planetList) { continue; } ok = false; } if (!ok) { continue; } IOrderedEnumerable<AO> sorted = from ao in this.empire.GetGSAI().AreasOfOperations orderby Vector2.Distance(planetList.Position, ao.Position) select ao; if (sorted.Count<AO>() > 0) { AO ClosestAO = sorted.First<AO>(); if (Vector2.Distance(planetList.Position, ClosestAO.Position) > ClosestAO.Radius * 1.5f) { continue; } } if (planetList.ExploredDict[this.empire] && planetList.habitable && planetList.Owner == null) { if (this.empire == EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty) && this.ThreatMatrix.PingRadarStr(planetList.Position, 50000f, this.empire) > 0f) { continue; } Goal.PlanetRanker r = new Goal.PlanetRanker() { Distance = Vector2.Distance(WeightedCenter, planetList.Position) }; float DistanceInJumps = r.Distance / 400000f; if (DistanceInJumps < 1f) { DistanceInJumps = 1f; } r.planet = planetList; if (this.empire.data.Traits.Cybernetic != 0) { //if (planetList.MineralRichness < 1f) //{ // continue; //} r.PV = (planetList.MineralRichness + planetList.MaxPopulation / 1000f) / DistanceInJumps; } else { r.PV = (planetList.MineralRichness + planetList.Fertility + planetList.MaxPopulation / 1000f) / DistanceInJumps; } //Added by McShooterz: changed the requirement from having research to having the building if (planetList.Type == "Barren" && this.empire.GetBDict()["Biospheres"]) { ranker.Add(r); } else if (planetList.Type != "Barren" && ((double)planetList.Fertility >= 1 || this.empire.GetBDict()["Aeroponic Farm"] || this.empire.data.Traits.Cybernetic != 0)) { ranker.Add(r); } } if (!planetList.ExploredDict[this.empire] || !planetList.habitable || planetList.Owner == this.empire || this.empire == EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty) && this.ThreatMatrix.PingRadarStr(planetList.Position, 50000f, this.empire) > 0f) { continue; } Goal.PlanetRanker r0 = new Goal.PlanetRanker() { Distance = Vector2.Distance(WeightedCenter, planetList.Position) }; float DistanceInJumps0 = r0.Distance / 400000f; if (DistanceInJumps0 < 1f) { DistanceInJumps0 = 1f; } r0.planet = planetList; if (this.empire.data.Traits.Cybernetic != 0) { r0.PV = (planetList.MineralRichness + planetList.MaxPopulation / 1000f) / DistanceInJumps0; } else { r0.PV = (planetList.MineralRichness + planetList.Fertility + planetList.MaxPopulation / 1000f) / DistanceInJumps0; } if (!(planetList.Type == "Barren") || !this.empire.GetBDict()["Biospheres"]) { if (!(planetList.Type != "Barren") || (double)planetList.Fertility < 1 && !this.empire.GetBDict()["Aeroponic Farm"] && this.empire.data.Traits.Cybernetic == 0) { continue; } allPlanetsRanker.Add(r0); } else { allPlanetsRanker.Add(r0); } } } if (ranker.Count > 0) { Goal.PlanetRanker winner = new Goal.PlanetRanker(); float highest = 0f; foreach (Goal.PlanetRanker pr in ranker) { if (pr.PV <= highest) { continue; } bool ok = true; foreach (Goal g in this.Goals) { if (g.GetMarkedPlanet() == null || g.GetMarkedPlanet() != pr.planet) { if (!g.Held || g.GetMarkedPlanet() == null || g.GetMarkedPlanet().system != pr.planet.system) { continue; } ok = false; break; } else { ok = false; break; } } if (!ok) { continue; } winner = pr; highest = pr.PV; } toMark = winner.planet; } if (allPlanetsRanker.Count > 0) { this.DesiredPlanets.Clear(); IOrderedEnumerable<Goal.PlanetRanker> sortedList = from ran in allPlanetsRanker orderby ran.PV descending select ran; for (int i = 0; i < allPlanetsRanker.Count; i++) { this.DesiredPlanets.Add(sortedList.ElementAt<Goal.PlanetRanker>(i).planet); } } if (toMark != null) { bool ok = true; foreach (Goal g in this.Goals) { if (g.type != GoalType.Colonize || g.GetMarkedPlanet() != toMark) { continue; } ok = false; } if (ok) { Goal cgoal = new Goal(toMark, this.empire) { GoalName = "MarkForColonization" }; this.Goals.Add(cgoal); numColonyGoals++; } } } }
//Added By Gremlin ExpansionPlanner private void RunExpansionPlanner() { int numColonyGoals = 0; this.desired_ColonyGoals = ((int)Ship.universeScreen.GameDifficulty+3) ; foreach (Goal g in this.Goals) { if (g.type != GoalType.Colonize) { continue; } //added by Gremlin: Colony expansion changes if (g.GetMarkedPlanet() != null) { if (g.GetMarkedPlanet().ParentSystem.ShipList.Where(ship => ship.loyalty != null && ship.loyalty.isFaction).Count() > 0) { numColonyGoals--; } //foreach (Ship enemy in g.GetMarkedPlanet().ParentSystem.ShipList) //{ // if (enemy.loyalty != this.empire) // { // numColonyGoals--; // break; // } //} numColonyGoals++; } } if (numColonyGoals < this.desired_ColonyGoals + (this.empire.data.EconomicPersonality != null ? this.empire.data.EconomicPersonality.ColonyGoalsPlus : 0) )// { Planet toMark = null; float DistanceInJumps = 0; Vector2 WeightedCenter = new Vector2(); int numPlanets = 0; foreach (Planet p in this.empire.GetPlanets()) { for (int i = 0; (float)i < p.Population / 1000f; i++) { WeightedCenter = WeightedCenter + p.Position; numPlanets++; } } WeightedCenter = WeightedCenter / (float)numPlanets; List<Goal.PlanetRanker> ranker = new List<Goal.PlanetRanker>(); List<Goal.PlanetRanker> allPlanetsRanker = new List<Goal.PlanetRanker>(); foreach (SolarSystem s in UniverseScreen.SolarSystemList) { //added by gremlin make non offensive races act like it. bool systemOK = true; if (!this.empire.isFaction && this.empire.data != null && this.empire.data.DiplomaticPersonality != null && !( (this.empire.GetRelations().Where(war => war.Value.AtWar).Count() > 0 && this.empire.data.DiplomaticPersonality.Name != "Honorable") || this.empire.data.DiplomaticPersonality.Name == "Agressive" || this.empire.data.DiplomaticPersonality.Name == "Ruthless" || this.empire.data.DiplomaticPersonality.Name == "Cunning") ) { foreach (Empire enemy in s.OwnerList) { if (enemy != this.empire && !enemy.isFaction && !this.empire.GetRelations()[enemy].Treaty_Alliance) { systemOK = false; break; } } } if (!systemOK) continue; if (!s.ExploredDict[this.empire]) { continue; } foreach (Planet planetList in s.PlanetList) { bool ok = true; foreach (Goal g in this.Goals) { if (g.type != GoalType.Colonize || g.GetMarkedPlanet() != planetList) { continue; } ok = false; } if (!ok) { continue; } IOrderedEnumerable<AO> sorted = from ao in this.empire.GetGSAI().AreasOfOperations orderby Vector2.Distance(planetList.Position, ao.Position) select ao; if (sorted.Count<AO>() > 0) { AO ClosestAO = sorted.First<AO>(); if (Vector2.Distance(planetList.Position, ClosestAO.Position) > ClosestAO.Radius * 2f) { continue; } } int commodities = 0; //Added by gremlin adding in commodities foreach (Building commodity in planetList.BuildingList) { if (!commodity.IsCommodity) continue; commodities += 1; } if (planetList.ExploredDict[this.empire] && planetList .habitable && planetList.Owner == null) { if (this.empire == EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty) && this.ThreatMatrix.PingRadarStr(planetList.Position, 50000f, this.empire) > 0f) { continue; } Goal.PlanetRanker r2 = new Goal.PlanetRanker() { Distance = Vector2.Distance(WeightedCenter, planetList.Position) }; DistanceInJumps = r2.Distance / 400000f; if (DistanceInJumps < 1f) { DistanceInJumps = 1f; } r2.planet = planetList; //Cyberbernetic planet picker if (this.empire.data.Traits.Cybernetic != 0) { r2.PV = (commodities + planetList.MineralRichness + planetList.MaxPopulation / 1000f) / DistanceInJumps; } else { r2.PV = (commodities + planetList.MineralRichness + planetList.Fertility + planetList.MaxPopulation / 1000f) / DistanceInJumps; } if (commodities > 0) ranker.Add(r2); if (planetList.Type == "Barren" && commodities > 0 || this.empire.GetBDict()["Biospheres"] || this.empire.data.Traits.Cybernetic != 0 ) { ranker.Add(r2); } else if (planetList.Type != "Barren" && commodities > 0 || ((double)planetList.Fertility >= .5f || (this.empire.data.Traits.Cybernetic != 0 && (double)planetList.MineralRichness >= .5f)) || (this.empire.GetTDict()["Aeroponics"].Unlocked)) //|| (this.empire.data.Traits.Cybernetic != 0 && this.empire.GetBDict()["Biospheres"])) { ranker.Add(r2); } else if (planetList.Type != "Barren") { if (this.empire.data.Traits.Cybernetic == 0) foreach (Planet food in this.empire.GetPlanets()) { if (food.FoodHere > food.MAX_STORAGE * .7f && food.fs == Planet.GoodState.EXPORT) { ranker.Add(r2); break; } } else { if (planetList.MineralRichness < .5f) { foreach (Planet food in this.empire.GetPlanets()) { if (food.ProductionHere > food.MAX_STORAGE * .7f || food.ps == Planet.GoodState.EXPORT) { ranker.Add(r2); break; } } } else { ranker.Add(r2); } } } } if (!planetList.ExploredDict[this.empire] || !planetList.habitable || planetList.Owner == this.empire || this.empire == EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty) && this.ThreatMatrix.PingRadarStr(planetList.Position, 50000f, this.empire) > 0f) { continue; } Goal.PlanetRanker r = new Goal.PlanetRanker() { Distance = Vector2.Distance(WeightedCenter, planetList.Position) }; DistanceInJumps = r.Distance / 400000f; if (DistanceInJumps < 1f) { DistanceInJumps = 1f; } r.planet = planetList; if (this.empire.data.Traits.Cybernetic != 0) { r.PV = (commodities + planetList.MineralRichness + planetList.MaxPopulation / 1000f) / DistanceInJumps; } else { r.PV = (commodities + planetList.MineralRichness + planetList.Fertility + planetList.MaxPopulation / 1000f) / DistanceInJumps; } //if (planetList.Type == "Barren" && (commodities > 0 || this.empire.GetTDict()["Biospheres"].Unlocked || (this.empire.data.Traits.Cybernetic != 0 && (double)planetList.MineralRichness >= .5f))) //if (!(planetList.Type == "Barren") || !this.empire.GetTDict()["Biospheres"].Unlocked) if (planetList.Type == "Barren" && commodities > 0 || this.empire.GetBDict()["Biospheres"] || this.empire.data.Traits.Cybernetic != 0) { if (!(planetList.Type != "Barren") || (double)planetList.Fertility < .5 && !this.empire.GetTDict()["Aeroponics"].Unlocked && this.empire.data.Traits.Cybernetic == 0) { foreach (Planet food in this.empire.GetPlanets()) { if (food.FoodHere > food.MAX_STORAGE * .9f && food.fs == Planet.GoodState.EXPORT) { allPlanetsRanker.Add(r); break; } } continue; } allPlanetsRanker.Add(r); } else { allPlanetsRanker.Add(r); } } } if (ranker.Count > 0) { Goal.PlanetRanker winner = new Goal.PlanetRanker(); float highest = 0f; foreach (Goal.PlanetRanker pr in ranker) { if (pr.PV <= highest) { continue; } bool ok = true; foreach (Goal g in this.Goals) { if (g.GetMarkedPlanet() == null || g.GetMarkedPlanet() != pr.planet) { if (!g.Held || g.GetMarkedPlanet() == null || g.GetMarkedPlanet().system != pr.planet.system) { continue; } ok = false; break; } else { ok = false; break; } } if (!ok) { continue; } winner = pr; highest = pr.PV; } toMark = winner.planet; } if (allPlanetsRanker.Count > 0) { this.DesiredPlanets.Clear(); IOrderedEnumerable<Goal.PlanetRanker> sortedList = from ran in allPlanetsRanker orderby ran.PV descending select ran; for (int i = 0; i < allPlanetsRanker.Count; i++) { this.DesiredPlanets.Add(sortedList.ElementAt<Goal.PlanetRanker>(i).planet); } } if (toMark != null) { bool ok = true; foreach (Goal g in this.Goals) { if (g.type != GoalType.Colonize || g.GetMarkedPlanet() != toMark) { continue; } ok = false; } if (ok) { Goal cgoal = new Goal(toMark, this.empire) { GoalName = "MarkForColonization" }; this.Goals.Add(cgoal); numColonyGoals++; } } } }