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