diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index ce3297d61..23f2978e6 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -688,7 +688,9 @@ namespace MWMechanics creatureStats.getActiveSpells().visitEffectSources(updateSummonedCreatures); if (ptr.getClass().hasInventoryStore(ptr)) ptr.getClass().getInventoryStore(ptr).visitEffectSources(updateSummonedCreatures); - updateSummonedCreatures.finish(); + std::set deleted = updateSummonedCreatures.process(); + for (std::set::const_iterator it = deleted.begin(); it != deleted.end(); ++it) + purgeSpellEffects(*it); } void Actors::calculateNpcStatModifiers (const MWWorld::Ptr& ptr, float duration) @@ -1242,11 +1244,7 @@ namespace MWMechanics ++mDeathCount[Misc::StringUtils::lowerCase(iter->first.getCellRef().getRefId())]; // Make sure spell effects are removed - for (PtrActorMap::iterator iter2(mActors.begin());iter2 != mActors.end();++iter2) - { - MWMechanics::ActiveSpells& spells = iter2->first.getClass().getCreatureStats(iter2->first).getActiveSpells(); - spells.purge(stats.getActorId()); - } + purgeSpellEffects(stats.getActorId()); if( iter->first == getPlayer()) { @@ -1261,6 +1259,15 @@ namespace MWMechanics } } + void Actors::purgeSpellEffects(int casterActorId) + { + for (PtrActorMap::iterator iter(mActors.begin());iter != mActors.end();++iter) + { + MWMechanics::ActiveSpells& spells = iter->first.getClass().getCreatureStats(iter->first).getActiveSpells(); + spells.purge(casterActorId); + } + } + void Actors::restoreDynamicStats(bool sleep) { for(PtrActorMap::iterator iter(mActors.begin());iter != mActors.end();++iter) diff --git a/apps/openmw/mwmechanics/actors.hpp b/apps/openmw/mwmechanics/actors.hpp index 6eb062ca2..2dae6b1fb 100644 --- a/apps/openmw/mwmechanics/actors.hpp +++ b/apps/openmw/mwmechanics/actors.hpp @@ -43,6 +43,8 @@ namespace MWMechanics void killDeadActors (); + void purgeSpellEffects (int casterActorId); + public: Actors(); diff --git a/apps/openmw/mwmechanics/summoning.cpp b/apps/openmw/mwmechanics/summoning.cpp index 177378e03..5108e40ff 100644 --- a/apps/openmw/mwmechanics/summoning.cpp +++ b/apps/openmw/mwmechanics/summoning.cpp @@ -61,8 +61,10 @@ namespace MWMechanics } } - void UpdateSummonedCreatures::finish() + std::set UpdateSummonedCreatures::process() { + std::set deletedCreatures; + static std::map summonMap; if (summonMap.empty()) { @@ -101,6 +103,7 @@ namespace MWMechanics { // Effect has ended cleanupSummonedCreature(creatureStats, it->second); + deletedCreatures.insert(it->second); creatureMap.erase(it++); continue; } @@ -188,6 +191,8 @@ namespace MWMechanics else ++it; } + + return deletedCreatures; } } diff --git a/apps/openmw/mwmechanics/summoning.hpp b/apps/openmw/mwmechanics/summoning.hpp index 8e418cdeb..2e1c48856 100644 --- a/apps/openmw/mwmechanics/summoning.hpp +++ b/apps/openmw/mwmechanics/summoning.hpp @@ -21,7 +21,8 @@ namespace MWMechanics float magnitude, float remainingTime = -1, float totalTime = -1); /// To call after all effect sources have been visited - void finish(); + /// Returns list of actorIds for creatures that have been deleted due to the magic effect having expired + std::set process(); private: MWWorld::Ptr mActor;