OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
spells.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWMECHANICS_SPELLS_H
2 #define GAME_MWMECHANICS_SPELLS_H
3 
4 #include <map>
5 #include <string>
6 #include <set>
7 
9 
10 #include "../mwworld/ptr.hpp"
11 #include "../mwworld/timestamp.hpp"
12 
13 #include "magiceffects.hpp"
14 
15 
16 namespace ESM
17 {
18  struct Spell;
19 
20  struct SpellState;
21 }
22 
23 namespace MWMechanics
24 {
25  class MagicEffects;
26 
31  class Spells
32  {
33  public:
34 
35  typedef const ESM::Spell* SpellKey;
36  struct SpellParams {
37  std::map<int, float> mEffectRands; // <effect index, normalised random magnitude>
38  std::set<int> mPurgedEffects; // indices of purged effects
39  };
40 
41  typedef std::map<SpellKey, SpellParams> TContainer;
42  typedef TContainer::const_iterator TIterator;
43 
44  struct CorprusStats
45  {
46  static const int sWorseningPeriod = 24;
47 
50  };
51 
52  private:
54 
55  // spell-tied effects that will be applied even after removing the spell (currently used to keep positive effects when corprus is removed)
56  std::map<SpellKey, MagicEffects> mPermanentSpellEffects;
57 
58  // Note: this is the spell that's about to be cast, *not* the spell selected in the GUI (which may be different)
59  std::string mSelectedSpell;
60 
61  std::map<SpellKey, MWWorld::TimeStamp> mUsedPowers;
62 
63  std::map<SpellKey, CorprusStats> mCorprusSpells;
64 
65  mutable bool mSpellsChanged;
67  mutable std::map<SpellKey, MagicEffects> mSourcedEffects;
68  void rebuildEffects() const;
69 
71  const ESM::Spell* getSpell(const std::string& id) const;
72 
73  public:
74  Spells();
75 
76  void worsenCorprus(const ESM::Spell* spell);
77  static bool hasCorprusEffect(const ESM::Spell *spell);
78  const std::map<SpellKey, CorprusStats> & getCorprusSpells() const;
79 
80  void purgeEffect(int effectId);
81  void purgeEffect(int effectId, const std::string & sourceId);
82 
83  bool canUsePower (const ESM::Spell* spell) const;
84  void usePower (const ESM::Spell* spell);
85 
86  void purgeCommonDisease();
87  void purgeBlightDisease();
88  void purgeCorprusDisease();
89  void purgeCurses();
90 
91  TIterator begin() const;
92 
93  TIterator end() const;
94 
95  bool hasSpell(const std::string& spell) const;
96  bool hasSpell(const ESM::Spell* spell) const;
97 
98  void add (const std::string& spell);
100 
101  void add (const ESM::Spell* spell);
103 
104  void remove (const std::string& spell);
107 
110 
111  void clear();
113 
114  void setSelectedSpell (const std::string& spellId);
116 
117  const std::string getSelectedSpell() const;
119 
120  bool isSpellActive(const std::string& id) const;
122 
123  bool hasCommonDisease() const;
124 
125  bool hasBlightDisease() const;
126 
128 
129  void readState (const ESM::SpellState& state);
130  void writeState (ESM::SpellState& state) const;
131  };
132 }
133 
134 #endif
Definition: magiceffects.hpp:73
std::map< SpellKey, MagicEffects > mSourcedEffects
Definition: spells.hpp:67
void clear()
Remove all spells of al types.
Definition: spells.cpp:169
bool hasSpell(const std::string &spell) const
Definition: spells.cpp:76
bool canUsePower(const ESM::Spell *spell) const
Definition: spells.cpp:379
void purgeCurses()
Definition: spells.cpp:267
Effects currently affecting a NPC or creature.
Definition: magiceffects.hpp:83
void rebuildEffects() const
Definition: spells.cpp:38
static const int sWorseningPeriod
Definition: spells.hpp:46
MagicEffects getMagicEffects() const
Return sum of magic effects resulting from abilities, blights, deseases and curses.
Definition: spells.cpp:160
Definition: loadspel.hpp:14
int mWorsenings
Definition: spells.hpp:48
void purgeEffect(int effectId)
Definition: spells.cpp:343
const ESM::Spell * getSpell(const std::string &id) const
Get spell from ID, throws exception if not found.
Definition: spells.cpp:33
void purgeCorprusDisease()
Definition: spells.cpp:252
void writeState(ESM::SpellState &state) const
Definition: spells.cpp:444
std::map< SpellKey, CorprusStats > mCorprusSpells
Definition: spells.hpp:63
Definition: spells.hpp:44
std::map< SpellKey, MagicEffects > mPermanentSpellEffects
Definition: spells.hpp:56
void add(const std::string &spell)
Adding a spell that is already listed in *this is a no-op.
Definition: spells.cpp:119
void worsenCorprus(const ESM::Spell *spell)
Definition: spells.cpp:301
const ESM::Spell * SpellKey
Definition: spells.hpp:35
bool isSpellActive(const std::string &id) const
Are we under the effects of the given spell ID?
Definition: spells.cpp:185
bool mSpellsChanged
Definition: spells.hpp:65
std::string mSelectedSpell
Definition: spells.hpp:59
Spells()
Definition: spells.cpp:18
void purgeBlightDisease()
Definition: spells.cpp:237
void setSelectedSpell(const std::string &spellId)
This function does not verify, if the spell is available.
Definition: spells.cpp:175
const std::string getSelectedSpell() const
May return an empty string.
Definition: spells.cpp:180
bool hasCommonDisease() const
Definition: spells.cpp:198
const std::map< SpellKey, CorprusStats > & getCorprusSpells() const
Definition: spells.cpp:338
void visitEffectSources(MWMechanics::EffectSourceVisitor &visitor) const
Definition: spells.cpp:282
TIterator begin() const
Definition: spells.cpp:23
TContainer::const_iterator TIterator
Definition: spells.hpp:42
TIterator end() const
Definition: spells.cpp:28
bool hasBlightDisease() const
Definition: spells.cpp:210
std::set< int > mPurgedEffects
Definition: spells.hpp:38
In-game time stamp.
Definition: timestamp.hpp:14
Definition: spellstate.hpp:17
void readState(const ESM::SpellState &state)
Definition: spells.cpp:393
MWWorld::TimeStamp mNextWorsening
Definition: spells.hpp:49
std::map< SpellKey, SpellParams > TContainer
Definition: spells.hpp:41
void purgeCommonDisease()
Definition: spells.cpp:222
void usePower(const ESM::Spell *spell)
Definition: spells.cpp:388
std::map< int, float > mEffectRands
Definition: spells.hpp:37
TContainer mSpells
Definition: spells.hpp:53
Definition: spells.hpp:36
Spell list.
Definition: spells.hpp:31
static bool hasCorprusEffect(const ESM::Spell *spell)
Definition: spells.cpp:326
MagicEffects mEffects
Definition: spells.hpp:66
std::map< SpellKey, MWWorld::TimeStamp > mUsedPowers
Definition: spells.hpp:61