How does barbarian city spawning work?

Joined
Apr 29, 2003
Messages
4,509
Location
the Netherlands
There are lots of threads about barbarian spawning and how to avoid it. Avoiding the spawning of barbarian cities works similar, just remove the fog of war and they won't spawn. However, I'm interested in the more detailed mechanics of barbarian city spawning/founding. Does anyone know how it works? Has anyone looked into the code of the game to see how it works?


Below are some questions to which I would like to see some answers. Any information that extends my knowledge on the issue would be appreciated, even if it is just a confirmation of some of my suspicions.

-From game experience, it seems that a barbarian city cannot spawn as long as the centre city tile or any of the 8 adjacent tiles are visible to some civilisation. Is this correct?

-It seems that the barbarian city spawning/founding code is different from the city founding code of a real civilisation. A normal civilisation tries to keep its cities at a certain distance of other already founded cities (plot-distance 4 or 5 is optimal). The barbarians seem to spawn their cities in a way as to greedily grab as many good tiles (like resources). This of course means that their cities tend to not fit very well in the settling pattern that the human player or AI tries to create. Does anyone know how the barbarian AI picks its settling spots?

-It seems that barbarians first appear at a certain date but remain somewhat passive and won't enter cultural borders or attack cities (first animal barbarians, then warriors and archers). The type of military unit available to the barbarian civilisation is related to what is available to the various civilisations in the world. Somewhat later, they will start to attack cities and a little later barbarian cities will start to spawn. Each of these events also occurs earlier on the higher difficulty levels than on the lower difficulty levels. What are the triggers for each of these events? I know one of them is related to the average number of cities per player on that continent, but I don't recall the details.

-I regularly find barbarian cities on the continent which I started on or on the continents that the AI civilisations started on, but barbarian cities seem to be rare on islands which are discovered later. It could be a coincidence, but maybe there is some prerequisite for the spawning of barbarian cities which is related to the presence of a real civilisation or the size of the land. Does such a condition exist?

Thanks in advance to anyone who can help me answer some of these questions. :bowdown:
 
