diff options
author | Pablo Beltrán <spekdrum@gmail.com> | 2017-05-21 10:29:06 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-05-21 10:29:06 +0200 |
commit | 2359611c57edc70f68b1ba05bb87dbf9c3bbc11d (patch) | |
tree | c7f56d7a6b7916fae6228cdec65b5b57dd0bb8d7 /src | |
parent | Update submodule tolua++ (diff) | |
download | cuberite-2359611c57edc70f68b1ba05bb87dbf9c3bbc11d.tar cuberite-2359611c57edc70f68b1ba05bb87dbf9c3bbc11d.tar.gz cuberite-2359611c57edc70f68b1ba05bb87dbf9c3bbc11d.tar.bz2 cuberite-2359611c57edc70f68b1ba05bb87dbf9c3bbc11d.tar.lz cuberite-2359611c57edc70f68b1ba05bb87dbf9c3bbc11d.tar.xz cuberite-2359611c57edc70f68b1ba05bb87dbf9c3bbc11d.tar.zst cuberite-2359611c57edc70f68b1ba05bb87dbf9c3bbc11d.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Mobs/Monster.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 5 | ||||
-rw-r--r-- | src/World.cpp | 4 |
3 files changed, 9 insertions, 2 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index ece59828e..f49175922 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -100,6 +100,7 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A , m_RelativeWalkSpeed(1) , m_Age(1) , m_AgingTimer(20 * 60 * 20) // about 20 minutes + , m_WasLastTargetAPlayer(false) , m_Target(nullptr) { if (!a_ConfigName.empty()) @@ -945,6 +946,7 @@ void cMonster::SetTarget (cPawn * a_NewTarget) ASSERT(a_NewTarget->IsTicking()); // Notify the new target that we are now targeting it. m_Target->TargetingMe(this); + m_WasLastTargetAPlayer = m_Target->IsPlayer(); } } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 1c3d9c37a..3aaadb57f 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -176,6 +176,9 @@ public: */ static cMonster * NewMonsterFromType(eMonsterType a_MobType); + /** Returns if this mob last target was a player to avoid destruction on player quit */ + bool WasLastTargetAPlayer() const { return m_WasLastTargetAPlayer; } + protected: /** The pathfinder instance handles pathfinding for this monster. */ @@ -251,6 +254,8 @@ protected: int m_Age; int m_AgingTimer; + bool m_WasLastTargetAPlayer; + /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops */ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); diff --git a/src/World.cpp b/src/World.cpp index 447e2cf25..d4be3addb 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1149,8 +1149,8 @@ void cWorld::TickMobs(std::chrono::milliseconds a_Dt) { Monster->Tick(m_Dt, *(a_Entity->GetParentChunk())); } - // Destroy far hostile mobs - else if ((Monster->GetMobFamily() == cMonster::eFamily::mfHostile)) + // Destroy far hostile mobs except if last target was a player + else if ((Monster->GetMobFamily() == cMonster::eFamily::mfHostile) && !Monster->WasLastTargetAPlayer()) { if (Monster->GetMobType() != eMonsterType::mtWolf) { |