diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 6e11caee7..e1d738078 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -483,8 +483,6 @@ namespace MWMechanics { if (spells.mCorprusSpells.find(it->first) != spells.mCorprusSpells.end()) { - const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(it->first); - if (MWBase::Environment::get().getWorld()->getTimeStamp() >= spells.mCorprusSpells[it->first].mNextWorsening) { spells.worsenCorprus(it->first); diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index da4fa6556..b16fc0aa6 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -44,17 +44,7 @@ namespace MWMechanics } } - bool hasCorprusEffect = false; - for (std::vector::const_iterator effectIt = spell->mEffects.mList.begin(); effectIt != spell->mEffects.mList.end(); ++effectIt) - { - if (effectIt->mEffectID == ESM::MagicEffect::Corprus) - { - hasCorprusEffect = true; - break; - } - } - - if (hasCorprusEffect) + if (hasCorprusEffect(spell)) { CorprusStats corprus; corprus.mWorsenings = 0; @@ -104,15 +94,15 @@ namespace MWMechanics if (iter->second.find(i) != iter->second.end()) random = iter->second.at(i); - int applyTimes = 1; + int magnMult = 1; if (mCorprusSpells.find(spell->mId) != mCorprusSpells.end()) { const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().get().find(spell->mEffects.mList.front().mEffectID); if ((it->mEffectID != ESM::MagicEffect::Corprus) && (effect->mData.mFlags & ESM::MagicEffect::UncappedDamage)) // APPLIED_ONCE - applyTimes += mCorprusSpells.at(spell->mId).mWorsenings; + magnMult += mCorprusSpells.at(spell->mId).mWorsenings; } - for (int j = 0; j < applyTimes; j++) - effects.add (*it, it->mMagnMin + (it->mMagnMax - it->mMagnMin) * random); + + effects.add (*it, (it->mMagnMin + (it->mMagnMax - it->mMagnMin) * random) * magnMult); ++i; } } @@ -253,6 +243,18 @@ namespace MWMechanics mCorprusSpells[corpSpellId].mWorsenings++; } + bool Spells::hasCorprusEffect(const ESM::Spell *spell) + { + for (std::vector::const_iterator effectIt = spell->mEffects.mList.begin(); effectIt != spell->mEffects.mList.end(); ++effectIt) + { + if (effectIt->mEffectID == ESM::MagicEffect::Corprus) + { + return true; + } + } + return false; + } + bool Spells::canUsePower(const std::string &power) const { std::map::const_iterator it = mUsedPowers.find(power); @@ -289,6 +291,16 @@ namespace MWMechanics // No need to discard spells here (doesn't really matter if non existent ids are kept) for (std::map::const_iterator it = state.mUsedPowers.begin(); it != state.mUsedPowers.end(); ++it) mUsedPowers[it->first] = MWWorld::TimeStamp(it->second); + + mCorprusSpells.clear(); + for (std::map::const_iterator it = state.mCorprusSpells.begin(); it != state.mCorprusSpells.end(); ++it) + { + if (mSpells.find(it->first) != mSpells.end()) // Discard unavailable corprus spells + { + mCorprusSpells[it->first].mWorsenings = state.mCorprusSpells.at(it->first).mWorsenings; + mCorprusSpells[it->first].mNextWorsening = MWWorld::TimeStamp(state.mCorprusSpells.at(it->first).mNextWorsening); + } + } } void Spells::writeState(ESM::SpellState &state) const @@ -298,5 +310,11 @@ namespace MWMechanics for (std::map::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it) state.mUsedPowers[it->first] = it->second.toEsm(); + + for (std::map::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it) + { + state.mCorprusSpells[it->first].mWorsenings = mCorprusSpells.at(it->first).mWorsenings; + state.mCorprusSpells[it->first].mNextWorsening = mCorprusSpells.at(it->first).mNextWorsening.toEsm(); + } } } diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 039ad57fa..576aca9af 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -56,6 +56,8 @@ namespace MWMechanics std::map mCorprusSpells; void worsenCorprus(const std::string &corpSpellId); + static bool hasCorprusEffect(const ESM::Spell *spell); + public: bool canUsePower (const std::string& power) const; diff --git a/components/esm/spellstate.cpp b/components/esm/spellstate.cpp index 2dca2dcec..238f93901 100644 --- a/components/esm/spellstate.cpp +++ b/components/esm/spellstate.cpp @@ -27,6 +27,17 @@ namespace ESM mSpells[id] = random; } + while (esm.isNextSub("CORP")) + { + std::string id = esm.getHString(); + + CorprusStats stats; + esm.getHNT(stats.mWorsenings, "WORS"); + esm.getHNT(stats.mNextWorsening, "TIME"); + + mCorprusSpells[id] = stats; + } + while (esm.isNextSub("USED")) { std::string id = esm.getHString(); @@ -53,6 +64,15 @@ namespace ESM } } + for (std::map::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it) + { + esm.writeHNString("CORP", it->first); + + const CorprusStats & stats = it->second; + esm.writeHNT("WORS", stats.mWorsenings); + esm.writeHNT("TIME", stats.mNextWorsening); + } + for (std::map::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it) { esm.writeHNString("USED", it->first); diff --git a/components/esm/spellstate.hpp b/components/esm/spellstate.hpp index cb5c0ff0d..bf8240246 100644 --- a/components/esm/spellstate.hpp +++ b/components/esm/spellstate.hpp @@ -13,9 +13,17 @@ namespace ESM struct SpellState { + struct CorprusStats + { + int mWorsenings; + TimeStamp mNextWorsening; + }; + typedef std::map > TContainer; TContainer mSpells; + std::map mCorprusSpells; + std::map mUsedPowers; std::string mSelectedSpell;