From 750d79eaf032ca8bd21f33899853e5a3595e311c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 11 Apr 2012 18:29:36 +0200 Subject: [PATCH] added spell container class --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwmechanics/spells.cpp | 77 ++++++++++++++++++++++++++++++ apps/openmw/mwmechanics/spells.hpp | 55 +++++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 apps/openmw/mwmechanics/spells.cpp create mode 100644 apps/openmw/mwmechanics/spells.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c31a9d8fd..79f0948f9 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -55,7 +55,7 @@ add_openmw_dir (mwclass ) add_openmw_dir (mwmechanics - mechanicsmanager stat creaturestats magiceffects movement + mechanicsmanager stat creaturestats magiceffects movement spells ) # Main executable diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp new file mode 100644 index 000000000..2b28f0c2f --- /dev/null +++ b/apps/openmw/mwmechanics/spells.cpp @@ -0,0 +1,77 @@ + +#include "spells.hpp" + +#include + +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "magiceffects.hpp" + +namespace MWMechanics +{ + void Spells::addSpell (const ESM::Spell *spell, MagicEffects& effects) const + { + for (std::vector::const_iterator iter = spell->effects.list.begin(); + iter!=spell->effects.list.end(); ++iter) + { + EffectParam param; + param.mMagnitude = iter->magnMax; /// \todo calculate magnitude + effects.add (EffectKey (*iter), param); + } + } + + Spells::TIterator Spells::begin (ESM::Spell::SpellType type) 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[type].begin(), mSpells[type].end(), spell); + + if (iter!=mSpells[type].end()) + mSpells[type].erase (iter); + } + + MagicEffects Spells::getMagicEffects (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); + + return effects; + } + + void Spells::clear() + { + for (int i=0; i + +#include + +namespace MWWorld +{ + struct Environment; +} + +namespace MWMechanics +{ + class MagicEffects; + + /// \brief Spell list + /// + /// This class manages known spells as well as abilities, powers and permanent negative effects like + /// diseaes. + class Spells + { + public: + + typedef std::vector TContainer; + typedef TContainer::const_iterator TIterator; + + private: + + static const int sTypes = 6; + + std::vector mSpells[sTypes]; + + void addSpell (const ESM::Spell *, MagicEffects& effects) const; + + public: + + TIterator begin (ESM::Spell::SpellType type) const; + + TIterator end (ESM::Spell::SpellType type) const; + + void add (const std::string& spell, MWWorld::Environment& environment); + /// \note Adding a spell that is already listed in *this is a no-op. + + void remove (const std::string& spell, MWWorld::Environment& environment); + + MagicEffects getMagicEffects (MWWorld::Environment& environment) const; + ///< Return sum of magic effects resulting from abilities, blights, deseases and curses. + + void clear(); + ///< Remove all spells of al types. + }; +} + +#endif