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

Function clear_no_charge_obj

src/shk.c:328–373  ·  view source on GitHub ↗

clear the no_charge bit on a single object and its contents */

Source from the content-addressed store, hash-verified

326
327/* clear the no_charge bit on a single object and its contents */
328staticfn void
329clear_no_charge_obj(
330 struct monst *shkp, /* if null, clear regardless of shop */
331 struct obj *otmp)
332{
333 if (Has_contents(otmp))
334 clear_no_charge(shkp, otmp->cobj);
335 if (otmp->no_charge) {
336 struct monst *rm_shkp;
337 int rno;
338 coordxy x, y;
339
340 /*
341 * Clear no_charge if
342 * shkp is Null (clear all items on specified list)
343 * or not located somewhere that we expect no_charge (which is
344 * floor [of shop] or inside container [on shop floor])
345 * or can't find object's map coordinates (should never happen
346 * for floor or contained; conceivable if on shop bill somehow
347 * but would have failed the floor-or-contained test since
348 * containers get emptied before going onto bill)
349 * or fails location sanity check (should always be good when
350 * location successfully found)
351 * or not inside any room
352 * or the room isn't a shop
353 * or the shop has no shopkeeper (deserted)
354 * or shopkeeper is the current one (to avoid clearing no_charge
355 * for items located in some rival's shop).
356 *
357 * no_charge items in a shop which is only temporarily deserted
358 * become owned by the shop now and will be for-sale once the shk
359 * returns.
360 */
361 if (!shkp
362 || (otmp->where != OBJ_FLOOR
363 && otmp->where != OBJ_CONTAINED
364 && otmp->where != OBJ_BURIED)
365 || !get_obj_location(otmp, &x, &y, OBJ_CONTAINED | OBJ_BURIED)
366 || !isok(x, y)
367 || (rno = levl[x][y].roomno) < ROOMOFFSET
368 || !IS_SHOP(rno - ROOMOFFSET)
369 || (rm_shkp = svr.rooms[rno - ROOMOFFSET].resident) == 0
370 || rm_shkp == shkp)
371 otmp->no_charge = 0;
372 }
373}
374
375/* clear the no_charge bit on all of the objects in the list */
376staticfn void

Callers 1

clear_no_chargeFunction · 0.85

Calls 3

clear_no_chargeFunction · 0.85
get_obj_locationFunction · 0.85
isokFunction · 0.85

Tested by

no test coverage detected