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