Source:Hack 1.0/hack.worn.c

From NetHackWiki
(Redirected from Hack 1.0/hack.worn.c)
Jump to navigation Jump to search

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

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

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

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