NetBSD/games/hack/hack.fight.c

412 lines
9.5 KiB
C
Raw Normal View History

/* $NetBSD: hack.fight.c,v 1.5 2001/03/25 20:44:00 jsm Exp $ */
1997-10-19 20:56:41 +04:00
1993-08-02 21:16:36 +04:00
/*
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
*/
1997-10-19 20:56:41 +04:00
#include <sys/cdefs.h>
1993-08-02 21:16:36 +04:00
#ifndef lint
__RCSID("$NetBSD: hack.fight.c,v 1.5 2001/03/25 20:44:00 jsm 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 "hack.h"
#include "extern.h"
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
static boolean far_noise;
static long noisetime;
1993-03-21 12:45:37 +03:00
/* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
1997-10-19 20:56:41 +04:00
int
hitmm(magr, mdef)
struct monst *magr, *mdef;
{
const struct permonst *pa = magr->data, *pd = mdef->data;
1997-10-19 20:56:41 +04:00
int hit;
schar tmp;
boolean vis;
if (strchr("Eauy", pa->mlet))
return (0);
if (magr->mfroz)
return (0); /* riv05!a3 */
1993-03-21 12:45:37 +03:00
tmp = pd->ac + pa->mlevel;
1997-10-19 20:56:41 +04:00
if (mdef->mconf || mdef->mfroz || mdef->msleep) {
1993-03-21 12:45:37 +03:00
tmp += 4;
1997-10-19 20:56:41 +04:00
if (mdef->msleep)
mdef->msleep = 0;
1993-03-21 12:45:37 +03:00
}
hit = (tmp > rnd(20));
1997-10-19 20:56:41 +04:00
if (hit)
mdef->msleep = 0;
vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my));
if (vis) {
char buf[BUFSZ];
if (mdef->mimic)
seemimic(mdef);
if (magr->mimic)
seemimic(magr);
(void) sprintf(buf, "%s %s", Monnam(magr),
hit ? "hits" : "misses");
1993-03-21 12:45:37 +03:00
pline("%s %s.", buf, monnam(mdef));
} else {
1997-10-19 20:56:41 +04:00
boolean far = (dist(magr->mx, magr->my) > 15);
if (far != far_noise || moves - noisetime > 10) {
1993-03-21 12:45:37 +03:00
far_noise = far;
noisetime = moves;
pline("You hear some noises%s.",
1997-10-19 20:56:41 +04:00
far ? " in the distance" : "");
1993-03-21 12:45:37 +03:00
}
}
1997-10-19 20:56:41 +04:00
if (hit) {
if (magr->data->mlet == 'c' && !magr->cham) {
1993-03-21 12:45:37 +03:00
magr->mhpmax += 3;
1997-10-19 20:56:41 +04:00
if (vis)
pline("%s is turned to stone!", Monnam(mdef));
else if (mdef->mtame)
pline("You have a peculiarly sad feeling for a moment, then it passes.");
1993-03-21 12:45:37 +03:00
monstone(mdef);
hit = 2;
1997-10-19 20:56:41 +04:00
} else if ((mdef->mhp -= d(pa->damn, pa->damd)) < 1) {
magr->mhpmax += 1 + rn2(pd->mlevel + 1);
if (magr->mtame && magr->mhpmax > 8 * pa->mlevel) {
if (pa == &li_dog)
magr->data = pa = &dog;
else if (pa == &dog)
magr->data = pa = &la_dog;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (vis)
pline("%s is killed!", Monnam(mdef));
else if (mdef->mtame)
pline("You have a sad feeling for a moment, then it passes.");
1993-03-21 12:45:37 +03:00
mondied(mdef);
hit = 2;
}
}
1997-10-19 20:56:41 +04:00
return (hit);
1993-03-21 12:45:37 +03:00
}
/* drop (perhaps) a cadaver and remove monster */
1997-10-19 20:56:41 +04:00
void
mondied(mdef)
struct monst *mdef;
{
const struct permonst *pd = mdef->data;
1997-10-19 20:56:41 +04:00
if (letter(pd->mlet) && rn2(3)) {
(void) mkobj_at(pd->mlet, mdef->mx, mdef->my);
if (cansee(mdef->mx, mdef->my)) {
unpmon(mdef);
atl(mdef->mx, mdef->my, fobj->olet);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
stackobj(fobj);
}
mondead(mdef);
1993-03-21 12:45:37 +03:00
}
/* drop a rock and remove monster */
1997-10-19 20:56:41 +04:00
void
monstone(mdef)
struct monst *mdef;
{
if (strchr(mlarge, mdef->data->mlet))
1993-03-21 12:45:37 +03:00
mksobj_at(ENORMOUS_ROCK, mdef->mx, mdef->my);
else
mksobj_at(ROCK, mdef->mx, mdef->my);
1997-10-19 20:56:41 +04:00
if (cansee(mdef->mx, mdef->my)) {
1993-03-21 12:45:37 +03:00
unpmon(mdef);
1997-10-19 20:56:41 +04:00
atl(mdef->mx, mdef->my, fobj->olet);
1993-03-21 12:45:37 +03:00
}
mondead(mdef);
}
1997-10-19 20:56:41 +04:00
int
fightm(mtmp)
struct monst *mtmp;
{
struct monst *mon;
for (mon = fmon; mon; mon = mon->nmon)
if (mon != mtmp) {
if (DIST(mon->mx, mon->my, mtmp->mx, mtmp->my) < 3)
if (rn2(4))
return (hitmm(mtmp, mon));
}
return (-1);
1993-03-21 12:45:37 +03:00
}
/* u is hit by sth, but not a monster */
1997-10-19 20:56:41 +04:00
int
thitu(tlev, dam, name)
int tlev, dam;
const char *name;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
char buf[BUFSZ];
setan(name, buf);
if (u.uac + tlev <= rnd(20)) {
if (Blind)
pline("It misses.");
else
pline("You are almost hit by %s!", buf);
return (0);
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
if (Blind)
pline("You are hit!");
else
pline("You are hit by %s!", buf);
losehp(dam, name);
return (1);
1993-03-21 12:45:37 +03:00
}
}
1997-10-19 20:56:41 +04:00
char mlarge[] = "bCDdegIlmnoPSsTUwY',&";
1993-03-21 12:45:37 +03:00
boolean
1997-10-19 20:56:41 +04:00
hmon(mon, obj, thrown) /* return TRUE if mon still alive */
struct monst *mon;
struct obj *obj;
int thrown;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
int tmp;
boolean hittxt = FALSE;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (!obj) {
1993-03-21 12:45:37 +03:00
tmp = rnd(2); /* attack with bare hands */
1997-10-19 20:56:41 +04:00
if (mon->data->mlet == 'c' && !uarmg) {
1993-03-21 12:45:37 +03:00
pline("You hit the cockatrice with your bare hands.");
pline("You turn to stone ...");
done_in_by(mon);
}
1997-10-19 20:56:41 +04:00
} else if (obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) {
if (obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG))
tmp = rnd(2);
else {
if (strchr(mlarge, mon->data->mlet)) {
tmp = rnd(objects[obj->otyp].wldam);
if (obj->otyp == TWO_HANDED_SWORD)
tmp += d(2, 6);
else if (obj->otyp == FLAIL)
tmp += rnd(4);
} else {
tmp = rnd(objects[obj->otyp].wsdam);
}
tmp += obj->spe;
if (!thrown && obj == uwep && obj->otyp == BOOMERANG
&& !rn2(3)) {
pline("As you hit %s, the boomerang breaks into splinters.",
monnam(mon));
freeinv(obj);
setworn((struct obj *) 0, obj->owornmask);
obfree(obj, (struct obj *) 0);
tmp++;
}
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD &&
!strcmp(ONAME(obj), "Orcrist"))
tmp += rnd(10);
} else
switch (obj->otyp) {
1993-03-21 12:45:37 +03:00
case HEAVY_IRON_BALL:
1997-10-19 20:56:41 +04:00
tmp = rnd(25);
break;
1993-03-21 12:45:37 +03:00
case EXPENSIVE_CAMERA:
1997-10-19 20:56:41 +04:00
pline("You succeed in destroying your camera. Congratulations!");
1993-03-21 12:45:37 +03:00
freeinv(obj);
1997-10-19 20:56:41 +04:00
if (obj->owornmask)
1993-03-21 12:45:37 +03:00
setworn((struct obj *) 0, obj->owornmask);
obfree(obj, (struct obj *) 0);
1997-10-19 20:56:41 +04:00
return (TRUE);
1993-03-21 12:45:37 +03:00
case DEAD_COCKATRICE:
pline("You hit %s with the cockatrice corpse.",
1997-10-19 20:56:41 +04:00
monnam(mon));
if (mon->data->mlet == 'c') {
1993-03-21 12:45:37 +03:00
tmp = 1;
hittxt = TRUE;
break;
}
pline("%s is turned to stone!", Monnam(mon));
killed(mon);
1997-10-19 20:56:41 +04:00
return (FALSE);
case CLOVE_OF_GARLIC: /* no effect against demons */
if (strchr(UNDEAD, mon->data->mlet))
1993-03-21 12:45:37 +03:00
mon->mflee = 1;
tmp = 1;
break;
default:
/* non-weapons can damage because of their weight */
/* (but not too much) */
1997-10-19 20:56:41 +04:00
tmp = obj->owt / 10;
if (tmp < 1)
tmp = 1;
else
tmp = rnd(tmp);
if (tmp > 6)
tmp = 6;
1993-03-21 12:45:37 +03:00
}
/****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
tmp += u.udaminc + dbon();
1997-10-19 20:56:41 +04:00
if (u.uswallow) {
if ((tmp -= u.uswldtim) <= 0) {
1993-03-21 12:45:37 +03:00
pline("Your arms are no longer able to hit.");
1997-10-19 20:56:41 +04:00
return (TRUE);
1993-03-21 12:45:37 +03:00
}
}
1997-10-19 20:56:41 +04:00
if (tmp < 1)
tmp = 1;
1993-03-21 12:45:37 +03:00
mon->mhp -= tmp;
1997-10-19 20:56:41 +04:00
if (mon->mhp < 1) {
1993-03-21 12:45:37 +03:00
killed(mon);
1997-10-19 20:56:41 +04:00
return (FALSE);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (mon->mtame && (!mon->mflee || mon->mfleetim)) {
mon->mflee = 1; /* Rick Richardson */
mon->mfleetim += 10 * rnd(tmp);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (!hittxt) {
if (thrown)
1993-03-21 12:45:37 +03:00
/* this assumes that we cannot throw plural things */
1997-10-19 20:56:41 +04:00
hit(xname(obj) /* or: objects[obj->otyp].oc_name */ ,
mon, exclam(tmp));
else if (Blind)
1993-03-21 12:45:37 +03:00
pline("You hit it.");
else
pline("You hit %s%s", monnam(mon), exclam(tmp));
}
1997-10-19 20:56:41 +04:00
if (u.umconf && !thrown) {
if (!Blind) {
1993-03-21 12:45:37 +03:00
pline("Your hands stop glowing blue.");
1997-10-19 20:56:41 +04:00
if (!mon->mfroz && !mon->msleep)
pline("%s appears confused.", Monnam(mon));
1993-03-21 12:45:37 +03:00
}
mon->mconf = 1;
u.umconf = 0;
}
1997-10-19 20:56:41 +04:00
return (TRUE); /* mon still alive */
1993-03-21 12:45:37 +03:00
}
/* try to attack; return FALSE if monster evaded */
/* u.dx and u.dy must be set */
1997-10-19 20:56:41 +04:00
int
1993-03-21 12:45:37 +03:00
attack(mtmp)
1997-10-19 20:56:41 +04:00
struct monst *mtmp;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
schar tmp;
boolean malive = TRUE;
const struct permonst *mdat;
1993-03-21 12:45:37 +03:00
mdat = mtmp->data;
1997-10-19 20:56:41 +04:00
u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe
* attacks */
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (mdat->mlet == 'L' && !mtmp->mfroz && !mtmp->msleep &&
!mtmp->mconf && mtmp->mcansee && !rn2(7) &&
(m_move(mtmp, 0) == 2 /* he died */ || /* he moved: */
mtmp->mx != u.ux + u.dx || mtmp->my != u.uy + u.dy))
return (FALSE);
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (mtmp->mimic) {
if (!u.ustuck && !mtmp->mflee)
u.ustuck = mtmp;
switch (levl[u.ux + u.dx][u.uy + u.dy].scrsym) {
1993-03-21 12:45:37 +03:00
case '+':
pline("The door actually was a Mimic.");
break;
case '$':
pline("The chest was a Mimic!");
break;
default:
pline("Wait! That's a Mimic!");
}
wakeup(mtmp); /* clears mtmp->mimic */
1997-10-19 20:56:41 +04:00
return (TRUE);
1993-03-21 12:45:37 +03:00
}
wakeup(mtmp);
1997-10-19 20:56:41 +04:00
if (mtmp->mhide && mtmp->mundetected) {
struct obj *obj;
1993-03-21 12:45:37 +03:00
mtmp->mundetected = 0;
1997-10-19 20:56:41 +04:00
if ((obj = o_at(mtmp->mx, mtmp->my)) && !Blind)
1993-03-21 12:45:37 +03:00
pline("Wait! There's a %s hiding under %s!",
1997-10-19 20:56:41 +04:00
mdat->mname, doname(obj));
return (TRUE);
1993-03-21 12:45:37 +03:00
}
tmp = u.uluck + u.ulevel + mdat->ac + abon();
1997-10-19 20:56:41 +04:00
if (uwep) {
if (uwep->olet == WEAPON_SYM || uwep->otyp == PICK_AXE)
1993-03-21 12:45:37 +03:00
tmp += uwep->spe;
1997-10-19 20:56:41 +04:00
if (uwep->otyp == TWO_HANDED_SWORD)
tmp -= 1;
else if (uwep->otyp == DAGGER)
tmp += 2;
else if (uwep->otyp == CRYSKNIFE)
tmp += 3;
else if (uwep->otyp == SPEAR &&
strchr("XDne", mdat->mlet))
tmp += 2;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (mtmp->msleep) {
1993-03-21 12:45:37 +03:00
mtmp->msleep = 0;
tmp += 2;
}
1997-10-19 20:56:41 +04:00
if (mtmp->mfroz) {
1993-03-21 12:45:37 +03:00
tmp += 4;
1997-10-19 20:56:41 +04:00
if (!rn2(10))
mtmp->mfroz = 0;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (mtmp->mflee)
tmp += 2;
if (u.utrap)
tmp -= 3;
1993-03-21 12:45:37 +03:00
/* with a lot of luggage, your agility diminishes */
1997-10-19 20:56:41 +04:00
tmp -= (inv_weight() + 40) / 20;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (tmp <= rnd(20) && !u.uswallow) {
if (Blind)
pline("You miss it.");
else
pline("You miss %s.", monnam(mtmp));
1993-03-21 12:45:37 +03:00
} else {
/* we hit the monster; be careful: it might die! */
1997-10-19 20:56:41 +04:00
if ((malive = hmon(mtmp, uwep, 0)) == TRUE) {
/* monster still alive */
if (!rn2(25) && mtmp->mhp < mtmp->mhpmax / 2) {
1993-03-21 12:45:37 +03:00
mtmp->mflee = 1;
1997-10-19 20:56:41 +04:00
if (!rn2(3))
mtmp->mfleetim = rnd(100);
if (u.ustuck == mtmp && !u.uswallow)
1993-03-21 12:45:37 +03:00
u.ustuck = 0;
}
#ifndef NOWORM
1997-10-19 20:56:41 +04:00
if (mtmp->wormno)
cutworm(mtmp, u.ux + u.dx, u.uy + u.dy,
1993-03-21 12:45:37 +03:00
uwep ? uwep->otyp : 0);
1997-10-19 20:56:41 +04:00
#endif /* NOWORM */
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (mdat->mlet == 'a') {
if (rn2(2)) {
1993-03-21 12:45:37 +03:00
pline("You are splashed by the blob's acid!");
losehp_m(rnd(6), mtmp);
1997-10-19 20:56:41 +04:00
if (!rn2(30))
corrode_armor();
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (!rn2(6))
corrode_weapon();
1993-03-21 12:45:37 +03:00
}
}
1997-10-19 20:56:41 +04:00
if (malive && mdat->mlet == 'E' && canseemon(mtmp)
&& !mtmp->mcan && rn2(3)) {
if (mtmp->mcansee) {
pline("You are frozen by the floating eye's gaze!");
nomul((u.ulevel > 6 || rn2(4)) ? rn1(20, -21) : -200);
} else {
pline("The blinded floating eye cannot defend itself.");
if (!rn2(500))
if ((int) u.uluck > LUCKMIN)
u.uluck--;
}
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
return (TRUE);
1993-03-21 12:45:37 +03:00
}