From: PatR Date: Wed, 26 Dec 2018 00:45:41 +0000 (-0800) Subject: stolen_value() vs containers X-Git-Tag: NetHack-3.6.2_Released~119^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f5f7f63f1b0923149f91d1645f2af508a0713b6;p=nethack stolen_value() vs containers stolen_value() treated hero-owned container holding shop-owned goods as free for the taking. The fix I'm working on which led to discovering this first added stolen_value() then eventually stopped using it so I don't have an example of where it is giving the wrong result. --- diff --git a/src/invent.c b/src/invent.c index 62ec70401..21fdcdf4b 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 invent.c $NHDT-Date: 1545597422 2018/12/23 20:37:02 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.245 $ */ +/* NetHack 3.6 invent.c $NHDT-Date: 1545785120 2018/12/26 00:45:20 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.246 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2892,6 +2892,7 @@ int *bcp, *ucp, *ccp, *xcp, *ocp; } } +/* count everything inside a container, or just shop-owned items inside */ long count_contents(container, nested, quantity, everything) struct obj *container; @@ -2899,13 +2900,24 @@ boolean nested, /* include contents of any nested containers */ quantity, /* count all vs count separate stacks */ everything; /* all objects vs only unpaid objects */ { - struct obj *otmp; + struct obj *otmp, *topc; + boolean shoppy = FALSE; long count = 0L; + if (!everything) { + for (topc = container; topc->ocontainer; topc = topc->ocontainer) + continue; + if (topc->where == OBJ_FLOOR) { + xchar x, y; + + (void) get_obj_location(topc, &x, &y, CONTAINED_TOO); + shoppy = costly_spot(x, y); + } + } for (otmp = container->cobj; otmp; otmp = otmp->nobj) { if (nested && Has_contents(otmp)) count += count_contents(otmp, nested, quantity, everything); - if (everything || otmp->unpaid) + if (everything || otmp->unpaid || (shoppy && !otmp->no_charge)) count += quantity ? otmp->quan : 1L; } return count; diff --git a/src/shk.c b/src/shk.c index 9f6715415..de436de87 100644 --- a/src/shk.c +++ b/src/shk.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 shk.c $NHDT-Date: 1545774524 2018/12/25 21:48:44 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.145 $ */ +/* NetHack 3.6 shk.c $NHDT-Date: 1545785119 2018/12/26 00:45:19 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.146 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2811,11 +2811,13 @@ boolean peaceful, silent; if (!billable(&shkp, obj, roomno, FALSE)) { /* things already on the bill yield a not-billable result, so we need to check bill before deciding that shk doesn't care */ - if ((bp = onbill(obj, shkp, FALSE)) == 0) + if ((bp = onbill(obj, shkp, FALSE)) != 0) { + /* shk does care; take obj off bill to avoid double billing */ + billamt = bp->bquan * bp->price; + sub_one_frombill(obj, shkp); + } + if (!bp && !u_count) return 0L; - /* shk does care; take obj off bill to avoid double billing */ - billamt = bp->bquan * bp->price; - sub_one_frombill(obj, shkp); } if (obj->oclass == COIN_CLASS) {