Combat AI: spell usage improvements

Everything about development and the OpenMW source code.
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Combat AI: spell usage improvements

Post by urm »

Well, one of the things to consider is how would the npc know it? Maybe, if an npc takes fire damage, it increases the chance of casting fire shield in the next defense phase? This way it will be harder for the player to just spam the same spell/enchantment, so a nice gameplay dynamic as well.
User avatar
DestinedToDie
Posts: 1181
Joined: 29 Jun 2015, 09:08

Re: Combat AI: spell usage improvements

Post by DestinedToDie »

I have an alternate suggestion for how things could work. It's a bit more simplistic than what you've proposed, but I believe there is elegance in this. We have factors, such as self, touch, target, magicka cost, distance.

Self

NPC should only cast 3 self spells max. They might have 10 different self spells and the 3 which are chosen are chosen based on highest magicka cost. It is quite likely that the ones costing the most magicka also have a decent duration, which would mean that the NPC doesn't have to recast them.

The exception is self restore spells. They would be only casted if health reaches a low %.

Touch

When player gets within certain distance of NPC, they will switch from target spell to touch spell, if they have one.

Target

When an NPC is far away from the PC, they should use target spells instead of touch spells. I don't think we currently have this, as the fire mage in Addamasartus cave outside Seyda Neen never uses his ranged spell, despite there being ample distance between us.

Magicka cost

So. Currently, it seems to me that spell priority is based on efficiency instead of magicka cost. I say we base it on magicka cost, because Touch spells are always more efficient than Target spells, despite it being preferrable to shoot fireballs from far away instead of running all the way up to your opponent to burn them by hand.

Distance

The only thing that would override magicka cost would be distance from the PC. If the player is right next to the NPC, it's time to switch over to touch spells, even if your target spells has a higher magicka cost.

-----------------------------------------------------------------------------------------------------

I see a potential problem in the previous solutions proposed that might come back to bite us in the nuts. That problem is - we might have new spells introduced in the coming dehardcoding. If so, how would a newly made spell effect be treated? Would the dehardcoding have to be done around the ideas you've had about isolating a specific spell against a specific action?

I would prefer that the improvements to AI spellcasting be modular, where a newly introduced spell effect would still fit together with AI smart spellcasting out of the box.
Last edited by DestinedToDie on 04 Jun 2017, 15:21, edited 1 time in total.
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Combat AI: spell usage improvements

Post by urm »

I assume after the great dehardcoding AI will also be available for change through construction set, so I at that point every spell would have a priority function attached to it for AI to handle
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

because Touch spells are always more efficient than Target spells
Any Target spell have 50% higher hardcoded priority now than a Touch spell with same parameters.
I say we base it on magicka cost
We base it on base cost, magnitude and duration. It means that more expensive spells will have higher priority. That's weird since mages in Morrowind usually have quite small amount of magicka.

The "great dehardcoding" will be a post-1.0 feature right? Post 1.0 we also can try to implement combat AI cooperation (based by role schemes: tank, healer, rogue, etc). AI scheme can be setted in NPC AI settings and can be calculated by default based by NPC stats. It this case we can set effect priority not in effect settings, but in role settings. It is similar to Dragon Age: Origins AI triggers.
Example of trigger in Healer role:
If Self or Ally Health < [select value] cast Restore Health spell

We can set triggers not only for spell effects, but set enemy priorities too. For example, tank will hold enemy warriors, archer will take down enemy mages.

Also we can use an actions queue. In current impelementaion AI takes decision for every single action. But to what purpose AI will cast a bound weapon if he will use spells until this effect will be expired (for example)?
For example, AI has this queue

"bound battle-axe" -> "first barrier" -> "fireball" -> "fireball" -> melee attack (magicka expired)

We can check if NPC has some spells in queue and modify queue order:

"fireball" -> "fireball" -> "bound battle-axe" -> "first barrier" -> melee attack (magicka expired)

Or we can force AI to use weaknesses only if he will use spells to take advantage from it:

"weakness to fire" -> "fireball" -> "fireball" -> "first barrier" -> "weakness to normal weapon" -> melee attack (steel sword)
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Combat AI: spell usage improvements

Post by urm »

yes, this would be an ideal solution. not sure if it should be approached before or after 1.0
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

not sure if it should be approached before or after 1.0
AI roles - definely post 1.0 since it will affect Editor and ESM format. Queue can be implemented before 1.0.
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

But first of all we need get ride of huge switch in rateEffect().

I suggest to use a map instead of switch. Key: effectId (integer), value: vector of rating calculation rules.
We can implement every rule as standalone class. Each rule get current rating from previous rule as argument and return new rating.
If there is no rules for effect, we can set rating to 0.
Only problem I see is a possible code duplication (when we need a one rule for several effects). Any suggestions here?

What I suggest to do:
1) Refactor rateEffect() to use calculation rules (something similar to this approach)
2) Implement missing spell usage cases
3) Try to implement actions queue
Last edited by akortunov on 07 Jun 2017, 10:14, edited 1 time in total.
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Combat AI: spell usage improvements

Post by urm »

about AI roles: why not use built-in NPC classes? I'm not sure how well they correspond with actual spells and weapons of NPCs though
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

about AI roles: why not use built-in NPC classes?
1) Player can use mods with non-built-in classes
2) Player may want to add new schemes for these classes or customise standart ones.
User avatar
urm
Posts: 83
Joined: 02 Jun 2017, 16:05
Gitlab profile: https://gitlab.com/uramer

Re: Combat AI: spell usage improvements

Post by urm »

1) yes, but then we can just use some default configuration
2) that won't be an option with unified AI anyways
Post Reply