I have a set of game objects positioned around a map with city models attached to them.
Each has a class Settlement attached, on a timer I execute a function in every settlement function.
public float population_growth{
get{
float housing_avalibility = Mathf.Clamp(1 - ((float)population_count/(float)housing_capacity), 0.0f, 1.0f);
float food_avalibility = Mathf.Clamp(1 - ((float)food_consumed/(float)food_produced), 0.0f, 1.0f);
float growth = ((0.5f * housing_avalibility) + (0.5f * food_avalibility)) * 0.5f;
growth = Mathf.Clamp(growth, 0.0f, 0.5f);
Debug.Log ("growth = " + growth + ", with housing at " + housing_avalibility*100 + "%, with food at "+ food_avalibility*100 + "%");
return growth;
}
}
public void ReproductionCycleUpdate(){
//need to add immigration
population_count += Mathf.RoundToInt(n_children);
n_children = Mathf.RoundToInt(population_growth * population_count);
eligable_recruits += Mathf.RoundToInt(population_count * recruits_rate);
Debug.Log ("population = " + population_count);
Debug.Log ("children = " + n_children);
Debug.Log ("eligable recruits = " + eligable_recruits);
}
I currently use population growth to calculate the growth rate, however I am not sure the best approach but I want to be able to base the growth rate of a number of variables such as how much housing is available and how much food surplus is available.
The growth cannot be lower than 0 or greater than 0.5 (presumes ruffly that 50% are females that can reproduce 1 child and that any anomalies to this balance)