mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Pathfinding: Allow using PathGenerator with any source location, not only objects current position
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourNavMeshQuery.h"
|
||||
#include "DisableMgr.h"
|
||||
#include "G3DPosition.hpp"
|
||||
#include "Log.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MMapManager.h"
|
||||
@@ -31,14 +32,14 @@
|
||||
PathGenerator::PathGenerator(WorldObject const* owner) :
|
||||
_polyLength(0), _type(PATHFIND_BLANK), _useStraightPath(false),
|
||||
_forceDestination(false), _pointPathLimit(MAX_POINT_PATH_LENGTH), _useRaycast(false),
|
||||
_endPosition(G3D::Vector3::zero()), _source(owner), _navMesh(nullptr),
|
||||
_startPosition(PositionToVector3(owner)), _endPosition(G3D::Vector3::zero()), _source(owner), _navMesh(nullptr),
|
||||
_navMeshQuery(nullptr)
|
||||
{
|
||||
memset(_pathPolyRefs, 0, sizeof(_pathPolyRefs));
|
||||
|
||||
TC_LOG_DEBUG("maps.mmaps", "++ PathGenerator::PathGenerator for {}", _source->GetGUID().ToString());
|
||||
|
||||
uint32 mapId = PhasingHandler::GetTerrainMapId(_source->GetPhaseShift(), _source->GetMapId(), _source->GetMap()->GetTerrain(), _source->GetPositionX(), _source->GetPositionY());
|
||||
uint32 mapId = PhasingHandler::GetTerrainMapId(_source->GetPhaseShift(), _source->GetMapId(), _source->GetMap()->GetTerrain(), _startPosition.x, _startPosition.y);
|
||||
if (DisableMgr::IsPathfindingEnabled(_source->GetMapId()))
|
||||
{
|
||||
MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
|
||||
@@ -54,12 +55,9 @@ PathGenerator::~PathGenerator()
|
||||
TC_LOG_DEBUG("maps.mmaps", "++ PathGenerator::~PathGenerator() for {}", _source->GetGUID().ToString());
|
||||
}
|
||||
|
||||
bool PathGenerator::CalculatePath(float destX, float destY, float destZ, bool forceDest)
|
||||
bool PathGenerator::CalculatePath(float srcX, float srcY, float srcZ, float destX, float destY, float destZ, bool forceDest)
|
||||
{
|
||||
float x, y, z;
|
||||
_source->GetPosition(x, y, z);
|
||||
|
||||
if (!Trinity::IsValidMapCoord(destX, destY, destZ) || !Trinity::IsValidMapCoord(x, y, z))
|
||||
if (!Trinity::IsValidMapCoord(destX, destY, destZ) || !Trinity::IsValidMapCoord(srcX, srcY, srcZ))
|
||||
return false;
|
||||
|
||||
TC_METRIC_DETAILED_EVENT("mmap_events", "CalculatePath", "");
|
||||
@@ -67,7 +65,7 @@ bool PathGenerator::CalculatePath(float destX, float destY, float destZ, bool fo
|
||||
G3D::Vector3 dest(destX, destY, destZ);
|
||||
SetEndPosition(dest);
|
||||
|
||||
G3D::Vector3 start(x, y, z);
|
||||
G3D::Vector3 start(srcX, srcY, srcZ);
|
||||
SetStartPosition(start);
|
||||
|
||||
_forceDestination = forceDest;
|
||||
@@ -91,6 +89,13 @@ bool PathGenerator::CalculatePath(float destX, float destY, float destZ, bool fo
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PathGenerator::CalculatePath(float destX, float destY, float destZ, bool forceDest)
|
||||
{
|
||||
float x, y, z;
|
||||
_source->GetPosition(x, y, z);
|
||||
return CalculatePath(x, y, z, destX, destY, destZ, forceDest);
|
||||
}
|
||||
|
||||
dtPolyRef PathGenerator::GetPathPolyByPosition(dtPolyRef const* polyPath, uint32 polyPathSize, float const* point, float* distance) const
|
||||
{
|
||||
if (!polyPath || !polyPathSize)
|
||||
@@ -684,9 +689,9 @@ void PathGenerator::UpdateFilter()
|
||||
if (_sourceUnit->IsInWater() || _sourceUnit->IsUnderWater())
|
||||
{
|
||||
uint16 includedFlags = _filter.getIncludeFlags();
|
||||
includedFlags |= GetNavTerrain(_source->GetPositionX(),
|
||||
_source->GetPositionY(),
|
||||
_source->GetPositionZ());
|
||||
includedFlags |= GetNavTerrain(_startPosition.x,
|
||||
_startPosition.y,
|
||||
_startPosition.z);
|
||||
|
||||
_filter.setIncludeFlags(includedFlags);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ class TC_GAME_API PathGenerator
|
||||
|
||||
// Calculate the path from owner to given destination
|
||||
// return: true if new path was calculated, false otherwise (no change needed)
|
||||
bool CalculatePath(float srcX, float srcY, float srcZ, float destX, float destY, float destZ, bool forceDest = false);
|
||||
bool CalculatePath(float destX, float destY, float destZ, bool forceDest = false);
|
||||
bool IsInvalidDestinationZ(WorldObject const* target) const;
|
||||
|
||||
@@ -84,7 +85,7 @@ class TC_GAME_API PathGenerator
|
||||
PathType GetPathType() const { return _type; }
|
||||
|
||||
// shortens the path until the destination is the specified distance from the target point
|
||||
void ShortenPathUntilDist(G3D::Vector3 const& point, float dist);
|
||||
void ShortenPathUntilDist(G3D::Vector3 const& target, float dist);
|
||||
|
||||
private:
|
||||
|
||||
@@ -142,7 +143,7 @@ class TC_GAME_API PathGenerator
|
||||
unsigned char& steerPosFlag, dtPolyRef& steerPosRef);
|
||||
dtStatus FindSmoothPath(float const* startPos, float const* endPos,
|
||||
dtPolyRef const* polyPath, uint32 polyPathSize,
|
||||
float* smoothPath, int* smoothPathSize, uint32 smoothPathMaxSize);
|
||||
float* smoothPath, int* smoothPathSize, uint32 maxSmoothPathSize);
|
||||
|
||||
void AddFarFromPolyFlags(bool startFarFromPoly, bool endFarFromPoly);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user