mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 04:15:33 +00:00
aicombat pathfinding workaround
This commit is contained in:
parent
d780364842
commit
1bd2664cb0
2 changed files with 25 additions and 12 deletions
|
@ -240,16 +240,20 @@ namespace MWMechanics
|
||||||
//target is at far distance: build path to target OR follow target (if previously actor had reached it once)
|
//target is at far distance: build path to target OR follow target (if previously actor had reached it once)
|
||||||
mFollowTarget = false;
|
mFollowTarget = false;
|
||||||
|
|
||||||
buildNewPath(actor);
|
buildNewPath(actor); //not guaranteed, check before use
|
||||||
|
|
||||||
//delete visited path node
|
//delete visited path node
|
||||||
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]);
|
mPathFinder.checkPathCompleted(pos.pos[0],pos.pos[1],pos.pos[2]);
|
||||||
|
|
||||||
|
//if buildNewPath() failed leave mTargetAngle unchanged
|
||||||
|
if(!mPathFinder.getPath().empty())
|
||||||
|
{
|
||||||
//try shortcut
|
//try shortcut
|
||||||
if(vDir.length() < mPathFinder.getDistToNext(pos.pos[0],pos.pos[1],pos.pos[2]) && MWBase::Environment::get().getWorld()->getLOS(actor, mTarget))
|
if(vDir.length() < mPathFinder.getDistToNext(pos.pos[0],pos.pos[1],pos.pos[2]) && MWBase::Environment::get().getWorld()->getLOS(actor, mTarget))
|
||||||
mTargetAngle = Ogre::Radian( Ogre::Math::ACos(vDir.y / vDir.length()) * sgn(Ogre::Math::ASin(vDir.x / vDir.length())) ).valueDegrees();
|
mTargetAngle = Ogre::Radian( Ogre::Math::ACos(vDir.y / vDir.length()) * sgn(Ogre::Math::ASin(vDir.x / vDir.length())) ).valueDegrees();
|
||||||
else
|
else
|
||||||
mTargetAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]);
|
mTargetAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]);
|
||||||
|
}
|
||||||
mRotate = true;
|
mRotate = true;
|
||||||
|
|
||||||
mMovement.mPosition[1] = 1;
|
mMovement.mPosition[1] = 1;
|
||||||
|
@ -300,9 +304,13 @@ namespace MWMechanics
|
||||||
dest.mZ = mTarget.getRefData().getPosition().pos[2];
|
dest.mZ = mTarget.getRefData().getPosition().pos[2];
|
||||||
Ogre::Vector3 newPathTarget = Ogre::Vector3(dest.mX, dest.mY, dest.mZ);
|
Ogre::Vector3 newPathTarget = Ogre::Vector3(dest.mX, dest.mY, dest.mZ);
|
||||||
|
|
||||||
|
float dist = -1; //hack to indicate first time, to construct a new path
|
||||||
|
if(!mPathFinder.getPath().empty())
|
||||||
|
{
|
||||||
ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back();
|
ESM::Pathgrid::Point lastPt = mPathFinder.getPath().back();
|
||||||
Ogre::Vector3 currPathTarget(lastPt.mX, lastPt.mY, lastPt.mZ);
|
Ogre::Vector3 currPathTarget(lastPt.mX, lastPt.mY, lastPt.mZ);
|
||||||
float dist = Ogre::Math::Abs((newPathTarget - currPathTarget).length());
|
dist = Ogre::Math::Abs((newPathTarget - currPathTarget).length());
|
||||||
|
}
|
||||||
|
|
||||||
float targetPosThreshold;
|
float targetPosThreshold;
|
||||||
bool isOutside = actor.getCell()->mCell->isExterior();
|
bool isOutside = actor.getCell()->mCell->isExterior();
|
||||||
|
@ -311,7 +319,7 @@ namespace MWMechanics
|
||||||
else
|
else
|
||||||
targetPosThreshold = 100;
|
targetPosThreshold = 100;
|
||||||
|
|
||||||
if(dist > targetPosThreshold)
|
if((dist < 0) || (dist > targetPosThreshold))
|
||||||
{
|
{
|
||||||
//construct new path only if target has moved away more than on <targetPosThreshold>
|
//construct new path only if target has moved away more than on <targetPosThreshold>
|
||||||
ESM::Position pos = actor.getRefData().getPosition();
|
ESM::Position pos = actor.getRefData().getPosition();
|
||||||
|
@ -332,11 +340,14 @@ namespace MWMechanics
|
||||||
//maybe here is a mistake (?): PathFinder::getPathSize() returns number of grid points in the path,
|
//maybe here is a mistake (?): PathFinder::getPathSize() returns number of grid points in the path,
|
||||||
//not the actual path length. Here we should know if the new path is actually more effective.
|
//not the actual path length. Here we should know if the new path is actually more effective.
|
||||||
//if(pathFinder2.getPathSize() < mPathFinder.getPathSize())
|
//if(pathFinder2.getPathSize() < mPathFinder.getPathSize())
|
||||||
|
if(!mPathFinder.getPath().empty())
|
||||||
|
{
|
||||||
newPathFinder.syncStart(mPathFinder.getPath());
|
newPathFinder.syncStart(mPathFinder.getPath());
|
||||||
mPathFinder = newPathFinder;
|
mPathFinder = newPathFinder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int AiCombat::getTypeId() const
|
int AiCombat::getTypeId() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -391,6 +391,8 @@ namespace MWMechanics
|
||||||
|
|
||||||
void PathFinder::syncStart(const std::list<ESM::Pathgrid::Point> &path)
|
void PathFinder::syncStart(const std::list<ESM::Pathgrid::Point> &path)
|
||||||
{
|
{
|
||||||
|
if (path.size() < 2)
|
||||||
|
return; //nothing to pop
|
||||||
std::list<ESM::Pathgrid::Point>::const_iterator oldStart = path.begin();
|
std::list<ESM::Pathgrid::Point>::const_iterator oldStart = path.begin();
|
||||||
std::list<ESM::Pathgrid::Point>::iterator iter = ++mPath.begin();
|
std::list<ESM::Pathgrid::Point>::iterator iter = ++mPath.begin();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue