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