Home | History | Annotate | Line # | Download | only in hack
hack.search.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.search.c,v 1.2 1993/08/02 17:19:22 mycroft Exp $";
      7  1.2  mycroft #endif /* not lint */
      8  1.1      cgd 
      9  1.1      cgd #include "hack.h"
     10  1.1      cgd 
     11  1.1      cgd extern struct monst *makemon();
     12  1.1      cgd 
     13  1.1      cgd findit()	/* returns number of things found */
     14  1.1      cgd {
     15  1.1      cgd 	int num;
     16  1.1      cgd 	register xchar zx,zy;
     17  1.1      cgd 	register struct trap *ttmp;
     18  1.1      cgd 	register struct monst *mtmp;
     19  1.1      cgd 	xchar lx,hx,ly,hy;
     20  1.1      cgd 
     21  1.1      cgd 	if(u.uswallow) return(0);
     22  1.1      cgd 	for(lx = u.ux; (num = levl[lx-1][u.uy].typ) && num != CORR; lx--) ;
     23  1.1      cgd 	for(hx = u.ux; (num = levl[hx+1][u.uy].typ) && num != CORR; hx++) ;
     24  1.1      cgd 	for(ly = u.uy; (num = levl[u.ux][ly-1].typ) && num != CORR; ly--) ;
     25  1.1      cgd 	for(hy = u.uy; (num = levl[u.ux][hy+1].typ) && num != CORR; hy++) ;
     26  1.1      cgd 	num = 0;
     27  1.1      cgd 	for(zy = ly; zy <= hy; zy++)
     28  1.1      cgd 		for(zx = lx; zx <= hx; zx++) {
     29  1.1      cgd 			if(levl[zx][zy].typ == SDOOR) {
     30  1.1      cgd 				levl[zx][zy].typ = DOOR;
     31  1.1      cgd 				atl(zx, zy, '+');
     32  1.1      cgd 				num++;
     33  1.1      cgd 			} else if(levl[zx][zy].typ == SCORR) {
     34  1.1      cgd 				levl[zx][zy].typ = CORR;
     35  1.1      cgd 				atl(zx, zy, CORR_SYM);
     36  1.1      cgd 				num++;
     37  1.1      cgd 			} else if(ttmp = t_at(zx, zy)) {
     38  1.1      cgd 				if(ttmp->ttyp == PIERC){
     39  1.1      cgd 					(void) makemon(PM_PIERCER, zx, zy);
     40  1.1      cgd 					num++;
     41  1.1      cgd 					deltrap(ttmp);
     42  1.1      cgd 				} else if(!ttmp->tseen) {
     43  1.1      cgd 					ttmp->tseen = 1;
     44  1.1      cgd 					if(!vism_at(zx, zy))
     45  1.1      cgd 						atl(zx,zy,'^');
     46  1.1      cgd 					num++;
     47  1.1      cgd 				}
     48  1.1      cgd 			} else if(mtmp = m_at(zx,zy)) if(mtmp->mimic){
     49  1.1      cgd 				seemimic(mtmp);
     50  1.1      cgd 				num++;
     51  1.1      cgd 			}
     52  1.1      cgd 		}
     53  1.1      cgd 	return(num);
     54  1.1      cgd }
     55  1.1      cgd 
     56  1.1      cgd dosearch()
     57  1.1      cgd {
     58  1.1      cgd 	register xchar x,y;
     59  1.1      cgd 	register struct trap *trap;
     60  1.1      cgd 	register struct monst *mtmp;
     61  1.1      cgd 
     62  1.1      cgd 	if(u.uswallow)
     63  1.1      cgd 		pline("What are you looking for? The exit?");
     64  1.1      cgd 	else
     65  1.1      cgd 	for(x = u.ux-1; x < u.ux+2; x++)
     66  1.1      cgd 	for(y = u.uy-1; y < u.uy+2; y++) if(x != u.ux || y != u.uy) {
     67  1.1      cgd 		if(levl[x][y].typ == SDOOR) {
     68  1.1      cgd 			if(rn2(7)) continue;
     69  1.1      cgd 			levl[x][y].typ = DOOR;
     70  1.1      cgd 			levl[x][y].seen = 0;	/* force prl */
     71  1.1      cgd 			prl(x,y);
     72  1.1      cgd 			nomul(0);
     73  1.1      cgd 		} else if(levl[x][y].typ == SCORR) {
     74  1.1      cgd 			if(rn2(7)) continue;
     75  1.1      cgd 			levl[x][y].typ = CORR;
     76  1.1      cgd 			levl[x][y].seen = 0;	/* force prl */
     77  1.1      cgd 			prl(x,y);
     78  1.1      cgd 			nomul(0);
     79  1.1      cgd 		} else {
     80  1.1      cgd 		/* Be careful not to find anything in an SCORR or SDOOR */
     81  1.1      cgd 			if(mtmp = m_at(x,y)) if(mtmp->mimic){
     82  1.1      cgd 				seemimic(mtmp);
     83  1.1      cgd 				pline("You find a mimic.");
     84  1.1      cgd 				return(1);
     85  1.1      cgd 			}
     86  1.1      cgd 			for(trap = ftrap; trap; trap = trap->ntrap)
     87  1.1      cgd 			if(trap->tx == x && trap->ty == y &&
     88  1.1      cgd 			   !trap->tseen && !rn2(8)) {
     89  1.1      cgd 				nomul(0);
     90  1.1      cgd 				pline("You find a%s.", traps[trap->ttyp]);
     91  1.1      cgd 				if(trap->ttyp == PIERC) {
     92  1.1      cgd 					deltrap(trap);
     93  1.1      cgd 					(void) makemon(PM_PIERCER,x,y);
     94  1.1      cgd 					return(1);
     95  1.1      cgd 				}
     96  1.1      cgd 				trap->tseen = 1;
     97  1.1      cgd 				if(!vism_at(x,y)) atl(x,y,'^');
     98  1.1      cgd 			}
     99  1.1      cgd 		}
    100  1.1      cgd 	}
    101  1.1      cgd 	return(1);
    102  1.1      cgd }
    103  1.1      cgd 
    104  1.1      cgd doidtrap() {
    105  1.1      cgd register struct trap *trap;
    106  1.1      cgd register int x,y;
    107  1.1      cgd 	if(!getdir(1)) return(0);
    108  1.1      cgd 	x = u.ux + u.dx;
    109  1.1      cgd 	y = u.uy + u.dy;
    110  1.1      cgd 	for(trap = ftrap; trap; trap = trap->ntrap)
    111  1.1      cgd 		if(trap->tx == x && trap->ty == y && trap->tseen) {
    112  1.1      cgd 		    if(u.dz)
    113  1.1      cgd 			if((u.dz < 0) != (!xdnstair && trap->ttyp == TRAPDOOR))
    114  1.1      cgd 			    continue;
    115  1.1      cgd 		    pline("That is a%s.", traps[trap->ttyp]);
    116  1.1      cgd 		    return(0);
    117  1.1      cgd 		}
    118  1.1      cgd 	pline("I can't see a trap there.");
    119  1.1      cgd 	return(0);
    120  1.1      cgd }
    121  1.1      cgd 
    122  1.1      cgd wakeup(mtmp)
    123  1.1      cgd register struct monst *mtmp;
    124  1.1      cgd {
    125  1.1      cgd 	mtmp->msleep = 0;
    126  1.1      cgd 	setmangry(mtmp);
    127  1.1      cgd 	if(mtmp->mimic) seemimic(mtmp);
    128  1.1      cgd }
    129  1.1      cgd 
    130  1.1      cgd /* NOTE: we must check if(mtmp->mimic) before calling this routine */
    131  1.1      cgd seemimic(mtmp)
    132  1.1      cgd register struct monst *mtmp;
    133  1.1      cgd {
    134  1.1      cgd 		mtmp->mimic = 0;
    135  1.1      cgd 		mtmp->mappearance = 0;
    136  1.1      cgd 		unpmon(mtmp);
    137  1.1      cgd 		pmon(mtmp);
    138  1.1      cgd }
    139