From c9e80cdeaeba33b22661bdcca77b5565f89d9afa Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Wed, 6 Apr 2016 12:16:14 +0300 Subject: Revert "Move mob tick code to cChunk" --- src/World.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index dcf02f02a..d8b77647a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1131,6 +1131,52 @@ void cWorld::TickMobs(std::chrono::milliseconds a_Dt) } } // for i - AllFamilies[] } // if (Spawning enabled) + + class cCallback : public cEntityCallback + { + virtual bool Item(cEntity * a_Entity) override + { + if (!a_Entity->IsMob()) + { + return false; + } + if (!a_Entity->IsTicking()) + { + return false; + } + + auto Monster = static_cast(a_Entity); + ASSERT(Monster->GetParentChunk() != nullptr); // A ticking entity must have a valid parent chunk + + // Tick close mobs + if (Monster->GetParentChunk()->HasAnyClients()) + { + Monster->Tick(m_Dt, *(a_Entity->GetParentChunk())); + } + // Destroy far hostile mobs + else if ((Monster->GetMobFamily() == cMonster::eFamily::mfHostile)) + { + if (Monster->GetMobType() != eMonsterType::mtWolf) + { + Monster->Destroy(true); + } + else + { + auto Wolf = static_cast(Monster); + if (Wolf->IsAngry()) + { + Monster->Destroy(true); + } + } + } + return false; + } + public: + std::chrono::milliseconds m_Dt; + } Callback; + + Callback.m_Dt = a_Dt; + ForEachEntity(Callback); } -- cgit v1.2.3