Wikia

Wikihack

Source:NetHack 1.4f/search.c

2,032pages on
this wiki
Talk0

Below is the full text to search.c from the source code of NetHack 1.4f. To link to a particular line, write [[NetHack 1.4f/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.4	87/08/08
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.   				atl(zx, zy, DOOR_SYM);
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)) {
35.   				if(ttmp->ttyp == PIERC){
36.   					(void) 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,TRAP_SYM);
43.   					num++;
44.   				}
45.   			} else if(mtmp = m_at(zx,zy)) if(mtmp->mimic){
46.   				seemimic(mtmp);
47.   				num++;
48.   			}
49.   		}
50.   	return(num);
51.   }
52.   
53.   dosearch()
54.   {
55.   	register xchar x,y;
56.   	register struct trap *trap;
57.   	register struct monst *mtmp;
58.   
59.   	if(u.uswallow)
60.   		pline("What are you looking for? The exit?");
61.   	else
62.   	for(x = u.ux-1; x < u.ux+2; x++)
63.   	for(y = u.uy-1; y < u.uy+2; y++) if(x != u.ux || y != u.uy) {
64.   		if(levl[x][y].typ == SDOOR) {
65.   			if(rn2(7)) continue;
66.   			levl[x][y].typ = DOOR;
67.   			levl[x][y].seen = 0;	/* force prl */
68.   			prl(x,y);
69.   			nomul(0);
70.   		} else if(levl[x][y].typ == SCORR) {
71.   			if(rn2(7)) continue;
72.   			levl[x][y].typ = CORR;
73.   			levl[x][y].seen = 0;	/* force prl */
74.   			prl(x,y);
75.   			nomul(0);
76.   		} else {
77.   		/* Be careful not to find anything in an SCORR or SDOOR */
78.   			if(mtmp = m_at(x,y)) if(mtmp->mimic){
79.   				seemimic(mtmp);
80.   				pline("You find %s.",defmonnam(mtmp));
81.   				return(1);
82.   			}
83.   			for(trap = ftrap; trap; trap = trap->ntrap)
84.   			if(trap->tx == x && trap->ty == y &&
85.   			   !trap->tseen && !rn2(8)) {
86.   				nomul(0);
87.   				if (trap->ttyp != PIERC)
88.   				pline("You find a%s.", traps[Hallucination ?
89.   				rn2(TRAPNUM-2) : trap->ttyp ]);
90.   
91.   				if(trap->ttyp == PIERC) {
92.   				    deltrap(trap);
93.   				    if((mtmp=makemon(PM_PIERCER,x,y)))
94.   					pline("You find %s.", defmonnam(mtmp));
95.   				    return(1);
96.   				}
97.   				trap->tseen = 1;
98.   				if(!vism_at(x,y)) atl(x,y,TRAP_SYM);
99.   			}
100.  		}
101.  	}
102.  	return(1);
103.  }
104.  
105.  doidtrap() {
106.  register struct trap *trap;
107.  register int x,y;
108.  	if(!getdir(1)) return(0);
109.  	x = u.ux + u.dx;
110.  	y = u.uy + u.dy;
111.  	for(trap = ftrap; trap; trap = trap->ntrap)
112.  		if(trap->tx == x && trap->ty == y && trap->tseen) {
113.  		    if(u.dz)
114.  			if((u.dz < 0) != (!xdnstair && trap->ttyp == TRAPDOOR))
115.  			    continue;
116.  			pline("That is a%s.",traps[ Hallucination ? rn2(TRAPNUM-2) :
117.  			trap->ttyp]);
118.  		    return(0);
119.  		}
120.  	pline("I can't see a trap there.");
121.  	return(0);
122.  }
123.  
124.  wakeup(mtmp)
125.  register struct monst *mtmp;
126.  {
127.  	mtmp->msleep = 0;
128.  	setmangry(mtmp);
129.  	if(mtmp->mimic) seemimic(mtmp);
130.  }
131.  
132.  /* NOTE: we must check if(mtmp->mimic) before calling this routine */
133.  seemimic(mtmp)
134.  register struct monst *mtmp;
135.  {
136.  		mtmp->mimic = 0;
137.  		mtmp->mappearance = 0;
138.  		unpmon(mtmp);
139.  		pmon(mtmp);
140.  }

Around Wikia's network

Random Wiki