diff options
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/debug.cc | 13 | ||||
-rw-r--r-- | crawl-ref/source/dungeon.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/externs.h | 10 | ||||
-rw-r--r-- | crawl-ref/source/items.cc | 27 | ||||
-rw-r--r-- | crawl-ref/source/makeitem.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/misc.cc | 6 | ||||
-rw-r--r-- | crawl-ref/source/mon-util.cc | 22 | ||||
-rw-r--r-- | crawl-ref/source/mon-util.h | 3 | ||||
-rw-r--r-- | crawl-ref/source/mstuff2.cc | 1 |
9 files changed, 50 insertions, 36 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index 3ff7d97624..6e9924cd0b 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -2489,7 +2489,7 @@ void wizard_list_items() for (int i = 0; i < MAX_ITEMS; i++) { item_def &item(mitm[i]); - if (!is_valid_item(item) || held_by_monster(item)) + if (!is_valid_item(item) || item.held_by_monster()) continue; if (item.link != NON_ITEM) @@ -2728,7 +2728,7 @@ void debug_item_scan( void ) strcpy(name, mitm[i].name(DESC_PLAIN).c_str()); - const monsters* mon = holding_monster(mitm[i]); + const monsters* mon = mitm[i].holding_monster(); // Don't check (-1, -1) player items or (-2, -2) monster items // (except to make sure that the monster is alive). @@ -3007,7 +3007,7 @@ void debug_mons_scan() continue; } - const monsters* holder = holding_monster(item); + const monsters* holder = item.holding_monster(); if (holder == NULL) { @@ -3031,6 +3031,7 @@ void debug_mons_scan() "monster %s (%d, %d) [midx = %d]", m->full_name(DESC_PLAIN, true).c_str(), m->pos().x, m->pos().y, i, + item.name(DESC_PLAIN).c_str(), holder->full_name(DESC_PLAIN, true).c_str(), holder->pos().x, holder->pos().y, holder->mindex()); @@ -6680,12 +6681,12 @@ void debug_dump_mon(const monsters* mon, bool recurse) fprintf(stderr, "%s", item.name(DESC_PLAIN, false, true).c_str()); - if (!held_by_monster(item)) + if (!item.held_by_monster()) fprintf(stderr, " [not held by monster, pos = %s]", debug_coord_str(item.pos).c_str()); - else if (holding_monster(item) != mon) + else if (item.holding_monster() != mon) fprintf(stderr, " [held by other monster: %s]", - debug_mon_str(holding_monster(item)).c_str()); + debug_mon_str(item.holding_monster()).c_str()); fprintf(stderr, EOL); } diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index e5b51ee0cf..3930a08826 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -1089,7 +1089,7 @@ static void _fixup_misplaced_items() { item_def& item(mitm[i]); if (!is_valid_item(item) || (item.pos.x == 0) - || held_by_monster(item)) + || item.held_by_monster()) { continue; } diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 0e773c455f..e94cc0c68c 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -620,6 +620,16 @@ public: { *this = item_def(); } + + // Sets this item as being held by a given monster. + void set_holding_monster(int midx); + + // Returns monster holding this item. NULL if none. + monsters* holding_monster() const; + + // Returns true if a monster is holding this item. + bool held_by_monster() const; + private: std::string name_aux(description_level_type desc, bool terse, bool ident, diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 24d63b7dd9..d13e974967 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -114,7 +114,7 @@ void link_items(void) { // Don't mess with monster held items, since the index of the holding // monster is stored in the link field. - if (held_by_monster(mitm[i])) + if (mitm[i].held_by_monster()) continue; if (!is_valid_item(mitm[i])) @@ -368,7 +368,7 @@ void unlink_item( int dest ) if (dest == NON_ITEM || !is_valid_item( mitm[dest] )) return; - monsters* monster = holding_monster(mitm[dest]); + monsters* monster = mitm[dest].holding_monster(); if (monster != NULL) { @@ -2688,3 +2688,26 @@ int item_def::armour_rating() const return (property(*this, PARM_AC) + plus); } + +monsters* item_def::holding_monster() const +{ + if (!pos.equals(-2, -2)) + return (NULL); + const int midx = link - NON_ITEM - 1; + if (invalid_monster_index(midx)) + return (NULL); + + return (&menv[midx]); +} + +void item_def::set_holding_monster(int midx) +{ + ASSERT(midx != NON_MONSTER); + pos.set(-2, -2); + link = NON_ITEM + 1 + midx; +} + +bool item_def::held_by_monster() const +{ + return (pos.equals(-2, -2) && !invalid_monster_index(link - NON_ITEM - 1)); +} diff --git a/crawl-ref/source/makeitem.cc b/crawl-ref/source/makeitem.cc index fa81f0de80..703def7229 100644 --- a/crawl-ref/source/makeitem.cc +++ b/crawl-ref/source/makeitem.cc @@ -3029,7 +3029,7 @@ static void _give_monster_item(monsters *mon, int thing, return; } ASSERT(is_valid_item(mthing)); - ASSERT(holding_monster(mthing) == mon); + ASSERT(mthing.holding_monster() == mon); if (!force_item || mthing.colour == BLACK) item_colour(mthing); diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index 488babbb43..72edbf9402 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -302,7 +302,7 @@ void maybe_coagulate_blood_potions_floor(int obj) // Coagulated blood cannot coagulate any further... ASSERT(blood.sub_type == POT_BLOOD); - if (!held_by_monster(blood)) + if (!blood.held_by_monster()) { // Now that coagulating is necessary, check square for // !coagulated blood. @@ -392,8 +392,8 @@ void maybe_coagulate_blood_potions_floor(int obj) ASSERT(timer_new.size() == coag_count); props_new.assert_validity(); - if (held_by_monster(blood)) - move_item_to_grid(&o, holding_monster(blood)->pos()); + if (blood.held_by_monster()) + move_item_to_grid(&o, blood.holding_monster()->pos()); else move_item_to_grid(&o, blood.pos); diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 1f4763e561..6e5f00f6ac 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -4329,28 +4329,11 @@ void monsters::pickup_message(const item_def &item, int near) } } -bool held_by_monster(const item_def &item) -{ - return (item.pos.equals(-2, -2) - && !invalid_monster_index(item.link - NON_ITEM - 1)); -} - -monsters* holding_monster(const item_def &item) -{ - if (!item.pos.equals(-2, -2)) - return (NULL); - const int midx = item.link - NON_ITEM - 1; - if (invalid_monster_index(midx)) - return (NULL); - - return (&menv[midx]); -} - bool monsters::pickup(item_def &item, int slot, int near, bool force_merge) { ASSERT(is_valid_item(item)); - const monsters *other_mon = holding_monster(item); + const monsters *other_mon = item.holding_monster(); if (other_mon != NULL) { @@ -4442,8 +4425,7 @@ bool monsters::pickup(item_def &item, int slot, int near, bool force_merge) inv[slot] = item_index; - item.pos.set(-2, -2); - item.link = NON_ITEM + 1 + mindex(); + item.set_holding_monster(mindex()); pickup_message(item, near); equip(item, slot, near); diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h index 77e64f15df..9bd0ce27d3 100644 --- a/crawl-ref/source/mon-util.h +++ b/crawl-ref/source/mon-util.h @@ -868,7 +868,4 @@ bool mons_can_pass(const monsters *mon, dungeon_feature_type grid); mon_inv_type equip_slot_to_mslot(equipment_type eq); mon_inv_type item_to_mslot(const item_def &item); - -bool held_by_monster(const item_def &item); -monsters* holding_monster(const item_def &item); #endif diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc index dc7b2d9e75..0908dcea75 100644 --- a/crawl-ref/source/mstuff2.cc +++ b/crawl-ref/source/mstuff2.cc @@ -2565,6 +2565,7 @@ int clone_mons(const monsters* orig, bool quiet, bool* obvious, mon.inv[i] = new_index; mitm[new_index] = mitm[old_index]; + mitm[new_index].set_holding_monster(midx); } bool _obvious; |