From c0c47d33c571bde4cfb45043b645b3d45c3223e6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 12 Apr 2014 13:16:48 +0100 Subject: Entities handle chunks properly again * Entities properly handle chunks * Changed EntityStatus enums to be less shouty --- src/Mobs/Sheep.cpp | 2 +- src/Mobs/Villager.cpp | 2 +- src/Mobs/Wolf.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index c64360153..d599a4cef 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -101,7 +101,7 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk) { if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS) { - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_SHEEP_EATING); + m_World->BroadcastEntityStatus(*this, esSheepEating); m_TimeToStopEating = 40; } } diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index bbd8d6aaa..d049acc1e 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -30,7 +30,7 @@ void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) { if (m_World->GetTickRandomNumber(5) == 3) { - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_VILLAGER_ANGRY); + m_World->BroadcastEntityStatus(*this, esVillagerAngry); } } } diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 0d3619166..f02b8a4fc 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -75,12 +75,12 @@ void cWolf::OnRightClicked(cPlayer & a_Player) SetMaxHealth(20); SetIsTame(true); SetOwner(a_Player.GetName()); - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED); + m_World->BroadcastEntityStatus(*this, esWolfTamed); m_World->BroadcastParticleEffect("heart", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5); } else { - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMING); + m_World->BroadcastEntityStatus(*this, esWolfTaming); m_World->BroadcastParticleEffect("smoke", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5); } } -- cgit v1.2.3 From bdea8706d8050ba3ea00b580bba795bc468cfdbd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 17 Apr 2014 18:50:25 +0100 Subject: Added new AI rules + Added new AI rules handling cacti and large heights * Fixed cIniFile not recognising comments in cIniFile::ReadFile() * Fixed users.ini not being properly generated * Changed all instances of (int)floor(GetPosXXX()) to POSXXX_TOINT --- src/Mobs/Monster.cpp | 38 ++++++++++++++++++++++++++------------ src/Mobs/Monster.h | 4 ++-- 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 171097aba..d63758b3d 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -111,9 +111,9 @@ void cMonster::SpawnOn(cClientHandle & a_Client) void cMonster::TickPathFinding() { - const int PosX = (int)floor(GetPosX()); - const int PosY = (int)floor(GetPosY()); - const int PosZ = (int)floor(GetPosZ()); + const int PosX = POSX_TOINT; + const int PosY = POSY_TOINT; + const int PosZ = POSZ_TOINT; m_FinalDestination.y = (double)FindFirstNonAirBlockPosition(m_FinalDestination.x, m_FinalDestination.z); @@ -148,13 +148,27 @@ void cMonster::TickPathFinding() BLOCKTYPE BlockAtY = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ); 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); - BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ); - - if ((!cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) + 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); + + if ( + (!cBlockInfo::IsSolid(BlockAtY)) && + (!cBlockInfo::IsSolid(BlockAtYP)) && + (!IsBlockLava(BlockAtLowestY)) && + (BlockAtLowestY != E_BLOCK_CACTUS) && + (PosY - LowestY < FALL_DAMAGE_HEIGHT) + ) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ)); } - else if ((cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!cBlockInfo::IsSolid(BlockAtYPP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) + else if ( + (cBlockInfo::IsSolid(BlockAtY)) && + (BlockAtY != E_BLOCK_CACTUS) && + (!cBlockInfo::IsSolid(BlockAtYP)) && + (!cBlockInfo::IsSolid(BlockAtYPP)) && + (BlockAtY != E_BLOCK_FENCE) && + (BlockAtY != E_BLOCK_FENCE_GATE) + ) { m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ)); } @@ -402,7 +416,7 @@ void cMonster::HandleFalling() GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */); } - m_LastGroundHeight = (int)floor(GetPosY()); + m_LastGroundHeight = POSY_TOINT; } } @@ -411,7 +425,7 @@ void cMonster::HandleFalling() int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) { - int PosY = (int)floor(GetPosY()); + int PosY = POSY_TOINT; if (PosY < 0) PosY = 0; @@ -969,15 +983,15 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk) return; } - int RelY = (int)floor(GetPosY()); + int RelY = POSY_TOINT; if ((RelY < 0) || (RelY >= cChunkDef::Height)) { // Outside the world return; } - int RelX = (int)floor(GetPosX()) - GetChunkX() * cChunkDef::Width; - int RelZ = (int)floor(GetPosZ()) - GetChunkZ() * cChunkDef::Width; + int RelX = POSX_TOINT - GetChunkX() * cChunkDef::Width; + int RelZ = POSZ_TOINT - GetChunkZ() * cChunkDef::Width; if (!a_Chunk.IsLightValid()) { diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 776426a0d..70b3783fc 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -185,14 +185,14 @@ protected: inline bool IsNextYPosReachable(int a_PosY) { return ( - (a_PosY <= (int)floor(GetPosY())) || + (a_PosY <= POSY_TOINT) || DoesPosYRequireJump(a_PosY) ); } /** Returns if a monster can reach a given height by jumping */ inline bool DoesPosYRequireJump(int a_PosY) { - return ((a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1)); + return ((a_PosY > POSY_TOINT) && (a_PosY == POSY_TOINT + 1)); } /** A semi-temporary list to store the traversed coordinates during active pathfinding so we don't visit them again */ -- cgit v1.2.3