Source:NetHack 3.0.0/search.c

From NetHackWiki
Jump to navigation Jump to search

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

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

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1.    /*	SCCS Id: @(#)search.c	3.0	88/04/13
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include "hack.h"
6.    #ifdef NAMED_ITEMS
7.    #  include "artifact.h"
8.    #endif
9.    
10.   static void
11.   findone(zx,zy,num)
12.   xchar zx,zy;
13.   int *num;
14.   {
15.   	register struct trap *ttmp;
16.   	register struct monst *mtmp;
17.   
18.   	if(levl[zx][zy].typ == SDOOR) {
19.   		levl[zx][zy].typ = DOOR;
20.   		levl[zx][zy].seen = 0;
21.   		prl(zx, zy);
22.   		(*num)++;
23.   	} else if(levl[zx][zy].typ == SCORR) {
24.   		levl[zx][zy].typ = CORR;
25.   		levl[zx][zy].seen = 0;
26.   		prl(zx, zy);
27.   		(*num)++;
28.   	} else if(ttmp = t_at(zx, zy)) {
29.   		if(ttmp->ttyp == MONST_TRAP) {
30.   			(void) makemon(&mons[ttmp->pm], zx, zy);
31.   			(*num)++;
32.   			deltrap(ttmp);
33.   		} else if(!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) {
34.   			ttmp->tseen = 1;
35.   			if(!vism_at(zx, zy))
36.   		    atl(zx,zy,(char)((ttmp->ttyp==WEB) ? WEB_SYM : TRAP_SYM));
37.   			(*num)++;
38.   		}
39.   	} else if(levl[zx][zy].mmask) {
40.   		mtmp = m_at(zx,zy);
41.   		if(mtmp->mimic) {
42.   		        seemimic(mtmp);
43.   		        (*num)++;
44.   		}
45.   	}
46.   }
47.   
48.   int
49.   findit()	/* returns number of things found */
50.   {
51.   	int num;
52.   	register xchar zx,zy;
53.   	xchar lx,hx,ly,hy;
54.   	xchar lx2,hx2,ly2,hy2;
55.   
56.   	if(u.uswallow) return(0);
57.   	if(inroom(u.ux,u.uy) < 0) {
58.   		lx = u.ux - 1;
59.   		hx = u.ux + 1;
60.   		ly = u.uy - 1;
61.   		hy = u.uy + 1;
62.   		lx2 = ly2 = 1;
63.   		hx2 = hy2 = 0;
64.   	} else
65.   		getcorners(&lx,&hx,&ly,&hy,&lx2,&hx2,&ly2,&hy2);
66.   	num = 0;
67.   	for(zy = ly; zy <= hy; zy++)
68.   		for(zx = lx; zx <= hx; zx++)
69.   			findone(zx,zy,&num);
70.   	for(zy = ly2; zy <= hy2; zy++)
71.   		for(zx = lx2; zx <= hx2; zx++)
72.   			findone(zx,zy,&num);
73.   	return(num);
74.   }
75.   
76.   int
77.   dosearch()
78.   {
79.   	return(dosearch0(0));
80.   }
81.   
82.   int
83.   dosearch0(aflag)
84.   register int aflag;
85.   {
86.   	register xchar x, y;
87.   	register struct trap *trap;
88.   	register struct monst *mtmp;
89.   	register struct obj *otmp;
90.   
91.   #ifdef NAMED_ITEMS
92.   	int fund = (spec_ability(uwep, SPFX_SEARCH)) ?
93.   			((uwep->spe > 5) ? 5 : uwep->spe) : 0;
94.   #endif /* NAMED_ITEMS */
95.   
96.   	if(u.uswallow) {
97.   		if (!aflag)
98.   			pline("What are you looking for?  The exit?");
99.   	} else
100.  	    for(x = u.ux-1; x < u.ux+2; x++)
101.  	      for(y = u.uy-1; y < u.uy+2; y++)
102.  		if(x != u.ux || y != u.uy) {
103.  		    if(levl[x][y].typ == SDOOR) {
104.  #ifdef NAMED_ITEMS
105.  			if(rnl(7-fund)) continue;
106.  #else
107.  			if(rnl(7)) continue;
108.  #endif
109.  			levl[x][y].typ = DOOR;
110.  			levl[x][y].seen = 0;	/* force prl */
111.  			nomul(0);
112.  			prl(x,y);
113.  		    } else if(levl[x][y].typ == SCORR) {
114.  #ifdef NAMED_ITEMS
115.  			if(rnl(7-fund)) continue;
116.  #else
117.  			if(rnl(7)) continue;
118.  #endif
119.  			levl[x][y].typ = CORR;
120.  			levl[x][y].seen = 0;	/* force prl */
121.  			nomul(0);
122.  			prl(x,y);
123.  		    } else {
124.  		/* Be careful not to find anything in an SCORR or SDOOR */
125.  			if(levl[x][y].mmask) {
126.  			    mtmp = m_at(x,y);
127.  			    if(!aflag && mtmp->mimic) {
128.  				seemimic(mtmp);
129.  				You("find %s.", defmonnam(mtmp));
130.  				return(1);
131.  			    }
132.  			}
133.  
134.  			for(trap = ftrap; trap; trap = trap->ntrap)
135.  			    if(trap->tx == x && trap->ty == y &&
136.  				!trap->tseen && !rnl(8)) {
137.  				nomul(0);
138.  				if(trap->ttyp != MONST_TRAP &&
139.  				   trap->ttyp != STATUE_TRAP)
140.  				You("find a%s.", traps[Hallucination ?
141.  				rn2(TRAPNUM-3)+2 : trap->ttyp ]);
142.  
143.  				if(trap->ttyp == MONST_TRAP) {
144.  				    if((mtmp=makemon(&mons[trap->pm], x, y)))
145.  					You("find %s.", defmonnam(mtmp));
146.  				    deltrap(trap);
147.  				    return(1);
148.  				} else if(trap->ttyp == STATUE_TRAP) {
149.  				    if((otmp = sobj_at(STATUE, x, y)))
150.  				      if(otmp->corpsenm == trap->pm) {
151.  					    
152.  					if((mtmp=makemon(&mons[trap->pm], x, y)))
153.  					    You("find %s posing as a statue.",
154.  						  defmonnam(mtmp));
155.  					delobj(otmp);
156.  				      }
157.  				    deltrap(trap);
158.  				    return(1);
159.  				}
160.  				trap->tseen = 1;
161.  				if(!vism_at(x,y)) atl(x,y,(char) TRAP_SYM);
162.  			    }
163.  		    }
164.  		}
165.  	return(1);
166.  }
167.  
168.  int
169.  doidtrap() {
170.  	register struct trap *trap;
171.  	register int x,y;
172.  
173.  	if(!getdir(1)) return 0;
174.  	x = u.ux + u.dx;
175.  	y = u.uy + u.dy;
176.  	for(trap = ftrap; trap; trap = trap->ntrap)
177.  		if(trap->tx == x && trap->ty == y && trap->tseen) {
178.  		    if(u.dz)
179.  			if((u.dz < 0) != (is_maze_lev && trap->ttyp == TRAPDOOR))
180.  			    continue;
181.  			pline("That is a%s.",traps[ Hallucination ? rn2(TRAPNUM-3)+2 :
182.  			trap->ttyp]);
183.  		    return 0;
184.  		}
185.  	pline("I can't see a trap there.");
186.  	return 0;
187.  }
188.  
189.  void
190.  wakeup(mtmp)
191.  register struct monst *mtmp;
192.  {
193.  	mtmp->msleep = 0;
194.  	mtmp->meating = 0;	/* assume there's no salvagable food left */
195.  	setmangry(mtmp);
196.  	if(mtmp->mimic) seemimic(mtmp);
197.  }
198.  
199.  /* NOTE: we must check if(mtmp->mimic) before calling this routine */
200.  void
201.  seemimic(mtmp)
202.  register struct monst *mtmp;
203.  {
204.  		mtmp->mimic = 0;
205.  		mtmp->mappearance = 0;
206.  		unpmon(mtmp);
207.  		pmon(mtmp);
208.  }