The only thing I can contribute here is that barbarian cities are supposed to spawn if (# of civs on continent) + 1 city has been founded (correct me if I'm even here wrong...)

I looked in the reference sheet, where it also says that # of turns when barbs start spawning is dependant on difficulty level.

Hoping for some answers as well, great idea, getting some more insight in what might be considered as rather unimportant.
 
I noticed on the earth 18 civ scenario that the cities always spawned on top of goody huts. Not sure if this is always the case, or it that just happens on that map. That map always seems to have the goody huts in the same place, so it might not be the way things always work.
 
Barb City Spawning works like this (BC = Barbarian Cities.. Civ= non Barb Civ, TG = Target Barb Cities (global) TC= Target Barb Cities (Continental), TCM Total Cities Modifier)

1. Determine if a Barb city will spawn
Requirements:
Number of Civ Cities >= Number of Civs alive * 2
Game Turn > Barb city Spawning Turn (based on Difficulty)
Random (1-100) < Barb City Creation probability (based on Difficulty)

2. Determine Where the barb city will spawn
The barb city will spawn on the city center tile that has the highest Value and meets the Requirements

Requirements:
Not Water,
Not Visible to Civs
Number of Barb cities on that Tile's continent < TC

The Value of a City settling Tile for barbs is calculated this way
=Basic AI city founding Value with a "Min Barb city Starting distance" factor
*Number of Owned tiles on the continent IF TCM >100
+100-150 (Random)
/100

The Highest Value gets it

TC (Target Number of BC for a continent)
=Unowned Tiles
* 3 if there are no civ cities on this continent (Barb cities here=total cities here)
* a Modifier (TCM) if the number of Total tiles on this continent are low (less than 1/3 of the total 'unowned tiles per barbarian city')
/ Unowned Tiles per barbarian city (Handicap info)

TG (Target number of BC for the world)
= 5*Civ Cities*Barb City Creation probability/100

TCM (Modifier)
=100
+300 * (TG-BC)/TG (Positive numbers only)
*1.5 if Raging Barbs is on

-From game experience, it seems that a barbarian city cannot spawn as long as the centre city tile or any of the 8 adjacent tiles are visible to some civilisation. Is this correct?:

The city center yes.. not the other 8

-It seems that the barbarian city spawning/founding code is different from the city founding code of a real civilisation. A normal civilisation tries to keep its cities at a certain distance of other already founded cities (plot-distance 4 or 5 is optimal). The barbarians seem to spawn their cities in a way as to greedily grab as many good tiles (like resources). This of course means that their cities tend to not fit very well in the settling pattern that the human player or AI tries to create. Does anyone know how the barbarian AI picks its settling spots?:

Same as the AI does, with some minimum limit of closeness (I'd have to look more at the City Tile valuation algorithm.. but I'm guessing the Barb city Minimum distance number is less than the AI standard one)

-It seems that barbarians first appear at a certain date but remain somewhat passive and won't enter cultural borders or attack cities (first animal barbarians, then warriors and archers). The type of military unit available to the barbarian civilisation is related to what is available to the various civilisations in the world. Somewhat later, they will start to attack cities and a little later barbarian cities will start to spawn. Each of these events also occurs earlier on the higher difficulty levels than on the lower difficulty levels. What are the triggers for each of these events? I know one of them is related to the average number of cities per player on that continent, but I don't recall the details.:

Well, it's not average cities per player on the continent, it's the Average civ cities/civ player in the World that must be 2 or more

Otherwise it is just game turn (different at different difficulty levels)

-I regularly find barbarian cities on the continent which I started on or on the continents that the AI civilisations started on, but barbarian cities seem to be rare on islands which are discovered later. It could be a coincidence, but maybe there is some prerequisite for the spawning of barbarian cities which is related to the presence of a real civilisation or the size of the land. Does such a condition exist?

Thanks in advance to anyone who can help me answer some of these questions. :bowdown:

Well this is a complex thing, if
EITHER Global Barb cities are below expected levels OR Raging Barbs is on

Then you get the Barb cities Favoring "Settled" Continents (ie ones with Owned Tiles)

However, for a Continent to Qualify for Barbs, there must be enough Unowned Tiles for it to fit in a barb city. This number of tiles it has available if it has no "Civ" cities ie either Barren or Barb owned.

So Basically Barbs will tend to go on the Settled continent If they Can (if Raging Barbs are on, and/or there are too few Barb cities world wide)
However it is easier for them to "fit" on continents with no other civs.

(The preference is obviously for a Barb Settled continent ie the Terran new World)
 
Barb City Spawning works like this (BC = Barbarian Cities.. Civ= non Barb Civ, TG = Target Barb Cities (global) TC= Target Barb Cities (Continental), TCM Total Cities Modifier)

Thank you for the very interesting information, Krikkitone. It might not be easy to understand all of what you wrote or the implications of these algorithms and thus it might not be that interesting to many, but it was exactly the kind of information that I was looking for. Thank you. :worship:

I assume that only a single barbarian city can spawn during a game turn and there also seems to be no modifier for the size of the map or the game speed setting. If I understand that correctly, it means that the target number of barbarian cities will be reached a little slow on the larger map sizes with many AI civilizations which are creating cities. On the other hand, if you play at the slower game speeds, the barbarian cities have all the time to spawn as there are more game turns during which they can spawn.

Another reason why the slower game speeds and bigger maps are a good combination.

1. Determine if a Barb city will spawn
Requirements:
Number of Civ Cities >= Number of Civs alive * 2
Game Turn > Barb city Spawning Turn (based on Difficulty)
Random (1-100) < Barb City Creation probability (based on Difficulty)

2. Determine Where the barb city will spawn
The barb city will spawn on the city center tile that has the highest Value and meets the Requirements

Requirements:
Not Water,
Not Visible to Civs
Number of Barb cities on that Tile's continent < TC

The Value of a City settling Tile for barbs is calculated this way
=Basic AI city founding Value with a "Min Barb city Starting distance" factor
*Number of Owned tiles on the continent IF TCM >100
+100-150 (Random)
/100

The Highest Value gets it

That factor "Number of Owned tiles on the continent IF TCM >100" is pretty large as long as the barbarians don't have enough cities. I guess that the barbarians would rather found a crappy city on an already settled continent than a great one on an undiscovered and unsettled continent (as long as there is enough room left). There is some logic in that as where did those people come from on that unsettled continent (apparently a native people that just started creating cities).

Do the tiles owned by a barbarian city count as tiles owned on the continent?

I guess that on a terra map, the barbarian cities first arise in the old world until it is almost fully settled and only when the barbarian cities cannot spawn in the old world anymore will the first one spawn in the new world. When that has happened, many more will spawn in the new world.

TC (Target Number of BC for a continent)
=Unowned Tiles
* 3 if there are no civ cities on this continent (Barb cities here=total cities here)
* a Modifier (TCM) if the number of Total tiles on this continent are low (less than 1/3 of the total 'unowned tiles per barbarian city')
/ Unowned Tiles per barbarian city (Handicap info)

Should the factor TCM in this formula maybe be divided by 100? TCM is a value between 100 and 600 and that would make the target number of continental cities a bit high.

TG (Target number of BC for the world)
= 5*Civ Cities*Barb City Creation probability/100

TCM (Modifier)
=100
+300 * (TG-BC)/TG (Positive numbers only)
*1.5 if Raging Barbs is on



The city center yes.. not the other 8

So when you uncover all but a single tile on a continent, then a barbarian city could arise on that single tile and the probability of that happening wouldn't even be diminished by you uncovering all of those other tiles? Weird, I haven't seen that happen yet.

Same as the AI does, with some minimum limit of closeness (I'd have to look more at the City Tile valuation algorithm.. but I'm guessing the Barb city Minimum distance number is less than the AI standard one)

I guess that the barbarian cities don't fit nice with the other cities because of all the exploring units which obstruct the best settling locations.

Well, it's not average cities per player on the continent, it's the Average civ cities/civ player in the World that must be 2 or more

I knew that it was something like that. Thanks.

Well this is a complex thing, if
EITHER Global Barb cities are below expected levels OR Raging Barbs is on

Then you get the Barb cities Favoring "Settled" Continents (ie ones with Owned Tiles)

However, for a Continent to Qualify for Barbs, there must be enough Unowned Tiles for it to fit in a barb city. This number of tiles it has available if it has no "Civ" cities ie either Barren or Barb owned.

So Basically Barbs will tend to go on the Settled continent If they Can (if Raging Barbs are on, and/or there are too few Barb cities world wide)
However it is easier for them to "fit" on continents with no other civs.

(The preference is obviously for a Barb Settled continent ie the Terran new World)[/QUOTE]

Yes, I understand. Very interesting. You might find a new large island, completely unsettled and found a single city on it which just happens to increase the world wide barbarian target number of cities and also makes that island the most attractive founding location. Thus shortly after you've settled your city, a barbarian city will arise on that large island (assuming that enough empty tiles are left).

Thank you again for the interesting information! :goodjob:
 
Back
Top Bottom