]> granicus.if.org Git - nethack/commitdiff
"(contents, N zorkmids)" fix (trunk only)
authornethack.rankin <nethack.rankin>
Thu, 9 Nov 2006 05:20:00 +0000 (05:20 +0000)
committernethack.rankin <nethack.rankin>
Thu, 9 Nov 2006 05:20:00 +0000 (05:20 +0000)
     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
src/dokick.c
src/dothrow.c
src/objnam.c
src/shk.c

index 1412f1a87f60120c01b890bfca2ae2fd445f6251..3f5eb9f4863338fa6993a193fcb8cce0e9748fee 100644 (file)
@@ -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));
index e9f7d294976a341628367f54101e0c73b21609a7..06148e2204d230199523722f38bbb0a7ecfc968e 100644 (file)
@@ -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)
index 5d61f0356707eb06501f261598a9a8a5f4bb9afd..894631416df19a8bea32e115f10b685f67b0c211 100644 (file)
@@ -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);
index e3e9df70150e4acdffef4f3b093e90c17dfbaf78..37ec1b220cb44d4607e5de20752cda30ce707d2b 100644 (file)
@@ -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)",
index a17c877032ca50470f2aaf475efb77172246be2d..a6dfbea00730ff20a7d57db330b3b46889d34dd5 100644 (file)
--- 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;