Add sanity checking for long worms

This commit is contained in:
Pasi Kallinen
2017-06-16 18:27:25 +03:00
parent 015f877705
commit 60443a4ee7
3 changed files with 25 additions and 0 deletions

View File

@@ -2761,6 +2761,7 @@ E void FDECL(detect_wsegs, (struct monst *, BOOLEAN_P));
E void FDECL(save_worm, (int, int));
E void FDECL(rest_worm, (int));
E void FDECL(place_wsegs, (struct monst *));
E void FDECL(sanity_check_worm, (struct monst *));
E void FDECL(remove_worm, (struct monst *));
E void FDECL(place_worm_tail_randomly, (struct monst *, XCHAR_P, XCHAR_P));
E int FDECL(size_wseg, (struct monst *));

View File

@@ -93,6 +93,8 @@ mon_sanity_check()
else if (level.monsters[x][y] != mtmp)
impossible("mon (%s) at <%d,%d> is not there!",
fmt_ptr((genericptr_t) mtmp), x, y);
else if (mtmp->wormno)
sanity_check_worm(mtmp);
}
for (x = 0; x < COLNO; x++)

View File

@@ -569,6 +569,28 @@ struct monst *worm;
}
}
void
sanity_check_worm(worm)
struct monst *worm;
{
struct wseg *curr;
if (!worm)
panic("no worm!");
if (!worm->wormno)
panic("not a worm?!");
curr = wtails[worm->wormno];
while (curr != wheads[worm->wormno]) {
if (!isok(curr->wx, curr->wy))
panic("worm seg not isok");
if (level.monsters[curr->wx][curr->wy] != worm)
panic("worm not at seg location");
curr = curr->nseg;
}
}
/*
* remove_worm()
*