]> granicus.if.org Git - nethack/commitdiff
The unpaid cost displayed in your inventory now
authornethack.allison <nethack.allison>
Mon, 25 Feb 2002 19:14:42 +0000 (19:14 +0000)
committernethack.allison <nethack.allison>
Mon, 25 Feb 2002 19:14:42 +0000 (19:14 +0000)
includes container contents, not just the cost of the
container itself (a prices in inventory phenomenon).

Along the way I discovered a peculiarity -
contained_cost() was adding up the cost of everything in
a container, even if you had stashed items in it that were your
own and not marked unpaid it seems.

I added a flag to force the code to only add objects
that were marked "unpaid" so I could use it in this new
instance, but I didn't change any of
the existing usages (I left the flag at FALSE which leaves
the consideration of the unpaid status alone just as
before).

Some of this is correction of some messages that were
wrong prior to this when dealing with selling of objects
inside a container when only part of the contents was unpaid.

include/extern.h
src/objnam.c
src/shk.c
src/zap.c

index 2f129af6f04e6d7eefaa2468905ec1edaf135197..e338b5b1a10a14845069dd4f2dd3672df45de2e5 100644 (file)
@@ -1744,7 +1744,7 @@ E int NDECL(dopay);
 E boolean FDECL(paybill, (BOOLEAN_P));
 E void NDECL(finish_paybill);
 E struct obj *FDECL(find_oid, (unsigned));
-E long FDECL(contained_cost, (struct obj *,struct monst *,long,BOOLEAN_P));
+E long FDECL(contained_cost, (struct obj *,struct monst *,long,BOOLEAN_P, BOOLEAN_P));
 E long FDECL(contained_gold, (struct obj *));
 E void FDECL(picked_container, (struct obj *));
 E long FDECL(unpaid_cost, (struct obj *));
index 900437e0337d50e30533d49129d4a2cf56f6d717..88d8f1491ada840e94be1ac16579604e13e82976 100644 (file)
@@ -748,7 +748,15 @@ ring:
        }
        if(obj->owornmask & W_QUIVER) Strcat(bp, " (in quiver)");
        if(obj->unpaid) {
+               xchar ox, oy; 
                long quotedprice = unpaid_cost(obj);
+               struct monst *shkp = (struct monst *)0;
+
+               if (Has_contents(obj) &&
+                   get_obj_location(obj, &ox, &oy, BURIED_TOO|CONTAINED_TOO) &&
+                   costly_spot(ox, oy) &&
+                   (shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE))))
+                       quotedprice += contained_cost(obj, shkp, 0L, FALSE, TRUE);
                Sprintf(eos(bp), " (unpaid, %ld %s)",
                        quotedprice, currency(quotedprice));
        }
index 12cb3498958bf9bfa84e321835442da31f0aba23..2d9bcc2151e110ef812834d89970b16e4ba2fec4 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -1879,11 +1879,12 @@ register struct monst *shkp;    /* if angry, impose a surcharge */
  * a different price quoted for selling as vs. buying.
  */
 long
-contained_cost(obj, shkp, price, usell)
+contained_cost(obj, shkp, price, usell, unpaid_only)
 register struct obj *obj;
 register struct monst *shkp;
 long price;
 register boolean usell;
+register boolean unpaid_only;
 {
        register struct obj *otmp;
 
@@ -1898,12 +1899,13 @@ register boolean usell;
                        !(Is_candle(otmp) && otmp->age <
                                20L * (long)objects[otmp->otyp].oc_cost))
                    price += set_cost(otmp, shkp);
-           } else if (!otmp->no_charge) {
+           } else if (!otmp->no_charge &&
+                     (!unpaid_only || (unpaid_only && otmp->unpaid))) {
                    price += get_cost(otmp, shkp) * otmp->quan;
            }
 
            if (Has_contents(otmp))
-                   price += contained_cost(otmp, shkp, price, usell);
+                   price += contained_cost(otmp, shkp, price, usell, unpaid_only);
        }
 
        return(price);
@@ -2185,7 +2187,7 @@ register boolean ininv, dummy, silent;
                    goto speak;
                }
            } else {
-               cltmp += contained_cost(obj, shkp, cltmp, FALSE);
+               cltmp += contained_cost(obj, shkp, cltmp, FALSE, FALSE);
                gltmp += contained_gold(obj);
            }
 
