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