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");
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.");
71 use_camera(__unused struct obj *obj)
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 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(struct obj *obj)
121 if(obj == current_ice_box ||
122 (Punished && (obj == uball || obj == uchain))){
123 pline("You must be kidding.");
126 if(obj->owornmask & (W_ARMOR | W_RING)) {
127 pline("You cannot refrigerate something you are wearing.");
130 if(obj->owt + current_ice_box->owt > 70) {
131 pline("It won't fit.");
132 return(1); /* be careful! */
136 pline("Your weapon is welded to your hand!");
139 setuwep((struct obj *) 0);
141 current_ice_box->owt += obj->owt;
143 obj->o_cnt_id = current_ice_box->o_id;
146 obj->age = moves - obj->age; /* actual age */
151 ck_ice_box(struct obj *obj)
153 return(obj->o_cnt_id == current_ice_box->o_id);
157 out_ice_box(struct obj *obj)
160 if(obj == fcobj) fcobj = fcobj->nobj;
162 for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
163 if(!otmp->nobj) panic("out_ice_box");
164 otmp->nobj = obj->nobj;
166 current_ice_box->owt -= obj->owt;
167 obj->age = moves - obj->age; /* simulated point of time */
173 use_ice_box(struct obj *obj)
177 current_ice_box = obj; /* for use by in/out_ice_box */
178 for(otmp = fcobj; otmp; otmp = otmp->nobj)
179 if(otmp->o_cnt_id == obj->o_id)
181 if(!cnt) pline("Your ice-box is empty.");
183 pline("Do you want to take something out of the ice-box? [yn] ");
184 if(readchar() == 'y')
185 if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
187 pline("That was all. Do you wish to put something in? [yn] ");
188 if(readchar() != 'y') return;
190 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
191 otmp = getobj("0#%", "put in");
192 if(!otmp || !in_ice_box(otmp))
193 flags.move = multi = 0;
196 static struct monst *
197 bchit(int ddx, int ddy, int range, char sym)
199 struct monst *mtmp = (struct monst *) 0;
200 int bchx = u.ux, bchy = u.uy;
202 if(sym) Tmp_at(-1, sym); /* open call */
206 if((mtmp = m_at(bchx,bchy)))
208 if(!ZAP_POS(levl[bchx][bchy].typ)) {
213 if(sym) Tmp_at(bchx, bchy);
215 if(sym) Tmp_at(-1, -1);
220 use_whistle(__unused struct obj *obj)
222 struct monst *mtmp = fmon;
223 pline("You produce a high whistling sound.");
225 if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) {
229 EDOG(mtmp)->whistletime = moves;
236 use_magic_whistle(__unused struct obj *obj)
238 struct monst *mtmp = fmon;
239 pline("You produce a strange whistling sound.");
241 if(mtmp->mtame) mnexto(mtmp);
246 static int dig_effort; /* effort expended on current pos */
247 static uchar dig_level;
248 static coord dig_pos;
249 static boolean dig_down;
255 int dpx = dig_pos.x, dpy = dig_pos.y;
257 /* perhaps a nymph stole his pick-axe while he was busy digging */
258 /* or perhaps he teleported away */
259 if(u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
260 dig_level != dlevel ||
261 ((dig_down && (dpx != u.ux || dpy != u.uy)) ||
262 (!dig_down && dist(dpx,dpy) > 2)))
265 dig_effort += 10 + abon() + uwep->spe + rn2(5);
268 pline("The floor here seems too hard to dig in.");
271 if(dig_effort > 250) {
273 return(0); /* done with digging */
275 if(dig_effort > 50) {
276 struct trap *ttmp = t_at(dpx,dpy);
279 ttmp = maketrap(dpx,dpy,PIT);
281 pline("You have dug a pit.");
283 u.utraptype = TT_PIT;
288 if(dig_effort > 100) {
292 lev = &levl[dpx][dpy];
293 if((obj = sobj_at(ENORMOUS_ROCK, dpx, dpy))) {
295 digtxt = "The rock falls apart.";
296 } else if(!lev->typ || lev->typ == SCORR) {
298 digtxt = "You succeeded in cutting away some rock.";
299 } else if(lev->typ == HWALL || lev->typ == VWALL
300 || lev->typ == SDOOR) {
301 lev->typ = xdnstair ? DOOR : ROOM;
302 digtxt = "You just made an opening in the wall.";
304 digtxt = "Now what exactly was it that you were digging in?";
307 pline("%s", digtxt); /* after mnewsym & prl */
310 if(IS_WALL(levl[dpx][dpy].typ)) {
311 int rno = inroom(dpx,dpy);
313 if(rno >= 0 && rooms[rno].rtype >= 8) {
314 pline("This wall seems too hard to dig into.");
318 pline("You hit the rock with all your might.");
323 /* When will hole be finished? Very rough indication used by shopkeeper. */
327 return( (occupation == dig) ? (250 - dig_effort)/20 : -1);
333 struct trap *ttmp = t_at(u.ux, u.uy);
336 pline("The floor here seems too hard to dig in.");
339 ttmp->ttyp = TRAPDOOR;
341 ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
343 pline("You've made a hole in the floor.");
347 pline("You fall through ...");
348 if(u.utraptype == TT_PIT) {
352 goto_level(dlevel+1, FALSE);
358 use_pick_axe(struct obj *obj)
361 char *dsp = dirsyms, *sdp = sdir;
367 if(uwep && uwep->cursed) {
368 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
369 pline("Since your weapon is welded to your hand,");
370 pline("you cannot use that pick-axe.");
373 pline("You now wield %s.", doname(obj));
378 movecmd(*sdp); /* sets u.dx and u.dy and u.dz */
381 if(u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
382 (IS_ROCK(levl[rx][ry].typ)
383 || sobj_at(ENORMOUS_ROCK, rx, ry))))
388 pline("In what direction do you want to dig? [%s] ", dirsyms);
389 if(!getdir(0)) /* no txt */
391 if(u.uswallow && attack(u.ustuck)) /* return(1) */;
394 pline("You cannot reach the ceiling.");
401 if((mtmp = m_at(rx, ry)) && attack(mtmp))
409 pline("Your %s against the door.",
410 aobjnam(obj, "clang"));
411 else if(!IS_ROCK(lev->typ)
412 && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
413 /* ACCESSIBLE or POOL */
414 pline("You swing your %s through thin air.",
415 aobjnam(obj, (char *) 0));
417 if(dig_pos.x != rx || dig_pos.y != ry
418 || dig_level != dlevel || dig_down) {
424 pline("You start digging.");
426 pline("You continue digging.");
430 } else if(Levitation) {
431 pline("You cannot reach the floor.");
433 if(dig_pos.x != u.ux || dig_pos.y != u.uy
434 || dig_level != dlevel || !dig_down) {
440 pline("You start digging in the floor.");
444 pline("You continue digging in the floor.");