NetBSD/games/hack/hack.mhitu.c

399 lines
8.3 KiB
C
Raw Normal View History

1997-10-19 20:56:41 +04:00
/* $NetBSD: hack.mhitu.c,v 1.4 1997/10/19 16:58:22 christos Exp $ */
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
1997-10-19 20:56:41 +04:00
__RCSID("$NetBSD: hack.mhitu.c,v 1.4 1997/10/19 16:58:22 christos Exp $");
#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
/*
* mhitu: monster hits you
* returns 1 if monster dies (e.g. 'y', 'F'), 0 otherwise
*/
1997-10-19 20:56:41 +04:00
int
1993-03-21 12:45:37 +03:00
mhitu(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
struct permonst *mdat = mtmp->data;
int tmp, ctmp;
1993-03-21 12:45:37 +03:00
nomul(0);
/* If swallowed, can only be affected by hissers and by u.ustuck */
1997-10-19 20:56:41 +04:00
if (u.uswallow) {
if (mtmp != u.ustuck) {
if (mdat->mlet == 'c' && !rn2(13)) {
1993-03-21 12:45:37 +03:00
pline("Outside, you hear %s's hissing!",
1997-10-19 20:56:41 +04:00
monnam(mtmp));
1993-03-21 12:45:37 +03:00
pline("%s gets turned to stone!",
1997-10-19 20:56:41 +04:00
Monnam(u.ustuck));
1993-03-21 12:45:37 +03:00
pline("And the same fate befalls you.");
done_in_by(mtmp);
/* "notreached": not return(1); */
}
1997-10-19 20:56:41 +04:00
return (0);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
switch (mdat->mlet) { /* now mtmp == u.ustuck */
1993-03-21 12:45:37 +03:00
case ',':
1997-10-19 20:56:41 +04:00
youswld(mtmp, (u.uac > 0) ? u.uac + 4 : 4,
1993-03-21 12:45:37 +03:00
5, "The trapper");
break;
case '\'':
1997-10-19 20:56:41 +04:00
youswld(mtmp, rnd(6), 7, "The lurker above");
1993-03-21 12:45:37 +03:00
break;
case 'P':
1997-10-19 20:56:41 +04:00
youswld(mtmp, d(2, 4), 12, "The purple worm");
1993-03-21 12:45:37 +03:00
break;
default:
/* This is not impossible! */
pline("The mysterious monster totally digests you.");
u.uhp = 0;
}
1997-10-19 20:56:41 +04:00
if (u.uhp < 1)
done_in_by(mtmp);
return (0);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (mdat->mlet == 'c' && Stoned)
return (0);
1993-03-21 12:45:37 +03:00
/* make eels visible the moment they hit/miss us */
1997-10-19 20:56:41 +04:00
if (mdat->mlet == ';' && mtmp->minvis && cansee(mtmp->mx, mtmp->my)) {
1993-03-21 12:45:37 +03:00
mtmp->minvis = 0;
pmon(mtmp);
}
1997-10-19 20:56:41 +04:00
if (!strchr("1&DuxynNF", mdat->mlet))
tmp = hitu(mtmp, d(mdat->damn, mdat->damd));
1993-03-21 12:45:37 +03:00
else
tmp = 0;
1997-10-19 20:56:41 +04:00
if (strchr(UNDEAD, mdat->mlet) && midnight())
tmp += hitu(mtmp, d(mdat->damn, mdat->damd));
1993-03-21 12:45:37 +03:00
ctmp = tmp && !mtmp->mcan &&
1997-10-19 20:56:41 +04:00
(!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50));
switch (mdat->mlet) {
1993-03-21 12:45:37 +03:00
case '1':
1997-10-19 20:56:41 +04:00
if (wiz_hit(mtmp))
return (1); /* he disappeared */
1993-03-21 12:45:37 +03:00
break;
case '&':
1997-10-19 20:56:41 +04:00
if (!mtmp->cham && !mtmp->mcan && !rn2(13)) {
(void) makemon(PM_DEMON, u.ux, u.uy);
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, d(2, 6));
(void) hitu(mtmp, d(2, 6));
(void) hitu(mtmp, rnd(3));
(void) hitu(mtmp, rnd(3));
(void) hitu(mtmp, rn1(4, 2));
1993-03-21 12:45:37 +03:00
}
break;
case ',':
1997-10-19 20:56:41 +04:00
if (tmp)
justswld(mtmp, "The trapper");
1993-03-21 12:45:37 +03:00
break;
case '\'':
1997-10-19 20:56:41 +04:00
if (tmp)
justswld(mtmp, "The lurker above");
1993-03-21 12:45:37 +03:00
break;
case ';':
1997-10-19 20:56:41 +04:00
if (ctmp) {
if (!u.ustuck && !rn2(10)) {
1993-03-21 12:45:37 +03:00
pline("%s swings itself around you!",
1997-10-19 20:56:41 +04:00
Monnam(mtmp));
1993-03-21 12:45:37 +03:00
u.ustuck = mtmp;
1997-10-19 20:56:41 +04:00
} else if (u.ustuck == mtmp &&
levl[mtmp->mx][mtmp->my].typ == POOL) {
1993-03-21 12:45:37 +03:00
pline("%s drowns you ...", Monnam(mtmp));
done("drowned");
}
}
break;
case 'A':
1997-10-19 20:56:41 +04:00
if (ctmp && rn2(2)) {
if (Poison_resistance)
pline("The sting doesn't seem to affect you.");
else {
pline("You feel weaker!");
losestr(1);
}
1993-03-21 12:45:37 +03:00
}
break;
case 'C':
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, rnd(6));
1993-03-21 12:45:37 +03:00
break;
case 'c':
1997-10-19 20:56:41 +04:00
if (!rn2(5)) {
1993-03-21 12:45:37 +03:00
pline("You hear %s's hissing!", monnam(mtmp));
1997-10-19 20:56:41 +04:00
if (ctmp || !rn2(20) || (flags.moonphase == NEW_MOON
&& !carrying(DEAD_LIZARD))) {
1993-03-21 12:45:37 +03:00
Stoned = 5;
/* pline("You get turned to stone!"); */
/* done_in_by(mtmp); */
}
}
break;
case 'D':
1997-10-19 20:56:41 +04:00
if (rn2(6) || mtmp->mcan) {
(void) hitu(mtmp, d(3, 10));
(void) hitu(mtmp, rnd(8));
(void) hitu(mtmp, rnd(8));
1993-03-21 12:45:37 +03:00
break;
}
1997-10-19 20:56:41 +04:00
kludge("%s breathes fire!", "The dragon");
buzz(-1, mtmp->mx, mtmp->my, u.ux - mtmp->mx, u.uy - mtmp->my);
1993-03-21 12:45:37 +03:00
break;
case 'd':
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, d(2, (flags.moonphase == FULL_MOON) ? 3 : 4));
1993-03-21 12:45:37 +03:00
break;
case 'e':
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, d(3, 6));
1993-03-21 12:45:37 +03:00
break;
case 'F':
1997-10-19 20:56:41 +04:00
if (mtmp->mcan)
break;
kludge("%s explodes!", "The freezing sphere");
if (Cold_resistance)
pline("You don't seem affected by it.");
1993-03-21 12:45:37 +03:00
else {
1997-10-19 20:56:41 +04:00
xchar dn;
if (17 - (u.ulevel / 2) > rnd(20)) {
1993-03-21 12:45:37 +03:00
pline("You get blasted!");
dn = 6;
} else {
pline("You duck the blast...");
dn = 3;
}
1997-10-19 20:56:41 +04:00
losehp_m(d(dn, 6), mtmp);
1993-03-21 12:45:37 +03:00
}
mondead(mtmp);
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
case 'g':
1997-10-19 20:56:41 +04:00
if (ctmp && multi >= 0 && !rn2(3)) {
kludge("You are frozen by %ss juices", "the cube'");
1993-03-21 12:45:37 +03:00
nomul(-rnd(10));
}
break;
case 'h':
1997-10-19 20:56:41 +04:00
if (ctmp && multi >= 0 && !rn2(5)) {
1993-03-21 12:45:37 +03:00
nomul(-rnd(10));
kludge("You are put to sleep by %ss bite!",
1997-10-19 20:56:41 +04:00
"the homunculus'");
1993-03-21 12:45:37 +03:00
}
break;
case 'j':
1997-10-19 20:56:41 +04:00
tmp = hitu(mtmp, rnd(3));
tmp &= hitu(mtmp, rnd(3));
if (tmp) {
(void) hitu(mtmp, rnd(4));
(void) hitu(mtmp, rnd(4));
1993-03-21 12:45:37 +03:00
}
break;
case 'k':
1997-10-19 20:56:41 +04:00
if ((hitu(mtmp, rnd(4)) || !rn2(3)) && ctmp) {
poisoned("bee's sting", mdat->mname);
1993-03-21 12:45:37 +03:00
}
break;
case 'L':
1997-10-19 20:56:41 +04:00
if (tmp)
stealgold(mtmp);
1993-03-21 12:45:37 +03:00
break;
case 'N':
1997-10-19 20:56:41 +04:00
if (mtmp->mcan && !Blind) {
pline("%s tries to seduce you, but you seem not interested.",
Amonnam(mtmp, "plain"));
if (rn2(3))
rloc(mtmp);
} else if (steal(mtmp)) {
1993-03-21 12:45:37 +03:00
rloc(mtmp);
mtmp->mflee = 1;
}
break;
case 'n':
1997-10-19 20:56:41 +04:00
if (!uwep && !uarm && !uarmh && !uarms && !uarmg) {
pline("%s hits! (I hope you don't mind)",
Monnam(mtmp));
1993-03-21 12:45:37 +03:00
u.uhp += rnd(7);
1997-10-19 20:56:41 +04:00
if (!rn2(7))
u.uhpmax++;
if (u.uhp > u.uhpmax)
u.uhp = u.uhpmax;
1993-03-21 12:45:37 +03:00
flags.botl = 1;
1997-10-19 20:56:41 +04:00
if (!rn2(50))
rloc(mtmp);
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, d(2, 6));
(void) hitu(mtmp, d(2, 6));
1993-03-21 12:45:37 +03:00
}
break;
case 'o':
1997-10-19 20:56:41 +04:00
tmp = hitu(mtmp, rnd(6));
if (hitu(mtmp, rnd(6)) && tmp && /* hits with both paws */
1993-03-21 12:45:37 +03:00
!u.ustuck && rn2(2)) {
u.ustuck = mtmp;
1997-10-19 20:56:41 +04:00
kludge("%s has grabbed you!", "The owlbear");
u.uhp -= d(2, 8);
} else if (u.ustuck == mtmp) {
u.uhp -= d(2, 8);
1993-03-21 12:45:37 +03:00
pline("You are being crushed.");
}
break;
case 'P':
1997-10-19 20:56:41 +04:00
if (ctmp && !rn2(4))
justswld(mtmp, "The purple worm");
1993-03-21 12:45:37 +03:00
else
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, d(2, 4));
1993-03-21 12:45:37 +03:00
break;
case 'Q':
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, rnd(2));
(void) hitu(mtmp, rnd(2));
1993-03-21 12:45:37 +03:00
break;
case 'R':
1997-10-19 20:56:41 +04:00
if (tmp && uarmh && !uarmh->rustfree &&
1993-03-21 12:45:37 +03:00
(int) uarmh->spe >= -1) {
pline("Your helmet rusts!");
uarmh->spe--;
1997-10-19 20:56:41 +04:00
} else if (ctmp && uarm && !uarm->rustfree && /* Mike Newton */
uarm->otyp < STUDDED_LEATHER_ARMOR &&
(int) uarm->spe >= -1) {
1993-03-21 12:45:37 +03:00
pline("Your armor rusts!");
uarm->spe--;
}
break;
case 'S':
1997-10-19 20:56:41 +04:00
if (ctmp && !rn2(8)) {
poisoned("snake's bite", mdat->mname);
1993-03-21 12:45:37 +03:00
}
break;
case 's':
1997-10-19 20:56:41 +04:00
if (tmp && !rn2(8)) {
poisoned("scorpion's sting", mdat->mname);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, rnd(8));
(void) hitu(mtmp, rnd(8));
1993-03-21 12:45:37 +03:00
break;
case 'T':
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, rnd(6));
(void) hitu(mtmp, rnd(6));
1993-03-21 12:45:37 +03:00
break;
case 't':
1997-10-19 20:56:41 +04:00
if (!rn2(5))
rloc(mtmp);
1993-03-21 12:45:37 +03:00
break;
case 'u':
mtmp->mflee = 1;
break;
case 'U':
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, d(3, 4));
(void) hitu(mtmp, d(3, 4));
1993-03-21 12:45:37 +03:00
break;
case 'v':
1997-10-19 20:56:41 +04:00
if (ctmp && !u.ustuck)
u.ustuck = mtmp;
1993-03-21 12:45:37 +03:00
break;
case 'V':
1997-10-19 20:56:41 +04:00
if (tmp)
u.uhp -= 4;
if (ctmp)
losexp();
1993-03-21 12:45:37 +03:00
break;
case 'W':
1997-10-19 20:56:41 +04:00
if (ctmp)
losexp();
1993-03-21 12:45:37 +03:00
break;
#ifndef NOWORM
case 'w':
1997-10-19 20:56:41 +04:00
if (tmp)
wormhit(mtmp);
#endif /* NOWORM */
1993-03-21 12:45:37 +03:00
break;
case 'X':
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, rnd(5));
(void) hitu(mtmp, rnd(5));
(void) hitu(mtmp, rnd(5));
1993-03-21 12:45:37 +03:00
break;
case 'x':
1997-10-19 20:56:41 +04:00
{
long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE;
pline("%s pricks in your %s leg!",
Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left");
set_wounded_legs(side, rnd(50));
losehp_m(2, mtmp);
break;
1993-03-21 12:45:37 +03:00
}
case 'y':
1997-10-19 20:56:41 +04:00
if (mtmp->mcan)
break;
1993-03-21 12:45:37 +03:00
mondead(mtmp);
1997-10-19 20:56:41 +04:00
if (!Blind) {
1993-03-21 12:45:37 +03:00
pline("You are blinded by a blast of light!");
1997-10-19 20:56:41 +04:00
Blind = d(4, 12);
1993-03-21 12:45:37 +03:00
seeoff(0);
}
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
case 'Y':
1997-10-19 20:56:41 +04:00
(void) hitu(mtmp, rnd(6));
1993-03-21 12:45:37 +03:00
break;
}
1997-10-19 20:56:41 +04:00
if (u.uhp < 1)
done_in_by(mtmp);
return (0);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
hitu(mtmp, dam)
struct monst *mtmp;
int dam;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
int tmp, res;
1993-03-21 12:45:37 +03:00
nomul(0);
1997-10-19 20:56:41 +04:00
if (u.uswallow)
return (0);
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (mtmp->mhide && mtmp->mundetected) {
1993-03-21 12:45:37 +03:00
mtmp->mundetected = 0;
1997-10-19 20:56:41 +04:00
if (!Blind) {
struct obj *obj;
if ((obj = o_at(mtmp->mx, mtmp->my)) != NULL)
1993-03-21 12:45:37 +03:00
pline("%s was hidden under %s!",
1997-10-19 20:56:41 +04:00
Xmonnam(mtmp), doname(obj));
1993-03-21 12:45:37 +03:00
}
}
tmp = u.uac;
/* give people with Ac = -10 at least some vulnerability */
1997-10-19 20:56:41 +04:00
if (tmp < 0) {
dam += tmp; /* decrease damage */
if (dam <= 0)
dam = 1;
1993-03-21 12:45:37 +03:00
tmp = -rn2(-tmp);
}
tmp += mtmp->data->mlevel;
1997-10-19 20:56:41 +04:00
if (multi < 0)
tmp += 4;
if ((Invis && mtmp->data->mlet != 'I') || !mtmp->mcansee)
tmp -= 2;
if (mtmp->mtrapped)
tmp -= 2;
if (tmp <= rnd(20)) {
if (Blind)
pline("It misses.");
else
pline("%s misses.", Monnam(mtmp));
1993-03-21 12:45:37 +03:00
res = 0;
} else {
1997-10-19 20:56:41 +04:00
if (Blind)
pline("It hits!");
else
pline("%s hits!", Monnam(mtmp));
1993-03-21 12:45:37 +03:00
losehp_m(dam, mtmp);
res = 1;
}
stop_occupation();
1997-10-19 20:56:41 +04:00
return (res);
1993-03-21 12:45:37 +03:00
}