Source code for AI and MaxGlobalInstance Units

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296
In my mod that's in an alpha build state right now I've incorporated Legend Units. Just a dozen units that like wonders can only be built once. Now in early testing I can see the main problem with them is that the AI just doesn't understand how useful they are. In a recent test game I saw the AI actually throw in a legend unit as a sacrifice first because it was low level :hammer2: I was hoping better AI would have dealt with some of this, but it appears not...

I know hero units have been around for a while now, so I assume there is some decent code out there to improve the AI's use of them. I haven't added any unique promotion or anything like that to them (but I suppose I could, I'd just have it do nothing but mark the unit as such for the AI if that's how the code out there works to determine a hero unit).

Does anyone have some easy to understand & commented source code out there, hopefully limited to a few files like UnitAI.cpp that teaches the AI how to more effectively use such units? I'd really appreciate it if I could use such code, it would make things far more enjoyable. I'm a complete novice when it comes to code, I can understand some of it, and written a few things in the SDK and for python (with some help from these forums), so while I may have a few difficulties merging in some complex code related to the AI's handling of hero units, I'm pretty sure I could get it to work if there was some commented code out there.

Thanks for any help
 
Tell me, what would be a better behavior? I think the sacrifice was not a sacrifice, but the AI attacked with the unit first maybe because the chances to win with THAT unit were higher than with other units. Your legendary units are too weak maybe. Wonders are very powerful. Compared to wonders, wonder units must be suuuuuper strong. wonders cannot be destroyed. they just lose their effect after many many many rounds. you need a legendary maceman with power 16 for example. this maceman won't die on first attack (= no sacrifice). or you can give him a unique promotion (like a high chance survival promotion from tsetom).

unitai_reserve (or unitai_reserve_sea) could help a little bit too.

or you make them immortal (respawn promotion) and delete them (by python? if possible) when they get obselete.
 
Tell me, what would be a better behavior? I think the sacrifice was not a sacrifice, but the AI attacked with the unit first maybe because the chances to win with THAT unit were higher than with other units. Your legendary units are too weak maybe. Wonders are very powerful. Compared to wonders, wonder units must be suuuuuper strong. wonders cannot be destroyed. they just lose their effect after many many many rounds. you need a legendary maceman with power 16 for example. this maceman won't die on first attack (= no sacrifice). or you can give him a unique promotion (like a high chance survival promotion from tsetom).

unitai_reserve (or unitai_reserve_sea) could help a little bit too.

or you make them immortal (respawn promotion) and delete them (by python? if possible) when they get obselete.

That wol't work, as the Human player would just steamroll the game with one. I've set them up so that they are strong, but they have weaknesses. For game balance reasons, I must keep it this way.

I'm nearly certain the problem is two fold. First the AI values a unit based on it's level, so being level 1, they aren't protected in the stack (they are used as sacrifice units). Secondly, and this is just an issue with the AI in general, even high level units that the AI protects, this only applies if they are in a stack, if the unit gets pulled from the Stack, the AI will just send them off on random errands and strand them places where they get overwhelmed and killed.

I wasn't sure if there was any code to deal with the second problem, saw a thread on this in Better AI and asked the person that started the thread about it. Acording to the information in it, they have devised some logic so that the AI always protects high level units, forcing them into stacks. This would be optimal code to use, as I could easily just throw in a function so that units with a maxGlobalInstance that's > 0 would get +7 to it's level or something like this (such things are trivial to program, even I can do that)

I mostly figured that given Hero units have been around for a while, due to FFH, some of this was already written. I don't know much bout no programming, just written a few functions here or there. So writing a whole new logic routine for the AI would be beyond me in the first place. And also didn't want to reinvent the wheel. So, I'm mainly hoping someone has some good code already written that adds some AI logic for hero units. If the code is all neat and commented, I can then just cut and paste into the modified source code I already use for my gamecore anyway.

1 Thing I have been expirementing with recently is the Asset & Power Tags. Setting the Asset tag to a higher number and trying to see how the AI uses the unit.

I believe there is also a tag for AI Weight, which might come into play a bit.
I'm pretty sure this only applies to the AI's decisions for what to build, and determining a player's strength. For this reason I've already assigned them decent asset and weight values, and the AI certainly prioritizes building them. It's just that when it builds them, it treats them like any other unit in the stack, or worse doesn't even put them in a stack, and sends them galavanting around aimlessly...
 
Back
Top Bottom