@@ -2491,6 +2493,7 @@ xchar x, y;
        long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer;
        boolean saleitem, cgold = FALSE, container = Has_contents(obj);
        boolean isgold = (obj->oclass == GOLD_CLASS);
+       boolean only_partially_your_contents = FALSE;
 
        if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) ||
           !inhishop(shkp)) return;
@@ -2503,7 +2506,7 @@ xchar x, y;
        }
        if(container) {
                /* find the price of content before subfrombill */
-               cltmp += contained_cost(obj, shkp, cltmp, TRUE);
+               cltmp += contained_cost(obj, shkp, cltmp, TRUE, FALSE);
                /* find the value of contained gold */
                gltmp += contained_gold(obj);
                cgold = (gltmp > 0L);
@@ -2673,13 +2676,18 @@ move_on:
                if (short_funds) offer = shkmoney;
 #endif
                if (!sell_response) {
+                   only_partially_your_contents =
+                       (contained_cost(obj, shkp, 0L, FALSE, FALSE) !=
+                        contained_cost(obj, shkp, 0L, FALSE, TRUE));
                    Sprintf(qbuf,
                         "%s offers%s %ld gold piece%s for%s %s %s.  Sell %s?",
                            Monnam(shkp), short_funds ? " only" : "",
                            offer, plur(offer),
-                           (!ltmp && cltmp) ? " the contents of" : "",
+                           (!ltmp && cltmp && only_partially_your_contents) ?
+                            " your items in" : (!ltmp && cltmp) ? " the contents of" : "",
                            obj->unpaid ? "the" : "your", xname(obj),
-                           (obj->quan == 1L) ? "it" : "them");
+                           (obj->quan == 1L && !only_partially_your_contents) ?
+                           "it" : "them");
                } else  qbuf[0] = '\0';         /* just to pacify lint */
 
                switch (sell_response ? sell_response : ynaq(qbuf)) {
@@ -2696,6 +2704,8 @@ move_on:
                            subfrombill(obj, shkp);
                            pay(-offer, shkp);
                            shk_names_obj(shkp, obj, (sell_how != SELL_NORMAL) ?
+                                   only_partially_your_contents ?
+                                   "sold some items inside %s for %ld gold pieces%s.%s" :
                                    "sold %s for %ld gold piece%s.%s" :
               "relinquish %s and receive %ld gold piece%s in compensation.%s",
                                    offer, "");
@@ -3586,7 +3596,7 @@ register struct obj *first_obj;
        cost = (otmp->no_charge || otmp == uball || otmp == uchain) ? 0L :
                get_cost(otmp, (struct monst *)0);
        if (Has_contents(otmp))
-           cost += contained_cost(otmp, shkp, 0L, FALSE);
+           cost += contained_cost(otmp, shkp, 0L, FALSE, FALSE);
        if (!cost) {
            Strcpy(price, "no charge");
        } else {
@@ -3605,7 +3615,7 @@ register struct obj *first_obj;
            /* print cost in slightly different format, so can't reuse buf */
            cost = get_cost(first_obj, (struct monst *)0);
            if (Has_contents(first_obj))
-               cost += contained_cost(first_obj, shkp, 0L, FALSE);
+               cost += contained_cost(first_obj, shkp, 0L, FALSE, FALSE);
            pline("%s, price %ld %s%s%s", doname(first_obj),
                cost, currency(cost), first_obj->quan > 1L ? " each" : "",
                shk_embellish(first_obj, cost));
index aad71a8e3ad3fb561504817fd464df22d8c79b3c..0ed75f3d6495bfd1c80ae157a5578f398bed9c59 100644 (file)
--- a/src/zap.c
+++ b/src/zap.c
@@ -1400,7 +1400,7 @@ no_unwear:
 
            if ((!obj->no_charge ||
                 (Has_contents(obj) &&
-                   (contained_cost(obj, shkp, 0L, FALSE) != 0L)))
+                   (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 0L)))
               && inhishop(shkp)) {
                if(shkp->mpeaceful) {
                    if(*u.ushops && *in_rooms(u.ux, u.uy, 0) ==