]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.apply.c
WARNsify...
[bsdgames-darwin.git] / hack / hack.apply.c
1 /* $NetBSD: hack.apply.c,v 1.5 1997/10/19 16:57:32 christos Exp $ */
2
3 /*
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
5 */
6
7 #include <sys/cdefs.h>
8 #ifndef lint
9 __RCSID("$NetBSD: hack.apply.c,v 1.5 1997/10/19 16:57:32 christos Exp $");
10 #endif /* not lint */
11
12 #include "hack.h"
13 #include "extern.h"
14 #include "def.edog.h"
15 #include "def.mkroom.h"
16
17 static void use_camera __P((struct obj *));
18 static int in_ice_box __P((struct obj *));
19 static int ck_ice_box __P((struct obj *));
20 static int out_ice_box __P((struct obj *));
21 static void use_ice_box __P((struct obj *));
22 static struct monst *bchit __P((int, int , int , int));
23 static void use_whistle __P((struct obj *));
24 static void use_magic_whistle __P((struct obj *));
25 static int dig __P((void));
26 static int use_pick_axe __P((struct obj *));
27
28 int
29 doapply()
30 {
31 struct obj *obj;
32 int res = 1;
33
34 obj = getobj("(", "use or apply");
35 if (!obj)
36 return (0);
37
38 switch (obj->otyp) {
39 case EXPENSIVE_CAMERA:
40 use_camera(obj);
41 break;
42 case ICE_BOX:
43 use_ice_box(obj);
44 break;
45 case PICK_AXE:
46 res = use_pick_axe(obj);
47 break;
48
49 case MAGIC_WHISTLE:
50 if (pl_character[0] == 'W' || u.ulevel > 9) {
51 use_magic_whistle(obj);
52 break;
53 }
54 /* fall into next case */
55 case WHISTLE:
56 use_whistle(obj);
57 break;
58
59 case CAN_OPENER:
60 if (!carrying(TIN)) {
61 pline("You have no can to open.");
62 goto xit;
63 }
64 pline("You cannot open a tin without eating its contents.");
65 pline("In order to eat, use the 'e' command.");
66 if (obj != uwep)
67 pline("Opening the tin will be much easier if you wield the can-opener.");
68 goto xit;
69
70 default:
71 pline("Sorry, I don't know how to use that.");
72 xit:
73 nomul(0);
74 return (0);
75 }
76 nomul(0);
77 return (res);
78 }
79
80 /* ARGSUSED */
81 static void
82 use_camera(obj) /* */
83 struct obj *obj;
84 {
85 struct monst *mtmp;
86 if (!getdir(1)) { /* ask: in what direction? */
87 flags.move = multi = 0;
88 return;
89 }
90 if (u.uswallow) {
91 pline("You take a picture of %s's stomach.", monnam(u.ustuck));
92 return;
93 }
94 if (u.dz) {
95 pline("You take a picture of the %s.",
96 (u.dz > 0) ? "floor" : "ceiling");
97 return;
98 }
99 if ((mtmp = bchit(u.dx, u.dy, COLNO, '!')) != NULL) {
100 if (mtmp->msleep) {
101 mtmp->msleep = 0;
102 pline("The flash awakens %s.", monnam(mtmp)); /* a3 */
103 } else if (mtmp->data->mlet != 'y')
104 if (mtmp->mcansee || mtmp->mblinded) {
105 int tmp = dist(mtmp->mx, mtmp->my);
106 int tmp2;
107 if (cansee(mtmp->mx, mtmp->my))
108 pline("%s is blinded by the flash!", Monnam(mtmp));
109 setmangry(mtmp);
110 if (tmp < 9 && !mtmp->isshk && rn2(4)) {
111 mtmp->mflee = 1;
112 if (rn2(4))
113 mtmp->mfleetim = rnd(100);
114 }
115 if (tmp < 3)
116 mtmp->mcansee = mtmp->mblinded = 0;
117 else {
118 tmp2 = mtmp->mblinded;
119 tmp2 += rnd(1 + 50 / tmp);
120 if (tmp2 > 127)
121 tmp2 = 127;
122 mtmp->mblinded = tmp2;
123 mtmp->mcansee = 0;
124 }
125 }
126 }
127 }
128
129 static
130 struct obj *current_ice_box;/* a local variable of use_ice_box, to be
131 * used by its local procedures in/ck_ice_box */
132 static int
133 in_ice_box(obj)
134 struct obj *obj;
135 {
136 if (obj == current_ice_box ||
137 (Punished && (obj == uball || obj == uchain))) {
138 pline("You must be kidding.");
139 return (0);
140 }
141 if (obj->owornmask & (W_ARMOR | W_RING)) {
142 pline("You cannot refrigerate something you are wearing.");
143 return (0);
144 }
145 if (obj->owt + current_ice_box->owt > 70) {
146 pline("It won't fit.");
147 return (1); /* be careful! */
148 }
149 if (obj == uwep) {
150 if (uwep->cursed) {
151 pline("Your weapon is welded to your hand!");
152 return (0);
153 }
154 setuwep((struct obj *) 0);
155 }
156 current_ice_box->owt += obj->owt;
157 freeinv(obj);
158 obj->o_cnt_id = current_ice_box->o_id;
159 obj->nobj = fcobj;
160 fcobj = obj;
161 obj->age = moves - obj->age; /* actual age */
162 return (1);
163 }
164
165 static int
166 ck_ice_box(obj)
167 struct obj *obj;
168 {
169 return (obj->o_cnt_id == current_ice_box->o_id);
170 }
171
172 static int
173 out_ice_box(obj)
174 struct obj *obj;
175 {
176 struct obj *otmp;
177 if (obj == fcobj)
178 fcobj = fcobj->nobj;
179 else {
180 for (otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
181 if (!otmp->nobj)
182 panic("out_ice_box");
183 otmp->nobj = obj->nobj;
184 }
185 current_ice_box->owt -= obj->owt;
186 obj->age = moves - obj->age; /* simulated point of time */
187 (void) addinv(obj);
188 return 0;
189 }
190
191 static void
192 use_ice_box(obj)
193 struct obj *obj;
194 {
195 int cnt = 0;
196 struct obj *otmp;
197 current_ice_box = obj; /* for use by in/out_ice_box */
198 for (otmp = fcobj; otmp; otmp = otmp->nobj)
199 if (otmp->o_cnt_id == obj->o_id)
200 cnt++;
201 if (!cnt)
202 pline("Your ice-box is empty.");
203 else {
204 pline("Do you want to take something out of the ice-box? [yn] ");
205 if (readchar() == 'y')
206 if (askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
207 return;
208 pline("That was all. Do you wish to put something in? [yn] ");
209 if (readchar() != 'y')
210 return;
211 }
212 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
213 otmp = getobj("0#%", "put in");
214 if (!otmp || !in_ice_box(otmp))
215 flags.move = multi = 0;
216 }
217
218 static struct monst *
219 bchit(ddx, ddy, range, sym)
220 int ddx, ddy, range;
221 char sym;
222 {
223 struct monst *mtmp = (struct monst *) 0;
224 int bchx = u.ux, bchy = u.uy;
225
226 if (sym)
227 Tmp_at(-1, sym);/* open call */
228 while (range--) {
229 bchx += ddx;
230 bchy += ddy;
231 if ((mtmp = m_at(bchx, bchy)) != NULL)
232 break;
233 if (!ZAP_POS(levl[bchx][bchy].typ)) {
234 bchx -= ddx;
235 bchy -= ddy;
236 break;
237 }
238 if (sym)
239 Tmp_at(bchx, bchy);
240 }
241 if (sym)
242 Tmp_at(-1, -1);
243 return (mtmp);
244 }
245
246 /* ARGSUSED */
247 static void
248 use_whistle(obj)
249 struct obj *obj;
250 {
251 struct monst *mtmp = fmon;
252 pline("You produce a high whistling sound.");
253 while (mtmp) {
254 if (dist(mtmp->mx, mtmp->my) < u.ulevel * 20) {
255 if (mtmp->msleep)
256 mtmp->msleep = 0;
257 if (mtmp->mtame)
258 EDOG(mtmp)->whistletime = moves;
259 }
260 mtmp = mtmp->nmon;
261 }
262 }
263
264 /* ARGSUSED */
265 static void
266 use_magic_whistle(obj)
267 struct obj *obj;
268 {
269 struct monst *mtmp = fmon;
270 pline("You produce a strange whistling sound.");
271 while (mtmp) {
272 if (mtmp->mtame)
273 mnexto(mtmp);
274 mtmp = mtmp->nmon;
275 }
276 }
277
278 static int dig_effort; /* effort expended on current pos */
279 static uchar dig_level;
280 static coord dig_pos;
281 static boolean dig_down;
282
283 static int
284 dig()
285 {
286 struct rm *lev;
287 int dpx = dig_pos.x, dpy = dig_pos.y;
288
289 /* perhaps a nymph stole his pick-axe while he was busy digging */
290 /* or perhaps he teleported away */
291 if (u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
292 dig_level != dlevel ||
293 ((dig_down && (dpx != u.ux || dpy != u.uy)) ||
294 (!dig_down && dist(dpx, dpy) > 2)))
295 return (0);
296
297 dig_effort += 10 + abon() + uwep->spe + rn2(5);
298 if (dig_down) {
299 if (!xdnstair) {
300 pline("The floor here seems too hard to dig in.");
301 return (0);
302 }
303 if (dig_effort > 250) {
304 dighole();
305 return (0); /* done with digging */
306 }
307 if (dig_effort > 50) {
308 struct trap *ttmp = t_at(dpx, dpy);
309
310 if (!ttmp) {
311 ttmp = maketrap(dpx, dpy, PIT);
312 ttmp->tseen = 1;
313 pline("You have dug a pit.");
314 u.utrap = rn1(4, 2);
315 u.utraptype = TT_PIT;
316 return (0);
317 }
318 }
319 } else if (dig_effort > 100) {
320 char *digtxt;
321 struct obj *obj;
322
323 lev = &levl[dpx][dpy];
324 if ((obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) != NULL) {
325 fracture_rock(obj);
326 digtxt = "The rock falls apart.";
327 } else if (!lev->typ || lev->typ == SCORR) {
328 lev->typ = CORR;
329 digtxt = "You succeeded in cutting away some rock.";
330 } else if (lev->typ == HWALL || lev->typ == VWALL
331 || lev->typ == SDOOR) {
332 lev->typ = xdnstair ? DOOR : ROOM;
333 digtxt = "You just made an opening in the wall.";
334 } else
335 digtxt = "Now what exactly was it that you were digging in?";
336 mnewsym(dpx, dpy);
337 prl(dpx, dpy);
338 pline(digtxt); /* after mnewsym & prl */
339 return (0);
340 } else {
341 if (IS_WALL(levl[dpx][dpy].typ)) {
342 int rno = inroom(dpx, dpy);
343
344 if (rno >= 0 && rooms[rno].rtype >= 8) {
345 pline("This wall seems too hard to dig into.");
346 return (0);
347 }
348 }
349 pline("You hit the rock with all your might.");
350 }
351 return (1);
352 }
353
354 /* When will hole be finished? Very rough indication used by shopkeeper. */
355 int
356 holetime()
357 {
358 return ((occupation == dig) ? (250 - dig_effort) / 20 : -1);
359 }
360
361 void
362 dighole()
363 {
364 struct trap *ttmp = t_at(u.ux, u.uy);
365
366 if (!xdnstair) {
367 pline("The floor here seems too hard to dig in.");
368 } else {
369 if (ttmp)
370 ttmp->ttyp = TRAPDOOR;
371 else
372 ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
373 ttmp->tseen = 1;
374 pline("You've made a hole in the floor.");
375 if (!u.ustuck) {
376 if (inshop())
377 shopdig(1);
378 pline("You fall through ...");
379 if (u.utraptype == TT_PIT) {
380 u.utrap = 0;
381 u.utraptype = 0;
382 }
383 goto_level(dlevel + 1, FALSE);
384 }
385 }
386 }
387
388 static int
389 use_pick_axe(obj)
390 struct obj *obj;
391 {
392 char dirsyms[12];
393 char *dsp = dirsyms, *sdp = sdir;
394 struct monst *mtmp;
395 struct rm *lev;
396 int rx, ry, res = 0;
397
398 if (obj != uwep) {
399 if (uwep && uwep->cursed) {
400 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
401 pline("Since your weapon is welded to your hand,");
402 pline("you cannot use that pick-axe.");
403 return (0);
404 }
405 pline("You now wield %s.", doname(obj));
406 setuwep(obj);
407 res = 1;
408 }
409 while (*sdp) {
410 (void) movecmd(*sdp); /* sets u.dx and u.dy and u.dz */
411 rx = u.ux + u.dx;
412 ry = u.uy + u.dy;
413 if (u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
414 (IS_ROCK(levl[rx][ry].typ)
415 || sobj_at(ENORMOUS_ROCK, rx, ry))))
416 *dsp++ = *sdp;
417 sdp++;
418 }
419 *dsp = 0;
420 pline("In what direction do you want to dig? [%s] ", dirsyms);
421 if (!getdir(0)) /* no txt */
422 return (res);
423 if (u.uswallow && attack(u.ustuck)) /* return(1) */
424 ;
425 else if (u.dz < 0)
426 pline("You cannot reach the ceiling.");
427 else if (u.dz == 0) {
428 if (Confusion)
429 confdir();
430 rx = u.ux + u.dx;
431 ry = u.uy + u.dy;
432 if ((mtmp = m_at(rx, ry)) && attack(mtmp))
433 return (1);
434 if (!isok(rx, ry)) {
435 pline("Clash!");
436 return (1);
437 }
438 lev = &levl[rx][ry];
439 if (lev->typ == DOOR)
440 pline("Your %s against the door.",
441 aobjnam(obj, "clang"));
442 else if (!IS_ROCK(lev->typ)
443 && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
444 /* ACCESSIBLE or POOL */
445 pline("You swing your %s through thin air.",
446 aobjnam(obj, (char *) 0));
447 } else {
448 if (dig_pos.x != rx || dig_pos.y != ry
449 || dig_level != dlevel || dig_down) {
450 dig_down = FALSE;
451 dig_pos.x = rx;
452 dig_pos.y = ry;
453 dig_level = dlevel;
454 dig_effort = 0;
455 pline("You start digging.");
456 } else
457 pline("You continue digging.");
458 occupation = dig;
459 occtxt = "digging";
460 }
461 } else if (Levitation) {
462 pline("You cannot reach the floor.");
463 } else {
464 if (dig_pos.x != u.ux || dig_pos.y != u.uy
465 || dig_level != dlevel || !dig_down) {
466 dig_down = TRUE;
467 dig_pos.x = u.ux;
468 dig_pos.y = u.uy;
469 dig_level = dlevel;
470 dig_effort = 0;
471 pline("You start digging in the floor.");
472 if (inshop())
473 shopdig(0);
474 } else
475 pline("You continue digging in the floor.");
476 occupation = dig;
477 occtxt = "digging";
478 }
479 return (1);
480 }