1 /* $NetBSD: hack.apply.c,v 1.9 2007/12/15 19:44:41 perry 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.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.apply.c,v 1.9 2007/12/15 19:44:41 perry Exp $");
72 #include "def.mkroom.h"
74 static void use_camera(struct obj
*);
75 static int in_ice_box(struct obj
*);
76 static int ck_ice_box(struct obj
*);
77 static int out_ice_box(struct obj
*);
78 static void use_ice_box(struct obj
*);
79 static struct monst
*bchit(int, int , int , int);
80 static void use_whistle(struct obj
*);
81 static void use_magic_whistle(struct obj
*);
83 static int use_pick_axe(struct obj
*);
91 obj
= getobj("(", "use or apply");
96 case EXPENSIVE_CAMERA
:
103 res
= use_pick_axe(obj
);
107 if (pl_character
[0] == 'W' || u
.ulevel
> 9) {
108 use_magic_whistle(obj
);
111 /* fall into next case */
117 if (!carrying(TIN
)) {
118 pline("You have no can to open.");
121 pline("You cannot open a tin without eating its contents.");
122 pline("In order to eat, use the 'e' command.");
124 pline("Opening the tin will be much easier if you wield the can-opener.");
128 pline("Sorry, I don't know how to use that.");
139 use_camera(struct obj
*obj __unused
)
142 if (!getdir(1)) { /* ask: in what direction? */
143 flags
.move
= multi
= 0;
147 pline("You take a picture of %s's stomach.", monnam(u
.ustuck
));
151 pline("You take a picture of the %s.",
152 (u
.dz
> 0) ? "floor" : "ceiling");
155 if ((mtmp
= bchit(u
.dx
, u
.dy
, COLNO
, '!')) != NULL
) {
158 pline("The flash awakens %s.", monnam(mtmp
)); /* a3 */
159 } else if (mtmp
->data
->mlet
!= 'y')
160 if (mtmp
->mcansee
|| mtmp
->mblinded
) {
161 int tmp
= dist(mtmp
->mx
, mtmp
->my
);
163 if (cansee(mtmp
->mx
, mtmp
->my
))
164 pline("%s is blinded by the flash!", Monnam(mtmp
));
166 if (tmp
< 9 && !mtmp
->isshk
&& rn2(4)) {
169 mtmp
->mfleetim
= rnd(100);
172 mtmp
->mcansee
= mtmp
->mblinded
= 0;
174 tmp2
= mtmp
->mblinded
;
175 tmp2
+= rnd(1 + 50 / tmp
);
178 mtmp
->mblinded
= tmp2
;
186 struct obj
*current_ice_box
;/* a local variable of use_ice_box, to be
187 * used by its local procedures in/ck_ice_box */
189 in_ice_box(struct obj
*obj
)
191 if (obj
== current_ice_box
||
192 (Punished
&& (obj
== uball
|| obj
== uchain
))) {
193 pline("You must be kidding.");
196 if (obj
->owornmask
& (W_ARMOR
| W_RING
)) {
197 pline("You cannot refrigerate something you are wearing.");
200 if (obj
->owt
+ current_ice_box
->owt
> 70) {
201 pline("It won't fit.");
202 return (1); /* be careful! */
206 pline("Your weapon is welded to your hand!");
209 setuwep((struct obj
*) 0);
211 current_ice_box
->owt
+= obj
->owt
;
213 obj
->o_cnt_id
= current_ice_box
->o_id
;
216 obj
->age
= moves
- obj
->age
; /* actual age */
221 ck_ice_box(struct obj
*obj
)
223 return (obj
->o_cnt_id
== current_ice_box
->o_id
);
227 out_ice_box(struct obj
*obj
)
233 for (otmp
= fcobj
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
235 panic("out_ice_box");
236 otmp
->nobj
= obj
->nobj
;
238 current_ice_box
->owt
-= obj
->owt
;
239 obj
->age
= moves
- obj
->age
; /* simulated point of time */
245 use_ice_box(struct obj
*obj
)
249 current_ice_box
= obj
; /* for use by in/out_ice_box */
250 for (otmp
= fcobj
; otmp
; otmp
= otmp
->nobj
)
251 if (otmp
->o_cnt_id
== obj
->o_id
)
254 pline("Your ice-box is empty.");
256 pline("Do you want to take something out of the ice-box? [yn] ");
257 if (readchar() == 'y')
258 if (askchain(fcobj
, (char *) 0, 0, out_ice_box
, ck_ice_box
, 0))
260 pline("That was all. Do you wish to put something in? [yn] ");
261 if (readchar() != 'y')
264 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
265 otmp
= getobj("0#%", "put in");
266 if (!otmp
|| !in_ice_box(otmp
))
267 flags
.move
= multi
= 0;
270 static struct monst
*
271 bchit(int ddx
, int ddy
, int range
, int sym
)
273 struct monst
*mtmp
= (struct monst
*) 0;
274 int bchx
= u
.ux
, bchy
= u
.uy
;
277 Tmp_at(-1, sym
);/* open call */
281 if ((mtmp
= m_at(bchx
, bchy
)) != NULL
)
283 if (!ZAP_POS(levl
[bchx
][bchy
].typ
)) {
298 use_whistle(struct obj
*obj __unused
)
300 struct monst
*mtmp
= fmon
;
301 pline("You produce a high whistling sound.");
303 if (dist(mtmp
->mx
, mtmp
->my
) < u
.ulevel
* 20) {
307 EDOG(mtmp
)->whistletime
= moves
;
315 use_magic_whistle(struct obj
*obj __unused
)
317 struct monst
*mtmp
= fmon
;
318 pline("You produce a strange whistling sound.");
326 static int dig_effort
; /* effort expended on current pos */
327 static uchar dig_level
;
328 static coord dig_pos
;
329 static boolean dig_down
;
335 int dpx
= dig_pos
.x
, dpy
= dig_pos
.y
;
337 /* perhaps a nymph stole his pick-axe while he was busy digging */
338 /* or perhaps he teleported away */
339 if (u
.uswallow
|| !uwep
|| uwep
->otyp
!= PICK_AXE
||
340 dig_level
!= dlevel
||
341 ((dig_down
&& (dpx
!= u
.ux
|| dpy
!= u
.uy
)) ||
342 (!dig_down
&& dist(dpx
, dpy
) > 2)))
345 dig_effort
+= 10 + abon() + uwep
->spe
+ rn2(5);
348 pline("The floor here seems too hard to dig in.");
351 if (dig_effort
> 250) {
353 return (0); /* done with digging */
355 if (dig_effort
> 50) {
356 struct trap
*ttmp
= t_at(dpx
, dpy
);
359 ttmp
= maketrap(dpx
, dpy
, PIT
);
361 pline("You have dug a pit.");
363 u
.utraptype
= TT_PIT
;
367 } else if (dig_effort
> 100) {
371 lev
= &levl
[dpx
][dpy
];
372 if ((obj
= sobj_at(ENORMOUS_ROCK
, dpx
, dpy
)) != NULL
) {
374 digtxt
= "The rock falls apart.";
375 } else if (!lev
->typ
|| lev
->typ
== SCORR
) {
377 digtxt
= "You succeeded in cutting away some rock.";
378 } else if (lev
->typ
== HWALL
|| lev
->typ
== VWALL
379 || lev
->typ
== SDOOR
) {
380 lev
->typ
= xdnstair
? DOOR
: ROOM
;
381 digtxt
= "You just made an opening in the wall.";
383 digtxt
= "Now what exactly was it that you were digging in?";
386 pline(digtxt
); /* after mnewsym & prl */
389 if (IS_WALL(levl
[dpx
][dpy
].typ
)) {
390 int rno
= inroom(dpx
, dpy
);
392 if (rno
>= 0 && rooms
[rno
].rtype
>= 8) {
393 pline("This wall seems too hard to dig into.");
397 pline("You hit the rock with all your might.");
402 /* When will hole be finished? Very rough indication used by shopkeeper. */
406 return ((occupation
== dig
) ? (250 - dig_effort
) / 20 : -1);
412 struct trap
*ttmp
= t_at(u
.ux
, u
.uy
);
415 pline("The floor here seems too hard to dig in.");
418 ttmp
->ttyp
= TRAPDOOR
;
420 ttmp
= maketrap(u
.ux
, u
.uy
, TRAPDOOR
);
422 pline("You've made a hole in the floor.");
426 pline("You fall through ...");
427 if (u
.utraptype
== TT_PIT
) {
431 goto_level(dlevel
+ 1, FALSE
);
437 use_pick_axe(struct obj
*obj
)
440 char *dsp
= dirsyms
, *sdp
= sdir
;
446 if (uwep
&& uwep
->cursed
) {
447 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
448 pline("Since your weapon is welded to your hand,");
449 pline("you cannot use that pick-axe.");
452 pline("You now wield %s.", doname(obj
));
457 (void) movecmd(*sdp
); /* sets u.dx and u.dy and u.dz */
460 if (u
.dz
> 0 || (u
.dz
== 0 && isok(rx
, ry
) &&
461 (IS_ROCK(levl
[rx
][ry
].typ
)
462 || sobj_at(ENORMOUS_ROCK
, rx
, ry
))))
467 pline("In what direction do you want to dig? [%s] ", dirsyms
);
468 if (!getdir(0)) /* no txt */
470 if (u
.uswallow
&& attack(u
.ustuck
)) /* return(1) */
473 pline("You cannot reach the ceiling.");
474 else if (u
.dz
== 0) {
479 if ((mtmp
= m_at(rx
, ry
)) && attack(mtmp
))
486 if (lev
->typ
== DOOR
)
487 pline("Your %s against the door.",
488 aobjnam(obj
, "clang"));
489 else if (!IS_ROCK(lev
->typ
)
490 && !sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
491 /* ACCESSIBLE or POOL */
492 pline("You swing your %s through thin air.",
493 aobjnam(obj
, (char *) 0));
495 if (dig_pos
.x
!= rx
|| dig_pos
.y
!= ry
496 || dig_level
!= dlevel
|| dig_down
) {
502 pline("You start digging.");
504 pline("You continue digging.");
508 } else if (Levitation
) {
509 pline("You cannot reach the floor.");
511 if (dig_pos
.x
!= u
.ux
|| dig_pos
.y
!= u
.uy
512 || dig_level
!= dlevel
|| !dig_down
) {
518 pline("You start digging in the floor.");
522 pline("You continue digging in the floor.");