MCPcopy Create free account
hub / github.com/NetHack/NetHack / contained_cost

Function contained_cost

src/shk.c:2994–3042  ·  view source on GitHub ↗

returns the price of a container's content. the price * of the "top" container is added in the calling functions. * a different price quoted for selling as vs. buying. */

Source from the content-addressed store, hash-verified

2992 * a different price quoted for selling as vs. buying.
2993 */
2994long
2995contained_cost(
2996 struct obj *obj,
2997 struct monst *shkp,
2998 long price,
2999 boolean usell,
3000 boolean unpaid_only)
3001{
3002 struct obj *otmp, *top;
3003 coordxy x, y;
3004 boolean on_floor, freespot;
3005
3006 for (top = obj; top->where == OBJ_CONTAINED; top = top->ocontainer)
3007 continue;
3008 /* pick_obj() removes item from floor, adds it to shop bill, then
3009 puts it in inventory; behave as if it is still on the floor
3010 during the add-to-bill portion of that situation */
3011 on_floor = (top->where == OBJ_FLOOR || top->where == OBJ_FREE);
3012 if (top->where == OBJ_FREE || !get_obj_location(top, &x, &y, 0))
3013 x = u.ux, y = u.uy;
3014 freespot = (on_floor && x == ESHK(shkp)->shk.x && y == ESHK(shkp)->shk.y);
3015
3016 /* price of contained objects; "top" container handled by caller */
3017 for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
3018 if (otmp->oclass == COIN_CLASS)
3019 continue;
3020
3021 if (usell) {
3022 if (saleable(shkp, otmp) && !otmp->unpaid
3023 && otmp->oclass != BALL_CLASS
3024 && !(otmp->oclass == FOOD_CLASS && otmp->oeaten)
3025 && !(Is_candle(otmp)
3026 && otmp->age < 20L * (long) objects[otmp->otyp].oc_cost))
3027 price += set_cost(otmp, shkp);
3028 } else {
3029 /* no_charge is only set for floor items (including
3030 contents of floor containers) inside shop proper;
3031 items on freespot are implicitly 'no charge' */
3032 if (on_floor ? (!otmp->no_charge && !freespot)
3033 : (otmp->unpaid || !unpaid_only))
3034 price += get_cost(otmp, shkp) * get_pricing_units(otmp);
3035 }
3036
3037 if (Has_contents(otmp))
3038 price = contained_cost(otmp, shkp, price, usell, unpaid_only);
3039 }
3040
3041 return price;
3042}
3043
3044/* count amount of gold inside container 'obj' and any nested containers */
3045long

Callers 7

poly_objFunction · 0.85
get_cost_of_shop_itemFunction · 0.85
unpaid_costFunction · 0.85
billableFunction · 0.85
addtobillFunction · 0.85
sellobjFunction · 0.85
price_quoteFunction · 0.85

Calls 5

get_obj_locationFunction · 0.85
saleableFunction · 0.85
set_costFunction · 0.85
get_costFunction · 0.85
get_pricing_unitsFunction · 0.85

Tested by

no test coverage detected