Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@ bool SpawnsMonster::loadFromXML(const std::string &filemonstername) {
}

void SpawnsMonster::startup() {
if (!isLoaded() || isStarted()) {
if (!isLoaded()) {
return;
}

if (isStarted()) {
for (const auto &spawnMonster : spawnMonsterList) {
spawnMonster->stopEvent();
spawnMonster->removeMonsters();
}
started = false;
}

for (const auto &spawnMonster : spawnMonsterList) {
spawnMonster->startup();
}
Expand All @@ -143,6 +151,7 @@ void SpawnsMonster::startup() {
void SpawnsMonster::clear() {
for (const auto &spawnMonster : spawnMonsterList) {
spawnMonster->stopEvent();
spawnMonster->removeMonsters();
}
spawnMonsterList.clear();

Expand Down Expand Up @@ -181,6 +190,7 @@ void SpawnMonster::startSpawnMonsterCheck() {

SpawnMonster::~SpawnMonster() {
stopEvent();
removeMonsters();
}

// moveable
Expand Down Expand Up @@ -336,6 +346,9 @@ void SpawnMonster::cleanup() {
for (auto it = spawnedMonsterMap.begin(); it != spawnedMonsterMap.end();) {
const auto &monster = it->second;
if (!monster || monster->isRemoved()) {
if (monster) {
monster->setSpawnMonster(nullptr);
}
auto spawnIt = spawnMonsterMap.find(it->first);
if (spawnIt != spawnMonsterMap.end()) {
spawnIt->second.lastSpawn = OTSYS_TIME();
Expand Down Expand Up @@ -425,10 +438,20 @@ void SpawnMonster::removeMonster(const std::shared_ptr<Monster> &monster) {
break;
}
}
spawnedMonsterMap.erase(spawnMonsterId);
if (spawnMonsterId != 0) {
if (monster) {
monster->setSpawnMonster(nullptr);
}
spawnedMonsterMap.erase(spawnMonsterId);
}
}

void SpawnMonster::removeMonsters() {
for (auto &[id, monster] : spawnedMonsterMap) {
if (monster) {
monster->setSpawnMonster(nullptr);
}
}
spawnMonsterMap.clear();
spawnedMonsterMap.clear();
}
Expand Down
Loading