diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 218d4b420..87f462d6f 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1261,7 +1261,7 @@ namespace MWMechanics { bool found = creatureStats.mBoundItems.find(effect) != creatureStats.mBoundItems.end(); float magnitude = effects.get(effect).getMagnitude(); - if (found != (magnitude > 0) || creatureStats.mBoundItems.empty()) + if (found != (magnitude > 0)) { if (magnitude > 0) creatureStats.mBoundItems.insert(effect); @@ -1281,10 +1281,6 @@ namespace MWMechanics } } } - // mBoundItems does not get saved so the cache is out of date after loading a save. - // Use Length as a sentinel value to force an update. - if(creatureStats.mBoundItems.empty()) - creatureStats.mBoundItems.insert(ESM::MagicEffect::Length); } // Summoned creature update visitor assumes the actor belongs to a cell. diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 4bc0b9a58..c6561af96 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -601,6 +601,28 @@ namespace MWMechanics mAiSequence.readState(state.mAiSequence); mMagicEffects.readState(state.mMagicEffects); + // Rebuild the bound item cache + for(int effectId = ESM::MagicEffect::BoundDagger; effectId <= ESM::MagicEffect::BoundGloves; effectId++) + { + if(mMagicEffects.get(effectId).getMagnitude() > 0) + mBoundItems.insert(effectId); + else + { + // Check active spell effects + // We can't use mActiveSpells::getMagicEffects here because it doesn't include expired effects + auto spell = std::find_if(mActiveSpells.begin(), mActiveSpells.end(), [&] (const auto& spell) + { + const auto& effects = spell.second.mEffects; + return std::find_if(effects.begin(), effects.end(), [&] (const auto& effect) + { + return effect.mEffectId == effectId; + }) != effects.end(); + }); + if(spell != mActiveSpells.end()) + mBoundItems.insert(effectId); + } + } + mSummonedCreatures = state.mSummonedCreatureMap; mSummonGraveyard = state.mSummonGraveyard;