From ef2085bcafcd9ad1a45db43fa5212a62da9bbd52 Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Thu, 9 Nov 2006 05:20:00 +0000 Subject: [PATCH] "(contents, N zorkmids)" fix (trunk only) Some code I recently added was misusing count_unpaid() and would traverse some or all of inventory instead of just container's contents when looking for unpaid items. Add mew routine `is_unpaid(obj)' to do what I was intending to do with count_unpaid(). --- include/extern.h | 1 + src/dokick.c | 2 +- src/dothrow.c | 4 ++-- src/objnam.c | 2 +- src/shk.c | 13 ++++++++++--- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/extern.h b/include/extern.h index 1412f1a87..3f5eb9f48 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1975,6 +1975,7 @@ E void NDECL(shopper_financial_report); E int FDECL(inhishop, (struct monst *)); E struct monst *FDECL(shop_keeper, (CHAR_P)); E boolean FDECL(tended_shop, (struct mkroom *)); +E boolean FDECL(is_unpaid, (struct obj *)); E void FDECL(delete_contents, (struct obj *)); E void FDECL(obfree, (struct obj *,struct obj *)); E void FDECL(home_shk, (struct monst *,BOOLEAN_P)); diff --git a/src/dokick.c b/src/dokick.c index e9f7d2949..06148e220 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -1311,7 +1311,7 @@ boolean shop_floor_obj; (toloc != MIGR_LADDER_UP && rn2(3)); container = Has_contents(otmp); - unpaid = (otmp->unpaid || (container && count_unpaid(otmp->cobj))); + unpaid = is_unpaid(otmp); if(OBJ_AT(x, y)) { for(obj = level.objects[x][y]; obj; obj = obj->nexthere) diff --git a/src/dothrow.c b/src/dothrow.c index 5d61f0356..894631416 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -702,13 +702,13 @@ boolean broken; if (broken || !costly_spot(x, y) || *in_rooms(x, y, SHOPBASE) != *u.ushops) { /* thrown out of a shop or into a different shop */ - if (count_unpaid(obj)) + if (is_unpaid(obj)) (void)stolen_value(obj, u.ux, u.uy, (boolean)shkp->mpeaceful, FALSE); if (broken) obj->no_charge = 1; } else { if (costly_spot(u.ux, u.uy) && costly_spot(x, y)) { - if (count_unpaid(obj)) + if (is_unpaid(obj)) subfrombill(obj, shkp); else if (x != shkp->mx || y != shkp->my) sellobj(obj, x, y); diff --git a/src/objnam.c b/src/objnam.c index e3e9df701..37ec1b220 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -827,7 +827,7 @@ ring: Strcat(bp, " (alternate weapon; not wielded)"); } if(obj->owornmask & W_QUIVER) Strcat(bp, " (in quiver)"); - if (!iflags.suppress_price && count_unpaid(obj)) { + if (!iflags.suppress_price && is_unpaid(obj)) { long quotedprice = unpaid_cost(obj, TRUE); Sprintf(eos(bp), " (%s, %ld %s)", diff --git a/src/shk.c b/src/shk.c index a17c87703..a6dfbea00 100644 --- a/src/shk.c +++ b/src/shk.c @@ -769,6 +769,14 @@ register boolean silent; return (struct bill_x *)0; } +/* check whether an object or any of its contents belongs to a shop */ +boolean +is_unpaid(obj) +struct obj *obj; +{ + return (obj->unpaid || (Has_contents(obj) && count_unpaid(obj->cobj))); +} + /* Delete the contents of the given object. */ void delete_contents(obj) @@ -2621,14 +2629,13 @@ xchar x, y; /* get one case out of the way: nothing to sell, and no gold */ if (!isgold && ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) { - boolean unpaid = (obj->unpaid || - (container && count_unpaid(obj->cobj))); + boolean unpaid = is_unpaid(obj); if(container) { dropped_container(obj, shkp, FALSE); if(!obj->unpaid && !saleitem) obj->no_charge = 1; - if(obj->unpaid || count_unpaid(obj->cobj)) + if (unpaid) subfrombill(obj, shkp); } else obj->no_charge = 1;