From 04548d3fce91a4bea39fc4165c5ccfc38fa482d5 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 25 Oct 2024 18:40:35 -0300 Subject: [PATCH 1/3] init --- src/creatures/creature.hpp | 5 +++++ src/game/game.cpp | 27 ++++++++------------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 3d0eb24ff8a..eea144448ba 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -199,6 +199,11 @@ class Creature : virtual public Thing, public SharedObject { int32_t getHealth() const { return health; } + + bool isAlive() const { + return !isDead(); + } + virtual int32_t getMaxHealth() const { return healthMax; } diff --git a/src/game/game.cpp b/src/game/game.cpp index 279f4cf714b..329547d8ef1 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -6395,28 +6395,17 @@ void Game::checkCreatures() { metrics::method_latency measure(__METHOD_NAME__); static size_t index = 0; - auto &checkCreatureList = checkCreatureLists[index]; - size_t it = 0, end = checkCreatureList.size(); - while (it < end) { - auto creature = checkCreatureList[it]; - if (creature && creature->creatureCheck) { - if (creature->getHealth() > 0) { - creature->onThink(EVENT_CREATURE_THINK_INTERVAL); - creature->onAttacking(EVENT_CREATURE_THINK_INTERVAL); - creature->executeConditions(EVENT_CREATURE_THINK_INTERVAL); - } else { - afterCreatureZoneChange(creature, creature->getZones(), {}); - creature->onDeath(); - } - ++it; + std::erase_if(checkCreatureLists[index], [this](const std::shared_ptr &creature) { + if (creature->creatureCheck && creature->isAlive()) { + creature->onThink(EVENT_CREATURE_THINK_INTERVAL); + creature->onAttacking(EVENT_CREATURE_THINK_INTERVAL); + creature->executeConditions(EVENT_CREATURE_THINK_INTERVAL); } else { creature->inCheckCreaturesVector = false; - - checkCreatureList[it] = checkCreatureList.back(); - checkCreatureList.pop_back(); - --end; } - } + + return !creature->creatureCheck; + }); index = (index + 1) % EVENT_CREATURECOUNT; } From 073636165baf3c9326443cfa42a22df4fdce2824 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 25 Oct 2024 18:57:14 -0300 Subject: [PATCH 2/3] Update game.cpp --- src/game/game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 329547d8ef1..1148752a7b4 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -6404,7 +6404,7 @@ void Game::checkCreatures() { creature->inCheckCreaturesVector = false; } - return !creature->creatureCheck; + return !creature->inCheckCreaturesVector; }); index = (index + 1) % EVENT_CREATURECOUNT; From 39eea8e7942243a9fcaa0fa27a8b31f8d876983b Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 25 Oct 2024 18:57:47 -0300 Subject: [PATCH 3/3] Update game.cpp --- src/game/game.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 1148752a7b4..d4e33cfe797 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -6400,11 +6400,11 @@ void Game::checkCreatures() { creature->onThink(EVENT_CREATURE_THINK_INTERVAL); creature->onAttacking(EVENT_CREATURE_THINK_INTERVAL); creature->executeConditions(EVENT_CREATURE_THINK_INTERVAL); - } else { - creature->inCheckCreaturesVector = false; + return false; } - return !creature->inCheckCreaturesVector; + creature->inCheckCreaturesVector = false; + return true; }); index = (index + 1) % EVENT_CREATURECOUNT;