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.5 2006/08/21 19:45:32 pavalos Exp $ */
6 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
10 extern struct monst youmonst;
12 static int drop(struct obj *);
13 static void dropy(struct obj *);
18 return (drop(getobj("0$#", "drop")));
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));
41 if (obj->owornmask & (W_ARMOR | W_RING)) {
42 pline("You cannot drop something you are wearing.");
47 pline("Your weapon is welded to your hand!");
52 pline("You dropped %s.", doname(obj));
57 /* Called in several places - should not produce texts */
59 dropx(struct obj *obj)
66 dropy(struct obj *obj)
68 if (obj->otyp == CRYSKNIFE)
69 obj->otyp = WORM_TOOTH;
80 /* drop several things */
84 return (ggetobj("drop", drop, 0));
90 if (u.ux != xdnstair || u.uy != ydnstair) {
91 pline("You can't go down here.");
95 pline("You are being held, and cannot go down.");
99 pline("You're floating high above the stairs.");
103 goto_level(dlevel + 1, TRUE);
110 if (u.ux != xupstair || u.uy != yupstair) {
111 pline("You can't go up here.");
115 pline("You are being held, and cannot go up.");
118 if (!Levitation && inv_weight() + 5 > 0) {
119 pline("Your load is too heavy to climb the stairs.");
123 goto_level(dlevel - 1, TRUE);
128 goto_level(int newlevel, boolean at_stairs)
131 boolean up = (newlevel < dlevel);
133 if (newlevel <= 0) /* in fact < 0 is impossible */
135 if (newlevel > MAXLEVEL) /* strange ... */
137 if (newlevel == dlevel) /* this can happen */
141 fd = creat(lock, FMASK);
144 * This is not quite impossible: e.g., we may have
145 * exceeded our quota. If that is the case then we
146 * cannot leave this level, and cannot save either.
147 * Another possibility is that the directory was not
150 pline("A mysterious force prevents you from going %s.",
157 u.utrap = 0; /* needed in level_tele */
158 u.ustuck = 0; /* idem */
161 if (u.uswallow) /* idem */
162 u.uswldtim = u.uswallow = 0;
164 u.ux = FAR; /* hack */
165 inshop(); /* probably was a trapdoor */
171 if (maxdlevel < dlevel)
175 if (!level_exists[dlevel])
178 if ((fd = open(lock, O_RDONLY)) < 0) {
179 pline("Cannot open %s .", lock);
180 pline("Probably someone removed it.");
183 getlev(fd, hackpid, dlevel);
191 if (!u.ux) { /* entering a maze from below? */
192 u.ux = xupstair; /* this will confuse the player! */
195 if (Punished && !Levitation) {
196 pline("With great effort you climb the stairs.");
202 if (inv_weight() + 5 > 0 || Punished) {
203 pline("You fall down the stairs."); /* %% */
204 losehp(rnd(3), "fall");
206 if (uwep != uball && rn2(3)) {
207 pline("... and are hit by the iron ball.");
208 losehp(rnd(20), "iron ball");
212 selftouch("Falling, you");
216 struct monst *mtmp = m_at(u.ux, u.uy);
220 } else { /* trapdoor or level_tele */
222 u.ux = rnd(COLNO - 1);
224 } while (levl[u.ux][u.uy].typ != ROOM ||
227 if (uwep != uball && !up /* %% */ && rn2(5)) {
228 pline("The iron ball falls on your head.");
229 losehp(rnd(25), "iron ball");
233 selftouch("Falling, you");
241 if ((mtmp = m_at(u.ux, u.uy))) /* riv05!a3 */
246 seeobjs(); /* make old cadavers disappear - riv05!a3 */
249 read_engr_at(u.ux, u.uy);
255 return (1); /* Do nothing, but let other things happen */
261 nomovemsg = "You finished your prayer.";
273 obj = getobj("#)", "throw"); /* it is also possible to throw food */
274 /* (or jewels, or iron balls ... ) */
275 if (!obj || !getdir(1)) /* ask "in what direction?" */
277 if (obj->owornmask & (W_ARMOR | W_RING)) {
278 pline("You can't throw something you are wearing.");
286 pline("Your weapon is welded to your hand.");
290 setuwep(splitobj(obj, 1));
293 } else if (obj->quan > 1)
302 pline("%s hits the ceiling, then falls back on top of your head.",
303 Doname(obj)); /* note: obj->quan == 1 */
304 if (obj->olet == POTION_SYM)
305 potionhit(&youmonst, obj);
308 pline("Fortunately, you are wearing a helmet!");
309 losehp(uarmh ? 1 : rnd((int)(obj->owt)),
314 pline("%s hits the floor.", Doname(obj));
315 if (obj->otyp == EXPENSIVE_CAMERA) {
316 pline("It is shattered in a thousand pieces!");
318 } else if (obj->otyp == EGG) {
319 pline("\"Splash!\"");
321 } else if (obj->olet == POTION_SYM) {
322 pline("The flask breaks, and you smell a peculiar odor ...");
329 } else if (obj->otyp == BOOMERANG) {
330 mon = boomhit(u.dx, u.dy);
331 if (mon == &youmonst) { /* the thing was caught */
336 if (obj->otyp == PICK_AXE && shkcatch(obj))
339 mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 :
340 (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1,
341 obj->olet, (void (*)(struct monst *, struct obj *)) 0,
342 (bool (*)(struct obj *, struct obj *)) 0, obj);
345 /* awake monster if sleeping */
348 if (obj->olet == WEAPON_SYM) {
349 tmp = -1 + u.ulevel + mon->data->ac + abon();
350 if (obj->otyp < ROCK) {
352 uwep->otyp != obj->otyp + (BOW - ARROW))
357 } else if (obj->otyp == BOOMERANG)
360 if (u.uswallow || tmp >= rnd(20)) {
361 if (hmon(mon, obj, 1) == TRUE) {
362 /* mon still alive */
364 cutworm(mon, bhitpos.x, bhitpos.y, obj->otyp);
368 /* weapons thrown disappear sometimes */
369 if (obj->otyp < BOOMERANG && rn2(3)) {
370 /* check bill; free */
375 miss(objects[obj->otyp].oc_name, mon);
376 } else if (obj->otyp == HEAVY_IRON_BALL) {
377 tmp = -1 + u.ulevel + mon->data->ac + abon();
378 if (!Punished || obj != uball)
382 if (u.uswallow || tmp >= rnd(20)) {
383 if (hmon(mon, obj, 1) == FALSE)
384 mon = 0; /* he died */
386 miss("iron ball", mon);
387 } else if (obj->olet == POTION_SYM && u.ulevel > rn2(15)) {
391 if (cansee(bhitpos.x, bhitpos.y))
392 pline("You miss %s.", monnam(mon));
394 pline("You miss it.");
395 if (obj->olet == FOOD_SYM && mon->data->mlet == 'd')
396 if (tamedog(mon, obj))
398 if (obj->olet == GEM_SYM && mon->data->mlet == 'u' &&
400 if (obj->dknown && objects[obj->otyp].oc_name_known) {
401 if (objects[obj->otyp].g_val > 0) {
405 pline("%s is not interested in your junk.",
407 } else { /* value unknown to @ */
410 if (u.uluck > LUCKMAX) /* dan@ut-ngp */
412 pline("%s graciously accepts your gift.",
421 /* the code following might become part of dropy() */
422 if (obj->otyp == CRYSKNIFE)
423 obj->otyp = WORM_TOOTH;
428 /* prevent him from throwing articles to the exit and escaping */
429 /* subfrombill(obj); */
431 if (Punished && obj == uball &&
432 (bhitpos.x != u.ux || bhitpos.y != u.uy)) {
436 if (u.utraptype == TT_PIT)
437 pline("The ball pulls you out of the pit!");
439 long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
440 pline("The ball pulls you out of the bear trap.");
441 pline("Your %s leg is severely damaged.",
442 (side == LEFT_SIDE) ? "left" : "right");
443 set_wounded_legs(side, 500 + rn2(1000));
444 losehp(2, "thrown ball");
451 u.ux = uchain->ox = bhitpos.x - u.dx;
452 u.uy = uchain->oy = bhitpos.y - u.dy;
456 if (cansee(bhitpos.x, bhitpos.y))
457 prl(bhitpos.x, bhitpos.y);
461 /* split obj so that it gets size num */
462 /* remainder is put in the object structure delivered by this call */
464 splitobj(struct obj *obj, int num)
469 *otmp = *obj; /* copies whole structure */
470 otmp->o_id = flags.ident++;
473 obj->owt = weight(obj);
475 otmp->owt = weight(otmp); /* -= obj->owt ? */
478 splitbill(obj, otmp);
483 more_experienced(int exp, int rexp)
486 u.urexp += 4 * exp + rexp;
489 if (u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000))
494 set_wounded_legs(long side, int timex)
496 if (!Wounded_legs || (Wounded_legs & TIMEOUT))
497 Wounded_legs |= side + timex;
499 Wounded_legs |= side;
506 if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
507 pline("Your legs feel somewhat better.");
509 pline("Your leg feels somewhat better.");