Home | History | Annotate | Line # | Download | only in hack
hack.c revision 1.2
      1  1.2  mycroft /*
      2  1.2  mycroft  * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
      3  1.2  mycroft  */
      4  1.2  mycroft 
      5  1.2  mycroft #ifndef lint
      6  1.2  mycroft static char rcsid[] = "$Id: hack.c,v 1.2 1993/08/02 17:17:01 mycroft Exp $";
      7  1.2  mycroft #endif /* not lint */
      8  1.1      cgd 
      9  1.1      cgd #include "hack.h"
     10  1.1      cgd #include <stdio.h>
     11  1.1      cgd 
     12  1.1      cgd extern char news0();
     13  1.1      cgd extern char *nomovemsg;
     14  1.1      cgd extern char *exclam();
     15  1.1      cgd extern struct obj *addinv();
     16  1.1      cgd extern boolean hmon();
     17  1.1      cgd 
     18  1.1      cgd /* called on movement:
     19  1.1      cgd 	1. when throwing ball+chain far away
     20  1.1      cgd 	2. when teleporting
     21  1.1      cgd 	3. when walking out of a lit room
     22  1.1      cgd  */
     23  1.1      cgd unsee() {
     24  1.1      cgd 	register x,y;
     25  1.1      cgd 	register struct rm *lev;
     26  1.1      cgd 
     27  1.1      cgd /*
     28  1.1      cgd 	if(u.udispl){
     29  1.1      cgd 		u.udispl = 0;
     30  1.1      cgd 		newsym(u.udisx, u.udisy);
     31  1.1      cgd 	}
     32  1.1      cgd */
     33  1.1      cgd #ifndef QUEST
     34  1.1      cgd 	if(seehx){
     35  1.1      cgd 		seehx = 0;
     36  1.1      cgd 	} else
     37  1.1      cgd #endif QUEST
     38  1.1      cgd 	for(x = u.ux-1; x < u.ux+2; x++)
     39  1.1      cgd 	  for(y = u.uy-1; y < u.uy+2; y++) {
     40  1.1      cgd 		if(!isok(x, y)) continue;
     41  1.1      cgd 		lev = &levl[x][y];
     42  1.1      cgd 		if(!lev->lit && lev->scrsym == '.') {
     43  1.1      cgd 			lev->scrsym =' ';
     44  1.1      cgd 			lev->new = 1;
     45  1.1      cgd 			on_scr(x,y);
     46  1.1      cgd 		}
     47  1.1      cgd 	}
     48  1.1      cgd }
     49  1.1      cgd 
     50  1.1      cgd /* called:
     51  1.1      cgd 	in hack.eat.c: seeoff(0) - blind after eating rotten food
     52  1.1      cgd 	in hack.mon.c: seeoff(0) - blinded by a yellow light
     53  1.1      cgd 	in hack.mon.c: seeoff(1) - swallowed
     54  1.1      cgd 	in hack.do.c:  seeoff(0) - blind after drinking potion
     55  1.1      cgd 	in hack.do.c:  seeoff(1) - go up or down the stairs
     56  1.1      cgd 	in hack.trap.c:seeoff(1) - fall through trapdoor
     57  1.1      cgd  */
     58  1.1      cgd seeoff(mode)	/* 1 to redo @, 0 to leave them */
     59  1.1      cgd {	/* 1 means misc movement, 0 means blindness */
     60  1.1      cgd 	register x,y;
     61  1.1      cgd 	register struct rm *lev;
     62  1.1      cgd 
     63  1.1      cgd 	if(u.udispl && mode){
     64  1.1      cgd 		u.udispl = 0;
     65  1.1      cgd 		levl[u.udisx][u.udisy].scrsym = news0(u.udisx,u.udisy);
     66  1.1      cgd 	}
     67  1.1      cgd #ifndef QUEST
     68  1.1      cgd 	if(seehx) {
     69  1.1      cgd 		seehx = 0;
     70  1.1      cgd 	} else
     71  1.1      cgd #endif QUEST
     72  1.1      cgd 	if(!mode) {
     73  1.1      cgd 		for(x = u.ux-1; x < u.ux+2; x++)
     74  1.1      cgd 			for(y = u.uy-1; y < u.uy+2; y++) {
     75  1.1      cgd 				if(!isok(x, y)) continue;
     76  1.1      cgd 				lev = &levl[x][y];
     77  1.1      cgd 				if(!lev->lit && lev->scrsym == '.')
     78  1.1      cgd 					lev->seen = 0;
     79  1.1      cgd 			}
     80  1.1      cgd 	}
     81  1.1      cgd }
     82  1.1      cgd 
     83  1.1      cgd domove()
     84  1.1      cgd {
     85  1.1      cgd 	xchar oldx,oldy;
     86  1.1      cgd 	register struct monst *mtmp;
     87  1.1      cgd 	register struct rm *tmpr,*ust;
     88  1.1      cgd 	struct trap *trap;
     89  1.1      cgd 	register struct obj *otmp;
     90  1.1      cgd 
     91  1.1      cgd 	u_wipe_engr(rnd(5));
     92  1.1      cgd 
     93  1.1      cgd 	if(inv_weight() > 0){
     94  1.1      cgd 		pline("You collapse under your load.");
     95  1.1      cgd 		nomul(0);
     96  1.1      cgd 		return;
     97  1.1      cgd 	}
     98  1.1      cgd 	if(u.uswallow) {
     99  1.1      cgd 		u.dx = u.dy = 0;
    100  1.1      cgd 		u.ux = u.ustuck->mx;
    101  1.1      cgd 		u.uy = u.ustuck->my;
    102  1.1      cgd 	} else {
    103  1.1      cgd 		if(Confusion) {
    104  1.1      cgd 			do {
    105  1.1      cgd 				confdir();
    106  1.1      cgd 			} while(!isok(u.ux+u.dx, u.uy+u.dy) ||
    107  1.1      cgd 			    IS_ROCK(levl[u.ux+u.dx][u.uy+u.dy].typ));
    108  1.1      cgd 		}
    109  1.1      cgd 		if(!isok(u.ux+u.dx, u.uy+u.dy)){
    110  1.1      cgd 			nomul(0);
    111  1.1      cgd 			return;
    112  1.1      cgd 		}
    113  1.1      cgd 	}
    114  1.1      cgd 
    115  1.1      cgd 	ust = &levl[u.ux][u.uy];
    116  1.1      cgd 	oldx = u.ux;
    117  1.1      cgd 	oldy = u.uy;
    118  1.1      cgd 	if(!u.uswallow && (trap = t_at(u.ux+u.dx, u.uy+u.dy)) && trap->tseen)
    119  1.1      cgd 		nomul(0);
    120  1.1      cgd 	if(u.ustuck && !u.uswallow && (u.ux+u.dx != u.ustuck->mx ||
    121  1.1      cgd 		u.uy+u.dy != u.ustuck->my)) {
    122  1.1      cgd 		if(dist(u.ustuck->mx, u.ustuck->my) > 2){
    123  1.1      cgd 			/* perhaps it fled (or was teleported or ... ) */
    124  1.1      cgd 			u.ustuck = 0;
    125  1.1      cgd 		} else {
    126  1.1      cgd 			if(Blind) pline("You cannot escape from it!");
    127  1.1      cgd 			else pline("You cannot escape from %s!",
    128  1.1      cgd 				monnam(u.ustuck));
    129  1.1      cgd 			nomul(0);
    130  1.1      cgd 			return;
    131  1.1      cgd 		}
    132  1.1      cgd 	}
    133  1.1      cgd 	if(u.uswallow || (mtmp = m_at(u.ux+u.dx,u.uy+u.dy))) {
    134  1.1      cgd 	/* attack monster */
    135  1.1      cgd 
    136  1.1      cgd 		nomul(0);
    137  1.1      cgd 		gethungry();
    138  1.1      cgd 		if(multi < 0) return;	/* we just fainted */
    139  1.1      cgd 
    140  1.1      cgd 		/* try to attack; note that it might evade */
    141  1.1      cgd 		if(attack(u.uswallow ? u.ustuck : mtmp))
    142  1.1      cgd 			return;
    143  1.1      cgd 	}
    144  1.1      cgd 	/* not attacking an animal, so we try to move */
    145  1.1      cgd 	if(u.utrap) {
    146  1.1      cgd 		if(u.utraptype == TT_PIT) {
    147  1.1      cgd 			pline("You are still in a pit.");
    148  1.1      cgd 			u.utrap--;
    149  1.1      cgd 		} else {
    150  1.1      cgd 			pline("You are caught in a beartrap.");
    151  1.1      cgd 			if((u.dx && u.dy) || !rn2(5)) u.utrap--;
    152  1.1      cgd 		}
    153  1.1      cgd 		return;
    154  1.1      cgd 	}
    155  1.1      cgd 	tmpr = &levl[u.ux+u.dx][u.uy+u.dy];
    156  1.1      cgd 	if(IS_ROCK(tmpr->typ) ||
    157  1.1      cgd 	   (u.dx && u.dy && (tmpr->typ == DOOR || ust->typ == DOOR))){
    158  1.1      cgd 		flags.move = 0;
    159  1.1      cgd 		nomul(0);
    160  1.1      cgd 		return;
    161  1.1      cgd 	}
    162  1.1      cgd 	while(otmp = sobj_at(ENORMOUS_ROCK, u.ux+u.dx, u.uy+u.dy)) {
    163  1.1      cgd 		register xchar rx = u.ux+2*u.dx, ry = u.uy+2*u.dy;
    164  1.1      cgd 		register struct trap *ttmp;
    165  1.1      cgd 		nomul(0);
    166  1.1      cgd 		if(isok(rx,ry) && !IS_ROCK(levl[rx][ry].typ) &&
    167  1.1      cgd 		    (levl[rx][ry].typ != DOOR || !(u.dx && u.dy)) &&
    168  1.1      cgd 		    !sobj_at(ENORMOUS_ROCK, rx, ry)) {
    169  1.1      cgd 			if(m_at(rx,ry)) {
    170  1.1      cgd 			    pline("You hear a monster behind the rock.");
    171  1.1      cgd 			    pline("Perhaps that's why you cannot move it.");
    172  1.1      cgd 			    goto cannot_push;
    173  1.1      cgd 			}
    174  1.1      cgd 			if(ttmp = t_at(rx,ry))
    175  1.1      cgd 			    switch(ttmp->ttyp) {
    176  1.1      cgd 			    case PIT:
    177  1.1      cgd 				pline("You push the rock into a pit!");
    178  1.1      cgd 				deltrap(ttmp);
    179  1.1      cgd 				delobj(otmp);
    180  1.1      cgd 				pline("It completely fills the pit!");
    181  1.1      cgd 				continue;
    182  1.1      cgd 			    case TELEP_TRAP:
    183  1.1      cgd 				pline("You push the rock and suddenly it disappears!");
    184  1.1      cgd 				delobj(otmp);
    185  1.1      cgd 				continue;
    186  1.1      cgd 			    }
    187  1.1      cgd 			if(levl[rx][ry].typ == POOL) {
    188  1.1      cgd 				levl[rx][ry].typ = ROOM;
    189  1.1      cgd 				mnewsym(rx,ry);
    190  1.1      cgd 				prl(rx,ry);
    191  1.1      cgd 				pline("You push the rock into the water.");
    192  1.1      cgd 				pline("Now you can cross the water!");
    193  1.1      cgd 				delobj(otmp);
    194  1.1      cgd 				continue;
    195  1.1      cgd 			}
    196  1.1      cgd 			otmp->ox = rx;
    197  1.1      cgd 			otmp->oy = ry;
    198  1.1      cgd 			/* pobj(otmp); */
    199  1.1      cgd 			if(cansee(rx,ry)) atl(rx,ry,otmp->olet);
    200  1.1      cgd 			if(Invisible) newsym(u.ux+u.dx, u.uy+u.dy);
    201  1.1      cgd 
    202  1.1      cgd 			{ static long lastmovetime;
    203  1.1      cgd 			/* note: this var contains garbage initially and
    204  1.1      cgd 			   after a restore */
    205  1.1      cgd 			if(moves > lastmovetime+2 || moves < lastmovetime)
    206  1.1      cgd 			pline("With great effort you move the enormous rock.");
    207  1.1      cgd 			lastmovetime = moves;
    208  1.1      cgd 			}
    209  1.1      cgd 		} else {
    210  1.1      cgd 		    pline("You try to move the enormous rock, but in vain.");
    211  1.1      cgd 	    cannot_push:
    212  1.1      cgd 		    if((!invent || inv_weight()+90 <= 0) &&
    213  1.1      cgd 			(!u.dx || !u.dy || (IS_ROCK(levl[u.ux][u.uy+u.dy].typ)
    214  1.1      cgd 					&& IS_ROCK(levl[u.ux+u.dx][u.uy].typ)))){
    215  1.1      cgd 			pline("However, you can squeeze yourself into a small opening.");
    216  1.1      cgd 			break;
    217  1.1      cgd 		    } else
    218  1.1      cgd 			return;
    219  1.1      cgd 		}
    220  1.1      cgd 	    }
    221  1.1      cgd 	if(u.dx && u.dy && IS_ROCK(levl[u.ux][u.uy+u.dy].typ) &&
    222  1.1      cgd 		IS_ROCK(levl[u.ux+u.dx][u.uy].typ) &&
    223  1.1      cgd 		invent && inv_weight()+40 > 0) {
    224  1.1      cgd 		pline("You are carrying too much to get through.");
    225  1.1      cgd 		nomul(0);
    226  1.1      cgd 		return;
    227  1.1      cgd 	}
    228  1.1      cgd 	if(Punished &&
    229  1.1      cgd 	   DIST(u.ux+u.dx, u.uy+u.dy, uchain->ox, uchain->oy) > 2){
    230  1.1      cgd 		if(carried(uball)) {
    231  1.1      cgd 			movobj(uchain, u.ux, u.uy);
    232  1.1      cgd 			goto nodrag;
    233  1.1      cgd 		}
    234  1.1      cgd 
    235  1.1      cgd 		if(DIST(u.ux+u.dx, u.uy+u.dy, uball->ox, uball->oy) < 3){
    236  1.1      cgd 			/* leave ball, move chain under/over ball */
    237  1.1      cgd 			movobj(uchain, uball->ox, uball->oy);
    238  1.1      cgd 			goto nodrag;
    239  1.1      cgd 		}
    240  1.1      cgd 
    241  1.1      cgd 		if(inv_weight() + (int) uball->owt/2 > 0) {
    242  1.1      cgd 			pline("You cannot %sdrag the heavy iron ball.",
    243  1.1      cgd 			invent ? "carry all that and also " : "");
    244  1.1      cgd 			nomul(0);
    245  1.1      cgd 			return;
    246  1.1      cgd 		}
    247  1.1      cgd 
    248  1.1      cgd 		movobj(uball, uchain->ox, uchain->oy);
    249  1.1      cgd 		unpobj(uball);		/* BAH %% */
    250  1.1      cgd 		uchain->ox = u.ux;
    251  1.1      cgd 		uchain->oy = u.uy;
    252  1.1      cgd 		nomul(-2);
    253  1.1      cgd 		nomovemsg = "";
    254  1.1      cgd 	nodrag:	;
    255  1.1      cgd 	}
    256  1.1      cgd 	u.ux += u.dx;
    257  1.1      cgd 	u.uy += u.dy;
    258  1.1      cgd 	if(flags.run) {
    259  1.1      cgd 		if(tmpr->typ == DOOR ||
    260  1.1      cgd 		(xupstair == u.ux && yupstair == u.uy) ||
    261  1.1      cgd 		(xdnstair == u.ux && ydnstair == u.uy))
    262  1.1      cgd 			nomul(0);
    263  1.1      cgd 	}
    264  1.1      cgd 
    265  1.1      cgd 	if(tmpr->typ == POOL && !Levitation)
    266  1.1      cgd 		drown();	/* not necessarily fatal */
    267  1.1      cgd 
    268  1.1      cgd /*
    269  1.1      cgd 	if(u.udispl) {
    270  1.1      cgd 		u.udispl = 0;
    271  1.1      cgd 		newsym(oldx,oldy);
    272  1.1      cgd 	}
    273  1.1      cgd */
    274  1.1      cgd 	if(!Blind) {
    275  1.1      cgd #ifdef QUEST
    276  1.1      cgd 		setsee();
    277  1.1      cgd #else
    278  1.1      cgd 		if(ust->lit) {
    279  1.1      cgd 			if(tmpr->lit) {
    280  1.1      cgd 				if(tmpr->typ == DOOR)
    281  1.1      cgd 					prl1(u.ux+u.dx,u.uy+u.dy);
    282  1.1      cgd 				else if(ust->typ == DOOR)
    283  1.1      cgd 					nose1(oldx-u.dx,oldy-u.dy);
    284  1.1      cgd 			} else {
    285  1.1      cgd 				unsee();
    286  1.1      cgd 				prl1(u.ux+u.dx,u.uy+u.dy);
    287  1.1      cgd 			}
    288  1.1      cgd 		} else {
    289  1.1      cgd 			if(tmpr->lit) setsee();
    290  1.1      cgd 			else {
    291  1.1      cgd 				prl1(u.ux+u.dx,u.uy+u.dy);
    292  1.1      cgd 				if(tmpr->typ == DOOR) {
    293  1.1      cgd 					if(u.dy) {
    294  1.1      cgd 						prl(u.ux-1,u.uy);
    295  1.1      cgd 						prl(u.ux+1,u.uy);
    296  1.1      cgd 					} else {
    297  1.1      cgd 						prl(u.ux,u.uy-1);
    298  1.1      cgd 						prl(u.ux,u.uy+1);
    299  1.1      cgd 					}
    300  1.1      cgd 				}
    301  1.1      cgd 			}
    302  1.1      cgd 			nose1(oldx-u.dx,oldy-u.dy);
    303  1.1      cgd 		}
    304  1.1      cgd #endif QUEST
    305  1.1      cgd 	} else {
    306  1.1      cgd 		pru();
    307  1.1      cgd 	}
    308  1.1      cgd 	if(!flags.nopick) pickup(1);
    309  1.1      cgd 	if(trap) dotrap(trap);		/* fall into pit, arrow trap, etc. */
    310  1.1      cgd 	(void) inshop();
    311  1.1      cgd 	if(!Blind) read_engr_at(u.ux,u.uy);
    312  1.1      cgd }
    313  1.1      cgd 
    314  1.1      cgd movobj(obj, ox, oy)
    315  1.1      cgd register struct obj *obj;
    316  1.1      cgd register int ox, oy;
    317  1.1      cgd {
    318  1.1      cgd 	/* Some dirty programming to get display right */
    319  1.1      cgd 	freeobj(obj);
    320  1.1      cgd 	unpobj(obj);
    321  1.1      cgd 	obj->nobj = fobj;
    322  1.1      cgd 	fobj = obj;
    323  1.1      cgd 	obj->ox = ox;
    324  1.1      cgd 	obj->oy = oy;
    325  1.1      cgd }
    326  1.1      cgd 
    327  1.1      cgd dopickup(){
    328  1.1      cgd 	if(!g_at(u.ux,u.uy) && !o_at(u.ux,u.uy)) {
    329  1.1      cgd 		pline("There is nothing here to pick up.");
    330  1.1      cgd 		return(0);
    331  1.1      cgd 	}
    332  1.1      cgd 	if(Levitation) {
    333  1.1      cgd 		pline("You cannot reach the floor.");
    334  1.1      cgd 		return(1);
    335  1.1      cgd 	}
    336  1.1      cgd 	pickup(0);
    337  1.1      cgd 	return(1);
    338  1.1      cgd }
    339  1.1      cgd 
    340  1.1      cgd pickup(all)
    341  1.1      cgd {
    342  1.1      cgd 	register struct gold *gold;
    343  1.1      cgd 	register struct obj *obj, *obj2;
    344  1.1      cgd 	register int wt;
    345  1.1      cgd 
    346  1.1      cgd 	if(Levitation) return;
    347  1.1      cgd 	while(gold = g_at(u.ux,u.uy)) {
    348  1.1      cgd 		pline("%ld gold piece%s.", gold->amount, plur(gold->amount));
    349  1.1      cgd 		u.ugold += gold->amount;
    350  1.1      cgd 		flags.botl = 1;
    351  1.1      cgd 		freegold(gold);
    352  1.1      cgd 		if(flags.run) nomul(0);
    353  1.1      cgd 		if(Invisible) newsym(u.ux,u.uy);
    354  1.1      cgd 	}
    355  1.1      cgd 
    356  1.1      cgd 	/* check for more than one object */
    357  1.1      cgd 	if(!all) {
    358  1.1      cgd 		register int ct = 0;
    359  1.1      cgd 
    360  1.1      cgd 		for(obj = fobj; obj; obj = obj->nobj)
    361  1.1      cgd 			if(obj->ox == u.ux && obj->oy == u.uy)
    362  1.1      cgd 				if(!Punished || obj != uchain)
    363  1.1      cgd 					ct++;
    364  1.1      cgd 		if(ct < 2)
    365  1.1      cgd 			all++;
    366  1.1      cgd 		else
    367  1.1      cgd 			pline("There are several objects here.");
    368  1.1      cgd 	}
    369  1.1      cgd 
    370  1.1      cgd 	for(obj = fobj; obj; obj = obj2) {
    371  1.1      cgd 	    obj2 = obj->nobj;	/* perhaps obj will be picked up */
    372  1.1      cgd 	    if(obj->ox == u.ux && obj->oy == u.uy) {
    373  1.1      cgd 		if(flags.run) nomul(0);
    374  1.1      cgd 
    375  1.1      cgd 		/* do not pick up uchain */
    376  1.1      cgd 		if(Punished && obj == uchain)
    377  1.1      cgd 			continue;
    378  1.1      cgd 
    379  1.1      cgd 		if(!all) {
    380  1.1      cgd 			char c;
    381  1.1      cgd 
    382  1.1      cgd 			pline("Pick up %s ? [ynaq]", doname(obj));
    383  1.1      cgd 			while(!index("ynaq ", (c = readchar())))
    384  1.1      cgd 				bell();
    385  1.1      cgd 			if(c == 'q') return;
    386  1.1      cgd 			if(c == 'n') continue;
    387  1.1      cgd 			if(c == 'a') all = 1;
    388  1.1      cgd 		}
    389  1.1      cgd 
    390  1.1      cgd 		if(obj->otyp == DEAD_COCKATRICE && !uarmg){
    391  1.1      cgd 		    pline("Touching the dead cockatrice is a fatal mistake.");
    392  1.1      cgd 		    pline("You turn to stone.");
    393  1.1      cgd 		    killer = "cockatrice cadaver";
    394  1.1      cgd 		    done("died");
    395  1.1      cgd 		}
    396  1.1      cgd 
    397  1.1      cgd 		if(obj->otyp == SCR_SCARE_MONSTER){
    398  1.1      cgd 		  if(!obj->spe) obj->spe = 1;
    399  1.1      cgd 		  else {
    400  1.1      cgd 		    /* Note: perhaps the 1st pickup failed: you cannot
    401  1.1      cgd 			carry anymore, and so we never dropped it -
    402  1.1      cgd 			let's assume that treading on it twice also
    403  1.1      cgd 			destroys the scroll */
    404  1.1      cgd 		    pline("The scroll turns to dust as you pick it up.");
    405  1.1      cgd 		    delobj(obj);
    406  1.1      cgd 		    continue;
    407  1.1      cgd 		  }
    408  1.1      cgd 		}
    409  1.1      cgd 
    410  1.1      cgd 		wt = inv_weight() + obj->owt;
    411  1.1      cgd 		if(wt > 0) {
    412  1.1      cgd 			if(obj->quan > 1) {
    413  1.1      cgd 				/* see how many we can lift */
    414  1.1      cgd 				extern struct obj *splitobj();
    415  1.1      cgd 				int savequan = obj->quan;
    416  1.1      cgd 				int iw = inv_weight();
    417  1.1      cgd 				int qq;
    418  1.1      cgd 				for(qq = 1; qq < savequan; qq++){
    419  1.1      cgd 					obj->quan = qq;
    420  1.1      cgd 					if(iw + weight(obj) > 0)
    421  1.1      cgd 						break;
    422  1.1      cgd 				}
    423  1.1      cgd 				obj->quan = savequan;
    424  1.1      cgd 				qq--;
    425  1.1      cgd 				/* we can carry qq of them */
    426  1.1      cgd 				if(!qq) goto too_heavy;
    427  1.1      cgd 			pline("You can only carry %s of the %s lying here.",
    428  1.1      cgd 					(qq == 1) ? "one" : "some",
    429  1.1      cgd 					doname(obj));
    430  1.1      cgd 				(void) splitobj(obj, qq);
    431  1.1      cgd 				/* note: obj2 is set already, so we'll never
    432  1.1      cgd 				 * encounter the other half; if it should be
    433  1.1      cgd 				 * otherwise then write
    434  1.1      cgd 				 *	obj2 = splitobj(obj,qq);
    435  1.1      cgd 				 */
    436  1.1      cgd 				goto lift_some;
    437  1.1      cgd 			}
    438  1.1      cgd 		too_heavy:
    439  1.1      cgd 			pline("There %s %s here, but %s.",
    440  1.1      cgd 				(obj->quan == 1) ? "is" : "are",
    441  1.1      cgd 				doname(obj),
    442  1.1      cgd 				!invent ? "it is too heavy for you to lift"
    443  1.1      cgd 					: "you cannot carry anymore");
    444  1.1      cgd 			break;
    445  1.1      cgd 		}
    446  1.1      cgd 	lift_some:
    447  1.1      cgd 		if(inv_cnt() >= 52) {
    448  1.1      cgd 		    pline("Your knapsack cannot accomodate anymore items.");
    449  1.1      cgd 		    break;
    450  1.1      cgd 		}
    451  1.1      cgd 		if(wt > -5) pline("You have a little trouble lifting");
    452  1.1      cgd 		freeobj(obj);
    453  1.1      cgd 		if(Invisible) newsym(u.ux,u.uy);
    454  1.1      cgd 		addtobill(obj);       /* sets obj->unpaid if necessary */
    455  1.1      cgd 		{ int pickquan = obj->quan;
    456  1.1      cgd 		  int mergquan;
    457  1.1      cgd 		if(!Blind) obj->dknown = 1;	/* this is done by prinv(),
    458  1.1      cgd 				 but addinv() needs it already for merging */
    459  1.1      cgd 		obj = addinv(obj);    /* might merge it with other objects */
    460  1.1      cgd 		  mergquan = obj->quan;
    461  1.1      cgd 		  obj->quan = pickquan;	/* to fool prinv() */
    462  1.1      cgd 		prinv(obj);
    463  1.1      cgd 		  obj->quan = mergquan;
    464  1.1      cgd 		}
    465  1.1      cgd 	    }
    466  1.1      cgd 	}
    467  1.1      cgd }
    468  1.1      cgd 
    469  1.1      cgd /* stop running if we see something interesting */
    470  1.1      cgd /* turn around a corner if that is the only way we can proceed */
    471  1.1      cgd /* do not turn left or right twice */
    472  1.1      cgd lookaround(){
    473  1.1      cgd register x,y,i,x0,y0,m0,i0 = 9;
    474  1.1      cgd register int corrct = 0, noturn = 0;
    475  1.1      cgd register struct monst *mtmp;
    476  1.1      cgd #ifdef lint
    477  1.1      cgd 	/* suppress "used before set" message */
    478  1.1      cgd 	x0 = y0 = 0;
    479  1.1      cgd #endif lint
    480  1.1      cgd 	if(Blind || flags.run == 0) return;
    481  1.1      cgd 	if(flags.run == 1 && levl[u.ux][u.uy].typ == ROOM) return;
    482  1.1      cgd #ifdef QUEST
    483  1.1      cgd 	if(u.ux0 == u.ux+u.dx && u.uy0 == u.uy+u.dy) goto stop;
    484  1.1      cgd #endif QUEST
    485  1.1      cgd 	for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){
    486  1.1      cgd 		if(x == u.ux && y == u.uy) continue;
    487  1.1      cgd 		if(!levl[x][y].typ) continue;
    488  1.1      cgd 		if((mtmp = m_at(x,y)) && !mtmp->mimic &&
    489  1.1      cgd 		    (!mtmp->minvis || See_invisible)){
    490  1.1      cgd 			if(!mtmp->mtame || (x == u.ux+u.dx && y == u.uy+u.dy))
    491  1.1      cgd 				goto stop;
    492  1.1      cgd 		} else mtmp = 0; /* invisible M cannot influence us */
    493  1.1      cgd 		if(x == u.ux-u.dx && y == u.uy-u.dy) continue;
    494  1.1      cgd 		switch(levl[x][y].scrsym){
    495  1.1      cgd 		case '|':
    496  1.1      cgd 		case '-':
    497  1.1      cgd 		case '.':
    498  1.1      cgd 		case ' ':
    499  1.1      cgd 			break;
    500  1.1      cgd 		case '+':
    501  1.1      cgd 			if(x != u.ux && y != u.uy) break;
    502  1.1      cgd 			if(flags.run != 1) goto stop;
    503  1.1      cgd 			/* fall into next case */
    504  1.1      cgd 		case CORR_SYM:
    505  1.1      cgd 		corr:
    506  1.1      cgd 			if(flags.run == 1 || flags.run == 3) {
    507  1.1      cgd 				i = DIST(x,y,u.ux+u.dx,u.uy+u.dy);
    508  1.1      cgd 				if(i > 2) break;
    509  1.1      cgd 				if(corrct == 1 && DIST(x,y,x0,y0) != 1)
    510  1.1      cgd 					noturn = 1;
    511  1.1      cgd 				if(i < i0) {
    512  1.1      cgd 					i0 = i;
    513  1.1      cgd 					x0 = x;
    514  1.1      cgd 					y0 = y;
    515  1.1      cgd 					m0 = mtmp ? 1 : 0;
    516  1.1      cgd 				}
    517  1.1      cgd 			}
    518  1.1      cgd 			corrct++;
    519  1.1      cgd 			break;
    520  1.1      cgd 		case '^':
    521  1.1      cgd 			if(flags.run == 1) goto corr;	/* if you must */
    522  1.1      cgd 			if(x == u.ux+u.dx && y == u.uy+u.dy) goto stop;
    523  1.1      cgd 			break;
    524  1.1      cgd 		default:	/* e.g. objects or trap or stairs */
    525  1.1      cgd 			if(flags.run == 1) goto corr;
    526  1.1      cgd 			if(mtmp) break;		/* d */
    527  1.1      cgd 		stop:
    528  1.1      cgd 			nomul(0);
    529  1.1      cgd 			return;
    530  1.1      cgd 		}
    531  1.1      cgd 	}
    532  1.1      cgd #ifdef QUEST
    533  1.1      cgd 	if(corrct > 0 && (flags.run == 4 || flags.run == 5)) goto stop;
    534  1.1      cgd #endif QUEST
    535  1.1      cgd 	if(corrct > 1 && flags.run == 2) goto stop;
    536  1.1      cgd 	if((flags.run == 1 || flags.run == 3) && !noturn && !m0 && i0 &&
    537  1.1      cgd 		(corrct == 1 || (corrct == 2 && i0 == 1))) {
    538  1.1      cgd 		/* make sure that we do not turn too far */
    539  1.1      cgd 		if(i0 == 2) {
    540  1.1      cgd 		    if(u.dx == y0-u.uy && u.dy == u.ux-x0)
    541  1.1      cgd 			i = 2;		/* straight turn right */
    542  1.1      cgd 		    else
    543  1.1      cgd 			i = -2;		/* straight turn left */
    544  1.1      cgd 		} else if(u.dx && u.dy) {
    545  1.1      cgd 		    if((u.dx == u.dy && y0 == u.uy) ||
    546  1.1      cgd 			(u.dx != u.dy && y0 != u.uy))
    547  1.1      cgd 			i = -1;		/* half turn left */
    548  1.1      cgd 		    else
    549  1.1      cgd 			i = 1;		/* half turn right */
    550  1.1      cgd 		} else {
    551  1.1      cgd 		    if((x0-u.ux == y0-u.uy && !u.dy) ||
    552  1.1      cgd 			(x0-u.ux != y0-u.uy && u.dy))
    553  1.1      cgd 			i = 1;		/* half turn right */
    554  1.1      cgd 		    else
    555  1.1      cgd 			i = -1;		/* half turn left */
    556  1.1      cgd 		}
    557  1.1      cgd 		i += u.last_str_turn;
    558  1.1      cgd 		if(i <= 2 && i >= -2) {
    559  1.1      cgd 			u.last_str_turn = i;
    560  1.1      cgd 			u.dx = x0-u.ux, u.dy = y0-u.uy;
    561  1.1      cgd 		}
    562  1.1      cgd 	}
    563  1.1      cgd }
    564  1.1      cgd 
    565  1.1      cgd /* something like lookaround, but we are not running */
    566  1.1      cgd /* react only to monsters that might hit us */
    567  1.1      cgd monster_nearby() {
    568  1.1      cgd register int x,y;
    569  1.1      cgd register struct monst *mtmp;
    570  1.1      cgd 	if(!Blind)
    571  1.1      cgd 	for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){
    572  1.1      cgd 		if(x == u.ux && y == u.uy) continue;
    573  1.1      cgd 		if((mtmp = m_at(x,y)) && !mtmp->mimic && !mtmp->mtame &&
    574  1.1      cgd 			!mtmp->mpeaceful && !index("Ea", mtmp->data->mlet) &&
    575  1.1      cgd 			!mtmp->mfroz && !mtmp->msleep &&  /* aplvax!jcn */
    576  1.1      cgd 			(!mtmp->minvis || See_invisible))
    577  1.1      cgd 			return(1);
    578  1.1      cgd 	}
    579  1.1      cgd 	return(0);
    580  1.1      cgd }
    581  1.1      cgd 
    582  1.1      cgd #ifdef QUEST
    583  1.1      cgd cansee(x,y) xchar x,y; {
    584  1.1      cgd register int dx,dy,adx,ady,sdx,sdy,dmax,d;
    585  1.1      cgd 	if(Blind) return(0);
    586  1.1      cgd 	if(!isok(x,y)) return(0);
    587  1.1      cgd 	d = dist(x,y);
    588  1.1      cgd 	if(d < 3) return(1);
    589  1.1      cgd 	if(d > u.uhorizon*u.uhorizon) return(0);
    590  1.1      cgd 	if(!levl[x][y].lit)
    591  1.1      cgd 		return(0);
    592  1.1      cgd 	dx = x - u.ux;	adx = abs(dx);	sdx = sgn(dx);
    593  1.1      cgd 	dy = y - u.uy;  ady = abs(dy);	sdy = sgn(dy);
    594  1.1      cgd 	if(dx == 0 || dy == 0 || adx == ady){
    595  1.1      cgd 		dmax = (dx == 0) ? ady : adx;
    596  1.1      cgd 		for(d = 1; d <= dmax; d++)
    597  1.1      cgd 			if(!rroom(sdx*d,sdy*d))
    598  1.1      cgd 				return(0);
    599  1.1      cgd 		return(1);
    600  1.1      cgd 	} else if(ady > adx){
    601  1.1      cgd 		for(d = 1; d <= ady; d++){
    602  1.1      cgd 			if(!rroom(sdx*( (d*adx)/ady ), sdy*d) ||
    603  1.1      cgd 			   !rroom(sdx*( (d*adx-1)/ady+1 ), sdy*d))
    604  1.1      cgd 				return(0);
    605  1.1      cgd 		}
    606  1.1      cgd 		return(1);
    607  1.1      cgd 	} else {
    608  1.1      cgd 		for(d = 1; d <= adx; d++){
    609  1.1      cgd 			if(!rroom(sdx*d, sdy*( (d*ady)/adx )) ||
    610  1.1      cgd 			   !rroom(sdx*d, sdy*( (d*ady-1)/adx+1 )))
    611  1.1      cgd 				return(0);
    612  1.1      cgd 		}
    613  1.1      cgd 		return(1);
    614  1.1      cgd 	}
    615  1.1      cgd }
    616  1.1      cgd 
    617  1.1      cgd rroom(x,y) register int x,y; {
    618  1.1      cgd 	return(IS_ROOM(levl[u.ux+x][u.uy+y].typ));
    619  1.1      cgd }
    620  1.1      cgd 
    621  1.1      cgd #else
    622  1.1      cgd 
    623  1.1      cgd cansee(x,y) xchar x,y; {
    624  1.1      cgd 	if(Blind || u.uswallow) return(0);
    625  1.1      cgd 	if(dist(x,y) < 3) return(1);
    626  1.1      cgd 	if(levl[x][y].lit && seelx <= x && x <= seehx && seely <= y &&
    627  1.1      cgd 		y <= seehy) return(1);
    628  1.1      cgd 	return(0);
    629  1.1      cgd }
    630  1.1      cgd #endif QUEST
    631  1.1      cgd 
    632  1.1      cgd sgn(a) register int a; {
    633  1.1      cgd 	return((a > 0) ? 1 : (a == 0) ? 0 : -1);
    634  1.1      cgd }
    635  1.1      cgd 
    636  1.1      cgd #ifdef QUEST
    637  1.1      cgd setsee()
    638  1.1      cgd {
    639  1.1      cgd 	register x,y;
    640  1.1      cgd 
    641  1.1      cgd 	if(Blind) {
    642  1.1      cgd 		pru();
    643  1.1      cgd 		return;
    644  1.1      cgd 	}
    645  1.1      cgd 	for(y = u.uy-u.uhorizon; y <= u.uy+u.uhorizon; y++)
    646  1.1      cgd 		for(x = u.ux-u.uhorizon; x <= u.ux+u.uhorizon; x++) {
    647  1.1      cgd 			if(cansee(x,y))
    648  1.1      cgd 				prl(x,y);
    649  1.1      cgd 	}
    650  1.1      cgd }
    651  1.1      cgd 
    652  1.1      cgd #else
    653  1.1      cgd 
    654  1.1      cgd setsee()
    655  1.1      cgd {
    656  1.1      cgd 	register x,y;
    657  1.1      cgd 
    658  1.1      cgd 	if(Blind) {
    659  1.1      cgd 		pru();
    660  1.1      cgd 		return;
    661  1.1      cgd 	}
    662  1.1      cgd 	if(!levl[u.ux][u.uy].lit) {
    663  1.1      cgd 		seelx = u.ux-1;
    664  1.1      cgd 		seehx = u.ux+1;
    665  1.1      cgd 		seely = u.uy-1;
    666  1.1      cgd 		seehy = u.uy+1;
    667  1.1      cgd 	} else {
    668  1.1      cgd 		for(seelx = u.ux; levl[seelx-1][u.uy].lit; seelx--);
    669  1.1      cgd 		for(seehx = u.ux; levl[seehx+1][u.uy].lit; seehx++);
    670  1.1      cgd 		for(seely = u.uy; levl[u.ux][seely-1].lit; seely--);
    671  1.1      cgd 		for(seehy = u.uy; levl[u.ux][seehy+1].lit; seehy++);
    672  1.1      cgd 	}
    673  1.1      cgd 	for(y = seely; y <= seehy; y++)
    674  1.1      cgd 		for(x = seelx; x <= seehx; x++) {
    675  1.1      cgd 			prl(x,y);
    676  1.1      cgd 	}
    677  1.1      cgd 	if(!levl[u.ux][u.uy].lit) seehx = 0; /* seems necessary elsewhere */
    678  1.1      cgd 	else {
    679  1.1      cgd 	    if(seely == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seely-1);
    680  1.1      cgd 	    if(seehy == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seehy+1);
    681  1.1      cgd 	    if(seelx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seelx-1,y);
    682  1.1      cgd 	    if(seehx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seehx+1,y);
    683  1.1      cgd 	}
    684  1.1      cgd }
    685  1.1      cgd #endif QUEST
    686  1.1      cgd 
    687  1.1      cgd nomul(nval)
    688  1.1      cgd register nval;
    689  1.1      cgd {
    690  1.1      cgd 	if(multi < 0) return;
    691  1.1      cgd 	multi = nval;
    692  1.1      cgd 	flags.mv = flags.run = 0;
    693  1.1      cgd }
    694  1.1      cgd 
    695  1.1      cgd abon()
    696  1.1      cgd {
    697  1.1      cgd 	if(u.ustr == 3) return(-3);
    698  1.1      cgd 	else if(u.ustr < 6) return(-2);
    699  1.1      cgd 	else if(u.ustr < 8) return(-1);
    700  1.1      cgd 	else if(u.ustr < 17) return(0);
    701  1.1      cgd 	else if(u.ustr < 69) return(1);	/* up to 18/50 */
    702  1.1      cgd 	else if(u.ustr < 118) return(2);
    703  1.1      cgd 	else return(3);
    704  1.1      cgd }
    705  1.1      cgd 
    706  1.1      cgd dbon()
    707  1.1      cgd {
    708  1.1      cgd 	if(u.ustr < 6) return(-1);
    709  1.1      cgd 	else if(u.ustr < 16) return(0);
    710  1.1      cgd 	else if(u.ustr < 18) return(1);
    711  1.1      cgd 	else if(u.ustr == 18) return(2);	/* up to 18 */
    712  1.1      cgd 	else if(u.ustr < 94) return(3);		/* up to 18/75 */
    713  1.1      cgd 	else if(u.ustr < 109) return(4);	/* up to 18/90 */
    714  1.1      cgd 	else if(u.ustr < 118) return(5);	/* up to 18/99 */
    715  1.1      cgd 	else return(6);
    716  1.1      cgd }
    717  1.1      cgd 
    718  1.1      cgd losestr(num)	/* may kill you; cause may be poison or monster like 'A' */
    719  1.1      cgd register num;
    720  1.1      cgd {
    721  1.1      cgd 	u.ustr -= num;
    722  1.1      cgd 	while(u.ustr < 3) {
    723  1.1      cgd 		u.ustr++;
    724  1.1      cgd 		u.uhp -= 6;
    725  1.1      cgd 		u.uhpmax -= 6;
    726  1.1      cgd 	}
    727  1.1      cgd 	flags.botl = 1;
    728  1.1      cgd }
    729  1.1      cgd 
    730  1.1      cgd losehp(n,knam)
    731  1.1      cgd register n;
    732  1.1      cgd register char *knam;
    733  1.1      cgd {
    734  1.1      cgd 	u.uhp -= n;
    735  1.1      cgd 	if(u.uhp > u.uhpmax)
    736  1.1      cgd 		u.uhpmax = u.uhp;	/* perhaps n was negative */
    737  1.1      cgd 	flags.botl = 1;
    738  1.1      cgd 	if(u.uhp < 1) {
    739  1.1      cgd 		killer = knam;	/* the thing that killed you */
    740  1.1      cgd 		done("died");
    741  1.1      cgd 	}
    742  1.1      cgd }
    743  1.1      cgd 
    744  1.1      cgd losehp_m(n,mtmp)
    745  1.1      cgd register n;
    746  1.1      cgd register struct monst *mtmp;
    747  1.1      cgd {
    748  1.1      cgd 	u.uhp -= n;
    749  1.1      cgd 	flags.botl = 1;
    750  1.1      cgd 	if(u.uhp < 1)
    751  1.1      cgd 		done_in_by(mtmp);
    752  1.1      cgd }
    753  1.1      cgd 
    754  1.1      cgd losexp()	/* hit by V or W */
    755  1.1      cgd {
    756  1.1      cgd 	register num;
    757  1.1      cgd 	extern long newuexp();
    758  1.1      cgd 
    759  1.1      cgd 	if(u.ulevel > 1)
    760  1.1      cgd 		pline("Goodbye level %u.", u.ulevel--);
    761  1.1      cgd 	else
    762  1.1      cgd 		u.uhp = -1;
    763  1.1      cgd 	num = rnd(10);
    764  1.1      cgd 	u.uhp -= num;
    765  1.1      cgd 	u.uhpmax -= num;
    766  1.1      cgd 	u.uexp = newuexp();
    767  1.1      cgd 	flags.botl = 1;
    768  1.1      cgd }
    769  1.1      cgd 
    770  1.1      cgd inv_weight(){
    771  1.1      cgd register struct obj *otmp = invent;
    772  1.1      cgd register int wt = (u.ugold + 500)/1000;
    773  1.1      cgd register int carrcap;
    774  1.1      cgd 	if(Levitation)			/* pugh@cornell */
    775  1.1      cgd 		carrcap = MAX_CARR_CAP;
    776  1.1      cgd 	else {
    777  1.1      cgd 		carrcap = 5*(((u.ustr > 18) ? 20 : u.ustr) + u.ulevel);
    778  1.1      cgd 		if(carrcap > MAX_CARR_CAP) carrcap = MAX_CARR_CAP;
    779  1.1      cgd 		if(Wounded_legs & LEFT_SIDE) carrcap -= 10;
    780  1.1      cgd 		if(Wounded_legs & RIGHT_SIDE) carrcap -= 10;
    781  1.1      cgd 	}
    782  1.1      cgd 	while(otmp){
    783  1.1      cgd 		wt += otmp->owt;
    784  1.1      cgd 		otmp = otmp->nobj;
    785  1.1      cgd 	}
    786  1.1      cgd 	return(wt - carrcap);
    787  1.1      cgd }
    788  1.1      cgd 
    789  1.1      cgd inv_cnt(){
    790  1.1      cgd register struct obj *otmp = invent;
    791  1.1      cgd register int ct = 0;
    792  1.1      cgd 	while(otmp){
    793  1.1      cgd 		ct++;
    794  1.1      cgd 		otmp = otmp->nobj;
    795  1.1      cgd 	}
    796  1.1      cgd 	return(ct);
    797  1.1      cgd }
    798  1.1      cgd 
    799  1.1      cgd long
    800  1.1      cgd newuexp()
    801  1.1      cgd {
    802  1.1      cgd 	return(10*(1L << (u.ulevel-1)));
    803  1.1      cgd }
    804