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