AI Combat Bonus

Ymir9

Warlord
Joined
Nov 15, 2006
Messages
127
It seems simple, but does anybody know of a way to give a basic combat bonus (perhaps around 15%) to AI players or conversely a similar combat penalty to Human players?

I know some may disagree with this concept, but with the way the game works now, I find the idea of giving an appropriate bonus to the AI where it is weakest - combat - to be much less annoying than the massive gold/happiness bonuses they get now, and also probably much more effective in making them pose a threat to the player on the battlefield.

I thought of doing this via a special promotion but wasn't sure how to enable this for AI players only. Has anybody done this before?

Thanks!
 
There are several ways to do something like this.

1> In the HandicapInfos table are a bunch of bonuses. Remember that whatever difficulty YOU pick, the AI is still playing on Chieftain. Also, each handicap includes a couple modifiers for the AI as well; that is, a human playing on King gives the AI players a small bonus to research, gold, etc.
Very few of these are directly military, though, and it sounds like this is something you're trying to get away from, so let's go to the next option.

2> Create a Lua function using SerialEventUnitCreated to check each new unit's owner. If it's an AI, give it a custom promotion. The downside to this is the amount of overhead involved, as this event triggers multiple times for each unit and you'd be checking the owner's identity every time.
Alternatively, you can drop the promotion part and modify the base strengths of the unit directly. This won't work for ranged units, but it has the advantage of better stacking with promotions.

3> Create a Lua function that gives each AI player a free custom building in their capital. That building acts as a Wonder, giving all units that player owns a certain promotion automatically. The downside is what happens if a player's capital is conquered.

4> Don't use a permanent effect at all. Create Lua functions for RunCombatSim and EndCombatSim, and modify the strengths of the units directly during combat. So the AI will get an extra bonus right before the combat resolves, and lose it right after.
One issue with this one is that the AI won't know it gets this bonus. It'll make its decisions on whether to attack or not based on the "old" values, instead of seeing every combat as an easy win. Depending on what playstyle you want, this could be an improvement or a drawback.

5> If this is meant solely for you, there's another option: create a new Civilization with UU's for every unit type, where the UU is WEAKER than the normal alternative. This one would take a lot of work, but wouldn't involve any Lua.

6> Don't explicitly boost the AI, but instead add other modifiers that boost the way the AI generally handles its military (lots of low-XP, cheap units, fighting defensively, moving as a horde). For instance, giving every unit +10% when in friendly territory makes it a LOT harder for a human to sweep through his opponents, whereas the AI generally won't care. Or giving every unit +10% when adjacent to a friendly unit, or increasing the healing rate when in friendly territory... lots of things you can do that'd slow down a human player without significantly changing how the AI plays.

Personally, I'd go with #3, or maybe #2 if you're not comfortable with the start-of-game triggers. My own mod uses mostly #6.
 
>Spatzimaus

Wow, thanks very much for your long answer.
I haven't had much experience with LUA yet, but I think I can manage something.
#4 is actually interesting, especially as in my experience the AI is prone to suicidal attacks, it might help work as a compensator.

I'll be sure to check out your mod as well! :)
 
#4 is actually interesting, especially as in my experience the AI is prone to suicidal attacks, it might help work as a compensator.

In my Ascension mod, which is based on the old Alpha Centauri game, I used the #4 mechanism for my Psi units (Mind Worms, etc.), which form a new Combat Class in my mod. What happens is that when a Psi unit faces a non-Psi unit, the Psi unit's base strength will increase or decrease up to 25% to make the fight more even. Since Mind Worms are fairly weak, it's nearly always an upward increase; as a result, these are supposed to be the ideal unit for a civilization that's fallen behind its competitors. (Also, they regenerate, and are the main Barbarian unit in my future eras.)

So if you want to see the mechanics of how I did this, go into my Ascension_Units.lua file (in the Lua subdirectory) and search for SetBaseCombatStrength. I also use that mechanism for several other things in my mods (making Orbital units weaker when attacking someone who has Orbital Defense Pods, for instance), but it'll be the ones within the check for UNITCOMBAT_PSI. It'd be very easy to make a similar bit of logic that simply moved the AI units' strengths upward at the start of each fight and then returned them to their normal values at the end.

There's one thing to note. While I'm sure this method would work fairly well for your problem, I think it's an overly complex solution, as adjusting the base combat strengths could lead to a bunch of issues if you don't do it correctly. You could just as easily do something much similar in Lua, like:
> Having all AI-controlled units take 1 less damage in every fight. For an example of how to do this, see the Damage Reduction promotion in my Base mod. (Also Lua-based, and it's in the AoM_Units.lua file in that mod.) It's not actually taking 1 less, it's taking the full amount and then healing 1 every time it takes damage, which comes out to about the same thing.
> Having all AI-controlled units deal 1 more damage in every fight. Very similar to the above, and I use this in a few places in my Mythology mod.
Or something similar to these. All Lua-based mechanisms bypass the AI logic, so the AI won't change its tactics regardless, and these sorts of solutions are a lot less risky.
 
Top Bottom