OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
magiceffects.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWMECHANICS_MAGICEFFECTS_H
2 #define GAME_MWMECHANICS_MAGICEFFECTS_H
3 
4 #include <map>
5 #include <string>
6 
7 namespace ESM
8 {
9  struct ENAMstruct;
10  struct EffectList;
11 
12  struct MagicEffects;
13 }
14 
15 namespace MWMechanics
16 {
17  struct EffectKey
18  {
19  int mId;
20  int mArg; // skill or ability
21 
22  EffectKey();
23 
24  EffectKey (int id, int arg = -1) : mId (id), mArg (arg) {}
25 
26  EffectKey (const ESM::ENAMstruct& effect);
27  };
28 
29  bool operator< (const EffectKey& left, const EffectKey& right);
30 
31  struct EffectParam
32  {
33  private:
34  // Note usually this would be int, but applying partial resistance might introduce a decimal point.
35  float mModifier;
36 
37  int mBase;
38 
39  public:
41  float getMagnitude() const;
42 
43  void setModifier(float mod);
44  float getModifier() const;
45 
47  void modifyBase(int diff);
48  void setBase(int base);
49  int getBase() const;
50 
51  EffectParam();
52 
53  EffectParam(float magnitude) : mModifier(magnitude), mBase(0) {}
54 
55  EffectParam& operator+= (const EffectParam& param);
56 
57  EffectParam& operator-= (const EffectParam& param);
58  };
59 
60  inline EffectParam operator+ (const EffectParam& left, const EffectParam& right)
61  {
62  EffectParam param (left);
63  return param += right;
64  }
65 
66  inline EffectParam operator- (const EffectParam& left, const EffectParam& right)
67  {
68  EffectParam param (left);
69  return param -= right;
70  }
71 
72  // Used by effect management classes (ActiveSpells, InventoryStore, Spells) to list active effect sources for GUI display
74  {
75  virtual ~EffectSourceVisitor() { }
76 
77  virtual void visit (MWMechanics::EffectKey key,
78  const std::string& sourceName, const std::string& sourceId, int casterActorId,
79  float magnitude, float remainingTime = -1, float totalTime = -1) = 0;
80  };
81 
84  {
85  public:
86 
87  typedef std::map<EffectKey, EffectParam> Collection;
88 
89  private:
90 
92 
93  public:
94 
95  Collection::const_iterator begin() const { return mCollection.begin(); }
96 
97  Collection::const_iterator end() const { return mCollection.end(); }
98 
99  void readState (const ESM::MagicEffects& state);
100  void writeState (ESM::MagicEffects& state) const;
101 
102  void add (const EffectKey& key, const EffectParam& param);
103  void remove (const EffectKey& key);
104 
105  void modifyBase (const EffectKey& key, int diff);
106 
108  void setModifiers(const MagicEffects& effects);
109 
110  MagicEffects& operator+= (const MagicEffects& effects);
111 
112  EffectParam get (const EffectKey& key) const;
114 
115  static MagicEffects diff (const MagicEffects& prev, const MagicEffects& now);
117  };
118 }
119 
120 #endif
Definition: magiceffects.hpp:73
void writeState(ESM::MagicEffects &state) const
Definition: magiceffects.cpp:196
EffectKey(int id, int arg=-1)
Definition: magiceffects.hpp:24
Effects currently affecting a NPC or creature.
Definition: magiceffects.hpp:83
int getBase() const
Definition: magiceffects.cpp:53
EffectKey()
Definition: magiceffects.cpp:12
Collection::const_iterator end() const
Definition: magiceffects.hpp:97
Definition: magiceffects.hpp:31
int mBase
Definition: magiceffects.hpp:37
virtual ~EffectSourceVisitor()
Definition: magiceffects.hpp:75
float getMagnitude() const
Get the total magnitude including base and modifier.
Definition: magiceffects.cpp:43
std::map< EffectKey, EffectParam > Collection
Definition: magiceffects.hpp:87
Definition: effectlist.hpp:17
MagicEffects & operator+=(const MagicEffects &effects)
Definition: magiceffects.cpp:126
static MagicEffects diff(const MagicEffects &prev, const MagicEffects &now)
Return changes from prev to now.
Definition: magiceffects.cpp:162
void add(const EffectKey &key, const EffectParam &param)
Definition: magiceffects.cpp:94
virtual void visit(MWMechanics::EffectKey key, const std::string &sourceName, const std::string &sourceId, int casterActorId, float magnitude, float remainingTime=-1, float totalTime=-1)=0
Definition: magiceffects.hpp:17
EffectParam()
Definition: magiceffects.cpp:73
void modifyBase(const EffectKey &key, int diff)
Definition: magiceffects.cpp:108
Definition: magiceffects.hpp:12
float mModifier
Definition: magiceffects.hpp:35
EffectParam & operator+=(const EffectParam &param)
Definition: magiceffects.cpp:75
Collection::const_iterator begin() const
Definition: magiceffects.hpp:95
int mId
Definition: magiceffects.hpp:19
void setModifier(float mod)
Definition: magiceffects.cpp:63
bool operator<(const EffectKey &left, const EffectKey &right)
Definition: magiceffects.cpp:32
EffectParam operator+(const EffectParam &left, const EffectParam &right)
Definition: magiceffects.hpp:60
Collection mCollection
Definition: magiceffects.hpp:91
EffectParam operator-(const EffectParam &left, const EffectParam &right)
Definition: magiceffects.hpp:66
EffectParam(float magnitude)
Definition: magiceffects.hpp:53
int mArg
Definition: magiceffects.hpp:20
void setModifiers(const MagicEffects &effects)
Copy Modifier values from effects, but keep original mBase values.
Definition: magiceffects.cpp:113
void setBase(int base)
Definition: magiceffects.cpp:58
EffectParam & operator-=(const EffectParam &param)
Definition: magiceffects.cpp:82
void readState(const ESM::MagicEffects &state)
Definition: magiceffects.cpp:209
void modifyBase(int diff)
Change mBase by diff.
Definition: magiceffects.cpp:48
float getModifier() const
Definition: magiceffects.cpp:68