When do barbarian units enter cultural borders

regoarrarr

King
Joined
Nov 13, 2001
Messages
847
Location
Cincinnati, OH
Anyone know? I tried looking in the SDK and XML but was not able to find it. Seems like it must be dependent on difficulty as well as a certain time or maybe if there are a certain number of cities founded.
 
Yes it's dependent on difficulty. I don't know all the difficulties but immortal ca 1900 BC, deity ca 2500 bc.
 
I think I remember it depending of the number of cities and players on the continent. If the average number of cities per player is greater than x, they start entering cultural borders.
 
I read somewhere they enter if the average number of cities / player >= 2. Dunno if it is per continent and whether the extra settler of Deity is solely responsible for the earlier date or that there is another factor.

I guess once again we are dependent on the guru DanF.
 
:blush: Naahh!! There can only be one Guru -- and his name is
Spoiler :
Josh ;) ∞:dance::banana::dance:∞


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:move: barb Warriors and Archers will intrude to pillage improvements in your border tiles. I'm not certain about 2:move: 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:move: 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
  1. pillage an improvement (50%)
  2. attack somebody
  3. depending on conditions A and B move to another tile to pillage or attack a city (or target a city)
  4. 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...)
 
Interesting Dan. One thing I've noticed is that wounded barbs will often ignore the approximate datelines I've given (and hence likely in reality the city rules you gave) if they win a fight with a unit just outside the cultural borders moving them right next to it and there's a unit to attack or a tile to pillage in reach within the borders. Also I imagine that if a barb is trapped by expanding cultural borders and has nowhere to move but inside it, he will do so regardless of other conditions, but I'm not sure about this one.

I haven't seen mounted barbs since I got BTS from what I remember (aside from event-spawned HAs in some early versions). Also, metal-dependant barbs have been reduced drastically from Warlords from what I can tell.
 
Perhaps one of my biggest gripes with barbs to date is that they ignore fogbusters, often blowing right past them to head into owned player territory that, when they were adjacent to my unit, they couldn't see (either with fog or unit movement potential, which is apparently what the AI likes to use in a lot of cases). It's not fun to have archers, warriors, and possibly even spears ignore hill archers to pillage improvements they shouldn't know exist yet.

The above is annoying because it substantially increases the hammers I need to defeat them, especially if I don't have access to metal. Of course, the RNG is much more likely to screw you here too, not because outcomes are more or less likely, but the # of units is smaller, which means losing an archer that you just made to compensate for the archer that blew past the fogbuster means you lose a tile or two to pillaging in spite of what would have seemed a reasonable effort to contain barbs.

This seems to be affected by the RNG - they'll attack the fortified unit sometimes, sometimes they pass it. I don't know if they have some form of outside border AI that resembles what DanF has in the post above, but I'm guessing they're coded to do at least 2 different things. I DO remember this being a big, big problem for me in LHC Cathy with all that jungle near the capitol. Fogbusters there seemed routinely ignored...but I didn't think barbs had a courage factor that caused them to ignore bad odds like the AIs do...but maybe they do.
 
@TMIT

Agreed on this. I really don't like the changes made to barbs in 3.17. This is just one issue. The Galleys have been debated to death but my latest peeve is the Spears. You almost never saw spears in previous versions. The effect of adding them has been to increase the power of BW. It used to be that Chariots were an effective counter to barbs until the Swordsmen appeared. No longer. Since, as you point out, the barbs no longer attack your outposts, Archers don't work against them either!
 
TMIT: Yes I'm pretty sure from experience that they have attack courage as it seems they are less likely to attack a strong position, like archer vs archer on forested hilltop.
 
I realize its not a popular opinion, but I like the naval barb changes. In the past, I would almost never bother to build more than 1 galley, maybe 2, and only if there were islands to settle. This is not realistic in a game sense, IMHO. I should have to be more protective of my seafood, just like I have to protect my farms and mines, and my settlers and workers, etc.

I also dont mind the fact that we see more Spears now. I wish they had Chariots, to be honest, because that would force me to build Spears in situations where I may not have to build them otherwise. I imagine there must be some kind of pathing problems with random 2-move units, since we rarely see HAs even if the Barb cities have horses.

Crazy, I know, but somehow, it makes the game more immersive for me.
 
Barb units do not differ from other AI units in general, they also have a certain courage to attack. They just behave more erraticly and have lower inhibition thresholds on average.
The decision to attack a unit or not is made via a comparison of the unit's AttackOdds vs. a threshold individually specificied for all mission test calls (AI_anyAttack, AI_cityAttack). There are a lot of calculations adjusting the odds and thresholds depending on the situation of the combatants. What I read from all this is, that the AttackOdds are similar to the well known combat odds (depending on the strength, damage and bonuses of attacker and defender) + a "dare-devil offset", the AttackOddsChange. Each AI leader recalculates his/her AttackOddsChange each turn during CvPlayerAI::AI_doMilitary() according to:
[pre]AttackOddsChange = BaseAttackOddsChange + RNG(AttackOddsChangeRand) + RNG(AttackOddsChangeRand)[/pre]IIUC this value should vary around an average of BaseAttackOddsChange + AttackOddsChangeRand-1. As you can read from the Leaderhead-xml (or my converted spreadsheet :p) the barbs have BaseAttackOddsChange = 0 (it is 0 for Gandhi ... 6 for Ragnar), which would make them cowards, but their AttackOddsChangeRand = 16, that is double the value of all other leaders (8), so on average they should attack more often than Ragnar (0 + 15 > 6 + 7).
The great variation of the barbs' AttackOddsChange (0...30) is responsible for their erratic behavior -- they will often shy from combat on one turn and move pass your defenders only to attack them on the very next turn. As mentioned above the thresholds used in CvUnitAI::AI_barbAttackMove() are especially low (20, 15, 10), so that the barbs might attack regardless of the actual combat odds during certain turns, when a very high AttackOddsChange might bring them over the relevant threshold alone.

