Fandom

Wikihack

Source:NetHack 1.3d/search.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

Also on Fandom

Random Wiki