NetBSD/games/hack/hack.trap.c

496 lines
10 KiB
C
Raw Normal View History

1997-10-19 20:56:41 +04:00
/* $NetBSD: hack.trap.c,v 1.4 1997/10/19 16:59:16 christos Exp $ */
/*
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
*/
1997-10-19 20:56:41 +04:00
#include <sys/cdefs.h>
#ifndef lint
1997-10-19 20:56:41 +04:00
__RCSID("$NetBSD: hack.trap.c,v 1.4 1997/10/19 16:59:16 christos Exp $");
#endif /* not lint */
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
#include <stdlib.h>
#include "hack.h"
#include "extern.h"
#include "def.mkroom.h"
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
char vowels[] = "aeiou";
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
char *traps[] = {
1993-03-21 12:45:37 +03:00
" bear trap",
"n arrow trap",
" dart trap",
" trapdoor",
" teleportation trap",
" pit",
" sleeping gas trap",
" piercer",
" mimic"
};
1997-10-19 20:56:41 +04:00
struct trap *
maketrap(x, y, typ)
int x, y, typ;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
struct trap *ttmp;
1993-03-21 12:45:37 +03:00
ttmp = newtrap();
ttmp->ttyp = typ;
ttmp->tseen = 0;
ttmp->once = 0;
ttmp->tx = x;
ttmp->ty = y;
ttmp->ntrap = ftrap;
ftrap = ttmp;
1997-10-19 20:56:41 +04:00
return (ttmp);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
void
dotrap(trap)
struct trap *trap;
{
int ttype = trap->ttyp;
1993-03-21 12:45:37 +03:00
nomul(0);
1997-10-19 20:56:41 +04:00
if (trap->tseen && !rn2(5) && ttype != PIT)
1993-03-21 12:45:37 +03:00
pline("You escape a%s.", traps[ttype]);
else {
trap->tseen = 1;
1997-10-19 20:56:41 +04:00
switch (ttype) {
1993-03-21 12:45:37 +03:00
case SLP_GAS_TRAP:
pline("A cloud of gas puts you to sleep!");
nomul(-rnd(25));
break;
case BEAR_TRAP:
1997-10-19 20:56:41 +04:00
if (Levitation) {
1993-03-21 12:45:37 +03:00
pline("You float over a bear trap.");
break;
}
u.utrap = 4 + rn2(4);
u.utraptype = TT_BEARTRAP;
pline("A bear trap closes on your foot!");
break;
case PIERC:
deltrap(trap);
1997-10-19 20:56:41 +04:00
if (makemon(PM_PIERCER, u.ux, u.uy)) {
pline("A piercer suddenly drops from the ceiling!");
if (uarmh)
pline("Its blow glances off your helmet.");
else
(void) thitu(3, d(4, 6), "falling piercer");
1993-03-21 12:45:37 +03:00
}
break;
case ARROW_TRAP:
pline("An arrow shoots out at you!");
1997-10-19 20:56:41 +04:00
if (!thitu(8, rnd(6), "arrow")) {
1993-03-21 12:45:37 +03:00
mksobj_at(ARROW, u.ux, u.uy);
fobj->quan = 1;
}
break;
case TRAPDOOR:
1997-10-19 20:56:41 +04:00
if (!xdnstair) {
pline("A trap door in the ceiling opens and a rock falls on your head!");
if (uarmh)
pline("Fortunately, you are wearing a helmet!");
losehp(uarmh ? 2 : d(2, 10), "falling rock");
mksobj_at(ROCK, u.ux, u.uy);
fobj->quan = 1;
stackobj(fobj);
if (Invisible)
newsym(u.ux, u.uy);
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
int newlevel = dlevel + 1;
while (!rn2(4) && newlevel < 29)
1993-03-21 12:45:37 +03:00
newlevel++;
pline("A trap door opens up under you!");
1997-10-19 20:56:41 +04:00
if (Levitation || u.ustuck) {
pline("For some reason you don't fall in.");
1993-03-21 12:45:37 +03:00
break;
}
goto_level(newlevel, FALSE);
}
break;
case DART_TRAP:
pline("A little dart shoots out at you!");
1997-10-19 20:56:41 +04:00
if (thitu(7, rnd(3), "little dart")) {
if (!rn2(6))
poisoned("dart", "poison dart");
1993-03-21 12:45:37 +03:00
} else {
mksobj_at(DART, u.ux, u.uy);
fobj->quan = 1;
}
break;
case TELEP_TRAP:
1997-10-19 20:56:41 +04:00
if (trap->once) {
1993-03-21 12:45:37 +03:00
deltrap(trap);
1997-10-19 20:56:41 +04:00
newsym(u.ux, u.uy);
1993-03-21 12:45:37 +03:00
vtele();
} else {
1997-10-19 20:56:41 +04:00
newsym(u.ux, u.uy);
1993-03-21 12:45:37 +03:00
tele();
}
break;
case PIT:
1997-10-19 20:56:41 +04:00
if (Levitation) {
1993-03-21 12:45:37 +03:00
pline("A pit opens up under you!");
pline("You don't fall in!");
break;
}
pline("You fall into a pit!");
1997-10-19 20:56:41 +04:00
u.utrap = rn1(6, 2);
1993-03-21 12:45:37 +03:00
u.utraptype = TT_PIT;
1997-10-19 20:56:41 +04:00
losehp(rnd(6), "fall into a pit");
1993-03-21 12:45:37 +03:00
selftouch("Falling, you");
break;
default:
impossible("You hit a trap of type %u", trap->ttyp);
}
}
}
1997-10-19 20:56:41 +04:00
int
mintrap(mtmp)
struct monst *mtmp;
{
struct trap *trap = t_at(mtmp->mx, mtmp->my);
int wasintrap = mtmp->mtrapped;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (!trap) {
1993-03-21 12:45:37 +03:00
mtmp->mtrapped = 0; /* perhaps teleported? */
1997-10-19 20:56:41 +04:00
} else if (wasintrap) {
if (!rn2(40))
mtmp->mtrapped = 0;
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
int tt = trap->ttyp;
int in_sight = cansee(mtmp->mx, mtmp->my);
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (mtmp->mtrapseen & (1 << tt)) {
/* he has been in such a trap - perhaps he escapes */
if (rn2(4))
return (0);
}
mtmp->mtrapseen |= (1 << tt);
switch (tt) {
1993-03-21 12:45:37 +03:00
case BEAR_TRAP:
1997-10-19 20:56:41 +04:00
if (strchr(mlarge, mtmp->data->mlet)) {
if (in_sight)
pline("%s is caught in a bear trap!",
Monnam(mtmp));
else if (mtmp->data->mlet == 'o')
pline("You hear the roaring of an angry bear!");
1993-03-21 12:45:37 +03:00
mtmp->mtrapped = 1;
}
break;
case PIT:
/* there should be a mtmp/data -> floating */
1997-10-19 20:56:41 +04:00
if (!strchr("EywBfk'& ", mtmp->data->mlet)) { /* ab */
1993-03-21 12:45:37 +03:00
mtmp->mtrapped = 1;
1997-10-19 20:56:41 +04:00
if (in_sight)
pline("%s falls in a pit!", Monnam(mtmp));
1993-03-21 12:45:37 +03:00
}
break;
case SLP_GAS_TRAP:
1997-10-19 20:56:41 +04:00
if (!mtmp->msleep && !mtmp->mfroz) {
1993-03-21 12:45:37 +03:00
mtmp->msleep = 1;
1997-10-19 20:56:41 +04:00
if (in_sight)
pline("%s suddenly falls asleep!",
Monnam(mtmp));
1993-03-21 12:45:37 +03:00
}
break;
case TELEP_TRAP:
rloc(mtmp);
1997-10-19 20:56:41 +04:00
if (in_sight && !cansee(mtmp->mx, mtmp->my))
1993-03-21 12:45:37 +03:00
pline("%s suddenly disappears!",
1997-10-19 20:56:41 +04:00
Monnam(mtmp));
1993-03-21 12:45:37 +03:00
break;
case ARROW_TRAP:
1997-10-19 20:56:41 +04:00
if (in_sight) {
1993-03-21 12:45:37 +03:00
pline("%s is hit by an arrow!",
1997-10-19 20:56:41 +04:00
Monnam(mtmp));
1993-03-21 12:45:37 +03:00
}
mtmp->mhp -= 3;
break;
case DART_TRAP:
1997-10-19 20:56:41 +04:00
if (in_sight) {
1993-03-21 12:45:37 +03:00
pline("%s is hit by a dart!",
1997-10-19 20:56:41 +04:00
Monnam(mtmp));
1993-03-21 12:45:37 +03:00
}
mtmp->mhp -= 2;
/* not mondied here !! */
break;
case TRAPDOOR:
1997-10-19 20:56:41 +04:00
if (!xdnstair) {
1993-03-21 12:45:37 +03:00
mtmp->mhp -= 10;
1997-10-19 20:56:41 +04:00
if (in_sight)
pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp));
1993-03-21 12:45:37 +03:00
break;
}
1997-10-19 20:56:41 +04:00
if (mtmp->data->mlet != 'w') {
1993-03-21 12:45:37 +03:00
fall_down(mtmp);
1997-10-19 20:56:41 +04:00
if (in_sight)
pline("Suddenly, %s disappears out of sight.", monnam(mtmp));
return (2); /* no longer on this level */
1993-03-21 12:45:37 +03:00
}
break;
case PIERC:
break;
default:
impossible("Some monster encountered a strange trap.");
1997-10-19 20:56:41 +04:00
}
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
return (mtmp->mtrapped);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
void
selftouch(arg)
char *arg;
{
if (uwep && uwep->otyp == DEAD_COCKATRICE) {
1993-03-21 12:45:37 +03:00
pline("%s touch the dead cockatrice.", arg);
pline("You turn to stone.");
killer = objects[uwep->otyp].oc_name;
done("died");
}
}
1997-10-19 20:56:41 +04:00
void
float_up()
{
if (u.utrap) {
if (u.utraptype == TT_PIT) {
1993-03-21 12:45:37 +03:00
u.utrap = 0;
pline("You float up, out of the pit!");
} else {
pline("You float up, only your leg is still stuck.");
}
} else
pline("You start to float in the air!");
}
1997-10-19 20:56:41 +04:00
void
float_down()
{
struct trap *trap;
1993-03-21 12:45:37 +03:00
pline("You float gently to the ground.");
1997-10-19 20:56:41 +04:00
if ((trap = t_at(u.ux, u.uy)) != NULL)
switch (trap->ttyp) {
1993-03-21 12:45:37 +03:00
case PIERC:
break;
case TRAPDOOR:
1997-10-19 20:56:41 +04:00
if (!xdnstair || u.ustuck)
break;
1993-03-21 12:45:37 +03:00
/* fall into next case */
default:
dotrap(trap);
1997-10-19 20:56:41 +04:00
}
1993-03-21 12:45:37 +03:00
pickup(1);
}
1997-10-19 20:56:41 +04:00
void
vtele()
{
struct mkroom *croom;
for (croom = &rooms[0]; croom->hx >= 0; croom++)
if (croom->rtype == VAULT) {
int x, y;
x = rn2(2) ? croom->lx : croom->hx;
y = rn2(2) ? croom->ly : croom->hy;
if (teleok(x, y)) {
teleds(x, y);
return;
}
1993-03-21 12:45:37 +03:00
}
tele();
}
1997-10-19 20:56:41 +04:00
void
tele()
{
coord cc;
int nux, nuy;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (Teleport_control) {
1993-03-21 12:45:37 +03:00
pline("To what position do you want to be teleported?");
1997-10-19 20:56:41 +04:00
cc = getpos(1, "the desired position"); /* 1: force valid */
/*
* possible extensions: introduce a small error if magic
* power is low; allow transfer to solid rock
*/
if (teleok(cc.x, cc.y)) {
1993-03-21 12:45:37 +03:00
teleds(cc.x, cc.y);
return;
}
pline("Sorry ...");
}
do {
1997-10-19 20:56:41 +04:00
nux = rnd(COLNO - 1);
1993-03-21 12:45:37 +03:00
nuy = rn2(ROWNO);
1997-10-19 20:56:41 +04:00
} while (!teleok(nux, nuy));
1993-03-21 12:45:37 +03:00
teleds(nux, nuy);
}
1997-10-19 20:56:41 +04:00
void
1993-03-21 12:45:37 +03:00
teleds(nux, nuy)
1997-10-19 20:56:41 +04:00
int nux, nuy;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
if (Punished)
unplacebc();
1993-03-21 12:45:37 +03:00
unsee();
u.utrap = 0;
u.ustuck = 0;
u.ux = nux;
u.uy = nuy;
setsee();
1997-10-19 20:56:41 +04:00
if (Punished)
placebc(1);
if (u.uswallow) {
1993-03-21 12:45:37 +03:00
u.uswldtim = u.uswallow = 0;
docrt();
}
nomul(0);
1997-10-19 20:56:41 +04:00
if (levl[nux][nuy].typ == POOL && !Levitation)
1993-03-21 12:45:37 +03:00
drown();
(void) inshop();
pickup(1);
1997-10-19 20:56:41 +04:00
if (!Blind)
read_engr_at(u.ux, u.uy);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
teleok(x, y)
int x, y;
{ /* might throw him into a POOL */
return (isok(x, y) && !IS_ROCK(levl[x][y].typ) && !m_at(x, y) &&
!sobj_at(ENORMOUS_ROCK, x, y) && !t_at(x, y)
);
1993-03-21 12:45:37 +03:00
/* Note: gold is permitted (because of vaults) */
}
1997-10-19 20:56:41 +04:00
int
dotele()
{
if (
1993-03-21 12:45:37 +03:00
#ifdef WIZARD
1997-10-19 20:56:41 +04:00
!wizard &&
#endif /* WIZARD */
(!Teleportation || u.ulevel < 6 ||
(pl_character[0] != 'W' && u.ulevel < 10))) {
1993-03-21 12:45:37 +03:00
pline("You are not able to teleport at will.");
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
if (u.uhunger <= 100 || u.ustr < 6) {
1993-03-21 12:45:37 +03:00
pline("You miss the strength for a teleport spell.");
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}
tele();
morehungry(100);
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
void
placebc(attach)
int attach;
{
if (!uchain || !uball) {
1993-03-21 12:45:37 +03:00
impossible("Where are your chain and ball??");
return;
}
uball->ox = uchain->ox = u.ux;
uball->oy = uchain->oy = u.uy;
1997-10-19 20:56:41 +04:00
if (attach) {
1993-03-21 12:45:37 +03:00
uchain->nobj = fobj;
fobj = uchain;
1997-10-19 20:56:41 +04:00
if (!carried(uball)) {
1993-03-21 12:45:37 +03:00
uball->nobj = fobj;
fobj = uball;
}
}
}
1997-10-19 20:56:41 +04:00
void
unplacebc()
{
if (!carried(uball)) {
1993-03-21 12:45:37 +03:00
freeobj(uball);
unpobj(uball);
}
freeobj(uchain);
unpobj(uchain);
}
1997-10-19 20:56:41 +04:00
void
level_tele()
{
int newlevel;
if (Teleport_control) {
char buf[BUFSZ];
do {
pline("To what level do you want to teleport? [type a number] ");
getlin(buf);
} while (!digit(buf[0]) && (buf[0] != '-' || !digit(buf[1])));
newlevel = atoi(buf);
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
newlevel = 5 + rn2(20); /* 5 - 24 */
if (dlevel == newlevel)
if (!xdnstair)
newlevel--;
else
newlevel++;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (newlevel >= 30) {
if (newlevel > MAXLEVEL)
newlevel = MAXLEVEL;
pline("You arrive at the center of the earth ...");
pline("Unfortunately it is here that hell is located.");
if (Fire_resistance) {
pline("But the fire doesn't seem to harm you.");
} else {
pline("You burn to a crisp.");
dlevel = maxdlevel = newlevel;
killer = "visit to the hell";
done("burned");
}
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (newlevel < 0) {
newlevel = 0;
pline("You are now high above the clouds ...");
if (Levitation) {
pline("You float gently down to earth.");
done("escaped");
}
pline("Unfortunately, you don't know how to fly.");
pline("You fall down a few thousand feet and break your neck.");
dlevel = 0;
killer = "fall";
done("died");
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
goto_level(newlevel, FALSE); /* calls done("escaped") if
* newlevel==0 */
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
void
1993-03-21 12:45:37 +03:00
drown()
{
pline("You fall into a pool!");
pline("You can't swim!");
1997-10-19 20:56:41 +04:00
if (rn2(3) < u.uluck + 2) {
1993-03-21 12:45:37 +03:00
/* most scrolls become unreadable */
1997-10-19 20:56:41 +04:00
struct obj *obj;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
for (obj = invent; obj; obj = obj->nobj)
if (obj->olet == SCROLL_SYM && rn2(12) > u.uluck)
1993-03-21 12:45:37 +03:00
obj->otyp = SCR_BLANK_PAPER;
/* we should perhaps merge these scrolls ? */
pline("You attempt a teleport spell."); /* utcsri!carroll */
(void) dotele();
1997-10-19 20:56:41 +04:00
if (levl[u.ux][u.uy].typ != POOL)
return;
1993-03-21 12:45:37 +03:00
}
pline("You drown ...");
killer = "pool of water";
done("drowned");
}