1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.worm.c - version 1.0.2 */
9 struct wseg *wsegs[32]; /* linked list, tail first */
10 struct wseg *wheads[32];
13 getwn(mtmp) struct monst *mtmp; {
15 for(tmp=1; tmp<32; tmp++) if(!wsegs[tmp]) {
19 return(0); /* level infested with worms */
22 /* called to initialize a worm unless cut in half */
23 initworm(mtmp) struct monst *mtmp; {
25 int tmp = mtmp->wormno;
27 wheads[tmp] = wsegs[tmp] = wtmp = newseg();
31 /* wtmp->wdispl = 0; */
35 worm_move(mtmp) struct monst *mtmp; {
36 struct wseg *wtmp, *whd;
37 int tmp = mtmp->wormno;
42 /* wtmp->wdispl = 0; */
43 (whd = wheads[tmp])->nseg = wtmp;
45 if(cansee(whd->wx,whd->wy)){
47 atl(whd->wx, whd->wy, '~');
49 } else whd->wdispl = 0;
50 if(wgrowtime[tmp] <= moves) {
51 if(!wgrowtime[tmp]) wgrowtime[tmp] = moves + rnd(5);
52 else wgrowtime[tmp] += 2+rnd(15);
58 wsegs[tmp] = whd->nseg;
62 worm_nomove(mtmp) struct monst *mtmp; {
67 if(wtmp == wheads[tmp]) return;
68 if(wtmp == 0 || wtmp->nseg == 0) panic("worm_nomove?");
69 wsegs[tmp] = wtmp->nseg;
71 mtmp->mhp -= 3; /* mhpmax not changed ! */
74 wormdead(mtmp) struct monst *mtmp; {
75 int tmp = mtmp->wormno;
76 struct wseg *wtmp, *wtmp2;
79 for(wtmp = wsegs[tmp]; wtmp; wtmp = wtmp2){
86 wormhit(mtmp) struct monst *mtmp; {
87 int tmp = mtmp->wormno;
89 if(!tmp) return; /* worm without tail */
90 for(wtmp = wsegs[tmp]; wtmp; wtmp = wtmp->nseg)
94 wormsee(tmp) unsigned tmp; {
95 struct wseg *wtmp = wsegs[tmp];
96 if(!wtmp) panic("wormsee: wtmp==0");
97 for(; wtmp->nseg; wtmp = wtmp->nseg)
98 if(!cansee(wtmp->wx,wtmp->wy) && wtmp->wdispl){
99 newsym(wtmp->wx, wtmp->wy);
104 pwseg(wtmp) struct wseg *wtmp; {
106 atl(wtmp->wx, wtmp->wy, '~');
111 cutworm(mtmp,x,y,weptyp)
114 uchar weptyp; /* uwep->otyp or 0 */
116 struct wseg *wtmp, *wtmp2;
119 if(mtmp->mx == x && mtmp->my == y) return; /* hit headon */
121 /* cutting goes best with axe or sword */
123 if(weptyp == LONG_SWORD || weptyp == TWO_HANDED_SWORD ||
124 weptyp == AXE) tmp += 5;
127 /* if tail then worm just loses a tail segment */
130 if(wtmp->wx == x && wtmp->wy == y){
131 wsegs[tmp] = wtmp->nseg;
136 /* cut the worm in two halves */
139 mtmp2->mxlth = mtmp2->mnamelth = 0;
141 /* sometimes the tail end dies */
142 if(rn2(3) || !getwn(mtmp2)){
146 tmp2 = mtmp2->wormno;
147 wsegs[tmp2] = wsegs[tmp];
151 if(wtmp->nseg->wx == x && wtmp->nseg->wy == y){
152 if(tmp2) wheads[tmp2] = wtmp;
153 wsegs[tmp] = wtmp->nseg->nseg;
157 pline("You cut the worm in half.");
158 mtmp2->mhpmax = mtmp2->mhp =
159 d(mtmp2->data->mlevel, 8);
160 mtmp2->mx = wtmp->wx;
161 mtmp2->my = wtmp->wy;
166 pline("You cut off part of the worm's tail.");
173 if(!tmp2) remseg(wtmp);
176 panic("Cannot find worm segment");
179 remseg(wtmp) struct wseg *wtmp; {
181 newsym(wtmp->wx, wtmp->wy);