MCPcopy Index your code
hub / github.com/NetHack/NetHack / obj_sanity_check

Function obj_sanity_check

src/mkobj.c:2948–3028  ·  view source on GitHub ↗

Check all object lists for consistency. */

Source from the content-addressed store, hash-verified

2946
2947/* Check all object lists for consistency. */
2948void
2949obj_sanity_check(void)
2950{
2951 coordxy x, y;
2952 struct obj *obj, *otop, *prevo;
2953
2954 objlist_sanity(fobj, OBJ_FLOOR, "floor sanity");
2955
2956 /* check that the map's record of floor objects is consistent;
2957 those objects should have already been sanity checked via
2958 the floor list so container contents are skipped here */
2959 for (x = 0; x < COLNO; x++)
2960 for (y = 0; y < ROWNO; y++) {
2961 char at_fmt[BUFSZ];
2962
2963 otop = svl.level.objects[x][y];
2964 prevo = 0;
2965 for (obj = otop; obj; prevo = obj, obj = prevo->nexthere) {
2966 /* <ox,oy> should match <x,y>; <0,*> should always be empty */
2967 if (obj->where != OBJ_FLOOR || x == 0
2968 || obj->ox != x || obj->oy != y) {
2969 Sprintf(at_fmt, "%%s obj@<%d,%d> %%s %%s: %%s@<%d,%d>",
2970 x, y, obj->ox, obj->oy);
2971 insane_object(obj, at_fmt, "location sanity",
2972 (struct monst *) 0);
2973
2974 /* when one or more boulders are present, they should always
2975 be at the top of their pile; also never in water or lava */
2976 } else if (obj->otyp == BOULDER) {
2977 if (prevo && prevo->otyp != BOULDER) {
2978 Sprintf(at_fmt,
2979 "%%s boulder@<%d,%d> %%s %%s: not on top",
2980 x, y);
2981 insane_object(obj, at_fmt, "boulder sanity",
2982 (struct monst *) 0);
2983 }
2984 if (is_pool_or_lava(x, y)) {
2985 Sprintf(at_fmt,
2986 "%%s boulder@<%d,%d> %%s %%s: on/in %s",
2987 x, y, is_pool(x, y) ? "water" : "lava");
2988 insane_object(obj, at_fmt, "boulder sanity",
2989 (struct monst *) 0);
2990 }
2991 }
2992 }
2993 }
2994
2995 objlist_sanity(gi.invent, OBJ_INVENT, "invent sanity");
2996 objlist_sanity(gm.migrating_objs, OBJ_MIGRATING, "migrating sanity");
2997 objlist_sanity(svl.level.buriedobjlist, OBJ_BURIED, "buried sanity");
2998 objlist_sanity(gb.billobjs, OBJ_ONBILL, "bill sanity");
2999 objlist_sanity(go.objs_deleted, OBJ_DELETED, "deleted object sanity");
3000
3001 mon_obj_sanity(fmon, "minvent sanity");
3002 mon_obj_sanity(gm.migrating_mons, "migrating minvent sanity");
3003 /* monsters temporarily in transit;
3004 they should have arrived with hero by the time we get called */
3005 if (gm.mydogs) {

Callers 1

sanity_checkFunction · 0.85

Calls 6

objlist_sanityFunction · 0.85
insane_objectFunction · 0.85
is_pool_or_lavaFunction · 0.85
is_poolFunction · 0.85
mon_obj_sanityFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected