diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 13321bd3914..922f0210000 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -282,16 +282,17 @@ void SpawnMonster::scheduleSpawn(uint32_t spawnMonsterId, spawnBlock_t &sb, cons } void SpawnMonster::cleanup() { - std::vector removeList; - for (const auto &[spawnMonsterId, monster] : spawnedMonsterMap) { - if (monster == nullptr || monster->isRemoved()) { - removeList.push_back(spawnMonsterId); + std::erase_if(spawnedMonsterMap, [this](const auto &entry) { + const auto &monster = entry.second; + if (!monster || monster->isRemoved()) { + auto spawnIt = spawnMonsterMap.find(entry.first); + if (spawnIt != spawnMonsterMap.end()) { + spawnIt->second.lastSpawn = OTSYS_TIME(); + } + return true; } - } - for (const auto &spawnMonsterId : removeList) { - spawnMonsterMap[spawnMonsterId].lastSpawn = OTSYS_TIME(); - spawnedMonsterMap.erase(spawnMonsterId); - } + return false; + }); } bool SpawnMonster::addMonster(const std::string &name, const Position &pos, Direction dir, uint32_t scheduleInterval, uint32_t weight /*= 1*/) {