| 255 | } |
| 256 | |
| 257 | void |
| 258 | mon_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 |
no test coverage detected