summaryrefslogtreecommitdiffstats
path: root/src/Mobs/AggressiveMonster.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-04-26 23:26:59 +0200
committerMattes D <github@xoft.cz>2014-04-26 23:26:59 +0200
commitda931da6037279826a52980f9335e189c370d4d2 (patch)
tree2935aeea2eab9d1ce7dbf571087d905a4681fae3 /src/Mobs/AggressiveMonster.cpp
parentMerge pull request #863 from mc-server/chunkysparsing (diff)
parentMore small fixes. (diff)
downloadcuberite-da931da6037279826a52980f9335e189c370d4d2.tar
cuberite-da931da6037279826a52980f9335e189c370d4d2.tar.gz
cuberite-da931da6037279826a52980f9335e189c370d4d2.tar.bz2
cuberite-da931da6037279826a52980f9335e189c370d4d2.tar.lz
cuberite-da931da6037279826a52980f9335e189c370d4d2.tar.xz
cuberite-da931da6037279826a52980f9335e189c370d4d2.tar.zst
cuberite-da931da6037279826a52980f9335e189c370d4d2.zip
Diffstat (limited to 'src/Mobs/AggressiveMonster.cpp')
-rw-r--r--src/Mobs/AggressiveMonster.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 0901f85a9..3e5f72dbf 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -37,7 +37,7 @@ void cAggressiveMonster::InStateChasing(float a_Dt)
}
}
- if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ()))
+ if (!IsMovingToTargetPosition())
{
MoveToPosition(m_Target->GetPosition());
}
@@ -106,3 +106,18 @@ void cAggressiveMonster::Attack(float a_Dt)
+bool cAggressiveMonster::IsMovingToTargetPosition()
+{
+ float epsilon = 0.000000000001;
+ // Difference between destination x and target x is negligible (to 10^-12 precision)
+ if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon)
+ {
+ return false;
+ }
+ // Difference between destination z and target z is negligible (to 10^-12 precision)
+ else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon)
+ {
+ return false;
+ }
+ return true;
+}