1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.apply.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.apply.c,v 1.4.2.1 2001/02/18 02:20:07 kris Exp $ */
7 extern char quitchars
[];
9 static void use_camera(struct obj
*);
10 static bool in_ice_box(struct obj
*);
11 static bool ck_ice_box(struct obj
*);
12 static int out_ice_box(struct obj
*);
13 static void use_ice_box(struct obj
*);
14 static struct monst
*bchit(int, int, int, char);
15 static void use_whistle(struct obj
*);
16 static void use_magic_whistle(struct obj
*);
17 static bool dig(void);
18 static int use_pick_axe(struct obj
*);
26 obj
= getobj("(", "use or apply");
31 case EXPENSIVE_CAMERA
:
38 res
= use_pick_axe(obj
);
42 if (pl_character
[0] == 'W' || u
.ulevel
> 9) {
43 use_magic_whistle(obj
);
53 pline("You have no can to open.");
56 pline("You cannot open a tin without eating its contents.");
57 pline("In order to eat, use the 'e' command.");
59 pline("Opening the tin will be much easier if you wield the can-opener.");
63 pline("Sorry, I don't know how to use that.");
73 use_camera(struct obj
*obj __unused
)
77 if (!getdir(1)) { /* ask: in what direction? */
78 flags
.move
= multi
= 0;
82 pline("You take a picture of %s's stomach.", monnam(u
.ustuck
));
86 pline("You take a picture of the %s.",
87 (u
.dz
> 0) ? "floor" : "ceiling");
90 if ((mtmp
= bchit(u
.dx
, u
.dy
, COLNO
, '!')) != NULL
) {
93 pline("The flash awakens %s.", monnam(mtmp
)); /* a3 */
94 } else if (mtmp
->data
->mlet
!= 'y')
95 if (mtmp
->mcansee
|| mtmp
->mblinded
) {
96 int tmp
= dist(mtmp
->mx
, mtmp
->my
);
98 if (cansee(mtmp
->mx
, mtmp
->my
))
99 pline("%s is blinded by the flash!", Monnam(mtmp
));
101 if (tmp
< 9 && !mtmp
->isshk
&& rn2(4)) {
104 mtmp
->mfleetim
= rnd(100);
107 mtmp
->mcansee
= mtmp
->mblinded
= 0;
109 tmp2
= mtmp
->mblinded
;
110 tmp2
+= rnd(1 + 50 / tmp
);
113 mtmp
->mblinded
= tmp2
;
121 struct obj
*current_ice_box
; /* a local variable of use_ice_box, to be
122 used by its local procedures in/ck_ice_box */
124 in_ice_box(struct obj
*obj
)
126 if (obj
== current_ice_box
||
127 (Punished
&& (obj
== uball
|| obj
== uchain
))) {
128 pline("You must be kidding.");
131 if (obj
->owornmask
& (W_ARMOR
| W_RING
)) {
132 pline("You cannot refrigerate something you are wearing.");
135 if (obj
->owt
+ current_ice_box
->owt
> 70) {
136 pline("It won't fit.");
137 return (1); /* be careful! */
141 pline("Your weapon is welded to your hand!");
146 current_ice_box
->owt
+= obj
->owt
;
148 obj
->o_cnt_id
= current_ice_box
->o_id
;
151 obj
->age
= moves
- obj
->age
; /* actual age */
156 ck_ice_box(struct obj
*obj
)
158 return (obj
->o_cnt_id
== current_ice_box
->o_id
);
162 out_ice_box(struct obj
*obj
)
169 for (otmp
= fcobj
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
171 panic("out_ice_box");
172 otmp
->nobj
= obj
->nobj
;
174 current_ice_box
->owt
-= obj
->owt
;
175 obj
->age
= moves
- obj
->age
; /* simulated point of time */
181 use_ice_box(struct obj
*obj
)
186 current_ice_box
= obj
; /* for use by in/out_ice_box */
187 for (otmp
= fcobj
; otmp
; otmp
= otmp
->nobj
)
188 if (otmp
->o_cnt_id
== obj
->o_id
)
191 pline("Your ice-box is empty.");
193 pline("Do you want to take something out of the ice-box? [yn] ");
194 if (readchar() == 'y')
195 if (askchain(fcobj
, NULL
, 0, out_ice_box
, ck_ice_box
, 0))
197 pline("That was all. Do you wish to put something in? [yn] ");
198 if (readchar() != 'y')
201 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
202 otmp
= getobj("0#%", "put in");
203 if (!otmp
|| !in_ice_box(otmp
))
204 flags
.move
= multi
= 0;
209 bchit(int ddx
, int ddy
, int range
, char sym
)
211 struct monst
*mtmp
= NULL
;
212 int bchx
= u
.ux
, bchy
= u
.uy
;
215 Tmp_at(-1, sym
); /* open call */
219 if ((mtmp
= m_at(bchx
, bchy
)))
221 if (!ZAP_POS(levl
[bchx
][bchy
].typ
)) {
235 use_whistle(struct obj
*obj __unused
)
237 struct monst
*mtmp
= fmon
;
239 pline("You produce a high whistling sound.");
241 if (dist(mtmp
->mx
, mtmp
->my
) < u
.ulevel
* 20) {
245 EDOG(mtmp
)->whistletime
= moves
;
252 use_magic_whistle(struct obj
*obj __unused
)
254 struct monst
*mtmp
= fmon
;
256 pline("You produce a strange whistling sound.");
264 static int dig_effort
; /* effort expended on current pos */
265 static uchar dig_level
;
266 static coord dig_pos
;
267 static boolean dig_down
;
274 int dpx
= dig_pos
.x
, dpy
= dig_pos
.y
;
276 /* perhaps a nymph stole his pick-axe while he was busy digging */
277 /* or perhaps he teleported away */
278 if (u
.uswallow
|| !uwep
|| uwep
->otyp
!= PICK_AXE
||
279 dig_level
!= dlevel
||
280 ((dig_down
&& (dpx
!= u
.ux
|| dpy
!= u
.uy
)) ||
281 (!dig_down
&& dist(dpx
, dpy
) > 2)))
284 dig_effort
+= 10 + abon() + uwep
->spe
+ rn2(5);
287 pline("The floor here seems too hard to dig in.");
290 if (dig_effort
> 250) {
292 return (0); /* done with digging */
294 if (dig_effort
> 50) {
295 struct trap
*ttmp
= t_at(dpx
, dpy
);
298 ttmp
= maketrap(dpx
, dpy
, PIT
);
300 pline("You have dug a pit.");
302 u
.utraptype
= TT_PIT
;
306 } else if (dig_effort
> 100) {
310 lev
= &levl
[dpx
][dpy
];
311 if ((obj
= sobj_at(ENORMOUS_ROCK
, dpx
, dpy
)) != NULL
) {
313 digtxt
= "The rock falls apart.";
314 } else if (!lev
->typ
|| lev
->typ
== SCORR
) {
316 digtxt
= "You succeeded in cutting away some rock.";
317 } else if (lev
->typ
== HWALL
|| lev
->typ
== VWALL
318 || lev
->typ
== SDOOR
) {
319 lev
->typ
= xdnstair
? DOOR
: ROOM
;
320 digtxt
= "You just made an opening in the wall.";
322 digtxt
= "Now what exactly was it that you were digging in?";
325 pline("%s", digtxt
); /* after mnewsym & prl */
328 if (IS_WALL(levl
[dpx
][dpy
].typ
)) {
329 int rno
= inroom(dpx
, dpy
);
331 if (rno
>= 0 && rooms
[rno
].rtype
>= 8) {
332 pline("This wall seems too hard to dig into.");
336 pline("You hit the rock with all your might.");
341 /* When will hole be finished? Very rough indication used by shopkeeper. */
345 return ((occupation
== dig
) ? (250 - dig_effort
) / 20 : -1);
351 struct trap
*ttmp
= t_at(u
.ux
, u
.uy
);
354 pline("The floor here seems too hard to dig in.");
357 ttmp
->ttyp
= TRAPDOOR
;
359 ttmp
= maketrap(u
.ux
, u
.uy
, TRAPDOOR
);
361 pline("You've made a hole in the floor.");
365 pline("You fall through ...");
366 if (u
.utraptype
== TT_PIT
) {
370 goto_level(dlevel
+ 1, FALSE
);
376 use_pick_axe(struct obj
*obj
)
379 char *dsp
= dirsyms
, *sdp
= sdir
;
385 if (uwep
&& uwep
->cursed
) {
386 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
387 pline("Since your weapon is welded to your hand,");
388 pline("you cannot use that pick-axe.");
391 pline("You now wield %s.", doname(obj
));
396 movecmd(*sdp
); /* sets u.dx and u.dy and u.dz */
399 if (u
.dz
> 0 || (u
.dz
== 0 && isok(rx
, ry
) &&
400 (IS_ROCK(levl
[rx
][ry
].typ
)
401 || sobj_at(ENORMOUS_ROCK
, rx
, ry
))))
406 pline("In what direction do you want to dig? [%s] ", dirsyms
);
407 if (!getdir(0)) /* no txt */
409 if (u
.uswallow
&& attack(u
.ustuck
)) /* return(1) */
412 pline("You cannot reach the ceiling.");
413 else if (u
.dz
== 0) {
418 if ((mtmp
= m_at(rx
, ry
)) && attack(mtmp
))
425 if (lev
->typ
== DOOR
)
426 pline("Your %s against the door.",
427 aobjnam(obj
, "clang"));
428 else if (!IS_ROCK(lev
->typ
)
429 && !sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
430 /* ACCESSIBLE or POOL */
431 pline("You swing your %s through thin air.",
434 if (dig_pos
.x
!= rx
|| dig_pos
.y
!= ry
435 || dig_level
!= dlevel
|| dig_down
) {
441 pline("You start digging.");
443 pline("You continue digging.");
447 } else if (Levitation
) {
448 pline("You cannot reach the floor.");
450 if (dig_pos
.x
!= u
.ux
|| dig_pos
.y
!= u
.uy
451 || dig_level
!= dlevel
|| !dig_down
) {
457 pline("You start digging in the floor.");
461 pline("You continue digging in the floor.");