mps(4): Add module version.
[dragonfly.git] / games / hack / hack.worn.c
blob9067055ccae1569dfa8c4a686342fee64371844c
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.worn.c - version 1.0.2 */
3 /* $FreeBSD: src/games/hack/hack.worn.c,v 1.3 1999/11/16 02:57:14 billf Exp $ */
4 /* $DragonFly: src/games/hack/hack.worn.c,v 1.3 2006/08/21 19:45:32 pavalos Exp $ */
6 #include "hack.h"
8 struct worn {
9 long w_mask;
10 struct obj **w_obj;
11 } worn[] = {
12 { W_ARM, &uarm },
13 { W_ARM2, &uarm2 },
14 { W_ARMH, &uarmh },
15 { W_ARMS, &uarms },
16 { W_ARMG, &uarmg },
17 { W_RINGL, &uleft },
18 { W_RINGR, &uright },
19 { W_WEP, &uwep },
20 { W_BALL, &uball },
21 { W_CHAIN, &uchain },
22 { 0, 0 }
25 void
26 setworn(struct obj *obj, long mask)
28 struct worn *wp;
29 struct obj *oobj;
31 for (wp = worn; wp->w_mask; wp++)
32 if (wp->w_mask & mask) {
33 oobj = *(wp->w_obj);
34 if (oobj && !(oobj->owornmask & wp->w_mask))
35 impossible("Setworn: mask = %ld.", wp->w_mask);
36 if (oobj)
37 oobj->owornmask &= ~wp->w_mask;
38 if (obj && oobj && wp->w_mask == W_ARM) {
39 if (uarm2)
40 impossible("Setworn: uarm2 set?");
41 else
42 setworn(uarm, W_ARM2);
44 *(wp->w_obj) = obj;
45 if (obj)
46 obj->owornmask |= wp->w_mask;
48 if (uarm2 && !uarm) {
49 uarm = uarm2;
50 uarm2 = 0;
51 uarm->owornmask ^= (W_ARM | W_ARM2);
55 /* called e.g. when obj is destroyed */
56 void
57 setnotworn(struct obj *obj)
59 struct worn *wp;
61 for (wp = worn; wp->w_mask; wp++)
62 if (obj == *(wp->w_obj)) {
63 *(wp->w_obj) = 0;
64 obj->owornmask &= ~wp->w_mask;
66 if (uarm2 && !uarm) {
67 uarm = uarm2;
68 uarm2 = 0;
69 uarm->owornmask ^= (W_ARM | W_ARM2);