get_cost_from_price

I couldn't figure out why walking over a container in a shop might
give the wrong price; the code looks correct.  But I've reorganized
get_cost_from_price to perform the cheapest tests first.  The u.ushops
check should probably be done in doname to avoid calling this routine
at all 99.99% of the time.
This commit is contained in:
PatR
2015-05-30 18:22:14 -07:00
parent da64f26844
commit 24b4872e2f

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 shk.c $NHDT-Date: 1432512768 2015/05/25 00:12:48 $ $NHDT-Branch: master $:$NHDT-Revision: 1.109 $ */ /* NetHack 3.6 shk.c $NHDT-Date: 1433035328 2015/05/31 01:22:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.111 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -1873,24 +1873,20 @@ register struct obj *obj;
{ {
struct monst *shkp; struct monst *shkp;
xchar x, y; xchar x, y;
int cost=0; long cost = 0L;
if (get_obj_location(obj, &x, &y, 0) && if (*u.ushops
(obj->unpaid || && obj->oclass != COIN_CLASS
(obj->where == OBJ_FLOOR && !obj->no_charge && costly_spot(x,y)))) { && obj != uball && obj != uchain
&& get_obj_location(obj, &x, &y, 0)
if (!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)))) return 0; && (obj->unpaid
if (!inhishop(shkp)) return 0; || (obj->where == OBJ_FLOOR
if (!costly_spot(x, y)) return 0; && !obj->no_charge && costly_spot(x, y)))
if (!*u.ushops) return 0; && (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0
&& inhishop(shkp)) {
if (obj->oclass != COIN_CLASS) { cost = obj->quan * get_cost(obj, shkp);
cost = (obj == uball || obj == uchain) ? 0L : if (Has_contents(obj))
obj->quan * get_cost(obj, shkp); cost += contained_cost(obj, shkp, 0L, FALSE, FALSE);
if (Has_contents(obj)) {
cost += contained_cost(obj, shkp, 0L, FALSE, FALSE);
}
}
} }
return cost; return cost;
} }