Combat AI issue

Everything about development and the OpenMW source code.
Post Reply
phillipedison1891
Posts: 10
Joined: 13 Nov 2016, 22:13

Combat AI issue

Post by phillipedison1891 » 08 Apr 2019, 03:49

So I was snooping through Arkngthand today when I noticed that enemy NPCs were getting into an endless loop of combat/no combat running in and out of my line of sight. To reproduce run command

Code: Select all

player->positioncell 175 2376 903 -28 "Arkngthand, Hall of Centrifuge" 
stay put, and wait for someone to notice you. (Interestingly this issue doesn't show up on Debug builds due to slower execution therefore fewer AI calls)

I have tracked down the issue to the MWMechanics::canFight function in aicombataction.cpp, specifically this bit (lines 459-460 on my current Git mirror):

Code: Select all

if (getDistanceMinusHalfExtents(actor, enemy, true) <= 0.0f)
            return false;
The result is that enemies far below you at a steep angle will stop fighting because getDistanceMinusHalfExtents here calculates Euclidean distance minus vertical distance. Can anyone say as to why this function is used to calculate whether combat is feasible? MiroslavR, perhaps you could bring some light?

phillipedison1891
Posts: 10
Joined: 13 Nov 2016, 22:13

Re: Combat AI issue

Post by phillipedison1891 » 08 Apr 2019, 06:27

I have created a merge request https://gitlab.com/OpenMW/openmw/merge_requests/91 that seems to fix this issue with no side effects found so far. Will keep it WIP until input has been received.

phillipedison1891
Posts: 10
Joined: 13 Nov 2016, 22:13

Re: Combat AI issue

Post by phillipedison1891 » 08 Apr 2019, 17:51

MiroslavR has weighed in on the MR:
The code was reversed, though I could have easily missed or misinterpreted something - I'm not very good at RE. My memory is fuzzy but I think actors in combat are supposed to flee if you jump over them or something like that. The check is definitely very strange - maybe it's not worth replicating such an obscure feature if it harms gameplay.

Post Reply