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