public static SpeciesCount[] ProjectNextSpeciesCount(PopulationManager populationManager) { // Use a dictionary to easily store and look up the counts Dictionary <SpeciesType, SpeciesCount> counts = new Dictionary <SpeciesType, SpeciesCount>(); // Update the counts for each population in the population manager foreach (Population population in populationManager.Populations) { // Assign the species for convenience SpeciesType species = population.species.Species; // If the dictionary does not yet contain the key // then add the key to the dictionary if (!counts.ContainsKey(species)) { counts.Add(species, new SpeciesCount() { species = population.species.Species, count = 0 }); } // Calculate the population's next size GrowthCalculator calculator = population.GrowthCalculator; counts[species].count += calculator.CalculateNextPopulationSize(); } return(counts.Values.ToArray()); }
private void OnNextDay() { PopulationManager population = GameManager.Instance.m_populationManager; List <AnimalSpecies> endangeredSpecies = new List <AnimalSpecies>(); foreach (Population pop in population.Populations) { GrowthCalculator growth = pop.GrowthCalculator; // If the population is declining at a rate lower than -0.5f, // and it has not been marked as endangered already, then // add it to the list of endangered species if (growth.populationIncreaseRate <= -0.5f && !endangeredSpecies.Contains(pop.Species)) { endangeredSpecies.Add(pop.species); } } // Signal a warning about the endangered species if (endangeredSpecies.Count > 0) { SignalWarning(endangeredSpecies); } }
public SerializableGrowthCalculator(GrowthCalculator calculator) { growthStatus = calculator.GrowthStatus.ToString(); growthCountdown = calculator.GrowthCountdown; decayCountdown = calculator.DecayCountdown; foodRating = calculator.FoodRating; waterRating = calculator.WaterRating; terrainRating = calculator.TerrainRating; populationIncreaseRate = calculator.populationIncreaseRate; // Create a list with all need met entries IEnumerable <NeedMetEntry> entries = calculator.IsNeedMet .Select(entry => new NeedMetEntry(entry)); isNeedMet = new List <NeedMetEntry>(entries); }