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