From c8a270e51dc22f39ed048ab1cc609e6e456df58f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 7 Jun 2015 17:49:09 +0200 Subject: Split types.h into separate header for each type --- src/monster_type.hpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/monster_type.hpp (limited to 'src/monster_type.hpp') diff --git a/src/monster_type.hpp b/src/monster_type.hpp new file mode 100644 index 00000000..ccb555d4 --- /dev/null +++ b/src/monster_type.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include "h-basic.h" +#include "monster_blow.hpp" + +/** + * Monster information for a specific monster. + * + * Note: fy, fx constrain dungeon size to 256x256 + * + * The "hold_o_idx" field points to the first object of a stack + * of objects (if any) being carried by the monster (see above). + */ +struct monster_type +{ + s16b r_idx; /* Monster race index */ + + u16b ego; /* Ego monster type */ + + byte fy; /* Y location on map */ + byte fx; /* X location on map */ + + s32b hp; /* Current Hit points */ + s32b maxhp; /* Max Hit points */ + + monster_blow blow[4]; /* Up to four blows per round */ + + byte speed; /* Speed (normally 110) */ + byte level; /* Level of creature */ + s16b ac; /* Armour Class */ + s32b exp; /* Experience */ + + s16b csleep; /* Inactive counter */ + + byte mspeed; /* Monster "speed" */ + byte energy; /* Monster "energy" */ + + byte stunned; /* Monster is stunned */ + byte confused; /* Monster is confused */ + byte monfear; /* Monster is afraid */ + + s16b bleeding; /* Monster is bleeding */ + s16b poisoned; /* Monster is poisoned */ + + byte cdis; /* Current dis from player */ + + s32b mflag; /* Extra monster flags */ + + bool_ ml; /* Monster is "visible" */ + + s16b hold_o_idx; /* Object being held (if any) */ + + u32b smart; /* Field for "smart_learn" */ + + s16b status; /* Status(friendly, pet, companion, ..) */ + + s16b target; /* Monster target */ + + s16b possessor; /* Is it under the control of a possessor ? */ +}; -- cgit v1.2.3 From c6196b25d119a10e79deedef26a73e0d5a021b0e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 12 Jun 2015 06:27:05 +0200 Subject: 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. --- src/monster_type.hpp | 84 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 27 deletions(-) (limited to 'src/monster_type.hpp') 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 +#include + /** * 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 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 ? */ }; -- cgit v1.2.3 From 00be445e9127922933dae91a3d68660a57f53c5b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Refactor race_info_idx() to avoid "invisible" static pointers --- src/monster_type.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/monster_type.hpp') diff --git a/src/monster_type.hpp b/src/monster_type.hpp index 912c97d0..8353f228 100644 --- a/src/monster_type.hpp +++ b/src/monster_type.hpp @@ -2,9 +2,11 @@ #include "h-basic.h" #include "monster_blow.hpp" +#include "monster_race_fwd.hpp" #include #include +#include /** * Monster information for a specific monster. @@ -66,6 +68,12 @@ struct monster_type s16b possessor = 0; /* Is it under the control of a possessor ? */ + /** + * @brief get the "effective race" of the monster. This incorporates + * the effects of the "ego" of the monster, if any. + */ + std::shared_ptr race() const; + /** * @brief wipe the object's state */ -- cgit v1.2.3 From f693888666c64c75a636be3504e6decb55f2865b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Give monster_blow default values --- src/monster_type.hpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/monster_type.hpp') diff --git a/src/monster_type.hpp b/src/monster_type.hpp index 8353f228..ed6d3d2a 100644 --- a/src/monster_type.hpp +++ b/src/monster_type.hpp @@ -4,6 +4,7 @@ #include "monster_blow.hpp" #include "monster_race_fwd.hpp" +#include #include #include #include @@ -28,12 +29,7 @@ struct monster_type s32b hp = 0; /* Current Hit points */ s32b maxhp = 0; /* Max Hit points */ - 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 }, - }; + std::array blow {};/* Up to four blows per round */ byte speed = 0; /* Speed (normally 110) */ byte level = 0; /* Level of creature */ -- cgit v1.2.3