]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.c
1 /* $NetBSD: hack.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.c,v 1.6 2003/04/02 18:36:35 jsm Exp $");
73 * called on movement: 1. when throwing ball+chain far away 2. when
74 * teleporting 3. when walking out of a lit room
85 newsym(u.udisx, u.udisy);
93 for (x
= u
.ux
- 1; x
< u
.ux
+ 2; x
++)
94 for (y
= u
.uy
- 1; y
< u
.uy
+ 2; y
++) {
98 if (!lev
->lit
&& lev
->scrsym
== '.') {
107 * called: in hack.eat.c: seeoff(0) - blind after eating rotten food in
108 * hack.mon.c: seeoff(0) - blinded by a yellow light in hack.mon.c: seeoff(1)
109 * - swallowed in hack.do.c: seeoff(0) - blind after drinking potion in
110 * hack.do.c: seeoff(1) - go up or down the stairs in hack.trap.c:seeoff(1)
111 * - fall through trapdoor
115 int mode
; /* 1 to redo @, 0 to leave them *//* 1 means
116 * misc movement, 0 means blindness */
121 if (u
.udispl
&& mode
) {
123 levl
[u
.udisx
][u
.udisy
].scrsym
= news0(u
.udisx
, u
.udisy
);
131 for (x
= u
.ux
- 1; x
< u
.ux
+ 2; x
++)
132 for (y
= u
.uy
- 1; y
< u
.uy
+ 2; y
++) {
136 if (!lev
->lit
&& lev
->scrsym
== '.')
146 struct monst
*mtmp
= NULL
;
147 struct rm
*tmpr
, *ust
;
148 struct trap
*trap
= NULL
;
149 struct obj
*otmp
= NULL
;
153 if (inv_weight() > 0) {
154 pline("You collapse under your load.");
166 } while (!isok(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
) ||
167 IS_ROCK(levl
[u
.ux
+ u
.dx
][u
.uy
+ u
.dy
].typ
));
169 if (!isok(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
)) {
175 ust
= &levl
[u
.ux
][u
.uy
];
178 if (!u
.uswallow
&& (trap
= t_at(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
)) && trap
->tseen
)
180 if (u
.ustuck
&& !u
.uswallow
&& (u
.ux
+ u
.dx
!= u
.ustuck
->mx
||
181 u
.uy
+ u
.dy
!= u
.ustuck
->my
)) {
182 if (dist(u
.ustuck
->mx
, u
.ustuck
->my
) > 2) {
183 /* perhaps it fled (or was teleported or ... ) */
187 pline("You cannot escape from it!");
189 pline("You cannot escape from %s!",
195 if (u
.uswallow
|| (mtmp
= m_at(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
))) {
201 return; /* we just fainted */
203 /* try to attack; note that it might evade */
204 if (attack(u
.uswallow
? u
.ustuck
: mtmp
))
207 /* not attacking an animal, so we try to move */
209 if (u
.utraptype
== TT_PIT
) {
210 pline("You are still in a pit.");
213 pline("You are caught in a beartrap.");
214 if ((u
.dx
&& u
.dy
) || !rn2(5))
219 tmpr
= &levl
[u
.ux
+ u
.dx
][u
.uy
+ u
.dy
];
220 if (IS_ROCK(tmpr
->typ
) ||
221 (u
.dx
&& u
.dy
&& (tmpr
->typ
== DOOR
|| ust
->typ
== DOOR
))) {
226 while ((otmp
= sobj_at(ENORMOUS_ROCK
, u
.ux
+ u
.dx
, u
.uy
+ u
.dy
)) != NULL
){
227 xchar rx
= u
.ux
+ 2 * u
.dx
, ry
= u
.uy
+ 2 * u
.dy
;
230 if (isok(rx
, ry
) && !IS_ROCK(levl
[rx
][ry
].typ
) &&
231 (levl
[rx
][ry
].typ
!= DOOR
|| !(u
.dx
&& u
.dy
)) &&
232 !sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
234 pline("You hear a monster behind the rock.");
235 pline("Perhaps that's why you cannot move it.");
238 if ((ttmp
= t_at(rx
, ry
)) != NULL
)
239 switch (ttmp
->ttyp
) {
241 pline("You push the rock into a pit!");
244 pline("It completely fills the pit!");
247 pline("You push the rock and suddenly it disappears!");
251 if (levl
[rx
][ry
].typ
== POOL
) {
252 levl
[rx
][ry
].typ
= ROOM
;
255 pline("You push the rock into the water.");
256 pline("Now you can cross the water!");
264 atl(rx
, ry
, otmp
->olet
);
266 newsym(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
269 static long lastmovetime
;
271 * note: this var contains garbage initially
272 * and after a restore
274 if (moves
> lastmovetime
+ 2 || moves
< lastmovetime
)
275 pline("With great effort you move the enormous rock.");
276 lastmovetime
= moves
;
279 pline("You try to move the enormous rock, but in vain.");
281 if ((!invent
|| inv_weight() + 90 <= 0) &&
282 (!u
.dx
|| !u
.dy
|| (IS_ROCK(levl
[u
.ux
][u
.uy
+ u
.dy
].typ
)
283 && IS_ROCK(levl
[u
.ux
+ u
.dx
][u
.uy
].typ
)))) {
284 pline("However, you can squeeze yourself into a small opening.");
290 if (u
.dx
&& u
.dy
&& IS_ROCK(levl
[u
.ux
][u
.uy
+ u
.dy
].typ
) &&
291 IS_ROCK(levl
[u
.ux
+ u
.dx
][u
.uy
].typ
) &&
292 invent
&& inv_weight() + 40 > 0) {
293 pline("You are carrying too much to get through.");
298 DIST(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
, uchain
->ox
, uchain
->oy
) > 2) {
299 if (carried(uball
)) {
300 movobj(uchain
, u
.ux
, u
.uy
);
303 if (DIST(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
, uball
->ox
, uball
->oy
) < 3) {
304 /* leave ball, move chain under/over ball */
305 movobj(uchain
, uball
->ox
, uball
->oy
);
308 if (inv_weight() + (int) uball
->owt
/ 2 > 0) {
309 pline("You cannot %sdrag the heavy iron ball.",
310 invent
? "carry all that and also " : "");
314 movobj(uball
, uchain
->ox
, uchain
->oy
);
315 unpobj(uball
); /* BAH %% */
325 if (tmpr
->typ
== DOOR
||
326 (xupstair
== u
.ux
&& yupstair
== u
.uy
) ||
327 (xdnstair
== u
.ux
&& ydnstair
== u
.uy
))
330 if (tmpr
->typ
== POOL
&& !Levitation
)
331 drown(); /* not necessarily fatal */
345 if (tmpr
->typ
== DOOR
)
346 prl1(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
347 else if (ust
->typ
== DOOR
)
348 nose1(oldx
- u
.dx
, oldy
- u
.dy
);
351 prl1(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
357 prl1(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
358 if (tmpr
->typ
== DOOR
) {
368 nose1(oldx
- u
.dx
, oldy
- u
.dy
);
377 dotrap(trap
); /* fall into pit, arrow trap, etc. */
380 read_engr_at(u
.ux
, u
.uy
);
388 /* Some dirty programming to get display right */
400 if (!g_at(u
.ux
, u
.uy
) && !o_at(u
.ux
, u
.uy
)) {
401 pline("There is nothing here to pick up.");
405 pline("You cannot reach the floor.");
416 struct obj
*obj
, *obj2
;
421 while ((gold
= g_at(u
.ux
, u
.uy
)) != NULL
) {
422 pline("%ld gold piece%s.", gold
->amount
, plur(gold
->amount
));
423 u
.ugold
+= gold
->amount
;
432 /* check for more than one object */
436 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
437 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
438 if (!Punished
|| obj
!= uchain
)
443 pline("There are several objects here.");
445 for (obj
= fobj
; obj
; obj
= obj2
) {
446 obj2
= obj
->nobj
; /* perhaps obj will be picked up */
447 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
) {
451 /* do not pick up uchain */
452 if (Punished
&& obj
== uchain
)
458 pline("Pick up %s ? [ynaq]", doname(obj
));
459 while (!strchr("ynaq ", (c
= readchar())))
468 if (obj
->otyp
== DEAD_COCKATRICE
&& !uarmg
) {
469 pline("Touching the dead cockatrice is a fatal mistake.");
470 pline("You turn to stone.");
471 killer
= "cockatrice cadaver";
474 if (obj
->otyp
== SCR_SCARE_MONSTER
) {
479 * Note: perhaps the 1st pickup
480 * failed: you cannot carry anymore,
481 * and so we never dropped it - let's
482 * assume that treading on it twice
483 * also destroys the scroll
485 pline("The scroll turns to dust as you pick it up.");
490 wt
= inv_weight() + obj
->owt
;
493 /* see how many we can lift */
494 int savequan
= obj
->quan
;
495 int iw
= inv_weight();
497 for (qq
= 1; qq
< savequan
; qq
++) {
499 if (iw
+ weight(obj
) > 0)
502 obj
->quan
= savequan
;
504 /* we can carry qq of them */
507 pline("You can only carry %s of the %s lying here.",
508 (qq
== 1) ? "one" : "some",
510 (void) splitobj(obj
, qq
);
512 * note: obj2 is set already, so
513 * we'll never encounter the other
514 * half; if it should be otherwise
521 pline("There %s %s here, but %s.",
522 (obj
->quan
== 1) ? "is" : "are",
524 !invent
? "it is too heavy for you to lift"
525 : "you cannot carry anymore");
529 if (inv_cnt() >= 52) {
530 pline("Your knapsack cannot accomodate anymore items.");
534 pline("You have a little trouble lifting");
538 addtobill(obj
); /* sets obj->unpaid if necessary */
540 int pickquan
= obj
->quan
;
543 obj
->dknown
= 1; /* this is done by
544 * prinv(), but addinv()
545 * needs it already for
547 obj
= addinv(obj
); /* might merge it with
549 mergquan
= obj
->quan
;
550 obj
->quan
= pickquan
; /* to fool prinv() */
552 obj
->quan
= mergquan
;
558 /* stop running if we see something interesting */
559 /* turn around a corner if that is the only way we can proceed */
560 /* do not turn left or right twice */
564 int x
, y
, i
, x0
= 0, y0
= 0, m0
= 0, i0
= 9;
565 int corrct
= 0, noturn
= 0;
567 if (Blind
|| flags
.run
== 0)
569 if (flags
.run
== 1 && levl
[u
.ux
][u
.uy
].typ
== ROOM
)
572 if (u
.ux0
== u
.ux
+ u
.dx
&& u
.uy0
== u
.uy
+ u
.dy
)
575 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
576 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++) {
577 if (x
== u
.ux
&& y
== u
.uy
)
581 if ((mtmp
= m_at(x
, y
)) && !mtmp
->mimic
&&
582 (!mtmp
->minvis
|| See_invisible
)) {
583 if (!mtmp
->mtame
|| (x
== u
.ux
+ u
.dx
&& y
== u
.uy
+ u
.dy
))
586 mtmp
= 0; /* invisible M cannot
588 if (x
== u
.ux
- u
.dx
&& y
== u
.uy
- u
.dy
)
590 switch (levl
[x
][y
].scrsym
) {
597 if (x
!= u
.ux
&& y
!= u
.uy
)
601 /* fall into next case */
604 if (flags
.run
== 1 || flags
.run
== 3) {
605 i
= DIST(x
, y
, u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
608 if (corrct
== 1 && DIST(x
, y
, x0
, y0
) != 1)
621 goto corr
; /* if you must */
622 if (x
== u
.ux
+ u
.dx
&& y
== u
.uy
+ u
.dy
)
625 default: /* e.g. objects or trap or stairs */
636 if (corrct
> 0 && (flags
.run
== 4 || flags
.run
== 5))
639 if (corrct
> 1 && flags
.run
== 2)
641 if ((flags
.run
== 1 || flags
.run
== 3) && !noturn
&& !m0
&& i0
&&
642 (corrct
== 1 || (corrct
== 2 && i0
== 1))) {
643 /* make sure that we do not turn too far */
645 if (u
.dx
== y0
- u
.uy
&& u
.dy
== u
.ux
- x0
)
646 i
= 2; /* straight turn right */
648 i
= -2; /* straight turn left */
649 } else if (u
.dx
&& u
.dy
) {
650 if ((u
.dx
== u
.dy
&& y0
== u
.uy
) ||
651 (u
.dx
!= u
.dy
&& y0
!= u
.uy
))
652 i
= -1; /* half turn left */
654 i
= 1; /* half turn right */
656 if ((x0
- u
.ux
== y0
- u
.uy
&& !u
.dy
) ||
657 (x0
- u
.ux
!= y0
- u
.uy
&& u
.dy
))
658 i
= 1; /* half turn right */
660 i
= -1; /* half turn left */
662 i
+= u
.last_str_turn
;
663 if (i
<= 2 && i
>= -2) {
665 u
.dx
= x0
- u
.ux
, u
.dy
= y0
- u
.uy
;
670 /* something like lookaround, but we are not running */
671 /* react only to monsters that might hit us */
678 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
679 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++) {
680 if (x
== u
.ux
&& y
== u
.uy
)
682 if ((mtmp
= m_at(x
, y
)) && !mtmp
->mimic
&& !mtmp
->mtame
&&
683 !mtmp
->mpeaceful
&& !strchr("Ea", mtmp
->data
->mlet
) &&
684 !mtmp
->mfroz
&& !mtmp
->msleep
&& /* aplvax!jcn */
685 (!mtmp
->minvis
|| See_invisible
))
696 int dx
, dy
, adx
, ady
, sdx
, sdy
, dmax
, d
;
704 if (d
> u
.uhorizon
* u
.uhorizon
)
714 if (dx
== 0 || dy
== 0 || adx
== ady
) {
715 dmax
= (dx
== 0) ? ady
: adx
;
716 for (d
= 1; d
<= dmax
; d
++)
717 if (!rroom(sdx
* d
, sdy
* d
))
720 } else if (ady
> adx
) {
721 for (d
= 1; d
<= ady
; d
++) {
722 if (!rroom(sdx
* ((d
* adx
) / ady
), sdy
* d
) ||
723 !rroom(sdx
* ((d
* adx
- 1) / ady
+ 1), sdy
* d
))
728 for (d
= 1; d
<= adx
; d
++) {
729 if (!rroom(sdx
* d
, sdy
* ((d
* ady
) / adx
)) ||
730 !rroom(sdx
* d
, sdy
* ((d
* ady
- 1) / adx
+ 1)))
741 return (IS_ROOM(levl
[u
.ux
+ x
][u
.uy
+ y
].typ
));
750 if (Blind
|| u
.uswallow
)
754 if (levl
[x
][y
].lit
&& seelx
<= x
&& x
<= seehx
&& seely
<= y
&&
765 return ((a
> 0) ? 1 : (a
== 0) ? 0 : -1);
778 for (y
= u
.uy
- u
.uhorizon
; y
<= u
.uy
+ u
.uhorizon
; y
++)
779 for (x
= u
.ux
- u
.uhorizon
; x
<= u
.ux
+ u
.uhorizon
; x
++) {
796 if (!levl
[u
.ux
][u
.uy
].lit
) {
802 for (seelx
= u
.ux
; levl
[seelx
- 1][u
.uy
].lit
; seelx
--);
803 for (seehx
= u
.ux
; levl
[seehx
+ 1][u
.uy
].lit
; seehx
++);
804 for (seely
= u
.uy
; levl
[u
.ux
][seely
- 1].lit
; seely
--);
805 for (seehy
= u
.uy
; levl
[u
.ux
][seehy
+ 1].lit
; seehy
++);
807 for (y
= seely
; y
<= seehy
; y
++)
808 for (x
= seelx
; x
<= seehx
; x
++) {
811 if (!levl
[u
.ux
][u
.uy
].lit
)
812 seehx
= 0; /* seems necessary elsewhere */
815 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
818 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
821 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++)
824 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++)
837 flags
.mv
= flags
.run
= 0;
849 else if (u
.ustr
< 17)
851 else if (u
.ustr
< 69)
852 return (1); /* up to 18/50 */
853 else if (u
.ustr
< 118)
864 else if (u
.ustr
< 16)
866 else if (u
.ustr
< 18)
868 else if (u
.ustr
== 18)
869 return (2); /* up to 18 */
870 else if (u
.ustr
< 94)
871 return (3); /* up to 18/75 */
872 else if (u
.ustr
< 109)
873 return (4); /* up to 18/90 */
874 else if (u
.ustr
< 118)
875 return (5); /* up to 18/99 */
881 losestr(num
) /* may kill you; cause may be poison or */
882 int num
; /* monster like 'A' */
899 if (u
.uhp
> u
.uhpmax
)
900 u
.uhpmax
= u
.uhp
; /* perhaps n was negative */
903 killer
= knam
; /* the thing that killed you */
921 { /* hit by V or W */
925 pline("Goodbye level %u.", u
.ulevel
--);
938 struct obj
*otmp
= invent
;
939 int wt
= (u
.ugold
+ 500) / 1000;
941 if (Levitation
) /* pugh@cornell */
942 carrcap
= MAX_CARR_CAP
;
944 carrcap
= 5 * (((u
.ustr
> 18) ? 20 : u
.ustr
) + u
.ulevel
);
945 if (carrcap
> MAX_CARR_CAP
)
946 carrcap
= MAX_CARR_CAP
;
947 if (Wounded_legs
& LEFT_SIDE
)
949 if (Wounded_legs
& RIGHT_SIDE
)
956 return (wt
- carrcap
);
962 struct obj
*otmp
= invent
;
974 return (10 * (1L << (u
.ulevel
- 1)));