summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-24 14:50:17 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-24 14:50:17 +0200
commit7f5058f1872e1ecc2ea9b897e32708903480e702 (patch)
treeeb413f839b0e36c1bc05cb3c3e6bf2435a70810c
parentMerge branch 'master' into mobs2 (diff)
downloadcuberite-7f5058f1872e1ecc2ea9b897e32708903480e702.tar
cuberite-7f5058f1872e1ecc2ea9b897e32708903480e702.tar.gz
cuberite-7f5058f1872e1ecc2ea9b897e32708903480e702.tar.bz2
cuberite-7f5058f1872e1ecc2ea9b897e32708903480e702.tar.lz
cuberite-7f5058f1872e1ecc2ea9b897e32708903480e702.tar.xz
cuberite-7f5058f1872e1ecc2ea9b897e32708903480e702.tar.zst
cuberite-7f5058f1872e1ecc2ea9b897e32708903480e702.zip
-rw-r--r--src/Mobs/AggressiveMonster.cpp2
-rw-r--r--src/Mobs/Behaviors/Behavior.cpp5
-rw-r--r--src/Mobs/Behaviors/Behavior.h9
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.cpp14
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.h2
-rw-r--r--src/Mobs/Behaviors/BehaviorBreeder.cpp18
-rw-r--r--src/Mobs/Behaviors/BehaviorBreeder.h5
-rw-r--r--src/Mobs/Behaviors/BehaviorChaser.cpp21
-rw-r--r--src/Mobs/Behaviors/BehaviorChaser.h3
-rw-r--r--src/Mobs/Behaviors/BehaviorCoward.cpp17
-rw-r--r--src/Mobs/Behaviors/BehaviorCoward.h3
-rw-r--r--src/Mobs/Behaviors/BehaviorDayLightBurner.cpp13
-rw-r--r--src/Mobs/Behaviors/BehaviorDayLightBurner.h6
-rw-r--r--src/Mobs/Behaviors/BehaviorItemFollower.cpp7
-rw-r--r--src/Mobs/Behaviors/BehaviorItemFollower.h2
-rw-r--r--src/Mobs/Behaviors/BehaviorWanderer.cpp40
-rw-r--r--src/Mobs/Behaviors/BehaviorWanderer.h9
-rw-r--r--src/Mobs/Monster.cpp78
-rw-r--r--src/Mobs/Monster.h19
-rw-r--r--src/Mobs/PassiveMonster.cpp3
20 files changed, 214 insertions, 62 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 9d9532573..0e6911305 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -13,7 +13,7 @@
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
- super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height), m_BehaviorAggressive(this)
+ super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
{
m_EMPersonality = AGGRESSIVE;
ASSERT(GetBehaviorChaser() != nullptr);
diff --git a/src/Mobs/Behaviors/Behavior.cpp b/src/Mobs/Behaviors/Behavior.cpp
index 695343732..86922427f 100644
--- a/src/Mobs/Behaviors/Behavior.cpp
+++ b/src/Mobs/Behaviors/Behavior.cpp
@@ -1,8 +1,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Behavior.h"
-
-
+#include "../Monster.h"
@@ -76,7 +75,7 @@ void cBehavior::PreTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
-void cBehavior::onRightClicked()
+void cBehavior::OnRightClicked(cPlayer & a_Player)
{
LOGD("ERROR: Called onRightClicked on a behavior that doesn't have one.");
ASSERT(1 == 0);
diff --git a/src/Mobs/Behaviors/Behavior.h b/src/Mobs/Behaviors/Behavior.h
index 989addf8d..0b554ec62 100644
--- a/src/Mobs/Behaviors/Behavior.h
+++ b/src/Mobs/Behaviors/Behavior.h
@@ -2,11 +2,16 @@
struct TakeDamageInfo;
class cChunk;
+class cPlayer;
+class cMonster;
#include <chrono>
class cBehavior
{
public:
+ virtual void AttachToMonster(cMonster & a_Parent) = 0;
+
+ // Tick-related
virtual bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
virtual bool ControlStarting(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
virtual bool ControlEnding(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
@@ -14,8 +19,8 @@ public:
virtual void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
virtual void PreTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
-
- virtual void onRightClicked();
+ // Other
+ virtual void OnRightClicked(cPlayer & a_Player);
virtual void Destroyed();
virtual void DoTakeDamage(TakeDamageInfo & a_TDI);
virtual ~cBehavior() {}
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp
index f7c553f52..65618e123 100644
--- a/src/Mobs/Behaviors/BehaviorAggressive.cpp
+++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp
@@ -6,21 +6,17 @@
#include "../../Chunk.h"
#include "../../Entities/Player.h"
-
-
-cBehaviorAggressive::cBehaviorAggressive(cMonster * a_Parent) : m_Parent(a_Parent)
+void cBehaviorAggressive::AttachToMonster(cMonster & a_Parent)
{
- ASSERT(m_Parent != nullptr);
- m_ParentChaser = m_Parent->GetBehaviorChaser();
- ASSERT(m_ParentChaser != nullptr);
+ m_Parent = &a_Parent;
+ m_Parent->AttachPreTickBehavior(this);
}
-
-
-
void cBehaviorAggressive::PreTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
+ UNUSED(a_Dt);
+ UNUSED(a_Chunk);
// Target something new if we have no target
if (m_ParentChaser->GetTarget() == nullptr)
{
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.h b/src/Mobs/Behaviors/BehaviorAggressive.h
index 5bf86b23f..7dc7060c7 100644
--- a/src/Mobs/Behaviors/BehaviorAggressive.h
+++ b/src/Mobs/Behaviors/BehaviorAggressive.h
@@ -19,7 +19,7 @@ class cBehaviorAggressive : public cBehavior
{
public:
- cBehaviorAggressive(cMonster * a_Parent);
+ void AttachToMonster(cMonster & a_Parent) override;
// cBehaviorAggressive(cMonster * a_Parent, bool a_HatesPlayer);
// TODO agression toward specific players, and specific mobtypes, etc
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.cpp b/src/Mobs/Behaviors/BehaviorBreeder.cpp
index b2bd8da5d..b32fafc8c 100644
--- a/src/Mobs/Behaviors/BehaviorBreeder.cpp
+++ b/src/Mobs/Behaviors/BehaviorBreeder.cpp
@@ -9,15 +9,25 @@
#include "../../Item.h"
#include "../../BoundingBox.h"
-cBehaviorBreeder::cBehaviorBreeder(cMonster * a_Parent) :
- m_Parent(a_Parent),
+cBehaviorBreeder::cBehaviorBreeder() :
m_LovePartner(nullptr),
m_LoveTimer(0),
m_LoveCooldown(0),
m_MatingTimer(0)
{
- m_Parent = a_Parent;
- ASSERT(m_Parent != nullptr);
+}
+
+
+
+
+
+void cBehaviorBreeder::AttachToMonster(cMonster & a_Parent)
+{
+ m_Parent = &a_Parent;
+ m_Parent->AttachTickBehavior(this);
+ m_Parent->AttachPostTickBehavior(this);
+ m_Parent->AttachRightClickBehavior(this);
+ m_Parent->AttachDestroyBehavior(this);
}
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.h b/src/Mobs/Behaviors/BehaviorBreeder.h
index cf030b8f3..576234066 100644
--- a/src/Mobs/Behaviors/BehaviorBreeder.h
+++ b/src/Mobs/Behaviors/BehaviorBreeder.h
@@ -18,13 +18,14 @@ class cBehaviorBreeder : public cBehavior
{
public:
- cBehaviorBreeder(cMonster * a_Parent);
+ cBehaviorBreeder();
+ void AttachToMonster(cMonster & a_Parent) override;
// Functions our host Monster should invoke:
bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
- void OnRightClicked(cPlayer & a_Player);
+ void OnRightClicked(cPlayer & a_Player) override;
void Destroyed() override;
/** Returns the partner which the monster is currently mating with. */
diff --git a/src/Mobs/Behaviors/BehaviorChaser.cpp b/src/Mobs/Behaviors/BehaviorChaser.cpp
index 025c60dd0..8e2a70bd4 100644
--- a/src/Mobs/Behaviors/BehaviorChaser.cpp
+++ b/src/Mobs/Behaviors/BehaviorChaser.cpp
@@ -9,20 +9,33 @@
-cBehaviorChaser::cBehaviorChaser(cMonster * a_Parent) :
- m_Parent(a_Parent)
- , m_AttackRate(3)
+cBehaviorChaser::cBehaviorChaser() :
+ m_AttackRate(3)
, m_AttackDamage(1)
, m_AttackRange(1)
, m_AttackCoolDownTicksLeft(0)
, m_TicksSinceLastDamaged(100)
{
- ASSERT(m_Parent != nullptr);
+
+}
+
+
+
+
+
+void cBehaviorChaser::AttachToMonster(cMonster & a_Parent)
+{
+ m_Parent = &a_Parent;
+ m_Parent->AttachTickBehavior(this);
+ m_Parent->AttachDestroyBehavior(this);
+ m_Parent->AttachPostTickBehavior(this);
+ m_Parent->AttachDoTakeDamageBehavior(this);
}
+
bool cBehaviorChaser::IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
UNUSED(a_Dt);
diff --git a/src/Mobs/Behaviors/BehaviorChaser.h b/src/Mobs/Behaviors/BehaviorChaser.h
index d0910e11e..a40be6aba 100644
--- a/src/Mobs/Behaviors/BehaviorChaser.h
+++ b/src/Mobs/Behaviors/BehaviorChaser.h
@@ -17,7 +17,8 @@ class cBehaviorChaser : public cBehavior
{
public:
- cBehaviorChaser(cMonster * a_Parent);
+ cBehaviorChaser();
+ void AttachToMonster(cMonster & a_Parent) override;
// Functions our host Monster should invoke:
bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
diff --git a/src/Mobs/Behaviors/BehaviorCoward.cpp b/src/Mobs/Behaviors/BehaviorCoward.cpp
index 43be5c49c..d23da5ac6 100644
--- a/src/Mobs/Behaviors/BehaviorCoward.cpp
+++ b/src/Mobs/Behaviors/BehaviorCoward.cpp
@@ -6,16 +6,27 @@
#include "../../Entities/Player.h"
#include "../../Entities/Entity.h"
-cBehaviorCoward::cBehaviorCoward(cMonster * a_Parent) :
- m_Parent(a_Parent),
+cBehaviorCoward::cBehaviorCoward() :
m_Attacker(nullptr)
{
- ASSERT(m_Parent != nullptr);
}
+void cBehaviorCoward::AttachToMonster(cMonster & a_Parent)
+{
+ m_Parent = &a_Parent;
+ m_Parent->AttachTickBehavior(this);
+ m_Parent->AttachDestroyBehavior(this);
+ m_Parent->AttachPostTickBehavior(this);
+ m_Parent->AttachDoTakeDamageBehavior(this);
+}
+
+
+
+
+
bool cBehaviorCoward::IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
UNUSED(a_Dt);
diff --git a/src/Mobs/Behaviors/BehaviorCoward.h b/src/Mobs/Behaviors/BehaviorCoward.h
index 048101d5d..b72dbaf41 100644
--- a/src/Mobs/Behaviors/BehaviorCoward.h
+++ b/src/Mobs/Behaviors/BehaviorCoward.h
@@ -13,7 +13,8 @@ struct TakeDamageInfo;
class cBehaviorCoward : cBehavior
{
public:
- cBehaviorCoward(cMonster * a_Parent);
+ cBehaviorCoward();
+ void AttachToMonster(cMonster & a_Parent) override;
// Functions our host Monster should invoke:
bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp b/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp
index b28c3c49c..efa4b6518 100644
--- a/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp
+++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp
@@ -7,11 +7,20 @@
#include "../../Chunk.h"
-cBehaviorDayLightBurner::cBehaviorDayLightBurner(cMonster * a_Parent) : m_Parent(a_Parent)
+
+
+
+
+void cBehaviorDayLightBurner::AttachToMonster(cMonster & a_Parent)
{
- ASSERT(m_Parent != nullptr);
+ m_Parent = &a_Parent;
+ m_Parent->AttachPostTickBehavior(this);
}
+
+
+
+
void cBehaviorDayLightBurner::PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
// mobTodo WouldBurn
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.h b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
index 77fcce281..0acdeea40 100644
--- a/src/Mobs/Behaviors/BehaviorDayLightBurner.h
+++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
@@ -12,13 +12,13 @@ class cChunk;
class cBehaviorDayLightBurner : cBehavior
{
public:
- cBehaviorDayLightBurner(cMonster * a_Parent);
+ void AttachToMonster(cMonster & a_Parent) override;
- void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
+ void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
bool WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk);
// Functions our host Monster should invoke:
- void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
+ void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
private:
cMonster * m_Parent; // Our Parent
diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.cpp b/src/Mobs/Behaviors/BehaviorItemFollower.cpp
index c6cb0df04..d10b46776 100644
--- a/src/Mobs/Behaviors/BehaviorItemFollower.cpp
+++ b/src/Mobs/Behaviors/BehaviorItemFollower.cpp
@@ -6,11 +6,10 @@
#include "../../Entities/Player.h"
-cBehaviorItemFollower::cBehaviorItemFollower(cMonster * a_Parent) :
- m_Parent(a_Parent)
+void cBehaviorItemFollower::AttachToMonster(cMonster & a_Parent)
{
- m_Parent = a_Parent;
- ASSERT(m_Parent != nullptr);
+ m_Parent = &a_Parent;
+ m_Parent->AttachTickBehavior(this);
}
diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.h b/src/Mobs/Behaviors/BehaviorItemFollower.h
index 94f8bda15..277323ab1 100644
--- a/src/Mobs/Behaviors/BehaviorItemFollower.h
+++ b/src/Mobs/Behaviors/BehaviorItemFollower.h
@@ -12,7 +12,7 @@ class cItems;
class cBehaviorItemFollower : public cBehavior
{
public:
- cBehaviorItemFollower(cMonster * a_Parent);
+ void AttachToMonster(cMonster & a_Parent) override;
void GetBreedingItems(cItems & a_Items);
diff --git a/src/Mobs/Behaviors/BehaviorWanderer.cpp b/src/Mobs/Behaviors/BehaviorWanderer.cpp
index 53efd407c..44dda077b 100644
--- a/src/Mobs/Behaviors/BehaviorWanderer.cpp
+++ b/src/Mobs/Behaviors/BehaviorWanderer.cpp
@@ -4,18 +4,43 @@
#include "../../Chunk.h"
#include "../../World.h"
-cBehaviorWanderer::cBehaviorWanderer(cMonster * a_Parent)
- : m_Parent(a_Parent)
- , m_IdleInterval(0)
+cBehaviorWanderer::cBehaviorWanderer() : m_IdleInterval(0)
{
- ASSERT(m_Parent != nullptr);
+
}
-bool cBehaviorWanderer::ActiveTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+
+
+
+
+void cBehaviorWanderer::AttachToMonster(cMonster & a_Parent)
+{
+ m_Parent = &a_Parent;
+ m_Parent->AttachTickBehavior(this);
+}
+
+
+
+
+
+bool cBehaviorWanderer::IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+{
+ // Wandering behavior always happily accepts control.
+ // It should therefore be the last one attached to a monster.
+ UNUSED(a_Dt);
+ UNUSED(a_Chunk);
+ return true;
+}
+
+
+
+
+
+void cBehaviorWanderer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
if (m_Parent->IsPathFinderActivated())
{
- return true; // Still getting there
+ return; // Still getting there
}
m_IdleInterval += a_Dt;
@@ -38,7 +63,7 @@ bool cBehaviorWanderer::ActiveTick(std::chrono::milliseconds a_Dt, cChunk & a_Ch
cChunk * Chunk = a_Chunk.GetNeighborChunk(static_cast<int>(Destination.x), static_cast<int>(Destination.z));
if ((Chunk == nullptr) || !Chunk->IsValid())
{
- return true;
+ return;
}
BLOCKTYPE BlockType;
@@ -56,5 +81,4 @@ bool cBehaviorWanderer::ActiveTick(std::chrono::milliseconds a_Dt, cChunk & a_Ch
}
}
}
- return true;
}
diff --git a/src/Mobs/Behaviors/BehaviorWanderer.h b/src/Mobs/Behaviors/BehaviorWanderer.h
index 258bf5f59..90dddcebc 100644
--- a/src/Mobs/Behaviors/BehaviorWanderer.h
+++ b/src/Mobs/Behaviors/BehaviorWanderer.h
@@ -2,19 +2,22 @@
// The mob will wander around
#include <chrono>
+#include "Behavior.h"
class cMonster;
class cEntity;
class cChunk;
-class cBehaviorWanderer
+class cBehaviorWanderer : cBehavior
{
public:
- cBehaviorWanderer(cMonster * a_Parent);
+ cBehaviorWanderer();
+ void AttachToMonster(cMonster & a_Parent) override;
// Functions our host Monster should invoke:
- bool ActiveTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
+ bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
+ void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
private:
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 80da3b03a..6e7e175a3 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -137,6 +137,9 @@ cMonster::~cMonster()
void cMonster::Destroy(bool a_ShouldBroadcast)
{
+ //mobtodo Destroy vs Destroyed
+
+ // mobTodo behavior for leash
if (IsLeashed())
{
cEntity * LeashedTo = GetLeashedTo();
@@ -158,6 +161,11 @@ void cMonster::Destroy(bool a_ShouldBroadcast)
void cMonster::Destroyed()
{
+ for (cBehavior * Behavior : m_AttachedDestroyBehaviors)
+ {
+ Behavior->Destroyed();
+ }
+
SetTarget(nullptr); // Tell them we're no longer targeting them.
super::Destroyed();
}
@@ -182,6 +190,7 @@ void cMonster::SpawnOn(cClientHandle & a_Client)
void cMonster::MoveToWayPoint(cChunk & a_Chunk)
{
+ UNUSED(a_Chunk);
if ((m_NextWayPointPosition - GetPosition()).SqrLength() < WAYPOINT_RADIUS * WAYPOINT_RADIUS)
{
return;
@@ -304,7 +313,7 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// All behaviors can execute PostTick and PreTick.
// These are for bookkeeping or passive actions like laying eggs.
// They MUST NOT control mob movement or interefere with the main Tick.
- for (cBehavior * Behavior : PreTickBehaviors)
+ for (cBehavior * Behavior : m_AttachedPreTickBehaviors)
{
Behavior->PreTick(a_Dt, a_Chunk);
}
@@ -318,7 +327,7 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
// ask the behaviors sequentially if they are interested in controlling this mob
// Stop at the first one that says yes.
- for (cBehavior * Behavior : TickBehaviors)
+ for (cBehavior * Behavior : m_AttachedTickBehaviors)
{
if (Behavior->IsControlDesired(a_Dt, a_Chunk))
{
@@ -378,7 +387,7 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// All behaviors can execute PostTick and PreTick.
// These are for bookkeeping or passive actions like laying eggs.
// They MUST NOT control mob movement or interefere with the main Tick.
- for (cBehavior * Behavior : PostTickBehaviors)
+ for (cBehavior * Behavior : m_AttachedPostTickBehaviors)
{
Behavior->PostTick(a_Dt, a_Chunk);
}
@@ -691,6 +700,7 @@ void cMonster::OnRightClicked(cPlayer & a_Player)
{
super::OnRightClicked(a_Player);
+ // mobTodo put this in a behavior?
const cItem & EquippedItem = a_Player.GetEquippedItem();
if ((EquippedItem.m_ItemType == E_ITEM_NAME_TAG) && !EquippedItem.m_CustomName.empty())
{
@@ -701,6 +711,12 @@ void cMonster::OnRightClicked(cPlayer & a_Player)
}
}
+ for (cBehavior * Behavior : m_AttachedOnRightClickBehaviors)
+ {
+ Behavior->OnRightClicked(a_Player);
+ }
+
+ // mobTodo put this in a behavior?
// Using leashes
m_IsLeashActionJustDone = false;
if (IsLeashed() && (GetLeashedTo() == &a_Player)) // a player can only unleash a mob leashed to him
@@ -1297,6 +1313,62 @@ void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, unsigned int a_LootingL
+void cMonster::AttachPreTickBehavior(cBehavior * a_Behavior)
+{
+ ASSERT(a_Behavior != nullptr);
+ m_AttachedPreTickBehaviors.push_back(a_Behavior);
+}
+
+
+
+
+
+void cMonster::AttachPostTickBehavior(cBehavior * a_Behavior)
+{
+ ASSERT(a_Behavior != nullptr);
+ m_AttachedPostTickBehaviors.push_back(a_Behavior);
+}
+
+
+
+
+
+void cMonster::AttachTickBehavior(cBehavior * a_Behavior)
+{
+ ASSERT(a_Behavior != nullptr);
+ m_AttachedTickBehaviors.push_back(a_Behavior);
+}
+
+
+
+
+
+void cMonster::AttachDestroyBehavior(cBehavior * a_Behavior)
+{
+ ASSERT(a_Behavior != nullptr);
+ m_AttachedDestroyBehaviors.push_back(a_Behavior);
+}
+
+
+
+
+
+void cMonster::AttachRightClickBehavior(cBehavior * a_Behavior)
+{
+ ASSERT(a_Behavior != nullptr);
+ m_AttachedOnRightClickBehaviors.push_back(a_Behavior);
+}
+
+
+
+
+
+void cMonster::AttachDoTakeDamageBehavior(cBehavior * a_Behavior)
+{
+ m_AttachedDoTakeDamageBehaviors.push_back(a_Behavior);
+}
+
+
cMonster::eFamily cMonster::GetMobFamily(void) const
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 6e24220b5..32091d6f9 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -220,6 +220,14 @@ public:
cPlayer * GetNearestPlayer();
+ // These should only be called from cBehavior::attachToMonster
+ void AttachPreTickBehavior(cBehavior * a_Behavior);
+ void AttachPostTickBehavior(cBehavior * a_Behavior);
+ void AttachTickBehavior(cBehavior * a_Behavior);
+ void AttachDestroyBehavior(cBehavior * a_Behavior);
+ void AttachRightClickBehavior(cBehavior * a_Behavior);
+ void AttachDoTakeDamageBehavior(cBehavior * a_Behavior);
+
protected:
/** Whether or not m_NearestPlayer is stale. Always true at the beginning of a tick.
@@ -328,11 +336,12 @@ private:
/** Leash calculations inside Tick function */
void CalcLeashActions();
- std::vector<cBehavior*> PreTickBehaviors;
- std::vector<cBehavior*> TickBehaviors;
- std::vector<cBehavior*> PostTickBehaviors;
- std::vector<cBehavior*> OnDestroyBehaviors;
- std::vector<cBehavior*> OnRightClickBehaviors;
+ std::vector<cBehavior*> m_AttachedPreTickBehaviors;
+ std::vector<cBehavior*> m_AttachedTickBehaviors;
+ std::vector<cBehavior*> m_AttachedPostTickBehaviors;
+ std::vector<cBehavior*> m_AttachedDestroyBehaviors;
+ std::vector<cBehavior*> m_AttachedOnRightClickBehaviors;
+ std::vector<cBehavior*> m_AttachedDoTakeDamageBehaviors;
cBehavior * m_CurrentTickControllingBehavior;
cBehavior * m_NewTickControllingBehavior;
diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp
index 81bf681ea..8773e4f79 100644
--- a/src/Mobs/PassiveMonster.cpp
+++ b/src/Mobs/PassiveMonster.cpp
@@ -10,8 +10,7 @@
cPassiveMonster::cPassiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
- super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height),
- m_BehaviorBreeder(this), m_BehaviorItemFollower(this), m_BehaviorCoward(this), m_BehaviorWanderer(this)
+ super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
{
m_EMPersonality = PASSIVE;
}