Exemple #1
0
 private void RemovePreviousPlant(BuildablePivot produced)
 {
     if (CityImprovementPivot.HydroPlant == produced)
     {
         _improvements.Remove(CityImprovementPivot.NuclearPlant);
         _improvements.Remove(CityImprovementPivot.PowerPlant);
     }
     else if (CityImprovementPivot.NuclearPlant == produced)
     {
         _improvements.Remove(CityImprovementPivot.PowerPlant);
         _improvements.Remove(CityImprovementPivot.HydroPlant);
     }
     else if (CityImprovementPivot.PowerPlant == produced)
     {
         _improvements.Remove(CityImprovementPivot.NuclearPlant);
         _improvements.Remove(CityImprovementPivot.HydroPlant);
     }
 }
Exemple #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="player">The <see cref="Player"/> value.</param>
        /// <param name="currentTurn">The <see cref="CreationTurn"/> value.</param>
        /// <param name="name">The <see cref="Name"/> value.</param>
        /// <param name="location">The <see cref="MapSquareLocation"/> value.</param>
        /// <param name="production">The <see cref="Production"/> value.</param>
        internal CityPivot(PlayerPivot player, int currentTurn, string name, MapSquarePivot location, BuildablePivot production)
        {
            Player            = player;
            Name              = name;
            MapSquareLocation = location;
            CreationTurn      = currentTurn;
            Production        = production;

            _improvements = new List <CityImprovementPivot>();
            _wonders      = new List <WonderPivot>();

            _specialistCitizens = new List <CitizenPivot>();
            _areaMapSquares     = new List <CityAreaMapSquarePivot>
            {
                new CityAreaMapSquarePivot(this, MapSquareLocation)
            };
            _areaMapSquares.Add(new CityAreaMapSquarePivot(this, BestVacantMapSquareLocation()));

            location.ApplyCityActions();
        }
Exemple #3
0
        /// <summary>
        /// Recomputes everything before passing to the next turn.
        /// </summary>
        /// <returns>A tuple of values [finished production / settler to disband].</returns>
        internal Tuple <BuildablePivot, bool> NextTurn()
        {
            bool disbandSettler = false;

            BuildablePivot produced = null;
            bool           resetCitizensRequired  = false;
            bool           checkCitizensHappiness = false;

            if (ExtraFoodByTurn > 0)
            {
                // Fills the FoodGranaryStorage, then the FoodStorage.
                var tmpExtraFoodByTurn = ExtraFoodByTurn;
                if (_improvements.Contains(CityImprovementPivot.Granary) &&
                    FoodGranaryStorage < NextCitizenFoodRequirement)
                {
                    FoodGranaryStorage += tmpExtraFoodByTurn;
                    tmpExtraFoodByTurn  = 0;
                    if (FoodGranaryStorage > NextCitizenFoodRequirement)
                    {
                        tmpExtraFoodByTurn = FoodGranaryStorage - NextCitizenFoodRequirement;
                        FoodGranaryStorage = NextCitizenFoodRequirement;
                    }
                }
                FoodStorage += tmpExtraFoodByTurn;
            }
            else if (ExtraFoodByTurn < 0)
            {
                // Empty the FoodStorage, then the FoodGranaryStorage.
                FoodStorage += ExtraFoodByTurn;
                if (FoodStorage < 0 && _improvements.Contains(CityImprovementPivot.Granary))
                {
                    FoodGranaryStorage += FoodStorage;
                    FoodStorage         = 0;
                }
            }

            if (FoodStorage < 0 && FoodGranaryStorage < 0)
            {
                if (Player.Units.Any(u => u.Is <SettlerPivot>() && u.City == this))
                {
                    disbandSettler = true;
                }
                else
                {
                    RemoveAnyCitizen();
                    resetCitizensRequired = true;
                }
                FoodStorage        = 0;
                FoodGranaryStorage = 0;
            }
            else if (FoodStorage >= NextCitizenFoodRequirement)
            {
                if (CitizensCount < AQUEDUC_MAX_POPULATION_WITHOUT || _improvements.Contains(CityImprovementPivot.Aqueduc))
                {
                    FoodStorage = 0; // Note : excess is not keeped.
                    _areaMapSquares.Add(new CityAreaMapSquarePivot(this, BestVacantMapSquareLocation()));
                    resetCitizensRequired = true;
                }
                else
                {
                    FoodStorage = NextCitizenFoodRequirement;
                }
            }

            ProductivityStorage += Productivity;
            if (Production != null && ProductivityStorage >= Production.ProductivityCost)
            {
                bool produce = true;
                ProductivityStorage = Production.ProductivityCost;
                if (Production.Is <UnitPivot>())
                {
                    produce = false;
                    var citizensCost = ((UnitPivot)Production).CitizenCostToProduce;
                    if (citizensCost < CitizensCount)
                    {
                        for (int i = 0; i < citizensCost; i++)
                        {
                            RemoveAnyCitizen();
                        }
                        produce = true;
                    }
                }
                if (produce)
                {
                    ProductivityStorage = 0;
                    produced            = Production;
                    Production          = null;
                    if (produced.Is <CityImprovementPivot>())
                    {
                        _improvements.Add((CityImprovementPivot)produced);
                        if (CityImprovementPivot.Granary == produced)
                        {
                            // Note : at this point, "NextCitizenFoodRequirement" takes the granary in consideration.
                            if (FoodStorage > NextCitizenFoodRequirement)
                            {
                                FoodGranaryStorage = NextCitizenFoodRequirement;
                                FoodStorage       -= NextCitizenFoodRequirement;
                            }
                            else
                            {
                                FoodGranaryStorage = FoodStorage;
                                FoodStorage        = 0;
                            }
                        }
                    }
                    else if (produced.Is <WonderPivot>())
                    {
                        _wonders.Add((WonderPivot)produced);
                    }
                    if (produced.HasCitizenHappinessEffect)
                    {
                        checkCitizensHappiness = true;
                    }
                }
            }

            if (resetCitizensRequired)
            {
                ResetCitizens();
            }
            else if (checkCitizensHappiness)
            {
                CheckCitizensHappiness();
            }

            if (produced != null)
            {
                RemovePreviousPlant(produced);
            }

            return(new Tuple <BuildablePivot, bool>(produced, disbandSettler));
        }
Exemple #4
0
 /// <summary>
 /// Changes the city current production.
 /// </summary>
 /// <param name="buildable">The new production.</param>
 internal void ChangeProduction(BuildablePivot buildable)
 {
     Production = buildable;
 }