]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.worn.c
Don't use <sys/cdefs.h> __COPYRIGHT/__RCSID macros for host programs -
[bsdgames-darwin.git] / hack / hack.worn.c
1 /* $NetBSD: hack.worn.c,v 1.4 1997/10/19 16:59:32 christos Exp $ */
2
3 /*
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
5 */
6
7 #include <sys/cdefs.h>
8 #ifndef lint
9 __RCSID("$NetBSD: hack.worn.c,v 1.4 1997/10/19 16:59:32 christos Exp $");
10 #endif /* not lint */
11
12 #include "hack.h"
13 #include "extern.h"
14
15 struct worn {
16 long w_mask;
17 struct obj **w_obj;
18 } worn[] = {
19 {
20 W_ARM, &uarm
21 },
22 {
23 W_ARM2, &uarm2
24 },
25 {
26 W_ARMH, &uarmh
27 },
28 {
29 W_ARMS, &uarms
30 },
31 {
32 W_ARMG, &uarmg
33 },
34 {
35 W_RINGL, &uleft
36 },
37 {
38 W_RINGR, &uright
39 },
40 {
41 W_WEP, &uwep
42 },
43 {
44 W_BALL, &uball
45 },
46 {
47 W_CHAIN, &uchain
48 },
49 {
50 0, 0
51 }
52 };
53
54 void
55 setworn(obj, mask)
56 struct obj *obj;
57 long mask;
58 {
59 struct worn *wp;
60 struct obj *oobj;
61
62 for (wp = worn; wp->w_mask; wp++)
63 if (wp->w_mask & mask) {
64 oobj = *(wp->w_obj);
65 if (oobj && !(oobj->owornmask & wp->w_mask))
66 impossible("Setworn: mask = %ld.", wp->w_mask);
67 if (oobj)
68 oobj->owornmask &= ~wp->w_mask;
69 if (obj && oobj && wp->w_mask == W_ARM) {
70 if (uarm2) {
71 impossible("Setworn: uarm2 set?");
72 } else
73 setworn(uarm, W_ARM2);
74 }
75 *(wp->w_obj) = obj;
76 if (obj)
77 obj->owornmask |= wp->w_mask;
78 }
79 if (uarm2 && !uarm) {
80 uarm = uarm2;
81 uarm2 = 0;
82 uarm->owornmask ^= (W_ARM | W_ARM2);
83 }
84 }
85
86 /* called e.g. when obj is destroyed */
87 void
88 setnotworn(obj)
89 struct obj *obj;
90 {
91 struct worn *wp;
92
93 for (wp = worn; wp->w_mask; wp++)
94 if (obj == *(wp->w_obj)) {
95 *(wp->w_obj) = 0;
96 obj->owornmask &= ~wp->w_mask;
97 }
98 if (uarm2 && !uarm) {
99 uarm = uarm2;
100 uarm2 = 0;
101 uarm->owornmask ^= (W_ARM | W_ARM2);
102 }
103 }