1 /* $NetBSD: hack.do.c,v 1.8 2009/06/07 18:30:39 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 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.do.c,v 1.8 2009/06/07 18:30:39 dholland Exp $");
69 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
78 static int drop(struct obj
*);
79 static void dropy(struct obj
*);
84 return (drop(getobj("0$#", "drop")));
92 if (obj
->olet
== '$') { /* pseudo object */
93 long amount
= OGOLD(obj
);
96 pline("You didn't drop any gold pieces.");
98 mkgold(amount
, u
.ux
, u
.uy
);
99 pline("You dropped %ld gold piece%s.",
100 amount
, plur(amount
));
107 if (obj
->owornmask
& (W_ARMOR
| W_RING
)) {
108 pline("You cannot drop something you are wearing.");
113 pline("Your weapon is welded to your hand!");
116 setuwep((struct obj
*) 0);
118 pline("You dropped %s.", doname(obj
));
123 /* Called in several places - should not produce texts */
125 dropx(struct obj
*obj
)
132 dropy(struct obj
*obj
)
134 if (obj
->otyp
== CRYSKNIFE
)
135 obj
->otyp
= WORM_TOOTH
;
146 /* drop several things */
150 return (ggetobj("drop", drop
, 0));
156 if (u
.ux
!= xdnstair
|| u
.uy
!= ydnstair
) {
157 pline("You can't go down here.");
161 pline("You are being held, and cannot go down.");
165 pline("You're floating high above the stairs.");
168 goto_level(dlevel
+ 1, TRUE
);
175 if (u
.ux
!= xupstair
|| u
.uy
!= yupstair
) {
176 pline("You can't go up here.");
180 pline("You are being held, and cannot go up.");
183 if (!Levitation
&& inv_weight() + 5 > 0) {
184 pline("Your load is too heavy to climb the stairs.");
187 goto_level(dlevel
- 1, TRUE
);
192 goto_level(int newlevel
, boolean at_stairs
)
195 boolean up
= (newlevel
< dlevel
);
198 done("escaped");/* in fact < 0 is impossible */
199 if (newlevel
> MAXLEVEL
)
200 newlevel
= MAXLEVEL
; /* strange ... */
201 if (newlevel
== dlevel
)
202 return; /* this can happen */
205 fd
= creat(lock
, FMASK
);
208 * This is not quite impossible: e.g., we may have
209 * exceeded our quota. If that is the case then we
210 * cannot leave this level, and cannot save either.
211 * Another possibility is that the directory was not
214 pline("A mysterious force prevents you from going %s.",
220 u
.utrap
= 0; /* needed in level_tele */
221 u
.ustuck
= 0; /* idem */
224 if (u
.uswallow
) /* idem */
225 u
.uswldtim
= u
.uswallow
= 0;
227 u
.ux
= FAR
; /* hack */
228 (void) inshop(); /* probably was a trapdoor */
234 if (maxdlevel
< dlevel
)
238 if (!level_exists
[dlevel
])
241 if ((fd
= open(lock
, O_RDONLY
)) < 0) {
242 pline("Cannot open %s .", lock
);
243 pline("Probably someone removed it.");
246 getlev(fd
, hackpid
, dlevel
);
254 if (!u
.ux
) { /* entering a maze from below? */
255 u
.ux
= xupstair
; /* this will confuse the
259 if (Punished
&& !Levitation
) {
260 pline("With great effort you climb the stairs.");
266 if (inv_weight() + 5 > 0 || Punished
) {
267 pline("You fall down the stairs."); /* %% */
268 losehp(rnd(3), "fall");
270 if (uwep
!= uball
&& rn2(3)) {
271 pline("... and are hit by the iron ball.");
272 losehp(rnd(20), "iron ball");
276 selftouch("Falling, you");
280 struct monst
*mtmp
= m_at(u
.ux
, u
.uy
);
284 } else { /* trapdoor or level_tele */
286 u
.ux
= rnd(COLNO
- 1);
288 } while (levl
[u
.ux
][u
.uy
].typ
!= ROOM
||
291 if (uwep
!= uball
&& !up
/* %% */ && rn2(5)) {
292 pline("The iron ball falls on your head.");
293 losehp(rnd(25), "iron ball");
297 selftouch("Falling, you");
305 if ((mtmp
= m_at(u
.ux
, u
.uy
)) != NULL
)
306 mnexto(mtmp
); /* riv05!a3 */
310 seeobjs(); /* make old cadavers disappear - riv05!a3 */
313 read_engr_at(u
.ux
, u
.uy
);
319 return (1); /* Do nothing, but let other things happen */
325 nomovemsg
= "You finished your prayer.";
337 obj
= getobj("#)", "throw"); /* it is also possible to throw food */
338 /* (or jewels, or iron balls ... ) */
339 if (!obj
|| !getdir(1)) /* ask "in what direction?" */
341 if (obj
->owornmask
& (W_ARMOR
| W_RING
)) {
342 pline("You can't throw something you are wearing.");
349 pline("Your weapon is welded to your hand.");
353 setuwep(splitobj(obj
, 1));
355 setuwep((struct obj
*) 0);
356 } else if (obj
->quan
> 1)
357 (void) splitobj(obj
, 1);
365 pline("%s hits the ceiling, then falls back on top of your head.",
366 Doname(obj
)); /* note: obj->quan == 1 */
367 if (obj
->olet
== POTION_SYM
)
368 potionhit(&youmonst
, obj
);
371 pline("Fortunately, you are wearing a helmet!");
372 losehp(uarmh
? 1 : rnd((int) (obj
->owt
)), "falling object");
376 pline("%s hits the floor.", Doname(obj
));
377 if (obj
->otyp
== EXPENSIVE_CAMERA
) {
378 pline("It is shattered in a thousand pieces!");
379 obfree(obj
, Null(obj
));
380 } else if (obj
->otyp
== EGG
) {
381 pline("\"Splash!\"");
382 obfree(obj
, Null(obj
));
383 } else if (obj
->olet
== POTION_SYM
) {
384 pline("The flask breaks, and you smell a peculiar odor ...");
386 obfree(obj
, Null(obj
));
392 } else if (obj
->otyp
== BOOMERANG
) {
393 mon
= boomhit(u
.dx
, u
.dy
);
394 if (mon
== &youmonst
) { /* the thing was caught */
399 if (obj
->otyp
== PICK_AXE
&& shkcatch(obj
))
402 mon
= bhit(u
.dx
, u
.dy
, (obj
->otyp
== ICE_BOX
) ? 1 :
403 (!Punished
|| obj
!= uball
) ? 8 : !u
.ustuck
? 5 : 1,
405 (void (*)(struct monst
*, struct obj
*)) 0,
406 (int (*)(struct obj
*, struct obj
*)) 0, obj
);
409 /* awake monster if sleeping */
412 if (obj
->olet
== WEAPON_SYM
) {
413 tmp
= -1 + u
.ulevel
+ mon
->data
->ac
+ abon();
414 if (obj
->otyp
< ROCK
) {
416 uwep
->otyp
!= obj
->otyp
+ (BOW
- ARROW
))
421 } else if (obj
->otyp
== BOOMERANG
)
424 if (u
.uswallow
|| tmp
>= rnd(20)) {
425 if (hmon(mon
, obj
, 1) == TRUE
) {
426 /* mon still alive */
428 cutworm(mon
, bhitpos
.x
, bhitpos
.y
, obj
->otyp
);
432 /* weapons thrown disappear sometimes */
433 if (obj
->otyp
< BOOMERANG
&& rn2(3)) {
434 /* check bill; free */
435 obfree(obj
, (struct obj
*) 0);
439 miss(objects
[obj
->otyp
].oc_name
, mon
);
440 } else if (obj
->otyp
== HEAVY_IRON_BALL
) {
441 tmp
= -1 + u
.ulevel
+ mon
->data
->ac
+ abon();
442 if (!Punished
|| obj
!= uball
)
446 if (u
.uswallow
|| tmp
>= rnd(20)) {
447 if (hmon(mon
, obj
, 1) == FALSE
)
448 mon
= 0; /* he died */
450 miss("iron ball", mon
);
451 } else if (obj
->olet
== POTION_SYM
&& u
.ulevel
> rn2(15)) {
455 if (cansee(bhitpos
.x
, bhitpos
.y
))
456 pline("You miss %s.", monnam(mon
));
458 pline("You miss it.");
459 if (obj
->olet
== FOOD_SYM
&& mon
->data
->mlet
== 'd')
460 if (tamedog(mon
, obj
))
462 if (obj
->olet
== GEM_SYM
&& mon
->data
->mlet
== 'u' &&
464 if (obj
->dknown
&& objects
[obj
->otyp
].oc_name_known
) {
465 if (objects
[obj
->otyp
].g_val
> 0) {
469 pline("%s is not interested in your junk.",
472 } else { /* value unknown to @ */
475 if (u
.uluck
> LUCKMAX
) /* dan@ut-ngp */
477 pline("%s graciously accepts your gift.",
486 /* the code following might become part of dropy() */
487 if (obj
->otyp
== CRYSKNIFE
)
488 obj
->otyp
= WORM_TOOTH
;
493 /* prevent him from throwing articles to the exit and escaping */
494 /* subfrombill(obj); */
496 if (Punished
&& obj
== uball
&&
497 (bhitpos
.x
!= u
.ux
|| bhitpos
.y
!= u
.uy
)) {
501 if (u
.utraptype
== TT_PIT
)
502 pline("The ball pulls you out of the pit!");
505 rn2(3) ? LEFT_SIDE
: RIGHT_SIDE
;
506 pline("The ball pulls you out of the bear trap.");
507 pline("Your %s leg is severely damaged.",
508 (side
== LEFT_SIDE
) ? "left" : "right");
509 set_wounded_legs(side
, 500 + rn2(1000));
510 losehp(2, "thrown ball");
517 u
.ux
= uchain
->ox
= bhitpos
.x
- u
.dx
;
518 u
.uy
= uchain
->oy
= bhitpos
.y
- u
.dy
;
522 if (cansee(bhitpos
.x
, bhitpos
.y
))
523 prl(bhitpos
.x
, bhitpos
.y
);
527 /* split obj so that it gets size num */
528 /* remainder is put in the object structure delivered by this call */
530 splitobj(struct obj
*obj
, int num
)
534 *otmp
= *obj
; /* copies whole structure */
535 otmp
->o_id
= flags
.ident
++;
538 obj
->owt
= weight(obj
);
540 otmp
->owt
= weight(otmp
); /* -= obj->owt ? */
543 splitbill(obj
, otmp
);
548 more_experienced(int exp
, int rexp
)
551 u
.urexp
+= 4 * exp
+ rexp
;
554 if (u
.urexp
>= ((pl_character
[0] == 'W') ? 1000 : 2000))
559 set_wounded_legs(long side
, int timex
)
561 if (!Wounded_legs
|| (Wounded_legs
& TIMEOUT
))
562 Wounded_legs
|= side
+ timex
;
564 Wounded_legs
|= side
;
571 if ((Wounded_legs
& BOTH_SIDES
) == BOTH_SIDES
)
572 pline("Your legs feel somewhat better.");
574 pline("Your leg feels somewhat better.");