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.3 2005/05/22 03:37:05 y0netan1 Exp $ */
8 #include "def.mkroom.h"
9 static struct monst *bchit();
10 extern struct obj *addinv();
11 extern struct trap *maketrap();
12 extern int (*occupation)();
13 extern char quitchars[];
14 extern char pl_character[];
16 static void use_camera(), use_ice_box(), use_whistle(), use_magic_whistle();
17 static int use_pick_axe();
23 obj = getobj("(", "use or apply");
27 case EXPENSIVE_CAMERA:
28 use_camera(obj); break;
30 use_ice_box(obj); break;
32 res = use_pick_axe(obj);
36 if(pl_character[0] == 'W' || u.ulevel > 9) {
37 use_magic_whistle(obj);
40 /* fall into next case */
47 pline("You have no can to open.");
50 pline("You cannot open a tin without eating its contents.");
51 pline("In order to eat, use the 'e' command.");
53 pline("Opening the tin will be much easier if you wield the can-opener.");
57 pline("Sorry, I don't know how to use that.");
68 use_camera(obj) /* */ struct obj *obj; {
70 if(!getdir(1)){ /* ask: in what direction? */
71 flags.move = multi = 0;
75 pline("You take a picture of %s's stomach.", monnam(u.ustuck));
79 pline("You take a picture of the %s.",
80 (u.dz > 0) ? "floor" : "ceiling");
83 if(mtmp = bchit(u.dx, u.dy, COLNO, '!')) {
86 pline("The flash awakens %s.", monnam(mtmp)); /* a3 */
88 if(mtmp->data->mlet != 'y')
89 if(mtmp->mcansee || mtmp->mblinded){
90 int tmp = dist(mtmp->mx,mtmp->my);
92 if(cansee(mtmp->mx,mtmp->my))
93 pline("%s is blinded by the flash!", Monnam(mtmp));
95 if(tmp < 9 && !mtmp->isshk && rn2(4)) {
97 if(rn2(4)) mtmp->mfleetim = rnd(100);
99 if(tmp < 3) mtmp->mcansee = mtmp->mblinded = 0;
101 tmp2 = mtmp->mblinded;
102 tmp2 += rnd(1 + 50/tmp);
103 if(tmp2 > 127) tmp2 = 127;
104 mtmp->mblinded = tmp2;
112 struct obj *current_ice_box; /* a local variable of use_ice_box, to be
113 used by its local procedures in/ck_ice_box */
115 in_ice_box(obj) struct obj *obj; {
116 if(obj == current_ice_box ||
117 (Punished && (obj == uball || obj == uchain))){
118 pline("You must be kidding.");
121 if(obj->owornmask & (W_ARMOR | W_RING)) {
122 pline("You cannot refrigerate something you are wearing.");
125 if(obj->owt + current_ice_box->owt > 70) {
126 pline("It won't fit.");
127 return(1); /* be careful! */
131 pline("Your weapon is welded to your hand!");
134 setuwep((struct obj *) 0);
136 current_ice_box->owt += obj->owt;
138 obj->o_cnt_id = current_ice_box->o_id;
141 obj->age = moves - obj->age; /* actual age */
146 ck_ice_box(obj) struct obj *obj; {
147 return(obj->o_cnt_id == current_ice_box->o_id);
151 out_ice_box(obj) struct obj *obj; {
153 if(obj == fcobj) fcobj = fcobj->nobj;
155 for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
156 if(!otmp->nobj) panic("out_ice_box");
157 otmp->nobj = obj->nobj;
159 current_ice_box->owt -= obj->owt;
160 obj->age = moves - obj->age; /* simulated point of time */
165 use_ice_box(obj) struct obj *obj; {
168 current_ice_box = obj; /* for use by in/out_ice_box */
169 for(otmp = fcobj; otmp; otmp = otmp->nobj)
170 if(otmp->o_cnt_id == obj->o_id)
172 if(!cnt) pline("Your ice-box is empty.");
174 pline("Do you want to take something out of the ice-box? [yn] ");
175 if(readchar() == 'y')
176 if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
178 pline("That was all. Do you wish to put something in? [yn] ");
179 if(readchar() != 'y') return;
181 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
182 otmp = getobj("0#%", "put in");
183 if(!otmp || !in_ice_box(otmp))
184 flags.move = multi = 0;
189 bchit(ddx,ddy,range,sym) int ddx,ddy,range; char sym; {
190 struct monst *mtmp = (struct monst *) 0;
191 int bchx = u.ux, bchy = u.uy;
193 if(sym) Tmp_at(-1, sym); /* open call */
197 if(mtmp = m_at(bchx,bchy))
199 if(!ZAP_POS(levl[bchx][bchy].typ)) {
204 if(sym) Tmp_at(bchx, bchy);
206 if(sym) Tmp_at(-1, -1);
212 use_whistle(obj) struct obj *obj; {
213 struct monst *mtmp = fmon;
214 pline("You produce a high whistling sound.");
216 if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) {
220 EDOG(mtmp)->whistletime = moves;
228 use_magic_whistle(obj) struct obj *obj; {
229 struct monst *mtmp = fmon;
230 pline("You produce a strange whistling sound.");
232 if(mtmp->mtame) mnexto(mtmp);
237 static int dig_effort; /* effort expended on current pos */
238 static uchar dig_level;
239 static coord dig_pos;
240 static boolean dig_down;
245 int dpx = dig_pos.x, dpy = dig_pos.y;
247 /* perhaps a nymph stole his pick-axe while he was busy digging */
248 /* or perhaps he teleported away */
249 if(u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
250 dig_level != dlevel ||
251 ((dig_down && (dpx != u.ux || dpy != u.uy)) ||
252 (!dig_down && dist(dpx,dpy) > 2)))
255 dig_effort += 10 + abon() + uwep->spe + rn2(5);
258 pline("The floor here seems too hard to dig in.");
261 if(dig_effort > 250) {
263 return(0); /* done with digging */
265 if(dig_effort > 50) {
266 struct trap *ttmp = t_at(dpx,dpy);
269 ttmp = maketrap(dpx,dpy,PIT);
271 pline("You have dug a pit.");
273 u.utraptype = TT_PIT;
278 if(dig_effort > 100) {
282 lev = &levl[dpx][dpy];
283 if(obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) {
285 digtxt = "The rock falls apart.";
286 } else if(!lev->typ || lev->typ == SCORR) {
288 digtxt = "You succeeded in cutting away some rock.";
289 } else if(lev->typ == HWALL || lev->typ == VWALL
290 || lev->typ == SDOOR) {
291 lev->typ = xdnstair ? DOOR : ROOM;
292 digtxt = "You just made an opening in the wall.";
294 digtxt = "Now what exactly was it that you were digging in?";
297 pline("%s", digtxt); /* after mnewsym & prl */
300 if(IS_WALL(levl[dpx][dpy].typ)) {
301 int rno = inroom(dpx,dpy);
303 if(rno >= 0 && rooms[rno].rtype >= 8) {
304 pline("This wall seems too hard to dig into.");
308 pline("You hit the rock with all your might.");
313 /* When will hole be finished? Very rough indication used by shopkeeper. */
315 return( (occupation == dig) ? (250 - dig_effort)/20 : -1);
320 struct trap *ttmp = t_at(u.ux, u.uy);
323 pline("The floor here seems too hard to dig in.");
326 ttmp->ttyp = TRAPDOOR;
328 ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
330 pline("You've made a hole in the floor.");
334 pline("You fall through ...");
335 if(u.utraptype == TT_PIT) {
339 goto_level(dlevel+1, FALSE);
350 char *dsp = dirsyms, *sdp = sdir;
356 if(uwep && uwep->cursed) {
357 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
358 pline("Since your weapon is welded to your hand,");
359 pline("you cannot use that pick-axe.");
362 pline("You now wield %s.", doname(obj));
367 (void) movecmd(*sdp); /* sets u.dx and u.dy and u.dz */
370 if(u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
371 (IS_ROCK(levl[rx][ry].typ)
372 || sobj_at(ENORMOUS_ROCK, rx, ry))))
377 pline("In what direction do you want to dig? [%s] ", dirsyms);
378 if(!getdir(0)) /* no txt */
380 if(u.uswallow && attack(u.ustuck)) /* return(1) */;
383 pline("You cannot reach the ceiling.");
390 if((mtmp = m_at(rx, ry)) && attack(mtmp))
398 pline("Your %s against the door.",
399 aobjnam(obj, "clang"));
400 else if(!IS_ROCK(lev->typ)
401 && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
402 /* ACCESSIBLE or POOL */
403 pline("You swing your %s through thin air.",
404 aobjnam(obj, (char *) 0));
406 if(dig_pos.x != rx || dig_pos.y != ry
407 || dig_level != dlevel || dig_down) {
413 pline("You start digging.");
415 pline("You continue digging.");
419 } else if(Levitation) {
420 pline("You cannot reach the floor.");
422 if(dig_pos.x != u.ux || dig_pos.y != u.uy
423 || dig_level != dlevel || !dig_down) {
429 pline("You start digging in the floor.");
433 pline("You continue digging in the floor.");