private static void initColonies(Player[] players, ColonyCollection colonies, StartingConditions startingConditions, TemporaryDB derivates, StaticsDB statics) { foreach (Colony colony in colonies) { var colonyProc = new ColonyProcessor(colony); colonyProc.CalculateBaseEffects(statics, derivates.Players.Of[colony.Owner]); derivates.Colonies.Add(colonyProc); } foreach (Player player in players) { var weights = new ChoiceWeights <Colony>(); foreach (Colony colony in colonies.OwnedBy[player]) { weights.Add(colony, derivates.Colonies.Of[colony].Desirability); } var maxPopulation = colonies.OwnedBy[player].Sum(x => derivates.Colonies.Of[x].MaxPopulation); double totalPopulation = Math.Min(startingConditions.Population, maxPopulation); double totalInfrastructure = Math.Min(startingConditions.Infrastructure, maxPopulation); foreach (var colony in colonies.OwnedBy[player]) { colony.Population = weights.Relative(colony) * totalPopulation; derivates.Colonies.Of[colony].CalculateBaseEffects(statics, derivates.Players.Of[player]); } } }
private static ColonyCollection createColonies(Player[] players, IList <StarSystemBuilder> starSystems, IList <int> homeSystemIndices, StartingConditions startingConditions, StaticsDB statics) { var colonies = new ColonyCollection(); for (int playerI = 0; playerI < players.Length; playerI++) { var planets = starSystems[homeSystemIndices[playerI]].Planets; var fitness = planets. ToDictionary(x => x, x => ColonyProcessor.DesirabilityOf(x, statics)); for (int i = 0; i < Math.Min(startingConditions.Colonies, planets.Count); i++) { var planet = Methods.FindBest(planets, x => fitness[x]); colonies.Add(new Colony( 0, planet, players[playerI] )); fitness[planet] = double.NegativeInfinity; } } return(colonies); }
public StatesDB(StarCollection stars, WormholeCollection wormholes, PlanetCollection planets, ColonyCollection Colonies, StellarisCollection stellarises, DevelopmentProgressCollection developmentAdvances, ResearchProgressCollection researchAdvances, TreatyCollection treaties, ReportCollection reports, DesignCollection designs, FleetCollection fleets, ColonizationCollection colonizations) { this.Colonies = Colonies; this.Planets = planets; this.Stars = stars; this.Stellarises = stellarises; this.Wormholes = wormholes; this.DevelopmentAdvances = developmentAdvances; this.ResearchAdvances = researchAdvances; this.Reports = reports; this.Designs = designs; this.Fleets = fleets; this.ColonizationProjects = colonizations; this.Treaties = treaties; }
private static ColonyCollection createColonies(Player[] players, IList <StarSystem> starSystems, IList <int> homeSystemIndices, StartingConditions startingConditions) { var colonies = new ColonyCollection(); for (int playerI = 0; playerI < players.Length; playerI++) { //TODO(later): pick top most suitable planets for (int colonyI = 0; colonyI < startingConditions.Colonies; colonyI++) { colonies.Add(new Colony( 1, //TODO(v0.6): make a constant starSystems[homeSystemIndices[playerI]].Planets[colonyI], players[playerI] )); } } return(colonies); }
private static ColonyCollection createColonies(Player[] players, IList <StarSystemBuilder> starSystems, IList <int> homeSystemIndices, StartingConditions startingConditions, StaticsDB statics) { var colonies = new ColonyCollection(); for (int playerI = 0; playerI < players.Length; playerI++) { var planets = new HashSet <Planet>(starSystems[homeSystemIndices[playerI]].Planets); var fitness = planets. ToDictionary(x => x, x => ColonyProcessor.DesirabilityOf(x, statics)); while (planets.Count > startingConditions.Colonies) { planets.Remove(Methods.FindWorst(planets, x => fitness[x])); } foreach (var planet in planets) { colonies.Add(new Colony(0, planet, players[playerI])); } } return(colonies); }
private static Tuple <StatesDB, Player[], Player> loadSaveData(IkonComposite saveData, ObjectDeindexer deindexer, StaticsDB statics) { var stateData = saveData[MainGame.StatesKey].To <IkonComposite>(); var ordersData = saveData[MainGame.OrdersKey].To <IkonArray>(); var stars = new StarCollection(); foreach (var rawData in stateData[StatesDB.StarsKey].To <IEnumerable <IkonComposite> >()) { stars.Add(StarData.Load(rawData, deindexer)); } var planets = new PlanetCollection(); foreach (var rawData in stateData[StatesDB.PlanetsKey].To <IEnumerable <IkonComposite> >()) { planets.Add(Planet.Load(rawData, deindexer)); } var wormholes = new WormholeCollection(); foreach (var rawData in stateData[StatesDB.WormholesKey].To <IEnumerable <IkonComposite> >()) { wormholes.Add(Wormhole.Load(rawData, deindexer)); } var players = new List <Player>(); foreach (var rawData in saveData[MainGame.PlayersKey].To <IEnumerable <IkonComposite> >()) { players.Add(Player.Load(rawData, deindexer)); } var organellePlayer = Player.Load(saveData[MainGame.OrganellePlayerKey].To <IkonComposite>(), deindexer); var developments = new DevelopmentProgressCollection(); foreach (var rawData in stateData[StatesDB.DevelopmentAdvancesKey].To <IEnumerable <IkonComposite> >()) { developments.Add(DevelopmentProgress.Load(rawData, deindexer)); } var research = new ResearchProgressCollection(); foreach (var rawData in stateData[StatesDB.ResearchAdvancesKey].To <IEnumerable <IkonComposite> >()) { research.Add(ResearchProgress.Load(rawData, deindexer)); } var treaties = new TreatyCollection(); foreach (var rawData in stateData[StatesDB.TreatiesKey].To <IEnumerable <IkonComposite> >()) { treaties.Add(Treaty.Load(rawData, deindexer)); } var reports = new ReportCollection(); foreach (var rawData in stateData[StatesDB.ReportsKey].To <IEnumerable <IkonComposite> >()) { reports.Add(ReportFactory.Load(rawData, deindexer)); } var designs = new DesignCollection(); foreach (var rawData in stateData[StatesDB.DesignsKey].To <IEnumerable <IkonComposite> >()) { var design = Design.Load(rawData, deindexer); design.CalcHash(statics); designs.Add(design); deindexer.Add(design.ConstructionProject, design.ConstructionProject.IdCode); } var colonizations = new ColonizationCollection(); foreach (var rawData in stateData[StatesDB.ColonizationKey].To <IEnumerable <IkonComposite> >()) { colonizations.Add(ColonizationProject.Load(rawData, deindexer)); } var fleets = new FleetCollection(); foreach (var rawData in stateData[StatesDB.IdleFleetsKey].To <IEnumerable <IkonComposite> >()) { fleets.Add(Fleet.Load(rawData, deindexer)); } var colonies = new ColonyCollection(); foreach (var rawData in stateData[StatesDB.ColoniesKey].To <IEnumerable <IkonComposite> >()) { colonies.Add(Colony.Load(rawData, deindexer)); } var stellarises = new StellarisCollection(); foreach (var rawData in stateData[StatesDB.StellarisesKey].To <IEnumerable <IkonComposite> >()) { stellarises.Add(StellarisAdmin.Load(rawData, deindexer)); } for (int i = 0; i < players.Count; i++) { players[i].Orders = PlayerOrders.Load(ordersData[i].To <IkonComposite>(), deindexer); } organellePlayer.Orders = PlayerOrders.Load(saveData[MainGame.OrganelleOrdersKey].To <IkonComposite>(), deindexer); return(new Tuple <StatesDB, Player[], Player>( new StatesDB(stars, wormholes, planets, colonies, stellarises, developments, research, treaties, reports, designs, fleets, colonizations), players.ToArray(), organellePlayer )); }