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