From becccf3b5e30cff03a358295cf6dd1f547542022 Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 10 Feb 2021 22:34:15 +0100 Subject: [PATCH] Make actor flee from a combat when cannot reach a target --- apps/openmw/mwmechanics/aicombat.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index b98d5ef49..4b0128119 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -262,6 +262,25 @@ namespace MWMechanics // start new attack storage.startAttackIfReady(actor, characterController, weapon, isRangedCombat); } + else if (!isRangedCombat && !mPathFinder.isPathConstructed() && storage.mCurrentAction->isAttackingOrSpell()) + { + const osg::Vec3f position = actor.getRefData().getPosition().asVec3(); + const osg::Vec3f destination = target.getRefData().getPosition().asVec3(); + const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(actor); + mPathFinder.buildPath(actor, position, destination, actor.getCell(), getPathGridGraph(actor.getCell()), + halfExtents, getNavigatorFlags(actor), getAreaCosts(actor)); + + if (!mPathFinder.isPathConstructed()) + { + storage.stopAttack(); + characterController.setAttackingOrSpell(false); + currentAction.reset(new ActionFlee()); + actionCooldown = currentAction->getActionCooldown(); + storage.startFleeing(); + MWBase::Environment::get().getDialogueManager()->say(actor, "flee"); + } + } + return false; }