Example #1
0
        /// <summary>
        /// Calculates the growth for the star.
        /// </summary>
        /// <param name="race"></param>
        /// <returns>The amount of colonists the star will gain on update.</returns>
        /// <remarks>
        /// See Update().
        /// </remarks>
        public int CalculateGrowth(Race race)
        {
            double habitalValue = race.HabValue(this);
            double growthRate   = race.GrowthRate;

            if (race.HasTrait("HyperExpansion"))
            {
                growthRate *= Global.GrowthFactorHyperExpansion;
            }

            double populationGrowth = 0;

            double capacity = (double)Capacity(race) / 100.0;

            if (habitalValue < 0.0)
            {
                // negative hab planet
                populationGrowth = 0.1 * this.Colonists * habitalValue;
            }
            else if (capacity < 0.25)
            {
                // low pop planet
                populationGrowth = Colonists * growthRate / 100.0 * habitalValue;
            }
            else if (capacity > 0.25 && capacity < 1.0)
            {
                // early crowding
                populationGrowth = Colonists * growthRate / 100.0 * habitalValue;
                double crowdingFactor = Global.BaseCrowdingFactor * (1.0 - capacity) * (1.0 - capacity);
                populationGrowth *= crowdingFactor;
            }
            else if (capacity == 1.0)
            {
                // full planet
                populationGrowth = 0;
            }
            else if (capacity > 1.0 && capacity < 4.0)
            {
                // over full planet
                populationGrowth = Colonists * (capacity - 1) * -4.0 / 100.0; // .04% per 1% over capacity
            }
            else if (capacity >= 4.0)
            {
                // very over full planet: crowding deaths cap at 12%
                populationGrowth = Colonists * -0.12;
            }

            // As per vanilla Stars! the minimal colonist growth unit
            // is set as 100 colonists. A planet does not track colonists
            // by the tens. While visually this does not matter much,
            // the compounding effect of growth can make those extra tens of
            // colonists matter in the long run and mismatch the behaviour
            // of Stars! and Nova.
            int finalGrowth = (int)populationGrowth;

            finalGrowth /= 100;
            finalGrowth *= 100;

            return(finalGrowth);
        }
Example #2
0
        /// <summary>
        /// Calculate the utilized capacity (as a percentage).
        /// </summary>
        /// <param name="race"></param>
        /// <returns>Capacity in the range 1 - 100 (%).</returns>
        public int Capacity(Race race)
        {
            double maxPopulation = race.MaxPopulation;

            if (race.HasTrait("HyperExpansion"))
            {
                maxPopulation *= Global.PopulationFactorHyperExpansion;
            }

            // handle negative hab worlds
            if (race.HabValue(this) < 0.0)
            {
                maxPopulation = 25000.0;
            }

            double capacity = (Colonists / maxPopulation) * 100;

            return((int)Math.Ceiling(capacity));
        }