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