]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.c
1 /* $NetBSD: hack.c,v 1.4 1997/10/19 16:57:37 christos Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.c,v 1.4 1997/10/19 16:57:37 christos Exp $");
16 * called on movement: 1. when throwing ball+chain far away 2. when
17 * teleporting 3. when walking out of a lit room
28 newsym(u.udisx, u.udisy);
36 for (x
= u
.ux
- 1; x
< u
.ux
+ 2; x
++)
37 for (y
= u
.uy
- 1; y
< u
.uy
+ 2; y
++) {
41 if (!lev
->lit
&& lev
->scrsym
== '.') {
50 * called: in hack.eat.c: seeoff(0) - blind after eating rotten food in
51 * hack.mon.c: seeoff(0) - blinded by a yellow light in hack.mon.c: seeoff(1)
52 * - swallowed in hack.do.c: seeoff(0) - blind after drinking potion in
53 * hack.do.c: seeoff(1) - go up or down the stairs in hack.trap.c:seeoff(1)
54 * - fall through trapdoor
58 int mode
; /* 1 to redo @, 0 to leave them *//* 1 means
59 * misc movement, 0 means blindness */
64 if (u
.udispl
&& mode
) {
66 levl
[u
.udisx
][u
.udisy
].scrsym
= news0(u
.udisx
, u
.udisy
);
74 for (x
= u
.ux
- 1; x
< u
.ux
+ 2; x
++)
75 for (y
= u
.uy
- 1; y
< u
.uy
+ 2; y
++) {
79 if (!lev
->lit
&& lev
->scrsym
== '.')
89 struct monst
*mtmp
= NULL
;
90 struct rm
*tmpr
, *ust
;
91 struct trap
*trap
= NULL
;
92 struct obj
*otmp
= NULL
;
96 if (inv_weight() > 0) {
97 pline("You collapse under your load.");
109 } while (!isok(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
) ||
110 IS_ROCK(levl
[u
.ux
+ u
.dx
][u
.uy
+ u
.dy
].typ
));
112 if (!isok(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
)) {
118 ust
= &levl
[u
.ux
][u
.uy
];
121 if (!u
.uswallow
&& (trap
= t_at(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
)) && trap
->tseen
)
123 if (u
.ustuck
&& !u
.uswallow
&& (u
.ux
+ u
.dx
!= u
.ustuck
->mx
||
124 u
.uy
+ u
.dy
!= u
.ustuck
->my
)) {
125 if (dist(u
.ustuck
->mx
, u
.ustuck
->my
) > 2) {
126 /* perhaps it fled (or was teleported or ... ) */
130 pline("You cannot escape from it!");
132 pline("You cannot escape from %s!",
138 if (u
.uswallow
|| (mtmp
= m_at(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
))) {
144 return; /* we just fainted */
146 /* try to attack; note that it might evade */
147 if (attack(u
.uswallow
? u
.ustuck
: mtmp
))
150 /* not attacking an animal, so we try to move */
152 if (u
.utraptype
== TT_PIT
) {
153 pline("You are still in a pit.");
156 pline("You are caught in a beartrap.");
157 if ((u
.dx
&& u
.dy
) || !rn2(5))
162 tmpr
= &levl
[u
.ux
+ u
.dx
][u
.uy
+ u
.dy
];
163 if (IS_ROCK(tmpr
->typ
) ||
164 (u
.dx
&& u
.dy
&& (tmpr
->typ
== DOOR
|| ust
->typ
== DOOR
))) {
169 while ((otmp
= sobj_at(ENORMOUS_ROCK
, u
.ux
+ u
.dx
, u
.uy
+ u
.dy
)) != NULL
){
170 xchar rx
= u
.ux
+ 2 * u
.dx
, ry
= u
.uy
+ 2 * u
.dy
;
173 if (isok(rx
, ry
) && !IS_ROCK(levl
[rx
][ry
].typ
) &&
174 (levl
[rx
][ry
].typ
!= DOOR
|| !(u
.dx
&& u
.dy
)) &&
175 !sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
177 pline("You hear a monster behind the rock.");
178 pline("Perhaps that's why you cannot move it.");
181 if ((ttmp
= t_at(rx
, ry
)) != NULL
)
182 switch (ttmp
->ttyp
) {
184 pline("You push the rock into a pit!");
187 pline("It completely fills the pit!");
190 pline("You push the rock and suddenly it disappears!");
194 if (levl
[rx
][ry
].typ
== POOL
) {
195 levl
[rx
][ry
].typ
= ROOM
;
198 pline("You push the rock into the water.");
199 pline("Now you can cross the water!");
207 atl(rx
, ry
, otmp
->olet
);
209 newsym(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
212 static long lastmovetime
;
214 * note: this var contains garbage initially
215 * and after a restore
217 if (moves
> lastmovetime
+ 2 || moves
< lastmovetime
)
218 pline("With great effort you move the enormous rock.");
219 lastmovetime
= moves
;
222 pline("You try to move the enormous rock, but in vain.");
224 if ((!invent
|| inv_weight() + 90 <= 0) &&
225 (!u
.dx
|| !u
.dy
|| (IS_ROCK(levl
[u
.ux
][u
.uy
+ u
.dy
].typ
)
226 && IS_ROCK(levl
[u
.ux
+ u
.dx
][u
.uy
].typ
)))) {
227 pline("However, you can squeeze yourself into a small opening.");
233 if (u
.dx
&& u
.dy
&& IS_ROCK(levl
[u
.ux
][u
.uy
+ u
.dy
].typ
) &&
234 IS_ROCK(levl
[u
.ux
+ u
.dx
][u
.uy
].typ
) &&
235 invent
&& inv_weight() + 40 > 0) {
236 pline("You are carrying too much to get through.");
241 DIST(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
, uchain
->ox
, uchain
->oy
) > 2) {
242 if (carried(uball
)) {
243 movobj(uchain
, u
.ux
, u
.uy
);
246 if (DIST(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
, uball
->ox
, uball
->oy
) < 3) {
247 /* leave ball, move chain under/over ball */
248 movobj(uchain
, uball
->ox
, uball
->oy
);
251 if (inv_weight() + (int) uball
->owt
/ 2 > 0) {
252 pline("You cannot %sdrag the heavy iron ball.",
253 invent
? "carry all that and also " : "");
257 movobj(uball
, uchain
->ox
, uchain
->oy
);
258 unpobj(uball
); /* BAH %% */
268 if (tmpr
->typ
== DOOR
||
269 (xupstair
== u
.ux
&& yupstair
== u
.uy
) ||
270 (xdnstair
== u
.ux
&& ydnstair
== u
.uy
))
273 if (tmpr
->typ
== POOL
&& !Levitation
)
274 drown(); /* not necessarily fatal */
288 if (tmpr
->typ
== DOOR
)
289 prl1(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
290 else if (ust
->typ
== DOOR
)
291 nose1(oldx
- u
.dx
, oldy
- u
.dy
);
294 prl1(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
300 prl1(u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
301 if (tmpr
->typ
== DOOR
) {
311 nose1(oldx
- u
.dx
, oldy
- u
.dy
);
320 dotrap(trap
); /* fall into pit, arrow trap, etc. */
323 read_engr_at(u
.ux
, u
.uy
);
331 /* Some dirty programming to get display right */
343 if (!g_at(u
.ux
, u
.uy
) && !o_at(u
.ux
, u
.uy
)) {
344 pline("There is nothing here to pick up.");
348 pline("You cannot reach the floor.");
359 struct obj
*obj
, *obj2
;
364 while ((gold
= g_at(u
.ux
, u
.uy
)) != NULL
) {
365 pline("%ld gold piece%s.", gold
->amount
, plur(gold
->amount
));
366 u
.ugold
+= gold
->amount
;
375 /* check for more than one object */
379 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
380 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
381 if (!Punished
|| obj
!= uchain
)
386 pline("There are several objects here.");
388 for (obj
= fobj
; obj
; obj
= obj2
) {
389 obj2
= obj
->nobj
; /* perhaps obj will be picked up */
390 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
) {
394 /* do not pick up uchain */
395 if (Punished
&& obj
== uchain
)
401 pline("Pick up %s ? [ynaq]", doname(obj
));
402 while (!strchr("ynaq ", (c
= readchar())))
411 if (obj
->otyp
== DEAD_COCKATRICE
&& !uarmg
) {
412 pline("Touching the dead cockatrice is a fatal mistake.");
413 pline("You turn to stone.");
414 killer
= "cockatrice cadaver";
417 if (obj
->otyp
== SCR_SCARE_MONSTER
) {
422 * Note: perhaps the 1st pickup
423 * failed: you cannot carry anymore,
424 * and so we never dropped it - let's
425 * assume that treading on it twice
426 * also destroys the scroll
428 pline("The scroll turns to dust as you pick it up.");
433 wt
= inv_weight() + obj
->owt
;
436 /* see how many we can lift */
437 int savequan
= obj
->quan
;
438 int iw
= inv_weight();
440 for (qq
= 1; qq
< savequan
; qq
++) {
442 if (iw
+ weight(obj
) > 0)
445 obj
->quan
= savequan
;
447 /* we can carry qq of them */
450 pline("You can only carry %s of the %s lying here.",
451 (qq
== 1) ? "one" : "some",
453 (void) splitobj(obj
, qq
);
455 * note: obj2 is set already, so
456 * we'll never encounter the other
457 * half; if it should be otherwise
464 pline("There %s %s here, but %s.",
465 (obj
->quan
== 1) ? "is" : "are",
467 !invent
? "it is too heavy for you to lift"
468 : "you cannot carry anymore");
472 if (inv_cnt() >= 52) {
473 pline("Your knapsack cannot accomodate anymore items.");
477 pline("You have a little trouble lifting");
481 addtobill(obj
); /* sets obj->unpaid if necessary */
483 int pickquan
= obj
->quan
;
486 obj
->dknown
= 1; /* this is done by
487 * prinv(), but addinv()
488 * needs it already for
490 obj
= addinv(obj
); /* might merge it with
492 mergquan
= obj
->quan
;
493 obj
->quan
= pickquan
; /* to fool prinv() */
495 obj
->quan
= mergquan
;
501 /* stop running if we see something interesting */
502 /* turn around a corner if that is the only way we can proceed */
503 /* do not turn left or right twice */
507 int x
, y
, i
, x0
= 0, y0
= 0, m0
= 0, i0
= 9;
508 int corrct
= 0, noturn
= 0;
510 if (Blind
|| flags
.run
== 0)
512 if (flags
.run
== 1 && levl
[u
.ux
][u
.uy
].typ
== ROOM
)
515 if (u
.ux0
== u
.ux
+ u
.dx
&& u
.uy0
== u
.uy
+ u
.dy
)
518 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
519 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++) {
520 if (x
== u
.ux
&& y
== u
.uy
)
524 if ((mtmp
= m_at(x
, y
)) && !mtmp
->mimic
&&
525 (!mtmp
->minvis
|| See_invisible
)) {
526 if (!mtmp
->mtame
|| (x
== u
.ux
+ u
.dx
&& y
== u
.uy
+ u
.dy
))
529 mtmp
= 0; /* invisible M cannot
531 if (x
== u
.ux
- u
.dx
&& y
== u
.uy
- u
.dy
)
533 switch (levl
[x
][y
].scrsym
) {
540 if (x
!= u
.ux
&& y
!= u
.uy
)
544 /* fall into next case */
547 if (flags
.run
== 1 || flags
.run
== 3) {
548 i
= DIST(x
, y
, u
.ux
+ u
.dx
, u
.uy
+ u
.dy
);
551 if (corrct
== 1 && DIST(x
, y
, x0
, y0
) != 1)
564 goto corr
; /* if you must */
565 if (x
== u
.ux
+ u
.dx
&& y
== u
.uy
+ u
.dy
)
568 default: /* e.g. objects or trap or stairs */
579 if (corrct
> 0 && (flags
.run
== 4 || flags
.run
== 5))
582 if (corrct
> 1 && flags
.run
== 2)
584 if ((flags
.run
== 1 || flags
.run
== 3) && !noturn
&& !m0
&& i0
&&
585 (corrct
== 1 || (corrct
== 2 && i0
== 1))) {
586 /* make sure that we do not turn too far */
588 if (u
.dx
== y0
- u
.uy
&& u
.dy
== u
.ux
- x0
)
589 i
= 2; /* straight turn right */
591 i
= -2; /* straight turn left */
592 } else if (u
.dx
&& u
.dy
) {
593 if ((u
.dx
== u
.dy
&& y0
== u
.uy
) ||
594 (u
.dx
!= u
.dy
&& y0
!= u
.uy
))
595 i
= -1; /* half turn left */
597 i
= 1; /* half turn right */
599 if ((x0
- u
.ux
== y0
- u
.uy
&& !u
.dy
) ||
600 (x0
- u
.ux
!= y0
- u
.uy
&& u
.dy
))
601 i
= 1; /* half turn right */
603 i
= -1; /* half turn left */
605 i
+= u
.last_str_turn
;
606 if (i
<= 2 && i
>= -2) {
608 u
.dx
= x0
- u
.ux
, u
.dy
= y0
- u
.uy
;
613 /* something like lookaround, but we are not running */
614 /* react only to monsters that might hit us */
621 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
622 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++) {
623 if (x
== u
.ux
&& y
== u
.uy
)
625 if ((mtmp
= m_at(x
, y
)) && !mtmp
->mimic
&& !mtmp
->mtame
&&
626 !mtmp
->mpeaceful
&& !strchr("Ea", mtmp
->data
->mlet
) &&
627 !mtmp
->mfroz
&& !mtmp
->msleep
&& /* aplvax!jcn */
628 (!mtmp
->minvis
|| See_invisible
))
639 int dx
, dy
, adx
, ady
, sdx
, sdy
, dmax
, d
;
647 if (d
> u
.uhorizon
* u
.uhorizon
)
657 if (dx
== 0 || dy
== 0 || adx
== ady
) {
658 dmax
= (dx
== 0) ? ady
: adx
;
659 for (d
= 1; d
<= dmax
; d
++)
660 if (!rroom(sdx
* d
, sdy
* d
))
663 } else if (ady
> adx
) {
664 for (d
= 1; d
<= ady
; d
++) {
665 if (!rroom(sdx
* ((d
* adx
) / ady
), sdy
* d
) ||
666 !rroom(sdx
* ((d
* adx
- 1) / ady
+ 1), sdy
* d
))
671 for (d
= 1; d
<= adx
; d
++) {
672 if (!rroom(sdx
* d
, sdy
* ((d
* ady
) / adx
)) ||
673 !rroom(sdx
* d
, sdy
* ((d
* ady
- 1) / adx
+ 1)))
684 return (IS_ROOM(levl
[u
.ux
+ x
][u
.uy
+ y
].typ
));
693 if (Blind
|| u
.uswallow
)
697 if (levl
[x
][y
].lit
&& seelx
<= x
&& x
<= seehx
&& seely
<= y
&&
708 return ((a
> 0) ? 1 : (a
== 0) ? 0 : -1);
721 for (y
= u
.uy
- u
.uhorizon
; y
<= u
.uy
+ u
.uhorizon
; y
++)
722 for (x
= u
.ux
- u
.uhorizon
; x
<= u
.ux
+ u
.uhorizon
; x
++) {
739 if (!levl
[u
.ux
][u
.uy
].lit
) {
745 for (seelx
= u
.ux
; levl
[seelx
- 1][u
.uy
].lit
; seelx
--);
746 for (seehx
= u
.ux
; levl
[seehx
+ 1][u
.uy
].lit
; seehx
++);
747 for (seely
= u
.uy
; levl
[u
.ux
][seely
- 1].lit
; seely
--);
748 for (seehy
= u
.uy
; levl
[u
.ux
][seehy
+ 1].lit
; seehy
++);
750 for (y
= seely
; y
<= seehy
; y
++)
751 for (x
= seelx
; x
<= seehx
; x
++) {
754 if (!levl
[u
.ux
][u
.uy
].lit
)
755 seehx
= 0; /* seems necessary elsewhere */
758 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
761 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
764 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++)
767 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++)
780 flags
.mv
= flags
.run
= 0;
792 else if (u
.ustr
< 17)
794 else if (u
.ustr
< 69)
795 return (1); /* up to 18/50 */
796 else if (u
.ustr
< 118)
807 else if (u
.ustr
< 16)
809 else if (u
.ustr
< 18)
811 else if (u
.ustr
== 18)
812 return (2); /* up to 18 */
813 else if (u
.ustr
< 94)
814 return (3); /* up to 18/75 */
815 else if (u
.ustr
< 109)
816 return (4); /* up to 18/90 */
817 else if (u
.ustr
< 118)
818 return (5); /* up to 18/99 */
824 losestr(num
) /* may kill you; cause may be poison or */
825 int num
; /* monster like 'A' */
842 if (u
.uhp
> u
.uhpmax
)
843 u
.uhpmax
= u
.uhp
; /* perhaps n was negative */
846 killer
= knam
; /* the thing that killed you */
864 { /* hit by V or W */
868 pline("Goodbye level %u.", u
.ulevel
--);
881 struct obj
*otmp
= invent
;
882 int wt
= (u
.ugold
+ 500) / 1000;
884 if (Levitation
) /* pugh@cornell */
885 carrcap
= MAX_CARR_CAP
;
887 carrcap
= 5 * (((u
.ustr
> 18) ? 20 : u
.ustr
) + u
.ulevel
);
888 if (carrcap
> MAX_CARR_CAP
)
889 carrcap
= MAX_CARR_CAP
;
890 if (Wounded_legs
& LEFT_SIDE
)
892 if (Wounded_legs
& RIGHT_SIDE
)
899 return (wt
- carrcap
);
905 struct obj
*otmp
= invent
;
917 return (10 * (1L << (u
.ulevel
- 1)));