1 /* $NetBSD: hack.apply.c,v 1.13 2011/08/07 06:03:45 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 #include "def.mkroom.h"
69 static void use_camera(struct obj *);
70 static int in_ice_box(struct obj *);
71 static int ck_ice_box(struct obj *);
72 static int out_ice_box(struct obj *);
73 static void use_ice_box(struct obj *);
74 static struct monst *bchit(int, int , int , int);
75 static void use_whistle(struct obj *);
76 static void use_magic_whistle(struct obj *);
78 static int use_pick_axe(struct obj *);
86 obj = getobj("(", "use or apply");
91 case EXPENSIVE_CAMERA:
98 res = use_pick_axe(obj);
102 if (pl_character[0] == 'W' || u.ulevel > 9) {
103 use_magic_whistle(obj);
112 if (!carrying(TIN)) {
113 pline("You have no can to open.");
116 pline("You cannot open a tin without eating its contents.");
117 pline("In order to eat, use the 'e' command.");
119 pline("Opening the tin will be much easier if you wield the can-opener.");
123 pline("Sorry, I don't know how to use that.");
134 use_camera(struct obj *obj __unused)
137 if (!getdir(1)) { /* ask: in what direction? */
138 flags.move = multi = 0;
142 pline("You take a picture of %s's stomach.", monnam(u.ustuck));
146 pline("You take a picture of the %s.",
147 (u.dz > 0) ? "floor" : "ceiling");
150 if ((mtmp = bchit(u.dx, u.dy, COLNO, '!')) != NULL) {
153 pline("The flash awakens %s.", monnam(mtmp)); /* a3 */
154 } else if (mtmp->data->mlet != 'y')
155 if (mtmp->mcansee || mtmp->mblinded) {
156 int tmp = dist(mtmp->mx, mtmp->my);
158 if (cansee(mtmp->mx, mtmp->my))
159 pline("%s is blinded by the flash!", Monnam(mtmp));
161 if (tmp < 9 && !mtmp->isshk && rn2(4)) {
164 mtmp->mfleetim = rnd(100);
167 mtmp->mcansee = mtmp->mblinded = 0;
169 tmp2 = mtmp->mblinded;
170 tmp2 += rnd(1 + 50 / tmp);
173 mtmp->mblinded = tmp2;
181 struct obj *current_ice_box;/* a local variable of use_ice_box, to be
182 * used by its local procedures in/ck_ice_box */
184 in_ice_box(struct obj *obj)
186 if (obj == current_ice_box ||
187 (Punished && (obj == uball || obj == uchain))) {
188 pline("You must be kidding.");
191 if (obj->owornmask & (W_ARMOR | W_RING)) {
192 pline("You cannot refrigerate something you are wearing.");
195 if (obj->owt + current_ice_box->owt > 70) {
196 pline("It won't fit.");
197 return (1); /* be careful! */
201 pline("Your weapon is welded to your hand!");
204 setuwep((struct obj *) 0);
206 current_ice_box->owt += obj->owt;
208 obj->o_cnt_id = current_ice_box->o_id;
211 obj->age = moves - obj->age; /* actual age */
216 ck_ice_box(struct obj *obj)
218 return (obj->o_cnt_id == current_ice_box->o_id);
222 out_ice_box(struct obj *obj)
228 for (otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
230 panic("out_ice_box");
231 otmp->nobj = obj->nobj;
233 current_ice_box->owt -= obj->owt;
234 obj->age = moves - obj->age; /* simulated point of time */
240 use_ice_box(struct obj *obj)
244 current_ice_box = obj; /* for use by in/out_ice_box */
245 for (otmp = fcobj; otmp; otmp = otmp->nobj)
246 if (otmp->o_cnt_id == obj->o_id)
249 pline("Your ice-box is empty.");
251 pline("Do you want to take something out of the ice-box? [yn] ");
252 if (readchar() == 'y')
253 if (askchain(fcobj, NULL, 0, out_ice_box, ck_ice_box, 0))
255 pline("That was all. Do you wish to put something in? [yn] ");
256 if (readchar() != 'y')
259 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
260 otmp = getobj("0#%", "put in");
261 if (!otmp || !in_ice_box(otmp))
262 flags.move = multi = 0;
265 static struct monst *
266 bchit(int ddx, int ddy, int range, int sym)
268 struct monst *mtmp = (struct monst *) 0;
269 int bchx = u.ux, bchy = u.uy;
272 Tmp_at(-1, sym);/* open call */
276 if ((mtmp = m_at(bchx, bchy)) != NULL)
278 if (!ZAP_POS(levl[bchx][bchy].typ)) {
293 use_whistle(struct obj *obj __unused)
295 struct monst *mtmp = fmon;
296 pline("You produce a high whistling sound.");
298 if (dist(mtmp->mx, mtmp->my) < u.ulevel * 20) {
302 EDOG(mtmp)->whistletime = moves;
310 use_magic_whistle(struct obj *obj __unused)
312 struct monst *mtmp = fmon;
313 pline("You produce a strange whistling sound.");
321 static int dig_effort; /* effort expended on current pos */
322 static uchar dig_level;
323 static coord dig_pos;
324 static boolean dig_down;
330 int dpx = dig_pos.x, dpy = dig_pos.y;
332 /* perhaps a nymph stole his pick-axe while he was busy digging */
333 /* or perhaps he teleported away */
334 if (u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
335 dig_level != dlevel ||
336 ((dig_down && (dpx != u.ux || dpy != u.uy)) ||
337 (!dig_down && dist(dpx, dpy) > 2)))
340 dig_effort += 10 + abon() + uwep->spe + rn2(5);
343 pline("The floor here seems too hard to dig in.");
346 if (dig_effort > 250) {
348 return (0); /* done with digging */
350 if (dig_effort > 50) {
351 struct trap *ttmp = t_at(dpx, dpy);
354 ttmp = maketrap(dpx, dpy, PIT);
356 pline("You have dug a pit.");
358 u.utraptype = TT_PIT;
362 } else if (dig_effort > 100) {
366 lev = &levl[dpx][dpy];
367 if ((obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) != NULL) {
369 digtxt = "The rock falls apart.";
370 } else if (!lev->typ || lev->typ == SCORR) {
372 digtxt = "You succeeded in cutting away some rock.";
373 } else if (lev->typ == HWALL || lev->typ == VWALL
374 || lev->typ == SDOOR) {
375 lev->typ = xdnstair ? DOOR : ROOM;
376 digtxt = "You just made an opening in the wall.";
378 digtxt = "Now what exactly was it that you were digging in?";
381 pline("%s", digtxt); /* after mnewsym & prl */
384 if (IS_WALL(levl[dpx][dpy].typ)) {
385 int rno = inroom(dpx, dpy);
387 if (rno >= 0 && rooms[rno].rtype >= 8) {
388 pline("This wall seems too hard to dig into.");
392 pline("You hit the rock with all your might.");
397 /* When will hole be finished? Very rough indication used by shopkeeper. */
401 return ((occupation == dig) ? (250 - dig_effort) / 20 : -1);
407 struct trap *ttmp = t_at(u.ux, u.uy);
410 pline("The floor here seems too hard to dig in.");
413 ttmp->ttyp = TRAPDOOR;
415 ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
417 pline("You've made a hole in the floor.");
421 pline("You fall through ...");
422 if (u.utraptype == TT_PIT) {
426 goto_level(dlevel + 1, FALSE);
432 use_pick_axe(struct obj *obj)
435 char *dsp = dirsyms, *sdp = sdir;
441 if (uwep && uwep->cursed) {
442 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
443 pline("Since your weapon is welded to your hand,");
444 pline("you cannot use that pick-axe.");
447 pline("You now wield %s.", doname(obj));
452 (void) movecmd(*sdp); /* sets u.dx and u.dy and u.dz */
455 if (u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
456 (IS_ROCK(levl[rx][ry].typ)
457 || sobj_at(ENORMOUS_ROCK, rx, ry))))
462 pline("In what direction do you want to dig? [%s] ", dirsyms);
463 if (!getdir(0)) /* no txt */
465 if (u.uswallow && attack(u.ustuck)) /* return(1) */
468 pline("You cannot reach the ceiling.");
469 else if (u.dz == 0) {
474 if ((mtmp = m_at(rx, ry)) && attack(mtmp))
481 if (lev->typ == DOOR)
482 pline("Your %s against the door.",
483 aobjnam(obj, "clang"));
484 else if (!IS_ROCK(lev->typ)
485 && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
486 /* ACCESSIBLE or POOL */
487 pline("You swing your %s through thin air.",
490 if (dig_pos.x != rx || dig_pos.y != ry
491 || dig_level != dlevel || dig_down) {
497 pline("You start digging.");
499 pline("You continue digging.");
503 } else if (Levitation) {
504 pline("You cannot reach the floor.");
506 if (dig_pos.x != u.ux || dig_pos.y != u.uy
507 || dig_level != dlevel || !dig_down) {
513 pline("You start digging in the floor.");
517 pline("You continue digging in the floor.");