Skip to content

Commit

Permalink
Merge branch 'endoftheearth' into 'master'
Browse files Browse the repository at this point in the history
Don't try to escort to nowhere

See merge request OpenMW/openmw!3603
  • Loading branch information
Capostrophic committed Nov 24, 2023
2 parents 5623a5c + 8ca6f1a commit 9873ab2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
19 changes: 13 additions & 6 deletions apps/openmw/mwmechanics/aiescort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ namespace MWMechanics
, mZ(z)
, mDuration(duration)
, mRemainingDuration(static_cast<float>(duration))
, mCellX(std::numeric_limits<int>::max())
, mCellY(std::numeric_limits<int>::max())
{
mTargetActorRefId = actorId;
}
Expand All @@ -45,8 +43,6 @@ namespace MWMechanics
, mZ(z)
, mDuration(duration)
, mRemainingDuration(static_cast<float>(duration))
, mCellX(std::numeric_limits<int>::max())
, mCellY(std::numeric_limits<int>::max())
{
mTargetActorRefId = actorId;
}
Expand All @@ -59,8 +55,6 @@ namespace MWMechanics
, mZ(escort->mData.mZ)
, mDuration(escort->mData.mDuration)
, mRemainingDuration(escort->mRemainingDuration)
, mCellX(std::numeric_limits<int>::max())
, mCellY(std::numeric_limits<int>::max())
{
mTargetActorRefId = escort->mTargetId;
mTargetActorId = escort->mTargetActorId;
Expand Down Expand Up @@ -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<float>::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))
{
Expand Down
3 changes: 0 additions & 3 deletions apps/openmw/mwmechanics/aiescort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions apps/openmw/mwmechanics/aisequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ namespace MWMechanics
{
ESM::AITarget data = esmPackage.mTarget;
package = std::make_unique<MWMechanics::AiEscort>(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)
{
Expand All @@ -484,7 +484,7 @@ namespace MWMechanics
{
ESM::AITarget data = esmPackage.mTarget;
package = std::make_unique<MWMechanics::AiFollow>(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);
Expand Down

0 comments on commit 9873ab2

Please sign in to comment.