
Naahh!! There can only be one Guru -- and his name is
Well, here is what I found digging through the 3.17 SDK (finally with a new Debug dll, yeah!):
Barbs enter cultural borders if an appropriate mission is chosen in
CvUnitAI::AI_barbAttackMove(). This function is only called for barbarian units with UNITAI_ATTACK (barb animals always have UNITAI_ANIMAL and they cannot enter owned plots anyway). So this represents a direct effect of the difficulty level as non-animal barbs (Warriors and Archers) spawn earlier plus in greater numbers on the higher levels. The indirect effect is indeed given by the conditional behavior of the barb units depending on the total number of non-barb cities
on the whole map (not continents! -- the continents(=areas) only determine their number of needed barbs according to their unowned tiles).
There are 2 thresholds:
A) NumCities > 2*NumPlayersAlive:
- Barbs will enter your territory if they can pillage an improvement on their next turn, so the common 1
barb Warriors and Archers will intrude to pillage improvements in your border tiles. I'm not certain about 2
mounted barb units (do barb Chariots spawn regularly?). I know about a random event which places barb Horse Archers on the map, but they demonstrate "special" behavior (they directly target the barbs' TargetCity of the area).
- Barbs will enter your territory if they can attack a city on the same turn --> this should only be possible for the uncommon 2
units.
B) NumCities > 3*NumPlayersAlive:
The restrictions for the missions are lifted to
- pillage on the 3rd turn
- attack city on the second turn
- If the barbs have calculated AREAAI_OFFENSIVE for their AreaAI (huge numbers of ATTACK barb units, most likely after random event; normally it's AREAAI_MASSING) they will straight target their chosen city without any such restrictions.
With
GAMEOPTION_RAGING_BARBARIANS it gets even worse (NumCities is irrelevant then):
- pillage on the 4th turn
- attack city on the 3rd turn
- target city when AREAAI_OFFENSIVE
Important things to keep in mind:
- Barbs will ALWAYS enter your borders if they can attack one of your units directly (--> watch your Workers!).
- Once they have entered your territory, they will consider the following options for their current turn
- pillage an improvement (50%)
- attack somebody
- depending on conditions A and B move to another tile to pillage or attack a city (or target a city)
- patrol --> here they always prefer to move into unowned tiles (this is why they don't enter in the first place; if possible they will move out again; if they somehow get boxed in by cultural borders they might also "have to" enter your territory with this mission)
- Hence they can also change their minds - if they enter to pillage on their 3rd turn, they will choose to attack somebody on their second turn if possible (if you move a defending unit to an adjacent tile).
- There are certainly special situations where barb behavior might contradict the above rules (the code for unit AI is pretty complex...)