Oh yeah, and they of course have a very advanced radar to detect all your units, cities and improvements. SearchRange = (Range+1)*(BaseMovements+1), with Range being the other parameter passed in the mission test calls besides the thresholds --> a 1:move: unit will scan a circle with a diameter of 9 tiles at the minimum (Range = 1).

Edit: It's not a circle but a sqaure area of 9 x 9 tiles.
 
I read somewhere they enter if the average number of cities / player >= 2. Dunno if it is per continent and whether the extra settler of Deity is solely responsible for the earlier date or that there is another factor.

I guess once again we are dependent on the guru DanF.
Agreed on DanF ultimately having the last word on these things, nothing better than really knowing how it's coded.Especially on deity i've found barb behavior very complex. Glieses guidelines are correct most of the time, on immortal you can trust they don't enter before 2000 BC, on deity there's much more variety, sometime they don't enter before 2200 bc, sometimes they can hit ~2500 bc or even a bit earlier. I think fjordan's idea of the extra settler is correct and that the far greater variety on deity has to do with the (sometimes big) amount of cities founded early. So it should be worse on Pangeae i suspect.

More than on other levels you can clearly see on deity this "enter border" turning point especially if you haven't fog busted to well. 2520 BC no unit in sight, 2480 BC 4 units appear out of the woods, followed by 4 units 2440 BC.

@TMIT,

I agree that barbs and especially barb galley's are a nuisance, they're there to make the game more interesting though. Apart from making a good plan to get your civ going you'll need to have contingency plan's to deal with unpredictable behavior (such as barbs sometimes passing your fog busters). In the end it just adds to the complexity of the game, you'll have to decide on more units early slowing worker/settler building against taking more risks and getting pillaged. Looking at the map and ai placement often gives the answer.

Edit: @DanF, it's too late too digest everything you posted here but from quick reading it confirms my experience, good work again, one day all your findings should be bundled in a guide i think. In my deity pt III thread there were 2 interesting declarations, not on me, one of them could easily have been on me i think (and not the other if i understood what you wrote about his correctly). I'm interested what the chances were, i'll get back to you on that.
 
@DanF. . . good work again, one day all your findings should be bundled in a guide i think.
Hear here. I dont know where we would be without Dan's amazing ability to nail down these answers so quickly and efficiently.
 
Do I understand it correctly that 1 movement barbs will enter the culture of a culture size 2 city (i.e. with the BFC as cultural borders) only to pillage or on the four corners, unless AREAAI_OFFENSIVE is set? And such barbs will not enter size 3 cities, except to pillage? As of size 4 they don't even want to pillage the 9 tile first ring.

This makes creative a better trait (I know some people like barbs as experience farm, but I'd rather exp farm outside my cultural borders). Also it brings new tactics in which tiles to improve.
 
Have you ever wondered about the sudden "wave" of barb units storming towards your capital followed by surprisingly very calm periods? That's exactly when threshold B) has been passed (NumCities > 3*NumPlayers) and the barbs have calculated AREAAI_OFFENSIVE for your area. In contrast to the misleading comment in the code of CvTeamAI::AI_calculateAreaAIType ("// XXX does this ever happen?") this is almost guaranteed to happen in every game. If the barbs haven't founded a city on your landmass yet, they only need TWO attack units for that AreaAI.
The formula for this minimum number of offensive units is:
[pre]N = ((NumBarbPop+NumBarbCities+1)*20)/100 + 2[/pre]So once they have a few cities on your landmass they more or less leave you alone again, because the number of "needed" barbs per landmass is limited by the number of unowned tiles and the difficulty level.

But during this period of harassment, not even the finest [game] tactics ;) or the broadest creative-boosted cultural borders will protect you...
 
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.

If the barbs haven't founded a city on your landmass yet, they only need TWO attack units for that AreaAI.

Just to make this clear "Huge = 2"? (Probably a case of increasing knowledge, such a nasty remarks in comments could be confusing). It does make more sense though as I've indeed noticed that after some point barbs go straight to my cities in hordes; even if I had ring 3.

More seriously, Numbarpop= the total population in all barbarian cities?
 
Just to make this clear "Huge = 2"? (Probably a case of increasing knowledge, such a nasty remarks in comments could be confusing). It does make more sense though as I've indeed noticed that after some point barbs go straight to my cities in hordes; even if I had ring 3.
Correct = increased my knowledge while watching the barbs storm my improvement-less 100:culture: capital in a WBed test scenario and took a closer look at the code...
More seriously, Numbarpop= the total population in all barbarian cities?
Only the total barbarian population on your landmass (NumBarbCities likewise). So with 3 barb cities on your continent size 4 each, the barbs need N = ((3*4+3+1)*20)/100 + 2 = 5 roaming attackers for AREAAI_OFFENSIVE (hmmm, actually not *that* many).
 
Another question: does this also hold for galleys, and how do they treat the "attack city" possibility? If they only enter cultural boundaries to pillage, they should ignore AreaAIOffensive and only enter to pillage resources at most one tile in from your cultural boundaries. If this were true, then if you have three cities along the coast, the resources in the middle city would be save (at least, as long as there are no resources to pillage in the outer cities to lure the barb galleys in).
 
Top Bottom