MCPcopy Index your code
hub / github.com/NetHack/NetHack / count_contents

Function count_contents

src/invent.c:3619–3651  ·  view source on GitHub ↗

count everything inside a container, or just shop-owned items inside */

Source from the content-addressed store, hash-verified

3617
3618/* count everything inside a container, or just shop-owned items inside */
3619long
3620count_contents(
3621 struct obj *container,
3622 boolean nested, /* include contents of any nested containers */
3623 boolean quantity, /* count all vs count separate stacks */
3624 boolean everything, /* all objects vs only unpaid objects */
3625 boolean newdrop) /* on floor, but hero-owned items haven't
3626 * been marked no_charge yet and shop-owned
3627 * items are still marked unpaid -- used
3628 * when asking the player whether to sell */
3629{
3630 struct obj *otmp, *topc;
3631 boolean shoppy = FALSE;
3632 long count = 0L;
3633
3634 if (!everything && !newdrop) {
3635 coordxy x, y;
3636
3637 for (topc = container; topc->where == OBJ_CONTAINED;
3638 topc = topc->ocontainer)
3639 continue;
3640 if (topc->where == OBJ_FLOOR && get_obj_location(topc, &x, &y, 0))
3641 shoppy = costly_spot(x, y);
3642 }
3643 for (otmp = container->cobj; otmp; otmp = otmp->nobj) {
3644 if (nested && Has_contents(otmp))
3645 count += count_contents(otmp, nested, quantity, everything,
3646 newdrop);
3647 if (everything || otmp->unpaid || (shoppy && !otmp->no_charge))
3648 count += quantity ? otmp->quan : 1L;
3649 }
3650 return count;
3651}
3652
3653staticfn void
3654dounpaid(

Callers 3

doname_baseFunction · 0.85
stolen_valueFunction · 0.85
sellobjFunction · 0.85

Calls 2

get_obj_locationFunction · 0.85
costly_spotFunction · 0.85

Tested by

no test coverage detected