]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.c,v 1.3 1995/03/23 08:29:50 cgd Exp $";
13 extern char *nomovemsg
;
14 extern char *exclam();
15 extern struct obj
*addinv();
16 extern boolean
hmon();
18 /* called on movement:
19 1. when throwing ball+chain far away
21 3. when walking out of a lit room
25 register struct rm
*lev
;
30 newsym(u.udisx, u.udisy);
38 for(x
= u
.ux
-1; x
< u
.ux
+2; x
++)
39 for(y
= u
.uy
-1; y
< u
.uy
+2; y
++) {
40 if(!isok(x
, y
)) continue;
42 if(!lev
->lit
&& lev
->scrsym
== '.') {
51 in hack.eat.c: seeoff(0) - blind after eating rotten food
52 in hack.mon.c: seeoff(0) - blinded by a yellow light
53 in hack.mon.c: seeoff(1) - swallowed
54 in hack.do.c: seeoff(0) - blind after drinking potion
55 in hack.do.c: seeoff(1) - go up or down the stairs
56 in hack.trap.c:seeoff(1) - fall through trapdoor
58 seeoff(mode
) /* 1 to redo @, 0 to leave them */
59 { /* 1 means misc movement, 0 means blindness */
61 register struct rm
*lev
;
65 levl
[u
.udisx
][u
.udisy
].scrsym
= news0(u
.udisx
,u
.udisy
);
73 for(x
= u
.ux
-1; x
< u
.ux
+2; x
++)
74 for(y
= u
.uy
-1; y
< u
.uy
+2; y
++) {
75 if(!isok(x
, y
)) continue;
77 if(!lev
->lit
&& lev
->scrsym
== '.')
86 register struct monst
*mtmp
;
87 register struct rm
*tmpr
,*ust
;
89 register struct obj
*otmp
;
94 pline("You collapse under your load.");
106 } while(!isok(u
.ux
+u
.dx
, u
.uy
+u
.dy
) ||
107 IS_ROCK(levl
[u
.ux
+u
.dx
][u
.uy
+u
.dy
].typ
));
109 if(!isok(u
.ux
+u
.dx
, u
.uy
+u
.dy
)){
115 ust
= &levl
[u
.ux
][u
.uy
];
118 if(!u
.uswallow
&& (trap
= t_at(u
.ux
+u
.dx
, u
.uy
+u
.dy
)) && trap
->tseen
)
120 if(u
.ustuck
&& !u
.uswallow
&& (u
.ux
+u
.dx
!= u
.ustuck
->mx
||
121 u
.uy
+u
.dy
!= u
.ustuck
->my
)) {
122 if(dist(u
.ustuck
->mx
, u
.ustuck
->my
) > 2){
123 /* perhaps it fled (or was teleported or ... ) */
126 if(Blind
) pline("You cannot escape from it!");
127 else pline("You cannot escape from %s!",
133 if(u
.uswallow
|| (mtmp
= m_at(u
.ux
+u
.dx
,u
.uy
+u
.dy
))) {
138 if(multi
< 0) return; /* we just fainted */
140 /* try to attack; note that it might evade */
141 if(attack(u
.uswallow
? u
.ustuck
: mtmp
))
144 /* not attacking an animal, so we try to move */
146 if(u
.utraptype
== TT_PIT
) {
147 pline("You are still in a pit.");
150 pline("You are caught in a beartrap.");
151 if((u
.dx
&& u
.dy
) || !rn2(5)) u
.utrap
--;
155 tmpr
= &levl
[u
.ux
+u
.dx
][u
.uy
+u
.dy
];
156 if(IS_ROCK(tmpr
->typ
) ||
157 (u
.dx
&& u
.dy
&& (tmpr
->typ
== DOOR
|| ust
->typ
== DOOR
))){
162 while(otmp
= sobj_at(ENORMOUS_ROCK
, u
.ux
+u
.dx
, u
.uy
+u
.dy
)) {
163 register xchar rx
= u
.ux
+2*u
.dx
, ry
= u
.uy
+2*u
.dy
;
164 register struct trap
*ttmp
;
166 if(isok(rx
,ry
) && !IS_ROCK(levl
[rx
][ry
].typ
) &&
167 (levl
[rx
][ry
].typ
!= DOOR
|| !(u
.dx
&& u
.dy
)) &&
168 !sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
170 pline("You hear a monster behind the rock.");
171 pline("Perhaps that's why you cannot move it.");
174 if(ttmp
= t_at(rx
,ry
))
177 pline("You push the rock into a pit!");
180 pline("It completely fills the pit!");
183 pline("You push the rock and suddenly it disappears!");
187 if(levl
[rx
][ry
].typ
== POOL
) {
188 levl
[rx
][ry
].typ
= ROOM
;
191 pline("You push the rock into the water.");
192 pline("Now you can cross the water!");
199 if(cansee(rx
,ry
)) atl(rx
,ry
,otmp
->olet
);
200 if(Invisible
) newsym(u
.ux
+u
.dx
, u
.uy
+u
.dy
);
202 { static long lastmovetime
;
203 /* note: this var contains garbage initially and
205 if(moves
> lastmovetime
+2 || moves
< lastmovetime
)
206 pline("With great effort you move the enormous rock.");
207 lastmovetime
= moves
;
210 pline("You try to move the enormous rock, but in vain.");
212 if((!invent
|| inv_weight()+90 <= 0) &&
213 (!u
.dx
|| !u
.dy
|| (IS_ROCK(levl
[u
.ux
][u
.uy
+u
.dy
].typ
)
214 && IS_ROCK(levl
[u
.ux
+u
.dx
][u
.uy
].typ
)))){
215 pline("However, you can squeeze yourself into a small opening.");
221 if(u
.dx
&& u
.dy
&& IS_ROCK(levl
[u
.ux
][u
.uy
+u
.dy
].typ
) &&
222 IS_ROCK(levl
[u
.ux
+u
.dx
][u
.uy
].typ
) &&
223 invent
&& inv_weight()+40 > 0) {
224 pline("You are carrying too much to get through.");
229 DIST(u
.ux
+u
.dx
, u
.uy
+u
.dy
, uchain
->ox
, uchain
->oy
) > 2){
231 movobj(uchain
, u
.ux
, u
.uy
);
235 if(DIST(u
.ux
+u
.dx
, u
.uy
+u
.dy
, uball
->ox
, uball
->oy
) < 3){
236 /* leave ball, move chain under/over ball */
237 movobj(uchain
, uball
->ox
, uball
->oy
);
241 if(inv_weight() + (int) uball
->owt
/2 > 0) {
242 pline("You cannot %sdrag the heavy iron ball.",
243 invent
? "carry all that and also " : "");
248 movobj(uball
, uchain
->ox
, uchain
->oy
);
249 unpobj(uball
); /* BAH %% */
259 if(tmpr
->typ
== DOOR
||
260 (xupstair
== u
.ux
&& yupstair
== u
.uy
) ||
261 (xdnstair
== u
.ux
&& ydnstair
== u
.uy
))
265 if(tmpr
->typ
== POOL
&& !Levitation
)
266 drown(); /* not necessarily fatal */
280 if(tmpr
->typ
== DOOR
)
281 prl1(u
.ux
+u
.dx
,u
.uy
+u
.dy
);
282 else if(ust
->typ
== DOOR
)
283 nose1(oldx
-u
.dx
,oldy
-u
.dy
);
286 prl1(u
.ux
+u
.dx
,u
.uy
+u
.dy
);
289 if(tmpr
->lit
) setsee();
291 prl1(u
.ux
+u
.dx
,u
.uy
+u
.dy
);
292 if(tmpr
->typ
== DOOR
) {
302 nose1(oldx
-u
.dx
,oldy
-u
.dy
);
308 if(!flags
.nopick
) pickup(1);
309 if(trap
) dotrap(trap
); /* fall into pit, arrow trap, etc. */
311 if(!Blind
) read_engr_at(u
.ux
,u
.uy
);
315 register struct obj
*obj
;
318 /* Some dirty programming to get display right */
328 if(!g_at(u
.ux
,u
.uy
) && !o_at(u
.ux
,u
.uy
)) {
329 pline("There is nothing here to pick up.");
333 pline("You cannot reach the floor.");
342 register struct gold
*gold
;
343 register struct obj
*obj
, *obj2
;
346 if(Levitation
) return;
347 while(gold
= g_at(u
.ux
,u
.uy
)) {
348 pline("%ld gold piece%s.", gold
->amount
, plur(gold
->amount
));
349 u
.ugold
+= gold
->amount
;
352 if(flags
.run
) nomul(0);
353 if(Invisible
) newsym(u
.ux
,u
.uy
);
356 /* check for more than one object */
360 for(obj
= fobj
; obj
; obj
= obj
->nobj
)
361 if(obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
362 if(!Punished
|| obj
!= uchain
)
367 pline("There are several objects here.");
370 for(obj
= fobj
; obj
; obj
= obj2
) {
371 obj2
= obj
->nobj
; /* perhaps obj will be picked up */
372 if(obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
) {
373 if(flags
.run
) nomul(0);
375 /* do not pick up uchain */
376 if(Punished
&& obj
== uchain
)
382 pline("Pick up %s ? [ynaq]", doname(obj
));
383 while(!index("ynaq ", (c
= readchar())))
386 if(c
== 'n') continue;
387 if(c
== 'a') all
= 1;
390 if(obj
->otyp
== DEAD_COCKATRICE
&& !uarmg
){
391 pline("Touching the dead cockatrice is a fatal mistake.");
392 pline("You turn to stone.");
393 killer
= "cockatrice cadaver";
397 if(obj
->otyp
== SCR_SCARE_MONSTER
){
398 if(!obj
->spe
) obj
->spe
= 1;
400 /* Note: perhaps the 1st pickup failed: you cannot
401 carry anymore, and so we never dropped it -
402 let's assume that treading on it twice also
403 destroys the scroll */
404 pline("The scroll turns to dust as you pick it up.");
410 wt
= inv_weight() + obj
->owt
;
413 /* see how many we can lift */
414 extern struct obj
*splitobj();
415 int savequan
= obj
->quan
;
416 int iw
= inv_weight();
418 for(qq
= 1; qq
< savequan
; qq
++){
420 if(iw
+ weight(obj
) > 0)
423 obj
->quan
= savequan
;
425 /* we can carry qq of them */
426 if(!qq
) goto too_heavy
;
427 pline("You can only carry %s of the %s lying here.",
428 (qq
== 1) ? "one" : "some",
430 (void) splitobj(obj
, qq
);
431 /* note: obj2 is set already, so we'll never
432 * encounter the other half; if it should be
433 * otherwise then write
434 * obj2 = splitobj(obj,qq);
439 pline("There %s %s here, but %s.",
440 (obj
->quan
== 1) ? "is" : "are",
442 !invent
? "it is too heavy for you to lift"
443 : "you cannot carry anymore");
447 if(inv_cnt() >= 52) {
448 pline("Your knapsack cannot accomodate anymore items.");
451 if(wt
> -5) pline("You have a little trouble lifting");
453 if(Invisible
) newsym(u
.ux
,u
.uy
);
454 addtobill(obj
); /* sets obj->unpaid if necessary */
455 { int pickquan
= obj
->quan
;
457 if(!Blind
) obj
->dknown
= 1; /* this is done by prinv(),
458 but addinv() needs it already for merging */
459 obj
= addinv(obj
); /* might merge it with other objects */
460 mergquan
= obj
->quan
;
461 obj
->quan
= pickquan
; /* to fool prinv() */
463 obj
->quan
= mergquan
;
469 /* stop running if we see something interesting */
470 /* turn around a corner if that is the only way we can proceed */
471 /* do not turn left or right twice */
473 register x
,y
,i
,x0
,y0
,m0
,i0
= 9;
474 register int corrct
= 0, noturn
= 0;
475 register struct monst
*mtmp
;
477 /* suppress "used before set" message */
480 if(Blind
|| flags
.run
== 0) return;
481 if(flags
.run
== 1 && levl
[u
.ux
][u
.uy
].typ
== ROOM
) return;
483 if(u
.ux0
== u
.ux
+u
.dx
&& u
.uy0
== u
.uy
+u
.dy
) goto stop
;
485 for(x
= u
.ux
-1; x
<= u
.ux
+1; x
++) for(y
= u
.uy
-1; y
<= u
.uy
+1; y
++){
486 if(x
== u
.ux
&& y
== u
.uy
) continue;
487 if(!levl
[x
][y
].typ
) continue;
488 if((mtmp
= m_at(x
,y
)) && !mtmp
->mimic
&&
489 (!mtmp
->minvis
|| See_invisible
)){
490 if(!mtmp
->mtame
|| (x
== u
.ux
+u
.dx
&& y
== u
.uy
+u
.dy
))
492 } else mtmp
= 0; /* invisible M cannot influence us */
493 if(x
== u
.ux
-u
.dx
&& y
== u
.uy
-u
.dy
) continue;
494 switch(levl
[x
][y
].scrsym
){
501 if(x
!= u
.ux
&& y
!= u
.uy
) break;
502 if(flags
.run
!= 1) goto stop
;
503 /* fall into next case */
506 if(flags
.run
== 1 || flags
.run
== 3) {
507 i
= DIST(x
,y
,u
.ux
+u
.dx
,u
.uy
+u
.dy
);
509 if(corrct
== 1 && DIST(x
,y
,x0
,y0
) != 1)
521 if(flags
.run
== 1) goto corr
; /* if you must */
522 if(x
== u
.ux
+u
.dx
&& y
== u
.uy
+u
.dy
) goto stop
;
524 default: /* e.g. objects or trap or stairs */
525 if(flags
.run
== 1) goto corr
;
526 if(mtmp
) break; /* d */
533 if(corrct
> 0 && (flags
.run
== 4 || flags
.run
== 5)) goto stop
;
535 if(corrct
> 1 && flags
.run
== 2) goto stop
;
536 if((flags
.run
== 1 || flags
.run
== 3) && !noturn
&& !m0
&& i0
&&
537 (corrct
== 1 || (corrct
== 2 && i0
== 1))) {
538 /* make sure that we do not turn too far */
540 if(u
.dx
== y0
-u
.uy
&& u
.dy
== u
.ux
-x0
)
541 i
= 2; /* straight turn right */
543 i
= -2; /* straight turn left */
544 } else if(u
.dx
&& u
.dy
) {
545 if((u
.dx
== u
.dy
&& y0
== u
.uy
) ||
546 (u
.dx
!= u
.dy
&& y0
!= u
.uy
))
547 i
= -1; /* half turn left */
549 i
= 1; /* half turn right */
551 if((x0
-u
.ux
== y0
-u
.uy
&& !u
.dy
) ||
552 (x0
-u
.ux
!= y0
-u
.uy
&& u
.dy
))
553 i
= 1; /* half turn right */
555 i
= -1; /* half turn left */
557 i
+= u
.last_str_turn
;
558 if(i
<= 2 && i
>= -2) {
560 u
.dx
= x0
-u
.ux
, u
.dy
= y0
-u
.uy
;
565 /* something like lookaround, but we are not running */
566 /* react only to monsters that might hit us */
569 register struct monst
*mtmp
;
571 for(x
= u
.ux
-1; x
<= u
.ux
+1; x
++) for(y
= u
.uy
-1; y
<= u
.uy
+1; y
++){
572 if(x
== u
.ux
&& y
== u
.uy
) continue;
573 if((mtmp
= m_at(x
,y
)) && !mtmp
->mimic
&& !mtmp
->mtame
&&
574 !mtmp
->mpeaceful
&& !index("Ea", mtmp
->data
->mlet
) &&
575 !mtmp
->mfroz
&& !mtmp
->msleep
&& /* aplvax!jcn */
576 (!mtmp
->minvis
|| See_invisible
))
583 cansee(x
,y
) xchar x
,y
; {
584 register int dx
,dy
,adx
,ady
,sdx
,sdy
,dmax
,d
;
586 if(!isok(x
,y
)) return(0);
589 if(d
> u
.uhorizon
*u
.uhorizon
) return(0);
592 dx
= x
- u
.ux
; adx
= abs(dx
); sdx
= sgn(dx
);
593 dy
= y
- u
.uy
; ady
= abs(dy
); sdy
= sgn(dy
);
594 if(dx
== 0 || dy
== 0 || adx
== ady
){
595 dmax
= (dx
== 0) ? ady
: adx
;
596 for(d
= 1; d
<= dmax
; d
++)
597 if(!rroom(sdx
*d
,sdy
*d
))
600 } else if(ady
> adx
){
601 for(d
= 1; d
<= ady
; d
++){
602 if(!rroom(sdx
*( (d
*adx
)/ady
), sdy
*d
) ||
603 !rroom(sdx
*( (d
*adx
-1)/ady
+1 ), sdy
*d
))
608 for(d
= 1; d
<= adx
; d
++){
609 if(!rroom(sdx
*d
, sdy
*( (d
*ady
)/adx
)) ||
610 !rroom(sdx
*d
, sdy
*( (d
*ady
-1)/adx
+1 )))
617 rroom(x
,y
) register int x
,y
; {
618 return(IS_ROOM(levl
[u
.ux
+x
][u
.uy
+y
].typ
));
623 cansee(x
,y
) xchar x
,y
; {
624 if(Blind
|| u
.uswallow
) return(0);
625 if(dist(x
,y
) < 3) return(1);
626 if(levl
[x
][y
].lit
&& seelx
<= x
&& x
<= seehx
&& seely
<= y
&&
627 y
<= seehy
) return(1);
632 sgn(a
) register int a
; {
633 return((a
> 0) ? 1 : (a
== 0) ? 0 : -1);
645 for(y
= u
.uy
-u
.uhorizon
; y
<= u
.uy
+u
.uhorizon
; y
++)
646 for(x
= u
.ux
-u
.uhorizon
; x
<= u
.ux
+u
.uhorizon
; x
++) {
662 if(!levl
[u
.ux
][u
.uy
].lit
) {
668 for(seelx
= u
.ux
; levl
[seelx
-1][u
.uy
].lit
; seelx
--);
669 for(seehx
= u
.ux
; levl
[seehx
+1][u
.uy
].lit
; seehx
++);
670 for(seely
= u
.uy
; levl
[u
.ux
][seely
-1].lit
; seely
--);
671 for(seehy
= u
.uy
; levl
[u
.ux
][seehy
+1].lit
; seehy
++);
673 for(y
= seely
; y
<= seehy
; y
++)
674 for(x
= seelx
; x
<= seehx
; x
++) {
677 if(!levl
[u
.ux
][u
.uy
].lit
) seehx
= 0; /* seems necessary elsewhere */
679 if(seely
== u
.uy
) for(x
= u
.ux
-1; x
<= u
.ux
+1; x
++) prl(x
,seely
-1);
680 if(seehy
== u
.uy
) for(x
= u
.ux
-1; x
<= u
.ux
+1; x
++) prl(x
,seehy
+1);
681 if(seelx
== u
.ux
) for(y
= u
.uy
-1; y
<= u
.uy
+1; y
++) prl(seelx
-1,y
);
682 if(seehx
== u
.ux
) for(y
= u
.uy
-1; y
<= u
.uy
+1; y
++) prl(seehx
+1,y
);
690 if(multi
< 0) return;
692 flags
.mv
= flags
.run
= 0;
697 if(u
.ustr
== 3) return(-3);
698 else if(u
.ustr
< 6) return(-2);
699 else if(u
.ustr
< 8) return(-1);
700 else if(u
.ustr
< 17) return(0);
701 else if(u
.ustr
< 69) return(1); /* up to 18/50 */
702 else if(u
.ustr
< 118) return(2);
708 if(u
.ustr
< 6) return(-1);
709 else if(u
.ustr
< 16) return(0);
710 else if(u
.ustr
< 18) return(1);
711 else if(u
.ustr
== 18) return(2); /* up to 18 */
712 else if(u
.ustr
< 94) return(3); /* up to 18/75 */
713 else if(u
.ustr
< 109) return(4); /* up to 18/90 */
714 else if(u
.ustr
< 118) return(5); /* up to 18/99 */
718 losestr(num
) /* may kill you; cause may be poison or monster like 'A' */
736 u
.uhpmax
= u
.uhp
; /* perhaps n was negative */
739 killer
= knam
; /* the thing that killed you */
746 register struct monst
*mtmp
;
754 losexp() /* hit by V or W */
757 extern long newuexp();
760 pline("Goodbye level %u.", u
.ulevel
--);
771 register struct obj
*otmp
= invent
;
772 register int wt
= (u
.ugold
+ 500)/1000;
773 register int carrcap
;
774 if(Levitation
) /* pugh@cornell */
775 carrcap
= MAX_CARR_CAP
;
777 carrcap
= 5*(((u
.ustr
> 18) ? 20 : u
.ustr
) + u
.ulevel
);
778 if(carrcap
> MAX_CARR_CAP
) carrcap
= MAX_CARR_CAP
;
779 if(Wounded_legs
& LEFT_SIDE
) carrcap
-= 10;
780 if(Wounded_legs
& RIGHT_SIDE
) carrcap
-= 10;
786 return(wt
- carrcap
);
790 register struct obj
*otmp
= invent
;
802 return(10*(1L << (u
.ulevel
-1)));