Created
February 24, 2011 21:00
-
-
Save vermie/842876 to your computer and use it in GitHub Desktop.
check tile exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/game/PathFinder.cpp b/src/game/PathFinder.cpp | |
index d343503..082c6dd 100644 | |
--- a/src/game/PathFinder.cpp | |
+++ b/src/game/PathFinder.cpp | |
@@ -81,7 +81,8 @@ bool PathInfo::Update(const float destX, const float destY, const float destZ, b | |
PATH_DEBUG("++ PathInfo::Update() for %u \n", m_sourceUnit->GetGUID()); | |
// make sure navMesh works - we can run on map w/o mmap | |
- if (!m_navMesh || !m_navMeshQuery || m_sourceUnit->hasUnitState(UNIT_STAT_IGNORE_PATHFINDING)) | |
+ if (m_sourceUnit->hasUnitState(UNIT_STAT_IGNORE_PATHFINDING) || | |
+ !m_navMesh || !m_navMeshQuery || !HaveTiles(newStart, newDest)) | |
{ | |
BuildShortcut(); | |
m_type = PathType(PATHFIND_NORMAL | PATHFIND_NOT_USING_PATH); | |
@@ -185,6 +186,13 @@ void PathInfo::BuildPolyPath(PathNode startPos, PathNode endPos) | |
{ | |
// *** getting start/end poly logic *** | |
+ if (!HaveTiles(startPos, endPos)) | |
+ { | |
+ BuildShortcut(); | |
+ m_type = PathType(PATHFIND_NORMAL | PATHFIND_NOT_USING_PATH); | |
+ return; | |
+ } | |
+ | |
float distToStartPoly, distToEndPoly; | |
float startPoint[VERTEX_SIZE] = {startPos.y, startPos.z, startPos.x}; | |
float endPoint[VERTEX_SIZE] = {endPos.y, endPos.z, endPos.x}; | |
@@ -752,3 +760,24 @@ dtStatus PathInfo::findSmoothPath(const float* startPos, const float* endPos, | |
// this is most likely loop | |
return nsmoothPath < maxSmoothPathSize ? DT_SUCCESS : DT_FAILURE; | |
} | |
+ | |
+bool PathInfo::HaveTiles(const PathNode startPos, const PathNode endPos) const | |
+{ | |
+ bool haveTiles; | |
+ int tx, ty; | |
+ | |
+ float startPoint[VERTEX_SIZE] = {startPos.y, startPos.z, startPos.x}; | |
+ float endPoint[VERTEX_SIZE] = {endPos.y, endPos.z, endPos.x}; | |
+ | |
+ // check if the start and end point have a mmtile loaded | |
+ m_navMesh->calcTileLoc(startPoint, &tx, &ty); | |
+ haveTiles = m_navMesh->getTileAt(tx, ty) != NULL; | |
+ | |
+ if (haveTiles) | |
+ { | |
+ m_navMesh->calcTileLoc(endPoint, &tx, &ty); | |
+ haveTiles = m_navMesh->getTileAt(tx, ty) != NULL; | |
+ } | |
+ | |
+ return haveTiles; | |
+} | |
diff --git a/src/game/PathFinder.h b/src/game/PathFinder.h | |
index e716a91..4228e16 100644 | |
--- a/src/game/PathFinder.h | |
+++ b/src/game/PathFinder.h | |
@@ -116,6 +116,7 @@ class PathInfo | |
void BuildPolyPath(PathNode startPos, PathNode endPos); | |
void BuildPointPath(float *startPoint, float *endPoint); | |
void BuildShortcut(); | |
+ bool HaveTiles(const PathNode startPos, const PathNode endPos) const; | |
NavTerrain getNavTerrain(float x, float y, float z); | |
void createFilter(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment