From 187bdab4fa90fbfa5b1979ea529dc9c0deac89d9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 25 Nov 2014 23:03:33 +0000 Subject: Merge remote-tracking branch 'origin-master' into c++11 --- src/Mobs/Monster.cpp | 4 ++-- src/Mobs/Monster.h | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index bcdc404c2..4f8afa0de 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -159,7 +159,7 @@ void cMonster::TickPathFinding() BLOCKTYPE BlockAtYP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 1, gCrossCoords[i].z + PosZ); BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ); int LowestY = FindFirstNonAirBlockPosition(gCrossCoords[i].x + PosX, gCrossCoords[i].z + PosZ); - BLOCKTYPE BlockAtLowestY = m_World->GetBlock(gCrossCoords[i].x + PosX, LowestY, gCrossCoords[i].z + PosZ); + BLOCKTYPE BlockAtLowestY = (LowestY >= cChunkDef::Height) ? E_BLOCK_AIR : m_World->GetBlock(gCrossCoords[i].x + PosX, LowestY, gCrossCoords[i].z + PosZ); if ( (!cBlockInfo::IsSolid(BlockAtY)) && @@ -452,7 +452,7 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) } else { - while (cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY < cChunkDef::Height)) + while ((PosY < cChunkDef::Height) && cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ)))) { PosY++; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index f5ae2cb4d..e5dcb0309 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -169,10 +169,12 @@ protected: /** Stores if mobile is currently moving towards the ultimate, final destination */ bool m_bMovingToDestination; - /** Finds the first non-air block position (not the highest, as cWorld::GetHeight does) - If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1 - If current Y is solid, goes up to find first nonsolid block, and returns that */ + /** Finds the lowest non-air block position (not the highest, as cWorld::GetHeight does) + If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1 + If current Y is solid, goes up to find first nonsolid block, and returns that. + If no suitable position is found, returns cChunkDef::Height. */ int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ); + /** Returns if a monster can actually reach a given height by jumping or walking */ inline bool IsNextYPosReachable(int a_PosY) { -- cgit v1.2.3