From 1b820b980aa6f9bbdfdd8dcd96c1e673579650fb Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 19 Nov 2023 10:25:20 +0100 Subject: [PATCH 1/2] Don't try to escort to nowhere --- apps/openmw/mwmechanics/aiescort.cpp | 19 +++++++++++++------ apps/openmw/mwmechanics/aiescort.hpp | 3 --- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index e1d657a207e..380c0ace9f8 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -30,8 +30,6 @@ namespace MWMechanics , mZ(z) , mDuration(duration) , mRemainingDuration(static_cast(duration)) - , mCellX(std::numeric_limits::max()) - , mCellY(std::numeric_limits::max()) { mTargetActorRefId = actorId; } @@ -45,8 +43,6 @@ namespace MWMechanics , mZ(z) , mDuration(duration) , mRemainingDuration(static_cast(duration)) - , mCellX(std::numeric_limits::max()) - , mCellY(std::numeric_limits::max()) { mTargetActorRefId = actorId; } @@ -59,8 +55,6 @@ namespace MWMechanics , mZ(escort->mData.mZ) , mDuration(escort->mData.mDuration) , mRemainingDuration(escort->mRemainingDuration) - , mCellX(std::numeric_limits::max()) - , mCellY(std::numeric_limits::max()) { mTargetActorRefId = escort->mTargetId; mTargetActorId = escort->mTargetActorId; @@ -96,6 +90,19 @@ namespace MWMechanics if ((leaderPos - followerPos).length2() <= mMaxDist * mMaxDist) { + // TESCS allows the creation of Escort packages without a specific destination + constexpr float nowhere = std::numeric_limits::max(); + if (mX == nowhere || mY == nowhere) + return true; + if (mZ == nowhere) + { + if (mCellId.empty() + && ESM::positionToExteriorCellLocation(mX, mY) + == actor.getCell()->getCell()->getExteriorCellLocation()) + return false; + return true; + } + const osg::Vec3f dest(mX, mY, mZ); if (pathTo(actor, dest, duration, characterController.getSupportedMovementDirections(), maxHalfExtent)) { diff --git a/apps/openmw/mwmechanics/aiescort.hpp b/apps/openmw/mwmechanics/aiescort.hpp index e22752446dd..709b2bee596 100644 --- a/apps/openmw/mwmechanics/aiescort.hpp +++ b/apps/openmw/mwmechanics/aiescort.hpp @@ -59,9 +59,6 @@ namespace MWMechanics float mMaxDist = 450; const float mDuration; // In hours float mRemainingDuration; // In hours - - const int mCellX; - const int mCellY; }; } #endif From 8ca6f1ad4940d98afca21aeb491e12cff7eda801 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 19 Nov 2023 10:53:50 +0100 Subject: [PATCH 2/2] Use destination cell --- apps/openmw/mwmechanics/aisequence.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index de626ace957..af35be37636 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -467,7 +467,7 @@ namespace MWMechanics { ESM::AITarget data = esmPackage.mTarget; package = std::make_unique(ESM::RefId::stringRefId(data.mId.toStringView()), - data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0); + esmPackage.mCellName, data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0); } else if (esmPackage.mType == ESM::AI_Travel) { @@ -484,7 +484,7 @@ namespace MWMechanics { ESM::AITarget data = esmPackage.mTarget; package = std::make_unique(ESM::RefId::stringRefId(data.mId.toStringView()), - data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0); + esmPackage.mCellName, data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0); } onPackageAdded(*package);