summaryrefslogtreecommitdiff
path: root/src/monster_type.hpp
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-06-12 06:27:05 +0200
committerBardur Arantsson <bardur@scientician.net>2015-08-01 17:26:10 +0200
commitc6196b25d119a10e79deedef26a73e0d5a021b0e (patch)
tree199f5bff5cf363787eb610caa495fd3682a463ed /src/monster_type.hpp
parent000f6272f8ab1d43ec6300fb5972f7813ada1c88 (diff)
Refactor cave_type and monster_type to use non-intrusive lists
We use vectors of object indexes instead of embedding the list within object_type itself.
Diffstat (limited to 'src/monster_type.hpp')
-rw-r--r--src/monster_type.hpp84
1 files changed, 57 insertions, 27 deletions
diff --git a/src/monster_type.hpp b/src/monster_type.hpp
index ccb555d4..912c97d0 100644
--- a/src/monster_type.hpp
+++ b/src/monster_type.hpp
@@ -3,6 +3,9 @@
#include "h-basic.h"
#include "monster_blow.hpp"
+#include <cassert>
+#include <vector>
+
/**
* Monster information for a specific monster.
*
@@ -13,48 +16,75 @@
*/
struct monster_type
{
- s16b r_idx; /* Monster race index */
+ s16b r_idx = 0; /* Monster race index */
+
+ u16b ego = 0; /* Ego monster type */
+
+ byte fy = 0; /* Y location on map */
+ byte fx = 0; /* X location on map */
+
+ s32b hp = 0; /* Current Hit points */
+ s32b maxhp = 0; /* Max Hit points */
- u16b ego; /* Ego monster type */
+ monster_blow blow[4] = { /* Up to four blows per round */
+ { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 },
+ { 0, 0, 0, 0 },
+ };
- byte fy; /* Y location on map */
- byte fx; /* X location on map */
+ byte speed = 0; /* Speed (normally 110) */
+ byte level = 0; /* Level of creature */
+ s16b ac = 0; /* Armour Class */
+ s32b exp = 0; /* Experience */
- s32b hp; /* Current Hit points */
- s32b maxhp; /* Max Hit points */
+ s16b csleep = 0; /* Inactive counter */
- monster_blow blow[4]; /* Up to four blows per round */
+ byte mspeed = 0; /* Monster "speed" */
+ byte energy = 0; /* Monster "energy" */
- byte speed; /* Speed (normally 110) */
- byte level; /* Level of creature */
- s16b ac; /* Armour Class */
- s32b exp; /* Experience */
+ byte stunned = 0; /* Monster is stunned */
+ byte confused = 0; /* Monster is confused */
+ byte monfear = 0; /* Monster is afraid */
- s16b csleep; /* Inactive counter */
+ s16b bleeding = 0; /* Monster is bleeding */
+ s16b poisoned = 0; /* Monster is poisoned */
- byte mspeed; /* Monster "speed" */
- byte energy; /* Monster "energy" */
+ byte cdis = 0; /* Current dis from player */
- byte stunned; /* Monster is stunned */
- byte confused; /* Monster is confused */
- byte monfear; /* Monster is afraid */
+ s32b mflag = 0; /* Extra monster flags */
- s16b bleeding; /* Monster is bleeding */
- s16b poisoned; /* Monster is poisoned */
+ bool_ ml = FALSE; /* Monster is "visible" */
- byte cdis; /* Current dis from player */
+ std::vector<s16b> hold_o_idxs { }; /* Objects being held */
- s32b mflag; /* Extra monster flags */
+ u32b smart = 0; /* Field for "smart_learn" */
- bool_ ml; /* Monster is "visible" */
+ s16b status = 0; /* Status(friendly, pet, companion, ..) */
- s16b hold_o_idx; /* Object being held (if any) */
+ s16b target = 0; /* Monster target */
- u32b smart; /* Field for "smart_learn" */
+ s16b possessor = 0; /* Is it under the control of a possessor ? */
- s16b status; /* Status(friendly, pet, companion, ..) */
+ /**
+ * @brief wipe the object's state
+ */
+ void wipe()
+ {
+ /* Reset to defaults */
+ *this = monster_type();
+ }
- s16b target; /* Monster target */
+ /**
+ * Get the o_idx of the object being mimicked
+ */
+ s16b mimic_o_idx() const
+ {
+ // We *should* also assert that the monster has flag RF9_MIMIC,
+ // but it's currently not safe since the functions we need for
+ // that are a) expensive, and b) side-effecting via statics.
+ assert(hold_o_idxs.size() == 1); // Mimics are defined by exactly one object
+ return hold_o_idxs.front();
+ }
- s16b possessor; /* Is it under the control of a possessor ? */
};