summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Path.h
diff options
context:
space:
mode:
authorSafwat Halaby <SafwatHalaby@users.noreply.github.com>2015-05-17 22:21:52 +0200
committerSafwat Halaby <SafwatHalaby@users.noreply.github.com>2015-05-17 22:21:52 +0200
commitb7b088494c601576750e014204635f5b21600eb1 (patch)
tree9600532fc83329798b39ce3e09714060dcd81839 /src/Mobs/Path.h
parentproperly this time? (diff)
parentPathfinder - approximated paths when original destination unreachable (diff)
downloadcuberite-b7b088494c601576750e014204635f5b21600eb1.tar
cuberite-b7b088494c601576750e014204635f5b21600eb1.tar.gz
cuberite-b7b088494c601576750e014204635f5b21600eb1.tar.bz2
cuberite-b7b088494c601576750e014204635f5b21600eb1.tar.lz
cuberite-b7b088494c601576750e014204635f5b21600eb1.tar.xz
cuberite-b7b088494c601576750e014204635f5b21600eb1.tar.zst
cuberite-b7b088494c601576750e014204635f5b21600eb1.zip
Diffstat (limited to 'src/Mobs/Path.h')
-rw-r--r--src/Mobs/Path.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h
index 008722d29..7a4182f17 100644
--- a/src/Mobs/Path.h
+++ b/src/Mobs/Path.h
@@ -23,7 +23,7 @@ Put this in your .cpp:
class cChunk;
/* Various little structs and classes */
-enum class ePathFinderStatus {CALCULATING, PATH_FOUND, PATH_NOT_FOUND};
+enum class ePathFinderStatus {CALCULATING, PATH_FOUND, PATH_NOT_FOUND, NEARBY_FOUND};
struct cPathCell; // Defined inside Path.cpp
class compareHeuristics
{
@@ -62,9 +62,17 @@ public:
/** Destroys the path and frees its memory. */
~cPath();
- /** Performs part of the path calculation and returns true if the path computation has finished. */
+ /** Performs part of the path calculation and returns the appropriate status.
+ If NEARBY_FOUND is returned, it means that the destination is not reachable, but a nearby destination
+ is reachable. If the user likes the alternative destination, they can call AcceptNearbyPath to treat the path as found,
+ and to make consequent calls to step return PATH_FOUND*/
ePathFinderStatus Step(cChunk & a_Chunk);
+ /** Called after the PathFinder's step returns NEARBY_FOUND.
+ Changes the PathFinder status from NEARBY_FOUND to PATH_FOUND, returns the nearby destination that
+ the PathFinder found a path to. */
+ Vector3i AcceptNearbyPath();
+
/* Point retrieval functions, inlined for performance. */
/** Returns the next point in the path. */
inline Vector3i GetNextPoint()
@@ -93,7 +101,10 @@ public:
/** Returns the total number of points this path has. */
inline int GetPointCount()
{
- ASSERT(m_Status == ePathFinderStatus::PATH_FOUND);
+ if (m_Status != ePathFinderStatus::PATH_FOUND)
+ {
+ return 0;
+ }
return m_PathPoints.size();
}
@@ -119,6 +130,8 @@ private:
bool Step_Internal(); // The public version just calls this version * CALCULATIONS_PER_CALL times.
void FinishCalculation(); // Clears the memory used for calculating the path.
void FinishCalculation(ePathFinderStatus a_NewStatus); // Clears the memory used for calculating the path and changes the status.
+ void AttemptToFindAlternative();
+ void BuildPath();
/* Openlist and closedlist management */
void OpenListAdd(cPathCell * a_Cell);
@@ -135,6 +148,7 @@ private:
Vector3i m_Destination;
Vector3i m_Source;
int m_StepsLeft;
+ cPathCell * m_NearestPointToTarget;
/* Control fields */
ePathFinderStatus m_Status;
@@ -145,6 +159,7 @@ private:
/* Interfacing with the world */
cChunk * m_Chunk; // Only valid inside Step()!
+ bool m_BadChunkFound;
#ifdef COMPILING_PATHFIND_DEBUGGER
#include "../path_irrlicht.cpp"
#endif