]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.apply.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.apply.c,v 1.4 1995/03/23 08:29:47 cgd Exp $";
11 #include "def.mkroom.h"
12 static struct monst
*bchit();
13 extern struct obj
*addinv();
14 extern struct trap
*maketrap();
15 extern int (*occupation
)();
17 extern char quitchars
[];
18 extern char pl_character
[];
20 static void use_camera(), use_ice_box(), use_whistle(), use_magic_whistle();
21 static int use_pick_axe();
24 register struct obj
*obj
;
27 obj
= getobj("(", "use or apply");
31 case EXPENSIVE_CAMERA
:
32 use_camera(obj
); break;
34 use_ice_box(obj
); break;
36 res
= use_pick_axe(obj
);
40 if(pl_character
[0] == 'W' || u
.ulevel
> 9) {
41 use_magic_whistle(obj
);
44 /* fall into next case */
51 pline("You have no can to open.");
54 pline("You cannot open a tin without eating its contents.");
55 pline("In order to eat, use the 'e' command.");
57 pline("Opening the tin will be much easier if you wield the can-opener.");
61 pline("Sorry, I don't know how to use that.");
72 use_camera(obj
) /* register */ struct obj
*obj
; {
73 register struct monst
*mtmp
;
74 if(!getdir(1)){ /* ask: in what direction? */
75 flags
.move
= multi
= 0;
79 pline("You take a picture of %s's stomach.", monnam(u
.ustuck
));
83 pline("You take a picture of the %s.",
84 (u
.dz
> 0) ? "floor" : "ceiling");
87 if(mtmp
= bchit(u
.dx
, u
.dy
, COLNO
, '!')) {
90 pline("The flash awakens %s.", monnam(mtmp
)); /* a3 */
92 if(mtmp
->data
->mlet
!= 'y')
93 if(mtmp
->mcansee
|| mtmp
->mblinded
){
94 register int tmp
= dist(mtmp
->mx
,mtmp
->my
);
96 if(cansee(mtmp
->mx
,mtmp
->my
))
97 pline("%s is blinded by the flash!", Monnam(mtmp
));
99 if(tmp
< 9 && !mtmp
->isshk
&& rn2(4)) {
101 if(rn2(4)) mtmp
->mfleetim
= rnd(100);
103 if(tmp
< 3) mtmp
->mcansee
= mtmp
->mblinded
= 0;
105 tmp2
= mtmp
->mblinded
;
106 tmp2
+= rnd(1 + 50/tmp
);
107 if(tmp2
> 127) tmp2
= 127;
108 mtmp
->mblinded
= tmp2
;
116 struct obj
*current_ice_box
; /* a local variable of use_ice_box, to be
117 used by its local procedures in/ck_ice_box */
119 in_ice_box(obj
) register struct obj
*obj
; {
120 if(obj
== current_ice_box
||
121 (Punished
&& (obj
== uball
|| obj
== uchain
))){
122 pline("You must be kidding.");
125 if(obj
->owornmask
& (W_ARMOR
| W_RING
)) {
126 pline("You cannot refrigerate something you are wearing.");
129 if(obj
->owt
+ current_ice_box
->owt
> 70) {
130 pline("It won't fit.");
131 return(1); /* be careful! */
135 pline("Your weapon is welded to your hand!");
138 setuwep((struct obj
*) 0);
140 current_ice_box
->owt
+= obj
->owt
;
142 obj
->o_cnt_id
= current_ice_box
->o_id
;
145 obj
->age
= moves
- obj
->age
; /* actual age */
150 ck_ice_box(obj
) register struct obj
*obj
; {
151 return(obj
->o_cnt_id
== current_ice_box
->o_id
);
155 out_ice_box(obj
) register struct obj
*obj
; {
156 register struct obj
*otmp
;
157 if(obj
== fcobj
) fcobj
= fcobj
->nobj
;
159 for(otmp
= fcobj
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
160 if(!otmp
->nobj
) panic("out_ice_box");
161 otmp
->nobj
= obj
->nobj
;
163 current_ice_box
->owt
-= obj
->owt
;
164 obj
->age
= moves
- obj
->age
; /* simulated point of time */
169 use_ice_box(obj
) register struct obj
*obj
; {
170 register int cnt
= 0;
171 register struct obj
*otmp
;
172 current_ice_box
= obj
; /* for use by in/out_ice_box */
173 for(otmp
= fcobj
; otmp
; otmp
= otmp
->nobj
)
174 if(otmp
->o_cnt_id
== obj
->o_id
)
176 if(!cnt
) pline("Your ice-box is empty.");
178 pline("Do you want to take something out of the ice-box? [yn] ");
179 if(readchar() == 'y')
180 if(askchain(fcobj
, (char *) 0, 0, out_ice_box
, ck_ice_box
, 0))
182 pline("That was all. Do you wish to put something in? [yn] ");
183 if(readchar() != 'y') return;
185 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
186 otmp
= getobj("0#%", "put in");
187 if(!otmp
|| !in_ice_box(otmp
))
188 flags
.move
= multi
= 0;
193 bchit(ddx
,ddy
,range
,sym
) register int ddx
,ddy
,range
; char sym
; {
194 register struct monst
*mtmp
= (struct monst
*) 0;
195 register int bchx
= u
.ux
, bchy
= u
.uy
;
197 if(sym
) Tmp_at(-1, sym
); /* open call */
201 if(mtmp
= m_at(bchx
,bchy
))
203 if(!ZAP_POS(levl
[bchx
][bchy
].typ
)) {
208 if(sym
) Tmp_at(bchx
, bchy
);
210 if(sym
) Tmp_at(-1, -1);
216 use_whistle(obj
) struct obj
*obj
; {
217 register struct monst
*mtmp
= fmon
;
218 pline("You produce a high whistling sound.");
220 if(dist(mtmp
->mx
,mtmp
->my
) < u
.ulevel
*20) {
224 EDOG(mtmp
)->whistletime
= moves
;
232 use_magic_whistle(obj
) struct obj
*obj
; {
233 register struct monst
*mtmp
= fmon
;
234 pline("You produce a strange whistling sound.");
236 if(mtmp
->mtame
) mnexto(mtmp
);
241 static int dig_effort
; /* effort expended on current pos */
242 static uchar dig_level
;
243 static coord dig_pos
;
244 static boolean dig_down
;
248 register struct rm
*lev
;
249 register dpx
= dig_pos
.x
, dpy
= dig_pos
.y
;
251 /* perhaps a nymph stole his pick-axe while he was busy digging */
252 /* or perhaps he teleported away */
253 if(u
.uswallow
|| !uwep
|| uwep
->otyp
!= PICK_AXE
||
254 dig_level
!= dlevel
||
255 ((dig_down
&& (dpx
!= u
.ux
|| dpy
!= u
.uy
)) ||
256 (!dig_down
&& dist(dpx
,dpy
) > 2)))
259 dig_effort
+= 10 + abon() + uwep
->spe
+ rn2(5);
262 pline("The floor here seems too hard to dig in.");
265 if(dig_effort
> 250) {
267 return(0); /* done with digging */
269 if(dig_effort
> 50) {
270 register struct trap
*ttmp
= t_at(dpx
,dpy
);
273 ttmp
= maketrap(dpx
,dpy
,PIT
);
275 pline("You have dug a pit.");
277 u
.utraptype
= TT_PIT
;
282 if(dig_effort
> 100) {
283 register char *digtxt
;
284 register struct obj
*obj
;
286 lev
= &levl
[dpx
][dpy
];
287 if(obj
= sobj_at(ENORMOUS_ROCK
, dpx
, dpy
)) {
289 digtxt
= "The rock falls apart.";
290 } else if(!lev
->typ
|| lev
->typ
== SCORR
) {
292 digtxt
= "You succeeded in cutting away some rock.";
293 } else if(lev
->typ
== HWALL
|| lev
->typ
== VWALL
294 || lev
->typ
== SDOOR
) {
295 lev
->typ
= xdnstair
? DOOR
: ROOM
;
296 digtxt
= "You just made an opening in the wall.";
298 digtxt
= "Now what exactly was it that you were digging in?";
301 pline(digtxt
); /* after mnewsym & prl */
304 if(IS_WALL(levl
[dpx
][dpy
].typ
)) {
305 register int rno
= inroom(dpx
,dpy
);
307 if(rno
>= 0 && rooms
[rno
].rtype
>= 8) {
308 pline("This wall seems too hard to dig into.");
312 pline("You hit the rock with all your might.");
317 /* When will hole be finished? Very rough indication used by shopkeeper. */
319 return( (occupation
== dig
) ? (250 - dig_effort
)/20 : -1);
324 register struct trap
*ttmp
= t_at(u
.ux
, u
.uy
);
327 pline("The floor here seems too hard to dig in.");
330 ttmp
->ttyp
= TRAPDOOR
;
332 ttmp
= maketrap(u
.ux
, u
.uy
, TRAPDOOR
);
334 pline("You've made a hole in the floor.");
338 pline("You fall through ...");
339 if(u
.utraptype
== TT_PIT
) {
343 goto_level(dlevel
+1, FALSE
);
354 register char *dsp
= dirsyms
, *sdp
= sdir
;
355 register struct monst
*mtmp
;
356 register struct rm
*lev
;
357 register int rx
, ry
, res
= 0;
360 if(uwep
&& uwep
->cursed
) {
361 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
362 pline("Since your weapon is welded to your hand,");
363 pline("you cannot use that pick-axe.");
366 pline("You now wield %s.", doname(obj
));
371 (void) movecmd(*sdp
); /* sets u.dx and u.dy and u.dz */
374 if(u
.dz
> 0 || (u
.dz
== 0 && isok(rx
, ry
) &&
375 (IS_ROCK(levl
[rx
][ry
].typ
)
376 || sobj_at(ENORMOUS_ROCK
, rx
, ry
))))
381 pline("In what direction do you want to dig? [%s] ", dirsyms
);
382 if(!getdir(0)) /* no txt */
384 if(u
.uswallow
&& attack(u
.ustuck
)) /* return(1) */;
387 pline("You cannot reach the ceiling.");
394 if((mtmp
= m_at(rx
, ry
)) && attack(mtmp
))
402 pline("Your %s against the door.",
403 aobjnam(obj
, "clang"));
404 else if(!IS_ROCK(lev
->typ
)
405 && !sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
406 /* ACCESSIBLE or POOL */
407 pline("You swing your %s through thin air.",
408 aobjnam(obj
, (char *) 0));
410 if(dig_pos
.x
!= rx
|| dig_pos
.y
!= ry
411 || dig_level
!= dlevel
|| dig_down
) {
417 pline("You start digging.");
419 pline("You continue digging.");
423 } else if(Levitation
) {
424 pline("You cannot reach the floor.");
426 if(dig_pos
.x
!= u
.ux
|| dig_pos
.y
!= u
.uy
427 || dig_level
!= dlevel
|| !dig_down
) {
433 pline("You start digging in the floor.");
437 pline("You continue digging in the floor.");