]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.worm.c
ba3505d19b4f32ff9059609b840cf5c8f25e8e00
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.worm.c - version 1.0.2 */
8 struct wseg
*wsegs
[32]; /* linked list, tail first */
9 struct wseg
*wheads
[32];
12 getwn(mtmp
) struct monst
*mtmp
; {
14 for(tmp
=1; tmp
<32; tmp
++) if(!wsegs
[tmp
]) {
18 return(0); /* level infested with worms */
21 /* called to initialize a worm unless cut in half */
22 initworm(mtmp
) struct monst
*mtmp
; {
23 register struct wseg
*wtmp
;
24 register tmp
= mtmp
->wormno
;
26 wheads
[tmp
] = wsegs
[tmp
] = wtmp
= newseg();
30 /* wtmp->wdispl = 0; */
34 worm_move(mtmp
) struct monst
*mtmp
; {
35 register struct wseg
*wtmp
, *whd
;
36 register tmp
= mtmp
->wormno
;
41 /* wtmp->wdispl = 0; */
42 (whd
= wheads
[tmp
])->nseg
= wtmp
;
44 if(cansee(whd
->wx
,whd
->wy
)){
46 atl(whd
->wx
, whd
->wy
, '~');
48 } else whd
->wdispl
= 0;
49 if(wgrowtime
[tmp
] <= moves
) {
50 if(!wgrowtime
[tmp
]) wgrowtime
[tmp
] = moves
+ rnd(5);
51 else wgrowtime
[tmp
] += 2+rnd(15);
57 wsegs
[tmp
] = whd
->nseg
;
61 worm_nomove(mtmp
) register struct monst
*mtmp
; {
63 register struct wseg
*wtmp
;
66 if(wtmp
== wheads
[tmp
]) return;
67 if(wtmp
== 0 || wtmp
->nseg
== 0) panic("worm_nomove?");
68 wsegs
[tmp
] = wtmp
->nseg
;
70 mtmp
->mhp
-= 3; /* mhpmax not changed ! */
73 wormdead(mtmp
) register struct monst
*mtmp
; {
74 register tmp
= mtmp
->wormno
;
75 register struct wseg
*wtmp
, *wtmp2
;
78 for(wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp2
){
85 wormhit(mtmp
) register struct monst
*mtmp
; {
86 register tmp
= mtmp
->wormno
;
87 register struct wseg
*wtmp
;
88 if(!tmp
) return; /* worm without tail */
89 for(wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp
->nseg
)
93 wormsee(tmp
) register unsigned tmp
; {
94 register struct wseg
*wtmp
= wsegs
[tmp
];
95 if(!wtmp
) panic("wormsee: wtmp==0");
96 for(; wtmp
->nseg
; wtmp
= wtmp
->nseg
)
97 if(!cansee(wtmp
->wx
,wtmp
->wy
) && wtmp
->wdispl
){
98 newsym(wtmp
->wx
, wtmp
->wy
);
103 pwseg(wtmp
) register struct wseg
*wtmp
; {
105 atl(wtmp
->wx
, wtmp
->wy
, '~');
110 cutworm(mtmp
,x
,y
,weptyp
)
111 register struct monst
*mtmp
;
113 register uchar weptyp
; /* uwep->otyp or 0 */
115 register struct wseg
*wtmp
, *wtmp2
;
116 register struct monst
*mtmp2
;
118 if(mtmp
->mx
== x
&& mtmp
->my
== y
) return; /* hit headon */
120 /* cutting goes best with axe or sword */
122 if(weptyp
== LONG_SWORD
|| weptyp
== TWO_HANDED_SWORD
||
123 weptyp
== AXE
) tmp
+= 5;
126 /* if tail then worm just loses a tail segment */
129 if(wtmp
->wx
== x
&& wtmp
->wy
== y
){
130 wsegs
[tmp
] = wtmp
->nseg
;
135 /* cut the worm in two halves */
138 mtmp2
->mxlth
= mtmp2
->mnamelth
= 0;
140 /* sometimes the tail end dies */
141 if(rn2(3) || !getwn(mtmp2
)){
145 tmp2
= mtmp2
->wormno
;
146 wsegs
[tmp2
] = wsegs
[tmp
];
150 if(wtmp
->nseg
->wx
== x
&& wtmp
->nseg
->wy
== y
){
151 if(tmp2
) wheads
[tmp2
] = wtmp
;
152 wsegs
[tmp
] = wtmp
->nseg
->nseg
;
156 pline("You cut the worm in half.");
157 mtmp2
->mhpmax
= mtmp2
->mhp
=
158 d(mtmp2
->data
->mlevel
, 8);
159 mtmp2
->mx
= wtmp
->wx
;
160 mtmp2
->my
= wtmp
->wy
;
165 pline("You cut off part of the worm's tail.");
172 if(!tmp2
) remseg(wtmp
);
175 panic("Cannot find worm segment");
178 remseg(wtmp
) register struct wseg
*wtmp
; {
180 newsym(wtmp
->wx
, wtmp
->wy
);