Source:NetHack 2.2a/worn.c

Below is the full text to worn.c from the source code of NetHack 2.2a. To link to a particular line, write [[NetHack 2.2a/worn.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)worn.c	1.4	87/08/08 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* worn.c - version 1.0.2 */ 4.    5.    #include "hack.h"  6. 7.   struct worn { 8.   	long w_mask; 9.   	struct obj **w_obj; 10.  } worn[] = { 11.  	{ W_ARM, &uarm }, 12.  	{ W_ARM2, &uarm2 }, 13.  	{ W_ARMH, &uarmh }, 14.  	{ W_ARMS, &uarms }, 15.  	{ W_ARMG, &uarmg }, 16.  	{ W_RINGL, &uleft }, 17.  	{ W_RINGR, &uright }, 18.  	{ W_WEP, &uwep }, 19.  	{ W_BALL, &uball }, 20.  	{ W_CHAIN, &uchain }, 21.  	{ 0, 0 }  22.   };  23.    24.   setworn(obj, mask) 25.  register struct obj *obj; 26.  long mask; 27.  {  28.   	register struct worn *wp; 29.  	register struct obj *oobj; 30.   31.   	for(wp = worn; wp->w_mask; wp++) if(wp->w_mask & mask) { 32.  		oobj = *(wp->w_obj); 33.  		if(oobj && !(oobj->owornmask & wp->w_mask)) 34.  			impossible("Setworn: mask = %ld.", wp->w_mask); 35.  		if(oobj) oobj->owornmask &= ~wp->w_mask; 36.  		if(obj && oobj && wp->w_mask == W_ARM){ 37.  			if(uarm2) { 38.  				impossible("Setworn: uarm2 set?"); 39.  			} else 40.  				setworn(uarm, W_ARM2); 41.  		}  42.   		*(wp->w_obj) = obj; 43.  		if(obj) obj->owornmask |= wp->w_mask; 44.  	}  45.   	if(uarm2 && !uarm) { 46.  		uarm = uarm2; 47.  		uarm2 = 0; 48.  		uarm->owornmask ^= (W_ARM | W_ARM2); 49.  	}  50.   }  51.    52.   /* called e.g. when obj is destroyed */ 53.  setnotworn(obj) register struct obj *obj; { 54.  	register struct worn *wp; 55.   56.   	for(wp = worn; wp->w_mask; wp++) 57.  		if(obj == *(wp->w_obj)) { 58.  			*(wp->w_obj) = 0; 59.  			obj->owornmask &= ~wp->w_mask; 60.  		}  61.   	if(uarm2 && !uarm) { 62.  		uarm = uarm2; 63.  		uarm2 = 0; 64.  		uarm->owornmask ^= (W_ARM | W_ARM2); 65.  	}  66.   }