NetBSD/games/hack/hack.worn.c

104 lines
1.6 KiB
C
Raw Normal View History

1997-10-19 20:56:41 +04:00
/* $NetBSD: hack.worn.c,v 1.4 1997/10/19 16:59:32 christos Exp $ */
/*
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
*/
1997-10-19 20:56:41 +04:00
#include <sys/cdefs.h>
#ifndef lint
1997-10-19 20:56:41 +04:00
__RCSID("$NetBSD: hack.worn.c,v 1.4 1997/10/19 16:59:32 christos Exp $");
#endif /* not lint */
1993-03-21 12:45:37 +03:00
#include "hack.h"
1997-10-19 20:56:41 +04:00
#include "extern.h"
1993-03-21 12:45:37 +03:00
struct worn {
1997-10-19 20:56:41 +04:00
long w_mask;
struct obj **w_obj;
} worn[] = {
{
W_ARM, &uarm
},
{
W_ARM2, &uarm2
},
{
W_ARMH, &uarmh
},
{
W_ARMS, &uarms
},
{
W_ARMG, &uarmg
},
{
W_RINGL, &uleft
},
{
W_RINGR, &uright
},
{
W_WEP, &uwep
},
{
W_BALL, &uball
},
{
W_CHAIN, &uchain
},
{
0, 0
}
1993-03-21 12:45:37 +03:00
};
1997-10-19 20:56:41 +04:00
void
1993-03-21 12:45:37 +03:00
setworn(obj, mask)
1997-10-19 20:56:41 +04:00
struct obj *obj;
long mask;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
struct worn *wp;
struct obj *oobj;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
for (wp = worn; wp->w_mask; wp++)
if (wp->w_mask & mask) {
oobj = *(wp->w_obj);
if (oobj && !(oobj->owornmask & wp->w_mask))
impossible("Setworn: mask = %ld.", wp->w_mask);
if (oobj)
oobj->owornmask &= ~wp->w_mask;
if (obj && oobj && wp->w_mask == W_ARM) {
if (uarm2) {
impossible("Setworn: uarm2 set?");
} else
setworn(uarm, W_ARM2);
}
*(wp->w_obj) = obj;
if (obj)
obj->owornmask |= wp->w_mask;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (uarm2 && !uarm) {
1993-03-21 12:45:37 +03:00
uarm = uarm2;
uarm2 = 0;
uarm->owornmask ^= (W_ARM | W_ARM2);
}
}
/* called e.g. when obj is destroyed */
1997-10-19 20:56:41 +04:00
void
setnotworn(obj)
struct obj *obj;
{
struct worn *wp;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
for (wp = worn; wp->w_mask; wp++)
if (obj == *(wp->w_obj)) {
1993-03-21 12:45:37 +03:00
*(wp->w_obj) = 0;
obj->owornmask &= ~wp->w_mask;
}
1997-10-19 20:56:41 +04:00
if (uarm2 && !uarm) {
1993-03-21 12:45:37 +03:00
uarm = uarm2;
uarm2 = 0;
uarm->owornmask ^= (W_ARM | W_ARM2);
}
}