1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.c - version 1.0.3 */
9 extern char *nomovemsg;
10 extern char *exclam();
11 extern struct obj *addinv();
12 extern boolean hmon();
14 /* called on movement:
15 1. when throwing ball+chain far away
17 3. when walking out of a lit room
26 newsym(u.udisx, u.udisy);
34 for(x = u.ux-1; x < u.ux+2; x++)
35 for(y = u.uy-1; y < u.uy+2; y++) {
36 if(!isok(x, y)) continue;
38 if(!lev->lit && lev->scrsym == '.') {
47 in hack.eat.c: seeoff(0) - blind after eating rotten food
48 in hack.mon.c: seeoff(0) - blinded by a yellow light
49 in hack.mon.c: seeoff(1) - swallowed
50 in hack.do.c: seeoff(0) - blind after drinking potion
51 in hack.do.c: seeoff(1) - go up or down the stairs
52 in hack.trap.c:seeoff(1) - fall through trapdoor
54 seeoff(mode) /* 1 to redo @, 0 to leave them */
55 { /* 1 means misc movement, 0 means blindness */
61 levl[u.udisx][u.udisy].scrsym = news0(u.udisx,u.udisy);
69 for(x = u.ux-1; x < u.ux+2; x++)
70 for(y = u.uy-1; y < u.uy+2; y++) {
71 if(!isok(x, y)) continue;
73 if(!lev->lit && lev->scrsym == '.')
90 pline("You collapse under your load.");
102 } while(!isok(u.ux+u.dx, u.uy+u.dy) ||
103 IS_ROCK(levl[u.ux+u.dx][u.uy+u.dy].typ));
105 if(!isok(u.ux+u.dx, u.uy+u.dy)){
111 ust = &levl[u.ux][u.uy];
114 if(!u.uswallow && (trap = t_at(u.ux+u.dx, u.uy+u.dy)) && trap->tseen)
116 if(u.ustuck && !u.uswallow && (u.ux+u.dx != u.ustuck->mx ||
117 u.uy+u.dy != u.ustuck->my)) {
118 if(dist(u.ustuck->mx, u.ustuck->my) > 2){
119 /* perhaps it fled (or was teleported or ... ) */
122 if(Blind) pline("You cannot escape from it!");
123 else pline("You cannot escape from %s!",
129 if(u.uswallow || (mtmp = m_at(u.ux+u.dx,u.uy+u.dy))) {
134 if(multi < 0) return; /* we just fainted */
136 /* try to attack; note that it might evade */
137 if(attack(u.uswallow ? u.ustuck : mtmp))
140 /* not attacking an animal, so we try to move */
142 if(u.utraptype == TT_PIT) {
143 pline("You are still in a pit.");
146 pline("You are caught in a beartrap.");
147 if((u.dx && u.dy) || !rn2(5)) u.utrap--;
151 tmpr = &levl[u.ux+u.dx][u.uy+u.dy];
152 if(IS_ROCK(tmpr->typ) ||
153 (u.dx && u.dy && (tmpr->typ == DOOR || ust->typ == DOOR))){
158 while(otmp = sobj_at(ENORMOUS_ROCK, u.ux+u.dx, u.uy+u.dy)) {
159 xchar rx = u.ux+2*u.dx, ry = u.uy+2*u.dy;
162 if(isok(rx,ry) && !IS_ROCK(levl[rx][ry].typ) &&
163 (levl[rx][ry].typ != DOOR || !(u.dx && u.dy)) &&
164 !sobj_at(ENORMOUS_ROCK, rx, ry)) {
166 pline("You hear a monster behind the rock.");
167 pline("Perhaps that's why you cannot move it.");
170 if(ttmp = t_at(rx,ry))
173 pline("You push the rock into a pit!");
176 pline("It completely fills the pit!");
179 pline("You push the rock and suddenly it disappears!");
183 if(levl[rx][ry].typ == POOL) {
184 levl[rx][ry].typ = ROOM;
187 pline("You push the rock into the water.");
188 pline("Now you can cross the water!");
195 if(cansee(rx,ry)) atl(rx,ry,otmp->olet);
196 if(Invisible) newsym(u.ux+u.dx, u.uy+u.dy);
198 { static long lastmovetime;
199 /* note: this var contains garbage initially and
201 if(moves > lastmovetime+2 || moves < lastmovetime)
202 pline("With great effort you move the enormous rock.");
203 lastmovetime = moves;
206 pline("You try to move the enormous rock, but in vain.");
208 if((!invent || inv_weight()+90 <= 0) &&
209 (!u.dx || !u.dy || (IS_ROCK(levl[u.ux][u.uy+u.dy].typ)
210 && IS_ROCK(levl[u.ux+u.dx][u.uy].typ)))){
211 pline("However, you can squeeze yourself into a small opening.");
217 if(u.dx && u.dy && IS_ROCK(levl[u.ux][u.uy+u.dy].typ) &&
218 IS_ROCK(levl[u.ux+u.dx][u.uy].typ) &&
219 invent && inv_weight()+40 > 0) {
220 pline("You are carrying too much to get through.");
225 DIST(u.ux+u.dx, u.uy+u.dy, uchain->ox, uchain->oy) > 2){
227 movobj(uchain, u.ux, u.uy);
231 if(DIST(u.ux+u.dx, u.uy+u.dy, uball->ox, uball->oy) < 3){
232 /* leave ball, move chain under/over ball */
233 movobj(uchain, uball->ox, uball->oy);
237 if(inv_weight() + (int) uball->owt/2 > 0) {
238 pline("You cannot %sdrag the heavy iron ball.",
239 invent ? "carry all that and also " : "");
244 movobj(uball, uchain->ox, uchain->oy);
245 unpobj(uball); /* BAH %% */
255 if(tmpr->typ == DOOR ||
256 (xupstair == u.ux && yupstair == u.uy) ||
257 (xdnstair == u.ux && ydnstair == u.uy))
261 if(tmpr->typ == POOL && !Levitation)
262 drown(); /* not necessarily fatal */
276 if(tmpr->typ == DOOR)
277 prl1(u.ux+u.dx,u.uy+u.dy);
278 else if(ust->typ == DOOR)
279 nose1(oldx-u.dx,oldy-u.dy);
282 prl1(u.ux+u.dx,u.uy+u.dy);
285 if(tmpr->lit) setsee();
287 prl1(u.ux+u.dx,u.uy+u.dy);
288 if(tmpr->typ == DOOR) {
298 nose1(oldx-u.dx,oldy-u.dy);
304 if(!flags.nopick) pickup(1);
305 if(trap) dotrap(trap); /* fall into pit, arrow trap, etc. */
307 if(!Blind) read_engr_at(u.ux,u.uy);
314 /* Some dirty programming to get display right */
324 if(!g_at(u.ux,u.uy) && !o_at(u.ux,u.uy)) {
325 pline("There is nothing here to pick up.");
329 pline("You cannot reach the floor.");
339 struct obj *obj, *obj2;
342 if(Levitation) return;
343 while(gold = g_at(u.ux,u.uy)) {
344 pline("%ld gold piece%s.", gold->amount, plur(gold->amount));
345 u.ugold += gold->amount;
348 if(flags.run) nomul(0);
349 if(Invisible) newsym(u.ux,u.uy);
352 /* check for more than one object */
356 for(obj = fobj; obj; obj = obj->nobj)
357 if(obj->ox == u.ux && obj->oy == u.uy)
358 if(!Punished || obj != uchain)
363 pline("There are several objects here.");
366 for(obj = fobj; obj; obj = obj2) {
367 obj2 = obj->nobj; /* perhaps obj will be picked up */
368 if(obj->ox == u.ux && obj->oy == u.uy) {
369 if(flags.run) nomul(0);
371 /* do not pick up uchain */
372 if(Punished && obj == uchain)
378 pline("Pick up %s ? [ynaq]", doname(obj));
379 while(!index("ynaq ", (c = readchar())))
382 if(c == 'n') continue;
383 if(c == 'a') all = 1;
386 if(obj->otyp == DEAD_COCKATRICE && !uarmg){
387 pline("Touching the dead cockatrice is a fatal mistake.");
388 pline("You turn to stone.");
389 killer = "cockatrice cadaver";
393 if(obj->otyp == SCR_SCARE_MONSTER){
394 if(!obj->spe) obj->spe = 1;
396 /* Note: perhaps the 1st pickup failed: you cannot
397 carry anymore, and so we never dropped it -
398 let's assume that treading on it twice also
399 destroys the scroll */
400 pline("The scroll turns to dust as you pick it up.");
406 wt = inv_weight() + obj->owt;
409 /* see how many we can lift */
410 extern struct obj *splitobj();
411 int savequan = obj->quan;
412 int iw = inv_weight();
414 for(qq = 1; qq < savequan; qq++){
416 if(iw + weight(obj) > 0)
419 obj->quan = savequan;
421 /* we can carry qq of them */
422 if(!qq) goto too_heavy;
423 pline("You can only carry %s of the %s lying here.",
424 (qq == 1) ? "one" : "some",
426 (void) splitobj(obj, qq);
427 /* note: obj2 is set already, so we'll never
428 * encounter the other half; if it should be
429 * otherwise then write
430 * obj2 = splitobj(obj,qq);
435 pline("There %s %s here, but %s.",
436 (obj->quan == 1) ? "is" : "are",
438 !invent ? "it is too heavy for you to lift"
439 : "you cannot carry anymore");
443 if(inv_cnt() >= 52) {
444 pline("Your knapsack cannot accomodate anymore items.");
447 if(wt > -5) pline("You have a little trouble lifting");
449 if(Invisible) newsym(u.ux,u.uy);
450 addtobill(obj); /* sets obj->unpaid if necessary */
451 { int pickquan = obj->quan;
453 if(!Blind) obj->dknown = 1; /* this is done by prinv(),
454 but addinv() needs it already for merging */
455 obj = addinv(obj); /* might merge it with other objects */
456 mergquan = obj->quan;
457 obj->quan = pickquan; /* to fool prinv() */
459 obj->quan = mergquan;
465 /* stop running if we see something interesting */
466 /* turn around a corner if that is the only way we can proceed */
467 /* do not turn left or right twice */
469 int x,y,i,x0,y0,m0,i0 = 9;
470 int corrct = 0, noturn = 0;
473 /* suppress "used before set" message */
476 if(Blind || flags.run == 0) return;
477 if(flags.run == 1 && levl[u.ux][u.uy].typ == ROOM) return;
479 if(u.ux0 == u.ux+u.dx && u.uy0 == u.uy+u.dy) goto stop;
481 for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){
482 if(x == u.ux && y == u.uy) continue;
483 if(!levl[x][y].typ) continue;
484 if((mtmp = m_at(x,y)) && !mtmp->mimic &&
485 (!mtmp->minvis || See_invisible)){
486 if(!mtmp->mtame || (x == u.ux+u.dx && y == u.uy+u.dy))
488 } else mtmp = 0; /* invisible M cannot influence us */
489 if(x == u.ux-u.dx && y == u.uy-u.dy) continue;
490 switch(levl[x][y].scrsym){
497 if(x != u.ux && y != u.uy) break;
498 if(flags.run != 1) goto stop;
499 /* fall into next case */
502 if(flags.run == 1 || flags.run == 3) {
503 i = DIST(x,y,u.ux+u.dx,u.uy+u.dy);
505 if(corrct == 1 && DIST(x,y,x0,y0) != 1)
517 if(flags.run == 1) goto corr; /* if you must */
518 if(x == u.ux+u.dx && y == u.uy+u.dy) goto stop;
520 default: /* e.g. objects or trap or stairs */
521 if(flags.run == 1) goto corr;
522 if(mtmp) break; /* d */
529 if(corrct > 0 && (flags.run == 4 || flags.run == 5)) goto stop;
531 if(corrct > 1 && flags.run == 2) goto stop;
532 if((flags.run == 1 || flags.run == 3) && !noturn && !m0 && i0 &&
533 (corrct == 1 || (corrct == 2 && i0 == 1))) {
534 /* make sure that we do not turn too far */
536 if(u.dx == y0-u.uy && u.dy == u.ux-x0)
537 i = 2; /* straight turn right */
539 i = -2; /* straight turn left */
540 } else if(u.dx && u.dy) {
541 if((u.dx == u.dy && y0 == u.uy) ||
542 (u.dx != u.dy && y0 != u.uy))
543 i = -1; /* half turn left */
545 i = 1; /* half turn right */
547 if((x0-u.ux == y0-u.uy && !u.dy) ||
548 (x0-u.ux != y0-u.uy && u.dy))
549 i = 1; /* half turn right */
551 i = -1; /* half turn left */
553 i += u.last_str_turn;
554 if(i <= 2 && i >= -2) {
556 u.dx = x0-u.ux, u.dy = y0-u.uy;
561 /* something like lookaround, but we are not running */
562 /* react only to monsters that might hit us */
567 for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){
568 if(x == u.ux && y == u.uy) continue;
569 if((mtmp = m_at(x,y)) && !mtmp->mimic && !mtmp->mtame &&
570 !mtmp->mpeaceful && !index("Ea", mtmp->data->mlet) &&
571 !mtmp->mfroz && !mtmp->msleep && /* aplvax!jcn */
572 (!mtmp->minvis || See_invisible))
579 cansee(x,y) xchar x,y; {
580 int dx,dy,adx,ady,sdx,sdy,dmax,d;
582 if(!isok(x,y)) return(0);
585 if(d > u.uhorizon*u.uhorizon) return(0);
588 dx = x - u.ux; adx = abs(dx); sdx = sgn(dx);
589 dy = y - u.uy; ady = abs(dy); sdy = sgn(dy);
590 if(dx == 0 || dy == 0 || adx == ady){
591 dmax = (dx == 0) ? ady : adx;
592 for(d = 1; d <= dmax; d++)
593 if(!rroom(sdx*d,sdy*d))
596 } else if(ady > adx){
597 for(d = 1; d <= ady; d++){
598 if(!rroom(sdx*( (d*adx)/ady ), sdy*d) ||
599 !rroom(sdx*( (d*adx-1)/ady+1 ), sdy*d))
604 for(d = 1; d <= adx; d++){
605 if(!rroom(sdx*d, sdy*( (d*ady)/adx )) ||
606 !rroom(sdx*d, sdy*( (d*ady-1)/adx+1 )))
613 rroom(x,y) int x,y; {
614 return(IS_ROOM(levl[u.ux+x][u.uy+y].typ));
619 cansee(x,y) xchar x,y; {
620 if(Blind || u.uswallow) return(0);
621 if(dist(x,y) < 3) return(1);
622 if(levl[x][y].lit && seelx <= x && x <= seehx && seely <= y &&
623 y <= seehy) return(1);
629 return((a > 0) ? 1 : (a == 0) ? 0 : -1);
641 for(y = u.uy-u.uhorizon; y <= u.uy+u.uhorizon; y++)
642 for(x = u.ux-u.uhorizon; x <= u.ux+u.uhorizon; x++) {
658 if(!levl[u.ux][u.uy].lit) {
664 for(seelx = u.ux; levl[seelx-1][u.uy].lit; seelx--);
665 for(seehx = u.ux; levl[seehx+1][u.uy].lit; seehx++);
666 for(seely = u.uy; levl[u.ux][seely-1].lit; seely--);
667 for(seehy = u.uy; levl[u.ux][seehy+1].lit; seehy++);
669 for(y = seely; y <= seehy; y++)
670 for(x = seelx; x <= seehx; x++) {
673 if(!levl[u.ux][u.uy].lit) seehx = 0; /* seems necessary elsewhere */
675 if(seely == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seely-1);
676 if(seehy == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seehy+1);
677 if(seelx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seelx-1,y);
678 if(seehx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seehx+1,y);
686 if(multi < 0) return;
688 flags.mv = flags.run = 0;
693 if(u.ustr == 3) return(-3);
694 else if(u.ustr < 6) return(-2);
695 else if(u.ustr < 8) return(-1);
696 else if(u.ustr < 17) return(0);
697 else if(u.ustr < 69) return(1); /* up to 18/50 */
698 else if(u.ustr < 118) return(2);
704 if(u.ustr < 6) return(-1);
705 else if(u.ustr < 16) return(0);
706 else if(u.ustr < 18) return(1);
707 else if(u.ustr == 18) return(2); /* up to 18 */
708 else if(u.ustr < 94) return(3); /* up to 18/75 */
709 else if(u.ustr < 109) return(4); /* up to 18/90 */
710 else if(u.ustr < 118) return(5); /* up to 18/99 */
714 losestr(num) /* may kill you; cause may be poison or monster like 'A' */
732 u.uhpmax = u.uhp; /* perhaps n was negative */
735 killer = knam; /* the thing that killed you */
750 losexp() /* hit by V or W */
753 extern long newuexp();
756 pline("Goodbye level %u.", u.ulevel--);
767 struct obj *otmp = invent;
768 int wt = (u.ugold + 500)/1000;
770 if(Levitation) /* pugh@cornell */
771 carrcap = MAX_CARR_CAP;
773 carrcap = 5*(((u.ustr > 18) ? 20 : u.ustr) + u.ulevel);
774 if(carrcap > MAX_CARR_CAP) carrcap = MAX_CARR_CAP;
775 if(Wounded_legs & LEFT_SIDE) carrcap -= 10;
776 if(Wounded_legs & RIGHT_SIDE) carrcap -= 10;
782 return(wt - carrcap);
786 struct obj *otmp = invent;
798 return(10*(1L << (u.ulevel-1)));