summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Monster.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-25 15:42:26 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-25 15:42:26 +0100
commit314fc3cdac702a44a257ada5fab52f0a7d37ffcd (patch)
treeb8fe855a3cd86841b16fba630dc7748d59a505fa /src/Mobs/Monster.cpp
parentAll mobs now drown (fixes #54) (diff)
downloadcuberite-314fc3cdac702a44a257ada5fab52f0a7d37ffcd.tar
cuberite-314fc3cdac702a44a257ada5fab52f0a7d37ffcd.tar.gz
cuberite-314fc3cdac702a44a257ada5fab52f0a7d37ffcd.tar.bz2
cuberite-314fc3cdac702a44a257ada5fab52f0a7d37ffcd.tar.lz
cuberite-314fc3cdac702a44a257ada5fab52f0a7d37ffcd.tar.xz
cuberite-314fc3cdac702a44a257ada5fab52f0a7d37ffcd.tar.zst
cuberite-314fc3cdac702a44a257ada5fab52f0a7d37ffcd.zip
Diffstat (limited to 'src/Mobs/Monster.cpp')
-rw-r--r--src/Mobs/Monster.cpp49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 1db16ab71..9ba18f4d1 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -259,6 +259,17 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
if (m_bMovingToDestination)
{
+ if (m_bOnGround)
+ {
+ int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z);
+
+ if (DoesPosYRequireJump(NextHeight))
+ {
+ m_bOnGround = false;
+ AddPosY(1.5); // Jump!!
+ }
+ }
+
Vector3f Distance = m_Destination - GetPosition();
if(!ReachedDestination() && !ReachedFinalDestination()) // If we haven't reached any sort of destination, move
{
@@ -285,17 +296,6 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
TickPathFinding(); // We have reached the next point in our path, calculate another point
}
}
-
- if(m_bOnGround)
- {
- int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z);
-
- if (IsNextYPosReachable(NextHeight))
- {
- m_bOnGround = false;
- SetSpeedY(5.f); // Jump!!
- }
- }
}
if (ReachedFinalDestination())
@@ -373,6 +373,11 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
{
int PosY = (int)floor(GetPosY());
+ if (PosY < 0)
+ PosY = 0;
+ else if (PosY > cChunkDef::Height)
+ PosY = cChunkDef::Height;
+
if (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))])
{
while (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY > 0))
@@ -494,7 +499,7 @@ void cMonster::KilledBy(cEntity * a_Killer)
void cMonster::CheckEventSeePlayer(void)
{
// TODO: Rewrite this to use cWorld's DoWithPlayers()
- cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
+ cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance, false);
if (Closest != NULL)
{
@@ -548,6 +553,11 @@ void cMonster::EventLosePlayer(void)
void cMonster::InStateIdle(float a_Dt)
{
+ if (m_bMovingToDestination)
+ {
+ return; // Still getting there
+ }
+
m_IdleInterval += a_Dt;
if (m_IdleInterval > 1)
@@ -557,20 +567,19 @@ void cMonster::InStateIdle(float a_Dt)
m_IdleInterval -= 1; // So nothing gets dropped when the server hangs for a few seconds
Vector3d Dist;
- Dist.x = (double)m_World->GetTickRandomNumber(m_SightDistance * 2) - m_SightDistance;
- Dist.z = (double)m_World->GetTickRandomNumber(m_SightDistance * 2) - m_SightDistance;
+ Dist.x = (double)m_World->GetTickRandomNumber(10) - 5;
+ Dist.z = (double)m_World->GetTickRandomNumber(10) - 5;
if ((Dist.SqrLength() > 2) && (rem >= 3))
{
- m_Destination.x = GetPosX() + Dist.x;
- m_Destination.z = GetPosZ() + Dist.z;
+ Vector3d Destination(GetPosX() + Dist.x, 0, GetPosZ() + Dist.z);
- int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z);
+ int NextHeight = FindFirstNonAirBlockPosition(Destination.x, Destination.z);
- if (IsNextYPosReachable(NextHeight + 1))
+ if (IsNextYPosReachable(NextHeight))
{
- m_Destination.y = (double)NextHeight;
- MoveToPosition(m_Destination);
+ Destination.y = NextHeight;
+ MoveToPosition(Destination);
}
}
}