diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 00453eee5..414faa414 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -71,7 +71,7 @@ namespace MWMechanics for (std::vector::const_iterator iter (race->powers.list.begin()); iter!=race->powers.list.end(); ++iter) { - creatureStats.mSpells.add (*iter, mEnvironment); + creatureStats.mSpells.add (*iter); } } @@ -85,7 +85,7 @@ namespace MWMechanics for (std::vector::const_iterator iter (sign->powers.list.begin()); iter!=sign->powers.list.end(); ++iter) { - creatureStats.mSpells.add (*iter, mEnvironment); + creatureStats.mSpells.add (*iter); } } diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 2b28f0c2f..4e8c6fa5a 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -1,7 +1,7 @@ #include "spells.hpp" -#include +#include #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" @@ -21,57 +21,48 @@ namespace MWMechanics } } - Spells::TIterator Spells::begin (ESM::Spell::SpellType type) const + Spells::TIterator Spells::begin() const { - assert (type>=0 && type=0 && typegetStore().spells.find (spellId); - - int type = spell->data.type; - - assert (type>=0 && typegetStore().spells.find (spellId); - - int type = spell->data.type; + TContainer::iterator iter = std::find (mSpells.begin(), mSpells.end(), spellId); - TContainer::iterator iter = std::find (mSpells[type].begin(), mSpells[type].end(), spell); - - if (iter!=mSpells[type].end()) - mSpells[type].erase (iter); + if (iter!=mSpells.end()) + mSpells.erase (iter); } - MagicEffects Spells::getMagicEffects (MWWorld::Environment& environment) const + MagicEffects Spells::getMagicEffects (const MWWorld::Environment& environment) const { MagicEffects effects; - for (int i=ESM::Spell::ST_Ability; i<=ESM::Spell::ST_Curse; ++i) - for (TIterator iter (begin (static_cast (i))); - iter!=end(static_cast (i)); ++iter) - addSpell (*iter, effects); + for (TIterator iter = mSpells.begin(); iter!=mSpells.end(); ++iter) + { + const ESM::Spell *spell = environment.mWorld->getStore().spells.find (*iter); + + if (spell->data.type==ESM::Spell::ST_Ability || spell->data.type==ESM::Spell::ST_Blight || + spell->data.type==ESM::Spell::ST_Disease || spell->data.type==ESM::Spell::ST_Curse) + addSpell (spell, effects); + } return effects; } void Spells::clear() { - for (int i=0; i - #include +#include + +namespace ESM +{ + struct Spell; +} namespace MWWorld { @@ -22,29 +26,27 @@ namespace MWMechanics { public: - typedef std::vector TContainer; + typedef std::vector TContainer; typedef TContainer::const_iterator TIterator; private: - static const int sTypes = 6; - - std::vector mSpells[sTypes]; + std::vector mSpells; void addSpell (const ESM::Spell *, MagicEffects& effects) const; public: - TIterator begin (ESM::Spell::SpellType type) const; + TIterator begin() const; - TIterator end (ESM::Spell::SpellType type) const; + TIterator end() const; - void add (const std::string& spell, MWWorld::Environment& environment); + void add (const std::string& spell); /// \note Adding a spell that is already listed in *this is a no-op. - void remove (const std::string& spell, MWWorld::Environment& environment); + void remove (const std::string& spell); - MagicEffects getMagicEffects (MWWorld::Environment& environment) const; + MagicEffects getMagicEffects (const MWWorld::Environment& environment) const; ///< Return sum of magic effects resulting from abilities, blights, deseases and curses. void clear();