OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
creaturestats.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWMECHANICS_CREATURESTATS_H
2 #define GAME_MWMECHANICS_CREATURESTATS_H
3 
4 #include <set>
5 #include <string>
6 #include <stdexcept>
7 
8 #include "stat.hpp"
9 #include "magiceffects.hpp"
10 #include "spells.hpp"
11 #include "activespells.hpp"
12 #include "aisequence.hpp"
13 #include "drawstate.hpp"
14 
15 namespace ESM
16 {
17  struct CreatureStats;
18 }
19 
20 namespace MWMechanics
21 {
26  {
27  static int sActorId;
30  DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
36  bool mDead;
38  bool mDied; // flag for OnDeath script function
39  bool mMurdered;
41  bool mTalkedTo;
42  bool mAlarmed;
43  bool mAttacked;
44  bool mKnockdown;
48  bool mBlock;
49  unsigned int mMovementFlags;
50 
51  float mFallHeight;
52 
53  std::string mLastHitObject; // The last object to hit this actor
54  std::string mLastHitAttemptObject; // The last object to attempt to hit this actor
55 
57 
58  // For merchants: the last time items were restocked and gold pool refilled.
60 
61  // The pool of merchant gold (not in inventory)
62  int mGoldPool;
63 
64  int mActorId;
65 
66  // The index of the death animation that was played, or -1 if none played
67  signed char mDeathAnimation;
68 
70 
71  public:
72  typedef std::pair<int, std::string> SummonKey; // <ESM::MagicEffect index, spell ID>
73  private:
74  std::map<SummonKey, int> mSummonedCreatures; // <SummonKey, ActorId>
75 
76  // Contains ActorIds of summoned creatures with an expired lifetime that have not been deleted yet.
77  // This may be necessary when the creature is in an inactive cell.
78  std::vector<int> mSummonGraveyard;
79 
80  protected:
81  int mLevel;
82 
83  public:
84  CreatureStats();
85 
86  DrawState_ getDrawState() const;
87  void setDrawState(DrawState_ state);
88 
90  void setNeedRecalcDynamicStats(bool val);
91 
92  void addToFallHeight(float height);
93 
96  float land();
97 
98  const AttributeValue & getAttribute(int index) const;
99 
100  const DynamicStat<float> & getHealth() const;
101 
102  const DynamicStat<float> & getMagicka() const;
103 
104  const DynamicStat<float> & getFatigue() const;
105 
106  const DynamicStat<float> & getDynamic (int index) const;
107 
108  const Spells & getSpells() const;
109 
110  const ActiveSpells & getActiveSpells() const;
111 
112  const MagicEffects & getMagicEffects() const;
113 
114  bool getAttackingOrSpell() const;
115 
116  int getLevel() const;
117 
118  Spells & getSpells();
119 
121 
123 
124  void setAttribute(int index, const AttributeValue &value);
125  // Shortcut to set only the base
126  void setAttribute(int index, int base);
127 
128  void setHealth(const DynamicStat<float> &value);
129 
130  void setMagicka(const DynamicStat<float> &value);
131 
132  void setFatigue(const DynamicStat<float> &value);
133 
134  void setDynamic (int index, const DynamicStat<float> &value);
135 
137  void modifyMagicEffects(const MagicEffects &effects);
138 
139  void setAttackingOrSpell(bool attackingOrSpell);
140 
141  void setLevel(int level);
142 
144  {
145  AI_Hello = 0,
146  AI_Fight = 1,
147  AI_Flee = 2,
149  };
150  void setAiSetting (AiSetting index, Stat<int> value);
151  void setAiSetting (AiSetting index, int base);
152  Stat<int> getAiSetting (AiSetting index) const;
153 
154  const AiSequence& getAiSequence() const;
155 
157 
158  float getFatigueTerm() const;
160 
161  bool isParalyzed() const;
162 
163  bool isDead() const;
164 
165  bool isDeathAnimationFinished() const;
166  void setDeathAnimationFinished(bool finished);
167 
168  void notifyDied();
169 
170  bool hasDied() const;
171 
172  void clearHasDied();
173 
174  bool hasBeenMurdered() const;
175 
176  void clearHasBeenMurdered();
177 
178  void notifyMurder();
179 
180  void resurrect();
181 
182  bool hasCommonDisease() const;
183 
184  bool hasBlightDisease() const;
185 
186  int getFriendlyHits() const;
188 
189  void friendlyHit();
191 
192  bool hasTalkedToPlayer() const;
194 
195  void talkedToPlayer();
196 
197  bool isAlarmed() const;
198  void setAlarmed (bool alarmed);
199 
200  bool getAttacked() const;
201  void setAttacked (bool attacked);
202 
203  float getEvasion() const;
204 
205  void setKnockedDown(bool value);
208  bool getKnockedDown() const;
209  void setKnockedDownOneFrame(bool value);
211  bool getKnockedDownOneFrame() const;
212  void setKnockedDownOverOneFrame(bool value);
214  bool getKnockedDownOverOneFrame() const;
215  void setHitRecovery(bool value);
216  bool getHitRecovery() const;
217  void setBlock(bool value);
218  bool getBlock() const;
219 
220  std::map<SummonKey, int>& getSummonedCreatureMap(); // <SummonKey, ActorId of summoned creature>
221  std::vector<int>& getSummonedCreatureGraveyard(); // ActorIds
222 
223  enum Flag
224  {
227  Flag_Run = 4,
231  };
232  enum Stance
233  {
236  };
237 
238  bool getMovementFlag (Flag flag) const;
239  void setMovementFlag (Flag flag, bool state);
241  bool getStance (Stance flag) const;
242 
243  void setLastHitObject(const std::string &objectid);
244  void setLastHitAttemptObject(const std::string &objectid);
245  const std::string &getLastHitObject() const;
246  const std::string &getLastHitAttemptObject() const;
247 
248  // Note, this is just a cache to avoid checking the whole container store every frame. We don't need to store it in saves.
249  // TODO: Put it somewhere else?
250  std::set<int> mBoundItems;
251 
252  void writeState (ESM::CreatureStats& state) const;
253 
254  void readState (const ESM::CreatureStats& state);
255 
256  static void writeActorIdCounter (ESM::ESMWriter& esm);
257  static void readActorIdCounter (ESM::ESMReader& esm);
258 
259  void setLastRestockTime(MWWorld::TimeStamp tradeTime);
261 
262  void setGoldPool(int pool);
263  int getGoldPool() const;
264 
265  signed char getDeathAnimation() const; // -1 means not decided
266  void setDeathAnimation(signed char index);
267 
269 
270  int getActorId();
272 
273  bool matchesActorId (int id) const;
276 
277  static void cleanup();
278  };
279 }
280 
281 #endif
bool hasBeenMurdered() const
Definition: creaturestats.cpp:266
bool getAttacked() const
Definition: creaturestats.cpp:334
static void cleanup()
Definition: creaturestats.cpp:618
MagicEffects mMagicEffects
Definition: creaturestats.hpp:33
bool getHitRecovery() const
Definition: creaturestats.cpp:435
void notifyMurder()
Definition: creaturestats.cpp:271
Definition: stat.hpp:108
void modifyMagicEffects(const MagicEffects &effects)
Set Modifier for each magic effect according to effects. Does not touch Base values.
Definition: creaturestats.cpp:210
AiSetting
Definition: creaturestats.hpp:143
std::string mLastHitObject
Definition: creaturestats.hpp:53
bool mKnockdownOverOneFrame
Definition: creaturestats.hpp:46
bool mAttacked
Definition: creaturestats.hpp:43
bool mRecalcMagicka
Definition: creaturestats.hpp:56
float getFatigueTerm() const
Return effective fatigue.
Definition: creaturestats.cpp:41
bool isAlarmed() const
Definition: creaturestats.cpp:324
Effects currently affecting a NPC or creature.
Definition: magiceffects.hpp:83
bool isParalyzed() const
Definition: creaturestats.cpp:231
const std::string & getLastHitAttemptObject() const
Definition: creaturestats.cpp:369
bool isDeathAnimationFinished() const
Definition: creaturestats.cpp:241
bool hasBlightDisease() const
Definition: creaturestats.cpp:299
std::string mLastHitAttemptObject
Definition: creaturestats.hpp:54
float land()
Definition: creaturestats.cpp:379
Definition: esmreader.hpp:21
bool needToRecalcDynamicStats()
Definition: creaturestats.cpp:386
Stat< int > mAiSettings[4]
Definition: creaturestats.hpp:34
MWWorld::TimeStamp mLastRestock
Definition: creaturestats.hpp:59
Common creature stats.
Definition: creaturestats.hpp:25
DrawState_ mDrawState
Definition: creaturestats.hpp:28
const MagicEffects & getMagicEffects() const
Definition: creaturestats.cpp:90
bool getKnockedDownOverOneFrame() const
Returns true for all but the first frame of being knocked out; used to know to not reset mKnockedDown...
Definition: creaturestats.cpp:426
bool mBlock
Definition: creaturestats.hpp:48
bool mAlarmed
Definition: creaturestats.hpp:42
void setFatigue(const DynamicStat< float > &value)
Definition: creaturestats.cpp:178
void setDeathAnimationFinished(bool finished)
Definition: creaturestats.cpp:246
bool mMurdered
Definition: creaturestats.hpp:39
ActiveSpells mActiveSpells
Definition: creaturestats.hpp:32
bool getMovementFlag(Flag flag) const
Definition: creaturestats.cpp:450
static int sActorId
Definition: creaturestats.hpp:27
const DynamicStat< float > & getDynamic(int index) const
Definition: creaturestats.cpp:105
Definition: creaturestats.hpp:229
const DynamicStat< float > & getFatigue() const
Definition: creaturestats.cpp:75
bool mDied
Definition: creaturestats.hpp:38
int getActorId()
Will generate an actor ID, if the actor does not have one yet.
Definition: creaturestats.cpp:605
void setAttribute(int index, const AttributeValue &value)
Definition: creaturestats.cpp:135
void setBlock(bool value)
Definition: creaturestats.cpp:440
void setMovementFlag(Flag flag, bool state)
Definition: creaturestats.cpp:455
Definition: creaturestats.hpp:145
float getEvasion() const
Definition: creaturestats.cpp:344
CreatureStats()
Definition: creaturestats.cpp:19
void clearHasBeenMurdered()
Definition: creaturestats.cpp:276
Sequence of AI-packages for a single actor.
Definition: aisequence.hpp:34
void setLastRestockTime(MWWorld::TimeStamp tradeTime)
Definition: creaturestats.cpp:586
Definition: creaturestats.hpp:230
Definition: creaturestats.hpp:234
void setGoldPool(int pool)
Definition: creaturestats.cpp:596
MWWorld::TimeStamp getTimeOfDeath() const
Definition: creaturestats.cpp:645
unsigned int mMovementFlags
Definition: creaturestats.hpp:49
Definition: creaturestats.hpp:146
int mActorId
Definition: creaturestats.hpp:64
void setLastHitObject(const std::string &objectid)
Definition: creaturestats.cpp:354
int getGoldPool() const
Definition: creaturestats.cpp:600
Definition: esmwriter.hpp:17
const AttributeValue & getAttribute(int index) const
Definition: creaturestats.cpp:57
Definition: creaturestats.hpp:226
bool isDead() const
Definition: creaturestats.cpp:236
void setNeedRecalcDynamicStats(bool val)
Definition: creaturestats.cpp:396
Flag
Definition: creaturestats.hpp:223
DrawState_ getDrawState() const
Definition: creaturestats.cpp:476
const DynamicStat< float > & getHealth() const
Definition: creaturestats.cpp:65
Definition: creaturestats.hpp:225
Definition: creaturestats.hpp:23
std::map< SummonKey, int > mSummonedCreatures
Definition: creaturestats.hpp:74
static void writeActorIdCounter(ESM::ESMWriter &esm)
Definition: creaturestats.cpp:623
int getLevel() const
Definition: creaturestats.cpp:95
void setLastHitAttemptObject(const std::string &objectid)
Definition: creaturestats.cpp:364
AiSequence mAiSequence
Definition: creaturestats.hpp:35
int getFriendlyHits() const
Number of friendly hits received.
Definition: creaturestats.cpp:304
const AiSequence & getAiSequence() const
Definition: creaturestats.cpp:31
const Spells & getSpells() const
Definition: creaturestats.cpp:80
bool mKnockdownOneFrame
Definition: creaturestats.hpp:45
DrawState_
Definition: drawstate.hpp:7
bool mDeathAnimationFinished
Definition: creaturestats.hpp:37
AttributeValue mAttributes[8]
Definition: creaturestats.hpp:29
void setLevel(int level)
Definition: creaturestats.cpp:205
void talkedToPlayer()
Definition: creaturestats.cpp:319
void setDynamic(int index, const DynamicStat< float > &value)
Definition: creaturestats.cpp:183
bool getKnockedDownOneFrame() const
Returns true only for the first frame of the actor being knocked out; used for "onKnockedOut" command...
Definition: creaturestats.cpp:418
const DynamicStat< float > & getMagicka() const
Definition: creaturestats.cpp:70
void addToFallHeight(float height)
Definition: creaturestats.cpp:374
bool mTalkedTo
Definition: creaturestats.hpp:41
int mLevel
Definition: creaturestats.hpp:81
std::pair< int, std::string > SummonKey
Definition: creaturestats.hpp:72
bool getAttackingOrSpell() const
void setKnockedDownOneFrame(bool value)
Definition: creaturestats.cpp:413
bool hasDied() const
Definition: creaturestats.cpp:256
void setAlarmed(bool alarmed)
Definition: creaturestats.cpp:329
void resurrect()
Definition: creaturestats.cpp:281
Definition: creaturestats.hpp:148
float mFallHeight
Definition: creaturestats.hpp:51
void setDrawState(DrawState_ state)
Definition: creaturestats.cpp:481
void friendlyHit()
Increase number of friendly hits by one.
Definition: creaturestats.cpp:309
Definition: creaturestats.hpp:227
const std::string & getLastHitObject() const
Definition: creaturestats.cpp:359
void setHealth(const DynamicStat< float > &value)
Definition: creaturestats.cpp:168
bool mDead
Definition: creaturestats.hpp:36
std::vector< int > & getSummonedCreatureGraveyard()
Definition: creaturestats.cpp:655
void clearHasDied()
Definition: creaturestats.cpp:261
Definition: creaturestats.hpp:228
In-game time stamp.
Definition: timestamp.hpp:14
std::map< SummonKey, int > & getSummonedCreatureMap()
Definition: creaturestats.cpp:650
signed char mDeathAnimation
Definition: creaturestats.hpp:67
void setAttacked(bool attacked)
Definition: creaturestats.cpp:339
MWWorld::TimeStamp mTimeOfDeath
Definition: creaturestats.hpp:69
std::set< int > mBoundItems
Definition: creaturestats.hpp:250
bool mKnockdown
Definition: creaturestats.hpp:44
static void readActorIdCounter(ESM::ESMReader &esm)
Definition: creaturestats.cpp:630
const ActiveSpells & getActiveSpells() const
Definition: creaturestats.cpp:85
MWWorld::TimeStamp getLastRestockTime() const
Definition: creaturestats.cpp:591
void setKnockedDown(bool value)
Definition: creaturestats.cpp:401
Definition: creaturestats.hpp:235
void setDeathAnimation(signed char index)
Definition: creaturestats.cpp:640
Stance
Definition: creaturestats.hpp:232
void setHitRecovery(bool value)
Definition: creaturestats.cpp:430
bool hasTalkedToPlayer() const
Has this creature talked with the player before?
Definition: creaturestats.cpp:314
bool getKnockedDown() const
Definition: creaturestats.cpp:408
Spell list.
Definition: spells.hpp:31
std::vector< int > mSummonGraveyard
Definition: creaturestats.hpp:78
void setMagicka(const DynamicStat< float > &value)
Definition: creaturestats.cpp:173
bool getBlock() const
Definition: creaturestats.cpp:445
Definition: creaturestats.hpp:147
Stat< int > getAiSetting(AiSetting index) const
Definition: creaturestats.cpp:100
int mGoldPool
Definition: creaturestats.hpp:62
void setAttackingOrSpell(bool attackingOrSpell)
signed char getDeathAnimation() const
Definition: creaturestats.cpp:635
void readState(const ESM::CreatureStats &state)
Definition: creaturestats.cpp:538
void setKnockedDownOverOneFrame(bool value)
Definition: creaturestats.cpp:423
void writeState(ESM::CreatureStats &state) const
Definition: creaturestats.cpp:486
bool hasCommonDisease() const
Definition: creaturestats.cpp:294
void notifyDied()
Definition: creaturestats.cpp:251
void setAiSetting(AiSetting index, Stat< int > value)
Definition: creaturestats.cpp:219
bool mHitRecovery
Definition: creaturestats.hpp:47
DynamicStat< float > mDynamic[3]
Definition: creaturestats.hpp:30
bool matchesActorId(int id) const
Definition: creaturestats.cpp:613
Lasting spell effects.
Definition: activespells.hpp:21
int mFriendlyHits
Definition: creaturestats.hpp:40
Spells mSpells
Definition: creaturestats.hpp:31
bool getStance(Stance flag) const
Like getMovementFlag, but also takes into account if the flag is Forced.
Definition: creaturestats.cpp:463