1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.do.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.do.c,v 1.4 1999/11/16 10:26:36 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.do.c,v 1.3 2004/11/06 12:29:17 eirikn Exp $ */
6 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
10 extern struct obj *splitobj(), *addinv();
11 extern boolean hmon();
12 extern boolean level_exists[];
13 extern struct monst youmonst;
14 extern char *Doname();
15 extern char *nomovemsg;
20 return(drop(getobj("0$#", "drop")));
24 drop(obj) struct obj *obj; {
26 if(obj->olet == '$') { /* pseudo object */
27 long amount = OGOLD(obj);
30 pline("You didn't drop any gold pieces.");
32 mkgold(amount, u.ux, u.uy);
33 pline("You dropped %ld gold piece%s.",
34 amount, plur(amount));
35 if(Invisible) newsym(u.ux, u.uy);
40 if(obj->owornmask & (W_ARMOR | W_RING)){
41 pline("You cannot drop something you are wearing.");
46 pline("Your weapon is welded to your hand!");
49 setuwep((struct obj *) 0);
51 pline("You dropped %s.", doname(obj));
56 /* Called in several places - should not produce texts */
67 if(obj->otyp == CRYSKNIFE)
68 obj->otyp = WORM_TOOTH;
73 if(Invisible) newsym(u.ux,u.uy);
78 /* drop several things */
80 return(ggetobj("drop", drop, 0));
85 if(u.ux != xdnstair || u.uy != ydnstair) {
86 pline("You can't go down here.");
90 pline("You are being held, and cannot go down.");
94 pline("You're floating high above the stairs.");
98 goto_level(dlevel+1, TRUE);
104 if(u.ux != xupstair || u.uy != yupstair) {
105 pline("You can't go up here.");
109 pline("You are being held, and cannot go up.");
112 if(!Levitation && inv_weight() + 5 > 0) {
113 pline("Your load is too heavy to climb the stairs.");
117 goto_level(dlevel-1, TRUE);
121 goto_level(newlevel, at_stairs)
126 boolean up = (newlevel < dlevel);
128 if(newlevel <= 0) done("escaped"); /* in fact < 0 is impossible */
129 if(newlevel > MAXLEVEL) newlevel = MAXLEVEL; /* strange ... */
130 if(newlevel == dlevel) return; /* this can happen */
133 fd = creat(lock, FMASK);
136 * This is not quite impossible: e.g., we may have
137 * exceeded our quota. If that is the case then we
138 * cannot leave this level, and cannot save either.
139 * Another possibility is that the directory was not
142 pline("A mysterious force prevents you from going %s.",
147 if(Punished) unplacebc();
148 u.utrap = 0; /* needed in level_tele */
149 u.ustuck = 0; /* idem */
152 if(u.uswallow) /* idem */
153 u.uswldtim = u.uswallow = 0;
155 u.ux = FAR; /* hack */
156 (void) inshop(); /* probably was a trapdoor */
162 if(maxdlevel < dlevel)
166 if(!level_exists[dlevel])
171 if((fd = open(lock,0)) < 0) {
172 pline("Cannot open %s .", lock);
173 pline("Probably someone removed it.");
176 getlev(fd, hackpid, dlevel);
184 if(!u.ux) { /* entering a maze from below? */
185 u.ux = xupstair; /* this will confuse the player! */
188 if(Punished && !Levitation){
189 pline("With great effort you climb the stairs.");
195 if(inv_weight() + 5 > 0 || Punished){
196 pline("You fall down the stairs."); /* %% */
197 losehp(rnd(3), "fall");
199 if(uwep != uball && rn2(3)){
200 pline("... and are hit by the iron ball.");
201 losehp(rnd(20), "iron ball");
205 selftouch("Falling, you");
208 { struct monst *mtmp = m_at(u.ux, u.uy);
212 } else { /* trapdoor or level_tele */
216 } while(levl[u.ux][u.uy].typ != ROOM ||
219 if(uwep != uball && !up /* %% */ && rn2(5)){
220 pline("The iron ball falls on your head.");
221 losehp(rnd(25), "iron ball");
225 selftouch("Falling, you");
231 { struct monst *mtmp;
232 if(mtmp = m_at(u.ux, u.uy)) mnexto(mtmp); /* riv05!a3 */
236 seeobjs(); /* make old cadavers disappear - riv05!a3 */
239 read_engr_at(u.ux,u.uy);
243 return(1); /* Do nothing, but let other things happen */
247 nomovemsg = "You finished your prayer.";
252 struct monst *bhit(), *boomhit();
259 obj = getobj("#)", "throw"); /* it is also possible to throw food */
260 /* (or jewels, or iron balls ... ) */
261 if(!obj || !getdir(1)) /* ask "in what direction?" */
263 if(obj->owornmask & (W_ARMOR | W_RING)){
264 pline("You can't throw something you are wearing.");
272 pline("Your weapon is welded to your hand.");
276 setuwep(splitobj(obj, 1));
278 setuwep((struct obj *) 0);
280 else if(obj->quan > 1)
281 (void) splitobj(obj, 1);
289 pline("%s hits the ceiling, then falls back on top of your head.",
290 Doname(obj)); /* note: obj->quan == 1 */
291 if(obj->olet == POTION_SYM)
292 potionhit(&youmonst, obj);
294 if(uarmh) pline("Fortunately, you are wearing a helmet!");
295 losehp(uarmh ? 1 : rnd((int)(obj->owt)), "falling object");
299 pline("%s hits the floor.", Doname(obj));
300 if(obj->otyp == EXPENSIVE_CAMERA) {
301 pline("It is shattered in a thousand pieces!");
302 obfree(obj, Null(obj));
303 } else if(obj->otyp == EGG) {
304 pline("\"Splash!\"");
305 obfree(obj, Null(obj));
306 } else if(obj->olet == POTION_SYM) {
307 pline("The flask breaks, and you smell a peculiar odor ...");
309 obfree(obj, Null(obj));
315 } else if(obj->otyp == BOOMERANG) {
316 mon = boomhit(u.dx, u.dy);
317 if(mon == &youmonst) { /* the thing was caught */
322 if(obj->otyp == PICK_AXE && shkcatch(obj))
325 mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 :
326 (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1,
328 (int (*)()) 0, (int (*)()) 0, obj);
331 /* awake monster if sleeping */
334 if(obj->olet == WEAPON_SYM) {
335 tmp = -1+u.ulevel+mon->data->ac+abon();
336 if(obj->otyp < ROCK) {
338 uwep->otyp != obj->otyp+(BOW-ARROW))
344 if(obj->otyp == BOOMERANG) tmp += 4;
346 if(u.uswallow || tmp >= rnd(20)) {
347 if(hmon(mon,obj,1) == TRUE){
348 /* mon still alive */
350 cutworm(mon,bhitpos.x,bhitpos.y,obj->otyp);
353 /* weapons thrown disappear sometimes */
354 if(obj->otyp < BOOMERANG && rn2(3)) {
355 /* check bill; free */
356 obfree(obj, (struct obj *) 0);
359 } else miss(objects[obj->otyp].oc_name, mon);
360 } else if(obj->otyp == HEAVY_IRON_BALL) {
361 tmp = -1+u.ulevel+mon->data->ac+abon();
362 if(!Punished || obj != uball) tmp += 2;
363 if(u.utrap) tmp -= 2;
364 if(u.uswallow || tmp >= rnd(20)) {
365 if(hmon(mon,obj,1) == FALSE)
366 mon = 0; /* he died */
367 } else miss("iron ball", mon);
368 } else if(obj->olet == POTION_SYM && u.ulevel > rn2(15)) {
372 if(cansee(bhitpos.x,bhitpos.y))
373 pline("You miss %s.",monnam(mon));
374 else pline("You miss it.");
375 if(obj->olet == FOOD_SYM && mon->data->mlet == 'd')
376 if(tamedog(mon,obj)) return(1);
377 if(obj->olet == GEM_SYM && mon->data->mlet == 'u' &&
379 if(obj->dknown && objects[obj->otyp].oc_name_known){
380 if(objects[obj->otyp].g_val > 0){
384 pline("%s is not interested in your junk.",
387 } else { /* value unknown to @ */
390 if(u.uluck > LUCKMAX) /* dan@ut-ngp */
392 pline("%s graciously accepts your gift.",
401 /* the code following might become part of dropy() */
402 if(obj->otyp == CRYSKNIFE)
403 obj->otyp = WORM_TOOTH;
408 /* prevent him from throwing articles to the exit and escaping */
409 /* subfrombill(obj); */
411 if(Punished && obj == uball &&
412 (bhitpos.x != u.ux || bhitpos.y != u.uy)){
416 if(u.utraptype == TT_PIT)
417 pline("The ball pulls you out of the pit!");
420 rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
421 pline("The ball pulls you out of the bear trap.");
422 pline("Your %s leg is severely damaged.",
423 (side == LEFT_SIDE) ? "left" : "right");
424 set_wounded_legs(side, 500+rn2(1000));
425 losehp(2, "thrown ball");
432 u.ux = uchain->ox = bhitpos.x - u.dx;
433 u.uy = uchain->oy = bhitpos.y - u.dy;
437 if(cansee(bhitpos.x, bhitpos.y)) prl(bhitpos.x,bhitpos.y);
441 /* split obj so that it gets size num */
442 /* remainder is put in the object structure delivered by this call */
444 splitobj(obj, num) struct obj *obj; int num; {
447 *otmp = *obj; /* copies whole structure */
448 otmp->o_id = flags.ident++;
451 obj->owt = weight(obj);
453 otmp->owt = weight(otmp); /* -= obj->owt ? */
455 if(obj->unpaid) splitbill(obj,otmp);
459 more_experienced(exp,rexp)
462 extern char pl_character[];
465 u.urexp += 4*exp + rexp;
466 if(exp) flags.botl = 1;
467 if(u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000))
471 set_wounded_legs(side, timex)
475 if(!Wounded_legs || (Wounded_legs & TIMEOUT))
476 Wounded_legs |= side + timex;
478 Wounded_legs |= side;
484 if((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
485 pline("Your legs feel somewhat better.");
487 pline("Your leg feels somewhat better.");