]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.apply.c
ebdf82adce54faee9fd517706d1380310bbaf076
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.apply.c - version 1.0.3 */
6 #include "def.mkroom.h"
7 extern struct monst
*bchit();
8 extern struct obj
*addinv();
9 extern struct trap
*maketrap();
10 extern int (*occupation
)();
12 extern char quitchars
[];
13 extern char pl_character
[];
15 static void use_camera(), use_ice_box(), use_whistle(), use_magic_whistle();
16 static int use_pick_axe();
19 register struct obj
*obj
;
22 obj
= getobj("(", "use or apply");
26 case EXPENSIVE_CAMERA
:
27 use_camera(obj
); break;
29 use_ice_box(obj
); break;
31 res
= use_pick_axe(obj
);
35 if(pl_character
[0] == 'W' || u
.ulevel
> 9) {
36 use_magic_whistle(obj
);
39 /* fall into next case */
46 pline("You have no can to open.");
49 pline("You cannot open a tin without eating its contents.");
50 pline("In order to eat, use the 'e' command.");
52 pline("Opening the tin will be much easier if you wield the can-opener.");
56 pline("Sorry, I don't know how to use that.");
67 use_camera(obj
) /* register */ struct obj
*obj
; {
68 register struct monst
*mtmp
;
69 if(!getdir(1)){ /* ask: in what direction? */
70 flags
.move
= multi
= 0;
74 pline("You take a picture of %s's stomach.", monnam(u
.ustuck
));
78 pline("You take a picture of the %s.",
79 (u
.dz
> 0) ? "floor" : "ceiling");
82 if(mtmp
= bchit(u
.dx
, u
.dy
, COLNO
, '!')) {
85 pline("The flash awakens %s.", monnam(mtmp
)); /* a3 */
87 if(mtmp
->data
->mlet
!= 'y')
88 if(mtmp
->mcansee
|| mtmp
->mblinded
){
89 register int tmp
= dist(mtmp
->mx
,mtmp
->my
);
91 if(cansee(mtmp
->mx
,mtmp
->my
))
92 pline("%s is blinded by the flash!", Monnam(mtmp
));
94 if(tmp
< 9 && !mtmp
->isshk
&& rn2(4)) {
96 if(rn2(4)) mtmp
->mfleetim
= rnd(100);
98 if(tmp
< 3) mtmp
->mcansee
= mtmp
->mblinded
= 0;
100 tmp2
= mtmp
->mblinded
;
101 tmp2
+= rnd(1 + 50/tmp
);
102 if(tmp2
> 127) tmp2
= 127;
103 mtmp
->mblinded
= tmp2
;
111 struct obj
*current_ice_box
; /* a local variable of use_ice_box, to be
112 used by its local procedures in/ck_ice_box */
114 in_ice_box(obj
) register struct obj
*obj
; {
115 if(obj
== current_ice_box
||
116 (Punished
&& (obj
== uball
|| obj
== uchain
))){
117 pline("You must be kidding.");
120 if(obj
->owornmask
& (W_ARMOR
| W_RING
)) {
121 pline("You cannot refrigerate something you are wearing.");
124 if(obj
->owt
+ current_ice_box
->owt
> 70) {
125 pline("It won't fit.");
126 return(1); /* be careful! */
130 pline("Your weapon is welded to your hand!");
133 setuwep((struct obj
*) 0);
135 current_ice_box
->owt
+= obj
->owt
;
137 obj
->o_cnt_id
= current_ice_box
->o_id
;
140 obj
->age
= moves
- obj
->age
; /* actual age */
145 ck_ice_box(obj
) register struct obj
*obj
; {
146 return(obj
->o_cnt_id
== current_ice_box
->o_id
);
150 out_ice_box(obj
) register struct obj
*obj
; {
151 register struct obj
*otmp
;
152 if(obj
== fcobj
) fcobj
= fcobj
->nobj
;
154 for(otmp
= fcobj
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
155 if(!otmp
->nobj
) panic("out_ice_box");
156 otmp
->nobj
= obj
->nobj
;
158 current_ice_box
->owt
-= obj
->owt
;
159 obj
->age
= moves
- obj
->age
; /* simulated point of time */
164 use_ice_box(obj
) register struct obj
*obj
; {
165 register int cnt
= 0;
166 register struct obj
*otmp
;
167 current_ice_box
= obj
; /* for use by in/out_ice_box */
168 for(otmp
= fcobj
; otmp
; otmp
= otmp
->nobj
)
169 if(otmp
->o_cnt_id
== obj
->o_id
)
171 if(!cnt
) pline("Your ice-box is empty.");
173 pline("Do you want to take something out of the ice-box? [yn] ");
174 if(readchar() == 'y')
175 if(askchain(fcobj
, (char *) 0, 0, out_ice_box
, ck_ice_box
, 0))
177 pline("That was all. Do you wish to put something in? [yn] ");
178 if(readchar() != 'y') return;
180 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
181 otmp
= getobj("0#%", "put in");
182 if(!otmp
|| !in_ice_box(otmp
))
183 flags
.move
= multi
= 0;
188 bchit(ddx
,ddy
,range
,sym
) register int ddx
,ddy
,range
; char sym
; {
189 register struct monst
*mtmp
= (struct monst
*) 0;
190 register int bchx
= u
.ux
, bchy
= u
.uy
;
192 if(sym
) Tmp_at(-1, sym
); /* open call */
196 if(mtmp
= m_at(bchx
,bchy
))
198 if(!ZAP_POS(levl
[bchx
][bchy
].typ
)) {
203 if(sym
) Tmp_at(bchx
, bchy
);
205 if(sym
) Tmp_at(-1, -1);
211 use_whistle(obj
) struct obj
*obj
; {
212 register struct monst
*mtmp
= fmon
;
213 pline("You produce a high whistling sound.");
215 if(dist(mtmp
->mx
,mtmp
->my
) < u
.ulevel
*20) {
219 EDOG(mtmp
)->whistletime
= moves
;
227 use_magic_whistle(obj
) struct obj
*obj
; {
228 register struct monst
*mtmp
= fmon
;
229 pline("You produce a strange whistling sound.");
231 if(mtmp
->mtame
) mnexto(mtmp
);
236 static int dig_effort
; /* effort expended on current pos */
237 static uchar dig_level
;
238 static coord dig_pos
;
239 static boolean dig_down
;
243 register struct rm
*lev
;
244 register dpx
= dig_pos
.x
, dpy
= dig_pos
.y
;
246 /* perhaps a nymph stole his pick-axe while he was busy digging */
247 /* or perhaps he teleported away */
248 if(u
.uswallow
|| !uwep
|| uwep
->otyp
!= PICK_AXE
||
249 dig_level
!= dlevel
||
250 ((dig_down
&& (dpx
!= u
.ux
|| dpy
!= u
.uy
)) ||
251 (!dig_down
&& dist(dpx
,dpy
) > 2)))
254 dig_effort
+= 10 + abon() + uwep
->spe
+ rn2(5);
257 pline("The floor here seems too hard to dig in.");
260 if(dig_effort
> 250) {
262 return(0); /* done with digging */
264 if(dig_effort
> 50) {
265 register struct trap
*ttmp
= t_at(dpx
,dpy
);
268 ttmp
= maketrap(dpx
,dpy
,PIT
);
270 pline("You have dug a pit.");
272 u
.utraptype
= TT_PIT
;
277 if(dig_effort
> 100) {
278 register char *digtxt
;
279 register struct obj
*obj
;
281 lev
= &levl
[dpx
][dpy
];
282 if(obj
= sobj_at(ENORMOUS_ROCK
, dpx
, dpy
)) {
284 digtxt
= "The rock falls apart.";
285 } else if(!lev
->typ
|| lev
->typ
== SCORR
) {
287 digtxt
= "You succeeded in cutting away some rock.";
288 } else if(lev
->typ
== HWALL
|| lev
->typ
== VWALL
289 || lev
->typ
== SDOOR
) {
290 lev
->typ
= xdnstair
? DOOR
: ROOM
;
291 digtxt
= "You just made an opening in the wall.";
293 digtxt
= "Now what exactly was it that you were digging in?";
296 pline(digtxt
); /* after mnewsym & prl */
299 if(IS_WALL(levl
[dpx
][dpy
].typ
)) {
300 register int rno
= inroom(dpx
,dpy
);
302 if(rno
>= 0 && rooms
[rno
].rtype
>= 8) {
303 pline("This wall seems too hard to dig into.");
307 pline("You hit the rock with all your might.");
312 /* When will hole be finished? Very rough indication used by shopkeeper. */
314 return( (occupation
== dig
) ? (250 - dig_effort
)/20 : -1);
319 register struct trap
*ttmp
= t_at(u
.ux
, u
.uy
);
322 pline("The floor here seems too hard to dig in.");
325 ttmp
->ttyp
= TRAPDOOR
;
327 ttmp
= maketrap(u
.ux
, u
.uy
, TRAPDOOR
);
329 pline("You've made a hole in the floor.");
333 pline("You fall through ...");
334 if(u
.utraptype
== TT_PIT
) {
338 goto_level(dlevel
+1, FALSE
);
349 register char *dsp
= dirsyms
, *sdp
= sdir
;
350 register struct monst
*mtmp
;
351 register struct rm
*lev
;
352 register int rx
, ry
, res
= 0;
355 if(uwep
&& uwep
->cursed
) {
356 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
357 pline("Since your weapon is welded to your hand,");
358 pline("you cannot use that pick-axe.");
361 pline("You now wield %s.", doname(obj
));
366 (void) movecmd(*sdp
); /* sets u.dx and u.dy and u.dz */
369 if(u
.dz
> 0 || (u
.dz
== 0 && isok(rx
, ry
) &&
370 (IS_ROCK(levl
[rx
][ry
].typ
)
371 || sobj_at(ENORMOUS_ROCK
, rx
, ry
))))
376 pline("In what direction do you want to dig? [%s] ", dirsyms
);
377 if(!getdir(0)) /* no txt */
379 if(u
.uswallow
&& attack(u
.ustuck
)) /* return(1) */;
382 pline("You cannot reach the ceiling.");
389 if((mtmp
= m_at(rx
, ry
)) && attack(mtmp
))
397 pline("Your %s against the door.",
398 aobjnam(obj
, "clang"));
399 else if(!IS_ROCK(lev
->typ
)
400 && !sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
401 /* ACCESSIBLE or POOL */
402 pline("You swing your %s through thin air.",
403 aobjnam(obj
, (char *) 0));
405 if(dig_pos
.x
!= rx
|| dig_pos
.y
!= ry
406 || dig_level
!= dlevel
|| dig_down
) {
412 pline("You start digging.");
414 pline("You continue digging.");
418 } else if(Levitation
) {
419 pline("You cannot reach the floor.");
421 if(dig_pos
.x
!= u
.ux
|| dig_pos
.y
!= u
.uy
422 || dig_level
!= dlevel
|| !dig_down
) {
428 pline("You start digging in the floor.");
432 pline("You continue digging in the floor.");