1 /* $NetBSD: hack.do.c,v 1.11 2011/08/06 20:29:37 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
73 static int drop(struct obj *);
74 static void dropy(struct obj *);
79 return (drop(getobj("0$#", "drop")));
87 if (obj->olet == '$') { /* pseudo object */
88 long amount = OGOLD(obj);
91 pline("You didn't drop any gold pieces.");
93 mkgold(amount, u.ux, u.uy);
94 pline("You dropped %ld gold piece%s.",
95 amount, plur(amount));
102 if (obj->owornmask & (W_ARMOR | W_RING)) {
103 pline("You cannot drop something you are wearing.");
108 pline("Your weapon is welded to your hand!");
111 setuwep((struct obj *) 0);
113 pline("You dropped %s.", doname(obj));
118 /* Called in several places - should not produce texts */
120 dropx(struct obj *obj)
127 dropy(struct obj *obj)
129 if (obj->otyp == CRYSKNIFE)
130 obj->otyp = WORM_TOOTH;
141 /* drop several things */
145 return (ggetobj("drop", drop, 0));
151 if (u.ux != xdnstair || u.uy != ydnstair) {
152 pline("You can't go down here.");
156 pline("You are being held, and cannot go down.");
160 pline("You're floating high above the stairs.");
163 goto_level(dlevel + 1, TRUE);
170 if (u.ux != xupstair || u.uy != yupstair) {
171 pline("You can't go up here.");
175 pline("You are being held, and cannot go up.");
178 if (!Levitation && inv_weight() + 5 > 0) {
179 pline("Your load is too heavy to climb the stairs.");
182 goto_level(dlevel - 1, TRUE);
187 goto_level(int newlevel, boolean at_stairs)
190 boolean up = (newlevel < dlevel);
193 done("escaped");/* in fact < 0 is impossible */
194 if (newlevel > MAXLEVEL)
195 newlevel = MAXLEVEL; /* strange ... */
196 if (newlevel == dlevel)
197 return; /* this can happen */
200 fd = creat(lock, FMASK);
203 * This is not quite impossible: e.g., we may have
204 * exceeded our quota. If that is the case then we
205 * cannot leave this level, and cannot save either.
206 * Another possibility is that the directory was not
209 pline("A mysterious force prevents you from going %s.",
215 u.utrap = 0; /* needed in level_tele */
216 u.ustuck = 0; /* idem */
219 if (u.uswallow) /* idem */
220 u.uswldtim = u.uswallow = 0;
222 u.ux = FAR; /* hack */
223 (void) inshop(); /* probably was a trapdoor */
229 if (maxdlevel < dlevel)
233 if (!level_exists[dlevel])
236 if ((fd = open(lock, O_RDONLY)) < 0) {
237 pline("Cannot open %s .", lock);
238 pline("Probably someone removed it.");
241 getlev(fd, hackpid, dlevel);
249 if (!u.ux) { /* entering a maze from below? */
250 u.ux = xupstair; /* this will confuse the
254 if (Punished && !Levitation) {
255 pline("With great effort you climb the stairs.");
261 if (inv_weight() + 5 > 0 || Punished) {
262 pline("You fall down the stairs."); /* %% */
263 losehp(rnd(3), "fall");
265 if (uwep != uball && rn2(3)) {
266 pline("... and are hit by the iron ball.");
267 losehp(rnd(20), "iron ball");
271 selftouch("Falling, you");
275 struct monst *mtmp = m_at(u.ux, u.uy);
279 } else { /* trapdoor or level_tele */
281 u.ux = rnd(COLNO - 1);
283 } while (levl[u.ux][u.uy].typ != ROOM ||
286 if (uwep != uball && !up /* %% */ && rn2(5)) {
287 pline("The iron ball falls on your head.");
288 losehp(rnd(25), "iron ball");
292 selftouch("Falling, you");
300 if ((mtmp = m_at(u.ux, u.uy)) != NULL)
301 mnexto(mtmp); /* riv05!a3 */
305 seeobjs(); /* make old cadavers disappear - riv05!a3 */
308 read_engr_at(u.ux, u.uy);
314 return (1); /* Do nothing, but let other things happen */
320 nomovemsg = "You finished your prayer.";
332 obj = getobj("#)", "throw"); /* it is also possible to throw food */
333 /* (or jewels, or iron balls ... ) */
334 if (!obj || !getdir(1)) /* ask "in what direction?" */
336 if (obj->owornmask & (W_ARMOR | W_RING)) {
337 pline("You can't throw something you are wearing.");
344 pline("Your weapon is welded to your hand.");
348 setuwep(splitobj(obj, 1));
350 setuwep((struct obj *) 0);
351 } else if (obj->quan > 1)
352 (void) splitobj(obj, 1);
360 pline("%s hits the ceiling, then falls back on top of your head.",
361 Doname(obj)); /* note: obj->quan == 1 */
362 if (obj->olet == POTION_SYM)
363 potionhit(&youmonst, obj);
366 pline("Fortunately, you are wearing a helmet!");
367 losehp(uarmh ? 1 : rnd((int) (obj->owt)), "falling object");
371 pline("%s hits the floor.", Doname(obj));
372 if (obj->otyp == EXPENSIVE_CAMERA) {
373 pline("It is shattered in a thousand pieces!");
374 obfree(obj, Null(obj));
375 } else if (obj->otyp == EGG) {
376 pline("\"Splash!\"");
377 obfree(obj, Null(obj));
378 } else if (obj->olet == POTION_SYM) {
379 pline("The flask breaks, and you smell a peculiar odor ...");
381 obfree(obj, Null(obj));
387 } else if (obj->otyp == BOOMERANG) {
388 mon = boomhit(u.dx, u.dy);
389 if (mon == &youmonst) { /* the thing was caught */
394 if (obj->otyp == PICK_AXE && shkcatch(obj))
397 mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 :
398 (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1,
400 (void (*)(struct monst *, struct obj *)) 0,
401 (int (*)(struct obj *, struct obj *)) 0, obj);
404 /* awake monster if sleeping */
407 if (obj->olet == WEAPON_SYM) {
408 tmp = -1 + u.ulevel + mon->data->ac + abon();
409 if (obj->otyp < ROCK) {
411 uwep->otyp != obj->otyp + (BOW - ARROW))
416 } else if (obj->otyp == BOOMERANG)
419 if (u.uswallow || tmp >= rnd(20)) {
420 if (hmon(mon, obj, 1) == TRUE) {
421 /* mon still alive */
423 cutworm(mon, bhitpos.x, bhitpos.y, obj->otyp);
427 /* weapons thrown disappear sometimes */
428 if (obj->otyp < BOOMERANG && rn2(3)) {
429 /* check bill; free */
430 obfree(obj, (struct obj *) 0);
434 miss(objects[obj->otyp].oc_name, mon);
435 } else if (obj->otyp == HEAVY_IRON_BALL) {
436 tmp = -1 + u.ulevel + mon->data->ac + abon();
437 if (!Punished || obj != uball)
441 if (u.uswallow || tmp >= rnd(20)) {
442 if (hmon(mon, obj, 1) == FALSE)
443 mon = 0; /* he died */
445 miss("iron ball", mon);
446 } else if (obj->olet == POTION_SYM && u.ulevel > rn2(15)) {
450 if (cansee(bhitpos.x, bhitpos.y))
451 pline("You miss %s.", monnam(mon));
453 pline("You miss it.");
454 if (obj->olet == FOOD_SYM && mon->data->mlet == 'd')
455 if (tamedog(mon, obj))
457 if (obj->olet == GEM_SYM && mon->data->mlet == 'u' &&
459 if (obj->dknown && objects[obj->otyp].oc_name_known) {
460 if (objects[obj->otyp].g_val > 0) {
464 pline("%s is not interested in your junk.",
467 } else { /* value unknown to @ */
470 if (u.uluck > LUCKMAX) /* dan@ut-ngp */
472 pline("%s graciously accepts your gift.",
481 /* the code following might become part of dropy() */
482 if (obj->otyp == CRYSKNIFE)
483 obj->otyp = WORM_TOOTH;
488 /* prevent him from throwing articles to the exit and escaping */
489 /* subfrombill(obj); */
491 if (Punished && obj == uball &&
492 (bhitpos.x != u.ux || bhitpos.y != u.uy)) {
496 if (u.utraptype == TT_PIT)
497 pline("The ball pulls you out of the pit!");
500 rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
501 pline("The ball pulls you out of the bear trap.");
502 pline("Your %s leg is severely damaged.",
503 (side == LEFT_SIDE) ? "left" : "right");
504 set_wounded_legs(side, 500 + rn2(1000));
505 losehp(2, "thrown ball");
512 u.ux = uchain->ox = bhitpos.x - u.dx;
513 u.uy = uchain->oy = bhitpos.y - u.dy;
517 if (cansee(bhitpos.x, bhitpos.y))
518 prl(bhitpos.x, bhitpos.y);
522 /* split obj so that it gets size num */
523 /* remainder is put in the object structure delivered by this call */
525 splitobj(struct obj *obj, int num)
529 *otmp = *obj; /* copies whole structure */
530 otmp->o_id = flags.ident++;
533 obj->owt = weight(obj);
535 otmp->owt = weight(otmp); /* -= obj->owt ? */
538 splitbill(obj, otmp);
543 more_experienced(int exp, int rexp)
546 u.urexp += 4 * exp + rexp;
549 if (u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000))
554 set_wounded_legs(long side, int timex)
556 if (!Wounded_legs || (Wounded_legs & TIMEOUT))
557 Wounded_legs |= side + timex;
559 Wounded_legs |= side;
566 if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES)
567 pline("Your legs feel somewhat better.");
569 pline("Your leg feels somewhat better.");