summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs')
-rw-r--r--src/Mobs/AggressiveMonster.cpp17
-rw-r--r--src/Mobs/AggressiveMonster.h4
-rw-r--r--src/Mobs/Blaze.cpp1
-rw-r--r--src/Mobs/Ghast.cpp1
-rw-r--r--src/Mobs/Monster.cpp22
-rw-r--r--src/Mobs/Monster.h3
-rw-r--r--src/Mobs/Skeleton.cpp1
7 files changed, 40 insertions, 9 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 0901f85a9..447bf3549 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()
+{
+ static const float epsilon = 0.000000000001f;
+ // 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((float)m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon)
+ {
+ return false;
+ }
+ return true;
+}
diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h
index 152260f95..d70ff04a3 100644
--- a/src/Mobs/AggressiveMonster.h
+++ b/src/Mobs/AggressiveMonster.h
@@ -22,6 +22,10 @@ public:
virtual void EventSeePlayer(cEntity *) override;
virtual void Attack(float a_Dt);
+protected:
+ /** Whether this mob's destination is the same as its target's position. */
+ bool IsMovingToTargetPosition();
+
} ;
diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp
index 84ff8929b..326b42f07 100644
--- a/src/Mobs/Blaze.cpp
+++ b/src/Mobs/Blaze.cpp
@@ -3,6 +3,7 @@
#include "Blaze.h"
#include "../World.h"
+#include "../Entities/FireChargeEntity.h"
diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp
index fe18f5e76..d8a7663f8 100644
--- a/src/Mobs/Ghast.cpp
+++ b/src/Mobs/Ghast.cpp
@@ -3,6 +3,7 @@
#include "Ghast.h"
#include "../World.h"
+#include "../Entities/GhastFireballEntity.h"
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 9e4c2ba25..c66ab4e04 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -765,8 +765,10 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type)
case mtChicken: return mfPassive;
case mtCow: return mfPassive;
case mtCreeper: return mfHostile;
+ case mtEnderDragon: return mfNoSpawn;
case mtEnderman: return mfHostile;
case mtGhast: return mfHostile;
+ case mtGiant: return mfNoSpawn;
case mtHorse: return mfPassive;
case mtIronGolem: return mfPassive;
case mtMagmaCube: return mfHostile;
@@ -777,17 +779,20 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type)
case mtSilverfish: return mfHostile;
case mtSkeleton: return mfHostile;
case mtSlime: return mfHostile;
+ case mtSnowGolem: return mfNoSpawn;
case mtSpider: return mfHostile;
case mtSquid: return mfWater;
case mtVillager: return mfPassive;
case mtWitch: return mfHostile;
- case mtWither: return mfHostile;
+ case mtWither: return mfNoSpawn;
case mtWolf: return mfHostile;
case mtZombie: return mfHostile;
case mtZombiePigman: return mfHostile;
- } ;
+
+ case mtInvalidType: break;
+ }
ASSERT(!"Unhandled mob type");
- return mfMaxplusone;
+ return mfUnhandled;
}
@@ -798,10 +803,12 @@ int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily)
{
switch (a_MobFamily)
{
- case mfHostile: return 40;
- case mfPassive: return 40;
- case mfAmbient: return 40;
- case mfWater: return 400;
+ case mfHostile: return 40;
+ case mfPassive: return 40;
+ case mfAmbient: return 40;
+ case mfWater: return 400;
+ case mfNoSpawn: return -1;
+ case mfUnhandled: break;
}
ASSERT(!"Unhandled mob family");
return -1;
@@ -870,6 +877,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType)
case mtEnderDragon: toReturn = new cEnderDragon(); break;
case mtEnderman: toReturn = new cEnderman(); break;
case mtGhast: toReturn = new cGhast(); break;
+ case mtGiant: toReturn = new cGiant(); break;
case mtIronGolem: toReturn = new cIronGolem(); break;
case mtMooshroom: toReturn = new cMooshroom(); break;
case mtOcelot: toReturn = new cOcelot(); break;
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 5a925dfc6..7d7e90eb2 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -66,7 +66,8 @@ public:
mfAmbient = 2, // Bats
mfWater = 3, // Squid
- mfMaxplusone, // Nothing. Be sure this is the last and the others are in order
+ mfNoSpawn,
+ mfUnhandled, // Nothing. Be sure this is the last and the others are in order
} ;
// tolua_end
diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp
index 1685f40c5..1e62d7987 100644
--- a/src/Mobs/Skeleton.cpp
+++ b/src/Mobs/Skeleton.cpp
@@ -3,6 +3,7 @@
#include "Skeleton.h"
#include "../World.h"
+#include "../Entities/ArrowEntity.h"