1*3ea4a95cSchristos /* $NetBSD: hack.search.c,v 1.4 1997/10/19 16:58:59 christos Exp $ */ 2*3ea4a95cSchristos 3210cab45Smycroft /* 4210cab45Smycroft * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. 5210cab45Smycroft */ 6210cab45Smycroft 7*3ea4a95cSchristos #include <sys/cdefs.h> 8210cab45Smycroft #ifndef lint 9*3ea4a95cSchristos __RCSID("$NetBSD: hack.search.c,v 1.4 1997/10/19 16:58:59 christos Exp $"); 10210cab45Smycroft #endif /* not lint */ 1161f28255Scgd 1261f28255Scgd #include "hack.h" 13*3ea4a95cSchristos #include "extern.h" 1461f28255Scgd 15*3ea4a95cSchristos int 16*3ea4a95cSchristos findit() 17*3ea4a95cSchristos { /* returns number of things found */ 1861f28255Scgd int num; 19*3ea4a95cSchristos xchar zx, zy; 20*3ea4a95cSchristos struct trap *ttmp; 21*3ea4a95cSchristos struct monst *mtmp; 2261f28255Scgd xchar lx, hx, ly, hy; 2361f28255Scgd 24*3ea4a95cSchristos if (u.uswallow) 25*3ea4a95cSchristos return (0); 2661f28255Scgd for (lx = u.ux; (num = levl[lx - 1][u.uy].typ) && num != CORR; lx--); 2761f28255Scgd for (hx = u.ux; (num = levl[hx + 1][u.uy].typ) && num != CORR; hx++); 2861f28255Scgd for (ly = u.uy; (num = levl[u.ux][ly - 1].typ) && num != CORR; ly--); 2961f28255Scgd for (hy = u.uy; (num = levl[u.ux][hy + 1].typ) && num != CORR; hy++); 3061f28255Scgd num = 0; 3161f28255Scgd for (zy = ly; zy <= hy; zy++) 3261f28255Scgd for (zx = lx; zx <= hx; zx++) { 3361f28255Scgd if (levl[zx][zy].typ == SDOOR) { 3461f28255Scgd levl[zx][zy].typ = DOOR; 3561f28255Scgd atl(zx, zy, '+'); 3661f28255Scgd num++; 3761f28255Scgd } else if (levl[zx][zy].typ == SCORR) { 3861f28255Scgd levl[zx][zy].typ = CORR; 3961f28255Scgd atl(zx, zy, CORR_SYM); 4061f28255Scgd num++; 41*3ea4a95cSchristos } else if ((ttmp = t_at(zx, zy)) != NULL) { 4261f28255Scgd if (ttmp->ttyp == PIERC) { 4361f28255Scgd (void) makemon(PM_PIERCER, zx, zy); 4461f28255Scgd num++; 4561f28255Scgd deltrap(ttmp); 4661f28255Scgd } else if (!ttmp->tseen) { 4761f28255Scgd ttmp->tseen = 1; 4861f28255Scgd if (!vism_at(zx, zy)) 4961f28255Scgd atl(zx, zy, '^'); 5061f28255Scgd num++; 5161f28255Scgd } 52*3ea4a95cSchristos } else if ((mtmp = m_at(zx, zy)) != NULL) 53*3ea4a95cSchristos if (mtmp->mimic) { 5461f28255Scgd seemimic(mtmp); 5561f28255Scgd num++; 5661f28255Scgd } 5761f28255Scgd } 5861f28255Scgd return (num); 5961f28255Scgd } 6061f28255Scgd 61*3ea4a95cSchristos int 6261f28255Scgd dosearch() 6361f28255Scgd { 64*3ea4a95cSchristos xchar x, y; 65*3ea4a95cSchristos struct trap *trap; 66*3ea4a95cSchristos struct monst *mtmp; 6761f28255Scgd 6861f28255Scgd if (u.uswallow) 6961f28255Scgd pline("What are you looking for? The exit?"); 7061f28255Scgd else 7161f28255Scgd for (x = u.ux - 1; x < u.ux + 2; x++) 72*3ea4a95cSchristos for (y = u.uy - 1; y < u.uy + 2; y++) 73*3ea4a95cSchristos if (x != u.ux || y != u.uy) { 7461f28255Scgd if (levl[x][y].typ == SDOOR) { 75*3ea4a95cSchristos if (rn2(7)) 76*3ea4a95cSchristos continue; 7761f28255Scgd levl[x][y].typ = DOOR; 7861f28255Scgd levl[x][y].seen = 0; /* force prl */ 7961f28255Scgd prl(x, y); 8061f28255Scgd nomul(0); 8161f28255Scgd } else if (levl[x][y].typ == SCORR) { 82*3ea4a95cSchristos if (rn2(7)) 83*3ea4a95cSchristos continue; 8461f28255Scgd levl[x][y].typ = CORR; 8561f28255Scgd levl[x][y].seen = 0; /* force prl */ 8661f28255Scgd prl(x, y); 8761f28255Scgd nomul(0); 8861f28255Scgd } else { 89*3ea4a95cSchristos /* 90*3ea4a95cSchristos * Be careful not to find 91*3ea4a95cSchristos * anything in an SCORR or 92*3ea4a95cSchristos * SDOOR 93*3ea4a95cSchristos */ 94*3ea4a95cSchristos if ((mtmp = m_at(x, y)) != NULL) 95*3ea4a95cSchristos if (mtmp->mimic) { 9661f28255Scgd seemimic(mtmp); 9761f28255Scgd pline("You find a mimic."); 9861f28255Scgd return (1); 9961f28255Scgd } 10061f28255Scgd for (trap = ftrap; trap; trap = trap->ntrap) 10161f28255Scgd if (trap->tx == x && trap->ty == y && 10261f28255Scgd !trap->tseen && !rn2(8)) { 10361f28255Scgd nomul(0); 10461f28255Scgd pline("You find a%s.", traps[trap->ttyp]); 10561f28255Scgd if (trap->ttyp == PIERC) { 10661f28255Scgd deltrap(trap); 10761f28255Scgd (void) makemon(PM_PIERCER, x, y); 10861f28255Scgd return (1); 10961f28255Scgd } 11061f28255Scgd trap->tseen = 1; 111*3ea4a95cSchristos if (!vism_at(x, y)) 112*3ea4a95cSchristos atl(x, y, '^'); 11361f28255Scgd } 11461f28255Scgd } 11561f28255Scgd } 11661f28255Scgd return (1); 11761f28255Scgd } 11861f28255Scgd 119*3ea4a95cSchristos int 120*3ea4a95cSchristos doidtrap() 121*3ea4a95cSchristos { 122*3ea4a95cSchristos struct trap *trap; 123*3ea4a95cSchristos int x, y; 124*3ea4a95cSchristos if (!getdir(1)) 125*3ea4a95cSchristos return (0); 12661f28255Scgd x = u.ux + u.dx; 12761f28255Scgd y = u.uy + u.dy; 12861f28255Scgd for (trap = ftrap; trap; trap = trap->ntrap) 12961f28255Scgd if (trap->tx == x && trap->ty == y && trap->tseen) { 13061f28255Scgd if (u.dz) 13161f28255Scgd if ((u.dz < 0) != (!xdnstair && trap->ttyp == TRAPDOOR)) 13261f28255Scgd continue; 13361f28255Scgd pline("That is a%s.", traps[trap->ttyp]); 13461f28255Scgd return (0); 13561f28255Scgd } 13661f28255Scgd pline("I can't see a trap there."); 13761f28255Scgd return (0); 13861f28255Scgd } 13961f28255Scgd 140*3ea4a95cSchristos void 14161f28255Scgd wakeup(mtmp) 142*3ea4a95cSchristos struct monst *mtmp; 14361f28255Scgd { 14461f28255Scgd mtmp->msleep = 0; 14561f28255Scgd setmangry(mtmp); 146*3ea4a95cSchristos if (mtmp->mimic) 147*3ea4a95cSchristos seemimic(mtmp); 14861f28255Scgd } 14961f28255Scgd 15061f28255Scgd /* NOTE: we must check if(mtmp->mimic) before calling this routine */ 151*3ea4a95cSchristos void 15261f28255Scgd seemimic(mtmp) 153*3ea4a95cSchristos struct monst *mtmp; 15461f28255Scgd { 15561f28255Scgd mtmp->mimic = 0; 15661f28255Scgd mtmp->mappearance = 0; 15761f28255Scgd unpmon(mtmp); 15861f28255Scgd pmon(mtmp); 15961f28255Scgd } 160