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

Function iter_mons_safe

src/mon.c:4499–4522  ·  view source on GitHub ↗

Iterate all monsters on the level, even dead or off-map ones, calling bfunc() for each monster. If bfunc() returns TRUE, stop iterating. If the game ends during the call to bfunc(), then freedynamicdata() will free 'itermonarr'. Safe for list deletions and insertions, and guarantees calling bfunc() once per monster in fmon unless it returns TRUE (or game ends). */

Source from the content-addressed store, hash-verified

4497 Safe for list deletions and insertions, and guarantees calling bfunc()
4498 once per monster in fmon unless it returns TRUE (or game ends). */
4499void
4500iter_mons_safe(boolean (*bfunc)(struct monst *))
4501{
4502 struct monst *mtmp;
4503 unsigned i, nmons;
4504
4505 for (nmons = 0, mtmp = fmon; mtmp; mtmp = mtmp->nmon)
4506 nmons++;
4507
4508 /* make sure itermonarr[] is big enough to hold nmons entries */
4509 alloc_itermonarr(nmons);
4510
4511 if (nmons) {
4512 for (i = 0, mtmp = fmon; mtmp; mtmp = mtmp->nmon)
4513 itermonarr[i++] = mtmp;
4514
4515 for (i = 0; i < nmons; i++) {
4516 mtmp = itermonarr[i];
4517 if ((*bfunc)(mtmp))
4518 break;
4519 }
4520 }
4521 return;
4522}
4523
4524
4525/* iterate all living monsters on current level, calling vfunc for each. */

Callers 1

movemonFunction · 0.85

Calls 1

alloc_itermonarrFunction · 0.85

Tested by

no test coverage detected