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

Function count_buc

src/invent.c:3547–3575  ·  view source on GitHub ↗

* Returns the number of items with b/u/c/unknown within the given list. * This does NOT include contained objects. * * Assumes that the hero sees or touches or otherwise senses the objects * at some point: bknown is forced for priest[ess], like in xname(). */

Source from the content-addressed store, hash-verified

3545 * at some point: bknown is forced for priest[ess], like in xname().
3546 */
3547int
3548count_buc(struct obj *list, int type, boolean (*filterfunc)(OBJ_P))
3549{
3550 int count = 0;
3551
3552 for (; list; list = list->nobj) {
3553 /* priests always know bless/curse state */
3554 if (Role_if(PM_CLERIC))
3555 list->bknown = (list->oclass != COIN_CLASS);
3556 /* some actions exclude some or most items */
3557 if (filterfunc && !(*filterfunc)(list))
3558 continue;
3559
3560 /* coins are either uncursed or unknown based upon option setting */
3561 if (list->oclass == COIN_CLASS) {
3562 if (type == (flags.goldX ? BUC_UNKNOWN : BUC_UNCURSED))
3563 ++count;
3564 continue;
3565 }
3566 /* check whether this object matches the requested type */
3567 if (!list->bknown
3568 ? (type == BUC_UNKNOWN)
3569 : list->blessed ? (type == BUC_BLESSED)
3570 : list->cursed ? (type == BUC_CURSED)
3571 : (type == BUC_UNCURSED))
3572 ++count;
3573 }
3574 return count;
3575}
3576
3577/* similar to count_buc(), but tallies all states at once
3578 rather than looking for a specific type */

Callers 2

ggetobjFunction · 0.85
query_categoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected