]> granicus.if.org Git - nethack/commitdiff
Show cost of merchandise when walking over it
authorPasi Kallinen <paxed@alt.org>
Wed, 27 May 2015 18:43:57 +0000 (21:43 +0300)
committerPasi Kallinen <paxed@alt.org>
Wed, 27 May 2015 18:45:00 +0000 (21:45 +0300)
This is another feature the betatesters seemed to miss a lot.

doc/fixes35.0
include/extern.h
src/invent.c
src/objnam.c
src/pickup.c
src/shk.c

index 57a903be3d424ba1b259338b3fb57d4da5d33d3c..b77eb242c3b7f95871237a3cb196e0ac7228a409 100644 (file)
@@ -919,6 +919,7 @@ the chest in the Castle containing the wishing wand can never be trapped
 the vibrating square is now a trap
 mimics wouldn't take on the form of "strange object"
 add an option to prevent omitting the uncursed status from inventory
+show prices when walking over the shop merchandise
 
 
 Platform- and/or Interface-Specific Fixes
index 1d26a6e55325189831f070f437239fffb8f8ef07..bfa13669fa5770fe43ea47e793097f0185c8d6be 100644 (file)
@@ -1567,6 +1567,7 @@ E char *FDECL(mshot_xname, (struct obj *));
 E boolean FDECL(the_unique_obj, (struct obj *));
 E boolean FDECL(the_unique_pm, (struct permonst *));
 E char *FDECL(doname, (struct obj *));
+E char *FDECL(doname_with_price, (struct obj *));
 E boolean FDECL(not_fully_identified, (struct obj *));
 E char *FDECL(corpse_xname, (struct obj *, const char *, unsigned));
 E char *FDECL(cxname, (struct obj *));
@@ -2102,6 +2103,7 @@ E void FDECL(shk_chat, (struct monst *));
 E void FDECL(check_unpaid_usage, (struct obj *, BOOLEAN_P));
 E void FDECL(check_unpaid, (struct obj *));
 E void FDECL(costly_gold, (XCHAR_P, XCHAR_P, long));
+E long FDECL(get_cost_of_shop_item, (struct obj *));
 E boolean FDECL(block_door, (XCHAR_P, XCHAR_P));
 E boolean FDECL(block_entry, (XCHAR_P, XCHAR_P));
 E char *FDECL(shk_your, (char *, struct obj *));
index 7c536c6d2a839485d9c8287cda295d4ef9f038cb..59f73cdfb4aeef4050a25eb2f8fad2d49ab3db3e 100644 (file)
@@ -2740,7 +2740,7 @@ boolean picked_some;
         if (dfeature)
             pline1(fbuf);
         read_engr_at(u.ux, u.uy); /* Eric Backus */
-        You("%s here %s.", verb, doname(otmp));
+        You("%s here %s.", verb, doname_with_price(otmp));
         iflags.last_msg = PLNMSG_ONE_ITEM_HERE;
         if (otmp->otyp == CORPSE)
             feel_cockatrice(otmp, FALSE);
@@ -2764,7 +2764,7 @@ boolean picked_some;
                 putstr(tmpwin, 0, buf);
                 break;
             }
-            putstr(tmpwin, 0, doname(otmp));
+            putstr(tmpwin, 0, doname_with_price(otmp));
         }
         display_nhwindow(tmpwin, TRUE);
         destroy_nhwindow(tmpwin);
index e249ab3d19e24237966a551e4486a2c3c45e086c..03b640c76e3b000846ab92a027a0956dce14470a 100644 (file)
@@ -705,9 +705,10 @@ char *prefix;
                                        is_flammable(obj) ? "fireproof " : "");
 }
 
-char *
-doname(obj)
+static char *
+doname_base(obj, with_price)
 register struct obj *obj;
+boolean with_price;
 {
     boolean ispoisoned = FALSE;
     boolean known, cknown, bknown, lknown;
@@ -988,6 +989,10 @@ register struct obj *obj;
 
         Sprintf(eos(bp), " (%s, %ld %s)", obj->unpaid ? "unpaid" : "contents",
                 quotedprice, currency(quotedprice));
+    } else if (with_price) {
+        long price = get_cost_of_shop_item(obj);
+        if (price > 0)
+            Sprintf(eos(bp), " (%ld %s)", price, currency(price));
     }
     if (!strncmp(prefix, "a ", 2)
         && index(vowels, *(prefix + 2) ? *(prefix + 2) : *bp)
@@ -1008,6 +1013,21 @@ register struct obj *obj;
     return (bp);
 }
 
+char *
+doname(obj)
+register struct obj *obj;
+{
+    return doname_base(obj, FALSE);
+}
+
+/* Name of object including price. */
+char *
+doname_with_price(obj)
+register struct obj *obj;
+{
+    return doname_base(obj, TRUE);
+}
+
 /* used from invent.c */
 boolean
 not_fully_identified(otmp)
index bdbbcb8a704969522ab5c1dadd80b909635a2f7a..6668135a49af17d3e233c1172a23b3de7df44611 100644 (file)
@@ -862,7 +862,7 @@ boolean FDECL((*allow), (OBJ_P)); /* allow function */
                 add_menu(win, obj_to_glyph(curr), &any,
                          (qflags & USE_INVLET) ? curr->invlet : 0,
                          def_oc_syms[(int) objects[curr->otyp].oc_class].sym,
-                         ATR_NONE, doname(curr), MENU_UNSELECTED);
+                         ATR_NONE, doname_with_price(curr), MENU_UNSELECTED);
             }
         }
         pack++;
index 17fb561cfc96ccd3e908099e323cef245664a2b9..6988640f0325a68b8d2b00ad6a89c07d6fa7fab6 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -1865,6 +1865,36 @@ unsigned id;
     return (struct obj *) 0;
 }
 
+/* Returns the price of an arbitrary item in the shop.
+ * Returns 0 if the item doesn't belong to a shopkeeper. */
+long
+get_cost_of_shop_item(obj)
+register struct obj *obj;
+{
+    struct monst *shkp;
+    xchar x, y;
+    int cost=0;
+
+    if (get_obj_location(obj, &x, &y, 0) &&
+        (obj->unpaid ||
+         (obj->where == OBJ_FLOOR && !obj->no_charge && costly_spot(x,y)))) {
+
+        if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)))) return 0;
+        if (!inhishop(shkp)) return 0;
+        if (!costly_spot(x, y))        return 0;
+        if (!*u.ushops) return 0;
+
+        if (obj->oclass != COIN_CLASS) {
+            cost = (obj == uball || obj == uchain) ? 0L :
+                obj->quan * get_cost(obj, shkp);
+            if (Has_contents(obj)) {
+                cost += contained_cost(obj, shkp, 0L, FALSE, FALSE);
+            }
+        }
+    }
+    return cost;
+}
+
 /* calculate the value that the shk will charge for [one of] an object */
 STATIC_OVL long
 get_cost(obj, shkp)