kernel - support dummy reallocblks in devfs
[dragonfly.git] / games / hack / hack.search.c
blobb1dd291fb9bb22049ef3d43585f1d581c0e62a9a
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.search.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.search.c,v 1.3 1999/11/16 02:57:11 billf Exp $ */
4 /* $DragonFly: src/games/hack/hack.search.c,v 1.3 2006/08/21 19:45:32 pavalos Exp $ */
6 #include "hack.h"
8 int
9 findit(void) /* returns number of things found */
11 int num;
12 xchar zx, zy;
13 struct trap *ttmp;
14 struct monst *mtmp;
15 xchar lx, hx, ly, hy;
17 if (u.uswallow)
18 return (0);
19 for (lx = u.ux; (num = levl[lx - 1][u.uy].typ) && num != CORR; lx--) ;
20 for (hx = u.ux; (num = levl[hx + 1][u.uy].typ) && num != CORR; hx++) ;
21 for (ly = u.uy; (num = levl[u.ux][ly - 1].typ) && num != CORR; ly--) ;
22 for (hy = u.uy; (num = levl[u.ux][hy + 1].typ) && num != CORR; hy++) ;
23 num = 0;
24 for (zy = ly; zy <= hy; zy++)
25 for (zx = lx; zx <= hx; zx++) {
26 if (levl[zx][zy].typ == SDOOR) {
27 levl[zx][zy].typ = DOOR;
28 atl(zx, zy, '+');
29 num++;
30 } else if (levl[zx][zy].typ == SCORR) {
31 levl[zx][zy].typ = CORR;
32 atl(zx, zy, CORR_SYM);
33 num++;
34 } else if ((ttmp = t_at(zx, zy)) != NULL) {
35 if (ttmp->ttyp == PIERC) {
36 makemon(PM_PIERCER, zx, zy);
37 num++;
38 deltrap(ttmp);
39 } else if (!ttmp->tseen) {
40 ttmp->tseen = 1;
41 if (!vism_at(zx, zy))
42 atl(zx, zy, '^');
43 num++;
45 } else if ((mtmp = m_at(zx, zy)) != NULL)
46 if (mtmp->mimic) {
47 seemimic(mtmp);
48 num++;
51 return (num);
54 int
55 dosearch(void)
57 xchar x, y;
58 struct trap *trap;
59 struct monst *mtmp;
61 if (u.uswallow)
62 pline("What are you looking for? The exit?");
63 else
64 for (x = u.ux - 1; x < u.ux + 2; x++)
65 for (y = u.uy - 1; y < u.uy + 2; y++)
66 if (x != u.ux || y != u.uy) {
67 if (levl[x][y].typ == SDOOR) {
68 if (rn2(7))
69 continue;
70 levl[x][y].typ = DOOR;
71 levl[x][y].seen = 0; /* force prl */
72 prl(x, y);
73 nomul(0);
74 } else if (levl[x][y].typ == SCORR) {
75 if (rn2(7))
76 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)))
84 if (mtmp->mimic) {
85 seemimic(mtmp);
86 pline("You find a mimic.");
87 return (1);
89 for (trap = ftrap; trap; trap = trap->ntrap)
90 if (trap->tx == x && trap->ty == y &&
91 !trap->tseen && !rn2(8)) {
92 nomul(0);
93 pline("You find a%s.", traps[trap->ttyp]);
94 if (trap->ttyp == PIERC) {
95 deltrap(trap);
96 makemon(PM_PIERCER, x, y);
97 return (1);
99 trap->tseen = 1;
100 if (!vism_at(x, y))
101 atl(x, y, '^');
105 return (1);
109 doidtrap(void)
111 struct trap *trap;
112 int x, y;
114 if (!getdir(1))
115 return (0);
116 x = u.ux + u.dx;
117 y = u.uy + u.dy;
118 for (trap = ftrap; trap; trap = trap->ntrap)
119 if (trap->tx == x && trap->ty == y && trap->tseen) {
120 if (u.dz)
121 if ((u.dz < 0) != (!xdnstair && trap->ttyp == TRAPDOOR))
122 continue;
123 pline("That is a%s.", traps[trap->ttyp]);
124 return (0);
126 pline("I can't see a trap there.");
127 return (0);
130 void
131 wakeup(struct monst *mtmp)
133 mtmp->msleep = 0;
134 setmangry(mtmp);
135 if (mtmp->mimic)
136 seemimic(mtmp);
139 /* NOTE: we must check if (mtmp->mimic) before calling this routine */
140 void
141 seemimic(struct monst *mtmp)
143 mtmp->mimic = 0;
144 mtmp->mappearance = 0;
145 unpmon(mtmp);
146 pmon(mtmp);