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

Function objlist_sanity

src/mkobj.c:3031–3129  ·  view source on GitHub ↗

sanity check for objects on specified list (fobj, &c) */

Source from the content-addressed store, hash-verified

3029
3030/* sanity check for objects on specified list (fobj, &c) */
3031staticfn void
3032objlist_sanity(struct obj *objlist, int wheretype, const char *mesg)
3033{
3034 struct obj *obj;
3035
3036 for (obj = objlist; obj; obj = obj->nobj) {
3037 if (obj->where != wheretype)
3038 insane_object(obj, ofmt0, mesg, (struct monst *) 0);
3039 if (obj->where == OBJ_INVENT && obj->how_lost != LOST_NONE) {
3040 char lostbuf[40];
3041
3042 /* %d: bitfield is unsigned but narrow, so promotes to int */
3043 Sprintf(lostbuf, "how_lost=%d obj in inventory!", obj->how_lost);
3044 insane_object(obj, ofmt0, lostbuf, (struct monst *) 0);
3045 }
3046 if (Has_contents(obj)) {
3047 if (wheretype == OBJ_ONBILL)
3048 /* containers on shop bill should always be empty */
3049 insane_object(obj, "%s obj contains something! %s %s: %s",
3050 mesg, (struct monst *) 0);
3051 check_contained(obj, mesg);
3052 }
3053 if (obj->unpaid || obj->no_charge) {
3054 shop_obj_sanity(obj, mesg);
3055 }
3056 if (obj->owornmask) {
3057 char maskbuf[40];
3058 boolean bc_ok = FALSE;
3059
3060 switch (obj->where) {
3061 case OBJ_INVENT:
3062 case OBJ_MINVENT:
3063 sanity_check_worn(obj);
3064 break;
3065 case OBJ_MIGRATING:
3066 /* migrating objects overload the owornmask field
3067 with a destination code; skip attempt to check it */
3068 break;
3069 case OBJ_FLOOR:
3070 /* note: ball and chain can also be OBJ_FREE, but not across
3071 turns so this sanity check shouldn't encounter that */
3072 bc_ok = TRUE;
3073 FALLTHROUGH;
3074 /*FALLTHRU*/
3075 default:
3076 if ((obj != uchain && obj != uball) || !bc_ok) {
3077 /* discovered an object not in inventory which
3078 erroneously has worn mask set */
3079 Sprintf(maskbuf, "worn mask 0x%08lx", obj->owornmask);
3080 insane_object(obj, ofmt0, maskbuf, (struct monst *) 0);
3081 }
3082 break;
3083 }
3084 }
3085 if (obj->otyp == LEASH && obj->leashmon) {
3086 char buf[BUFSZ];
3087 struct monst *mtmp = find_mid(obj->leashmon, FM_FMON);
3088

Callers 1

obj_sanity_checkFunction · 0.85

Calls 9

insane_objectFunction · 0.85
check_containedFunction · 0.85
shop_obj_sanityFunction · 0.85
sanity_check_wornFunction · 0.85
find_midFunction · 0.85
mon_pmnameFunction · 0.85
where_nameFunction · 0.85
check_globFunction · 0.85
insane_obj_bitsFunction · 0.85

Tested by

no test coverage detected