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

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

public UpdateOutputs ( ) : void
Результат void
        public void UpdateOutputs()
        {
            #region Infrastructure Output

            AmountLostToRefitThisTurn = 0;
            AmountOfBuildingsThisTurn = 0;
            AmountOfBCGeneratedThisTurn = 0;
            if (InfrastructureAmount > 0)
            {
                float amountOfBC = (InfrastructureAmount * 0.01f * ActualProduction);
                if (Factories * _owner.TechnologyManager.FactoryCost > _factoryInvestments)
                {
                    //We need to refit
                    AmountLostToRefitThisTurn = amountOfBC / _owner.TechnologyManager.FactoryDiscount; //adjust the BC spending to match factory cost, i.e. if 5 bc per factory, it is now 10 bc with 5 actual bcs
                    if (_factoryInvestments + AmountLostToRefitThisTurn >= Factories * _owner.TechnologyManager.FactoryCost)
                    {
                        //More BC than needed to refit
                        AmountLostToRefitThisTurn -= (_factoryInvestments + AmountLostToRefitThisTurn) - (Factories * _owner.TechnologyManager.FactoryCost);
                    }
                    amountOfBC -= (AmountLostToRefitThisTurn * _owner.TechnologyManager.FactoryDiscount);
                }
                if (amountOfBC > 0)
                {
                    if (Factories >= TotalMaxPopulation * _owner.TechnologyManager.RoboticControls)
                    {
                        AmountOfBuildingsThisTurn = 0; //Already reached the max
                        AmountOfBCGeneratedThisTurn = amountOfBC * 0.5f; //Lose half to corruption
                    }
                    else
                    {
                        float amountRemaining = (TotalMaxPopulation * _owner.TechnologyManager.RoboticControls) - Factories;
                        float adjustedBC = amountOfBC / _owner.TechnologyManager.FactoryDiscount;
                        AmountOfBuildingsThisTurn = adjustedBC / _owner.TechnologyManager.FactoryCost;
                        if (AmountOfBuildingsThisTurn > amountRemaining) //Will put some into reserve
                        {
                            AmountOfBCGeneratedThisTurn = (AmountOfBuildingsThisTurn - amountRemaining) * 5;
                            AmountOfBuildingsThisTurn = amountRemaining;
                        }
                    }
                }
            }
            else
            {
                //No output at all in this field
                AmountOfBuildingsThisTurn = 0;
                AmountOfBCGeneratedThisTurn = 0;
            }
            #endregion

            #region Defense Output

            AmountToInvestInShield = 0;
            AmountOfBaseInvestmentThisTurn = 0;
            AmountLostToUpgradeThisTurn = 0;
            if (DefenseAmount > 0)
            {
                //First check to see if there's available shield projects to invest in first
                if (ShieldLevel < _owner.TechnologyManager.HighestPlanetaryShield)
                {
                    AmountToInvestInShield = DefenseAmount * 0.01f * ActualProduction;
                }
                else
                {
                    //Building bases, but first, do we need to upgrade?
                    //TODO: Factor in nebula
                    float amountOfBCs = DefenseAmount * 0.01f * ActualProduction;
                    if (Bases * _owner.TechnologyManager.MissileBaseCost > _baseInvestments)
                    {
                        float amountNeeded = (Bases * _owner.TechnologyManager.MissileBaseCost) - _baseInvestments;
                        if (amountOfBCs < amountNeeded)
                        {
                            AmountLostToUpgradeThisTurn = amountOfBCs;
                        }
                        else
                        {
                            AmountLostToUpgradeThisTurn = amountNeeded;
                            AmountOfBaseInvestmentThisTurn = amountOfBCs - amountNeeded;
                        }
                    }
                    else
                    {
                        //Free to build new bases
                        AmountOfBaseInvestmentThisTurn = amountOfBCs;
                    }
                }
            }
            #endregion

            #region Environment Output

            AmountOfWasteCleanupNeeded = Waste; //Start with any leftover waste from last turn
            float factoriesOperated = TotalPopulation > (Factories / Owner.TechnologyManager.RoboticControls)
                                        ? Factories
                                        : (TotalPopulation * Owner.TechnologyManager.RoboticControls);
            AmountOfWasteCleanupNeeded += factoriesOperated * _owner.TechnologyManager.IndustryWasteRate;
            if (AmountOfWasteCleanupNeeded > _populationMax - 10)
            {
                AmountOfWasteCleanupNeeded = _populationMax - 10; //cap at base pop - 10
            }
            TerraformProjectInvestment = 0;
            ExtraPopulationCloned = 0;
            if (EnvironmentAmount > 0)
            {
                float amountOfBC = EnvironmentAmount * 0.01f * ActualProduction;
                float wasteBCCleanup = AmountOfWasteCleanupNeeded / Owner.TechnologyManager.IndustryCleanupPerBC;

                if (amountOfBC < wasteBCCleanup) //Polluting a bit
                {
                    AmountOfWasteCleanupNeeded -= amountOfBC * Owner.TechnologyManager.IndustryCleanupPerBC;
                }
                else
                {
                    AmountOfWasteCleanupNeeded = 0;
                    amountOfBC -= wasteBCCleanup; //Use remaining funds for terraforming/pop growth
                    if (amountOfBC > 0)
                    {
                        if (_owner.TechnologyManager.HasAtmosphericTerraform && EnvironmentBonus == PLANET_ENVIRONMENT_BONUS.HOSTILE ||
                            _owner.TechnologyManager.HasSoilEnrichment && EnvironmentBonus == PLANET_ENVIRONMENT_BONUS.AVERAGE ||
                            _owner.TechnologyManager.HasAdvancedSoilEnrichment && EnvironmentBonus != PLANET_ENVIRONMENT_BONUS.GAIA ||
                            _terraformPop < _owner.TechnologyManager.MaxTerraformPop)
                        {
                            //Invest into improving the planet
                            TerraformProjectInvestment += amountOfBC;
                        }
                        else
                        {
                            //Grow some more people
                            ExtraPopulationCloned = amountOfBC / _owner.TechnologyManager.CloningCost;
                            if (TotalMaxPopulation < ExtraPopulationCloned + TotalPopulation)
                            {
                                ExtraPopulationCloned = TotalMaxPopulation - (ExtraPopulationCloned + TotalMaxPopulation);
                            }
                        }
                    }
                }
            }
            #endregion

            if (ResearchAmount > 0)
            {
                AmountOfRPGeneratedThisTurn = ResearchAmount * 0.01f * ActualProduction;
            }
        }

Usage Example

Пример #1
0
 public void SetHomeSystem(StarSystem homeSystem, Planet homePlanet)
 {
     selectedSystem = homeSystem;
     lastSelectedSystem = homeSystem;
     PlanetManager.AddOwnedPlanet(homePlanet);
     FleetManager.SetupStarterFleet(homeSystem);
     homePlanet.ShipBeingBuilt = FleetManager.CurrentDesigns[0];
     homePlanet.SetCleanup();
     homePlanet.UpdateOutputs();
 }