From 52c7ee3b6ae8a9738289a1728cb02ad8d9a49e1f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 13 Apr 2012 10:49:45 +0200 Subject: [PATCH] moved selected spell from NpcStats to Spells --- apps/openmw/mwmechanics/npcstats.hpp | 5 ++--- apps/openmw/mwmechanics/spells.cpp | 13 +++++++++++++ apps/openmw/mwmechanics/spells.hpp | 11 ++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index ece85f893..b9c672722 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -12,7 +12,8 @@ namespace MWMechanics /// /// For non-NPC-specific stats, see the CreatureStats struct. /// - /// \note For technical reasons the spell list is also handled by CreatureStats. + /// \note For technical reasons the spell list and the currently selected spell is also handled by + /// CreatureStats, even though they are actually NPC stats. struct NpcStats { @@ -28,8 +29,6 @@ namespace MWMechanics bool mSneak; bool mCombat; - std::string mSelectedSpell; // can be an empty string (no spell selected) - NpcStats() : mForceRun (false), mForceSneak (false), mRun (false), mSneak (false), mCombat (false) {} }; diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 4e8c6fa5a..916239a84 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -43,6 +43,9 @@ namespace MWMechanics if (iter!=mSpells.end()) mSpells.erase (iter); + + if (spellId==mSelectedSpell) + mSelectedSpell.clear(); } MagicEffects Spells::getMagicEffects (const MWWorld::Environment& environment) const @@ -65,4 +68,14 @@ namespace MWMechanics { mSpells.clear(); } + + void Spells::setSelectedSpell (const std::string& spellId) + { + mSelectedSpell = spellId; + } + + const std::string Spells::getSelectedSpell() const + { + return mSelectedSpell; + } } diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 4c5f21d35..f7606c4ac 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -32,6 +32,7 @@ namespace MWMechanics private: std::vector mSpells; + std::string mSelectedSpell; void addSpell (const ESM::Spell *, MagicEffects& effects) const; @@ -42,15 +43,23 @@ namespace MWMechanics TIterator end() const; void add (const std::string& spell); - /// \note Adding a spell that is already listed in *this is a no-op. + ///< Adding a spell that is already listed in *this is a no-op. void remove (const std::string& spell); + ///< If the spell to be removed is the selected spell, the selected spell will be changed to + /// no spell (empty string). MagicEffects getMagicEffects (const MWWorld::Environment& environment) const; ///< Return sum of magic effects resulting from abilities, blights, deseases and curses. void clear(); ///< Remove all spells of al types. + + void setSelectedSpell (const std::string& spellId); + ///< This function does not verify, if the spell is available. + + const std::string getSelectedSpell() const; + ///< May return an empty string. }; }