From 176d5b846371dcfd9a694063bfdc33bf3b584383 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 19 Sep 2021 21:20:13 +0300 Subject: [PATCH] Bones piles can be ransacked by adjacent monsters If a bones file is created, any object-liking monster next to where hero died has a chance of grabbing objects from hero's inventory. This comes from xNetHack by copperwater . --- doc/fixes37.0 | 1 + src/bones.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/doc/fixes37.0 b/doc/fixes37.0 index bad9788b1..c9df2bc72 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -1161,6 +1161,7 @@ vomiting on an altar provokes the deities wrath branch stairs have a different glyph, show up in yellow color in tty duration of confusion when drinking booze depends upon hunger state using 'D' allows dropping items picked up previously +bones piles can be ransacked by adjacent monsters Platform- and/or Interface-Specific New Features diff --git a/src/bones.c b/src/bones.c index 22755289f..c34bd1449 100644 --- a/src/bones.c +++ b/src/bones.c @@ -8,6 +8,7 @@ static boolean no_bones_level(d_level *); static void goodfruit(int); static void resetobjs(struct obj *, boolean); +static void give_to_nearby_mon(struct obj *, int, int); static boolean fixuporacle(struct monst *); static boolean @@ -213,6 +214,41 @@ sanitize_name(char *namebuf) } } +/* Give object to a random object-liking monster on or adjacent to x,y + but skipping hero's location. + If no such monster, place object on floor at x,y. */ +static void +give_to_nearby_mon(struct obj *otmp, int x, int y) +{ + struct monst *mtmp; + struct monst *selected = (struct monst *) 0; + int nmon = 0, xx, yy; + + for (xx = x - 1; xx <= x + 1; ++xx) { + for (yy = y - 1; yy <= y + 1; ++yy) { + if (!isok(xx, yy)) + continue; + if (xx == u.ux && yy == u.uy) + continue; + if (!(mtmp = m_at(xx, yy))) + continue; + /* This doesn't do any checks on otmp to see that it matches the + * likes_* property, intentionally. Assume that the monster is + * rifling through and taking things that look interesting. */ + if (!(likes_gold(mtmp->data) || likes_gems(mtmp->data) + || likes_objs(mtmp->data) || likes_magic(mtmp->data))) + continue; + nmon++; + if (!rn2(nmon)) + selected = mtmp; + } + } + if (selected && can_carry(selected, otmp)) + add_to_minv(selected, otmp); + else + place_object(otmp, x, y); +} + /* called by savebones(); also by finish_paybill(shk.c) */ void drop_upon_death(struct monst *mtmp, /* monster if hero turned into one (other than ghost) */ @@ -249,6 +285,8 @@ drop_upon_death(struct monst *mtmp, /* monster if hero turned into one (other th (void) add_to_minv(mtmp, otmp); else if (cont) (void) add_to_container(cont, otmp); + else if (!rn2(8)) + give_to_nearby_mon(otmp, x, y); else place_object(otmp, x, y); }