NetBSD/games/hack/hack.apply.c

481 lines
11 KiB
C
Raw Normal View History

/* $NetBSD: hack.apply.c,v 1.6 2001/03/25 20:43:59 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.apply.c,v 1.6 2001/03/25 20:43:59 jsm Exp $");
1997-10-19 20:56:41 +04:00
#endif /* not lint */
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
#include "def.edog.h"
#include "def.mkroom.h"
1997-10-19 20:56:41 +04:00
static void use_camera __P((struct obj *));
static int in_ice_box __P((struct obj *));
static int ck_ice_box __P((struct obj *));
static int out_ice_box __P((struct obj *));
static void use_ice_box __P((struct obj *));
static struct monst *bchit __P((int, int , int , int));
static void use_whistle __P((struct obj *));
static void use_magic_whistle __P((struct obj *));
static int dig __P((void));
static int use_pick_axe __P((struct obj *));
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
int
doapply()
{
struct obj *obj;
int res = 1;
1993-03-21 12:45:37 +03:00
obj = getobj("(", "use or apply");
1997-10-19 20:56:41 +04:00
if (!obj)
return (0);
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
switch (obj->otyp) {
1993-03-21 12:45:37 +03:00
case EXPENSIVE_CAMERA:
1997-10-19 20:56:41 +04:00
use_camera(obj);
break;
1993-03-21 12:45:37 +03:00
case ICE_BOX:
1997-10-19 20:56:41 +04:00
use_ice_box(obj);
break;
1993-03-21 12:45:37 +03:00
case PICK_AXE:
res = use_pick_axe(obj);
break;
case MAGIC_WHISTLE:
1997-10-19 20:56:41 +04:00
if (pl_character[0] == 'W' || u.ulevel > 9) {
1993-03-21 12:45:37 +03:00
use_magic_whistle(obj);
break;
}
/* fall into next case */
case WHISTLE:
use_whistle(obj);
break;
case CAN_OPENER:
1997-10-19 20:56:41 +04:00
if (!carrying(TIN)) {
1993-03-21 12:45:37 +03:00
pline("You have no can to open.");
goto xit;
}
pline("You cannot open a tin without eating its contents.");
pline("In order to eat, use the 'e' command.");
1997-10-19 20:56:41 +04:00
if (obj != uwep)
pline("Opening the tin will be much easier if you wield the can-opener.");
1993-03-21 12:45:37 +03:00
goto xit;
default:
pline("Sorry, I don't know how to use that.");
1997-10-19 20:56:41 +04:00
xit:
1993-03-21 12:45:37 +03:00
nomul(0);
1997-10-19 20:56:41 +04:00
return (0);
1993-03-21 12:45:37 +03:00
}
nomul(0);
1997-10-19 20:56:41 +04:00
return (res);
1993-03-21 12:45:37 +03:00
}
/* ARGSUSED */
static void
1997-10-19 20:56:41 +04:00
use_camera(obj) /* */
struct obj *obj __attribute__((__unused__));
1997-10-19 20:56:41 +04:00
{
struct monst *mtmp;
if (!getdir(1)) { /* ask: in what direction? */
1993-03-21 12:45:37 +03:00
flags.move = multi = 0;
return;
}
1997-10-19 20:56:41 +04:00
if (u.uswallow) {
1993-03-21 12:45:37 +03:00
pline("You take a picture of %s's stomach.", monnam(u.ustuck));
return;
}
1997-10-19 20:56:41 +04:00
if (u.dz) {
1993-03-21 12:45:37 +03:00
pline("You take a picture of the %s.",
1997-10-19 20:56:41 +04:00
(u.dz > 0) ? "floor" : "ceiling");
1993-03-21 12:45:37 +03:00
return;
}
1997-10-19 20:56:41 +04:00
if ((mtmp = bchit(u.dx, u.dy, COLNO, '!')) != NULL) {
if (mtmp->msleep) {
1993-03-21 12:45:37 +03:00
mtmp->msleep = 0;
1997-10-19 20:56:41 +04:00
pline("The flash awakens %s.", monnam(mtmp)); /* a3 */
} else if (mtmp->data->mlet != 'y')
if (mtmp->mcansee || mtmp->mblinded) {
int tmp = dist(mtmp->mx, mtmp->my);
int tmp2;
if (cansee(mtmp->mx, mtmp->my))
pline("%s is blinded by the flash!", Monnam(mtmp));
setmangry(mtmp);
if (tmp < 9 && !mtmp->isshk && rn2(4)) {
mtmp->mflee = 1;
if (rn2(4))
mtmp->mfleetim = rnd(100);
}
if (tmp < 3)
mtmp->mcansee = mtmp->mblinded = 0;
else {
tmp2 = mtmp->mblinded;
tmp2 += rnd(1 + 50 / tmp);
if (tmp2 > 127)
tmp2 = 127;
mtmp->mblinded = tmp2;
mtmp->mcansee = 0;
}
1993-03-21 12:45:37 +03:00
}
}
}
static
1997-10-19 20:56:41 +04:00
struct obj *current_ice_box;/* a local variable of use_ice_box, to be
* used by its local procedures in/ck_ice_box */
static int
in_ice_box(obj)
struct obj *obj;
{
if (obj == current_ice_box ||
(Punished && (obj == uball || obj == uchain))) {
1993-03-21 12:45:37 +03:00
pline("You must be kidding.");
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 (obj->owornmask & (W_ARMOR | W_RING)) {
1993-03-21 12:45:37 +03:00
pline("You cannot refrigerate something you are wearing.");
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 (obj->owt + current_ice_box->owt > 70) {
1993-03-21 12:45:37 +03:00
pline("It won't fit.");
1997-10-19 20:56:41 +04:00
return (1); /* be careful! */
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (obj == uwep) {
if (uwep->cursed) {
1993-03-21 12:45:37 +03:00
pline("Your weapon is welded to your hand!");
1997-10-19 20:56:41 +04:00
return (0);
1993-03-21 12:45:37 +03:00
}
setuwep((struct obj *) 0);
}
current_ice_box->owt += obj->owt;
freeinv(obj);
obj->o_cnt_id = current_ice_box->o_id;
obj->nobj = fcobj;
fcobj = obj;
obj->age = moves - obj->age; /* actual age */
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
static int
ck_ice_box(obj)
struct obj *obj;
{
return (obj->o_cnt_id == current_ice_box->o_id);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
static int
out_ice_box(obj)
struct obj *obj;
{
struct obj *otmp;
if (obj == fcobj)
fcobj = fcobj->nobj;
1993-03-21 12:45:37 +03:00
else {
1997-10-19 20:56:41 +04:00
for (otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
if (!otmp->nobj)
panic("out_ice_box");
1993-03-21 12:45:37 +03:00
otmp->nobj = obj->nobj;
}
current_ice_box->owt -= obj->owt;
obj->age = moves - obj->age; /* simulated point of time */
(void) addinv(obj);
1997-10-19 20:56:41 +04:00
return 0;
1993-03-21 12:45:37 +03:00
}
static void
1997-10-19 20:56:41 +04:00
use_ice_box(obj)
struct obj *obj;
{
int cnt = 0;
struct obj *otmp;
1993-03-21 12:45:37 +03:00
current_ice_box = obj; /* for use by in/out_ice_box */
1997-10-19 20:56:41 +04:00
for (otmp = fcobj; otmp; otmp = otmp->nobj)
if (otmp->o_cnt_id == obj->o_id)
1993-03-21 12:45:37 +03:00
cnt++;
1997-10-19 20:56:41 +04:00
if (!cnt)
pline("Your ice-box is empty.");
1993-03-21 12:45:37 +03:00
else {
1997-10-19 20:56:41 +04:00
pline("Do you want to take something out of the ice-box? [yn] ");
if (readchar() == 'y')
if (askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
return;
1993-03-21 12:45:37 +03:00
pline("That was all. Do you wish to put something in? [yn] ");
1997-10-19 20:56:41 +04:00
if (readchar() != 'y')
return;
1993-03-21 12:45:37 +03:00
}
/* call getobj: 0: allow cnt; #: allow all types; %: expect food */
otmp = getobj("0#%", "put in");
1997-10-19 20:56:41 +04:00
if (!otmp || !in_ice_box(otmp))
1993-03-21 12:45:37 +03:00
flags.move = multi = 0;
}
1997-10-19 20:56:41 +04:00
static struct monst *
bchit(ddx, ddy, range, sym)
int ddx, ddy, range;
char sym;
{
struct monst *mtmp = (struct monst *) 0;
int bchx = u.ux, bchy = u.uy;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (sym)
Tmp_at(-1, sym);/* open call */
while (range--) {
1993-03-21 12:45:37 +03:00
bchx += ddx;
bchy += ddy;
1997-10-19 20:56:41 +04:00
if ((mtmp = m_at(bchx, bchy)) != NULL)
1993-03-21 12:45:37 +03:00
break;
1997-10-19 20:56:41 +04:00
if (!ZAP_POS(levl[bchx][bchy].typ)) {
1993-03-21 12:45:37 +03:00
bchx -= ddx;
bchy -= ddy;
break;
}
1997-10-19 20:56:41 +04:00
if (sym)
Tmp_at(bchx, bchy);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (sym)
Tmp_at(-1, -1);
return (mtmp);
1993-03-21 12:45:37 +03:00
}
/* ARGSUSED */
static void
1997-10-19 20:56:41 +04:00
use_whistle(obj)
struct obj *obj __attribute__((__unused__));
1997-10-19 20:56:41 +04:00
{
struct monst *mtmp = fmon;
1993-03-21 12:45:37 +03:00
pline("You produce a high whistling sound.");
1997-10-19 20:56:41 +04:00
while (mtmp) {
if (dist(mtmp->mx, mtmp->my) < u.ulevel * 20) {
if (mtmp->msleep)
1993-03-21 12:45:37 +03:00
mtmp->msleep = 0;
1997-10-19 20:56:41 +04:00
if (mtmp->mtame)
1993-03-21 12:45:37 +03:00
EDOG(mtmp)->whistletime = moves;
}
mtmp = mtmp->nmon;
}
}
/* ARGSUSED */
static void
1997-10-19 20:56:41 +04:00
use_magic_whistle(obj)
struct obj *obj __attribute__((__unused__));
1997-10-19 20:56:41 +04:00
{
struct monst *mtmp = fmon;
1993-03-21 12:45:37 +03:00
pline("You produce a strange whistling sound.");
1997-10-19 20:56:41 +04:00
while (mtmp) {
if (mtmp->mtame)
mnexto(mtmp);
1993-03-21 12:45:37 +03:00
mtmp = mtmp->nmon;
}
}
1997-10-19 20:56:41 +04:00
static int dig_effort; /* effort expended on current pos */
static uchar dig_level;
static coord dig_pos;
static boolean dig_down;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
static int
dig()
{
struct rm *lev;
int dpx = dig_pos.x, dpy = dig_pos.y;
1993-03-21 12:45:37 +03:00
/* perhaps a nymph stole his pick-axe while he was busy digging */
/* or perhaps he teleported away */
1997-10-19 20:56:41 +04:00
if (u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
1993-03-21 12:45:37 +03:00
dig_level != dlevel ||
((dig_down && (dpx != u.ux || dpy != u.uy)) ||
1997-10-19 20:56:41 +04:00
(!dig_down && dist(dpx, dpy) > 2)))
return (0);
1993-03-21 12:45:37 +03:00
dig_effort += 10 + abon() + uwep->spe + rn2(5);
1997-10-19 20:56:41 +04:00
if (dig_down) {
if (!xdnstair) {
1993-03-21 12:45:37 +03:00
pline("The floor here seems too hard to dig in.");
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 (dig_effort > 250) {
1993-03-21 12:45:37 +03:00
dighole();
1997-10-19 20:56:41 +04:00
return (0); /* done with digging */
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (dig_effort > 50) {
struct trap *ttmp = t_at(dpx, dpy);
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (!ttmp) {
ttmp = maketrap(dpx, dpy, PIT);
1993-03-21 12:45:37 +03:00
ttmp->tseen = 1;
pline("You have dug a pit.");
1997-10-19 20:56:41 +04:00
u.utrap = rn1(4, 2);
1993-03-21 12:45:37 +03:00
u.utraptype = TT_PIT;
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
} else if (dig_effort > 100) {
const char *digtxt;
1997-10-19 20:56:41 +04:00
struct obj *obj;
1993-03-21 12:45:37 +03:00
lev = &levl[dpx][dpy];
1997-10-19 20:56:41 +04:00
if ((obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) != NULL) {
1993-03-21 12:45:37 +03:00
fracture_rock(obj);
digtxt = "The rock falls apart.";
1997-10-19 20:56:41 +04:00
} else if (!lev->typ || lev->typ == SCORR) {
1993-03-21 12:45:37 +03:00
lev->typ = CORR;
digtxt = "You succeeded in cutting away some rock.";
1997-10-19 20:56:41 +04:00
} else if (lev->typ == HWALL || lev->typ == VWALL
|| lev->typ == SDOOR) {
1993-03-21 12:45:37 +03:00
lev->typ = xdnstair ? DOOR : ROOM;
digtxt = "You just made an opening in the wall.";
} else
1997-10-19 20:56:41 +04:00
digtxt = "Now what exactly was it that you were digging in?";
1993-03-21 12:45:37 +03:00
mnewsym(dpx, dpy);
prl(dpx, dpy);
1997-10-19 20:56:41 +04:00
pline(digtxt); /* after mnewsym & prl */
return (0);
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
if (IS_WALL(levl[dpx][dpy].typ)) {
int rno = inroom(dpx, dpy);
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (rno >= 0 && rooms[rno].rtype >= 8) {
pline("This wall seems too hard to dig into.");
return (0);
1993-03-21 12:45:37 +03:00
}
}
pline("You hit the rock with all your might.");
}
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}
/* When will hole be finished? Very rough indication used by shopkeeper. */
1997-10-19 20:56:41 +04:00
int
holetime()
{
return ((occupation == dig) ? (250 - dig_effort) / 20 : -1);
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
dighole()
{
1997-10-19 20:56:41 +04:00
struct trap *ttmp = t_at(u.ux, u.uy);
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (!xdnstair) {
1993-03-21 12:45:37 +03:00
pline("The floor here seems too hard to dig in.");
} else {
1997-10-19 20:56:41 +04:00
if (ttmp)
1993-03-21 12:45:37 +03:00
ttmp->ttyp = TRAPDOOR;
else
ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
ttmp->tseen = 1;
pline("You've made a hole in the floor.");
1997-10-19 20:56:41 +04:00
if (!u.ustuck) {
if (inshop())
1993-03-21 12:45:37 +03:00
shopdig(1);
pline("You fall through ...");
1997-10-19 20:56:41 +04:00
if (u.utraptype == TT_PIT) {
1993-03-21 12:45:37 +03:00
u.utrap = 0;
u.utraptype = 0;
}
1997-10-19 20:56:41 +04:00
goto_level(dlevel + 1, FALSE);
1993-03-21 12:45:37 +03:00
}
}
}
1997-10-19 20:56:41 +04:00
static int
1993-03-21 12:45:37 +03:00
use_pick_axe(obj)
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
char dirsyms[12];
char *dsp = dirsyms, *sdp = sdir;
struct monst *mtmp;
struct rm *lev;
int rx, ry, res = 0;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (obj != uwep) {
if (uwep && uwep->cursed) {
1993-03-21 12:45:37 +03:00
/* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
pline("Since your weapon is welded to your hand,");
pline("you cannot use that pick-axe.");
1997-10-19 20:56:41 +04:00
return (0);
1993-03-21 12:45:37 +03:00
}
pline("You now wield %s.", doname(obj));
setuwep(obj);
res = 1;
}
1997-10-19 20:56:41 +04:00
while (*sdp) {
1993-03-21 12:45:37 +03:00
(void) movecmd(*sdp); /* sets u.dx and u.dy and u.dz */
rx = u.ux + u.dx;
ry = u.uy + u.dy;
1997-10-19 20:56:41 +04:00
if (u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
(IS_ROCK(levl[rx][ry].typ)
|| sobj_at(ENORMOUS_ROCK, rx, ry))))
1993-03-21 12:45:37 +03:00
*dsp++ = *sdp;
sdp++;
}
*dsp = 0;
pline("In what direction do you want to dig? [%s] ", dirsyms);
1997-10-19 20:56:41 +04:00
if (!getdir(0)) /* no txt */
return (res);
if (u.uswallow && attack(u.ustuck)) /* return(1) */
;
else if (u.dz < 0)
1993-03-21 12:45:37 +03:00
pline("You cannot reach the ceiling.");
1997-10-19 20:56:41 +04:00
else if (u.dz == 0) {
if (Confusion)
1993-03-21 12:45:37 +03:00
confdir();
rx = u.ux + u.dx;
ry = u.uy + u.dy;
1997-10-19 20:56:41 +04:00
if ((mtmp = m_at(rx, ry)) && attack(mtmp))
return (1);
if (!isok(rx, ry)) {
1993-03-21 12:45:37 +03:00
pline("Clash!");
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}
lev = &levl[rx][ry];
1997-10-19 20:56:41 +04:00
if (lev->typ == DOOR)
1993-03-21 12:45:37 +03:00
pline("Your %s against the door.",
1997-10-19 20:56:41 +04:00
aobjnam(obj, "clang"));
else if (!IS_ROCK(lev->typ)
&& !sobj_at(ENORMOUS_ROCK, rx, ry)) {
1993-03-21 12:45:37 +03:00
/* ACCESSIBLE or POOL */
pline("You swing your %s through thin air.",
1997-10-19 20:56:41 +04:00
aobjnam(obj, (char *) 0));
1993-03-21 12:45:37 +03:00
} else {
1997-10-19 20:56:41 +04:00
if (dig_pos.x != rx || dig_pos.y != ry
1993-03-21 12:45:37 +03:00
|| dig_level != dlevel || dig_down) {
dig_down = FALSE;
dig_pos.x = rx;
dig_pos.y = ry;
dig_level = dlevel;
dig_effort = 0;
pline("You start digging.");
} else
pline("You continue digging.");
occupation = dig;
occtxt = "digging";
}
1997-10-19 20:56:41 +04:00
} else if (Levitation) {
1993-03-21 12:45:37 +03:00
pline("You cannot reach the floor.");
} else {
1997-10-19 20:56:41 +04:00
if (dig_pos.x != u.ux || dig_pos.y != u.uy
1993-03-21 12:45:37 +03:00
|| dig_level != dlevel || !dig_down) {
dig_down = TRUE;
dig_pos.x = u.ux;
dig_pos.y = u.uy;
dig_level = dlevel;
dig_effort = 0;
pline("You start digging in the floor.");
1997-10-19 20:56:41 +04:00
if (inshop())
1993-03-21 12:45:37 +03:00
shopdig(0);
} else
pline("You continue digging in the floor.");
occupation = dig;
occtxt = "digging";
}
1997-10-19 20:56:41 +04:00
return (1);
1993-03-21 12:45:37 +03:00
}