コード例 #1
0
        private static TemporaryDB initDerivates(StaticsDB statics, Player[] players, Player organellePlayer, StatesDB states)
        {
            var derivates = new TemporaryDB(players, organellePlayer, statics.DevelopmentTopics);

            foreach (var colony in states.Colonies)
            {
                var colonyProc = new ColonyProcessor(colony);
                colonyProc.CalculateBaseEffects(statics, derivates.Players.Of[colony.Owner]);
                derivates.Colonies.Add(colonyProc);
            }

            foreach (var stellaris in states.Stellarises)
            {
                var stellarisProc = new StellarisProcessor(stellaris);
                stellarisProc.CalculateBaseEffects();
                derivates.Stellarises.Add(stellarisProc);
            }

            foreach (var player in players)
            {
                var playerProc = derivates.Players.Of[player];
                playerProc.Initialize(statics, states);

                foreach (var design in states.Designs.OwnedBy[player])
                {
                    playerProc.Analyze(design, statics);
                }
            }

            derivates.Natives.Initialize(states, statics, derivates);

            return(derivates);
        }
コード例 #2
0
 private static void initStellarises(TemporaryDB derivates, IEnumerable <StellarisAdmin> stellarises)
 {
     foreach (var stellaris in stellarises)
     {
         derivates.Stellarises.Add(new StellarisProcessor(stellaris));
     }
 }
コード例 #3
0
        private static void initPlayers(TemporaryDB derivates, IEnumerable <Player> players, StatesDB states, StaticsDB statics)
        {
            foreach (var player in players)
            {
                foreach (var colony in states.Colonies.OwnedBy[player])
                {
                    player.Orders.ConstructionPlans.Add(colony, new ConstructionOrders(PlayerOrders.DefaultSiteSpendingRatio));
                }

                foreach (var stellaris in states.Stellarises.OwnedBy[player])
                {
                    player.Orders.ConstructionPlans.Add(stellaris, new ConstructionOrders(PlayerOrders.DefaultSiteSpendingRatio));
                }

                player.Orders.DevelopmentFocusIndex = statics.DevelopmentFocusOptions.Count / 2;
                //TODO(v0.6) focus can be null when all research is done
                player.Orders.ResearchFocus = statics.ResearchTopics.First().IdCode;
            }

            foreach (var player in players)
            {
                derivates.Players.Of[player].Initialize(statics, states);

                player.Intelligence.Initialize(states.Stars.Select(
                                                   star => new StarSystem(star, states.Planets.At[star].ToArray())
                                                   ));

                foreach (var colony in states.Colonies.OwnedBy[player])
                {
                    player.Intelligence.StarFullyVisited(colony.Star, 0);
                }
            }
        }
コード例 #4
0
        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]);
                }
            }
        }
コード例 #5
0
 public void ProcessPostcombat(StaticsDB statics, StatesDB states, TemporaryDB derivates)
 {
     this.advanceTechnologies(states, statics);
     this.checkColonizationValidity(states);
     this.doConstruction(statics, states, derivates);
     this.unlockPredefinedDesigns(statics, states);
     this.updateDesigns(statics, states, derivates);
 }
コード例 #6
0
        private static TemporaryDB createDerivates(Player[] players, Player organellePlayer, StaticsDB statics, StatesDB states)
        {
            var derivates = new TemporaryDB(players, organellePlayer, statics.DevelopmentTopics);

            derivates.Natives.Initialize(states, statics, derivates);

            return(derivates);
        }
コード例 #7
0
        public void ProcessPrecombat(StaticsDB statics, StatesDB states, TemporaryDB derivates)
        {
            var catalizers = states.Fleets.OwnedBy[this.OrganellePlayer].SelectMany(x => x.Ships).Where(x => x.Design.IdCode == CatalyzerId).Sum(x => x.Quantity);

            if (catalizers < MaxCatalyzers)
            {
                var nativeDesign = states.Designs.OwnedBy[this.OrganellePlayer].First(x => x.IdCode == CatalyzerId);
                derivates[this.OrganellePlayer].SpawnShip(states.StareaterBrain, nativeDesign, 1, 0, new AMission[0], states);
            }
        }
コード例 #8
0
        private static TemporaryDB createDerivates(Player[] players, Player organellePlayer, StartingConditions startingConditions, StaticsDB statics, StatesDB states)
        {
            var derivates = new TemporaryDB(players, organellePlayer, statics.DevelopmentTopics);

            initColonies(players, states.Colonies, startingConditions, derivates, statics);
            initStellarises(derivates, states.Stellarises);

            derivates.Natives.Initialize(states, statics, derivates);

            return(derivates);
        }
コード例 #9
0
        public void Initialize(StatesDB states, StaticsDB statics, TemporaryDB derivates)
        {
            this.OrganellePlayer.Intelligence.Initialize(states);
            foreach (var star in states.Stars)
            {
                this.OrganellePlayer.Intelligence.StarFullyVisited(star, 0);
            }

            foreach (var designData in statics.NativeDesigns)
            {
                makeDesign(statics, states, designData.Key, designData.Value, derivates[this.OrganellePlayer]);
            }
        }
