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.2 2003/06/17 04:25:24 dillon 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)();
14 extern char quitchars[];
15 extern char pl_character[];
17 static void use_camera(), use_ice_box(), use_whistle(), use_magic_whistle();
18 static int use_pick_axe();
24 obj = getobj("(", "use or apply");
28 case EXPENSIVE_CAMERA:
29 use_camera(obj); break;
31 use_ice_box(obj); break;
33 res = use_pick_axe(obj);
37 if(pl_character[0] == 'W' || u.ulevel > 9) {
38 use_magic_whistle(obj);
41 /* fall into next case */
48 pline("You have no can to open.");
51 pline("You cannot open a tin without eating its contents.");
52 pline("In order to eat, use the 'e' command.");
54 pline("Opening the tin will be much easier if you wield the can-opener.");
58 pline("Sorry, I don't know how to use that.");
69 use_camera(obj) /* */ struct obj *obj; {
71 if(!getdir(1)){ /* ask: in what direction? */
72 flags.move = multi = 0;
76 pline("You take a picture of %s's stomach.", monnam(u.ustuck));
80 pline("You take a picture of the %s.",
81 (u.dz > 0) ? "floor" : "ceiling");
84 if(mtmp = bchit(u.dx, u.dy, COLNO, '!')) {
87 pline("The flash awakens %s.", monnam(mtmp)); /* a3 */
89 if(mtmp->data->mlet != 'y')
90 if(mtmp->mcansee || mtmp->mblinded){
91 int tmp = dist(mtmp->mx,mtmp->my);
93 if(cansee(mtmp->mx,mtmp->my))
94 pline("%s is blinded by the flash!", Monnam(mtmp));
96 if(tmp < 9 && !mtmp->isshk && rn2(4)) {
98 if(rn2(4)) mtmp->mfleetim = rnd(100);
100 if(tmp < 3) mtmp->mcansee = mtmp->mblinded = 0;
102 tmp2 = mtmp->mblinded;
103 tmp2 += rnd(1 + 50/tmp);
104 if(tmp2 > 127) tmp2 = 127;
105 mtmp->mblinded = tmp2;
113 struct obj *current_ice_box; /* a local variable of use_ice_box, to be
114 used by its local procedures in/ck_ice_box */
116 in_ice_box(obj) struct obj *obj; {
117 if(obj == current_ice_box ||
118 (Punished && (obj == uball || obj == uchain))){
119 pline("You must be kidding.");
122 if(obj->owornmask & (W_ARMOR | W_RING)) {
123 pline("You cannot refrigerate something you are wearing.");
126 if(obj->owt + current_ice_box->owt > 70) {
127 pline("It won't fit.");
128 return(1); /* be careful! */
132 pline("Your weapon is welded to your hand!");
135 setuwep((struct obj *) 0);
137 current_ice_box->owt += obj->owt;
139 obj->o_cnt_id = current_ice_box->o_id;
142 obj->age = moves - obj->age; /* actual age */
147 ck_ice_box(obj) struct obj *obj; {
148 return(obj->o_cnt_id == current_ice_box->o_id);
152 out_ice_box(obj) struct obj *obj; {
154 if(obj == fcobj) fcobj = fcobj->nobj;
156 for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj)
157 if(!otmp->nobj) panic("out_ice_box");
158 otmp->nobj = obj->nobj;
160 current_ice_box->owt -= obj->owt;
161 obj->age = moves - obj->age; /* simulated point of time */
166 use_ice_box(obj) struct obj *obj; {
169 current_ice_box = obj; /* for use by in/out_ice_box */
170 for(otmp = fcobj; otmp; otmp = otmp->nobj)
171 if(otmp->o_cnt_id == obj->o_id)
173 if(!cnt) pline("Your ice-box is empty.");
175 pline("Do you want to take something out of the ice-box? [yn] ");
176 if(readchar() == 'y')
177 if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0))
179 pline("That was all. Do you wish to put something in? [yn] ");
180 if(readchar() != 'y') return;
182 /* call getobj: 0: allow cnt; #: allow all types; %: expect food */
183 otmp = getobj("0#%", "put in");
184 if(!otmp || !in_ice_box(otmp))
185 flags.move = multi = 0;
190 bchit(ddx,ddy,range,sym) int ddx,ddy,range; char sym; {
191 struct monst *mtmp = (struct monst *) 0;
192 int bchx = u.ux, bchy = u.uy;
194 if(sym) Tmp_at(-1, sym); /* open call */
198 if(mtmp = m_at(bchx,bchy))
200 if(!ZAP_POS(levl[bchx][bchy].typ)) {
205 if(sym) Tmp_at(bchx, bchy);
207 if(sym) Tmp_at(-1, -1);
213 use_whistle(obj) struct obj *obj; {
214 struct monst *mtmp = fmon;
215 pline("You produce a high whistling sound.");
217 if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) {
221 EDOG(mtmp)->whistletime = moves;
229 use_magic_whistle(obj) struct obj *obj; {
230 struct monst *mtmp = fmon;
231 pline("You produce a strange whistling sound.");
233 if(mtmp->mtame) mnexto(mtmp);
238 static int dig_effort; /* effort expended on current pos */
239 static uchar dig_level;
240 static coord dig_pos;
241 static boolean dig_down;
246 int dpx = dig_pos.x, dpy = dig_pos.y;
248 /* perhaps a nymph stole his pick-axe while he was busy digging */
249 /* or perhaps he teleported away */
250 if(u.uswallow || !uwep || uwep->otyp != PICK_AXE ||
251 dig_level != dlevel ||
252 ((dig_down && (dpx != u.ux || dpy != u.uy)) ||
253 (!dig_down && dist(dpx,dpy) > 2)))
256 dig_effort += 10 + abon() + uwep->spe + rn2(5);
259 pline("The floor here seems too hard to dig in.");
262 if(dig_effort > 250) {
264 return(0); /* done with digging */
266 if(dig_effort > 50) {
267 struct trap *ttmp = t_at(dpx,dpy);
270 ttmp = maketrap(dpx,dpy,PIT);
272 pline("You have dug a pit.");
274 u.utraptype = TT_PIT;
279 if(dig_effort > 100) {
283 lev = &levl[dpx][dpy];
284 if(obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) {
286 digtxt = "The rock falls apart.";
287 } else if(!lev->typ || lev->typ == SCORR) {
289 digtxt = "You succeeded in cutting away some rock.";
290 } else if(lev->typ == HWALL || lev->typ == VWALL
291 || lev->typ == SDOOR) {
292 lev->typ = xdnstair ? DOOR : ROOM;
293 digtxt = "You just made an opening in the wall.";
295 digtxt = "Now what exactly was it that you were digging in?";
298 pline("%s", digtxt); /* after mnewsym & prl */
301 if(IS_WALL(levl[dpx][dpy].typ)) {
302 int rno = inroom(dpx,dpy);
304 if(rno >= 0 && rooms[rno].rtype >= 8) {
305 pline("This wall seems too hard to dig into.");
309 pline("You hit the rock with all your might.");
314 /* When will hole be finished? Very rough indication used by shopkeeper. */
316 return( (occupation == dig) ? (250 - dig_effort)/20 : -1);
321 struct trap *ttmp = t_at(u.ux, u.uy);
324 pline("The floor here seems too hard to dig in.");
327 ttmp->ttyp = TRAPDOOR;
329 ttmp = maketrap(u.ux, u.uy, TRAPDOOR);
331 pline("You've made a hole in the floor.");
335 pline("You fall through ...");
336 if(u.utraptype == TT_PIT) {
340 goto_level(dlevel+1, FALSE);
351 char *dsp = dirsyms, *sdp = sdir;
357 if(uwep && uwep->cursed) {
358 /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */
359 pline("Since your weapon is welded to your hand,");
360 pline("you cannot use that pick-axe.");
363 pline("You now wield %s.", doname(obj));
368 (void) movecmd(*sdp); /* sets u.dx and u.dy and u.dz */
371 if(u.dz > 0 || (u.dz == 0 && isok(rx, ry) &&
372 (IS_ROCK(levl[rx][ry].typ)
373 || sobj_at(ENORMOUS_ROCK, rx, ry))))
378 pline("In what direction do you want to dig? [%s] ", dirsyms);
379 if(!getdir(0)) /* no txt */
381 if(u.uswallow && attack(u.ustuck)) /* return(1) */;
384 pline("You cannot reach the ceiling.");
391 if((mtmp = m_at(rx, ry)) && attack(mtmp))
399 pline("Your %s against the door.",
400 aobjnam(obj, "clang"));
401 else if(!IS_ROCK(lev->typ)
402 && !sobj_at(ENORMOUS_ROCK, rx, ry)) {
403 /* ACCESSIBLE or POOL */
404 pline("You swing your %s through thin air.",
405 aobjnam(obj, (char *) 0));
407 if(dig_pos.x != rx || dig_pos.y != ry
408 || dig_level != dlevel || dig_down) {
414 pline("You start digging.");
416 pline("You continue digging.");
420 } else if(Levitation) {
421 pline("You cannot reach the floor.");
423 if(dig_pos.x != u.ux || dig_pos.y != u.uy
424 || dig_level != dlevel || !dig_down) {
430 pline("You start digging in the floor.");
434 pline("You continue digging in the floor.");