From 1097c2cfc44d4707da1d9ce7b8496192cad21ce8 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Tue, 12 Nov 2019 17:50:06 +0300 Subject: [PATCH 1/2] Minor summoned creature cleanup fixes --- apps/openmw/mwmechanics/actors.cpp | 7 +++++++ apps/openmw/mwmechanics/summoning.cpp | 25 +++++-------------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 486c8b31bc..918c5c303d 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1884,6 +1884,13 @@ namespace MWMechanics if (fx) MWBase::Environment::get().getWorld()->spawnEffect("meshes\\" + fx->mModel, "", ptr.getRefData().getPosition().asVec3()); + + // Remove the summoned creature's summoned creatures as well + MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); + std::map& creatureMap = stats.getSummonedCreatureMap(); + for (const auto& creature : creatureMap) + cleanupSummonedCreature(stats, creature.second); + creatureMap.clear(); } else if (creatureActorId != -1) { diff --git a/apps/openmw/mwmechanics/summoning.cpp b/apps/openmw/mwmechanics/summoning.cpp index e2cbace702..86d0faa9d5 100644 --- a/apps/openmw/mwmechanics/summoning.cpp +++ b/apps/openmw/mwmechanics/summoning.cpp @@ -86,10 +86,9 @@ namespace MWMechanics } // Update summon effects - bool casterDead = creatureStats.isDead(); for (std::map::iterator it = creatureMap.begin(); it != creatureMap.end(); ) { - bool found = !casterDead && mActiveEffects.find(it->first) != mActiveEffects.end(); + bool found = mActiveEffects.find(it->first) != mActiveEffects.end(); if (!found) { // Effect has ended @@ -100,25 +99,11 @@ namespace MWMechanics ++it; } - std::vector& graveyard = creatureStats.getSummonedCreatureGraveyard(); - for (std::vector::iterator it = graveyard.begin(); it != graveyard.end(); ) - { - MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaActorId(*it); - if (!ptr.isEmpty()) - { - it = graveyard.erase(it); + std::vector graveyard = creatureStats.getSummonedCreatureGraveyard(); + creatureStats.getSummonedCreatureGraveyard().clear(); - const ESM::Static* fx = MWBase::Environment::get().getWorld()->getStore().get() - .search("VFX_Summon_End"); - if (fx) - MWBase::Environment::get().getWorld()->spawnEffect("meshes\\" + fx->mModel, - "", ptr.getRefData().getPosition().asVec3()); - - MWBase::Environment::get().getWorld()->deleteObject(ptr); - } - else - ++it; - } + for (const int creature : graveyard) + MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mActor, creature); if (!cleanup) return; From 120b7dcd2fe5e964050b82f82bbddf68d20e8cff Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Tue, 12 Nov 2019 21:44:46 +0300 Subject: [PATCH 2/2] Clean up summoned creatures when corpses are disposed --- apps/openmw/mwgui/container.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 6a303dfbad..f0e025a339 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -248,6 +248,12 @@ namespace MWGui MWScript::InterpreterContext interpreterContext (&mPtr.getRefData().getLocals(), mPtr); MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); } + + // Clean up summoned creatures as well + std::map& creatureMap = creatureStats.getSummonedCreatureMap(); + for (const auto& creature : creatureMap) + MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mPtr, creature.second); + creatureMap.clear(); } MWBase::Environment::get().getWorld()->deleteObject(mPtr);