コード例 #10
0
        public void Initialize(StatesDB states, StaticsDB statics, TemporaryDB derivates)
        {
            this.OrganellePlayer.Intelligence.Initialize(states.Stars.Select(
                                                             star => new Stareater.Galaxy.Builders.StarSystem(star, states.Planets.At[star].ToArray())
                                                             ));
            foreach (var star in states.Stars)
            {
                this.OrganellePlayer.Intelligence.StarFullyVisited(star, 0);
            }

            foreach (var template in statics.NativeDesigns)
            {
                makeDesign(statics, states, template.Key, template.Value, derivates.Of(this.OrganellePlayer));
            }
        }
コード例 #11
0
        public void Apply(StatesDB states, TemporaryDB derivates, AConstructionSite site, long quantity)
        {
            //TODO(v0.5) 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;
            }
        }
コード例 #12
0
        public void Initialize(StatesDB states, StaticsDB statics, TemporaryDB derivates)
        {
            this.OrganellePlayer.Intelligence.Initialize(states);
            foreach (var star in states.Stars)
            {
                this.OrganellePlayer.Intelligence.StarFullyVisited(star, 0);
            }

            foreach (var designData in statics.NativeDesigns)
            {
                var design = makeDesign(statics, designData.Value, this.OrganellePlayer);

                this.nativeDesigns[designData.Key] = design;
                states.Designs.Add(design);
                derivates[this.OrganellePlayer].Analyze(design, statics);
            }
        }
コード例 #13
0
        private static TemporaryDB initDerivates(StaticsDB statics, Player[] players, Player organellePlayer, StatesDB states)
        {
            var derivates = new TemporaryDB(players, organellePlayer, statics.DevelopmentTopics);

            foreach (var colony in states.Colonies)
            {
                derivates.Colonies.Add(new ColonyProcessor(colony));
            }

            foreach (var stellaris in states.Stellarises)
            {
                derivates.Stellarises.Add(new StellarisProcessor(stellaris));
            }

            derivates.Natives.Initialize(states, statics, derivates);

            return(derivates);
        }
コード例 #14
0
        private void doConstruction(StaticsDB statics, StatesDB states, TemporaryDB derivates)
        {
            var oldPlans = Player.Orders.ConstructionPlans;

            Player.Orders.ConstructionPlans = new Dictionary <AConstructionSite, ConstructionOrders>();

            foreach (var colony in states.Colonies.OwnedBy[Player])
            {
                if (oldPlans.ContainsKey(colony))
                {
                    var updatedPlans = updateConstructionPlans(
                        statics,
                        oldPlans[colony],
                        derivates.Of(colony),
                        this.TechLevels
                        );

                    Player.Orders.ConstructionPlans.Add(colony, updatedPlans);
                }
                else
                {
                    Player.Orders.ConstructionPlans.Add(colony, new ConstructionOrders(PlayerOrders.DefaultSiteSpendingRatio));
                }
            }

            foreach (var stellaris in states.Stellarises.OwnedBy[Player])
            {
                if (oldPlans.ContainsKey(stellaris))
                {
                    var updatedPlans = updateConstructionPlans(
                        statics,
                        oldPlans[stellaris],
                        derivates.Of(stellaris),
                        this.TechLevels
                        );

                    Player.Orders.ConstructionPlans.Add(stellaris, updatedPlans);
                }
                else
                {
                    Player.Orders.ConstructionPlans.Add(stellaris, new ConstructionOrders(PlayerOrders.DefaultSiteSpendingRatio));
                }
            }
        }
コード例 #15
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);
        }
コード例 #16
0
        public void ProcessPrecombat(StaticsDB statics, StatesDB states, TemporaryDB derivates)
        {
            this.updateColonizationOrders(states);

            foreach (var colonyProc in derivates.Colonies.OwnedBy[this.Player])
            {
                colonyProc.ProcessPrecombat(states, derivates);
            }

            foreach (var stellarisProc in derivates.Stellarises.OwnedBy[this.Player])
            {
                stellarisProc.ProcessPrecombat(states, derivates);
            }

            this.breakthroughs = new Queue <ResearchResult>(this.ResearchPlan.Where(x => x.CompletedCount > 0));

            /*
             * TODO(later):
             * - Perform migration
             */
        }
コード例 #17
0
        public virtual void ProcessPrecombat(StatesDB states, TemporaryDB derivates)
        {
            foreach (var construction in this.SpendingPlan)
            {
                if (construction.CompletedCount >= 1)
                {
                    foreach (var effect in construction.Type.Effects)
                    {
                        effect.Apply(states, derivates, this.Site, construction.CompletedCount);
                    }
                }

                var stockpileKey = construction.Type.StockpileGroup;
                if (construction.FromStockpile > 0 && this.Site.Stockpile.ContainsKey(stockpileKey))
                {
                    this.Site.Stockpile[stockpileKey] -= construction.FromStockpile;
                }

                if (construction.LeftoverPoints > 0)
                {
                    if (!this.Site.Stockpile.ContainsKey(stockpileKey))
                    {
                        this.Site.Stockpile.Add(stockpileKey, construction.LeftoverPoints);
                    }
                    else
                    {
                        this.Site.Stockpile[stockpileKey] += construction.LeftoverPoints;
                    }
                }

                if (this.Site.Stockpile.ContainsKey(stockpileKey) && this.Site.Stockpile[stockpileKey] <= 0)
                {
                    this.Site.Stockpile.Remove(stockpileKey);
                }
            }
        }
