1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

AI Unit Building Behavior Question

Discussion in 'Civ4 - Better AI' started by Yxklyx, Mar 11, 2010.

  1. Yxklyx

    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?
     
  2. Jawa'sRevenge

    Jawa'sRevenge Warlord

    Joined:
    May 6, 2009
    Messages:
    246
    Location:
    Galaxy Far Far Away
    Why not add it and find out, its probably easy then looking at the code and guessing
     
  3. Fuyu

    Fuyu Emperor

    Joined:
    Nov 5, 2009
    Messages:
    1,225
    Location:
    Austria
    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.
     
  4. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    If you give your new ship the same UNITAI types as an Ironclad you should have no problems.
     
  5. Yxklyx

    Yxklyx King

    Joined:
    May 7, 2008
    Messages:
    869
    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.
     
  6. Fuyu

    Fuyu Emperor

    Joined:
    Nov 5, 2009
    Messages:
    1,225
    Location:
    Austria
    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.
     
  7. Yxklyx

    Yxklyx King

    Joined:
    May 7, 2008
    Messages:
    869
    Thanks a bunch.
     
  8. Yxklyx

    Yxklyx King

    Joined:
    May 7, 2008
    Messages:
    869
    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.
     
  9. Fuyu

    Fuyu Emperor

    Joined:
    Nov 5, 2009
    Messages:
    1,225
    Location:
    Austria
    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..
     
  10. Yxklyx

    Yxklyx King

    Joined:
    May 7, 2008
    Messages:
    869
    This is in the DLL? What utility can I use to unpack it?
     
  11. phungus420

    phungus420 Deity

    Joined:
    Mar 1, 2003
    Messages:
    6,296
    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.
     
  12. Fuyu

    Fuyu Emperor

    Joined:
    Nov 5, 2009
    Messages:
    1,225
    Location:
    Austria
    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.
     

Share This Page