summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Mobs/AggressiveMonster.cpp (renamed from source/Mobs/AggressiveMonster.cpp)0
-rw-r--r--src/Mobs/AggressiveMonster.h (renamed from source/Mobs/AggressiveMonster.h)0
-rw-r--r--src/Mobs/Bat.cpp (renamed from source/Mobs/Bat.cpp)0
-rw-r--r--src/Mobs/Bat.h (renamed from source/Mobs/Bat.h)0
-rw-r--r--src/Mobs/Blaze.cpp (renamed from source/Mobs/Blaze.cpp)0
-rw-r--r--src/Mobs/Blaze.h (renamed from source/Mobs/Blaze.h)0
-rw-r--r--src/Mobs/Cavespider.cpp (renamed from source/Mobs/Cavespider.cpp)0
-rw-r--r--src/Mobs/Cavespider.h (renamed from source/Mobs/Cavespider.h)0
-rw-r--r--src/Mobs/Chicken.cpp (renamed from source/Mobs/Chicken.cpp)0
-rw-r--r--src/Mobs/Chicken.h (renamed from source/Mobs/Chicken.h)0
-rw-r--r--src/Mobs/Cow.cpp (renamed from source/Mobs/Cow.cpp)0
-rw-r--r--src/Mobs/Cow.h (renamed from source/Mobs/Cow.h)0
-rw-r--r--src/Mobs/Creeper.cpp (renamed from source/Mobs/Creeper.cpp)0
-rw-r--r--src/Mobs/Creeper.h (renamed from source/Mobs/Creeper.h)0
-rw-r--r--src/Mobs/EnderDragon.cpp (renamed from source/Mobs/EnderDragon.cpp)0
-rw-r--r--src/Mobs/EnderDragon.h (renamed from source/Mobs/EnderDragon.h)0
-rw-r--r--src/Mobs/Enderman.cpp (renamed from source/Mobs/Enderman.cpp)0
-rw-r--r--src/Mobs/Enderman.h (renamed from source/Mobs/Enderman.h)0
-rw-r--r--src/Mobs/Ghast.cpp (renamed from source/Mobs/Ghast.cpp)0
-rw-r--r--src/Mobs/Ghast.h (renamed from source/Mobs/Ghast.h)0
-rw-r--r--src/Mobs/Giant.cpp (renamed from source/Mobs/Giant.cpp)0
-rw-r--r--src/Mobs/Giant.h (renamed from source/Mobs/Giant.h)0
-rw-r--r--src/Mobs/Horse.cpp (renamed from source/Mobs/Horse.cpp)0
-rw-r--r--src/Mobs/Horse.h (renamed from source/Mobs/Horse.h)0
-rw-r--r--src/Mobs/IncludeAllMonsters.h (renamed from source/Mobs/IncludeAllMonsters.h)0
-rw-r--r--src/Mobs/IronGolem.cpp (renamed from source/Mobs/IronGolem.cpp)0
-rw-r--r--src/Mobs/IronGolem.h (renamed from source/Mobs/IronGolem.h)0
-rw-r--r--src/Mobs/Magmacube.cpp (renamed from source/Mobs/Magmacube.cpp)0
-rw-r--r--src/Mobs/Magmacube.h (renamed from source/Mobs/Magmacube.h)0
-rw-r--r--src/Mobs/Monster.cpp813
-rw-r--r--src/Mobs/Monster.h (renamed from source/Mobs/Monster.h)0
-rw-r--r--src/Mobs/Mooshroom.cpp (renamed from source/Mobs/Mooshroom.cpp)0
-rw-r--r--src/Mobs/Mooshroom.h (renamed from source/Mobs/Mooshroom.h)0
-rw-r--r--src/Mobs/Ocelot.h (renamed from source/Mobs/Ocelot.h)0
-rw-r--r--src/Mobs/PassiveAggressiveMonster.cpp (renamed from source/Mobs/PassiveAggressiveMonster.cpp)0
-rw-r--r--src/Mobs/PassiveAggressiveMonster.h (renamed from source/Mobs/PassiveAggressiveMonster.h)0
-rw-r--r--src/Mobs/PassiveMonster.cpp (renamed from source/Mobs/PassiveMonster.cpp)0
-rw-r--r--src/Mobs/PassiveMonster.h (renamed from source/Mobs/PassiveMonster.h)0
-rw-r--r--src/Mobs/Pig.cpp (renamed from source/Mobs/Pig.cpp)0
-rw-r--r--src/Mobs/Pig.h (renamed from source/Mobs/Pig.h)0
-rw-r--r--src/Mobs/Sheep.cpp (renamed from source/Mobs/Sheep.cpp)0
-rw-r--r--src/Mobs/Sheep.h (renamed from source/Mobs/Sheep.h)0
-rw-r--r--src/Mobs/Silverfish.h (renamed from source/Mobs/Silverfish.h)0
-rw-r--r--src/Mobs/Skeleton.cpp (renamed from source/Mobs/Skeleton.cpp)0
-rw-r--r--src/Mobs/Skeleton.h (renamed from source/Mobs/Skeleton.h)0
-rw-r--r--src/Mobs/Slime.cpp (renamed from source/Mobs/Slime.cpp)0
-rw-r--r--src/Mobs/Slime.h (renamed from source/Mobs/Slime.h)0
-rw-r--r--src/Mobs/SnowGolem.cpp (renamed from source/Mobs/SnowGolem.cpp)0
-rw-r--r--src/Mobs/SnowGolem.h (renamed from source/Mobs/SnowGolem.h)0
-rw-r--r--src/Mobs/Spider.cpp (renamed from source/Mobs/Spider.cpp)0
-rw-r--r--src/Mobs/Spider.h (renamed from source/Mobs/Spider.h)0
-rw-r--r--src/Mobs/Squid.cpp (renamed from source/Mobs/Squid.cpp)0
-rw-r--r--src/Mobs/Squid.h (renamed from source/Mobs/Squid.h)0
-rw-r--r--src/Mobs/Villager.cpp (renamed from source/Mobs/Villager.cpp)0
-rw-r--r--src/Mobs/Villager.h (renamed from source/Mobs/Villager.h)0
-rw-r--r--src/Mobs/Witch.cpp (renamed from source/Mobs/Witch.cpp)0
-rw-r--r--src/Mobs/Witch.h (renamed from source/Mobs/Witch.h)0
-rw-r--r--src/Mobs/Wither.cpp (renamed from source/Mobs/Wither.cpp)0
-rw-r--r--src/Mobs/Wither.h (renamed from source/Mobs/Wither.h)0
-rw-r--r--src/Mobs/Wolf.cpp (renamed from source/Mobs/Wolf.cpp)0
-rw-r--r--src/Mobs/Wolf.h (renamed from source/Mobs/Wolf.h)0
-rw-r--r--src/Mobs/Zombie.cpp (renamed from source/Mobs/Zombie.cpp)0
-rw-r--r--src/Mobs/Zombie.h (renamed from source/Mobs/Zombie.h)0
-rw-r--r--src/Mobs/Zombiepigman.cpp (renamed from source/Mobs/Zombiepigman.cpp)0
-rw-r--r--src/Mobs/Zombiepigman.h (renamed from source/Mobs/Zombiepigman.h)0
65 files changed, 813 insertions, 0 deletions
diff --git a/source/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index cc7e7da2b..cc7e7da2b 100644
--- a/source/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
diff --git a/source/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h
index 5a0d93f3d..5a0d93f3d 100644
--- a/source/Mobs/AggressiveMonster.h
+++ b/src/Mobs/AggressiveMonster.h
diff --git a/source/Mobs/Bat.cpp b/src/Mobs/Bat.cpp
index b9c82996b..b9c82996b 100644
--- a/source/Mobs/Bat.cpp
+++ b/src/Mobs/Bat.cpp
diff --git a/source/Mobs/Bat.h b/src/Mobs/Bat.h
index e878d0ee8..e878d0ee8 100644
--- a/source/Mobs/Bat.h
+++ b/src/Mobs/Bat.h
diff --git a/source/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp
index f9c05b17a..f9c05b17a 100644
--- a/source/Mobs/Blaze.cpp
+++ b/src/Mobs/Blaze.cpp
diff --git a/source/Mobs/Blaze.h b/src/Mobs/Blaze.h
index cdb3a1306..cdb3a1306 100644
--- a/source/Mobs/Blaze.h
+++ b/src/Mobs/Blaze.h
diff --git a/source/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp
index aba1ff9f5..aba1ff9f5 100644
--- a/source/Mobs/Cavespider.cpp
+++ b/src/Mobs/Cavespider.cpp
diff --git a/source/Mobs/Cavespider.h b/src/Mobs/Cavespider.h
index 10ea03f7b..10ea03f7b 100644
--- a/source/Mobs/Cavespider.h
+++ b/src/Mobs/Cavespider.h
diff --git a/source/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp
index 087fd088a..087fd088a 100644
--- a/source/Mobs/Chicken.cpp
+++ b/src/Mobs/Chicken.cpp
diff --git a/source/Mobs/Chicken.h b/src/Mobs/Chicken.h
index 979c4d8a0..979c4d8a0 100644
--- a/source/Mobs/Chicken.h
+++ b/src/Mobs/Chicken.h
diff --git a/source/Mobs/Cow.cpp b/src/Mobs/Cow.cpp
index 9eb74dac2..9eb74dac2 100644
--- a/source/Mobs/Cow.cpp
+++ b/src/Mobs/Cow.cpp
diff --git a/source/Mobs/Cow.h b/src/Mobs/Cow.h
index 0391d4a31..0391d4a31 100644
--- a/source/Mobs/Cow.h
+++ b/src/Mobs/Cow.h
diff --git a/source/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp
index 4e11ae13e..4e11ae13e 100644
--- a/source/Mobs/Creeper.cpp
+++ b/src/Mobs/Creeper.cpp
diff --git a/source/Mobs/Creeper.h b/src/Mobs/Creeper.h
index c3d4edeae..c3d4edeae 100644
--- a/source/Mobs/Creeper.h
+++ b/src/Mobs/Creeper.h
diff --git a/source/Mobs/EnderDragon.cpp b/src/Mobs/EnderDragon.cpp
index acd81cde1..acd81cde1 100644
--- a/source/Mobs/EnderDragon.cpp
+++ b/src/Mobs/EnderDragon.cpp
diff --git a/source/Mobs/EnderDragon.h b/src/Mobs/EnderDragon.h
index 77177edfe..77177edfe 100644
--- a/source/Mobs/EnderDragon.h
+++ b/src/Mobs/EnderDragon.h
diff --git a/source/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index a784131e4..a784131e4 100644
--- a/source/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
diff --git a/source/Mobs/Enderman.h b/src/Mobs/Enderman.h
index 32e40e70b..32e40e70b 100644
--- a/source/Mobs/Enderman.h
+++ b/src/Mobs/Enderman.h
diff --git a/source/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp
index 96a29b2d8..96a29b2d8 100644
--- a/source/Mobs/Ghast.cpp
+++ b/src/Mobs/Ghast.cpp
diff --git a/source/Mobs/Ghast.h b/src/Mobs/Ghast.h
index 43e8bedb6..43e8bedb6 100644
--- a/source/Mobs/Ghast.h
+++ b/src/Mobs/Ghast.h
diff --git a/source/Mobs/Giant.cpp b/src/Mobs/Giant.cpp
index bbcad46f0..bbcad46f0 100644
--- a/source/Mobs/Giant.cpp
+++ b/src/Mobs/Giant.cpp
diff --git a/source/Mobs/Giant.h b/src/Mobs/Giant.h
index 356dd4352..356dd4352 100644
--- a/source/Mobs/Giant.h
+++ b/src/Mobs/Giant.h
diff --git a/source/Mobs/Horse.cpp b/src/Mobs/Horse.cpp
index bb9a4e3f6..bb9a4e3f6 100644
--- a/source/Mobs/Horse.cpp
+++ b/src/Mobs/Horse.cpp
diff --git a/source/Mobs/Horse.h b/src/Mobs/Horse.h
index be0c23f9b..be0c23f9b 100644
--- a/source/Mobs/Horse.h
+++ b/src/Mobs/Horse.h
diff --git a/source/Mobs/IncludeAllMonsters.h b/src/Mobs/IncludeAllMonsters.h
index 1b436a11f..1b436a11f 100644
--- a/source/Mobs/IncludeAllMonsters.h
+++ b/src/Mobs/IncludeAllMonsters.h
diff --git a/source/Mobs/IronGolem.cpp b/src/Mobs/IronGolem.cpp
index 47c961098..47c961098 100644
--- a/source/Mobs/IronGolem.cpp
+++ b/src/Mobs/IronGolem.cpp
diff --git a/source/Mobs/IronGolem.h b/src/Mobs/IronGolem.h
index d49ff4cab..d49ff4cab 100644
--- a/source/Mobs/IronGolem.h
+++ b/src/Mobs/IronGolem.h
diff --git a/source/Mobs/Magmacube.cpp b/src/Mobs/Magmacube.cpp
index 86447ff6b..86447ff6b 100644
--- a/source/Mobs/Magmacube.cpp
+++ b/src/Mobs/Magmacube.cpp
diff --git a/source/Mobs/Magmacube.h b/src/Mobs/Magmacube.h
index 130952970..130952970 100644
--- a/source/Mobs/Magmacube.h
+++ b/src/Mobs/Magmacube.h
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
new file mode 100644
index 000000000..091623c8a
--- /dev/null
+++ b/src/Mobs/Monster.cpp
@@ -0,0 +1,813 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "IncludeAllMonsters.h"
+#include "../Root.h"
+#include "../Server.h"
+#include "../ClientHandle.h"
+#include "../World.h"
+#include "../Entities/Player.h"
+#include "../Entities/ExpOrb.h"
+#include "../Defines.h"
+#include "../MonsterConfig.h"
+#include "../MersenneTwister.h"
+
+#include "../Vector3f.h"
+#include "../Vector3i.h"
+#include "../Vector3d.h"
+#include "../Tracer.h"
+#include "../Chunk.h"
+#include "../FastRandom.h"
+
+
+
+
+
+/** Map for eType <-> string
+Needs to be alpha-sorted by the strings, because binary search is used in StringToMobType()
+The strings need to be lowercase (for more efficient comparisons in StringToMobType())
+*/
+static const struct
+{
+ cMonster::eType m_Type;
+ const char * m_lcName;
+} g_MobTypeNames[] =
+{
+ {cMonster::mtBat, "bat"},
+ {cMonster::mtBlaze, "blaze"},
+ {cMonster::mtCaveSpider, "cavespider"},
+ {cMonster::mtChicken, "chicken"},
+ {cMonster::mtCow, "cow"},
+ {cMonster::mtCreeper, "creeper"},
+ {cMonster::mtEnderman, "enderman"},
+ {cMonster::mtGhast, "ghast"},
+ {cMonster::mtHorse, "horse"},
+ {cMonster::mtMagmaCube, "magmacube"},
+ {cMonster::mtMooshroom, "mooshroom"},
+ {cMonster::mtOcelot, "ocelot"},
+ {cMonster::mtPig, "pig"},
+ {cMonster::mtSheep, "sheep"},
+ {cMonster::mtSilverfish, "silverfish"},
+ {cMonster::mtSkeleton, "skeleton"},
+ {cMonster::mtSlime, "slime"},
+ {cMonster::mtSpider, "spider"},
+ {cMonster::mtSquid, "squid"},
+ {cMonster::mtVillager, "villager"},
+ {cMonster::mtWitch, "witch"},
+ {cMonster::mtWolf, "wolf"},
+ {cMonster::mtZombie, "zombie"},
+ {cMonster::mtZombiePigman, "zombiepigman"},
+} ;
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cMonster:
+
+cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height)
+ : super(etMonster, a_Width, a_Height)
+ , m_Target(NULL)
+ , m_AttackRate(3)
+ , idle_interval(0)
+ , m_bMovingToDestination(false)
+ , m_DestinationTime( 0 )
+ , m_DestroyTimer( 0 )
+ , m_Jump(0)
+ , m_MobType(a_MobType)
+ , m_SoundHurt(a_SoundHurt)
+ , m_SoundDeath(a_SoundDeath)
+ , m_EMState(IDLE)
+ , m_SightDistance(25)
+ , m_SeePlayerInterval (0)
+ , m_EMPersonality(AGGRESSIVE)
+ , m_AttackDamage(1.0f)
+ , m_AttackRange(2.0f)
+ , m_AttackInterval(0)
+ , m_BurnsInDaylight(false)
+{
+ if (!a_ConfigName.empty())
+ {
+ GetMonsterConfig(a_ConfigName);
+ }
+}
+
+
+
+
+
+void cMonster::SpawnOn(cClientHandle & a_Client)
+{
+ a_Client.SendSpawnMob(*this);
+}
+
+
+
+
+
+void cMonster::MoveToPosition( const Vector3f & a_Position )
+{
+ m_bMovingToDestination = true;
+
+ m_Destination = a_Position;
+}
+
+
+
+
+
+bool cMonster::ReachedDestination()
+{
+ Vector3f Distance = (m_Destination) - GetPosition();
+ if( Distance.SqrLength() < 2.f )
+ return true;
+
+ return false;
+}
+
+
+
+
+
+void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ super::Tick(a_Dt, a_Chunk);
+
+ if (m_Health <= 0)
+ {
+ // The mob is dead, but we're still animating the "puff" they leave when they die
+ m_DestroyTimer += a_Dt / 1000;
+ if (m_DestroyTimer > 1)
+ {
+ Destroy(true);
+ }
+ return;
+ }
+
+ // Burning in daylight
+ HandleDaylightBurning(a_Chunk);
+
+ HandlePhysics(a_Dt,a_Chunk);
+ BroadcastMovementUpdate();
+
+ a_Dt /= 1000;
+
+ if (m_bMovingToDestination)
+ {
+ Vector3f Pos( GetPosition() );
+ Vector3f Distance = m_Destination - Pos;
+ if( !ReachedDestination() )
+ {
+ Distance.y = 0;
+ Distance.Normalize();
+ Distance *= 3;
+ SetSpeedX( Distance.x );
+ SetSpeedZ( Distance.z );
+
+ if (m_EMState == ESCAPING)
+ { //Runs Faster when escaping :D otherwise they just walk away
+ SetSpeedX (GetSpeedX() * 2.f);
+ SetSpeedZ (GetSpeedZ() * 2.f);
+ }
+ }
+ else
+ {
+ m_bMovingToDestination = false;
+ }
+
+ if( GetSpeed().SqrLength() > 0.f )
+ {
+ if( m_bOnGround )
+ {
+ Vector3f NormSpeed = Vector3f(GetSpeed()).NormalizeCopy();
+ Vector3f NextBlock = Vector3f( GetPosition() ) + NormSpeed;
+ int NextHeight;
+ if (!m_World->TryGetHeight((int)NextBlock.x, (int)NextBlock.z, NextHeight))
+ {
+ // The chunk at NextBlock is not loaded
+ return;
+ }
+ if( NextHeight > (GetPosY() - 1.0) && (NextHeight - GetPosY()) < 2.5 )
+ {
+ m_bOnGround = false;
+ SetSpeedY(5.f); // Jump!!
+ }
+ }
+ }
+ }
+
+ Vector3d Distance = m_Destination - GetPosition();
+ if (Distance.SqrLength() > 0.1f)
+ {
+ double Rotation, Pitch;
+ Distance.Normalize();
+ VectorToEuler( Distance.x, Distance.y, Distance.z, Rotation, Pitch );
+ SetHeadYaw (Rotation);
+ SetRotation( Rotation );
+ SetPitch( -Pitch );
+ }
+
+ switch (m_EMState)
+ {
+ case IDLE:
+ {
+ // If enemy passive we ignore checks for player visibility
+ InStateIdle(a_Dt);
+ break;
+ }
+
+ case CHASING:
+ {
+ // If we do not see a player anymore skip chasing action
+ InStateChasing(a_Dt);
+ break;
+ }
+
+ case ESCAPING:
+ {
+ InStateEscaping(a_Dt);
+ break;
+ }
+ } // switch (m_EMState)
+}
+
+
+
+
+
+
+void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
+{
+ super::DoTakeDamage(a_TDI);
+ if((m_SoundHurt != "") && (m_Health > 0)) m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
+ if (a_TDI.Attacker != NULL)
+ {
+ m_Target = a_TDI.Attacker;
+ AddReference(m_Target);
+ }
+}
+
+
+
+
+
+void cMonster::KilledBy(cEntity * a_Killer)
+{
+ super::KilledBy(a_Killer);
+ if (m_SoundHurt != "")
+ {
+ m_World->BroadcastSoundEffect(m_SoundDeath, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
+ }
+ int Reward;
+ switch (m_MobType)
+ {
+ // Animals
+ case cMonster::mtChicken:
+ case cMonster::mtCow:
+ case cMonster::mtHorse:
+ case cMonster::mtPig:
+ case cMonster::mtSheep:
+ case cMonster::mtSquid:
+ case cMonster::mtMooshroom:
+ case cMonster::mtOcelot:
+ case cMonster::mtWolf:
+ {
+ Reward = m_World->GetTickRandomNumber(2) + 1;
+ }
+
+ // Monsters
+ case cMonster::mtCaveSpider:
+ case cMonster::mtCreeper:
+ case cMonster::mtEnderman:
+ case cMonster::mtGhast:
+ case cMonster::mtSilverfish:
+ case cMonster::mtSkeleton:
+ case cMonster::mtSpider:
+ case cMonster::mtWitch:
+ case cMonster::mtZombie:
+ case cMonster::mtZombiePigman:
+ case cMonster::mtSlime:
+ case cMonster::mtMagmaCube:
+ {
+ Reward = 6 + (m_World->GetTickRandomNumber(2));
+ }
+ case cMonster::mtBlaze:
+ {
+ Reward = 10;
+ }
+
+ // Bosses
+ case cMonster::mtEnderDragon:
+ {
+ Reward = 12000;
+ }
+ case cMonster::mtWither:
+ {
+ Reward = 50;
+ }
+
+ default:
+ {
+ Reward = 0;
+ }
+ }
+ m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward);
+ m_DestroyTimer = 0;
+}
+
+
+
+
+
+//----State Logic
+
+const char *cMonster::GetState()
+{
+ switch(m_EMState)
+ {
+ case IDLE: return "Idle";
+ case ATTACKING: return "Attacking";
+ case CHASING: return "Chasing";
+ default: return "Unknown";
+ }
+}
+
+
+
+
+
+// for debugging
+void cMonster::SetState(const AString & a_State)
+{
+ if (a_State.compare("Idle") == 0)
+ {
+ m_EMState = IDLE;
+ }
+ else if (a_State.compare("Attacking") == 0)
+ {
+ m_EMState = ATTACKING;
+ }
+ else if (a_State.compare("Chasing") == 0)
+ {
+ m_EMState = CHASING;
+ }
+ else
+ {
+ LOGD("cMonster::SetState(): Invalid state");
+ ASSERT(!"Invalid state");
+ }
+}
+
+
+
+
+
+//Checks to see if EventSeePlayer should be fired
+//monster sez: Do I see the player
+void cMonster::CheckEventSeePlayer(void)
+{
+ // TODO: Rewrite this to use cWorld's DoWithPlayers()
+ cPlayer * Closest = FindClosestPlayer();
+
+ if (Closest != NULL)
+ {
+ EventSeePlayer(Closest);
+ }
+}
+
+
+
+
+
+void cMonster::CheckEventLostPlayer(void)
+{
+ Vector3f pos;
+ cTracer LineOfSight(GetWorld());
+
+ if (m_Target != NULL)
+ {
+ pos = m_Target->GetPosition();
+ if ((pos - GetPosition()).Length() > m_SightDistance || LineOfSight.Trace(GetPosition(),(pos - GetPosition()), (int)(pos - GetPosition()).Length()))
+ {
+ EventLosePlayer();
+ }
+ }
+ else
+ {
+ EventLosePlayer();
+ }
+}
+
+
+
+
+
+// What to do if player is seen
+// default to change state to chasing
+void cMonster::EventSeePlayer(cEntity * a_SeenPlayer)
+{
+ m_Target = a_SeenPlayer;
+ AddReference(m_Target);
+}
+
+
+
+
+
+void cMonster::EventLosePlayer(void)
+{
+ Dereference(m_Target);
+ m_Target = NULL;
+ m_EMState = IDLE;
+}
+
+
+
+
+
+// What to do if in Idle State
+void cMonster::InStateIdle(float a_Dt)
+{
+ idle_interval += a_Dt;
+ if (idle_interval > 1)
+ {
+ // at this interval the results are predictable
+ int rem = m_World->GetTickRandomNumber(6) + 1;
+ // LOGD("Moving: int: %3.3f rem: %i",idle_interval,rem);
+ idle_interval -= 1; // So nothing gets dropped when the server hangs for a few seconds
+ Vector3f Dist;
+ Dist.x = (float)(m_World->GetTickRandomNumber(10) - 5);
+ Dist.z = (float)(m_World->GetTickRandomNumber(10) - 5);
+ if ((Dist.SqrLength() > 2) && (rem >= 3))
+ {
+ m_Destination.x = (float)(GetPosX() + Dist.x);
+ m_Destination.z = (float)(GetPosZ() + Dist.z);
+ int PosY;
+ if (m_World->TryGetHeight((int)m_Destination.x, (int)m_Destination.z, PosY))
+ {
+ m_Destination.y = (float)PosY + 1.2f;
+ MoveToPosition(m_Destination);
+ }
+ }
+ }
+}
+
+
+
+
+
+// What to do if in Chasing State
+// This state should always be defined in each child class
+void cMonster::InStateChasing(float a_Dt)
+{
+ UNUSED(a_Dt);
+}
+
+
+
+
+
+// What to do if in Escaping State
+void cMonster::InStateEscaping(float a_Dt)
+{
+ UNUSED(a_Dt);
+
+ if (m_Target != NULL)
+ {
+ Vector3d newloc = GetPosition();
+ newloc.x = (m_Target->GetPosition().x < newloc.x)? (newloc.x + m_SightDistance): (newloc.x - m_SightDistance);
+ newloc.z = (m_Target->GetPosition().z < newloc.z)? (newloc.z + m_SightDistance): (newloc.z - m_SightDistance);
+ MoveToPosition(newloc);
+ }
+ else
+ {
+ m_EMState = IDLE; // This shouldnt be required but just to be safe
+ }
+}
+
+
+
+
+
+// Do attack here
+// a_Dt is passed so we can set attack rate
+void cMonster::Attack(float a_Dt)
+{
+ m_AttackInterval += a_Dt * m_AttackRate;
+ if ((m_Target != NULL) && (m_AttackInterval > 3.0))
+ {
+ // Setting this higher gives us more wiggle room for attackrate
+ m_AttackInterval = 0.0;
+ ((cPawn *)m_Target)->TakeDamage(*this);
+ }
+}
+
+
+
+
+
+// Checks for Players close by and if they are visible return the closest
+cPlayer * cMonster::FindClosestPlayer(void)
+{
+ return m_World->FindClosestPlayer(GetPosition(), m_SightDistance);
+}
+
+
+
+
+
+void cMonster::GetMonsterConfig(const AString & a_Name)
+{
+ cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name);
+}
+
+
+
+
+
+void cMonster::SetAttackRate(int ar)
+{
+ m_AttackRate = (float)ar;
+}
+
+
+
+
+
+void cMonster::SetAttackRange(float ar)
+{
+ m_AttackRange = ar;
+}
+
+
+
+
+
+void cMonster::SetAttackDamage(float ad)
+{
+ m_AttackDamage = ad;
+}
+
+
+
+
+
+void cMonster::SetSightDistance(float sd)
+{
+ m_SightDistance = sd;
+}
+
+
+
+
+
+AString cMonster::MobTypeToString(cMonster::eType a_MobType)
+{
+ // Mob types aren't sorted, so we need to search linearly:
+ for (int i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
+ {
+ if (g_MobTypeNames[i].m_Type == a_MobType)
+ {
+ return g_MobTypeNames[i].m_lcName;
+ }
+ }
+
+ // Not found:
+ return "";
+}
+
+
+
+
+
+cMonster::eType cMonster::StringToMobType(const AString & a_Name)
+{
+ AString lcName(a_Name);
+ StrToLower(lcName);
+
+ // Binary-search for the lowercase name:
+ int lo = 0, hi = ARRAYCOUNT(g_MobTypeNames) - 1;
+ while (hi - lo > 1)
+ {
+ int mid = (lo + hi) / 2;
+ int res = strcmp(g_MobTypeNames[mid].m_lcName, lcName.c_str());
+ if (res == 0)
+ {
+ return g_MobTypeNames[mid].m_Type;
+ }
+ if (res < 0)
+ {
+ lo = mid;
+ }
+ else
+ {
+ hi = mid;
+ }
+ }
+ // Range has collapsed to at most two elements, compare each:
+ if (strcmp(g_MobTypeNames[lo].m_lcName, lcName.c_str()) == 0)
+ {
+ return g_MobTypeNames[lo].m_Type;
+ }
+ if ((lo != hi) && (strcmp(g_MobTypeNames[hi].m_lcName, lcName.c_str()) == 0))
+ {
+ return g_MobTypeNames[hi].m_Type;
+ }
+
+ // Not found:
+ return mtInvalidType;
+}
+
+
+
+
+
+cMonster::eFamily cMonster::FamilyFromType(eType a_Type)
+{
+ switch (a_Type)
+ {
+ case mtBat: return mfAmbient;
+ case mtBlaze: return mfHostile;
+ case mtCaveSpider: return mfHostile;
+ case mtChicken: return mfPassive;
+ case mtCow: return mfPassive;
+ case mtCreeper: return mfHostile;
+ case mtEnderman: return mfHostile;
+ case mtGhast: return mfHostile;
+ case mtHorse: return mfPassive;
+ case mtMagmaCube: return mfHostile;
+ case mtMooshroom: return mfHostile;
+ case mtOcelot: return mfHostile;
+ case mtPig: return mfPassive;
+ case mtSheep: return mfPassive;
+ case mtSilverfish: return mfHostile;
+ case mtSkeleton: return mfHostile;
+ case mtSlime: return mfHostile;
+ case mtSpider: return mfHostile;
+ case mtSquid: return mfWater;
+ case mtVillager: return mfPassive;
+ case mtWitch: return mfHostile;
+ case mtWolf: return mfHostile;
+ case mtZombie: return mfHostile;
+ case mtZombiePigman: return mfHostile;
+ } ;
+ ASSERT(!"Unhandled mob type");
+ return mfMaxplusone;
+}
+
+
+
+
+
+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;
+ }
+ ASSERT(!"Unhandled mob family");
+ return -1;
+}
+
+
+
+
+
+cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType)
+{
+ cFastRandom Random;
+ cMonster * toReturn = NULL;
+
+ // Create the mob entity
+ switch (a_MobType)
+ {
+ case mtMagmaCube:
+ case mtSlime:
+ {
+ toReturn = new cSlime (Random.NextInt(2) + 1);
+ break;
+ }
+ case mtSkeleton:
+ {
+ // TODO: Actual detection of spawning in Nether
+ toReturn = new cSkeleton(Random.NextInt(1) == 0 ? false : true);
+ break;
+ }
+ case mtVillager:
+ {
+ int VillagerType = Random.NextInt(6);
+ if (VillagerType == 6)
+ {
+ // Give farmers a better chance of spawning
+ VillagerType = 0;
+ }
+
+ toReturn = new cVillager((cVillager::eVillagerType)VillagerType);
+ break;
+ }
+ case mtHorse:
+ {
+ // Horses take a type (species), a colour, and a style (dots, stripes, etc.)
+ int HorseType = Random.NextInt(7);
+ int HorseColor = Random.NextInt(6);
+ int HorseStyle = Random.NextInt(6);
+ int HorseTameTimes = Random.NextInt(6) + 1;
+
+ if ((HorseType == 5) || (HorseType == 6) || (HorseType == 7))
+ {
+ // Increase chances of normal horse (zero)
+ HorseType = 0;
+ }
+
+ toReturn = new cHorse(HorseType, HorseColor, HorseStyle, HorseTameTimes);
+ break;
+ }
+
+ case mtBat: toReturn = new cBat(); break;
+ case mtBlaze: toReturn = new cBlaze(); break;
+ case mtCaveSpider: toReturn = new cCavespider(); break;
+ case mtChicken: toReturn = new cChicken(); break;
+ case mtCow: toReturn = new cCow(); break;
+ case mtCreeper: toReturn = new cCreeper(); break;
+ case mtEnderman: toReturn = new cEnderman(); break;
+ case mtGhast: toReturn = new cGhast(); break;
+ case mtMooshroom: toReturn = new cMooshroom(); break;
+ case mtOcelot: toReturn = new cOcelot(); break;
+ case mtPig: toReturn = new cPig(); break;
+ case mtSheep: toReturn = new cSheep (Random.NextInt(15)); break; // Colour parameter
+ case mtSilverfish: toReturn = new cSilverfish(); break;
+ case mtSpider: toReturn = new cSpider(); break;
+ case mtSquid: toReturn = new cSquid(); break;
+ case mtWitch: toReturn = new cWitch(); break;
+ case mtWolf: toReturn = new cWolf(); break;
+ case mtZombie: toReturn = new cZombie(false); break; // TODO: Infected zombie parameter
+ case mtZombiePigman: toReturn = new cZombiePigman(); break;
+ default:
+ {
+ ASSERT(!"Unhandled mob type whilst trying to spawn mob!");
+ }
+ }
+ return toReturn;
+}
+
+
+
+
+
+void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth)
+{
+ MTRand r1;
+ int Count = r1.randInt() % (a_Max + 1 - a_Min) + a_Min;
+ if (Count > 0)
+ {
+ a_Drops.push_back(cItem(a_Item, Count, a_ItemHealth));
+ }
+}
+
+
+
+
+
+void cMonster::HandleDaylightBurning(cChunk & a_Chunk)
+{
+ if (!m_BurnsInDaylight)
+ {
+ return;
+ }
+
+ int RelY = (int)floor(GetPosY());
+ if ((RelY < 0) || (RelY >= cChunkDef::Height))
+ {
+ // Outside the world
+ return;
+ }
+
+ int RelX = (int)floor(GetPosX()) - GetChunkX() * cChunkDef::Width;
+ int RelZ = (int)floor(GetPosZ()) - GetChunkZ() * cChunkDef::Width;
+ if (
+ (a_Chunk.GetSkyLight(RelX, RelY, RelZ) == 15) && // In the daylight
+ (a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand
+ (GetWorld()->GetTimeOfDay() < (12000 + 1000)) && // It is nighttime
+ !IsOnFire() // Not already burning
+ )
+ {
+ // Burn for 100 ticks, then decide again
+ StartBurning(100);
+ }
+}
+
+
+
+
+cMonster::eFamily cMonster::GetMobFamily(void) const
+{
+ return FamilyFromType(m_MobType);
+}
+
+
+
+
diff --git a/source/Mobs/Monster.h b/src/Mobs/Monster.h
index 29a705d11..29a705d11 100644
--- a/source/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
diff --git a/source/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp
index 940e2db44..940e2db44 100644
--- a/source/Mobs/Mooshroom.cpp
+++ b/src/Mobs/Mooshroom.cpp
diff --git a/source/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h
index 73f6348b6..73f6348b6 100644
--- a/source/Mobs/Mooshroom.h
+++ b/src/Mobs/Mooshroom.h
diff --git a/source/Mobs/Ocelot.h b/src/Mobs/Ocelot.h
index adb7a1f75..adb7a1f75 100644
--- a/source/Mobs/Ocelot.h
+++ b/src/Mobs/Ocelot.h
diff --git a/source/Mobs/PassiveAggressiveMonster.cpp b/src/Mobs/PassiveAggressiveMonster.cpp
index 28de65905..28de65905 100644
--- a/source/Mobs/PassiveAggressiveMonster.cpp
+++ b/src/Mobs/PassiveAggressiveMonster.cpp
diff --git a/source/Mobs/PassiveAggressiveMonster.h b/src/Mobs/PassiveAggressiveMonster.h
index 2c5ef30b1..2c5ef30b1 100644
--- a/source/Mobs/PassiveAggressiveMonster.h
+++ b/src/Mobs/PassiveAggressiveMonster.h
diff --git a/source/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp
index 91ceb5a53..91ceb5a53 100644
--- a/source/Mobs/PassiveMonster.cpp
+++ b/src/Mobs/PassiveMonster.cpp
diff --git a/source/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h
index 14a6be6b1..14a6be6b1 100644
--- a/source/Mobs/PassiveMonster.h
+++ b/src/Mobs/PassiveMonster.h
diff --git a/source/Mobs/Pig.cpp b/src/Mobs/Pig.cpp
index 0871a38a9..0871a38a9 100644
--- a/source/Mobs/Pig.cpp
+++ b/src/Mobs/Pig.cpp
diff --git a/source/Mobs/Pig.h b/src/Mobs/Pig.h
index 4fd0d8db8..4fd0d8db8 100644
--- a/source/Mobs/Pig.h
+++ b/src/Mobs/Pig.h
diff --git a/source/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index bda4ccff8..bda4ccff8 100644
--- a/source/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
diff --git a/source/Mobs/Sheep.h b/src/Mobs/Sheep.h
index 8293a2c05..8293a2c05 100644
--- a/source/Mobs/Sheep.h
+++ b/src/Mobs/Sheep.h
diff --git a/source/Mobs/Silverfish.h b/src/Mobs/Silverfish.h
index a6e11c49d..a6e11c49d 100644
--- a/source/Mobs/Silverfish.h
+++ b/src/Mobs/Silverfish.h
diff --git a/source/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp
index 509c2191e..509c2191e 100644
--- a/source/Mobs/Skeleton.cpp
+++ b/src/Mobs/Skeleton.cpp
diff --git a/source/Mobs/Skeleton.h b/src/Mobs/Skeleton.h
index 8f31b42e1..8f31b42e1 100644
--- a/source/Mobs/Skeleton.h
+++ b/src/Mobs/Skeleton.h
diff --git a/source/Mobs/Slime.cpp b/src/Mobs/Slime.cpp
index 19f376c21..19f376c21 100644
--- a/source/Mobs/Slime.cpp
+++ b/src/Mobs/Slime.cpp
diff --git a/source/Mobs/Slime.h b/src/Mobs/Slime.h
index 782c3113f..782c3113f 100644
--- a/source/Mobs/Slime.h
+++ b/src/Mobs/Slime.h
diff --git a/source/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp
index 9e199f87e..9e199f87e 100644
--- a/source/Mobs/SnowGolem.cpp
+++ b/src/Mobs/SnowGolem.cpp
diff --git a/source/Mobs/SnowGolem.h b/src/Mobs/SnowGolem.h
index d1344adfd..d1344adfd 100644
--- a/source/Mobs/SnowGolem.h
+++ b/src/Mobs/SnowGolem.h
diff --git a/source/Mobs/Spider.cpp b/src/Mobs/Spider.cpp
index b19a5dcef..b19a5dcef 100644
--- a/source/Mobs/Spider.cpp
+++ b/src/Mobs/Spider.cpp
diff --git a/source/Mobs/Spider.h b/src/Mobs/Spider.h
index 51e65d028..51e65d028 100644
--- a/source/Mobs/Spider.h
+++ b/src/Mobs/Spider.h
diff --git a/source/Mobs/Squid.cpp b/src/Mobs/Squid.cpp
index a311108ae..a311108ae 100644
--- a/source/Mobs/Squid.cpp
+++ b/src/Mobs/Squid.cpp
diff --git a/source/Mobs/Squid.h b/src/Mobs/Squid.h
index ad299b95c..ad299b95c 100644
--- a/source/Mobs/Squid.h
+++ b/src/Mobs/Squid.h
diff --git a/source/Mobs/Villager.cpp b/src/Mobs/Villager.cpp
index 7f89fb6cc..7f89fb6cc 100644
--- a/source/Mobs/Villager.cpp
+++ b/src/Mobs/Villager.cpp
diff --git a/source/Mobs/Villager.h b/src/Mobs/Villager.h
index 4cd9aaa8e..4cd9aaa8e 100644
--- a/source/Mobs/Villager.h
+++ b/src/Mobs/Villager.h
diff --git a/source/Mobs/Witch.cpp b/src/Mobs/Witch.cpp
index 25d27041f..25d27041f 100644
--- a/source/Mobs/Witch.cpp
+++ b/src/Mobs/Witch.cpp
diff --git a/source/Mobs/Witch.h b/src/Mobs/Witch.h
index 4e637beea..4e637beea 100644
--- a/source/Mobs/Witch.h
+++ b/src/Mobs/Witch.h
diff --git a/source/Mobs/Wither.cpp b/src/Mobs/Wither.cpp
index c46e0beab..c46e0beab 100644
--- a/source/Mobs/Wither.cpp
+++ b/src/Mobs/Wither.cpp
diff --git a/source/Mobs/Wither.h b/src/Mobs/Wither.h
index 56effc6bb..56effc6bb 100644
--- a/source/Mobs/Wither.h
+++ b/src/Mobs/Wither.h
diff --git a/source/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp
index c86250142..c86250142 100644
--- a/source/Mobs/Wolf.cpp
+++ b/src/Mobs/Wolf.cpp
diff --git a/source/Mobs/Wolf.h b/src/Mobs/Wolf.h
index 040e2cf7a..040e2cf7a 100644
--- a/source/Mobs/Wolf.h
+++ b/src/Mobs/Wolf.h
diff --git a/source/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp
index a485d2b55..a485d2b55 100644
--- a/source/Mobs/Zombie.cpp
+++ b/src/Mobs/Zombie.cpp
diff --git a/source/Mobs/Zombie.h b/src/Mobs/Zombie.h
index 7e14fe42f..7e14fe42f 100644
--- a/source/Mobs/Zombie.h
+++ b/src/Mobs/Zombie.h
diff --git a/source/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp
index 6ac89ed4c..6ac89ed4c 100644
--- a/source/Mobs/Zombiepigman.cpp
+++ b/src/Mobs/Zombiepigman.cpp
diff --git a/source/Mobs/Zombiepigman.h b/src/Mobs/Zombiepigman.h
index 67991d56a..67991d56a 100644
--- a/source/Mobs/Zombiepigman.h
+++ b/src/Mobs/Zombiepigman.h