Пример #1
0
    void FeedSurvivors()
    {
        List <GameObject> survivors = GetUnfedSurvivors();

        // First, make them all hungry
        for (int i = 0; i < survivors.Count; i++)
        {
            Hunger hunger = survivors [i].GetComponent <Hunger> ();
            hunger.IncreaseHunger(CalculateHunger(hunger));
            hunger.FedToday = false;
        }

        // Now we find the most hungry and feed them
        while (farmManager.CurrentFood > 0)
        {
            int highestHunger = 0;
            int highestIndex  = 0;

            for (int i = 0; i < survivors.Count; i++)
            {
                Hunger hunger = survivors [i].GetComponent <Hunger> ();
                if (hunger.Hungers > highestHunger)
                {
                    highestHunger = hunger.Hungers;
                    highestIndex  = i;
                }
            }

            if (highestHunger > 0)
            {
                Hunger hunger = survivors [highestIndex].GetComponent <Hunger> ();
                hunger.DecreaseHunger(foodDecreaseAmount);
                hunger.FedToday = true;

                farmManager.DecreaseRations(1);
            }
            else
            {
                break;
            }
        }

        // If we have no food
        if (farmManager.CurrentFood <= 0)
        {
            reportManager.AddToReport(ReportManager.ReportTypes.FarmEmpty);
        }

        // Now we make a report of any who are unfed
        for (int i = 0; i < survivors.Count; i++)
        {
            Hunger hunger = survivors [i].GetComponent <Hunger> ();
            if (!hunger.FedToday)
            {
                if (hunger.Hungers >= 100)
                {
                    reportManager.AddToReport(ReportManager.ReportTypes.StarvingSurvivor);
                    survivors [i].GetComponent <LivingEntity> ().TakeHit(1);
                }
                else
                {
                    reportManager.AddToReport(ReportManager.ReportTypes.UnfedSurvivor);
                }
            }
        }
    }