From: Pasi Kallinen Date: Wed, 27 May 2015 18:43:57 +0000 (+0300) Subject: Show cost of merchandise when walking over it X-Git-Tag: NetHack-3.6.0_RC01~344 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2944dc693519874108d29b5190a9de87716d6279;p=nethack Show cost of merchandise when walking over it This is another feature the betatesters seemed to miss a lot. --- diff --git a/doc/fixes35.0 b/doc/fixes35.0 index 57a903be3..b77eb242c 100644 --- a/doc/fixes35.0 +++ b/doc/fixes35.0 @@ -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 diff --git a/include/extern.h b/include/extern.h index 1d26a6e55..bfa13669f 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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 *)); diff --git a/src/invent.c b/src/invent.c index 7c536c6d2..59f73cdfb 100644 --- a/src/invent.c +++ b/src/invent.c @@ -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); diff --git a/src/objnam.c b/src/objnam.c index e249ab3d1..03b640c76 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -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) diff --git a/src/pickup.c b/src/pickup.c index bdbbcb8a7..6668135a4 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -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++; diff --git a/src/shk.c b/src/shk.c index 17fb561cf..6988640f0 100644 --- 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)