Add monster data sanity checking

This commit is contained in:
Pasi Kallinen
2015-10-11 20:36:28 +03:00
parent 751fab7a59
commit f0220c4203
3 changed files with 36 additions and 0 deletions

View File

@@ -1280,6 +1280,7 @@ E int FDECL(cmap_to_type, (int));
/* ### mon.c ### */
E void NDECL(mon_sanity_check);
E int FDECL(undead_to_corpse, (int));
E int FDECL(genus, (int, int));
E int FDECL(pm_to_cham, (int));

View File

@@ -3067,6 +3067,7 @@ sanity_check()
{
obj_sanity_check();
timer_sanity_check();
mon_sanity_check();
}
#ifdef DEBUG_MIGRATING_MONS

View File

@@ -39,6 +39,40 @@ const char *warnings[] = {
};
#endif /* 0 */
void
sanity_check_single_mon(mtmp, msg)
struct monst *mtmp;
const char *msg;
{
if (DEADMONSTER(mtmp)) return;
if ((mtmp->data < &mons[LOW_PM]) || (mtmp->data >= &mons[NUMMONS]))
impossible("illegal mon data (%s)", msg);
}
void
mon_sanity_check()
{
int x,y;
struct monst *mtmp = fmon;
while (mtmp) {
sanity_check_single_mon(mtmp, "fmon");
mtmp = mtmp->nmon;
}
for (x = 0; x < COLNO; x++)
for (y = 0; y < ROWNO; y++)
if ((mtmp = m_at(x,y)) != 0)
sanity_check_single_mon(mtmp, "m_at");
mtmp = migrating_mons;
while (mtmp) {
sanity_check_single_mon(mtmp, "migr");
mtmp = mtmp->nmon;
}
}
/* convert the monster index of an undead to its living counterpart */
int
undead_to_corpse(mndx)