diff options
author | Adam Borowski <kilobyte@angband.pl> | 2011-01-18 15:02:29 +0100 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2011-01-18 20:11:56 +0100 |
commit | d8e9352fb109d6525cdf9c4191ee7ff7e3775ae0 (patch) | |
tree | 10f1859db122a97a14c1ef11144b78441504e8d8 /crawl-ref/source/map_knowledge.h | |
parent | 33ab3ac4b2c172208fef19eb4b4f8ece57138ffe (diff) | |
download | crawl-ref-d8e9352fb109d6525cdf9c4191ee7ff7e3775ae0.tar.gz crawl-ref-d8e9352fb109d6525cdf9c4191ee7ff7e3775ae0.zip |
Use a full monsterinfo structure for detected ones rather than a flag.
Diffstat (limited to 'crawl-ref/source/map_knowledge.h')
-rw-r--r-- | crawl-ref/source/map_knowledge.h | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/crawl-ref/source/map_knowledge.h b/crawl-ref/source/map_knowledge.h index 439c8126cf..6a4b35e74c 100644 --- a/crawl-ref/source/map_knowledge.h +++ b/crawl-ref/source/map_knowledge.h @@ -38,37 +38,36 @@ struct map_cell uint32_t flags; // Flags describing the mappedness of this square. map_cell() : flags(0), _feat(DNGN_UNSEEN), _feat_colour(0), - _item(0), _cloud(CLOUD_NONE), _cloud_colour(0) + _item(0), _mons(0), _cloud(CLOUD_NONE), _cloud_colour(0) { - memset(&_mons, 0, sizeof(_mons)); } map_cell(const map_cell& c) { memcpy(this, &c, sizeof(map_cell)); - if (!(flags & MAP_DETECTED_MONSTER) && _mons.info) - _mons.info = new monster_info(*_mons.info); + if (_mons) + _mons = new monster_info(*_mons); if (_item) _item = new item_info(*_item); } ~map_cell() { - if (!(flags & MAP_DETECTED_MONSTER) && _mons.info) - delete _mons.info; + if (!(flags & MAP_DETECTED_MONSTER) && _mons) + delete _mons; if (_item) delete _item; } map_cell& operator=(const map_cell& c) { - if (!(flags & MAP_DETECTED_MONSTER) && _mons.info) - delete _mons.info; + if (_mons) + delete _mons; if (_item) delete _item; memcpy(this, &c, sizeof(map_cell)); - if (!(flags & MAP_DETECTED_MONSTER) && _mons.info) - _mons.info = new monster_info(*_mons.info); + if (_mons) + _mons = new monster_info(*_mons); if (_item) _item = new item_info(*_item); return (*this); @@ -135,26 +134,21 @@ struct map_cell monster_type monster() const { - if (flags & MAP_DETECTED_MONSTER) - return _mons.detected; - else if (_mons.info) - return _mons.info->type; + if (_mons) + return _mons->type; else return MONS_NO_MONSTER; } monster_info* monsterinfo() const { - if (flags & MAP_DETECTED_MONSTER) - return 0; - else - return _mons.info; + return _mons; } void set_monster(const monster_info& mi) { clear_monster(); - _mons.info = new monster_info(mi); + _mons = new monster_info(mi); } bool detected_monster() const @@ -170,7 +164,7 @@ struct map_cell void set_detected_monster(monster_type mons) { clear_monster(); - _mons.detected = mons; + _mons = new monster_info(mons); flags |= MAP_DETECTED_MONSTER; } @@ -182,10 +176,10 @@ struct map_cell void clear_monster() { - if (!(flags & MAP_DETECTED_MONSTER) && _mons.info) - delete _mons.info; + if (_mons) + delete _mons; flags &= ~(MAP_DETECTED_MONSTER | MAP_INVISIBLE_MONSTER); - memset(&_mons, 0, sizeof(_mons)); + _mons = 0; } cloud_type cloud() const @@ -233,11 +227,7 @@ private: dungeon_feature_type _feat; uint8_t _feat_colour; item_info* _item; - union - { - monster_info* info; - monster_type detected; - } _mons; + monster_info* _mons; cloud_type _cloud; uint8_t _cloud_colour; }; |