]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.do.c
1 /* $NetBSD: hack.do.c,v 1.6 2003/04/02 18:36:35 jsm 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.6 2003/04/02 18:36:35 jsm Exp $");
69 /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
78 static int drop
__P((struct obj
*));
83 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 */
136 if (obj
->otyp
== CRYSKNIFE
)
137 obj
->otyp
= WORM_TOOTH
;
148 /* drop several things */
152 return (ggetobj("drop", drop
, 0));
158 if (u
.ux
!= xdnstair
|| u
.uy
!= ydnstair
) {
159 pline("You can't go down here.");
163 pline("You are being held, and cannot go down.");
167 pline("You're floating high above the stairs.");
170 goto_level(dlevel
+ 1, TRUE
);
177 if (u
.ux
!= xupstair
|| u
.uy
!= yupstair
) {
178 pline("You can't go up here.");
182 pline("You are being held, and cannot go up.");
185 if (!Levitation
&& inv_weight() + 5 > 0) {
186 pline("Your load is too heavy to climb the stairs.");
189 goto_level(dlevel
- 1, TRUE
);
194 goto_level(newlevel
, at_stairs
)
199 boolean up
= (newlevel
< dlevel
);
202 done("escaped");/* in fact < 0 is impossible */
203 if (newlevel
> MAXLEVEL
)
204 newlevel
= MAXLEVEL
; /* strange ... */
205 if (newlevel
== dlevel
)
206 return; /* this can happen */
209 fd
= creat(lock
, FMASK
);
212 * This is not quite impossible: e.g., we may have
213 * exceeded our quota. If that is the case then we
214 * cannot leave this level, and cannot save either.
215 * Another possibility is that the directory was not
218 pline("A mysterious force prevents you from going %s.",
224 u
.utrap
= 0; /* needed in level_tele */
225 u
.ustuck
= 0; /* idem */
228 if (u
.uswallow
) /* idem */
229 u
.uswldtim
= u
.uswallow
= 0;
231 u
.ux
= FAR
; /* hack */
232 (void) inshop(); /* probably was a trapdoor */
238 if (maxdlevel
< dlevel
)
242 if (!level_exists
[dlevel
])
245 if ((fd
= open(lock
, O_RDONLY
)) < 0) {
246 pline("Cannot open %s .", lock
);
247 pline("Probably someone removed it.");
250 getlev(fd
, hackpid
, dlevel
);
258 if (!u
.ux
) { /* entering a maze from below? */
259 u
.ux
= xupstair
; /* this will confuse the
263 if (Punished
&& !Levitation
) {
264 pline("With great effort you climb the stairs.");
270 if (inv_weight() + 5 > 0 || Punished
) {
271 pline("You fall down the stairs."); /* %% */
272 losehp(rnd(3), "fall");
274 if (uwep
!= uball
&& rn2(3)) {
275 pline("... and are hit by the iron ball.");
276 losehp(rnd(20), "iron ball");
280 selftouch("Falling, you");
284 struct monst
*mtmp
= m_at(u
.ux
, u
.uy
);
288 } else { /* trapdoor or level_tele */
290 u
.ux
= rnd(COLNO
- 1);
292 } while (levl
[u
.ux
][u
.uy
].typ
!= ROOM
||
295 if (uwep
!= uball
&& !up
/* %% */ && rn2(5)) {
296 pline("The iron ball falls on your head.");
297 losehp(rnd(25), "iron ball");
301 selftouch("Falling, you");
309 if ((mtmp
= m_at(u
.ux
, u
.uy
)) != NULL
)
310 mnexto(mtmp
); /* riv05!a3 */
314 seeobjs(); /* make old cadavers disappear - riv05!a3 */
317 read_engr_at(u
.ux
, u
.uy
);
323 return (1); /* Do nothing, but let other things happen */
329 nomovemsg
= "You finished your prayer.";
341 obj
= getobj("#)", "throw"); /* it is also possible to throw food */
342 /* (or jewels, or iron balls ... ) */
343 if (!obj
|| !getdir(1)) /* ask "in what direction?" */
345 if (obj
->owornmask
& (W_ARMOR
| W_RING
)) {
346 pline("You can't throw something you are wearing.");
353 pline("Your weapon is welded to your hand.");
357 setuwep(splitobj(obj
, 1));
359 setuwep((struct obj
*) 0);
360 } else if (obj
->quan
> 1)
361 (void) splitobj(obj
, 1);
369 pline("%s hits the ceiling, then falls back on top of your head.",
370 Doname(obj
)); /* note: obj->quan == 1 */
371 if (obj
->olet
== POTION_SYM
)
372 potionhit(&youmonst
, obj
);
375 pline("Fortunately, you are wearing a helmet!");
376 losehp(uarmh
? 1 : rnd((int) (obj
->owt
)), "falling object");
380 pline("%s hits the floor.", Doname(obj
));
381 if (obj
->otyp
== EXPENSIVE_CAMERA
) {
382 pline("It is shattered in a thousand pieces!");
383 obfree(obj
, Null(obj
));
384 } else if (obj
->otyp
== EGG
) {
385 pline("\"Splash!\"");
386 obfree(obj
, Null(obj
));
387 } else if (obj
->olet
== POTION_SYM
) {
388 pline("The flask breaks, and you smell a peculiar odor ...");
390 obfree(obj
, Null(obj
));
396 } else if (obj
->otyp
== BOOMERANG
) {
397 mon
= boomhit(u
.dx
, u
.dy
);
398 if (mon
== &youmonst
) { /* the thing was caught */
403 if (obj
->otyp
== PICK_AXE
&& shkcatch(obj
))
406 mon
= bhit(u
.dx
, u
.dy
, (obj
->otyp
== ICE_BOX
) ? 1 :
407 (!Punished
|| obj
!= uball
) ? 8 : !u
.ustuck
? 5 : 1,
409 (void (*) __P((struct monst
*, struct obj
*))) 0,
410 (int (*) __P((struct obj
*, struct obj
*))) 0, obj
);
413 /* awake monster if sleeping */
416 if (obj
->olet
== WEAPON_SYM
) {
417 tmp
= -1 + u
.ulevel
+ mon
->data
->ac
+ abon();
418 if (obj
->otyp
< ROCK
) {
420 uwep
->otyp
!= obj
->otyp
+ (BOW
- ARROW
))
425 } else if (obj
->otyp
== BOOMERANG
)
428 if (u
.uswallow
|| tmp
>= rnd(20)) {
429 if (hmon(mon
, obj
, 1) == TRUE
) {
430 /* mon still alive */
432 cutworm(mon
, bhitpos
.x
, bhitpos
.y
, obj
->otyp
);
436 /* weapons thrown disappear sometimes */
437 if (obj
->otyp
< BOOMERANG
&& rn2(3)) {
438 /* check bill; free */
439 obfree(obj
, (struct obj
*) 0);
443 miss(objects
[obj
->otyp
].oc_name
, mon
);
444 } else if (obj
->otyp
== HEAVY_IRON_BALL
) {
445 tmp
= -1 + u
.ulevel
+ mon
->data
->ac
+ abon();
446 if (!Punished
|| obj
!= uball
)
450 if (u
.uswallow
|| tmp
>= rnd(20)) {
451 if (hmon(mon
, obj
, 1) == FALSE
)
452 mon
= 0; /* he died */
454 miss("iron ball", mon
);
455 } else if (obj
->olet
== POTION_SYM
&& u
.ulevel
> rn2(15)) {
459 if (cansee(bhitpos
.x
, bhitpos
.y
))
460 pline("You miss %s.", monnam(mon
));
462 pline("You miss it.");
463 if (obj
->olet
== FOOD_SYM
&& mon
->data
->mlet
== 'd')
464 if (tamedog(mon
, obj
))
466 if (obj
->olet
== GEM_SYM
&& mon
->data
->mlet
== 'u' &&
468 if (obj
->dknown
&& objects
[obj
->otyp
].oc_name_known
) {
469 if (objects
[obj
->otyp
].g_val
> 0) {
473 pline("%s is not interested in your junk.",
476 } else { /* value unknown to @ */
479 if (u
.uluck
> LUCKMAX
) /* dan@ut-ngp */
481 pline("%s graciously accepts your gift.",
490 /* the code following might become part of dropy() */
491 if (obj
->otyp
== CRYSKNIFE
)
492 obj
->otyp
= WORM_TOOTH
;
497 /* prevent him from throwing articles to the exit and escaping */
498 /* subfrombill(obj); */
500 if (Punished
&& obj
== uball
&&
501 (bhitpos
.x
!= u
.ux
|| bhitpos
.y
!= u
.uy
)) {
505 if (u
.utraptype
== TT_PIT
)
506 pline("The ball pulls you out of the pit!");
509 rn2(3) ? LEFT_SIDE
: RIGHT_SIDE
;
510 pline("The ball pulls you out of the bear trap.");
511 pline("Your %s leg is severely damaged.",
512 (side
== LEFT_SIDE
) ? "left" : "right");
513 set_wounded_legs(side
, 500 + rn2(1000));
514 losehp(2, "thrown ball");
521 u
.ux
= uchain
->ox
= bhitpos
.x
- u
.dx
;
522 u
.uy
= uchain
->oy
= bhitpos
.y
- u
.dy
;
526 if (cansee(bhitpos
.x
, bhitpos
.y
))
527 prl(bhitpos
.x
, bhitpos
.y
);
531 /* split obj so that it gets size num */
532 /* remainder is put in the object structure delivered by this call */
540 *otmp
= *obj
; /* copies whole structure */
541 otmp
->o_id
= flags
.ident
++;
544 obj
->owt
= weight(obj
);
546 otmp
->owt
= weight(otmp
); /* -= obj->owt ? */
549 splitbill(obj
, otmp
);
554 more_experienced(exp
, rexp
)
558 u
.urexp
+= 4 * exp
+ rexp
;
561 if (u
.urexp
>= ((pl_character
[0] == 'W') ? 1000 : 2000))
566 set_wounded_legs(side
, timex
)
570 if (!Wounded_legs
|| (Wounded_legs
& TIMEOUT
))
571 Wounded_legs
|= side
+ timex
;
573 Wounded_legs
|= side
;
580 if ((Wounded_legs
& BOTH_SIDES
) == BOTH_SIDES
)
581 pline("Your legs feel somewhat better.");
583 pline("Your leg feels somewhat better.");