// Start is called before the first frame update void Start() { _animalController = GetComponent <AnimalController>(); _foodDistributionScript = GetComponent <FoodDistributionScript>(); _populations = _animalController.GetAnimalPopulations(); InitializeGrowthTimers(); }
public void UpdateFoodNeeds() { // Reset food needs values foreach (FoodSource foodSource in foodSources) { foreach (AnimalPopulation animalPopulation in animalController.GetAnimalPopulations()) { Need <float> foodSourceNeed = (Need <float>)animalPopulation.GetNeed(foodSource.Type); if (foodSourceNeed != null) { foodSourceNeed.CurrentValue = 0f; } } } foreach (FoodSource foodSource in foodSources) { int totalDominance = 0; // The list of animals that can consume the food source. List <AnimalPopulation> animalsThatCanConsumeFoodSource = new List <AnimalPopulation>(); // Iterate over all the existing animal populations and see if the food source is edible to any of them and // add them to animalsThatCanConsumeFoodSource list and also count up the total amount of dominance that will // be competing for the food source. foreach (AnimalPopulation animalPopulation in animalController.GetAnimalPopulations()) { if (animalPopulation.IsEdible(foodSource)) { totalDominance += animalPopulation.PopulationDominance(); animalsThatCanConsumeFoodSource.Add(animalPopulation); } } // Calculate the FoodPerIndividual score for each animal population. foreach (AnimalPopulation animalPopulation in animalsThatCanConsumeFoodSource) { float populationFood = ((float)animalPopulation.PopulationDominance() / (float)totalDominance) * foodSource.Output; float foodPerIndividual = populationFood / (float)animalPopulation.PopulationSize; Need <float> foodSourceNeed = (Need <float>)animalPopulation.GetNeed(foodSource.Type); //Debug.Log(foodSourceNeed.CurrentValue); foodSourceNeed.CurrentValue += foodPerIndividual; } } }
private void getAllAnimalPoplulation() { this.animalPopulations = animalController.GetAnimalPopulations(); }