diff options
author | Mattes D <github@xoft.cz> | 2014-04-26 23:26:59 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-04-26 23:26:59 +0200 |
commit | da931da6037279826a52980f9335e189c370d4d2 (patch) | |
tree | 2935aeea2eab9d1ce7dbf571087d905a4681fae3 /src/Mobs | |
parent | Merge pull request #863 from mc-server/chunkysparsing (diff) | |
parent | More small fixes. (diff) | |
download | cuberite-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 '')
-rw-r--r-- | src/Mobs/AggressiveMonster.cpp | 17 | ||||
-rw-r--r-- | src/Mobs/AggressiveMonster.h | 4 | ||||
-rw-r--r-- | src/Mobs/Monster.cpp | 22 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 3 |
4 files changed, 37 insertions, 9 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; +} 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/Monster.cpp b/src/Mobs/Monster.cpp index eb8480268..14d951393 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -761,8 +761,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; @@ -773,17 +775,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; } @@ -794,10 +799,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; @@ -866,6 +873,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 70b3783fc..6b9c4fab8 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 |