internal AConstructionSiteController(AConstructionSite site, bool readOnly, MainGame game, Player player)
 {
     this.Site       = site;
     this.IsReadOnly = readOnly;
     this.Game       = game;
     this.Player     = player;
 }
        public void Apply(MainGame game, AConstructionSite site, long quantity)
        {
            //TODO(v0.8) report new ship construction
            var playerProc = game.Derivates[site.Owner];

            var colonies         = game.States.Colonies.AtStar[site.Location.Star, site.Owner].ToList();
            var systemPopulation = colonies.Sum(x => x.Population);
            var migrants         = Math.Min(playerProc.DesignStats[this.Design].ColonizerPopulation * quantity, systemPopulation);

            playerProc.SpawnShip(site.Location.Star, this.Design, quantity, migrants, new AMission[0], game.States);

            var toMove = migrants;

            while (toMove >= 0.1)
            {
                foreach (var colony in colonies)
                {
                    var delta = Math.Min(migrants * colony.Population / systemPopulation, colony.Population);
                    colony.Population -= delta;
                    toMove            -= delta;
                }
                migrants         = toMove;
                systemPopulation = colonies.Sum(x => x.Population);
            }
        }
Beispiel #3
0
        internal AConstructionSite Site(AConstructionSite site)
        {
            if (Colonies.ContainsKey(site))
            {
                return(Colonies[site]);
            }
            else if (Stellarises.ContainsKey(site))
            {
                return(Stellarises[site]);
            }

            throw new KeyNotFoundException();
        }
Beispiel #4
0
        //TODO(later) make separate collections for colony and stellaris construction orders
        private Dictionary <AConstructionSite, ConstructionOrders> loadConstruction(IkadnBaseObject rawData, ObjectDeindexer deindexer)
        {
            var queue = new Dictionary <AConstructionSite, ConstructionOrders>();

            foreach (var plan in rawData.To <IEnumerable <IkonComposite> >())
            {
                AConstructionSite site = plan.Tag.Equals(StellarisConstructionTag) ?
                                         (AConstructionSite)deindexer.Get <StellarisAdmin>(plan[LocationKey].To <int>()) :
                                         (AConstructionSite)deindexer.Get <Colony>(plan[LocationKey].To <int>());

                queue.Add(site, ConstructionOrders.Load(plan[OrdersKey].To <IkonComposite>(), deindexer));
            }

            return(queue);
        }
Beispiel #5
0
        public void Apply(MainGame game, AConstructionSite site, long quantity)
        {
            //TODO(v0.8) report new building construction
            var vars = new Var("quantity", quantity);

            quantity = (long)this.quantity.Evaluate(vars.Get);

            if (!site.Buildings.ContainsKey(buildingCode))
            {
                site.Buildings.Add(buildingCode, quantity);
            }
            else
            {
                site.Buildings[buildingCode] += quantity;
            }
        }
Beispiel #6
0
        public void Apply(StatesDB states, TemporaryDB derivates, AConstructionSite site, long quantity)
        {
            var project  = states.ColonizationProjects.Of[Destination].FirstOrDefault(x => x.Owner == this.ColonizerDesign.Owner);
            var missions = new LinkedList <AMission>();

            missions.AddLast(new SkipTurnMission());

            //TODO(later) check shortest path
            if (site.Location.Star != Destination.Star)
            {
                var lastStar = site.Location.Star;
                var nextStar = Destination.Star;
                var wormhole = states.Wormholes.At[lastStar].FirstOrDefault(x => x.FromStar == nextStar || x.ToStar == nextStar);
                missions.AddLast(new MoveMission(Destination.Star, wormhole));
            }

            missions.AddLast(new ColonizationMission(Destination));

            //TODO(v0.6) report new ship construction
            derivates.Of(site.Owner).SpawnShip(site.Location.Star, this.ColonizerDesign, quantity, missions, states);
        }
 public void Apply(StatesDB states, TemporaryDB derivates, AConstructionSite site, long quantity)
 {
     //TODO(v0.6) report new ship construction
     derivates.Of(site.Owner).SpawnShip(site.Location.Star, this.Design, quantity, new AMission[0], states);
 }
Beispiel #8
0
 public void Apply(MainGame game, AConstructionSite site, long quantity)
 {
     site.Location.Planet.Traits.Add(game.Statics.PlanetTraits[this.traitId]);
 }
        protected static IEnumerable <ConstructionResult> SimulateSpending(
            AConstructionSite site, double industryPoints,
            IEnumerable <IConstructionProject> queue, IDictionary <string, double> vars)
        {
            var spendingPlan  = new List <ConstructionResult>();
            var planStockpile = new Dictionary <string, double>(site.Stockpile);

            foreach (var buildingItem in queue)
            {
                var stockpileKey = buildingItem.StockpileGroup;
                if (!site.Stockpile.ContainsKey(stockpileKey))
                {
                    site.Stockpile[stockpileKey] = 0;
                }

                if (buildingItem.Condition.Evaluate(vars) < 0)
                {
                    spendingPlan.Add(new ConstructionResult(0, 0, site.Stockpile[stockpileKey], buildingItem, site.Stockpile[stockpileKey]));
                    continue;
                }

                double cost            = buildingItem.Cost.Evaluate(vars);
                double stockpile       = planStockpile.ContainsKey(stockpileKey) ? planStockpile[stockpileKey] : 0;
                double totalInvestment = industryPoints + stockpile;

                double completed  = cost > 0 ? Math.Floor(totalInvestment / cost) : double.PositiveInfinity;
                double countLimit = buildingItem.TurnLimit.Evaluate(vars);
                planStockpile[stockpileKey] = 0;

                if (completed > countLimit)
                {
                    double totalCost = countLimit * cost;

                    if (stockpile >= totalCost)
                    {
                        spendingPlan.Add(new ConstructionResult(
                                             (long)countLimit,
                                             0,
                                             totalCost,
                                             buildingItem,
                                             stockpile - totalCost
                                             ));
                        planStockpile[stockpileKey] = stockpile - totalCost;
                    }
                    else
                    {
                        spendingPlan.Add(new ConstructionResult(
                                             (long)countLimit,
                                             totalCost - stockpile,
                                             stockpile,
                                             buildingItem,
                                             0
                                             ));

                        industryPoints -= totalCost - stockpile;
                    }
                }
                else
                {
                    spendingPlan.Add(new ConstructionResult(
                                         (long)completed,
                                         industryPoints,
                                         stockpile,
                                         buildingItem,
                                         totalInvestment - completed * cost
                                         ));

                    industryPoints = 0;
                }
            }

            return(spendingPlan);
        }