2011-08-07 00:29:37 +04:00
|
|
|
/* $NetBSD: hack.worm.c,v 1.9 2011/08/06 20:29:37 dholland Exp $ */
|
1997-10-19 20:56:41 +04:00
|
|
|
|
1993-08-02 21:18:41 +04:00
|
|
|
/*
|
2003-04-02 22:36:33 +04:00
|
|
|
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
|
|
|
|
* Amsterdam
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* - Neither the name of the Stichting Centrum voor Wiskunde en
|
|
|
|
* Informatica, nor the names of its contributors may be used to endorse or
|
|
|
|
* promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
|
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1993-08-02 21:18:41 +04:00
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:18:41 +04:00
|
|
|
#ifndef lint
|
2011-08-07 00:29:37 +04:00
|
|
|
__RCSID("$NetBSD: hack.worm.c,v 1.9 2011/08/06 20:29:37 dholland Exp $");
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <stdlib.h>
|
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
|
|
|
#ifndef NOWORM
|
|
|
|
#include "def.wseg.h"
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
struct wseg *wsegs[32]; /* linked list, tail first */
|
|
|
|
struct wseg *wheads[32];
|
|
|
|
long wgrowtime[32];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-08-12 11:28:40 +04:00
|
|
|
static void remseg(struct wseg *);
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
2009-06-07 22:30:39 +04:00
|
|
|
getwn(struct monst *mtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
for (tmp = 1; tmp < 32; tmp++)
|
|
|
|
if (!wsegs[tmp]) {
|
|
|
|
mtmp->wormno = tmp;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0); /* level infested with worms */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called to initialize a worm unless cut in half */
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
initworm(struct monst *mtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
struct wseg *wtmp;
|
|
|
|
int tmp = mtmp->wormno;
|
|
|
|
if (!tmp)
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
wheads[tmp] = wsegs[tmp] = wtmp = newseg();
|
|
|
|
wgrowtime[tmp] = 0;
|
|
|
|
wtmp->wx = mtmp->mx;
|
|
|
|
wtmp->wy = mtmp->my;
|
1997-10-19 20:56:41 +04:00
|
|
|
/* wtmp->wdispl = 0; */
|
1993-03-21 12:45:37 +03:00
|
|
|
wtmp->nseg = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
worm_move(struct monst *mtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
struct wseg *wtmp, *whd = NULL;
|
|
|
|
int tmp = mtmp->wormno;
|
1993-03-21 12:45:37 +03:00
|
|
|
wtmp = newseg();
|
|
|
|
wtmp->wx = mtmp->mx;
|
|
|
|
wtmp->wy = mtmp->my;
|
|
|
|
wtmp->nseg = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
/* wtmp->wdispl = 0; */
|
1993-03-21 12:45:37 +03:00
|
|
|
(whd = wheads[tmp])->nseg = wtmp;
|
|
|
|
wheads[tmp] = wtmp;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (cansee(whd->wx, whd->wy)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
unpmon(mtmp);
|
|
|
|
atl(whd->wx, whd->wy, '~');
|
|
|
|
whd->wdispl = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
} else
|
|
|
|
whd->wdispl = 0;
|
|
|
|
if (wgrowtime[tmp] <= moves) {
|
|
|
|
if (!wgrowtime[tmp])
|
|
|
|
wgrowtime[tmp] = moves + rnd(5);
|
|
|
|
else
|
|
|
|
wgrowtime[tmp] += 2 + rnd(15);
|
1993-03-21 12:45:37 +03:00
|
|
|
mtmp->mhpmax += 3;
|
|
|
|
mtmp->mhp += 3;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
whd = wsegs[tmp];
|
|
|
|
wsegs[tmp] = whd->nseg;
|
|
|
|
remseg(whd);
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
worm_nomove(struct monst *mtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
struct wseg *wtmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
tmp = mtmp->wormno;
|
|
|
|
wtmp = wsegs[tmp];
|
1997-10-19 20:56:41 +04:00
|
|
|
if (wtmp == wheads[tmp])
|
|
|
|
return;
|
|
|
|
if (wtmp == 0 || wtmp->nseg == 0)
|
|
|
|
panic("worm_nomove?");
|
1993-03-21 12:45:37 +03:00
|
|
|
wsegs[tmp] = wtmp->nseg;
|
|
|
|
remseg(wtmp);
|
1997-10-19 20:56:41 +04:00
|
|
|
mtmp->mhp -= 3; /* mhpmax not changed ! */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
wormdead(struct monst *mtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
int tmp = mtmp->wormno;
|
|
|
|
struct wseg *wtmp, *wtmp2;
|
|
|
|
if (!tmp)
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
mtmp->wormno = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (wtmp = wsegs[tmp]; wtmp; wtmp = wtmp2) {
|
1993-03-21 12:45:37 +03:00
|
|
|
wtmp2 = wtmp->nseg;
|
|
|
|
remseg(wtmp);
|
|
|
|
}
|
|
|
|
wsegs[tmp] = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
wormhit(struct monst *mtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
int tmp = mtmp->wormno;
|
|
|
|
struct wseg *wtmp;
|
|
|
|
if (!tmp)
|
|
|
|
return; /* worm without tail */
|
|
|
|
for (wtmp = wsegs[tmp]; wtmp; wtmp = wtmp->nseg)
|
|
|
|
(void) hitu(mtmp, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
wormsee(unsigned tmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
struct wseg *wtmp = wsegs[tmp];
|
|
|
|
if (!wtmp)
|
|
|
|
panic("wormsee: wtmp==0");
|
|
|
|
for (; wtmp->nseg; wtmp = wtmp->nseg)
|
|
|
|
if (!cansee(wtmp->wx, wtmp->wy) && wtmp->wdispl) {
|
1993-03-21 12:45:37 +03:00
|
|
|
newsym(wtmp->wx, wtmp->wy);
|
|
|
|
wtmp->wdispl = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
pwseg(struct wseg *wtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
if (!wtmp->wdispl) {
|
1993-03-21 12:45:37 +03:00
|
|
|
atl(wtmp->wx, wtmp->wy, '~');
|
|
|
|
wtmp->wdispl = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-07 22:30:39 +04:00
|
|
|
/* weptyp is uwep->otyp or 0 */
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
cutworm(struct monst *mtmp, xchar x, xchar y, uchar weptyp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct wseg *wtmp, *wtmp2;
|
|
|
|
struct monst *mtmp2;
|
|
|
|
int tmp, tmp2;
|
|
|
|
if (mtmp->mx == x && mtmp->my == y)
|
|
|
|
return; /* hit headon */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* cutting goes best with axe or sword */
|
|
|
|
tmp = rnd(20);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (weptyp == LONG_SWORD || weptyp == TWO_HANDED_SWORD ||
|
|
|
|
weptyp == AXE)
|
|
|
|
tmp += 5;
|
|
|
|
if (tmp < 12)
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* if tail then worm just loses a tail segment */
|
|
|
|
tmp = mtmp->wormno;
|
|
|
|
wtmp = wsegs[tmp];
|
1997-10-19 20:56:41 +04:00
|
|
|
if (wtmp->wx == x && wtmp->wy == y) {
|
1993-03-21 12:45:37 +03:00
|
|
|
wsegs[tmp] = wtmp->nseg;
|
|
|
|
remseg(wtmp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* cut the worm in two halves */
|
|
|
|
mtmp2 = newmonst(0);
|
|
|
|
*mtmp2 = *mtmp;
|
|
|
|
mtmp2->mxlth = mtmp2->mnamelth = 0;
|
|
|
|
|
|
|
|
/* sometimes the tail end dies */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (rn2(3) || !getwn(mtmp2)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
monfree(mtmp2);
|
|
|
|
tmp2 = 0;
|
|
|
|
} else {
|
|
|
|
tmp2 = mtmp2->wormno;
|
|
|
|
wsegs[tmp2] = wsegs[tmp];
|
|
|
|
wgrowtime[tmp2] = 0;
|
|
|
|
}
|
|
|
|
do {
|
1997-10-19 20:56:41 +04:00
|
|
|
if (wtmp->nseg->wx == x && wtmp->nseg->wy == y) {
|
|
|
|
if (tmp2)
|
|
|
|
wheads[tmp2] = wtmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
wsegs[tmp] = wtmp->nseg->nseg;
|
|
|
|
remseg(wtmp->nseg);
|
|
|
|
wtmp->nseg = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (tmp2) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("You cut the worm in half.");
|
|
|
|
mtmp2->mhpmax = mtmp2->mhp =
|
|
|
|
d(mtmp2->data->mlevel, 8);
|
|
|
|
mtmp2->mx = wtmp->wx;
|
|
|
|
mtmp2->my = wtmp->wy;
|
|
|
|
mtmp2->nmon = fmon;
|
|
|
|
fmon = mtmp2;
|
|
|
|
pmon(mtmp2);
|
|
|
|
} else {
|
|
|
|
pline("You cut off part of the worm's tail.");
|
|
|
|
remseg(wtmp);
|
2006-05-14 02:43:02 +04:00
|
|
|
monfree(mtmp2);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
mtmp->mhp /= 2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wtmp2 = wtmp->nseg;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!tmp2)
|
|
|
|
remseg(wtmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
wtmp = wtmp2;
|
1997-10-19 20:56:41 +04:00
|
|
|
} while (wtmp->nseg);
|
1993-03-21 12:45:37 +03:00
|
|
|
panic("Cannot find worm segment");
|
|
|
|
}
|
|
|
|
|
2009-08-12 11:28:40 +04:00
|
|
|
static void
|
2009-06-07 22:30:39 +04:00
|
|
|
remseg(struct wseg *wtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
if (wtmp->wdispl)
|
1993-03-21 12:45:37 +03:00
|
|
|
newsym(wtmp->wx, wtmp->wy);
|
2011-08-07 00:29:37 +04:00
|
|
|
free(wtmp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* NOWORM */
|