public void UpdatePopulation() //daily routine { //Update Citizens //Update Happiness //Process migration ulong overallHappiness = 0; //Though, with maxPopulation being set to 10E7, uint would be more than enough to handle these sums. ulong healthHappines = 0; ulong homeHappines = 0; ulong jobHappines = 0; ulong environmentHappiness = 0; for (int i = population.Count - 1; i >= 0; i--) { Citizen citizen = population[i]; if (!citizen.ProcessFinances()) //in current ProcessFinances implementation, return false if citizen can't pay its life expenses. So we remove it from simulation. { //print ("Citizen can't pay its expenses, removing it from simulation"); //test citizen.Emigrate(); population.RemoveAt(i); } else { //TODO handle remaining citizen updates here. DO NOT DO THIS OUTSIDE THIS ELSE CLAUSE! //Check if needing work, or if needing hospitalization citizen.Lookups(); //compute citizen's happiness here. UpdateCitizenHappiness(citizen); //add citizen's happines to sum overallHappiness += citizen.happiness.overall; healthHappines += citizen.happiness.health; homeHappines += citizen.happiness.home; jobHappines += citizen.happiness.job; environmentHappiness += citizen.happiness.environment; } } //Update populationHappiness int _populationCount = Mathf.Max(population.Count, 1); //to avoid division-by-zero at start of game when there is no population. populationHappiness.overall = (uint)Mathf.RoundToInt((float)overallHappiness / (float)_populationCount); populationHappiness.health = (uint)Mathf.RoundToInt((float)healthHappines / (float)_populationCount); populationHappiness.home = (uint)Mathf.RoundToInt((float)homeHappines / (float)_populationCount); populationHappiness.job = (uint)Mathf.RoundToInt((float)jobHappines / (float)_populationCount); populationHappiness.environment = (uint)Mathf.RoundToInt((float)environmentHappiness / (float)_populationCount); //process migration ProcessMigration(); }