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