mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-24 10:56:38 +01:00
Core/PathGenerator: Fix path generator returning shortcuts when start and end are on the same polygon (#24083)
* Core/PathGenerator: Fix path generator returning shortcuts when start and end are on the same polygon Second try of handling paths on same poly in a better way than just building a shortcut * Fix movement generators using paths with start/end positions far from mmap polygons * Include flag PATHFIND_FARFROMPOLY even with a normal path if start or end were far away from mmap poly
This commit is contained in:
@@ -107,7 +107,9 @@ bool ConfusedMovementGenerator<T>::DoUpdate(T* owner, uint32 diff)
|
||||
}
|
||||
|
||||
bool result = _path->CalculatePath(destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ());
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH) || (_path->GetPathType() & PATHFIND_SHORTCUT))
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH)
|
||||
|| (_path->GetPathType() & PATHFIND_SHORTCUT)
|
||||
|| (_path->GetPathType() & PATHFIND_FARFROMPOLY))
|
||||
{
|
||||
_timer.Reset(100);
|
||||
return true;
|
||||
|
||||
@@ -164,7 +164,9 @@ void FleeingMovementGenerator<T>::SetTargetLocation(T* owner)
|
||||
}
|
||||
|
||||
bool result = _path->CalculatePath(destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ());
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH) || (_path->GetPathType() & PATHFIND_SHORTCUT))
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH)
|
||||
|| (_path->GetPathType() & PATHFIND_SHORTCUT)
|
||||
|| (_path->GetPathType() & PATHFIND_FARFROMPOLY))
|
||||
{
|
||||
_timer.Reset(100);
|
||||
return;
|
||||
|
||||
@@ -140,7 +140,9 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
|
||||
}
|
||||
|
||||
bool result = _path->CalculatePath(position.GetPositionX(), position.GetPositionY(), position.GetPositionZ());
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH) || (_path->GetPathType() & PATHFIND_SHORTCUT))
|
||||
if (!result || (_path->GetPathType() & PATHFIND_NOPATH)
|
||||
|| (_path->GetPathType() & PATHFIND_SHORTCUT)
|
||||
|| (_path->GetPathType() & PATHFIND_FARFROMPOLY))
|
||||
{
|
||||
_timer.Reset(100);
|
||||
return;
|
||||
|
||||
@@ -225,7 +225,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
||||
if (buildShotrcut)
|
||||
{
|
||||
BuildShortcut();
|
||||
_type = PathType(PATHFIND_NORMAL | PATHFIND_NOT_USING_PATH);
|
||||
_type = PathType(PATHFIND_NORMAL | PATHFIND_NOT_USING_PATH | PATHFIND_FARFROMPOLY);
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -238,7 +238,7 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
||||
SetActualEndPosition(G3D::Vector3(endPoint[2], endPoint[0], endPoint[1]));
|
||||
}
|
||||
|
||||
_type = PATHFIND_INCOMPLETE;
|
||||
_type = PathType(PATHFIND_INCOMPLETE | PATHFIND_FARFROMPOLY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,14 +249,12 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
||||
if (startPoly == endPoly)
|
||||
{
|
||||
TC_LOG_DEBUG("maps.mmaps", "++ BuildPolyPath :: (startPoly == endPoly)");
|
||||
|
||||
BuildShortcut();
|
||||
|
||||
_pathPolyRefs[0] = startPoly;
|
||||
_polyLength = 1;
|
||||
|
||||
_type = farFromPoly ? PATHFIND_INCOMPLETE : PATHFIND_NORMAL;
|
||||
TC_LOG_DEBUG("maps.mmaps", "++ BuildPolyPath :: path type %d", _type);
|
||||
_type = farFromPoly ? PathType(PATHFIND_INCOMPLETE | PATHFIND_FARFROMPOLY) : PATHFIND_NORMAL;
|
||||
|
||||
BuildPointPath(startPoint, endPoint);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -467,6 +465,9 @@ void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 con
|
||||
else
|
||||
_type = PATHFIND_INCOMPLETE;
|
||||
|
||||
if (farFromPoly)
|
||||
_type = PathType(_type | PATHFIND_FARFROMPOLY);
|
||||
|
||||
// generate the point-path out of our up-to-date poly-path
|
||||
BuildPointPath(startPoint, endPoint);
|
||||
}
|
||||
@@ -772,11 +773,22 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
|
||||
uint32 npolys = polyPathSize;
|
||||
|
||||
float iterPos[VERTEX_SIZE], targetPos[VERTEX_SIZE];
|
||||
if (dtStatusFailed(_navMeshQuery->closestPointOnPolyBoundary(polys[0], startPos, iterPos)))
|
||||
return DT_FAILURE;
|
||||
|
||||
if (dtStatusFailed(_navMeshQuery->closestPointOnPolyBoundary(polys[npolys-1], endPos, targetPos)))
|
||||
return DT_FAILURE;
|
||||
if (polyPathSize > 1)
|
||||
{
|
||||
// Pick the closest poitns on poly border
|
||||
if (dtStatusFailed(_navMeshQuery->closestPointOnPolyBoundary(polys[0], startPos, iterPos)))
|
||||
return DT_FAILURE;
|
||||
|
||||
if (dtStatusFailed(_navMeshQuery->closestPointOnPolyBoundary(polys[npolys - 1], endPos, targetPos)))
|
||||
return DT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case where the path is on the same poly
|
||||
dtVcopy(iterPos, startPos);
|
||||
dtVcopy(targetPos, endPos);
|
||||
}
|
||||
|
||||
dtVcopy(&smoothPath[nsmoothPath*VERTEX_SIZE], iterPos);
|
||||
nsmoothPath++;
|
||||
|
||||
@@ -47,6 +47,7 @@ enum PathType
|
||||
PATHFIND_NOPATH = 0x08, // no valid path at all or error in generating one
|
||||
PATHFIND_NOT_USING_PATH = 0x10, // used when we are either flying/swiming or on map w/o mmaps
|
||||
PATHFIND_SHORT = 0x20, // path is longer or equal to its limited path length
|
||||
PATHFIND_FARFROMPOLY = 0x40, // start of end positions are far from the mmap poligon
|
||||
};
|
||||
|
||||
class TC_GAME_API PathGenerator
|
||||
|
||||
Reference in New Issue
Block a user