Source:Hack 1.0/hack.search.c

From NetHackWiki
Revision as of 22:36, 3 March 2008 by Kernigh bot (talk | contribs) (Hack 1.0/hack.search.c moved to Source:Hack 1.0/hack.search.c: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to hack.search.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/hack.search.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

Screenshots and source code from Hack are used under the CWI license.

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