|
|
|
@@ -12,10 +12,9 @@
|
|
|
|
|
#include "Log.h"
|
|
|
|
|
#include "DisableMgr.h"
|
|
|
|
|
#include "DetourCommon.h"
|
|
|
|
|
#include "DetourExtended.h"
|
|
|
|
|
#include "Geometry.h"
|
|
|
|
|
|
|
|
|
|
////////////////// PathGenerator //////////////////
|
|
|
|
|
////////////////// PathGenerator //////////////////
|
|
|
|
|
PathGenerator::PathGenerator(WorldObject const* owner) :
|
|
|
|
|
_polyLength(0), _type(PATHFIND_BLANK), _useStraightPath(false), _forceDestination(false),
|
|
|
|
|
_slopeCheck(false), _pointPathLimit(MAX_POINT_PATH_LENGTH), _useRaycast(false),
|
|
|
|
@@ -124,8 +123,8 @@ dtPolyRef PathGenerator::GetPolyByLocation(float const* point, float* distance)
|
|
|
|
|
// we don't have it in our old path
|
|
|
|
|
// try to get it by findNearestPoly()
|
|
|
|
|
// first try with low search box
|
|
|
|
|
float extents[VERTEX_SIZE] = {3.0f, 5.0f, 3.0f}; // bounds of poly search area
|
|
|
|
|
float closestPoint[VERTEX_SIZE] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
float extents[VERTEX_SIZE] = { 3.0f, 5.0f, 3.0f }; // bounds of poly search area
|
|
|
|
|
float closestPoint[VERTEX_SIZE] = { 0.0f, 0.0f, 0.0f };
|
|
|
|
|
if (dtStatusSucceed(_navMeshQuery->findNearestPoly(point, extents, &_filter, &polyRef, closestPoint)) && polyRef != INVALID_POLYREF)
|
|
|
|
|
{
|
|
|
|
|
*distance = dtVdist(closestPoint, point);
|
|
|
|
@@ -152,8 +151,8 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
// *** getting start/end poly logic ***
|
|
|
|
|
|
|
|
|
|
float distToStartPoly, distToEndPoly;
|
|
|
|
|
float startPoint[VERTEX_SIZE] = {startPos.y, startPos.z, startPos.x};
|
|
|
|
|
float endPoint[VERTEX_SIZE] = {endPos.y, endPos.z, endPos.x};
|
|
|
|
|
float startPoint[VERTEX_SIZE] = { startPos.y, startPos.z, startPos.x };
|
|
|
|
|
float endPoint[VERTEX_SIZE] = { endPos.y, endPos.z, endPos.x };
|
|
|
|
|
|
|
|
|
|
dtPolyRef startPoly = GetPolyByLocation(startPoint, &distToStartPoly);
|
|
|
|
|
dtPolyRef endPoly = GetPolyByLocation(endPoint, &distToEndPoly);
|
|
|
|
@@ -189,22 +188,30 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
// we may need a better number here
|
|
|
|
|
bool startFarFromPoly = distToStartPoly > 7.0f;
|
|
|
|
|
bool endFarFromPoly = distToEndPoly > 7.0f;
|
|
|
|
|
|
|
|
|
|
// create a shortcut if the path begins or end too far
|
|
|
|
|
// away from the desired path points.
|
|
|
|
|
// swimming creatures should not use a shortcut
|
|
|
|
|
// because exiting the water must be done following a proper path
|
|
|
|
|
// we just need to remove/normalize paths between 2 adjacent points
|
|
|
|
|
if ((!creature || !creature->CanSwim() || !creature->IsInWater() || _useRaycast)
|
|
|
|
|
&& (startFarFromPoly || endFarFromPoly))
|
|
|
|
|
if (startFarFromPoly || endFarFromPoly)
|
|
|
|
|
{
|
|
|
|
|
bool buildShotrcut = false;
|
|
|
|
|
|
|
|
|
|
bool isUnderWaterStart = _source->GetMap()->IsUnderWater(startPos.x, startPos.y, startPos.z);
|
|
|
|
|
bool isUnderWaterEnd = _source->GetMap()->IsUnderWater(endPos.x, endPos.y, endPos.z);
|
|
|
|
|
bool isFarUnderWater = startFarFromPoly ? isUnderWaterStart : isUnderWaterEnd;
|
|
|
|
|
|
|
|
|
|
Unit const* _sourceUnit = _source->ToUnit();
|
|
|
|
|
if (_useRaycast ||
|
|
|
|
|
(_sourceUnit && (_sourceUnit->CanFly() || (_sourceUnit->IsFalling() && endPos.z < startPos.z)))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (_sourceUnit)
|
|
|
|
|
{
|
|
|
|
|
buildShotrcut = true;
|
|
|
|
|
bool isUnderWater = (_sourceUnit->CanSwim() && isUnderWaterStart && isUnderWaterEnd) || (isFarUnderWater && _useRaycast);
|
|
|
|
|
|
|
|
|
|
if (isUnderWater || _sourceUnit->CanFly() || (_sourceUnit->IsFalling() && endPos.z < startPos.z))
|
|
|
|
|
{
|
|
|
|
|
buildShotrcut = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buildShotrcut)
|
|
|
|
@@ -216,7 +223,8 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
if (!isFarUnderWater)
|
|
|
|
|
{
|
|
|
|
|
float closestPoint[VERTEX_SIZE];
|
|
|
|
|
// we may want to use closestPointOnPolyBoundary instead
|
|
|
|
@@ -248,7 +256,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
AddFarFromPolyFlags(startFarFromPoly, endFarFromPoly);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_type = PATHFIND_NORMAL;
|
|
|
|
|
_type = PATHFIND_NORMAL;
|
|
|
|
|
|
|
|
|
|
BuildPointPath(startPoint, endPoint);
|
|
|
|
|
return;
|
|
|
|
@@ -278,7 +286,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (pathEndIndex = _polyLength-1; pathEndIndex > pathStartIndex; --pathEndIndex)
|
|
|
|
|
for (pathEndIndex = _polyLength - 1; pathEndIndex > pathStartIndex; --pathEndIndex)
|
|
|
|
|
{
|
|
|
|
|
if (_pathPolyRefs[pathEndIndex] == endPoly)
|
|
|
|
|
{
|
|
|
|
@@ -309,12 +317,12 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
// thus we have less poly to cover
|
|
|
|
|
// sub-path of optimal path is optimal
|
|
|
|
|
|
|
|
|
|
// take ~80% of the original length
|
|
|
|
|
// take ~80% of the original length
|
|
|
|
|
/// @todo play with the values here
|
|
|
|
|
uint32 prefixPolyLength = uint32(_polyLength * 0.8f + 0.5f);
|
|
|
|
|
memmove(_pathPolyRefs, _pathPolyRefs+pathStartIndex, prefixPolyLength * sizeof(dtPolyRef));
|
|
|
|
|
memmove(_pathPolyRefs, _pathPolyRefs + pathStartIndex, prefixPolyLength * sizeof(dtPolyRef));
|
|
|
|
|
|
|
|
|
|
dtPolyRef suffixStartPoly = _pathPolyRefs[prefixPolyLength-1];
|
|
|
|
|
dtPolyRef suffixStartPoly = _pathPolyRefs[prefixPolyLength - 1];
|
|
|
|
|
|
|
|
|
|
// we need any point on our suffix start poly to generate poly-path, so we need last poly in prefix data
|
|
|
|
|
float suffixEndPoint[VERTEX_SIZE];
|
|
|
|
@@ -323,7 +331,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
// we can hit offmesh connection as last poly - closestPointOnPoly() don't like that
|
|
|
|
|
// try to recover by using prev polyref
|
|
|
|
|
--prefixPolyLength;
|
|
|
|
|
suffixStartPoly = _pathPolyRefs[prefixPolyLength-1];
|
|
|
|
|
suffixStartPoly = _pathPolyRefs[prefixPolyLength - 1];
|
|
|
|
|
if (dtStatusFailed(_navMeshQuery->closestPointOnPoly(suffixStartPoly, endPoint, suffixEndPoint, nullptr)))
|
|
|
|
|
{
|
|
|
|
|
// suffixStartPoly is still invalid, error state
|
|
|
|
@@ -346,14 +354,14 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dtResult = _navMeshQuery->findPath(
|
|
|
|
|
suffixStartPoly, // start polygon
|
|
|
|
|
endPoly, // end polygon
|
|
|
|
|
suffixEndPoint, // start position
|
|
|
|
|
endPoint, // end position
|
|
|
|
|
&_filter, // polygon search filter
|
|
|
|
|
_pathPolyRefs + prefixPolyLength - 1, // [out] path
|
|
|
|
|
(int*)&suffixPolyLength,
|
|
|
|
|
MAX_PATH_LENGTH - prefixPolyLength); // max number of polygons in output path
|
|
|
|
|
suffixStartPoly, // start polygon
|
|
|
|
|
endPoly, // end polygon
|
|
|
|
|
suffixEndPoint, // start position
|
|
|
|
|
endPoint, // end position
|
|
|
|
|
&_filter, // polygon search filter
|
|
|
|
|
_pathPolyRefs + prefixPolyLength - 1, // [out] path
|
|
|
|
|
(int*)&suffixPolyLength,
|
|
|
|
|
MAX_PATH_LENGTH - prefixPolyLength); // max number of polygons in output path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!suffixPolyLength || dtStatusFailed(dtResult))
|
|
|
|
@@ -384,15 +392,15 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
memset(hitNormal, 0, sizeof(hitNormal));
|
|
|
|
|
|
|
|
|
|
dtResult = _navMeshQuery->raycast(
|
|
|
|
|
startPoly,
|
|
|
|
|
startPoint,
|
|
|
|
|
endPoint,
|
|
|
|
|
&_filter,
|
|
|
|
|
&hit,
|
|
|
|
|
hitNormal,
|
|
|
|
|
_pathPolyRefs,
|
|
|
|
|
(int*)&_polyLength,
|
|
|
|
|
MAX_PATH_LENGTH);
|
|
|
|
|
startPoly,
|
|
|
|
|
startPoint,
|
|
|
|
|
endPoint,
|
|
|
|
|
&_filter,
|
|
|
|
|
&hit,
|
|
|
|
|
hitNormal,
|
|
|
|
|
_pathPolyRefs,
|
|
|
|
|
(int*)&_polyLength,
|
|
|
|
|
MAX_PATH_LENGTH);
|
|
|
|
|
|
|
|
|
|
if (!_polyLength || dtStatusFailed(dtResult))
|
|
|
|
|
{
|
|
|
|
@@ -449,14 +457,14 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dtResult = _navMeshQuery->findPath(
|
|
|
|
|
startPoly, // start polygon
|
|
|
|
|
endPoly, // end polygon
|
|
|
|
|
startPoint, // start position
|
|
|
|
|
endPoint, // end position
|
|
|
|
|
&_filter, // polygon search filter
|
|
|
|
|
_pathPolyRefs, // [out] path
|
|
|
|
|
(int*)&_polyLength,
|
|
|
|
|
MAX_PATH_LENGTH); // max number of polygons in output path
|
|
|
|
|
startPoly, // start polygon
|
|
|
|
|
endPoly, // end polygon
|
|
|
|
|
startPoint, // start position
|
|
|
|
|
endPoint, // end position
|
|
|
|
|
&_filter, // polygon search filter
|
|
|
|
|
_pathPolyRefs, // [out] path
|
|
|
|
|
(int*)&_polyLength,
|
|
|
|
|
MAX_PATH_LENGTH); // max number of polygons in output path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_polyLength || dtStatusFailed(dtResult))
|
|
|
|
@@ -493,9 +501,9 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
|
|
|
|
BuildPointPath(startPoint, endPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoint)
|
|
|
|
|
void PathGenerator::BuildPointPath(const float* startPoint, const float* endPoint)
|
|
|
|
|
{
|
|
|
|
|
float pathPoints[MAX_POINT_PATH_LENGTH*VERTEX_SIZE];
|
|
|
|
|
float pathPoints[MAX_POINT_PATH_LENGTH * VERTEX_SIZE];
|
|
|
|
|
uint32 pointCount = 0;
|
|
|
|
|
dtStatus dtResult = DT_FAILURE;
|
|
|
|
|
if (_useRaycast)
|
|
|
|
@@ -509,26 +517,26 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin
|
|
|
|
|
else if (_useStraightPath)
|
|
|
|
|
{
|
|
|
|
|
dtResult = _navMeshQuery->findStraightPath(
|
|
|
|
|
startPoint, // start position
|
|
|
|
|
endPoint, // end position
|
|
|
|
|
_pathPolyRefs, // current path
|
|
|
|
|
_polyLength, // lenth of current path
|
|
|
|
|
pathPoints, // [out] path corner points
|
|
|
|
|
nullptr, // [out] flags
|
|
|
|
|
nullptr, // [out] shortened path
|
|
|
|
|
(int*)&pointCount,
|
|
|
|
|
_pointPathLimit); // maximum number of points/polygons to use
|
|
|
|
|
startPoint, // start position
|
|
|
|
|
endPoint, // end position
|
|
|
|
|
_pathPolyRefs, // current path
|
|
|
|
|
_polyLength, // lenth of current path
|
|
|
|
|
pathPoints, // [out] path corner points
|
|
|
|
|
nullptr, // [out] flags
|
|
|
|
|
nullptr, // [out] shortened path
|
|
|
|
|
(int*)&pointCount,
|
|
|
|
|
_pointPathLimit); // maximum number of points/polygons to use
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dtResult = FindSmoothPath(
|
|
|
|
|
startPoint, // start position
|
|
|
|
|
endPoint, // end position
|
|
|
|
|
_pathPolyRefs, // current path
|
|
|
|
|
_polyLength, // length of current path
|
|
|
|
|
pathPoints, // [out] path corner points
|
|
|
|
|
(int*)&pointCount,
|
|
|
|
|
_pointPathLimit); // maximum number of points
|
|
|
|
|
startPoint, // start position
|
|
|
|
|
endPoint, // end position
|
|
|
|
|
_pathPolyRefs, // current path
|
|
|
|
|
_polyLength, // length of current path
|
|
|
|
|
pathPoints, // [out] path corner points
|
|
|
|
|
(int*)&pointCount,
|
|
|
|
|
_pointPathLimit); // maximum number of points
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special case with start and end positions very close to each other
|
|
|
|
@@ -538,7 +546,7 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin
|
|
|
|
|
dtVcopy(&pathPoints[1 * VERTEX_SIZE], endPoint);
|
|
|
|
|
pointCount++;
|
|
|
|
|
}
|
|
|
|
|
else if ( pointCount < 2 || dtStatusFailed(dtResult))
|
|
|
|
|
else if (pointCount < 2 || dtStatusFailed(dtResult))
|
|
|
|
|
{
|
|
|
|
|
// only happens if pass bad data to findStraightPath or navmesh is broken
|
|
|
|
|
// single point paths can be generated here
|
|
|
|
@@ -557,7 +565,7 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin
|
|
|
|
|
_pathPoints.resize(pointCount);
|
|
|
|
|
uint32 newPointCount = 0;
|
|
|
|
|
for (uint32 i = 0; i < pointCount; ++i) {
|
|
|
|
|
G3D::Vector3 vector = G3D::Vector3(pathPoints[i*VERTEX_SIZE+2], pathPoints[i*VERTEX_SIZE], pathPoints[i*VERTEX_SIZE+1]);
|
|
|
|
|
G3D::Vector3 vector = G3D::Vector3(pathPoints[i * VERTEX_SIZE + 2], pathPoints[i * VERTEX_SIZE], pathPoints[i * VERTEX_SIZE + 1]);
|
|
|
|
|
ZLiquidStatus status = _source->GetMap()->getLiquidStatus(vector.x, vector.y, vector.z, MAP_ALL_LIQUIDS, nullptr);
|
|
|
|
|
// One of the points is not in the water
|
|
|
|
|
if (status == LIQUID_MAP_UNDER_WATER)
|
|
|
|
@@ -571,7 +579,7 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin
|
|
|
|
|
}
|
|
|
|
|
// if the last point is under water
|
|
|
|
|
// then set the desired end position instead
|
|
|
|
|
else if (i == pointCount - 1 )
|
|
|
|
|
else if (i == pointCount - 1)
|
|
|
|
|
{
|
|
|
|
|
_pathPoints[newPointCount] = GetActualEndPosition();
|
|
|
|
|
}
|
|
|
|
@@ -594,7 +602,7 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin
|
|
|
|
|
NormalizePath();
|
|
|
|
|
|
|
|
|
|
// first point is always our current location - we need the next one
|
|
|
|
|
SetActualEndPosition(_pathPoints[newPointCount-1]);
|
|
|
|
|
SetActualEndPosition(_pathPoints[newPointCount - 1]);
|
|
|
|
|
|
|
|
|
|
// force the given destination, if needed
|
|
|
|
|
if (_forceDestination &&
|
|
|
|
@@ -604,7 +612,7 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin
|
|
|
|
|
if (Dist3DSqr(GetActualEndPosition(), GetEndPosition()) < 0.3f * Dist3DSqr(GetStartPosition(), GetEndPosition()))
|
|
|
|
|
{
|
|
|
|
|
SetActualEndPosition(GetEndPosition());
|
|
|
|
|
_pathPoints[_pathPoints.size()-1] = GetEndPosition();
|
|
|
|
|
_pathPoints[_pathPoints.size() - 1] = GetEndPosition();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@@ -677,8 +685,8 @@ void PathGenerator::UpdateFilter()
|
|
|
|
|
{
|
|
|
|
|
uint16 includedFlags = _filter.getIncludeFlags();
|
|
|
|
|
includedFlags |= GetNavTerrain(_source->GetPositionX(),
|
|
|
|
|
_source->GetPositionY(),
|
|
|
|
|
_source->GetPositionZ());
|
|
|
|
|
_source->GetPositionY(),
|
|
|
|
|
_source->GetPositionZ());
|
|
|
|
|
|
|
|
|
|
_filter.setIncludeFlags(includedFlags);
|
|
|
|
|
}
|
|
|
|
@@ -712,7 +720,7 @@ NavTerrain PathGenerator::GetNavTerrain(float x, float y, float z) const
|
|
|
|
|
bool PathGenerator::HaveTile(const G3D::Vector3& p) const
|
|
|
|
|
{
|
|
|
|
|
int tx = -1, ty = -1;
|
|
|
|
|
float point[VERTEX_SIZE] = {p.y, p.z, p.x};
|
|
|
|
|
float point[VERTEX_SIZE] = { p.y, p.z, p.x };
|
|
|
|
|
|
|
|
|
|
_navMesh->calcTileLoc(point, &tx, &ty);
|
|
|
|
|
|
|
|
|
@@ -731,10 +739,10 @@ uint32 PathGenerator::FixupCorridor(dtPolyRef* path, uint32 npath, uint32 maxPat
|
|
|
|
|
int32 furthestVisited = -1;
|
|
|
|
|
|
|
|
|
|
// Find furthest common polygon.
|
|
|
|
|
for (int32 i = npath-1; i >= 0; --i)
|
|
|
|
|
for (int32 i = npath - 1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (int32 j = nvisited-1; j >= 0; --j)
|
|
|
|
|
for (int32 j = nvisited - 1; j >= 0; --j)
|
|
|
|
|
{
|
|
|
|
|
if (path[i] == visited[j])
|
|
|
|
|
{
|
|
|
|
@@ -758,7 +766,7 @@ uint32 PathGenerator::FixupCorridor(dtPolyRef* path, uint32 npath, uint32 maxPat
|
|
|
|
|
uint32 orig = uint32(furthestPath + 1) < npath ? furthestPath + 1 : npath;
|
|
|
|
|
uint32 size = npath > orig ? npath - orig : 0;
|
|
|
|
|
if (req + size > maxPath)
|
|
|
|
|
size = maxPath-req;
|
|
|
|
|
size = maxPath - req;
|
|
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
|
memmove(path + req, path + orig, size * sizeof(dtPolyRef));
|
|
|
|
@@ -767,21 +775,21 @@ uint32 PathGenerator::FixupCorridor(dtPolyRef* path, uint32 npath, uint32 maxPat
|
|
|
|
|
for (uint32 i = 0; i < req; ++i)
|
|
|
|
|
path[i] = visited[(nvisited - 1) - i];
|
|
|
|
|
|
|
|
|
|
return req+size;
|
|
|
|
|
return req + size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PathGenerator::GetSteerTarget(float const* startPos, float const* endPos,
|
|
|
|
|
float minTargetDist, dtPolyRef const* path, uint32 pathSize,
|
|
|
|
|
float* steerPos, unsigned char& steerPosFlag, dtPolyRef& steerPosRef)
|
|
|
|
|
float minTargetDist, dtPolyRef const* path, uint32 pathSize,
|
|
|
|
|
float* steerPos, unsigned char& steerPosFlag, dtPolyRef& steerPosRef)
|
|
|
|
|
{
|
|
|
|
|
// Find steer target.
|
|
|
|
|
static const uint32 MAX_STEER_POINTS = 3;
|
|
|
|
|
float steerPath[MAX_STEER_POINTS*VERTEX_SIZE];
|
|
|
|
|
float steerPath[MAX_STEER_POINTS * VERTEX_SIZE];
|
|
|
|
|
unsigned char steerPathFlags[MAX_STEER_POINTS];
|
|
|
|
|
dtPolyRef steerPathPolys[MAX_STEER_POINTS];
|
|
|
|
|
uint32 nsteerPath = 0;
|
|
|
|
|
dtStatus dtResult = _navMeshQuery->findStraightPath(startPos, endPos, path, pathSize,
|
|
|
|
|
steerPath, steerPathFlags, steerPathPolys, (int*)&nsteerPath, MAX_STEER_POINTS);
|
|
|
|
|
steerPath, steerPathFlags, steerPathPolys, (int*)&nsteerPath, MAX_STEER_POINTS);
|
|
|
|
|
if (!nsteerPath || dtStatusFailed(dtResult))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
@@ -791,7 +799,7 @@ bool PathGenerator::GetSteerTarget(float const* startPos, float const* endPos,
|
|
|
|
|
{
|
|
|
|
|
// Stop at Off-Mesh link or when point is further than slop away.
|
|
|
|
|
if ((steerPathFlags[ns] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
|
|
|
|
|
!InRangeYZX(&steerPath[ns*VERTEX_SIZE], startPos, minTargetDist, 1000.0f))
|
|
|
|
|
!InRangeYZX(&steerPath[ns * VERTEX_SIZE], startPos, minTargetDist, 1000.0f))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
ns++;
|
|
|
|
@@ -800,7 +808,7 @@ bool PathGenerator::GetSteerTarget(float const* startPos, float const* endPos,
|
|
|
|
|
if (ns >= nsteerPath)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
dtVcopy(steerPos, &steerPath[ns*VERTEX_SIZE]);
|
|
|
|
|
dtVcopy(steerPos, &steerPath[ns * VERTEX_SIZE]);
|
|
|
|
|
steerPos[1] = startPos[1]; // keep Z value
|
|
|
|
|
steerPosFlag = steerPathFlags[ns];
|
|
|
|
|
steerPosRef = steerPathPolys[ns];
|
|
|
|
@@ -809,14 +817,14 @@ bool PathGenerator::GetSteerTarget(float const* startPos, float const* endPos,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPos,
|
|
|
|
|
dtPolyRef const* polyPath, uint32 polyPathSize,
|
|
|
|
|
float* smoothPath, int* smoothPathSize, uint32 maxSmoothPathSize)
|
|
|
|
|
dtPolyRef const* polyPath, uint32 polyPathSize,
|
|
|
|
|
float* smoothPath, int* smoothPathSize, uint32 maxSmoothPathSize)
|
|
|
|
|
{
|
|
|
|
|
*smoothPathSize = 0;
|
|
|
|
|
uint32 nsmoothPath = 0;
|
|
|
|
|
|
|
|
|
|
dtPolyRef polys[MAX_PATH_LENGTH];
|
|
|
|
|
memcpy(polys, polyPath, sizeof(dtPolyRef)*polyPathSize);
|
|
|
|
|
memcpy(polys, polyPath, sizeof(dtPolyRef) * polyPathSize);
|
|
|
|
|
uint32 npolys = polyPathSize;
|
|
|
|
|
|
|
|
|
|
float iterPos[VERTEX_SIZE], targetPos[VERTEX_SIZE];
|
|
|
|
@@ -841,7 +849,7 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
|
|
|
|
|
dtVcopy(targetPos, endPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dtVcopy(&smoothPath[nsmoothPath*VERTEX_SIZE], iterPos);
|
|
|
|
|
dtVcopy(&smoothPath[nsmoothPath * VERTEX_SIZE], iterPos);
|
|
|
|
|
nsmoothPath++;
|
|
|
|
|
|
|
|
|
|
// Move towards target a small advancement at a time until target reached or
|
|
|
|
@@ -903,7 +911,7 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
|
|
|
|
|
dtVcopy(iterPos, targetPos);
|
|
|
|
|
if (nsmoothPath < maxSmoothPathSize)
|
|
|
|
|
{
|
|
|
|
|
dtVcopy(&smoothPath[nsmoothPath*VERTEX_SIZE], iterPos);
|
|
|
|
|
dtVcopy(&smoothPath[nsmoothPath * VERTEX_SIZE], iterPos);
|
|
|
|
|
nsmoothPath++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@@ -922,7 +930,7 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (uint32 i = npos; i < npolys; ++i)
|
|
|
|
|
polys[i-npos] = polys[i];
|
|
|
|
|
polys[i - npos] = polys[i];
|
|
|
|
|
|
|
|
|
|
npolys -= npos;
|
|
|
|
|
|
|
|
|
@@ -932,7 +940,7 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
|
|
|
|
|
{
|
|
|
|
|
if (nsmoothPath < maxSmoothPathSize)
|
|
|
|
|
{
|
|
|
|
|
dtVcopy(&smoothPath[nsmoothPath*VERTEX_SIZE], connectionStartPos);
|
|
|
|
|
dtVcopy(&smoothPath[nsmoothPath * VERTEX_SIZE], connectionStartPos);
|
|
|
|
|
nsmoothPath++;
|
|
|
|
|
}
|
|
|
|
|
// Move position at the other side of the off-mesh link.
|
|
|
|
@@ -946,7 +954,7 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
|
|
|
|
|
// Store results.
|
|
|
|
|
if (nsmoothPath < maxSmoothPathSize)
|
|
|
|
|
{
|
|
|
|
|
dtVcopy(&smoothPath[nsmoothPath*VERTEX_SIZE], iterPos);
|
|
|
|
|
dtVcopy(&smoothPath[nsmoothPath * VERTEX_SIZE], iterPos);
|
|
|
|
|
nsmoothPath++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -1047,7 +1055,7 @@ void PathGenerator::ShortenPathUntilDist(G3D::Vector3 const& target, float dist)
|
|
|
|
|
if ((*_pathPoints.rbegin() - target).squaredLength() >= distSq)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
size_t i = _pathPoints.size()-1;
|
|
|
|
|
size_t i = _pathPoints.size() - 1;
|
|
|
|
|
float x, y, z, collisionHeight = _source->GetCollisionHeight();
|
|
|
|
|
// find the first i s.t.:
|
|
|
|
|
// - _pathPoints[i] is still too close
|
|
|
|
@@ -1056,7 +1064,7 @@ void PathGenerator::ShortenPathUntilDist(G3D::Vector3 const& target, float dist)
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
// we know that pathPoints[i] is too close already (from the previous iteration)
|
|
|
|
|
if ((_pathPoints[i-1] - target).squaredLength() >= distSq)
|
|
|
|
|
if ((_pathPoints[i - 1] - target).squaredLength() >= distSq)
|
|
|
|
|
break; // bingo!
|
|
|
|
|
|
|
|
|
|
bool canCheckSlope = _slopeCheck && (GetPathType() & ~(PATHFIND_NOT_USING_PATH));
|
|
|
|
@@ -1068,7 +1076,7 @@ void PathGenerator::ShortenPathUntilDist(G3D::Vector3 const& target, float dist)
|
|
|
|
|
&& !IsSwimmableSegment(_source->GetPositionX(), _source->GetPositionY(), _source->GetPositionZ(), _pathPoints[i - 1].x, _pathPoints[i - 1].y, _pathPoints[i - 1].z)
|
|
|
|
|
&& !IsWalkableClimb(_source->GetPositionX(), _source->GetPositionY(), _source->GetPositionZ(), _pathPoints[i - 1].x, _pathPoints[i - 1].y, _pathPoints[i - 1].z)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
// whenver we find a point that is not valid anymore, simply use last valid path
|
|
|
|
|
_pathPoints.resize(i + 1);
|
|
|
|
@@ -1088,7 +1096,7 @@ void PathGenerator::ShortenPathUntilDist(G3D::Vector3 const& target, float dist)
|
|
|
|
|
// ... settle for a guesstimate since i'm not confident in doing trig on every chase motion tick...
|
|
|
|
|
// (@todo review this)
|
|
|
|
|
_pathPoints[i] += (_pathPoints[i - 1] - _pathPoints[i]).direction() * (dist - (_pathPoints[i] - target).length());
|
|
|
|
|
_pathPoints.resize(i+1);
|
|
|
|
|
_pathPoints.resize(i + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PathGenerator::IsInvalidDestinationZ(Unit const* target) const
|
|
|
|
@@ -1143,8 +1151,8 @@ bool PathGenerator::IsSwimmableSegment(float x, float y, float z, float destX, f
|
|
|
|
|
{
|
|
|
|
|
Creature const* _sourceCreature = _source->ToCreature();
|
|
|
|
|
return _source->GetMap()->IsInWater(x, y, z) &&
|
|
|
|
|
_source->GetMap()->IsInWater(destX, destY, destZ) &&
|
|
|
|
|
(!checkSwim || !_sourceCreature || _sourceCreature->CanSwim());
|
|
|
|
|
_source->GetMap()->IsInWater(destX, destY, destZ) &&
|
|
|
|
|
(!checkSwim || !_sourceCreature || _sourceCreature->CanSwim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PathGenerator::IsWaterPath(Movement::PointsArray _pathPoints) const
|
|
|
|
|