6 #include "../BlockInfo.h"
10 #define NORMAL_G_COST 10
11 #define DIAGONAL_G_COST 14
13 #define DISTANCE_MANHATTAN 0
14 #define HEURISTICS_ONLY 0
15 #define CALCULATIONS_PER_STEP 10
24 return a_Cell1->
m_F > a_Cell2->
m_F;
34 const Vector3d & a_StartingPoint,
const Vector3d & a_EndingPoint,
int a_MaxSteps,
35 double a_BoundingBoxWidth,
double a_BoundingBoxHeight
37 m_StepsLeft(a_MaxSteps),
41 m_BadChunkFound(false)
44 a_BoundingBoxWidth = 1;
50 int HalfWidthInt =
FloorC(a_BoundingBoxWidth / 2);
139 if (CurrentCell ==
nullptr)
173 bool DoneEast =
false,
180 bool WalkableEast =
false,
181 WalkableWest =
false,
182 WalkableNorth =
false,
183 WalkableSouth =
false;
223 for (
int y = 0; y >= -3; --y)
239 for (
int y = 0; y >= -3; --y)
255 for (
int y = 0; y >= -3; --y)
262 WalkableSouth =
true;
271 for (
int y = 0; y >= -3; --y)
278 WalkableNorth =
true;
287 if (WalkableNorth && WalkableEast)
291 if (WalkableNorth && WalkableWest)
295 if (WalkableSouth && WalkableEast)
299 if (WalkableSouth && WalkableWest)
332 while (CurrentCell->
m_Parent !=
nullptr)
341 CurrentCell = CurrentCell->
m_Parent;
378 #ifdef COMPILING_PATHFIND_DEBUGGER
397 #ifdef COMPILING_PATHFIND_DEBUGGER
398 si::setBlock((Ret)->m_Location.x, (Ret)->m_Location.y, (Ret)->m_Location.z, debug_closed, SetMini(Ret));
434 if (a_Caller !=
nullptr)
436 a_Cell->
m_G = a_Caller->
m_G + a_GDelta;
444 #if DISTANCE_MANHATTAN == 1
452 #if HEURISTICS_ONLY == 1
453 a_Cell->
m_F = a_Cell->
m_H;
463 int NewG = a_Caller->
m_G + a_GDelta;
464 if (NewG < a_Cell->m_G)
492 if ((Chunk ==
nullptr) || !Chunk->IsValid())
539 if (
m_Map.count(a_Location) == 0)
541 m_Map[a_Location].m_Location = a_Location;
544 #ifdef COMPILING_PATHFIND_DEBUGGER
545 #ifdef COMPILING_PATHFIND_DEBUGGER_MARK_UNCHECKED
546 si::setBlock(a_Location.x, a_Location.y, a_Location.z, debug_unchecked, Cell->m_IsSolid ? NORMAL : MINI);
549 return &
m_Map[a_Location];
553 return &
m_Map[a_Location];
634 if (a_Direction ==
Vector3i(0, 0, 0))
644 return (a_Direction.
y > 0);
bool IsBlockWater(BLOCKTYPE a_BlockType)
bool IsBlockFence(BLOCKTYPE a_BlockType)
@ E_BLOCK_STATIONARY_WATER
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
std::enable_if< std::is_arithmetic< T >::value, C >::type CeilC(T a_Value)
Ceils a value, then casts it to C (an int by default).
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
#define CALCULATIONS_PER_STEP
static bool IsSolid(BLOCKTYPE Block)
Is this block solid (player cannot walk through)?
cChunk * GetNeighborChunk(int a_BlockX, int a_BlockZ)
Returns the chunk into which the specified block belongs, by walking the neighbors.
void GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
The pathfinder has 3 types of cells (cPathCell).
bool operator()(cPathCell *&a_V1, cPathCell *&a_V2)
cPathCell * m_NearestPointToTarget
bool ProcessIfWalkable(const Vector3i &a_Location, cPathCell *a_Source, int a_Cost)
bool BodyFitsIn(const Vector3i &a_Location, const Vector3i &a_Source)
void AttemptToFindAlternative()
cPathCell * GetCell(const Vector3i &a_location)
void ProcessCell(cPathCell *a_Cell, cPathCell *a_Caller, int a_GDelta)
bool HasSolidBelow(const Vector3i &a_Location)
std::unordered_map< Vector3i, cPathCell, VectorHasher< int > > m_Map
bool IsWalkable(const Vector3i &a_Location, const Vector3i &a_Source)
void OpenListAdd(cPathCell *a_Cell)
ePathFinderStatus m_Status
cPathCell * OpenListPop()
void FillCellAttributes(cPathCell &a_Cell)
bool BlockTypeIsSpecial(BLOCKTYPE a_Type)
std::priority_queue< cPathCell *, std::vector< cPathCell * >, compareHeuristics > m_OpenList
std::vector< Vector3i > m_PathPoints
cPath()
Creates an invalid path which is not usable.
Vector3i AcceptNearbyPath()
Called after the PathFinder's step returns NEARBY_FOUND.
ePathFinderStatus CalculationStep(cChunk &a_Chunk)
Performs part of the path calculation and returns the appropriate status.
bool SpecialIsSolidFromThisDirection(BLOCKTYPE a_Type, NIBBLETYPE a_Meta, const Vector3i &a_Direction)