コード例 #18
0
 public void Initialze(StaticsDB statics, TemporaryDB derivates)
 {
     this.Statics   = statics;
     this.Derivates = derivates;
     this.Processor = new GameProcessor(this);
 }
コード例 #19
0
        public MainGame(Player[] players, Player organellePlayer, StaticsDB statics, StatesDB states, TemporaryDB derivates)
        {
            this.Turn = 0;

            this.StareaterOrganelles = organellePlayer;
            this.MainPlayers         = players;
            this.IsReadOnly          = false;
            this.Statics             = statics;
            this.States    = states;
            this.Derivates = derivates;

            this.Processor = new GameProcessor(this);

            this.Orders = new Dictionary <Player, PlayerOrders>();
            foreach (var player in this.AllPlayers)
            {
                this.Orders[player] = new PlayerOrders();
            }
        }
コード例 #20
0
 public override void ProcessPrecombat(StatesDB states, TemporaryDB derivates)
 {
     base.ProcessPrecombat(states, derivates);
     Colony.Population = Methods.Clamp(Colony.Population + PopulationGrowth, 0, MaxPopulation);
 }
コード例 #21
0
 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);
 }
コード例 #22
0
        private void updateDesigns(StaticsDB statics, StatesDB states, TemporaryDB derivates)
        {
            //Generate upgraded designs
            var upgradesTo = new Dictionary <Design, Design>();
            var newDesigns = new HashSet <Design>();

            foreach (var design in states.Designs.OwnedBy[this.Player])
            {
                var upgrade = this.DesignUpgrade(design, statics, states);
                if (states.Designs.Contains(upgrade))
                {
                    continue;
                }

                if (newDesigns.Contains(upgrade))
                {
                    upgrade = newDesigns.First(x => x == upgrade);
                }
                else
                {
                    this.Analyze(upgrade, statics);
                }

                design.IsObsolete  = true;
                upgradesTo[design] = upgrade;
                newDesigns.Add(upgrade);
            }
            states.Designs.Add(newDesigns);

            //Update refit orders to upgrade obsolete designs
            foreach (var upgrade in upgradesTo)
            {
                var orders = this.Player.Orders.RefitOrders;

                if (!orders.ContainsKey(upgrade.Key))
                {
                    orders[upgrade.Key] = upgrade.Value;
                }
                else if (orders[upgrade.Key] != null && orders[upgrade.Key].IsObsolete)
                {
                    orders[upgrade.Key] = upgradesTo[orders[upgrade.Key]];
                }
            }

            foreach (var site in this.Player.Orders.ConstructionPlans.Keys.ToList())
            {
                var updater = new ShipConstructionUpdater(this.Player.Orders.ConstructionPlans[site].Queue, this.Player.Orders.RefitOrders);
                this.Player.Orders.ConstructionPlans[site].Queue.Clear();
                this.Player.Orders.ConstructionPlans[site].Queue.AddRange(updater.Run());
            }

            //Removing inactive discarded designs
            var shipConstruction = new ShipConstructionCounter();

            shipConstruction.Check(derivates.Stellarises.OwnedBy[this.Player]);

            var activeDesigns = new HashSet <Design>(states.Fleets.
                                                     SelectMany(x => x.Ships).
                                                     Select(x => x.Design).
                                                     Concat(shipConstruction.Designs));
            var discardedDesigns = this.Player.Orders.RefitOrders.
                                   Where(x => x.Value == null && !activeDesigns.Contains(x.Key)).
                                   Select(x => x.Key).ToList();

            foreach (var design in discardedDesigns)
            {
                design.Owner.Orders.RefitOrders.Remove(design);
                states.Designs.Remove(design);
                this.DesignStats.Remove(design);
                this.RefitCosts.Remove(design);
            }
            foreach (var design in this.RefitCosts.Keys)
            {
                foreach (var discarded in discardedDesigns)
                {
                    this.RefitCosts[design].Remove(discarded);
                }
            }
        }
コード例 #23
0
ファイル: MainGame.cs プロジェクト: campycoder/zvjezdojedac
        public MainGame(Player[] players, Player organellePlayer, StaticsDB statics, StatesDB states, TemporaryDB derivates)
        {
            this.Turn = 0;

            this.StareaterOrganelles = organellePlayer;
            this.MainPlayers         = players;
            this.IsReadOnly          = false;
            this.Statics             = statics;
            this.States    = states;
            this.Derivates = derivates;

            this.Processor = new GameProcessor(this);
        }