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