From 74a2cbe6960ce178fb426f86430532c561cb0da7 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 1 Jun 2018 09:30:44 +0400 Subject: [PATCH] AI: return back after pursuit --- apps/openmw/mwmechanics/aisequence.cpp | 23 +++++++++++++++++++ .../mwmechanics/mechanicsmanagerimp.cpp | 20 ---------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 51c82f6ed..84ddf8fdf 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -308,6 +308,29 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor, boo if (isActualAiPackage(package.getTypeId())) stopCombat(); + // we should return a wandering actor back after combat or pursuit + // the same thing for actors without AI packages + int currentTypeId = getTypeId(); + int newTypeId = package.getTypeId(); + if (currentTypeId <= MWMechanics::AiPackage::TypeIdWander + && (newTypeId <= MWMechanics::AiPackage::TypeIdCombat + || newTypeId == MWMechanics::AiPackage::TypeIdPursue)) + { + osg::Vec3f dest; + if (currentTypeId == MWMechanics::AiPackage::TypeIdWander) + { + AiPackage* activePackage = getActivePackage(); + dest = activePackage->getDestination(actor); + } + else + { + dest = actor.getRefData().getPosition().asVec3(); + } + + MWMechanics::AiTravel travelPackage(dest.x(), dest.y(), dest.z(), true); + stack(travelPackage, actor, false); + } + // remove previous packages if required if (cancelOther && package.shouldCancelPreviousAi()) { diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index fbf989d05..89e1bef06 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1604,26 +1604,6 @@ namespace MWMechanics if (aiSequence.isInCombat(target)) return; - // we should return a wandering actor back after combat - // the same thing for actors without AI packages - if (aiSequence.getTypeId() <= MWMechanics::AiPackage::TypeIdWander) - { - int typeId = aiSequence.getTypeId(); - osg::Vec3f dest; - if (typeId == MWMechanics::AiPackage::TypeIdNone) - { - dest = ptr.getRefData().getPosition().asVec3(); - } - else if (typeId == MWMechanics::AiPackage::TypeIdWander) - { - AiPackage* activePackage = aiSequence.getActivePackage(); - dest = activePackage->getDestination(ptr); - } - - MWMechanics::AiTravel travelPackage(dest.x(), dest.y(), dest.z(), true); - aiSequence.stack(travelPackage, ptr, false); - } - aiSequence.stack(MWMechanics::AiCombat(target), ptr); if (target == getPlayer()) {