AI Unit Building Behavior Question

Yxklyx

King
Joined
May 7, 2008
Messages
869
This might not be the forum to ask this but I'm interested to know how the AI decides which unit it builds as well as how it uses some units. Now, the Caravel is a very good all purpose unit and I can see that being a good unit for the AI to handle. The problem is I'm thinking of adding a Galleas unit (stronger than Caravel but must stick to the coast and slightly more expensive) Given the choice, which one would the AI build and under which circumstances? Would the AI stop building Caravels and only build these new coastal ships - thereby perhaps handicapping itself? Also, is it a bad idea to have coastal-only ships set with Escort AI this late in the game when the AI has seafaring transports?
 
I can't tell you how the AI will use the ships once it has them but I believe it does care about ocean-going capabilities when deciding which naval unit to build for explore, assault, settler, missionary and spy unitAIs. For all others, including escort, it doesn't.
 
Back to the original question. If I make Airships not upgradeable to Fighters so that they are buildable throughout the game, how does the AI decide which to build? Will it always build the more expensive or the least expensive - or the more effective? Will I be handicapping the AI by not letting the Airship obsolete.
 
Since the fighter is only marginally more expensive but a lot stronger I'm pretty sure the AI would build fighters almost exclusively when it can (access to oil).
If you want to look at the code handling this: CvCityAI::AI_bestUnitAI() is called with eUnitAI set to UNITAI_ATTACK_AIR for fighter planes, which calls CvPlayerAI::AI_unitValue which determines the unit value with the help of CvGameAI::AI_combatValue. That unit value is divided by the turns it would take to complete building the unit in that city, and that final number is compared, the highest is chosen.
Same schema applies to all unit building decisions btw.
 
Since the fighter is only marginally more expensive but a lot stronger I'm pretty sure the AI would build fighters almost exclusively when it can (access to oil).
If you want to look at the code handling this: CvCityAI::AI_bestUnitAI() is called with eUnitAI set to UNITAI_ATTACK_AIR for fighter planes, which calls CvPlayerAI::AI_unitValue which determines the unit value with the help of CvGameAI::AI_combatValue. That unit value is divided by the turns it would take to complete building the unit in that city, and that final number is compared, the highest is chosen.
Same schema applies to all unit building decisions btw.

Thanks a bunch.
 
Going a little further on this. Does the AI ever take special abilities into consideration when building? For instance, I'm adding a new Musketman unit which has the same strength as the Grenadier for 10 fewer hammers but without the bonus vs Rifles. Using that formula only it would seem the AI would never build Grenadiers.
 
Those special abilities, called UnitCombatModifier and UnitClassAttackModifier, are only taken into account for UNITAI_COUNTER, UNITAI_CITY_COUNTER, UNITAI_CITY_SPECIAL, UNITAI_PARADROP and UNITAI_RESERVE (getUnitCombatModifier only); UnitClassDefenseModifier is always ignored. So for attack, city attack or city defence unitais the AI will probably only build the new unit, as for counter only the grenadier.
But seriously, look at it yourself. It's all there in CvPlayerAI::AI_unitValue. I'm not going to answer any further questions that you could answer yourself by reading a tiny bit of code that I already pointed out to you..
 
Those special abilities, called UnitCombatModifier and UnitClassAttackModifier, are only taken into account for UNITAI_COUNTER, UNITAI_CITY_COUNTER, UNITAI_CITY_SPECIAL, UNITAI_PARADROP and UNITAI_RESERVE (getUnitCombatModifier only); UnitClassDefenseModifier is always ignored. So for attack, city attack or city defence unitais the AI will probably only build the new unit, as for counter only the grenadier.
But seriously, look at it yourself. It's all there in CvPlayerAI::AI_unitValue. I'm not going to answer any further questions that you could answer yourself by reading a tiny bit of code that I already pointed out to you..

This is in the DLL? What utility can I use to unpack it?
 
This is in the DLL? What utility can I use to unpack it?

You can't "unpack" a dll. Theoretically you can decompile it, but then you get hard to read assembly code, which is next to useless anyway. What you need to do is look at the source code for BBAI, which Fuyu does publicly release.
 
If you are using the standard dll then you can find all the source code for it in your Civ4 folder at \Beyond the Sword\CvGameCoreDLL\. If you are using a mod with a custom dll, then usually the ones who distribute that mod also make the changed source code available in some way. In the case of Better BTS AI it's on sourceforge. Better BUG AI, RevDCM, Legends of Revolution, Rise of Mankind: A New Dawn, etc all have their own custom dll with source files available there.
 
Back
Top Bottom