diff options
author | Safwat Halaby <SafwatHalaby@users.noreply.github.com> | 2015-12-16 17:39:23 +0100 |
---|---|---|
committer | Safwat Halaby <SafwatHalaby@users.noreply.github.com> | 2015-12-16 17:39:23 +0100 |
commit | 3c1f9e8a3a0c70d82f2145f1e03ba846ad2a6399 (patch) | |
tree | 2d9f76057167d166516658f7be4dc3aab82e001d /src/Mobs/Path.cpp | |
parent | Merge pull request #2754 from Gargaj/horsefix (diff) | |
parent | Changed cPath to have a reset method. (diff) | |
download | cuberite-3c1f9e8a3a0c70d82f2145f1e03ba846ad2a6399.tar cuberite-3c1f9e8a3a0c70d82f2145f1e03ba846ad2a6399.tar.gz cuberite-3c1f9e8a3a0c70d82f2145f1e03ba846ad2a6399.tar.bz2 cuberite-3c1f9e8a3a0c70d82f2145f1e03ba846ad2a6399.tar.lz cuberite-3c1f9e8a3a0c70d82f2145f1e03ba846ad2a6399.tar.xz cuberite-3c1f9e8a3a0c70d82f2145f1e03ba846ad2a6399.tar.zst cuberite-3c1f9e8a3a0c70d82f2145f1e03ba846ad2a6399.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Mobs/Path.cpp | 90 |
1 files changed, 62 insertions, 28 deletions
diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp index c0cffbeb4..f3a0d6cf2 100644 --- a/src/Mobs/Path.cpp +++ b/src/Mobs/Path.cpp @@ -39,34 +39,7 @@ cPath::cPath( m_Chunk(&a_Chunk), m_BadChunkFound(false) { - // TODO: if src not walkable OR dest not walkable, then abort. - // Borrow a new "isWalkable" from ProcessIfWalkable, make ProcessIfWalkable also call isWalkable - - a_BoundingBoxWidth = 1; // Until we improve physics, if ever. - - m_BoundingBoxWidth = CeilC(a_BoundingBoxWidth); - m_BoundingBoxHeight = CeilC(a_BoundingBoxHeight); - m_HalfWidth = a_BoundingBoxWidth / 2; - - int HalfWidthInt = FloorC(a_BoundingBoxWidth / 2); - m_Source.x = FloorC(a_StartingPoint.x - HalfWidthInt); - m_Source.y = FloorC(a_StartingPoint.y); - m_Source.z = FloorC(a_StartingPoint.z - HalfWidthInt); - - m_Destination.x = FloorC(a_EndingPoint.x - HalfWidthInt); - m_Destination.y = FloorC(a_EndingPoint.y); - m_Destination.z = FloorC(a_EndingPoint.z - HalfWidthInt); - - if (GetCell(m_Source)->m_IsSolid || GetCell(m_Destination)->m_IsSolid) - { - m_Status = ePathFinderStatus::PATH_NOT_FOUND; - return; - } - - m_NearestPointToTarget = GetCell(m_Source); - m_Status = ePathFinderStatus::CALCULATING; - - ProcessCell(GetCell(m_Source), nullptr, 0); + ResetImpl(a_StartingPoint, a_EndingPoint, a_BoundingBoxWidth, a_BoundingBoxHeight); } cPath::cPath() : m_IsValid(false) @@ -497,3 +470,64 @@ cPathCell * cPath::GetCell(const Vector3i & a_Location) return &m_Map[a_Location]; } } + + + + + +void cPath::ResetImpl( + const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, + double a_BoundingBoxWidth, double a_BoundingBoxHeight +) +{ + // TODO: if src not walkable OR dest not walkable, then abort. + // Borrow a new "isWalkable" from ProcessIfWalkable, make ProcessIfWalkable also call isWalkable + + a_BoundingBoxWidth = 1; // Until we improve physics, if ever. + + m_BoundingBoxWidth = CeilC(a_BoundingBoxWidth); + m_BoundingBoxHeight = CeilC(a_BoundingBoxHeight); + m_HalfWidth = a_BoundingBoxWidth / 2; + + int HalfWidthInt = FloorC(a_BoundingBoxWidth / 2); + m_Source.x = FloorC(a_StartingPoint.x - HalfWidthInt); + m_Source.y = FloorC(a_StartingPoint.y); + m_Source.z = FloorC(a_StartingPoint.z - HalfWidthInt); + + m_Destination.x = FloorC(a_EndingPoint.x - HalfWidthInt); + m_Destination.y = FloorC(a_EndingPoint.y); + m_Destination.z = FloorC(a_EndingPoint.z - HalfWidthInt); + + if (GetCell(m_Source)->m_IsSolid || GetCell(m_Destination)->m_IsSolid) + { + m_Status = ePathFinderStatus::PATH_NOT_FOUND; + return; + } + + m_NearestPointToTarget = GetCell(m_Source); + m_Status = ePathFinderStatus::CALCULATING; + + ProcessCell(GetCell(m_Source), nullptr, 0); +} + + + + + +void cPath::Reset( + cChunk & a_Chunk, + const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, int a_MaxSteps, + double a_BoundingBoxWidth, double a_BoundingBoxHeight, + int a_MaxUp, int a_MaxDown +) +{ + m_Map.clear(); + m_OpenList = decltype(m_OpenList){}; + m_StepsLeft = a_MaxSteps; + m_IsValid = true; + m_CurrentPoint = 0; // GetNextPoint increments this to 1, but that's fine, since the first cell is always a_StartingPoint + m_Chunk = &a_Chunk; + m_BadChunkFound = false; + ResetImpl(a_StartingPoint, a_EndingPoint, a_BoundingBoxWidth, a_BoundingBoxHeight); +} + |