Combat AI: spell usage improvements

Everything about development and the OpenMW source code.
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Combat AI: spell usage improvements

Post by akortunov »

I suggest to discuss here problems with AI spell usage and ways to fix it.

Some work available here and here.
Last edited by akortunov on 03 Jun 2017, 08:07, edited 1 time in total.
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

SHIELD EFFECTS

Try to attack Marayn Dren in "Balmora, Guild of Mages". He casts all available shield spells in combat (shield, fire shield, etc. until his magicka ends)
If NPC has 10 different shield spells, he will cast them all.

I suggest to add three checks:

1) Check if an enemy is using weapon now:

Code: Select all

stats.getDrawState() == MWMechanics::DrawState_Weapon
2) Check the spell duration. There is no need to cast short shield spells (with duration lesser than 10-15 seconds)

3) Check already casted defense. There is no need to cast too much shield spells because defensive spells usually have a small duration. I think 20-30 points defense will be enough (1-3 spells).
UPDATE: since elemental shields do not affect armor rating we can use restriction instead: one active shield and one active elemental shield at time.

Also we can take to account enemy weapon enchantment. For example, when enemy weapon has Fire Damage on-hit effect, Fire Shield spells will take higher priority, when weapons has Shock Damage effect, Lightning Shield will take higher priority.
For range weapons in this case we should check ammo enchantment.
Last edited by akortunov on 04 Jun 2017, 08:02, edited 3 times in total.
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

BOUND ITEMS

If NPC has a bunch of bound weapons spells, he will cast them all, but obviously will use only one weapon.

What we can do:
1) Rate bound item and current item and modify spell priority to take the difference in account.
In this case NPC will cast only one bound weapon, with higher priority (including NPC weapon skills).

2) There is no need to cast bound longbow if NPC has no arrows.

3) Check NPC magicka level. Bound weapons priority should be higher when magicka level is low (and NPC will switch to his weapon soon) and should be lower if magicka level is high (and NPC will cast another spells insted of using conjured weapons).
Last edited by akortunov on 03 Jun 2017, 08:41, edited 1 time in total.
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

AREA OFFENSIVE SPELLS

Combat AI does not bother to check if area spells will kill not only a target, but friendy actors too. It is easy reproducible in Balmora Guild of Mages.
To fix this issue we need somehow to take in account difference between count of enemies and count of friendly actors in spell area.
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

UNDERWATER CASTING

Combat AI tries to use range spells (e.g. fireball) under water and these spells obviously do not work.
Maybe we should modify MWMechanics::getSpellSuccessChance() to return 0 in this case.

EDIT: IMPLEMENTED
Last edited by akortunov on 16 Jun 2017, 13:48, edited 1 time in total.
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

SILENCE, BLIND AND SOUND

Silence and sound are useful only when an enemy casts spells, blind - only when the enemy attacks with weapon (since this effect affects chance to hit).
What we can do:

1) Check the enemy draw state (weapon, spell)
If the enemy is ready to use spells, AI will cast silence or sound. If enemy is ready to attack with weapon - use blind spells.

2) Check if the enemy is unable to attack/cast (he is paralyzed, knocked out or fleeing)
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 think it isn't a very good idea to just go ahead and include all kinds of cases in a single cpp file.
It is already very messy, and with multiple people working on the problem, it will become really bad. We need a more systematic approach.
First of all, I think we need to separate "decision" making (flee/attack/defend/buff/heal) and spell/weapon priority. For every state we need a priority function that will rate all weapons/spells/enchantments according to their usability in this situation.
And all these should happen in separate files for sure, as there will be a lot of 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 »

such an approach could also fix things like https://bugs.openmw.org/issues/1374 by forcing NPCs into "defense" when at below half breath and prioritizing water breathing potions/spells/enchants, and having a special case fleeing for very low breath levels
User avatar
Br0ken
Posts: 243
Joined: 02 Apr 2012, 05:54
Location: Siberia

Re: Combat AI: spell usage improvements

Post by Br0ken »

Some thoughts:

If player casts fire damage spell, NPC should cast Fire Shield etc.
If player uses a weapon without any damaging enchantment, NPC should cast Shield. (hmm, may be enchantment check must be applied after successful hit? Otherwise, how NPC will be know what kind of enchantment on player's weapon? Sword with fire damage doesn't have a burning blade...

Or, for example, NPC with high Destruction can detect your frost damage axe as soon as you draw it. So, skill level = chance of detect. Others can detect it only after hit.
User avatar
akortunov
Posts: 900
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Combat AI: spell usage improvements

Post by akortunov »

If player casts fire damage spell, NPC should cast Fire Shield etc.
Looks interesting, but I do not know how we can implement this case.
Post Reply