From 624deea6c4f83f296c1bd1597e76b4704ffa4a9a Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 18:11:11 -0700 Subject: Giants! Changed mfMaxplusone to mfUnhandled for readability, and fixed a default case warning. --- src/Mobs/Monster.cpp | 17 +++++++++++------ src/Mobs/Monster.h | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index eb8480268..f68d2ef75 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -763,6 +763,7 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtCreeper: return mfHostile; case mtEnderman: return mfHostile; case mtGhast: return mfHostile; + case mtGiant: return mfHostile; case mtHorse: return mfPassive; case mtIronGolem: return mfPassive; case mtMagmaCube: return mfHostile; @@ -781,9 +782,11 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) 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 +797,11 @@ 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 mfUnhandled: break; } ASSERT(!"Unhandled mob family"); return -1; @@ -866,6 +870,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..0243f6637 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -66,7 +66,7 @@ public: mfAmbient = 2, // Bats mfWater = 3, // Squid - mfMaxplusone, // Nothing. Be sure this is the last and the others are in order + mfUnhandled, // Nothing. Be sure this is the last and the others are in order } ; // tolua_end -- cgit v1.2.3 From 5ffdaa8142da27c68f467f26c4f28129865b7bf9 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 12:59:55 -0700 Subject: Moved huge conditional out of InStateChasing(), improving readability Squashed a warning. --- src/Mobs/AggressiveMonster.cpp | 17 ++++++++++++++++- src/Mobs/AggressiveMonster.h | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/Mobs') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 0901f85a9..cafa7ee74 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 negligable (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 negligable (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..c66452360 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(); + } ; -- cgit v1.2.3 From 80b97fd9dd584c439ca25efaa7e5172da1509628 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 20:49:55 -0700 Subject: Fixed mobs that don't naturally spawn. --- src/Mobs/Monster.cpp | 7 +++++-- src/Mobs/Monster.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index f68d2ef75..14d951393 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -761,9 +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 mfHostile; + case mtGiant: return mfNoSpawn; case mtHorse: return mfPassive; case mtIronGolem: return mfPassive; case mtMagmaCube: return mfHostile; @@ -774,11 +775,12 @@ 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; @@ -801,6 +803,7 @@ int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) case mfPassive: return 40; case mfAmbient: return 40; case mfWater: return 400; + case mfNoSpawn: return -1; case mfUnhandled: break; } ASSERT(!"Unhandled mob family"); diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 0243f6637..6b9c4fab8 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -66,6 +66,7 @@ public: mfAmbient = 2, // Bats mfWater = 3, // Squid + mfNoSpawn, mfUnhandled, // Nothing. Be sure this is the last and the others are in order } ; -- cgit v1.2.3 From aef2c8ec628aa2522364da1333bc5158e55ac6a2 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 09:21:49 -0700 Subject: Further refactored, Reverted Minecart change Other small changes. --- src/Mobs/AggressiveMonster.cpp | 4 ++-- src/Mobs/AggressiveMonster.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index cafa7ee74..3e5f72dbf 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -109,12 +109,12 @@ void cAggressiveMonster::Attack(float a_Dt) bool cAggressiveMonster::IsMovingToTargetPosition() { float epsilon = 0.000000000001; - //Difference between destination x and target x is negligable (to 10^-12 precision) + // 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 negligable (to 10^-12 precision) + // 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; diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index c66452360..d70ff04a3 100644 --- a/src/Mobs/AggressiveMonster.h +++ b/src/Mobs/AggressiveMonster.h @@ -23,7 +23,7 @@ public: virtual void Attack(float a_Dt); protected: - /* Whether this mob's destination is the same as its target's position. */ + /** Whether this mob's destination is the same as its target's position. */ bool IsMovingToTargetPosition(); } ; -- cgit v1.2.3