summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/items.cc
diff options
context:
space:
mode:
authorennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2009-04-18 15:08:40 +0000
committerennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2009-04-18 15:08:40 +0000
commit4f56baa35df811304ef3e45c83471fcfd43bce2c (patch)
tree32443c8d02e82c16a5e8f1153e3ce194e9b8f02b /crawl-ref/source/items.cc
parent92a70a7bda3d5a52fd6cc016b748e6bf59fb81e4 (diff)
downloadcrawl-ref-4f56baa35df811304ef3e45c83471fcfd43bce2c.tar.gz
crawl-ref-4f56baa35df811304ef3e45c83471fcfd43bce2c.zip
[2758242] Fixing segfault during debug_mons_scan due to an mprf not matching its format string with its var args. Also, fixing clone function from chaos brand that was causing this where cloned items in monster inventories weren't setting their link to be part of the new monster's inventory. Refactoring monster holding functions into item_def, where they probably should be.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9618 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/items.cc')
-rw-r--r--crawl-ref/source/items.cc27
1 files changed, 25 insertions, 2 deletions
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));
+}