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. */
| 2992 | * a different price quoted for selling as vs. buying. |
| 2993 | */ |
| 2994 | long |
| 2995 | contained_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 */ |
| 3045 | long |
no test coverage detected