Exemplo n.º 1
0
 public GrowthCalculator(Population population)
 {
     this.population      = population;
     this.GrowthCountdown = population.Species.GrowthRate;
     this.DecayCountdown  = population.Species.DecayRate;
     this.GrowthStatus    = GrowthStatus.stagnate;
 }
Exemplo n.º 2
0
    /*
     *  0. if any predators nearby, population set to decrease next day
     *  1. if any need not met, handle growth logic and set growth status
     *  2. if all needs met, handle growth logic
     */
    public void CalculateGrowth()
    {
        float predatorValue = calculatePredatorPreyNeed();

        if (predatorValue > 0f)
        {
            this.GrowthStatus           = GrowthStatus.declining;
            this.DecayCountdown         = 1;
            this.populationIncreaseRate = -1 * predatorValue;
            return;
        }
        this.CalculateTerrainNeed();
        this.CalculateWaterNeed();
        this.GrowthStatus = GrowthStatus.growing;

        foreach (KeyValuePair <NeedType, bool> need in new Dictionary <NeedType, bool>(IsNeedMet))
        {
            if (!need.Key.Equals(NeedType.Prey) && !IsNeedMet[need.Key])
            {
                //If any need is not being met, set the growth status to declining
                GrowthStatus = GrowthStatus.declining;
            }
            IsNeedMet[need.Key] = false;
        }

        populationIncreaseRate = 0f;

        if (this.GrowthStatus == GrowthStatus.growing)
        {
            //Scales the increase rate between 100% and 200% population increase
            populationIncreaseRate = (waterRating + foodRating + terrainRating) / 3f;
        }
        else
        {
            //Scales the increase rate between 0% and 100% population decrease (could potentially wipe out a population if the player is failing as much as possible)
            populationIncreaseRate = (Mathf.Min(waterRating, 0) + Mathf.Min(foodRating, 0) + Mathf.Min(terrainRating, 0)) / 3f;
        }

        Debug.Log("Population status: " + this.GrowthStatus.ToString() + ", increase rate: " + populationIncreaseRate);
    }