diff options
5 files changed, 33 insertions, 14 deletions
diff --git a/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp index 9296cddc242..dd6e3708d68 100755 --- a/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp @@ -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; diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp index 26aaf495c2e..39f559394ee 100644 --- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp @@ -165,7 +165,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; diff --git a/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp index cd32124df2d..630b03606f0 100644 --- a/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp @@ -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; diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index 711e57eb1b5..ac46a8963c8 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -226,7 +226,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 @@ -239,7 +239,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); } } @@ -250,14 +250,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; } @@ -468,6 +466,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); } @@ -774,11 +775,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++; diff --git a/src/server/game/Movement/PathGenerator.h b/src/server/game/Movement/PathGenerator.h index 730efdcc995..3a9c260684f 100644 --- a/src/server/game/Movement/PathGenerator.h +++ b/src/server/game/Movement/PathGenerator.h @@ -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 |