1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.worm.c - version 1.0.2 */
3 /* $FreeBSD: src/games/hack/hack.worm.c,v 1.4 1999/11/16 10:26:38 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.worm.c,v 1.3 2004/11/06 12:29:17 eirikn Exp $ */
10 struct wseg
*wsegs
[32]; /* linked list, tail first */
11 struct wseg
*wheads
[32];
14 getwn(mtmp
) struct monst
*mtmp
; {
16 for(tmp
=1; tmp
<32; tmp
++) if(!wsegs
[tmp
]) {
20 return(0); /* level infested with worms */
23 /* called to initialize a worm unless cut in half */
24 initworm(mtmp
) struct monst
*mtmp
; {
26 int tmp
= mtmp
->wormno
;
28 wheads
[tmp
] = wsegs
[tmp
] = wtmp
= newseg();
32 /* wtmp->wdispl = 0; */
36 worm_move(mtmp
) struct monst
*mtmp
; {
37 struct wseg
*wtmp
, *whd
;
38 int tmp
= mtmp
->wormno
;
43 /* wtmp->wdispl = 0; */
44 (whd
= wheads
[tmp
])->nseg
= wtmp
;
46 if(cansee(whd
->wx
,whd
->wy
)){
48 atl(whd
->wx
, whd
->wy
, '~');
50 } else whd
->wdispl
= 0;
51 if(wgrowtime
[tmp
] <= moves
) {
52 if(!wgrowtime
[tmp
]) wgrowtime
[tmp
] = moves
+ rnd(5);
53 else wgrowtime
[tmp
] += 2+rnd(15);
59 wsegs
[tmp
] = whd
->nseg
;
63 worm_nomove(mtmp
) struct monst
*mtmp
; {
68 if(wtmp
== wheads
[tmp
]) return;
69 if(wtmp
== 0 || wtmp
->nseg
== 0) panic("worm_nomove?");
70 wsegs
[tmp
] = wtmp
->nseg
;
72 mtmp
->mhp
-= 3; /* mhpmax not changed ! */
75 wormdead(mtmp
) struct monst
*mtmp
; {
76 int tmp
= mtmp
->wormno
;
77 struct wseg
*wtmp
, *wtmp2
;
80 for(wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp2
){
87 wormhit(mtmp
) struct monst
*mtmp
; {
88 int tmp
= mtmp
->wormno
;
90 if(!tmp
) return; /* worm without tail */
91 for(wtmp
= wsegs
[tmp
]; wtmp
; wtmp
= wtmp
->nseg
)
95 wormsee(tmp
) unsigned tmp
; {
96 struct wseg
*wtmp
= wsegs
[tmp
];
97 if(!wtmp
) panic("wormsee: wtmp==0");
98 for(; wtmp
->nseg
; wtmp
= wtmp
->nseg
)
99 if(!cansee(wtmp
->wx
,wtmp
->wy
) && wtmp
->wdispl
){
100 newsym(wtmp
->wx
, wtmp
->wy
);
105 pwseg(wtmp
) struct wseg
*wtmp
; {
107 atl(wtmp
->wx
, wtmp
->wy
, '~');
112 cutworm(mtmp
,x
,y
,weptyp
)
115 uchar weptyp
; /* uwep->otyp or 0 */
117 struct wseg
*wtmp
, *wtmp2
;
120 if(mtmp
->mx
== x
&& mtmp
->my
== y
) return; /* hit headon */
122 /* cutting goes best with axe or sword */
124 if(weptyp
== LONG_SWORD
|| weptyp
== TWO_HANDED_SWORD
||
125 weptyp
== AXE
) tmp
+= 5;
128 /* if tail then worm just loses a tail segment */
131 if(wtmp
->wx
== x
&& wtmp
->wy
== y
){
132 wsegs
[tmp
] = wtmp
->nseg
;
137 /* cut the worm in two halves */
140 mtmp2
->mxlth
= mtmp2
->mnamelth
= 0;
142 /* sometimes the tail end dies */
143 if(rn2(3) || !getwn(mtmp2
)){
147 tmp2
= mtmp2
->wormno
;
148 wsegs
[tmp2
] = wsegs
[tmp
];
152 if(wtmp
->nseg
->wx
== x
&& wtmp
->nseg
->wy
== y
){
153 if(tmp2
) wheads
[tmp2
] = wtmp
;
154 wsegs
[tmp
] = wtmp
->nseg
->nseg
;
158 pline("You cut the worm in half.");
159 mtmp2
->mhpmax
= mtmp2
->mhp
=
160 d(mtmp2
->data
->mlevel
, 8);
161 mtmp2
->mx
= wtmp
->wx
;
162 mtmp2
->my
= wtmp
->wy
;
167 pline("You cut off part of the worm's tail.");
174 if(!tmp2
) remseg(wtmp
);
177 panic("Cannot find worm segment");
180 remseg(wtmp
) struct wseg
*wtmp
; {
182 newsym(wtmp
->wx
, wtmp
->wy
);