forked from mirror/openmw-tes3mp
Moved pathfinding logic from AiCombat to Pathfinding.
This commit is contained in:
parent
a37dee09e2
commit
5369d20682
2 changed files with 14 additions and 21 deletions
|
@ -458,28 +458,10 @@ namespace MWMechanics
|
||||||
|
|
||||||
followTarget = false;
|
followTarget = false;
|
||||||
|
|
||||||
buildNewPath(actor, target); //may fail to build a path, check before use
|
buildNewPath(actor, target);
|
||||||
|
|
||||||
// if current actor pos is closer to target then last point of path (excluding target itself) then go straight on target
|
// should always return a path (even if it's just go straight on target.)
|
||||||
// This works on the borders between the path grid and areas with no waypoints.
|
assert(mPathFinder.isPathConstructed());
|
||||||
if(inLOS && mPathFinder.getPath().size() > 1)
|
|
||||||
{
|
|
||||||
// get point just before target
|
|
||||||
std::list<ESM::Pathgrid::Point>::const_iterator pntIter = --mPathFinder.getPath().end();
|
|
||||||
--pntIter;
|
|
||||||
osg::Vec3f vBeforeTarget(PathFinder::MakeOsgVec3(*pntIter));
|
|
||||||
|
|
||||||
if(distToTarget <= (vTargetPos - vBeforeTarget).length())
|
|
||||||
{
|
|
||||||
mPathFinder.clearPath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there is no new path, then go straight on target
|
|
||||||
if (!mPathFinder.isPathConstructed())
|
|
||||||
{
|
|
||||||
movement.mRotation[2] = getZAngleToDir((vTargetPos-vActorPos));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readyToAttack)
|
if (readyToAttack)
|
||||||
|
|
|
@ -215,6 +215,17 @@ namespace MWMechanics
|
||||||
endPointInLocalCoords,
|
endPointInLocalCoords,
|
||||||
startNode);
|
startNode);
|
||||||
|
|
||||||
|
// if it's shorter for actor to travel from start to end, than to travel from either
|
||||||
|
// start or end to nearest pathgrid point, just travel from start to end.
|
||||||
|
float startToEndLength2 = (endPointInLocalCoords - startPointInLocalCoords).length2();
|
||||||
|
float endTolastNodeLength2 = distanceSquared(mPathgrid->mPoints[endNode.first], endPointInLocalCoords);
|
||||||
|
float startTo1stNodeLength2 = distanceSquared(mPathgrid->mPoints[startNode], startPointInLocalCoords);
|
||||||
|
if ((startToEndLength2 < startTo1stNodeLength2) || (startToEndLength2 < endTolastNodeLength2))
|
||||||
|
{
|
||||||
|
mPath.push_back(endPoint);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// AiWander has logic that depends on whether a path was created,
|
// AiWander has logic that depends on whether a path was created,
|
||||||
// deleting allowed nodes if not. Hence a path needs to be created
|
// deleting allowed nodes if not. Hence a path needs to be created
|
||||||
// even if the start and the end points are the same.
|
// even if the start and the end points are the same.
|
||||||
|
|
Loading…
Reference in a new issue