First I would like to you to check out the game mechanics for collecting food in a settlement. It can be found in this post: Collecting food.
One of the most important factors for a successful Settlement AI is to make sure that the population has enough food. A good food situation increases the population growth and loyalty among the civilians while a poor food situation might lead to disastreous effects.
A rule of thumb is that the foodPerPop variable should always be above 1 (otherwise the population starves). The maximum value is 2 and as the population get better fed they also breed faster. A settlement has two ways of increasing the food output; either it can improve the terrain around the settlement or it can build food buildings. To improve terrain more than the first level the empire must complete food research.
Winter is a special case as no food is collected during this season.
First we’ll look at how we want the Settlement AI to function:
- if foodPerPop >= 2.0: Settlement is satisfied and send a low priority request for more civilians.
- if foodPerPop > 1.5 && canImproveTerrain: Situation is fairly good but if the economy is good we improve the terrain outside the settlement.
- if foodPerPop > 1.5 && !canImproveTerrain: As the situation is fairly good we don’t do anything.
- if foodPerPop > 1.0 && canImproveTerrain: Situation could be better. Improve terrain even if economy is a bit bad.
- if foodPerPop > 1.0 && !canImproveTerrain: If room for more buildings and the settlements isn’t constructing a building we build one. A low priority request is sent for better food technology.
- if starving && canImproveTerrain: Start improving terrain even if economy is poor and swap building construction to food buildings.
- if starving && !canImproveTerrain: As above but also send a high priority request for better food technology.
The foodPerPop variables 1.5 and 1.0 is set in the Governor and allows us make sure that different settlements AIs can behave differently.