Barbarian spawning logic

megabearsfan

Prince
Joined
Jan 17, 2006
Messages
552
Location
Las Vegas, NV
Has anyone ever looked at the logic for barbarian spawning?

Does the logic decide that it wants to spawn a barb first, and then look for an appropriate place to do so (if one exists)?

Or does it loop through the tiles looking for a legal place to spawn a barb, and then deciding whether to spawn one or not?


Basically, I'm wondering if keeping extended visibility over your local region of the map would cause barbarians to spawn more frequently near other civs (because the game commits to spawning a barb, then finds an open tile to do it). Or if having such visibility just effectively reduces the likelihood of barbarians spawning at all (because there are fewer chances for a barb to spawn).
 
Very, very brief and abstracted description of void CvBarbarians:: DoCamps(). To make this comparatively brief, I have omitted the minor details to save time :crazyeye:.

Code:
Check if no barbarians is enabled.

Loop through every plot on the map: Determine number of existing barbarian camps, number of non-water tiles that is not visible to to all teams.

Pull from game database the number of barbarian camps per fog tile.

The [I]target[/I] number of camps is equal to the number of eligible plots divided by iFogTilesPerBarbarianCamp.

Number of camps to add (Target - already exisiting) is set

If this is the first turn of game, pull from game database the percentage of barbarian camps to spawn right off the get-go.

If this is not the first turn of the game, there is a 1 in 2 chance of spawning a camp each turn.

Apply a 1 in 6 chance (dice roll) of placing the barbarian camp on a coastal tile (so it can spawn boats).

Barbarian camps cannot be
[LIST]
[*]Less than 4 tiles from a capital
[*]Less than 7 tiles distance from another camp
[/LIST]

The maximum distance to look around a plot is the maximum of the 2 values defined above.

While loop: look through all eligible land plots in a [B]random[/B] order (think of shuffling a deck of cards), go through the following conditionals/steps:
[LIST]
[*]Plot must not be water 
[*]Cannot be impassable (mountain or natural wonder or otherwise)
[*]Plot cannot be owned, or be visible to any teams
[*]There cannot be any resources on that tile
[*]No camps on 1-tile islands
[*]Maximum camps for this continent = iCampTargetNum * Number of tiles on this continent / Number of total land plots
[*]Don't look at tiles with a camp on it
[*]Don't look at tiles with any sort of improvement on it (Read: Ancient Ruins and Excavation Dig Sites)
[*]Loop around this plot, with a radius of max (the 2 "cannot be closer than" variables defined at the start")
[*]Check if a camp or a capital is too close
[*]Only care about non-city-state capitals! I.e. they can spawn next to city states if vision is blocked by a hill/mountain 
[*]If plot checks out ok, add the camp, add a unit to it.
[*]Update visibility for those who have the Honor Opener
[*]"Seed" (i.e. set) whether the next camp needs to be coastal or not (1/5-6 chance)
[/LIST]

Hope that helps!
 
Thanks ThorHammerz, this is very useful. Cannot spawn within seven tiles of another barb camp, I kind of suspected something along those lines, but it is good to see it in writing. Another interesting one is the 1/6 chance of being coastal, so playing archipelago do the same rules apply in so much as 5/6 times an inland location will be found if available? In past games I have noticed that if there are very few inland spots matching the criteria from the database then the same camp seems to spawn frequently!
 
Thanks ThorHammerz, this is very useful. Cannot spawn within seven tiles of another barb camp, I kind of suspected something along those lines, but it is good to see it in writing. Another interesting one is the 1/6 chance of being coastal, so playing archipelago do the same rules apply in so much as 5/6 times an inland location will be found if available? In past games I have noticed that if there are very few inland spots matching the criteria from the database then the same camp seems to spawn frequently!

Hey,

Spoiler :
I have not done very much game-play testing (my computer is not suited to do the "turn on FireTuner and run the game on auto-play.... it usually takes 10x longer for each turn to finish and crashes very soon), so take my answer with a grain of salt, as I am basing it off purely from the design algorithm:

The 1/6 chance does not take into consideration if the map is a "naval" or "offshore expansion" map.

Spoiler :

For reference, this can be accessed by checking
Code:
GC.getMap().GetAIMapHint() & 4  [B]or[/B]
GC.getMap().GetAIMapHint() & 1

So yes, on an archipelago if there are only a few eligible spawn areas, then those areas will continue to host barb camps until you fog-bust it permanently.

Think of an alternate (and perfectly replicable) scenario: let's say you're playing on a landmass with a moderately sized peninsular that you are deliberately blocking off from the AI, and that you are keeping in the fog of war. Everywhere else on the map is invalidated from spawning barbarians due to vision.

If you were to run in, clean camps, run out, and leave it in the dark for a little while (10 turns maybe? depends on RNGesus hitting that dice roll for you), you will find a new barb camp inside.

- TH.
 
Hey,

Spoiler :
I have not done very much game-play testing (my computer is not suited to do the "turn on FireTuner and run the game on auto-play.... it usually takes 10x longer for each turn to finish and crashes very soon), so take my answer with a grain of salt, as I am basing it off purely from the design algorithm:

The 1/6 chance does not take into consideration if the map is a "naval" or "offshore expansion" map.

Spoiler :

For reference, this can be accessed by checking
Code:
GC.getMap().GetAIMapHint() & 4  [B]or[/B]
GC.getMap().GetAIMapHint() & 1

So yes, on an archipelago if there are only a few eligible spawn areas, then those areas will continue to host barb camps until you fog-bust it permanently.

Think of an alternate (and perfectly replicable) scenario: let's say you're playing on a landmass with a moderately sized peninsular that you are deliberately blocking off from the AI, and that you are keeping in the fog of war. Everywhere else on the map is invalidated from spawning barbarians due to vision.

If you were to run in, clean camps, run out, and leave it in the dark for a little while (10 turns maybe? depends on RNGesus hitting that dice roll for you), you will find a new barb camp inside.

- TH.

Thanks, you are a very considerate person, much appreciated.
 
Top Bottom