Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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
                       ));
        }