/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* hack.c - version 1.0.3 */
extern struct obj
*addinv();
1. when throwing ball+chain far away
3. when walking out of a lit room
newsym(u.udisx, u.udisy);
for(x
= u
.ux
-1; x
< u
.ux
+2; x
++)
for(y
= u
.uy
-1; y
< u
.uy
+2; y
++) {
if(!isok(x
, y
)) continue;
if(!lev
->lit
&& lev
->scrsym
== '.') {
in hack.eat.c: seeoff(0) - blind after eating rotten food
in hack.mon.c: seeoff(0) - blinded by a yellow light
in hack.mon.c: seeoff(1) - swallowed
in hack.do.c: seeoff(0) - blind after drinking potion
in hack.do.c: seeoff(1) - go up or down the stairs
in hack.trap.c:seeoff(1) - fall through trapdoor
seeoff(mode
) /* 1 to redo @, 0 to leave them */
{ /* 1 means misc movement, 0 means blindness */
levl
[u
.udisx
][u
.udisy
].scrsym
= news0(u
.udisx
,u
.udisy
);
for(x
= u
.ux
-1; x
< u
.ux
+2; x
++)
for(y
= u
.uy
-1; y
< u
.uy
+2; y
++) {
if(!isok(x
, y
)) continue;
if(!lev
->lit
&& lev
->scrsym
== '.')
register struct monst
*mtmp
;
register struct rm
*tmpr
,*ust
;
register struct obj
*otmp
;
pline("You collapse under your load.");
} while(!isok(u
.ux
+u
.dx
, u
.uy
+u
.dy
) ||
IS_ROCK(levl
[u
.ux
+u
.dx
][u
.uy
+u
.dy
].typ
));
if(!isok(u
.ux
+u
.dx
, u
.uy
+u
.dy
)){
if(!u
.uswallow
&& (trap
= t_at(u
.ux
+u
.dx
, u
.uy
+u
.dy
)) && trap
->tseen
)
if(u
.ustuck
&& !u
.uswallow
&& (u
.ux
+u
.dx
!= u
.ustuck
->mx
||
u
.uy
+u
.dy
!= u
.ustuck
->my
)) {
if(dist(u
.ustuck
->mx
, u
.ustuck
->my
) > 2){
/* perhaps it fled (or was teleported or ... ) */
if(Blind
) pline("You cannot escape from it!");
else pline("You cannot escape from %s!",
if(u
.uswallow
|| (mtmp
= m_at(u
.ux
+u
.dx
,u
.uy
+u
.dy
))) {
if(multi
< 0) return; /* we just fainted */
/* try to attack; note that it might evade */
if(attack(u
.uswallow
? u
.ustuck
: mtmp
))
/* not attacking an animal, so we try to move */
if(u
.utraptype
== TT_PIT
) {
pline("You are still in a pit.");
pline("You are caught in a beartrap.");
if((u
.dx
&& u
.dy
) || !rn2(5)) u
.utrap
--;
tmpr
= &levl
[u
.ux
+u
.dx
][u
.uy
+u
.dy
];
(u
.dx
&& u
.dy
&& (tmpr
->typ
== DOOR
|| ust
->typ
== DOOR
))){
while(otmp
= sobj_at(ENORMOUS_ROCK
, u
.ux
+u
.dx
, u
.uy
+u
.dy
)) {
register xchar rx
= u
.ux
+2*u
.dx
, ry
= u
.uy
+2*u
.dy
;
register struct trap
*ttmp
;
if(isok(rx
,ry
) && !IS_ROCK(levl
[rx
][ry
].typ
) &&
(levl
[rx
][ry
].typ
!= DOOR
|| !(u
.dx
&& u
.dy
)) &&
!sobj_at(ENORMOUS_ROCK
, rx
, ry
)) {
pline("You hear a monster behind the rock.");
pline("Perhaps that's why you cannot move it.");
pline("You push the rock into a pit!");
pline("It completely fills the pit!");
pline("You push the rock and suddenly it disappears!");
if(levl
[rx
][ry
].typ
== POOL
) {
pline("You push the rock into the water.");
pline("Now you can cross the water!");
if(cansee(rx
,ry
)) atl(rx
,ry
,otmp
->olet
);
if(Invisible
) newsym(u
.ux
+u
.dx
, u
.uy
+u
.dy
);
{ static long lastmovetime
;
/* note: this var contains garbage initially and
if(moves
> lastmovetime
+2 || moves
< lastmovetime
)
pline("With great effort you move the enormous rock.");
pline("You try to move the enormous rock, but in vain.");
if((!invent
|| inv_weight()+90 <= 0) &&
(!u
.dx
|| !u
.dy
|| (IS_ROCK(levl
[u
.ux
][u
.uy
+u
.dy
].typ
)
&& IS_ROCK(levl
[u
.ux
+u
.dx
][u
.uy
].typ
)))){
pline("However, you can squeeze yourself into a small opening.");
if(u
.dx
&& u
.dy
&& IS_ROCK(levl
[u
.ux
][u
.uy
+u
.dy
].typ
) &&
IS_ROCK(levl
[u
.ux
+u
.dx
][u
.uy
].typ
) &&
invent
&& inv_weight()+40 > 0) {
pline("You are carrying too much to get through.");
DIST(u
.ux
+u
.dx
, u
.uy
+u
.dy
, uchain
->ox
, uchain
->oy
) > 2){
movobj(uchain
, u
.ux
, u
.uy
);
if(DIST(u
.ux
+u
.dx
, u
.uy
+u
.dy
, uball
->ox
, uball
->oy
) < 3){
/* leave ball, move chain under/over ball */
movobj(uchain
, uball
->ox
, uball
->oy
);
if(inv_weight() + (int) uball
->owt
/2 > 0) {
pline("You cannot %sdrag the heavy iron ball.",
invent
? "carry all that and also " : "");
movobj(uball
, uchain
->ox
, uchain
->oy
);
unpobj(uball
); /* BAH %% */
(xupstair
== u
.ux
&& yupstair
== u
.uy
) ||
(xdnstair
== u
.ux
&& ydnstair
== u
.uy
))
if(tmpr
->typ
== POOL
&& !Levitation
)
drown(); /* not necessarily fatal */
prl1(u
.ux
+u
.dx
,u
.uy
+u
.dy
);
else if(ust
->typ
== DOOR
)
nose1(oldx
-u
.dx
,oldy
-u
.dy
);
prl1(u
.ux
+u
.dx
,u
.uy
+u
.dy
);
prl1(u
.ux
+u
.dx
,u
.uy
+u
.dy
);
nose1(oldx
-u
.dx
,oldy
-u
.dy
);
if(!flags
.nopick
) pickup(1);
if(trap
) dotrap(trap
); /* fall into pit, arrow trap, etc. */
if(!Blind
) read_engr_at(u
.ux
,u
.uy
);
register struct obj
*obj
;
/* Some dirty programming to get display right */
if(!g_at(u
.ux
,u
.uy
) && !o_at(u
.ux
,u
.uy
)) {
pline("There is nothing here to pick up.");
pline("You cannot reach the floor.");
register struct gold
*gold
;
register struct obj
*obj
, *obj2
;
while(gold
= g_at(u
.ux
,u
.uy
)) {
pline("%ld gold piece%s.", gold
->amount
, plur(gold
->amount
));
if(Invisible
) newsym(u
.ux
,u
.uy
);
/* check for more than one object */
for(obj
= fobj
; obj
; obj
= obj
->nobj
)
if(obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
if(!Punished
|| obj
!= uchain
)
pline("There are several objects here.");
for(obj
= fobj
; obj
; obj
= obj2
) {
obj2
= obj
->nobj
; /* perhaps obj will be picked up */
if(obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
) {
/* do not pick up uchain */
if(Punished
&& obj
== uchain
)
pline("Pick up %s ? [ynaq]", doname(obj
));
while(!index("ynaq ", (c
= readchar())))
if(obj
->otyp
== DEAD_COCKATRICE
&& !uarmg
){
pline("Touching the dead cockatrice is a fatal mistake.");
pline("You turn to stone.");
killer
= "cockatrice cadaver";
if(obj
->otyp
== SCR_SCARE_MONSTER
){
if(!obj
->spe
) obj
->spe
= 1;
/* Note: perhaps the 1st pickup failed: you cannot
carry anymore, and so we never dropped it -
let's assume that treading on it twice also
pline("The scroll turns to dust as you pick it up.");
wt
= inv_weight() + obj
->owt
;
/* see how many we can lift */
extern struct obj
*splitobj();
int savequan
= obj
->quan
;
for(qq
= 1; qq
< savequan
; qq
++){
/* we can carry qq of them */
pline("You can only carry %s of the %s lying here.",
(qq
== 1) ? "one" : "some",
(void) splitobj(obj
, qq
);
/* note: obj2 is set already, so we'll never
* encounter the other half; if it should be
* obj2 = splitobj(obj,qq);
pline("There %s %s here, but %s.",
(obj
->quan
== 1) ? "is" : "are",
!invent
? "it is too heavy for you to lift"
: "you cannot carry anymore");
pline("Your knapsack cannot accomodate anymore items.");
if(wt
> -5) pline("You have a little trouble lifting");
if(Invisible
) newsym(u
.ux
,u
.uy
);
addtobill(obj
); /* sets obj->unpaid if necessary */
{ int pickquan
= obj
->quan
;
if(!Blind
) obj
->dknown
= 1; /* this is done by prinv(),
but addinv() needs it already for merging */
obj
= addinv(obj
); /* might merge it with other objects */
obj
->quan
= pickquan
; /* to fool prinv() */
/* stop running if we see something interesting */
/* turn around a corner if that is the only way we can proceed */
/* do not turn left or right twice */
register x
,y
,i
,x0
,y0
,m0
,i0
= 9;
register int corrct
= 0, noturn
= 0;
register struct monst
*mtmp
;
/* suppress "used before set" message */
if(Blind
|| flags
.run
== 0) return;
if(flags
.run
== 1 && levl
[u
.ux
][u
.uy
].typ
== ROOM
) return;
if(u
.ux0
== u
.ux
+u
.dx
&& u
.uy0
== u
.uy
+u
.dy
) goto stop
;
for(x
= u
.ux
-1; x
<= u
.ux
+1; x
++) for(y
= u
.uy
-1; y
<= u
.uy
+1; y
++){
if(x
== u
.ux
&& y
== u
.uy
) continue;
if(!levl
[x
][y
].typ
) continue;
if((mtmp
= m_at(x
,y
)) && !mtmp
->mimic
&&
(!mtmp
->minvis
|| See_invisible
)){
if(!mtmp
->mtame
|| (x
== u
.ux
+u
.dx
&& y
== u
.uy
+u
.dy
))
} else mtmp
= 0; /* invisible M cannot influence us */
if(x
== u
.ux
-u
.dx
&& y
== u
.uy
-u
.dy
) continue;
switch(levl
[x
][y
].scrsym
){
if(x
!= u
.ux
&& y
!= u
.uy
) break;
if(flags
.run
!= 1) goto stop
;
/* fall into next case */
if(flags
.run
== 1 || flags
.run
== 3) {
i
= DIST(x
,y
,u
.ux
+u
.dx
,u
.uy
+u
.dy
);
if(corrct
== 1 && DIST(x
,y
,x0
,y0
) != 1)
if(flags
.run
== 1) goto corr
; /* if you must */
if(x
== u
.ux
+u
.dx
&& y
== u
.uy
+u
.dy
) goto stop
;
default: /* e.g. objects or trap or stairs */
if(flags
.run
== 1) goto corr
;
if(corrct
> 0 && (flags
.run
== 4 || flags
.run
== 5)) goto stop
;
if(corrct
> 1 && flags
.run
== 2) goto stop
;
if((flags
.run
== 1 || flags
.run
== 3) && !noturn
&& !m0
&& i0
&&
(corrct
== 1 || (corrct
== 2 && i0
== 1))) {
/* make sure that we do not turn too far */
if(u
.dx
== y0
-u
.uy
&& u
.dy
== u
.ux
-x0
)
i
= 2; /* straight turn right */
i
= -2; /* straight turn left */
} else if(u
.dx
&& u
.dy
) {
if((u
.dx
== u
.dy
&& y0
== u
.uy
) ||
(u
.dx
!= u
.dy
&& y0
!= u
.uy
))
i
= -1; /* half turn left */
i
= 1; /* half turn right */
if((x0
-u
.ux
== y0
-u
.uy
&& !u
.dy
) ||
(x0
-u
.ux
!= y0
-u
.uy
&& u
.dy
))
i
= 1; /* half turn right */
i
= -1; /* half turn left */
u
.dx
= x0
-u
.ux
, u
.dy
= y0
-u
.uy
;
/* something like lookaround, but we are not running */
/* react only to monsters that might hit us */
register struct monst
*mtmp
;
for(x
= u
.ux
-1; x
<= u
.ux
+1; x
++) for(y
= u
.uy
-1; y
<= u
.uy
+1; y
++){
if(x
== u
.ux
&& y
== u
.uy
) continue;
if((mtmp
= m_at(x
,y
)) && !mtmp
->mimic
&& !mtmp
->mtame
&&
!mtmp
->mpeaceful
&& !index("Ea", mtmp
->data
->mlet
) &&
!mtmp
->mfroz
&& !mtmp
->msleep
&& /* aplvax!jcn */
(!mtmp
->minvis
|| See_invisible
))
register int dx
,dy
,adx
,ady
,sdx
,sdy
,dmax
,d
;
if(!isok(x
,y
)) return(0);
if(d
> u
.uhorizon
*u
.uhorizon
) return(0);
dx
= x
- u
.ux
; adx
= abs(dx
); sdx
= sgn(dx
);
dy
= y
- u
.uy
; ady
= abs(dy
); sdy
= sgn(dy
);
if(dx
== 0 || dy
== 0 || adx
== ady
){
dmax
= (dx
== 0) ? ady
: adx
;
for(d
= 1; d
<= dmax
; d
++)
for(d
= 1; d
<= ady
; d
++){
if(!rroom(sdx
*( (d
*adx
)/ady
), sdy
*d
) ||
!rroom(sdx
*( (d
*adx
-1)/ady
+1 ), sdy
*d
))
for(d
= 1; d
<= adx
; d
++){
if(!rroom(sdx
*d
, sdy
*( (d
*ady
)/adx
)) ||
!rroom(sdx
*d
, sdy
*( (d
*ady
-1)/adx
+1 )))
rroom(x
,y
) register int x
,y
; {
return(IS_ROOM(levl
[u
.ux
+x
][u
.uy
+y
].typ
));
if(Blind
|| u
.uswallow
) return(0);
if(dist(x
,y
) < 3) return(1);
if(levl
[x
][y
].lit
&& seelx
<= x
&& x
<= seehx
&& seely
<= y
&&
return((a
> 0) ? 1 : (a
== 0) ? 0 : -1);
for(y
= u
.uy
-u
.uhorizon
; y
<= u
.uy
+u
.uhorizon
; y
++)
for(x
= u
.ux
-u
.uhorizon
; x
<= u
.ux
+u
.uhorizon
; x
++) {
if(!levl
[u
.ux
][u
.uy
].lit
) {
for(seelx
= u
.ux
; levl
[seelx
-1][u
.uy
].lit
; seelx
--);
for(seehx
= u
.ux
; levl
[seehx
+1][u
.uy
].lit
; seehx
++);
for(seely
= u
.uy
; levl
[u
.ux
][seely
-1].lit
; seely
--);
for(seehy
= u
.uy
; levl
[u
.ux
][seehy
+1].lit
; seehy
++);
for(y
= seely
; y
<= seehy
; y
++)
for(x
= seelx
; x
<= seehx
; x
++) {
if(!levl
[u
.ux
][u
.uy
].lit
) seehx
= 0; /* seems necessary elsewhere */
if(seely
== u
.uy
) for(x
= u
.ux
-1; x
<= u
.ux
+1; x
++) prl(x
,seely
-1);
if(seehy
== u
.uy
) for(x
= u
.ux
-1; x
<= u
.ux
+1; x
++) prl(x
,seehy
+1);
if(seelx
== u
.ux
) for(y
= u
.uy
-1; y
<= u
.uy
+1; y
++) prl(seelx
-1,y
);
if(seehx
== u
.ux
) for(y
= u
.uy
-1; y
<= u
.uy
+1; y
++) prl(seehx
+1,y
);
flags
.mv
= flags
.run
= 0;
if(u
.ustr
== 3) return(-3);
else if(u
.ustr
< 6) return(-2);
else if(u
.ustr
< 8) return(-1);
else if(u
.ustr
< 17) return(0);
else if(u
.ustr
< 69) return(1); /* up to 18/50 */
else if(u
.ustr
< 118) return(2);
if(u
.ustr
< 6) return(-1);
else if(u
.ustr
< 16) return(0);
else if(u
.ustr
< 18) return(1);
else if(u
.ustr
== 18) return(2); /* up to 18 */
else if(u
.ustr
< 94) return(3); /* up to 18/75 */
else if(u
.ustr
< 109) return(4); /* up to 18/90 */
else if(u
.ustr
< 118) return(5); /* up to 18/99 */
losestr(num
) /* may kill you; cause may be poison or monster like 'A' */
u
.uhpmax
= u
.uhp
; /* perhaps n was negative */
killer
= knam
; /* the thing that killed you */
register struct monst
*mtmp
;
losexp() /* hit by V or W */
pline("Goodbye level %u.", u
.ulevel
--);
register struct obj
*otmp
= invent
;
register int wt
= (u
.ugold
+ 500)/1000;
if(Levitation
) /* pugh@cornell */
carrcap
= 5*(((u
.ustr
> 18) ? 20 : u
.ustr
) + u
.ulevel
);
if(carrcap
> MAX_CARR_CAP
) carrcap
= MAX_CARR_CAP
;
if(Wounded_legs
& LEFT_SIDE
) carrcap
-= 10;
if(Wounded_legs
& RIGHT_SIDE
) carrcap
-= 10;
register struct obj
*otmp
= invent
;
return(10*(1L << (u
.ulevel
-1)));