]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.apply.c
1 /* $NetBSD: hack.apply.c,v 1.7 2003/04/02 18:36:35 jsm 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.7 2003/04/02 18:36:35 jsm Exp $");
72 #include "def.mkroom.h"
74 static void use_camera
__P((struct obj
*));
75 static int in_ice_box
__P((struct obj
*));
76 static int ck_ice_box
__P((struct obj
*));
77 static int out_ice_box
__P((struct obj
*));
78 static void use_ice_box
__P((struct obj
*));
79 static struct monst
*bchit
__P((int, int , int , int));
80 static void use_whistle
__P((struct obj
*));
81 static void use_magic_whistle
__P((struct obj
*));
82 static int dig
__P((void));
83 static int use_pick_axe
__P((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(obj
) /* */
140 struct obj
*obj
__attribute__((__unused__
));
143 if (!getdir(1)) { /* ask: in what direction? */
144 flags
.move
= multi
= 0;
148 pline("You take a picture of %s's stomach.", monnam(u
.ustuck
));
152 pline("You take a picture of the %s.",
153 (u
.dz
> 0) ? "floor" : "ceiling");
156 if ((mtmp
= bchit(u
.dx
, u
.dy
, COLNO
, '!')) != NULL
) {
159 pline("The flash awakens %s.", monnam(mtmp
)); /* a3 */
160 } else if (mtmp
->data
->mlet
!= 'y')
161 if (mtmp
->mcansee
|| mtmp
->mblinded
) {
162 int tmp
= dist(mtmp
->mx
, mtmp
->my
);
164 if (cansee(mtmp
->mx
, mtmp
->my
))
165 pline("%s is blinded by the flash!", Monnam(mtmp
));
167 if (tmp
< 9 && !mtmp
->isshk
&& rn2(4)) {
170 mtmp
->mfleetim
= rnd(100);
173 mtmp
->mcansee
= mtmp
->mblinded
= 0;
175 tmp2
= mtmp
->mblinded
;
176 tmp2
+= rnd(1 + 50 / tmp
);
179 mtmp
->mblinded
= tmp2
;
187 struct obj
*current_ice_box
;/* a local variable of use_ice_box, to be
188 * used by its local procedures in/ck_ice_box */
193 if (obj
== current_ice_box
||
194 (Punished
&& (obj
== uball
|| obj
== uchain
))) {
195 pline("You must be kidding.");
198 if (obj
->owornmask
& (W_ARMOR
| W_RING
)) {
199 pline("You cannot refrigerate something you are wearing.");
202 if (obj
->owt
+ current_ice_box
->owt
> 70) {
203 pline("It won't fit.");
204 return (1); /* be careful! */
208 pline("Your weapon is welded to your hand!");
211 setuwep((struct obj
*) 0);
213 current_ice_box
->owt
+= obj
->owt
;
215 obj
->o_cnt_id
= current_ice_box
->o_id
;
218 obj
->age
= moves
- obj
->age
; /* actual age */
226 return (obj
->o_cnt_id
== current_ice_box
->o_id
);
237 for (otmp
= fcobj
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
239 panic("out_ice_box");
240 otmp
->nobj
= obj
->nobj
;
242 current_ice_box
->owt
-= obj
->owt
;
243 obj
->age
= moves
- obj
->age
; /* simulated point of time */
254 current_ice_box
= obj
; /* for use by in/out_ice_box */
255 for (otmp
= fcobj
; otmp
; otmp
= otmp
->nobj
)
256 if (otmp
->o_cnt_id
== obj
->o_id
)
259 pline("Your ice-box is empty.");
261 pline("Do you want to take something out of the ice-box? [yn] ");
262 if (readchar() == 'y')
263 if (askchain(fcobj
, (char *) 0, 0, out_ice_box
, ck_ice_box
, 0))
265 pline("That was all. Do you wish to put something in? [yn] ");
266 if (readchar() != 'y')
269 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
270 otmp
= getobj("0#%", "put in");
271 if (!otmp
|| !in_ice_box(otmp
))
272 flags
.move
= multi
= 0;
275 static struct monst
*
276 bchit(ddx
, ddy
, range
, sym
)
280 struct monst
*mtmp
= (struct monst
*) 0;
281 int bchx
= u
.ux
, bchy
= u
.uy
;
284 Tmp_at(-1, sym
);/* open call */
288 if ((mtmp
= m_at(bchx
, bchy
)) != NULL
)
290 if (!ZAP_POS(levl
[bchx
][bchy
].typ
)) {
306 struct obj
*obj
__attribute__((__unused__
));
308 struct monst
*mtmp
= fmon
;
309 pline("You produce a high whistling sound.");
311 if (dist(mtmp
->mx
, mtmp
->my
) < u
.ulevel
* 20) {
315 EDOG(mtmp
)->whistletime
= moves
;
323 use_magic_whistle(obj
)
324 struct obj
*obj
__attribute__((__unused__
));
326 struct monst
*mtmp
= fmon
;
327 pline("You produce a strange whistling sound.");
335 static int dig_effort
; /* effort expended on current pos */
336 static uchar dig_level
;
337 static coord dig_pos
;
338 static boolean dig_down
;
344 int dpx
= dig_pos
.x
, dpy
= dig_pos
.y
;
346 /* perhaps a nymph stole his pick-axe while he was busy digging */
347 /* or perhaps he teleported away */
348 if (u
.uswallow
|| !uwep
|| uwep
->otyp
!= PICK_AXE
||
349 dig_level
!= dlevel
||
350 ((dig_down
&& (dpx
!= u
.ux
|| dpy
!= u
.uy
)) ||
351 (!dig_down
&& dist(dpx
, dpy
) > 2)))
354 dig_effort
+= 10 + abon() + uwep
->spe
+ rn2(5);
357 pline("The floor here seems too hard to dig in.");
360 if (dig_effort
> 250) {
362 return (0); /* done with digging */
364 if (dig_effort
> 50) {
365 struct trap
*ttmp
= t_at(dpx
, dpy
);
368 ttmp
= maketrap(dpx
, dpy
, PIT
);
370 pline("You have dug a pit.");
372 u
.utraptype
= TT_PIT
;
376 } else if (dig_effort
> 100) {
380 lev
= &levl
[dpx
][dpy
];
381 if ((obj
= sobj_at(ENORMOUS_ROCK
, dpx
, dpy
)) != NULL
) {
383 digtxt
= "The rock falls apart.";
384 } else if (!lev
->typ
|| lev
->typ
== SCORR
) {
386 digtxt
= "You succeeded in cutting away some rock.";
387 } else if (lev
->typ
== HWALL
|| lev
->typ
== VWALL
388 || lev
->typ
== SDOOR
) {
389 lev
->typ
= xdnstair
? DOOR
: ROOM
;
390 digtxt
= "You just made an opening in the wall.";
392 digtxt
= "Now what exactly was it that you were digging in?";
395 pline(digtxt
); /* after mnewsym & prl */
398 if (IS_WALL(levl
[dpx
][dpy
].typ
)) {
399 int rno
= inroom(dpx
, dpy
);
401 if (rno
>= 0 && rooms
[rno
].rtype
>= 8) {
402 pline("This wall seems too hard to dig into.");
406 pline("You hit the rock with all your might.");
411 /* When will hole be finished? Very rough indication used by shopkeeper. */
415 return ((occupation
== dig
) ? (250 - dig_effort
) / 20 : -1);
421 struct trap
*ttmp
= t_at(u
.ux
, u
.uy
);
424 pline("The floor here seems too hard to dig in.");
427 ttmp
->ttyp
= TRAPDOOR
;
429 ttmp
= maketrap(u
.ux
, u
.uy
, TRAPDOOR
);
431 pline("You've made a hole in the floor.");
435 pline("You fall through ...");
436 if (u
.utraptype
== TT_PIT
) {
440 goto_level(dlevel
+ 1, FALSE
);
450 char *dsp
= dirsyms
, *sdp
= sdir
;
456 if (uwep
&& uwep
->cursed
) {
457 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
458 pline("Since your weapon is welded to your hand,");
459 pline("you cannot use that pick-axe.");
462 pline("You now wield %s.", doname(obj
));
467 (void) movecmd(*sdp
); /* sets u.dx and u.dy and u.dz */
470 if (u
.dz
> 0 || (u
.dz
== 0 && isok(rx
, ry
) &&
471 (IS_ROCK(levl
[rx
][ry
].typ
)
472 || sobj_at(ENORMOUS_ROCK
, rx
, ry
))))
477 pline("In what direction do you want to dig? [%s] ", dirsyms
);
478 if (!getdir(0)) /* no txt */
480 if (u
.uswallow
&& attack(u
.ustuck
)) /* return(1) */
483 pline("You cannot reach the ceiling.");
484 else if (u
.dz
== 0) {
489 if ((mtmp
= m_at(rx
, ry
)) && attack(mtmp
))
496 if (lev
->typ
== DOOR
)
497 pline("Your %s against the door.",
498 aobjnam(obj
, "clang"));
499 else if (!IS_ROCK(lev
->typ
)
500 && !sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
501 /* ACCESSIBLE or POOL */
502 pline("You swing your %s through thin air.",
503 aobjnam(obj
, (char *) 0));
505 if (dig_pos
.x
!= rx
|| dig_pos
.y
!= ry
506 || dig_level
!= dlevel
|| dig_down
) {
512 pline("You start digging.");
514 pline("You continue digging.");
518 } else if (Levitation
) {
519 pline("You cannot reach the floor.");
521 if (dig_pos
.x
!= u
.ux
|| dig_pos
.y
!= u
.uy
522 || dig_level
!= dlevel
|| !dig_down
) {
528 pline("You start digging in the floor.");
532 pline("You continue digging in the floor.");