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

Function sanity_check_worn

src/mkobj.c:3446–3637  ·  view source on GitHub ↗

check an object in hero's or monster's inventory which has worn mask set */

Source from the content-addressed store, hash-verified

3444
3445/* check an object in hero's or monster's inventory which has worn mask set */
3446staticfn void
3447sanity_check_worn(struct obj *obj)
3448{
3449#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG)
3450 static unsigned long wearbits[] = {
3451 W_ARM, W_ARMC, W_ARMH, W_ARMS, W_ARMG, W_ARMF, W_ARMU,
3452 W_WEP, W_QUIVER, W_SWAPWEP, W_AMUL, W_RINGL, W_RINGR, W_TOOL,
3453 W_SADDLE, W_BALL, W_CHAIN, 0
3454 /* [W_ART,W_ARTI are property bits for items which aren't worn] */
3455 };
3456 char maskbuf[60];
3457 const char *what;
3458 unsigned long owornmask, allmask = 0L;
3459 boolean embedded = FALSE;
3460 int i, n = 0;
3461
3462 /* use owornmask for testing and bit twiddling, but use original
3463 obj->owornmask for printing */
3464 owornmask = obj->owornmask;
3465 /* figure out how many bits are set, and also which are viable */
3466 for (i = 0; wearbits[i]; ++i) {
3467 if ((owornmask & wearbits[i]) != 0L)
3468 ++n;
3469 allmask |= wearbits[i];
3470 }
3471 if (obj == uskin) {
3472 /* embedded dragon scales have an extra bit set;
3473 make sure it's set, then suppress it */
3474 embedded = TRUE;
3475 if ((owornmask & (W_ARM | I_SPECIAL)) == (W_ARM | I_SPECIAL))
3476 owornmask &= ~I_SPECIAL;
3477 else
3478 n = 0, owornmask = ~0; /* force insane_object("bogus") below */
3479 }
3480 if (n == 2 && carried(obj)
3481 && obj == uball && (owornmask & W_BALL) != 0L
3482 && (owornmask & W_WEAPONS) != 0L) {
3483 /* chained ball can be wielded/alt-wielded/quivered; if so,
3484 pretend it's not chained in order to check the weapon pointer
3485 (we've already verified the ball pointer by successfully passing
3486 the if-condition to get here...) */
3487 owornmask &= ~W_BALL;
3488 n = 1;
3489 }
3490 if (n > 1) {
3491 /* multiple bits set */
3492 Sprintf(maskbuf, "worn mask (multiple) 0x%08lx", obj->owornmask);
3493 insane_object(obj, ofmt0, maskbuf, (struct monst *) 0);
3494 }
3495 if ((owornmask & ~allmask) != 0L
3496 || (carried(obj) && (owornmask & W_SADDLE) != 0L)) {
3497 /* non-wearable bit(s) set */
3498 Sprintf(maskbuf, "worn mask (bogus)) 0x%08lx", obj->owornmask);
3499 insane_object(obj, ofmt0, maskbuf, (struct monst *) 0);
3500 }
3501 if (n == 1 && (carried(obj) || (owornmask & (W_BALL | W_CHAIN)) != 0L)) {
3502 what = 0;
3503 /* verify that obj in hero's invent (or ball/chain elsewhere)

Callers 1

objlist_sanityFunction · 0.85

Calls 2

insane_objectFunction · 0.85
makesingularFunction · 0.85

Tested by

no test coverage detected