Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / games / hack / hack.worn.c
CommitLineData
984263bc
MD
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 $ */
1de703da 4/* $DragonFly: src/games/hack/hack.worn.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ */
984263bc
MD
5
6#include "hack.h"
7
8struct 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 }
23};
24
25setworn(obj, mask)
26struct obj *obj;
27long mask;
28{
29 struct worn *wp;
30 struct obj *oobj;
31
32 for(wp = worn; wp->w_mask; wp++) 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) oobj->owornmask &= ~wp->w_mask;
37 if(obj && oobj && wp->w_mask == W_ARM){
38 if(uarm2) {
39 impossible("Setworn: uarm2 set?");
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 */
54setnotworn(obj) struct obj *obj; {
55 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}