]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.worm.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$Id: hack.worm.c,v 1.2 1993/08/02 17:19:40 mycroft Exp $";
13 struct wseg
*wsegs
[32]; /* linked list, tail first */
14 struct wseg
*wheads
[32];
17 getwn(mtmp
) struct monst
*mtmp
; {
19 for(tmp
=1; tmp
<32; tmp
++) if(!wsegs
[tmp
]) {
23 return(0); /* level infested with worms */
26 /* called to initialize a worm unless cut in half */
27 initworm(mtmp
) struct monst
*mtmp
; {
28 register struct wseg
*wtmp
;
29 register tmp
= mtmp
->wormno
;
31 wheads
[tmp
] = wsegs
[tmp
] = wtmp
= newseg();
35 /* wtmp->wdispl = 0; */
39 worm_move(mtmp
) struct monst
*mtmp
; {
40 register struct wseg
*wtmp
, *whd
;
41 register tmp
= mtmp
->wormno
;
46 /* wtmp->wdispl = 0; */
47 (whd
= wheads
[tmp
])->nseg
= wtmp
;
49 if(cansee(whd
->wx
,whd
->wy
)){
51 atl(whd
->wx
, whd
->wy
, '~');
53 } else whd
->wdispl
= 0;
54 if(wgrowtime
[tmp
] <= moves
) {
55 if(!wgrowtime
[tmp
]) wgrowtime
[tmp
] = moves
+ rnd(5);
56 else wgrowtime
[tmp
] += 2+rnd(15);
62 wsegs
[tmp
] = whd
->nseg
;
66 worm_nomove(mtmp
) register struct monst
*mtmp
; {
68 register struct wseg
*wtmp
;
71 if(wtmp
== wheads
[tmp
]) return;
72 if(wtmp
== 0 || wtmp
->nseg
== 0) panic("worm_nomove?");
73 wsegs
[tmp
] = wtmp
->nseg
;
75 mtmp
->mhp
-= 3; /* mhpmax not changed ! */
78 wormdead(mtmp
) register struct monst
*mtmp
; {
79 register tmp
= mtmp
->wormno
;
80 register struct wseg
*wtmp
, *wtmp2
;
83 for(wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp2
){
90 wormhit(mtmp
) register struct monst
*mtmp
; {
91 register tmp
= mtmp
->wormno
;
92 register struct wseg
*wtmp
;
93 if(!tmp
) return; /* worm without tail */
94 for(wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp
->nseg
)
98 wormsee(tmp
) register unsigned tmp
; {
99 register struct wseg
*wtmp
= wsegs
[tmp
];
100 if(!wtmp
) panic("wormsee: wtmp==0");
101 for(; wtmp
->nseg
; wtmp
= wtmp
->nseg
)
102 if(!cansee(wtmp
->wx
,wtmp
->wy
) && wtmp
->wdispl
){
103 newsym(wtmp
->wx
, wtmp
->wy
);
108 pwseg(wtmp
) register struct wseg
*wtmp
; {
110 atl(wtmp
->wx
, wtmp
->wy
, '~');
115 cutworm(mtmp
,x
,y
,weptyp
)
116 register struct monst
*mtmp
;
118 register uchar weptyp
; /* uwep->otyp or 0 */
120 register struct wseg
*wtmp
, *wtmp2
;
121 register struct monst
*mtmp2
;
123 if(mtmp
->mx
== x
&& mtmp
->my
== y
) return; /* hit headon */
125 /* cutting goes best with axe or sword */
127 if(weptyp
== LONG_SWORD
|| weptyp
== TWO_HANDED_SWORD
||
128 weptyp
== AXE
) tmp
+= 5;
131 /* if tail then worm just loses a tail segment */
134 if(wtmp
->wx
== x
&& wtmp
->wy
== y
){
135 wsegs
[tmp
] = wtmp
->nseg
;
140 /* cut the worm in two halves */
143 mtmp2
->mxlth
= mtmp2
->mnamelth
= 0;
145 /* sometimes the tail end dies */
146 if(rn2(3) || !getwn(mtmp2
)){
150 tmp2
= mtmp2
->wormno
;
151 wsegs
[tmp2
] = wsegs
[tmp
];
155 if(wtmp
->nseg
->wx
== x
&& wtmp
->nseg
->wy
== y
){
156 if(tmp2
) wheads
[tmp2
] = wtmp
;
157 wsegs
[tmp
] = wtmp
->nseg
->nseg
;
161 pline("You cut the worm in half.");
162 mtmp2
->mhpmax
= mtmp2
->mhp
=
163 d(mtmp2
->data
->mlevel
, 8);
164 mtmp2
->mx
= wtmp
->wx
;
165 mtmp2
->my
= wtmp
->wy
;
170 pline("You cut off part of the worm's tail.");
177 if(!tmp2
) remseg(wtmp
);
180 panic("Cannot find worm segment");
183 remseg(wtmp
) register struct wseg
*wtmp
; {
185 newsym(wtmp
->wx
, wtmp
->wy
);