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

Function mon_sanity_check

src/mon.c:257–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257void
258mon_sanity_check(void)
259{
260 coordxy x, y;
261 struct monst *mtmp, *m;
262
263 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
264 /* dead monsters should still have sane data */
265 sanity_check_single_mon(mtmp, TRUE, "fmon");
266 if (DEADMONSTER(mtmp) && !mtmp->isgd)
267 continue;
268
269 x = mtmp->mx, y = mtmp->my;
270 if (!isok(x, y) && !(mtmp->isgd && x == 0 && y == 0)) {
271 impossible("mon (%s) claims to be at <%d,%d>?",
272 fmt_ptr((genericptr_t) mtmp), x, y);
273 } else if (mtmp == u.usteed) {
274 /* steed is in fmon list but not on the map; its
275 <mx,my> coordinates should match hero's location */
276 if (x != u.ux || y != u.uy)
277 impossible("steed (%s) claims to be at <%d,%d>?",
278 fmt_ptr((genericptr_t) mtmp), x, y);
279 } else if (svl.level.monsters[x][y] != mtmp) {
280 impossible("mon (%s) at <%d,%d> is not there!",
281 fmt_ptr((genericptr_t) mtmp), x, y);
282 } else if (mtmp->wormno) {
283 sanity_check_worm(mtmp);
284
285 /* some temp mstate bits can be expected for a mon on fmon, as part of
286 removing it, but DEADMONSTER check above should skip those. */
287 } else if (mon_offmap(mtmp)) {
288 impossible("floor mon (%s) with mstate set to 0x%08lx",
289 fmt_ptr((genericptr_t) mtmp), mtmp->mstate);
290 }
291 }
292
293 for (x = 1; x < COLNO; x++)
294 for (y = 0; y < ROWNO; y++)
295 if ((mtmp = svl.level.monsters[x][y]) != 0) {
296 for (m = fmon; m; m = m->nmon)
297 if (m == mtmp)
298 break;
299 if (!m)
300 impossible("map mon (%s) at <%d,%d> not in fmon list!",
301 fmt_ptr((genericptr_t) mtmp), x, y);
302 else if (mtmp == u.usteed)
303 impossible("steed (%s) is on the map at <%d,%d>!",
304 fmt_ptr((genericptr_t) mtmp), x, y);
305 else if ((mtmp->mx != x || mtmp->my != y)
306 && mtmp->data != &mons[PM_LONG_WORM])
307 impossible("map mon (%s) at <%d,%d> is found at <%d,%d>?",
308 fmt_ptr((genericptr_t) mtmp),
309 mtmp->mx, mtmp->my, x, y);
310 }
311
312 for (mtmp = gm.migrating_mons; mtmp; mtmp = mtmp->nmon) {
313 sanity_check_single_mon(mtmp, FALSE, "migr");
314

Callers 1

sanity_checkFunction · 0.85

Calls 6

sanity_check_single_monFunction · 0.85
isokFunction · 0.85
fmt_ptrFunction · 0.85
sanity_check_wormFunction · 0.85
wormno_sanity_checkFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected