]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.worn.c
merge with Lite, new RCS id conventions, etc.
[bsdgames-darwin.git] / hack / hack.worn.c
1 /*
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
3 */
4
5 #ifndef lint
6 static char rcsid[] = "$NetBSD: hack.worn.c,v 1.3 1995/03/23 08:32:17 cgd Exp $";
7 #endif /* not lint */
8
9 #include "hack.h"
10
11 struct worn {
12 long w_mask;
13 struct obj **w_obj;
14 } worn[] = {
15 { W_ARM, &uarm },
16 { W_ARM2, &uarm2 },
17 { W_ARMH, &uarmh },
18 { W_ARMS, &uarms },
19 { W_ARMG, &uarmg },
20 { W_RINGL, &uleft },
21 { W_RINGR, &uright },
22 { W_WEP, &uwep },
23 { W_BALL, &uball },
24 { W_CHAIN, &uchain },
25 { 0, 0 }
26 };
27
28 setworn(obj, mask)
29 register struct obj *obj;
30 long mask;
31 {
32 register struct worn *wp;
33 register struct obj *oobj;
34
35 for(wp = worn; wp->w_mask; wp++) if(wp->w_mask & mask) {
36 oobj = *(wp->w_obj);
37 if(oobj && !(oobj->owornmask & wp->w_mask))
38 impossible("Setworn: mask = %ld.", wp->w_mask);
39 if(oobj) oobj->owornmask &= ~wp->w_mask;
40 if(obj && oobj && wp->w_mask == W_ARM){
41 if(uarm2) {
42 impossible("Setworn: uarm2 set?");
43 } else
44 setworn(uarm, W_ARM2);
45 }
46 *(wp->w_obj) = obj;
47 if(obj) obj->owornmask |= wp->w_mask;
48 }
49 if(uarm2 && !uarm) {
50 uarm = uarm2;
51 uarm2 = 0;
52 uarm->owornmask ^= (W_ARM | W_ARM2);
53 }
54 }
55
56 /* called e.g. when obj is destroyed */
57 setnotworn(obj) register struct obj *obj; {
58 register struct worn *wp;
59
60 for(wp = worn; wp->w_mask; wp++)
61 if(obj == *(wp->w_obj)) {
62 *(wp->w_obj) = 0;
63 obj->owornmask &= ~wp->w_mask;
64 }
65 if(uarm2 && !uarm) {
66 uarm = uarm2;
67 uarm2 = 0;
68 uarm->owornmask ^= (W_ARM | W_ARM2);
69 }
70 }