Source:NetHack 2.3e/worn.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to worn.c from the source code of NetHack 2.3e.

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

Screenshots and source code from Hack are used under the CWI license.

1.    /*	SCCS Id: @(#)worn.c	2.3	88/01/21
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    
4.    #include "hack.h"
5.    
6.    struct worn {
7.    	long w_mask;
8.    	struct obj **w_obj;
9.    } worn[] = {
10.   	{ W_ARM, &uarm },
11.   	{ W_ARM2, &uarm2 },
12.   	{ W_ARMH, &uarmh },
13.   	{ W_ARMS, &uarms },
14.   	{ W_ARMG, &uarmg },
15.   	{ W_ARMU, &uarmu },
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.   }