summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index a38a6552d..56f7b33a3 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -159,6 +159,15 @@ bool cEntity::Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld)
// Spawn the entity on the clients:
a_EntityWorld.BroadcastSpawnEntity(*this);
+ // If has any mob leashed broadcast every leashed entity to this
+ if (HasAnyMobLeashed())
+ {
+ for (auto LeashedMob : m_LeashedMobs)
+ {
+ m_World->BroadcastLeashEntity(*LeashedMob, *this);
+ }
+ }
+
return true;
}
@@ -218,6 +227,12 @@ void cEntity::Destroy(bool a_ShouldBroadcast)
ASSERT(GetParentChunk() != nullptr);
SetIsTicking(false);
+ // Unleash leashed mobs
+ while (!m_LeashedMobs.empty())
+ {
+ m_LeashedMobs.front()->Unleash(true, true);
+ }
+
if (a_ShouldBroadcast)
{
m_World->BroadcastDestroyEntity(*this);
@@ -2195,3 +2210,24 @@ void cEntity::SetPosition(const Vector3d & a_Position)
+
+void cEntity::AddLeashedMob(cMonster * a_Monster)
+{
+ // Not there already
+ ASSERT(std::find(m_LeashedMobs.begin(), m_LeashedMobs.end(), a_Monster) == m_LeashedMobs.end());
+
+ m_LeashedMobs.push_back(a_Monster);
+}
+
+
+
+
+void cEntity::RemoveLeashedMob(cMonster * a_Monster)
+{
+ ASSERT(a_Monster->GetLeashedTo() == this);
+
+ // Must exists
+ ASSERT(std::find(m_LeashedMobs.begin(), m_LeashedMobs.end(), a_Monster) != m_LeashedMobs.end());
+
+ m_LeashedMobs.remove(a_Monster);
+}