Beyond_Beyaan.Planet.UpdatePlanet C# (CSharp) Метод

UpdatePlanet() публичный Метод

public UpdatePlanet ( ) : void
Результат void
        public void UpdatePlanet()
        {
            bool setInfrastructureToZero = false;
            bool setDefenseToZero = false;
            bool setEnvironmentToZero = false;
            bool setConstructionToZero = false; //Only used when Stargates are built
            //Update ship construction
            if (ConstructionAmount > 0)
            {
                ShipConstructionAmount += ConstructionAmount * 0.01f * ActualProduction;
            }

            Factories += AmountOfBuildingsThisTurn;
            _factoryInvestments += AmountLostToRefitThisTurn;
            _factoryInvestments += AmountOfBuildingsThisTurn * _owner.TechnologyManager.FactoryCost;

            if (Factories >= TotalMaxPopulation * _owner.TechnologyManager.RoboticControls)
            {
                setInfrastructureToZero = true;
                //TODO: Notify player
            }

            Waste = AmountOfWasteCleanupNeeded;
            if (Waste > PopulationMax - 10)
            {
                Waste = PopulationMax - 10;
            }

            if (AmountLostToUpgradeThisTurn > 0)
            {
                _baseInvestments += AmountLostToUpgradeThisTurn;
                AmountLostToUpgradeThisTurn = 0;
            }
            if (AmountToInvestInShield > 0)
            {
                _shieldProjectRevenues += AmountToInvestInShield;
                if (_shieldProjectRevenues >= 500)
                {
                    //Upgrade the shield to next level
                    ShieldLevel += 5;
                    _shieldProjectRevenues -= 500;
                    if (ShieldLevel == _owner.TechnologyManager.HighestPlanetaryShield)
                    {
                        //TODO: Notify player that shield has been built, and invest the remaining BCs into bases, then set military spending to 0
                        float amountOfBCs = _shieldProjectRevenues;
                        setDefenseToZero = true;
                        if (Bases * _owner.TechnologyManager.MissileBaseCost < _baseInvestments)
                        {
                            float amountNeeded = (Bases * _owner.TechnologyManager.MissileBaseCost) - _baseInvestments;
                            if (amountOfBCs < amountNeeded)
                            {
                                _baseInvestments += amountOfBCs;
                            }
                            else
                            {
                                _baseInvestments += amountNeeded;
                                AmountOfBaseInvestmentThisTurn += amountOfBCs - amountNeeded;
                            }
                        }
                        else
                        {
                            //Free to build new bases
                            AmountOfBaseInvestmentThisTurn += amountOfBCs;
                        }
                    }
                }
            }
            if (AmountOfBaseInvestmentThisTurn > 0)
            {
                //Add to investment, and see if we built some bases
                NextBaseInvestment += AmountOfBaseInvestmentThisTurn;
                _baseInvestments += AmountOfBaseInvestmentThisTurn;
                //TODO: Factor in Nebula
                while (NextBaseInvestment >= _owner.TechnologyManager.MissileBaseCost)
                {
                    Bases++;
                    NextBaseInvestment -= _owner.TechnologyManager.MissileBaseCost;
                }
            }

            if (TerraformProjectInvestment > 0)
            {
                if (_owner.TechnologyManager.HasAtmosphericTerraform && (_planetType == PLANET_TYPE.RADIATED ||
                    _planetType == PLANET_TYPE.TOXIC || _planetType == PLANET_TYPE.VOLCANIC || _planetType == PLANET_TYPE.DEAD ||
                    _planetType == PLANET_TYPE.TUNDRA || _planetType == PLANET_TYPE.BARREN))
                {
                    //Invest into changing this to Arctic planet
                    _terraformProjectRevenues += TerraformProjectInvestment;
                    TerraformProjectInvestment = 0;
                    if (_terraformProjectRevenues >= 200) //Converted to Arctic
                    {
                        _terraformProjectRevenues -= 200;
                        //Barren planets get no population bonus.
                        if (_planetType == PLANET_TYPE.TUNDRA || _planetType == PLANET_TYPE.DEAD)
                        {
                            _populationMax += 10;
                        }
                        else if (_planetType != PLANET_TYPE.BARREN)
                        {
                            _populationMax += 20;
                        }
                        _planetType = PLANET_TYPE.ARCTIC;
                        EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.AVERAGE;
                        TerraformProjectInvestment = _terraformProjectRevenues; //Roll over into next terraforming project
                        _terraformProjectRevenues = 0;
                        //TODO: Notify player
                    }
                }
                if (TerraformProjectInvestment > 0)
                {
                    //Handle soil/advanced soil enrichment here
                    if ((_owner.TechnologyManager.HasSoilEnrichment || _owner.TechnologyManager.HasAdvancedSoilEnrichment) && !(_planetType == PLANET_TYPE.RADIATED ||
                        _planetType == PLANET_TYPE.TOXIC || _planetType == PLANET_TYPE.VOLCANIC || _planetType == PLANET_TYPE.DEAD ||
                        _planetType == PLANET_TYPE.TUNDRA || _planetType == PLANET_TYPE.BARREN))
                    {
                        if (EnvironmentBonus == PLANET_ENVIRONMENT_BONUS.AVERAGE)
                        {
                            _terraformProjectRevenues += TerraformProjectInvestment;
                            TerraformProjectInvestment = 0;
                            if (_terraformProjectRevenues >= 150)
                            {
                                //it is now fertile
                                EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.FERTILE;
                                _terraformProjectRevenues -= 150;
                                _populationMax += (((_populationMax - 5) / 20) + 1) * 5;
                                if (!_owner.TechnologyManager.HasAdvancedSoilEnrichment)
                                {
                                    TerraformProjectInvestment = _terraformProjectRevenues; //Stop at fertile, not gaia, and roll over BCs into terraforming
                                    _terraformProjectRevenues = 0;
                                    //TODO: Notify player
                                }
                            }
                        }
                        if (EnvironmentBonus == PLANET_ENVIRONMENT_BONUS.FERTILE && _owner.TechnologyManager.HasAdvancedSoilEnrichment)
                        {
                            //Gaia development here
                            _terraformProjectRevenues += TerraformProjectInvestment;
                            TerraformProjectInvestment = 0;
                            if (_terraformProjectRevenues >= 150) //Already deducted 150 for Fertile process from Gaia's 300 cost
                            {
                                EnvironmentBonus = PLANET_ENVIRONMENT_BONUS.GAIA;
                                _terraformProjectRevenues -= 150;
                                _populationMax += (((_populationMax - 20) / 25) + 1) * 5;
                                TerraformProjectInvestment = _terraformProjectRevenues;
                                _terraformProjectRevenues = 0; //No more projects at this point, only terraforming
                                //TODO: Notify player
                            }
                        }
                    }
                }
                if (TerraformProjectInvestment > 0)
                {
                    //Handle terraforming and pop growth here
                    if (_terraformPop < _owner.TechnologyManager.MaxTerraformPop)
                    {
                        _terraformPop += TerraformProjectInvestment / _owner.TechnologyManager.TerraformCost;
                        if (_terraformPop >= _owner.TechnologyManager.MaxTerraformPop)
                        {
                            float excess = _terraformPop - _owner.TechnologyManager.MaxTerraformPop;
                            _terraformPop = _owner.TechnologyManager.MaxTerraformPop;
                            TerraformProjectInvestment = excess * _owner.TechnologyManager.TerraformCost;
                            //TODO: Notify player
                        }
                    }
                    if (TerraformProjectInvestment > 0)
                    {
                        //Finally add population
                        ExtraPopulationCloned += TerraformProjectInvestment / _owner.TechnologyManager.CloningCost;
                        if (TotalPopulation + ExtraPopulationCloned > TotalMaxPopulation)
                        {
                            ExtraPopulationCloned = TotalMaxPopulation - TotalPopulation;
                            //Excess BC are wasted, matching MoO 1's handling
                        }
                    }
                }
            }
            if (ExtraPopulationCloned > 0)
            {
                float totalPop = TotalPopulation;
                //Sanity check
                if (TotalPopulation + ExtraPopulationCloned > TotalMaxPopulation)
                {
                    ExtraPopulationCloned = TotalMaxPopulation - TotalPopulation;
                }
                foreach (var race in _races)
                {
                    _racePopulations[race] += ExtraPopulationCloned * (_racePopulations[race] / totalPop);
                }
                if (TotalPopulation >= TotalMaxPopulation)
                {
                    setEnvironmentToZero = true;
                    //Extra population will die off due to growth formula, this is very minor, in decimal place.
                    //TODO: Notify player
                }
            }

            foreach (Race race in _races)
            {
                _racePopulations[race] += CalculateRaceGrowth(race);
            }

            _races.Sort((a, b) => { return (_racePopulations[a].CompareTo(_racePopulations[b])); });

            if (setConstructionToZero)
            {
                SetOutputAmount(OUTPUT_TYPE.CONSTRUCTION, 0, true);
            }
            if (setEnvironmentToZero)
            {
                SetOutputAmount(OUTPUT_TYPE.ENVIRONMENT, 0, true);
            }
            if (setInfrastructureToZero)
            {
                SetOutputAmount(OUTPUT_TYPE.INFRASTRUCTURE, 0, true);
            }
            if (setDefenseToZero)
            {
                SetOutputAmount(OUTPUT_TYPE.DEFENSE, 0, true);
            }
            //Update the enviroment to at least sufficient to clean up waste
            SetCleanup();
            UpdateOutputs();

            //Deduct reserves if any exists
            if (Reserves > 0)
            {
                Reserves -= (TotalProductionWithTrade - ProductionLostFromExpenses);
                if (Reserves < 0)
                {
                    Reserves = 0;
                }
            }
        }