How does one get the AI to guard a resource?

bdmarti

Chieftain
Joined
Sep 17, 2006
Messages
65
In game, it is common to see the AI post a fortified unit on a resource like copper or oil.

How can I get the AI to do that for other arbitrary resources?
 
bdmarti said:
In game, it is common to see the AI post a fortified unit on a resource like copper or oil.

How can I get the AI to do that for other arbitrary resources?
I haven't looked at this in depth, but it seems like the setting <iPlayer> in CIV4BonusInfos.xml sets the priority level for defending bonuses ... Oil gets 150, Iron 100, Copper 50, Bananas 0. To get a full picture, you could look into the SDK for when the MissionAIType MISSIONAI_GUARD_BONUS is applied ... hope that helps.
 
jdog5000 said:
I haven't looked at this in depth, but it seems like the setting <iPlayer> in CIV4BonusInfos.xml sets the priority level for defending bonuses ... Oil gets 150, Iron 100, Copper 50, Bananas 0. To get a full picture, you could look into the SDK for when the MissionAIType MISSIONAI_GUARD_BONUS is applied ... hope that helps.


I wouldn't have thought that <iPlayer> was the tag to use.
The Civ4Wiki says that tag is used for "Approximate occurances per player, in percent (%), so 150 is about 1.5 per player"

Of course 0 must have a special value if that's true...'cause obviously bananas are in the game.

I'll try setting that tag to something stupidly high and see if that works anyway. Maybe Civ4Wiki has it wrong or the tag has more than one use.
 
Plodding on with my research into Forts I've learned how it is the AI determines what resources to guard.

First, you need a unit to have the UNITAI_RESERVE...and then there is a chance
it will be given the mission GUARD_RESOURCE.

I'm working on how to determine when units will be "RESERVE"

But assuming you have some reserves...AND the AI doesn't think it needs more units to either: Guard a city or guard an airlift, then the units will go and stand on a resource.

What resource the choose to stand on is determined via a function in the SDK...I don't know yet if python modifies this value.

The formula is roughly something like this:

((100*Happy +100*Health)
+(40 per unit "AND" prereq + 30 per unit "OR" prereq + unit production modifier /10) * 1.5 for units it can build or divided by the difference in tech eras from where it is now
+(30 per unit "AND" prereq + 20 per unit "OR" prereq + building production modifier /10) * 1.5 for buildings it can build or divided by the difference in tech eras from where it is now.
+ 2 * project building modifier /10 * 1.5 for projects it can build or divided by the difference in tech eras from where it is now. )
/ 10
= PlotValue

If the value of ANY plot is greater than 10 and is greater than all other plots
AND
the function isVisibleEnemyUnit returns true for that plot
THEN
the RESERVE unit running the AI mission function will be assigned to guard the plot

MY CONCLUSIONS ARE...

The best way to get the AI to guard a plot is to pile on the health and happy bonuses. Absurdly high numbers for these values should result in high numbers of guards.

However, if the civ can also build non-obsolete units and buildings that require a resource, then it only takes a few of these to catch up to a single health or happiness bonus.

So, if for instance mages, archmages, and liches all required a tower resource, and the AI could build them all, then a tower resource would get 40*3*1.5/10 = 18 for a plot value, which is better than a single happiness, so the AI would be more inclined to guard that resource, and any fort that happened to be on it.

at least I think thats about how it works...
now on to find out how to encourage more "RESERVE" units from the AI...
 
AND
the function isVisibleEnemyUnit returns true for that plot

You missed a "!" there (in CvUnitAI::AI_guardBonus). The AI will not move to guard a bonus if there's a visible enemy unit on it.
 
PeteT said:
You missed a "!" there (in CvUnitAI::AI_guardBonus). The AI will not move to guard a bonus if there's a visible enemy unit on it.

Thanks for catching that Pete.
I'd have been confused when I was testing.

Any further insights on how to get the AI to guard a particular plot would be appriciated if you have experience in the matter.
 
Back
Top Bottom