Changing AI components

MyungHee

Chieftain
Joined
Feb 9, 2008
Messages
26
Hi all,

I'm looking to modify the way the AI works a bit.

Is there a way to:

1. Change the number of units required before AI attacks.
2. The number of defenders the AI needs to feel safe so it can switch to creating buildings (instead of creating more units).
3. Changing a city's defense so that it depends on population rather than culture.

Thanks in advance for any pointers :)
 
Yes to all of them, and all of them require SDK editing (c++).

1. Probably easiest to change CvUnitAI::AI_stackOfDoomExtra.

2. Change one of: CvCityAI::AI_neededDefenders (probably what you want), CvCityAI::AI_minDefenders or CvCityAI::AI_neededFloatingDefenders.

3. Change CvCity::getNaturalDefense.
 
You'll need to know at least some C++ (honestly, just knowing Java or C or some other related language should be enough, you can figure the rest out fairly easily). And how to compile the DLL.
 
Awesome, thanks to both of you. Snarko, thanks for figuring out (or offering up ideas on) the exact spots to change.

I'll have fun making these edits without crashing the game.

Do you think, in a similar way, I could force the AI to use specific defenders in specific situations? I want them to use archers if they build a city on a hill and spearmen if they build a city not on a hill.
 
Do you mean which units are selected for combat? The game automatically selects the unit with the best odds of winning. I think that can be overriden though.
 
It can be overriden in CvPlot::getBestDefender, but as Linkman266 said, the game already chooses the best defender for everyone, based on the situation, including hills bonuses etc. so there's no reason to do this. One exception is warlords, which have an added value - there's a mod called Lead From Behind (also an optional part of BBAI), which makes Warlords defend after other units, even if Warlords are better.
 
Linkman226 and embryodead:

Thanks for your input. You're right ... I realized I worded my question wrong.

I want to dictate who the AI chooses to build as its defenders depending on *where they build* their city. So if they build their city on a hill, they only make archer defenders. If they build their city on level ground, they only make spearman defenders.

Does CvPlot::getBestDefender affect the same concept? i.e., is my concept here essentially the same thing that I asked before?
 
Top Bottom