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). */
| 4497 | Safe for list deletions and insertions, and guarantees calling bfunc() |
| 4498 | once per monster in fmon unless it returns TRUE (or game ends). */ |
| 4499 | void |
| 4500 | iter_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. */ |
no test coverage detected