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 $ */
4 /* $DragonFly: src/games/hack/hack.apply.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
8 extern char quitchars[];
10 static void use_camera(struct obj *);
11 static bool in_ice_box(struct obj *);
12 static bool ck_ice_box(struct obj *);
13 static int out_ice_box(struct obj *);
14 static void use_ice_box(struct obj *);
15 static struct monst *bchit(int, int, int, char);
16 static void use_whistle(struct obj *);
17 static void use_magic_whistle(struct obj *);
18 static bool dig(void);
19 static int use_pick_axe(struct obj *);
27 obj = getobj("(", "use or apply");
32 case EXPENSIVE_CAMERA:
39 res = use_pick_axe(obj);
43 if (pl_character[0] == 'W' || u.ulevel > 9) {
44 use_magic_whistle(obj);
47 /* fall into next case */
54 pline("You have no can to open.");
57 pline("You cannot open a tin without eating its contents.");
58 pline("In order to eat, use the 'e' command.");
60 pline("Opening the tin will be much easier if you wield the can-opener.");
64 pline("Sorry, I don't know how to use that.");
74 use_camera(struct obj *obj __unused)
78 if (!getdir(1)) { /* ask: in what direction? */
79 flags.move = multi = 0;
83 pline("You take a picture of %s's stomach.", monnam(u.ustuck));
87 pline("You take a picture of the %s.",
88 (u.dz > 0) ? "floor" : "ceiling");
91 if ((mtmp = bchit(u.dx, u.dy, COLNO, '!')) != NULL) {
94 pline("The flash awakens %s.", monnam(mtmp)); /* a3 */
95 } else if (mtmp->data->mlet != 'y')
96 if (mtmp->mcansee || mtmp->mblinded) {
97 int tmp = dist(mtmp->mx, mtmp->my);
99 if (cansee(mtmp->mx, mtmp->my))
100 pline("%s is blinded by the flash!", Monnam(mtmp));
102 if (tmp < 9 && !mtmp->isshk && rn2(4)) {
105 mtmp->mfleetim = rnd(100);
108 mtmp->mcansee = mtmp->mblinded = 0;
110 tmp2 = mtmp->mblinded;
111 tmp2 += rnd(1 + 50 / tmp);
114 mtmp->mblinded = tmp2;
122 struct obj *current_ice_box; /* a local variable of use_ice_box, to be
123 used by its local procedures in/ck_ice_box */
125 in_ice_box(struct obj *obj)
127 if (obj == current_ice_box ||
128 (Punished && (obj == uball || obj == uchain))) {
129 pline("You must be kidding.");
132 if (obj->owornmask & (W_ARMOR | W_RING)) {
133 pline("You cannot refrigerate something you are wearing.");
136 if (obj->owt + current_ice_box->owt > 70) {
137 pline("It won't fit.");
138 return (1); /* be careful! */
142 pline("Your weapon is welded to your hand!");
147 current_ice_box->owt += obj->owt;
149 obj->o_cnt_id = current_ice_box->o_id;
152 obj->age = moves - obj->age; /* actual age */
157 ck_ice_box(struct obj *obj)
159 return (obj->o_cnt_id == current_ice_box->o_id);
163 out_ice_box(struct obj *obj)
170 for (otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
172 panic("out_ice_box");
173 otmp->nobj = obj->nobj;
175 current_ice_box->owt -= obj->owt;
176 obj->age = moves - obj->age; /* simulated point of time */
182 use_ice_box(struct obj *obj)
187 current_ice_box = obj; /* for use by in/out_ice_box */
188 for (otmp = fcobj; otmp; otmp = otmp->nobj)
189 if (otmp->o_cnt_id == obj->o_id)
192 pline("Your ice-box is empty.");
194 pline("Do you want to take something out of the ice-box? [yn] ");
195 if (readchar() == 'y')
196 if (askchain(fcobj, NULL, 0, out_ice_box, ck_ice_box, 0))
198 pline("That was all. Do you wish to put something in? [yn] ");
199 if (readchar() != 'y')
202 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
203 otmp = getobj("0#%", "put in");
204 if (!otmp || !in_ice_box(otmp))
205 flags.move = multi = 0;
210 bchit(int ddx, int ddy, int range, char sym)
212 struct monst *mtmp = NULL;
213 int bchx = u.ux, bchy = u.uy;
216 Tmp_at(-1, sym); /* open call */
220 if ((mtmp = m_at(bchx, bchy)))
222 if (!ZAP_POS(levl[bchx][bchy].typ)) {
236 use_whistle(struct obj *obj __unused)
238 struct monst *mtmp = fmon;
240 pline("You produce a high whistling sound.");
242 if (dist(mtmp->mx, mtmp->my) < u.ulevel * 20) {
246 EDOG(mtmp)->whistletime = moves;
253 use_magic_whistle(struct obj *obj __unused)
255 struct monst *mtmp = fmon;
257 pline("You produce a strange whistling sound.");
265 static int dig_effort; /* effort expended on current pos */
266 static uchar dig_level;
267 static coord dig_pos;
268 static boolean dig_down;
275 int dpx = dig_pos.x, dpy = dig_pos.y;
277 /* perhaps a nymph stole his pick-axe while he was busy digging */
278 /* or perhaps he teleported away */
279 if (u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
280 dig_level != dlevel ||
281 ((dig_down && (dpx != u.ux || dpy != u.uy)) ||
282 (!dig_down && dist(dpx, dpy) > 2)))
285 dig_effort += 10 + abon() + uwep->spe + rn2(5);
288 pline("The floor here seems too hard to dig in.");
291 if (dig_effort > 250) {
293 return (0); /* done with digging */
295 if (dig_effort > 50) {
296 struct trap *ttmp = t_at(dpx, dpy);
299 ttmp = maketrap(dpx, dpy, PIT);
301 pline("You have dug a pit.");
303 u.utraptype = TT_PIT;
307 } else if (dig_effort > 100) {
311 lev = &levl[dpx][dpy];
312 if ((obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) != NULL) {
314 digtxt = "The rock falls apart.";
315 } else if (!lev->typ || lev->typ == SCORR) {
317 digtxt = "You succeeded in cutting away some rock.";
318 } else if (lev->typ == HWALL || lev->typ == VWALL
319 || lev->typ == SDOOR) {
320 lev->typ = xdnstair ? DOOR : ROOM;
321 digtxt = "You just made an opening in the wall.";
323 digtxt = "Now what exactly was it that you were digging in?";
326 pline("%s", digtxt); /* after mnewsym & prl */
329 if (IS_WALL(levl[dpx][dpy].typ)) {
330 int rno = inroom(dpx, dpy);
332 if (rno >= 0 && rooms[rno].rtype >= 8) {
333 pline("This wall seems too hard to dig into.");
337 pline("You hit the rock with all your might.");
342 /* When will hole be finished? Very rough indication used by shopkeeper. */
346 return ((occupation == dig) ? (250 - dig_effort) / 20 : -1);
352 struct trap *ttmp = t_at(u.ux, u.uy);
355 pline("The floor here seems too hard to dig in.");
358 ttmp->ttyp = TRAPDOOR;
360 ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
362 pline("You've made a hole in the floor.");
366 pline("You fall through ...");
367 if (u.utraptype == TT_PIT) {
371 goto_level(dlevel + 1, FALSE);
377 use_pick_axe(struct obj *obj)
380 char *dsp = dirsyms, *sdp = sdir;
386 if (uwep && uwep->cursed) {
387 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
388 pline("Since your weapon is welded to your hand,");
389 pline("you cannot use that pick-axe.");
392 pline("You now wield %s.", doname(obj));
397 movecmd(*sdp); /* sets u.dx and u.dy and u.dz */
400 if (u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
401 (IS_ROCK(levl[rx][ry].typ)
402 || sobj_at(ENORMOUS_ROCK, rx, ry))))
407 pline("In what direction do you want to dig? [%s] ", dirsyms);
408 if (!getdir(0)) /* no txt */
410 if (u.uswallow && attack(u.ustuck)) /* return(1) */
413 pline("You cannot reach the ceiling.");
414 else if (u.dz == 0) {
419 if ((mtmp = m_at(rx, ry)) && attack(mtmp))
426 if (lev->typ == DOOR)
427 pline("Your %s against the door.",
428 aobjnam(obj, "clang"));
429 else if (!IS_ROCK(lev->typ)
430 && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
431 /* ACCESSIBLE or POOL */
432 pline("You swing your %s through thin air.",
435 if (dig_pos.x != rx || dig_pos.y != ry
436 || dig_level != dlevel || dig_down) {
442 pline("You start digging.");
444 pline("You continue digging.");
448 } else if (Levitation) {
449 pline("You cannot reach the floor.");
451 if (dig_pos.x != u.ux || dig_pos.y != u.uy
452 || dig_level != dlevel || !dig_down) {
458 pline("You start digging in the floor.");
462 pline("You continue digging in the floor.");