Show cost of merchandise when walking over it

This is another feature the betatesters seemed to miss a lot.
This commit is contained in:
Pasi Kallinen
2015-05-27 21:43:57 +03:00
parent b2291aaf93
commit 2944dc6935
6 changed files with 58 additions and 5 deletions

View 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

View 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 *));

View 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);

View 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)

View 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++;

View File

@@ -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)