summaryrefslogtreecommitdiffstats
path: root/source/Mobs
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-12-22 11:15:53 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-12-22 11:15:53 +0100
commitb29af701b9a0b6bfbd2acaae06e32e9742fd7e78 (patch)
tree54cf35d738196786b605ddff446fca32e8a45fa7 /source/Mobs
parentReduced most mobs' constructors to oneliners by passing parameters to superclasses (diff)
downloadcuberite-b29af701b9a0b6bfbd2acaae06e32e9742fd7e78.tar
cuberite-b29af701b9a0b6bfbd2acaae06e32e9742fd7e78.tar.gz
cuberite-b29af701b9a0b6bfbd2acaae06e32e9742fd7e78.tar.bz2
cuberite-b29af701b9a0b6bfbd2acaae06e32e9742fd7e78.tar.lz
cuberite-b29af701b9a0b6bfbd2acaae06e32e9742fd7e78.tar.xz
cuberite-b29af701b9a0b6bfbd2acaae06e32e9742fd7e78.tar.zst
cuberite-b29af701b9a0b6bfbd2acaae06e32e9742fd7e78.zip
Diffstat (limited to 'source/Mobs')
-rw-r--r--source/Mobs/AggressiveMonster.cpp19
-rw-r--r--source/Mobs/AggressiveMonster.h6
-rw-r--r--source/Mobs/Cavespider.cpp4
-rw-r--r--source/Mobs/Cavespider.h2
-rw-r--r--source/Mobs/Enderman.cpp4
-rw-r--r--source/Mobs/Enderman.h2
-rw-r--r--source/Mobs/Monster.cpp96
-rw-r--r--source/Mobs/Monster.h16
-rw-r--r--source/Mobs/PassiveMonster.cpp9
-rw-r--r--source/Mobs/PassiveMonster.h2
-rw-r--r--source/Mobs/Skeleton.cpp4
-rw-r--r--source/Mobs/Skeleton.h2
-rw-r--r--source/Mobs/Squid.cpp4
-rw-r--r--source/Mobs/Squid.h2
-rw-r--r--source/Mobs/Zombie.cpp4
-rw-r--r--source/Mobs/Zombie.h2
-rw-r--r--source/Mobs/Zombiepigman.cpp4
-rw-r--r--source/Mobs/Zombiepigman.h2
18 files changed, 97 insertions, 87 deletions
diff --git a/source/Mobs/AggressiveMonster.cpp b/source/Mobs/AggressiveMonster.cpp
index f2e53ce00..14c3135be 100644
--- a/source/Mobs/AggressiveMonster.cpp
+++ b/source/Mobs/AggressiveMonster.cpp
@@ -23,9 +23,9 @@ cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, char a_Prot
// What to do if in Chasing State
-void cAggressiveMonster::InStateChasing(float a_Dt)
+void cAggressiveMonster::InStateChasing(float a_Dt, MTRand & a_TickRandom)
{
- super::InStateChasing(a_Dt);
+ super::InStateChasing(a_Dt, a_TickRandom);
m_ChaseTime += a_Dt;
if (m_Target != NULL)
{
@@ -58,9 +58,9 @@ void cAggressiveMonster::InStateChasing(float a_Dt)
-void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
+void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity, MTRand & a_TickRandom)
{
- super::EventSeePlayer(a_Entity);
+ super::EventSeePlayer(a_Entity, a_TickRandom);
m_EMState = CHASING;
}
@@ -68,27 +68,26 @@ void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
-void cAggressiveMonster::Tick(float a_Dt)
+void cAggressiveMonster::Tick(float a_Dt, MTRand & a_TickRandom)
{
- super::Tick(a_Dt);
+ super::Tick(a_Dt, a_TickRandom);
m_SeePlayerInterval += a_Dt;
if (m_SeePlayerInterval > 1)
{
- MTRand r1;
- int rem = r1.randInt() % 3 + 1; // Check most of the time but miss occasionally
+ int rem = a_TickRandom.randInt() % 3 + 1; // Check most of the time but miss occasionally
m_SeePlayerInterval = 0.0;
if (rem >= 2)
{
if (m_EMState == CHASING)
{
- CheckEventLostPlayer();
+ CheckEventLostPlayer(a_TickRandom);
}
else
{
- CheckEventSeePlayer();
+ CheckEventSeePlayer(a_TickRandom);
}
}
}
diff --git a/source/Mobs/AggressiveMonster.h b/source/Mobs/AggressiveMonster.h
index f364d535d..a9303a975 100644
--- a/source/Mobs/AggressiveMonster.h
+++ b/source/Mobs/AggressiveMonster.h
@@ -15,10 +15,10 @@ class cAggressiveMonster :
public:
cAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath);
- virtual void Tick(float a_Dt) override;
- virtual void InStateChasing(float a_Dt) override;
+ virtual void Tick (float a_Dt, MTRand & a_TickRandom) override;
+ virtual void InStateChasing(float a_Dt, MTRand & a_TickRandom) override;
- virtual void EventSeePlayer(cEntity *) override;
+ virtual void EventSeePlayer(cEntity *, MTRand & a_TickRandom) override;
protected:
float m_ChaseTime;
diff --git a/source/Mobs/Cavespider.cpp b/source/Mobs/Cavespider.cpp
index b0dcd2eae..b63e28f1a 100644
--- a/source/Mobs/Cavespider.cpp
+++ b/source/Mobs/Cavespider.cpp
@@ -16,9 +16,9 @@ cCavespider::cCavespider(void) :
-void cCavespider::Tick(float a_Dt)
+void cCavespider::Tick(float a_Dt, MTRand & a_TickRandom)
{
- super::Tick(a_Dt);
+ super::Tick(a_Dt, a_TickRandom);
// TODO: Check vanilla if cavespiders really get passive during the day
m_EMPersonality = (GetWorld()->GetTimeOfDay() < (12000 + 1000)) ? PASSIVE : AGGRESSIVE;
diff --git a/source/Mobs/Cavespider.h b/source/Mobs/Cavespider.h
index 33f67b6f5..b02318a0f 100644
--- a/source/Mobs/Cavespider.h
+++ b/source/Mobs/Cavespider.h
@@ -17,7 +17,7 @@ public:
CLASS_PROTODEF(cCaveSpider);
- virtual void Tick(float a_Dt) override;
+ virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
virtual void GetDrops(cItems & a_Drops, cPawn * a_Killer = NULL) override;
} ;
diff --git a/source/Mobs/Enderman.cpp b/source/Mobs/Enderman.cpp
index 33aecc61d..d7bbaa144 100644
--- a/source/Mobs/Enderman.cpp
+++ b/source/Mobs/Enderman.cpp
@@ -16,9 +16,9 @@ cEnderman::cEnderman(void) :
-void cEnderman::Tick(float a_Dt)
+void cEnderman::Tick(float a_Dt, MTRand & a_TickRandom)
{
- cMonster::Tick(a_Dt);
+ cMonster::Tick(a_Dt, a_TickRandom);
// TODO Same as stated in cSkeleton
if ((GetWorld()->GetTimeOfDay() < (12000 + 1000)) && (GetMetaData() != BURNING))
diff --git a/source/Mobs/Enderman.h b/source/Mobs/Enderman.h
index adcbe3b4b..0703ca25e 100644
--- a/source/Mobs/Enderman.h
+++ b/source/Mobs/Enderman.h
@@ -17,7 +17,7 @@ public:
CLASS_PROTODEF(cEnderman);
- virtual void Tick(float a_Dt) override;
+ virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
virtual void GetDrops(cItems & a_Drops, cPawn * a_Killer = NULL) override;
} ;
diff --git a/source/Mobs/Monster.cpp b/source/Mobs/Monster.cpp
index 49f11ebfd..224a16782 100644
--- a/source/Mobs/Monster.cpp
+++ b/source/Mobs/Monster.cpp
@@ -87,14 +87,15 @@ bool cMonster::ReachedDestination()
-void cMonster::Tick(float a_Dt)
+void cMonster::Tick(float a_Dt, MTRand & a_TickRandom)
{
- cPawn::Tick(a_Dt);
+ super::Tick(a_Dt, a_TickRandom);
- if( m_Health <= 0 )
+ if (m_Health <= 0)
{
- m_DestroyTimer += a_Dt/1000;
- if( m_DestroyTimer > 1 )
+ // 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();
}
@@ -103,7 +104,7 @@ void cMonster::Tick(float a_Dt)
a_Dt /= 1000;
- if( m_bMovingToDestination )
+ if (m_bMovingToDestination)
{
Vector3f Pos( m_Pos );
Vector3f Distance = m_Destination - Pos;
@@ -142,8 +143,6 @@ void cMonster::Tick(float a_Dt)
}
}
- HandlePhysics( a_Dt );
-
ReplicateMovement();
Vector3f Distance = m_Destination - Vector3f( m_Pos );
@@ -156,22 +155,28 @@ void cMonster::Tick(float a_Dt)
SetPitch( Pitch );
}
- if (m_EMState == IDLE)
+ switch (m_EMState)
{
- // If enemy passive we ignore checks for player visibility
- InStateIdle(a_Dt);
- }
+ case IDLE:
+ {
+ // If enemy passive we ignore checks for player visibility
+ InStateIdle(a_Dt, a_TickRandom);
+ break;
+ }
- if (m_EMState == CHASING)
- {
- // If we do not see a player anymore skip chasing action
- InStateChasing(a_Dt);
- }
+ case CHASING:
+ {
+ // If we do not see a player anymore skip chasing action
+ InStateChasing(a_Dt, a_TickRandom);
+ break;
+ }
- if (m_EMState == ESCAPING)
- {
- InStateEscaping(a_Dt);
- }
+ case ESCAPING:
+ {
+ InStateEscaping(a_Dt, a_TickRandom);
+ break;
+ }
+ } // switch (m_EMState)
}
@@ -366,13 +371,14 @@ void cMonster::SetState(const AString & a_State)
//Checks to see if EventSeePlayer should be fired
//monster sez: Do I see the player
-void cMonster::CheckEventSeePlayer()
+void cMonster::CheckEventSeePlayer(MTRand & a_TickRandom)
{
- cPlayer *Closest = FindClosestPlayer();
+ // TODO: Rewrite this to use cWorld's DoWithPlayers()
+ cPlayer * Closest = FindClosestPlayer();
- if (Closest)
+ if (Closest != NULL)
{
- EventSeePlayer(Closest);
+ EventSeePlayer(Closest, a_TickRandom);
}
}
@@ -380,8 +386,10 @@ void cMonster::CheckEventSeePlayer()
-void cMonster::CheckEventLostPlayer()
+void cMonster::CheckEventLostPlayer(MTRand & a_TickRandom)
{
+ UNUSED(a_TickRandom);
+
Vector3f pos;
cTracer LineOfSight(GetWorld());
@@ -405,8 +413,10 @@ void cMonster::CheckEventLostPlayer()
// What to do if player is seen
// default to change state to chasing
-void cMonster::EventSeePlayer(cEntity *a_SeenPlayer)
+void cMonster::EventSeePlayer(cEntity * a_SeenPlayer, MTRand & a_TickRandom)
{
+ UNUSED(a_TickRandom);
+
m_Target = a_SeenPlayer;
AddReference( m_Target );
}
@@ -415,7 +425,7 @@ void cMonster::EventSeePlayer(cEntity *a_SeenPlayer)
-void cMonster::EventLosePlayer()
+void cMonster::EventLosePlayer(void)
{
Dereference(m_Target);
m_Target = 0;
@@ -426,26 +436,25 @@ void cMonster::EventLosePlayer()
-//What to do if in Idle State
-void cMonster::InStateIdle(float a_Dt)
+// What to do if in Idle State
+void cMonster::InStateIdle(float a_Dt, MTRand & a_TickRandom)
{
idle_interval += a_Dt;
if (idle_interval > 1)
{
// at this interval the results are predictable
- MTRand r1;
- int rem = r1.randInt()%6 + 1;
+ int rem = (a_TickRandom.randInt() % 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)((r1.randInt()%11)-5);
- Dist.z = (float)((r1.randInt()%11)-5);
- if( Dist.SqrLength() > 2 && rem >= 3)
+ Dist.x = (float)((a_TickRandom.randInt() % 11) - 5);
+ Dist.z = (float)((a_TickRandom.randInt() % 11) - 5);
+ if ((Dist.SqrLength() > 2) && (rem >= 3))
{
m_Destination.x = (float)(m_Pos.x + Dist.x);
m_Destination.z = (float)(m_Pos.z + Dist.z);
- m_Destination.y = (float)GetWorld()->GetHeight( (int)m_Destination.x, (int)m_Destination.z ) + 1.2f;
- MoveToPosition( m_Destination );
+ m_Destination.y = (float)GetWorld()->GetHeight((int)m_Destination.x, (int)m_Destination.z) + 1.2f;
+ MoveToPosition(m_Destination);
}
}
}
@@ -456,9 +465,10 @@ void cMonster::InStateIdle(float a_Dt)
// What to do if in Chasing State
// This state should always be defined in each child class
-void cMonster::InStateChasing(float a_Dt)
+void cMonster::InStateChasing(float a_Dt, MTRand & a_TickRandom)
{
UNUSED(a_Dt);
+ UNUSED(a_TickRandom);
}
@@ -466,10 +476,12 @@ void cMonster::InStateChasing(float a_Dt)
// What to do if in Escaping State
-void cMonster::InStateEscaping(float a_Dt)
+void cMonster::InStateEscaping(float a_Dt, MTRand & a_TickRandom)
{
- (void)a_Dt;
- if(m_Target)
+ UNUSED(a_Dt);
+ UNUSED(a_TickRandom);
+
+ if (m_Target != NULL)
{
Vector3d newloc = m_Pos;
newloc.x = (m_Target->GetPosition().x < newloc.x)? (newloc.x + m_SightDistance): (newloc.x - m_SightDistance);
@@ -478,7 +490,7 @@ void cMonster::InStateEscaping(float a_Dt)
}
else
{
- m_EMState = IDLE; //this shouldnt be required but just to be safe
+ m_EMState = IDLE; // This shouldnt be required but just to be safe
}
}
diff --git a/source/Mobs/Monster.h b/source/Mobs/Monster.h
index 066f17495..5f789fa47 100644
--- a/source/Mobs/Monster.h
+++ b/source/Mobs/Monster.h
@@ -36,7 +36,7 @@ public:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
- virtual void Tick(float a_Dt) override;
+ virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
virtual void HandlePhysics(float a_Dt);
virtual void ReplicateMovement(void);
@@ -53,20 +53,20 @@ public:
const char * GetState();
void SetState(const AString & str);
- virtual void CheckEventSeePlayer();
- virtual void EventSeePlayer(cEntity *);
+ virtual void CheckEventSeePlayer(MTRand & a_TickRandom);
+ virtual void EventSeePlayer(cEntity *, MTRand & a_TickRandom);
float m_SightDistance;
virtual cPlayer * FindClosestPlayer(); // non static is easier. also virtual so other mobs can implement their own searching algo
/// Reads the monster configuration for the specified monster name and assigns it to this object.
void GetMonsterConfig(const AString & a_Name);
- virtual void EventLosePlayer();
- virtual void CheckEventLostPlayer();
+ virtual void EventLosePlayer(void);
+ virtual void CheckEventLostPlayer(MTRand & a_TickRandom);
- virtual void InStateIdle(float a_Dt);
- virtual void InStateChasing(float a_Dt);
- virtual void InStateEscaping(float a_Dt);
+ virtual void InStateIdle (float a_Dt, MTRand & a_TickRandom);
+ virtual void InStateChasing (float a_Dt, MTRand & a_TickRandom);
+ virtual void InStateEscaping(float a_Dt, MTRand & a_TickRandom);
virtual void Attack(float a_Dt);
int GetMobType() {return m_MobType;}
diff --git a/source/Mobs/PassiveMonster.cpp b/source/Mobs/PassiveMonster.cpp
index b11f7305d..aa2e6c118 100644
--- a/source/Mobs/PassiveMonster.cpp
+++ b/source/Mobs/PassiveMonster.cpp
@@ -31,23 +31,22 @@ void cPassiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
-void cPassiveMonster::Tick(float a_Dt)
+void cPassiveMonster::Tick(float a_Dt, MTRand & a_TickRandom)
{
- super::Tick(a_Dt);
+ super::Tick(a_Dt, a_TickRandom);
m_SeePlayerInterval += a_Dt;
if (m_SeePlayerInterval > 1) // Check every second
{
- MTRand r1;
- int rem = r1.randInt() % 3 + 1; // Check most of the time but miss occasionally
+ int rem = a_TickRandom.randInt() % 3 + 1; // Check most of the time but miss occasionally
m_SeePlayerInterval = 0.0;
if (rem >= 2)
{
if (m_EMState == ESCAPING)
{
- CheckEventLostPlayer();
+ CheckEventLostPlayer(a_TickRandom);
}
}
}
diff --git a/source/Mobs/PassiveMonster.h b/source/Mobs/PassiveMonster.h
index d31510891..66e718ec3 100644
--- a/source/Mobs/PassiveMonster.h
+++ b/source/Mobs/PassiveMonster.h
@@ -15,7 +15,7 @@ class cPassiveMonster :
public:
cPassiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath);
- virtual void Tick(float a_Dt) override;
+ virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
/// When hit by someone, run away
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
diff --git a/source/Mobs/Skeleton.cpp b/source/Mobs/Skeleton.cpp
index 76a7b6beb..785584fcd 100644
--- a/source/Mobs/Skeleton.cpp
+++ b/source/Mobs/Skeleton.cpp
@@ -16,9 +16,9 @@ cSkeleton::cSkeleton(void) :
-void cSkeleton::Tick(float a_Dt)
+void cSkeleton::Tick(float a_Dt, MTRand & a_TickRandom)
{
- cMonster::Tick(a_Dt);
+ cMonster::Tick(a_Dt, a_TickRandom);
// TODO Outsource
// TODO should do SkyLight check, mobs in the dark donīt burn
diff --git a/source/Mobs/Skeleton.h b/source/Mobs/Skeleton.h
index 476b438e5..a02d1b5a6 100644
--- a/source/Mobs/Skeleton.h
+++ b/source/Mobs/Skeleton.h
@@ -17,7 +17,7 @@ public:
CLASS_PROTODEF(cSkeleton);
- virtual void Tick(float a_Dt) override;
+ virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
virtual void GetDrops(cItems & a_Drops, cPawn * a_Killer = NULL) override;
} ;
diff --git a/source/Mobs/Squid.cpp b/source/Mobs/Squid.cpp
index e300deef0..808bd359e 100644
--- a/source/Mobs/Squid.cpp
+++ b/source/Mobs/Squid.cpp
@@ -27,9 +27,9 @@ void cSquid::GetDrops(cItems & a_Drops, cPawn * a_Killer)
-void cSquid::Tick(float a_Dt)
+void cSquid::Tick(float a_Dt, MTRand & a_TickRandom)
{
- super::Tick(a_Dt);
+ super::Tick(a_Dt, a_TickRandom);
Vector3d Pos = GetPosition();
diff --git a/source/Mobs/Squid.h b/source/Mobs/Squid.h
index 4a8de4d28..158fbea4a 100644
--- a/source/Mobs/Squid.h
+++ b/source/Mobs/Squid.h
@@ -15,7 +15,7 @@ class cSquid :
public:
cSquid();
- virtual void Tick(float a_Dt) override;
+ virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
CLASS_PROTODEF(cSquid);
diff --git a/source/Mobs/Zombie.cpp b/source/Mobs/Zombie.cpp
index bf630929a..8038c51f6 100644
--- a/source/Mobs/Zombie.cpp
+++ b/source/Mobs/Zombie.cpp
@@ -16,9 +16,9 @@ cZombie::cZombie(void) :
-void cZombie::Tick(float a_Dt)
+void cZombie::Tick(float a_Dt, MTRand & a_TickRandom)
{
- super::Tick(a_Dt);
+ super::Tick(a_Dt, a_TickRandom);
// TODO Same as in cSkeleton :D
if ((GetWorld()->GetTimeOfDay() < (12000 + 1000)) && (GetMetaData() != BURNING))
diff --git a/source/Mobs/Zombie.h b/source/Mobs/Zombie.h
index 06bd9244a..c4988af72 100644
--- a/source/Mobs/Zombie.h
+++ b/source/Mobs/Zombie.h
@@ -16,7 +16,7 @@ public:
CLASS_PROTODEF(cZombie);
- virtual void Tick(float a_Dt) override;
+ virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
virtual void GetDrops(cItems & a_Drops, cPawn * a_Killer = NULL) override;
} ;
diff --git a/source/Mobs/Zombiepigman.cpp b/source/Mobs/Zombiepigman.cpp
index 0e618cbc2..a542723c4 100644
--- a/source/Mobs/Zombiepigman.cpp
+++ b/source/Mobs/Zombiepigman.cpp
@@ -16,9 +16,9 @@ cZombiepigman::cZombiepigman(void) :
-void cZombiepigman::Tick(float a_Dt)
+void cZombiepigman::Tick(float a_Dt, MTRand & a_TickRandom)
{
- super::Tick(a_Dt);
+ super::Tick(a_Dt, a_TickRandom);
// TODO Same as noticed in cSkeleton AND Do they really burn by sun?? :D In the neather is no sun :D
if ((GetWorld()->GetTimeOfDay() < (12000 + 1000)) && (GetMetaData() != BURNING))
diff --git a/source/Mobs/Zombiepigman.h b/source/Mobs/Zombiepigman.h
index 929d03241..201416dbd 100644
--- a/source/Mobs/Zombiepigman.h
+++ b/source/Mobs/Zombiepigman.h
@@ -17,7 +17,7 @@ public:
CLASS_PROTODEF(cZombiepigman);
- virtual void Tick(float a_Dt) override;
+ virtual void Tick(float a_Dt, MTRand & a_TickRandom) override;
virtual void GetDrops(cItems & a_Drops, cPawn * a_Killer = NULL) override;
virtual void KilledBy(cPawn * a_Killer) override;
} ;