summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Path.h
diff options
context:
space:
mode:
authorSafwatHalaby <SafwatHalaby@users.noreply.github.com>2015-05-16 13:05:33 +0200
committerSafwatHalaby <SafwatHalaby@users.noreply.github.com>2015-05-17 18:36:52 +0200
commit29e31c5be95abd6a7122a525f53d80f4576e49b2 (patch)
treed3fe3c82b0d27a9a35f120934eca16b3daf36829 /src/Mobs/Path.h
parentPathFinder uses UniquePtr for cell map. (diff)
downloadcuberite-29e31c5be95abd6a7122a525f53d80f4576e49b2.tar
cuberite-29e31c5be95abd6a7122a525f53d80f4576e49b2.tar.gz
cuberite-29e31c5be95abd6a7122a525f53d80f4576e49b2.tar.bz2
cuberite-29e31c5be95abd6a7122a525f53d80f4576e49b2.tar.lz
cuberite-29e31c5be95abd6a7122a525f53d80f4576e49b2.tar.xz
cuberite-29e31c5be95abd6a7122a525f53d80f4576e49b2.tar.zst
cuberite-29e31c5be95abd6a7122a525f53d80f4576e49b2.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