Пример #1
0
        //TODO(v0.8) can unintentionally land non-colony ships like scouts
        private void doColonization()
        {
            foreach (var project in this.game.States.ColonizationProjects)
            {
                var  playerProc   = this.game.Derivates[project.Owner];
                bool colonyExists = this.game.States.Colonies.AtPlanet.Contains(project.Destination);

                var colonizers = this.game.States.Fleets.At[project.Destination.Star.Position].
                                 Where(x => x.Owner == project.Owner && x.Ships.Any(s => s.PopulationTransport > 0));

                var arrivedPopulation    = colonizers.SelectMany(x => x.Ships).Sum(x => x.PopulationTransport);
                var colonizationTreshold = this.game.Statics.ColonyFormulas.ColonizationPopulationThreshold.Evaluate(null);

                if (!colonyExists && arrivedPopulation >= colonizationTreshold)
                {
                    var colony     = new Colony(0, project.Destination, project.Owner);
                    var colonyProc = new ColonyProcessor(colony);
                    colonyProc.CalculateBaseEffects(this.game.Statics, this.game.Derivates.Players.Of[colony.Owner]);

                    foreach (var fleet in colonizers)
                    {
                        foreach (var shipGroup in fleet.Ships)
                        {
                            var shipStats = playerProc.DesignStats[shipGroup.Design];
                            if (shipStats.ColonizerPopulation <= 0)
                            {
                                continue;
                            }

                            var landingLimit = (long)Math.Ceiling((colonizationTreshold - colony.Population) / shipStats.ColonizerPopulation);
                            var shipsLanded  = Math.Min(shipGroup.Quantity, landingLimit);

                            colonyProc.AddPopulation(shipsLanded * shipStats.ColonizerPopulation);

                            foreach (var building in shipStats.ColonizerBuildings)
                            {
                                if (colony.Buildings.ContainsKey(building.Key))
                                {
                                    colony.Buildings[building.Key] += building.Value * shipGroup.Quantity;
                                }
                                else
                                {
                                    colony.Buildings.Add(building.Key, building.Value * shipGroup.Quantity);
                                }
                            }

                            shipGroup.Quantity            -= shipsLanded;
                            shipGroup.PopulationTransport -= shipsLanded * shipStats.ColonizerPopulation;
                            if (shipGroup.Quantity < 1)
                            {
                                fleet.Ships.PendRemove(shipGroup);
                            }
                        }

                        fleet.Ships.ApplyPending();
                        if (fleet.Ships.Count == 0)
                        {
                            game.States.Fleets.PendRemove(fleet);
                        }
                    }
                    game.States.Fleets.ApplyPending();

                    this.game.States.Colonies.Add(colony);
                    this.game.Derivates.Colonies.Add(colonyProc);
                    this.game.Orders[project.Owner].ConstructionPlans[colony]     = new ConstructionOrders(PlayerOrders.DefaultSiteSpendingRatio);
                    this.game.Orders[project.Owner].AutomatedConstruction[colony] = new ConstructionOrders(0);

                    if (this.game.States.Stellarises.At[project.Destination.Star].All(x => x.Owner != project.Owner))
                    {
                        var stellaris = new StellarisAdmin(project.Destination.Star, project.Owner);
                        this.game.States.Stellarises.Add(stellaris);
                        this.game.Derivates.Stellarises.Add(new StellarisProcessor(stellaris));
                        this.game.Orders[project.Owner].Policies[stellaris] = game.Statics.Policies.First();
                        this.game.Orders[project.Owner].AutomatedConstruction[stellaris] = new ConstructionOrders(0);
                    }
                }

                if (colonyExists || arrivedPopulation >= colonizationTreshold)
                {
                    this.game.Orders[project.Owner].ColonizationTargets.Remove(project.Destination);
                    this.game.States.ColonizationProjects.PendRemove(project);
                }
            }

            this.game.States.ColonizationProjects.ApplyPending();
        }
Пример #2
0
        private void doColonization()
        {
            foreach (var project in this.game.States.ColonizationProjects)
            {
                var  playerProc   = this.game.Derivates.Of(project.Owner);
                bool colonyExists = this.game.States.Colonies.AtPlanet.Contains(project.Destination);

                var colonizers = this.game.States.Fleets.At[project.Destination.Star.Position].Where(
                    x =>
                {
                    if (x.Owner != project.Owner || x.Missions.Count == 0)
                    {
                        return(false);
                    }

                    var mission = x.Missions.First.Value as ColonizationMission;
                    return(mission != null && mission.Target == project.Destination);
                });

                var arrivedPopulation    = colonizers.SelectMany(x => x.Ships).Sum(x => playerProc.DesignStats[x.Design].ColonizerPopulation * x.Quantity);
                var colonizationTreshold = this.game.Statics.ColonyFormulas.ColonizationPopulationThreshold.Evaluate(null);

                if (!colonyExists && arrivedPopulation >= colonizationTreshold)
                {
                    var colony     = new Colony(0, project.Destination, project.Owner);
                    var colonyProc = new ColonyProcessor(colony);
                    colonyProc.CalculateBaseEffects(this.game.Statics, this.game.Derivates.Players.Of[colony.Owner]);

                    foreach (var fleet in colonizers)
                    {
                        foreach (var shipGroup in fleet.Ships)
                        {
                            var shipStats       = playerProc.DesignStats[shipGroup.Design];
                            var groupPopulation = shipStats.ColonizerPopulation * shipGroup.Quantity;
                            var landingLimit    = (long)Math.Ceiling((colonizationTreshold - colony.Population) / shipStats.ColonizerPopulation);
                            var shipsLanded     = Math.Min(shipGroup.Quantity, landingLimit);

                            colonyProc.AddPopulation(shipsLanded * shipStats.ColonizerPopulation);

                            foreach (var building in shipStats.ColonizerBuildings)
                            {
                                if (colony.Buildings.ContainsKey(building.Key))
                                {
                                    colony.Buildings[building.Key] += building.Value * shipGroup.Quantity;
                                }
                                else
                                {
                                    colony.Buildings.Add(building.Key, building.Value * shipGroup.Quantity);
                                }
                            }

                            shipGroup.Quantity -= shipsLanded;
                            if (shipGroup.Quantity < 1)
                            {
                                fleet.Ships.PendRemove(shipGroup);
                            }
                        }

                        fleet.Ships.ApplyPending();
                        if (fleet.Ships.Count == 0)
                        {
                            game.States.Fleets.PendRemove(fleet);
                        }
                    }
                    game.States.Fleets.ApplyPending();

                    this.game.States.Colonies.Add(colony);
                    this.game.Derivates.Colonies.Add(colonyProc);

                    if (this.game.States.Stellarises.At[project.Destination.Star].All(x => x.Owner != project.Owner))
                    {
                        var stellaris = new StellarisAdmin(project.Destination.Star, project.Owner);
                        this.game.States.Stellarises.Add(stellaris);
                        this.game.Derivates.Stellarises.Add(new StellarisProcessor(stellaris));
                    }
                }

                if (colonyExists || !colonyExists && arrivedPopulation >= colonizationTreshold)
                {
                    project.Owner.Orders.ColonizationOrders.Remove(project.Destination);
                    this.game.States.ColonizationProjects.PendRemove(project);
                }
            }

            this.game.States.ColonizationProjects.ApplyPending();
        }