Source:SLASH'EM 0.0.7E7F2/detect.c

Below is the full text to detect.c from the source code of SLASH'EM 0.0.7E7F2. To link to a particular line, write [[SLASH'EM 0.0.7E7F2/detect.c#line123 ]], for example.

The latest source code for vanilla NetHack is at Source code.

1.   /*	SCCS Id: @(#)detect.c	3.4	2003/08/13	*/ 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    /*  6.     * Detection routines, including crystal ball, magic mapping, and search 7.    * command. 8.    */  9.     10.   #include "hack.h"  11. #include "artifact.h" 12. 13.  extern boolean known;	/* from read.c */ 14.   15.   STATIC_DCL void FDECL(do_dknown_of, (struct obj *)); 16.  STATIC_DCL boolean FDECL(check_map_spot, (int,int,CHAR_P,unsigned)); 17.  STATIC_DCL boolean FDECL(clear_stale_map, (CHAR_P,unsigned)); 18.  STATIC_DCL void FDECL(sense_trap, (struct trap *,XCHAR_P,XCHAR_P,int)); 19.  STATIC_DCL void FDECL(show_map_spot, (int,int)); 20.  STATIC_PTR void FDECL(findone,(int,int,genericptr_t)); 21.  STATIC_PTR void FDECL(openone,(int,int,genericptr_t)); 22.   23.   /* Recursively search obj for an object in class oclass and return 1st found */ 24.  struct obj * 25.  o_in(obj, oclass) 26.  struct obj* obj; 27.  char oclass; 28.  {  29.       register struct obj* otmp; 30.      struct obj *temp; 31.   32.       if (obj->oclass == oclass) return obj; 33.   34.       /*  35.        * Pills inside medical kits are specially handled (see apply.c). 36.       * We don't want them to detect as food because then they will be  37. * shown as pink pills, which are something quite different. In 38. * practice the only other possible contents of medical kits are 39.       * bandages and phials, neither of which is detectable by any 40.       * means so we can simply avoid looking in medical kits. 41.       */  42.       if (Has_contents(obj) && obj->otyp != MEDICAL_KIT) { 43.  	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 44.  	    if (otmp->oclass == oclass) return otmp; 45.  	    else if (Has_contents(otmp) && otmp->otyp != MEDICAL_KIT &&  46.   		    (temp = o_in(otmp, oclass))) 47.  		return temp; 48.      }  49.       return (struct obj *) 0; 50.  }  51.    52.   /* Recursively search obj for an object made of specified material and return 1st found */ 53.  struct obj * 54.  o_material(obj, material) 55.  struct obj* obj; 56.  unsigned material; 57.  {  58.       register struct obj* otmp; 59.      struct obj *temp; 60.   61.       if (objects[obj->otyp].oc_material == material) return obj; 62.   63.       if (Has_contents(obj)) { 64.  	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 65.  	    if (objects[otmp->otyp].oc_material == material) return otmp; 66.  	    else if (Has_contents(otmp) && (temp = o_material(otmp, material))) 67.  		return temp; 68.      }  69.       return (struct obj *) 0; 70.  }  71.    72.   STATIC_OVL void 73.  do_dknown_of(obj) 74.  struct obj *obj; 75.  {  76.       struct obj *otmp; 77.   78.       obj->dknown = 1; 79.      if (Has_contents(obj)) { 80.  	for(otmp = obj->cobj; otmp; otmp = otmp->nobj) 81.  	    do_dknown_of(otmp); 82.      }  83.   }  84.    85.   /* Check whether the location has an outdated object displayed on it. */ 86.   STATIC_OVL boolean 87.  check_map_spot(x, y, oclass, material) 88.  int x, y;  89. register char oclass; 90.  unsigned material; 91.  {  92.   	register int glyph; 93.  	register struct obj *otmp; 94.  	register struct monst *mtmp; 95.   96.   	glyph = glyph_at(x,y); 97.  	if (glyph_is_object(glyph)) { 98.  	    /* there's some object shown here */ 99.  	    if (oclass == ALL_CLASSES) { 100. 		return((boolean)( !(level.objects[x][y] ||     /* stale if nothing here */  101.  			    ((mtmp = m_at(x,y)) != 0 && 102. 				(  103.  #ifndef GOLDOBJ  104.  				 mtmp->mgold ||  105.  #endif  106.  						 mtmp->minvent))))); 107. 	    } else { 108. 		if (material && objects[glyph_to_obj(glyph)].oc_material == material) { 109. 			/* the object shown here is of interest because material matches */ 110. 			for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 111. 				if (o_material(otmp, GOLD)) return FALSE; 112. 			/* didn't find it; perhaps a monster is carrying it */ 113. 			if ((mtmp = m_at(x,y)) != 0) { 114. 				for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 115. 					if (o_material(otmp, GOLD)) return FALSE; 116. 		        }  117.  			/* detection indicates removal of this object from the map */ 118. 			return TRUE; 119. 		}  120.  	        if (oclass && objects[glyph_to_obj(glyph)].oc_class == oclass) { 121. 			/* the object shown here is of interest because its class matches */ 122. 			for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 123. 				if (o_in(otmp, oclass)) return FALSE; 124. 			/* didn't find it; perhaps a monster is carrying it */ 125. #ifndef GOLDOBJ 126. 			if ((mtmp = m_at(x,y)) != 0) { 127. 				if (oclass == COIN_CLASS && mtmp->mgold) 128. 					return FALSE; 129. 				else for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 130. 					if (o_in(otmp, oclass)) return FALSE; 131. 		        }  132.  #else 133. 			if ((mtmp = m_at(x,y)) != 0) { 134. 				for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 135. 					if (o_in(otmp, oclass)) return FALSE; 136. 		        }  137.  #endif 138. 			/* detection indicates removal of this object from the map */ 139. 			return TRUE; 140. 	        }  141.  	    }  142.  	}  143.  	return FALSE; 144. }  145.   146.  /*  147.     When doing detection, remove stale data from the map display (corpses  148.     rotted away, objects carried away by monsters, etc) so that it won't  149. reappear after the detection has completed. Return true if noticeable 150.    change occurs. 151.  */  152.  STATIC_OVL boolean 153. clear_stale_map(oclass, material) 154. register char oclass; 155. unsigned material; 156. {  157.  	register int zx, zy; 158. 	register boolean change_made = FALSE; 159.  160.  	for (zx = 1; zx < COLNO; zx++) 161. 	    for (zy = 0; zy < ROWNO; zy++) 162. 		if (check_map_spot(zx, zy, oclass,material)) { 163. 		    unmap_object(zx, zy); 164. 		    change_made = TRUE; 165. 		}  166.   167.  	return change_made; 168. }  169.   170.  /* look for gold, on the floor or in monsters' possession */ 171. int 172. gold_detect(sobj) 173. register struct obj *sobj; 174. {  175.      register struct obj *obj; 176.     register struct monst *mtmp; 177.     int uw = u.uinwater; 178.     struct obj *temp; 179.     boolean stale; 180.  181.      known = stale = clear_stale_map(COIN_CLASS,  182.  				(unsigned)(sobj->blessed ? GOLD : 0)); 183.  184.      /* look for gold carried by monsters (might be in a container) */ 185.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 186.     	if (DEADMONSTER(mtmp)) continue;	/* probably not needed in this case but... */ 187.  #ifndef GOLDOBJ 188. 	if (mtmp->mgold || monsndx(mtmp->data) == PM_GOLD_GOLEM) { 189. #else 190. 	if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { 191. #endif 192. 	    known = TRUE; 193. 	    goto outgoldmap;	/* skip further searching */ 194. 	} else for (obj = mtmp->minvent; obj; obj = obj->nobj) 195. 	    if (sobj->blessed && o_material(obj, GOLD)) { 196. 	    	known = TRUE; 197. 	    	goto outgoldmap; 198. 	    } else if (o_in(obj, COIN_CLASS)) { 199. 		known = TRUE; 200. 		goto outgoldmap;	/* skip further searching */ 201. 	    }  202.      }  203.       204.      /* look for gold objects */ 205.     for (obj = fobj; obj; obj = obj->nobj) { 206. 	if (sobj->blessed && o_material(obj, GOLD)) { 207. 	    known = TRUE; 208. 	    if (obj->ox != u.ux || obj->oy != u.uy) goto outgoldmap; 209. 	} else if (o_in(obj, COIN_CLASS)) { 210. 	    known = TRUE; 211. 	    if (obj->ox != u.ux || obj->oy != u.uy) goto outgoldmap; 212. 	}  213.      }  214.   215.      if (!known) { 216. 	/* no gold found on floor or monster's inventory. 217. 	   adjust message if you have gold in your inventory */ 218. 	if (sobj) { 219. 		char buf[BUFSZ]; 220. 		if (youmonst.data == &mons[PM_GOLD_GOLEM]) { 221. 			Sprintf(buf, "You feel like a million %s!",  222.  				currency(2L)); 223. 		} else if (hidden_gold ||  224.  #ifndef GOLDOBJ  225.  				u.ugold) 226. #else 227. 			        money_cnt(invent))  228.  #endif  229.  			Strcpy(buf, 230. 				"You feel worried about your future financial situation.");  231.  		else  232.  			Strcpy(buf, "You feel materially poor.");  233.  		strange_feeling(sobj, buf);  234.          }  235.  	return(1);  236.      }  237.      /* only under me - no separate display required */  238.      if (stale) docrt;  239.      You("notice some gold between your %s.", makeplural(body_part(FOOT)));  240.      return(0);  241.   242.  outgoldmap:  243.      cls;  244.   245.      u.uinwater = 0;  246.      /* Discover gold locations. */  247.      for (obj = fobj; obj; obj = obj->nobj) {  248.      	if (sobj->blessed && (temp = o_material(obj, GOLD))) {  249.  	    if (temp != obj) {  250.  		temp->ox = obj->ox;  251.  		temp->oy = obj->oy;  252.  	    }  253.  	    map_object(temp,1);  254.  	} else if ((temp = o_in(obj, COIN_CLASS))) {  255.  	    if (temp != obj) {  256.  		temp->ox = obj->ox; 257. 		temp->oy = obj->oy; 258. 	    }  259.  	    map_object(temp,1); 260. 	}  261.      }  262.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 263.     	if (DEADMONSTER(mtmp)) continue;	/* probably overkill here */ 264. #ifndef GOLDOBJ 265. 	if (mtmp->mgold || monsndx(mtmp->data) == PM_GOLD_GOLEM) { 266. #else 267. 	if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { 268. #endif 269. 	    struct obj gold; 270.  271.  	    gold.otyp = GOLD_PIECE; 272. 	    gold.ox = mtmp->mx; 273. 	    gold.oy = mtmp->my; 274. 	    map_object(&gold,1); 275. 	} else for (obj = mtmp->minvent; obj; obj = obj->nobj) 276. 	    if (sobj->blessed && (temp = o_material(obj, GOLD))) { 277. 		temp->ox = mtmp->mx; 278. 		temp->oy = mtmp->my; 279. 		map_object(temp,1); 280. 		break; 281. 	    } else if ((temp = o_in(obj, COIN_CLASS))) { 282. 		temp->ox = mtmp->mx; 283. 		temp->oy = mtmp->my; 284. 		map_object(temp,1); 285. 		break; 286. 	    }  287.      }  288.       289.      newsym(u.ux,u.uy); 290.     You_feel("very greedy, and sense gold!"); 291.     exercise(A_WIS, TRUE); 292.     display_nhwindow(WIN_MAP, TRUE); 293.     docrt; 294.     u.uinwater = uw; 295.     if (Underwater) under_water(2); 296.     if (u.uburied) under_ground(2); 297.     return(0); 298. }  299.   300.  /* returns 1 if nothing was detected		*/ 301. /* returns 0 if something was detected		*/ 302. int 303. food_detect(sobj) 304. register struct obj	*sobj; 305. {  306.      register struct obj *obj; 307.     register struct monst *mtmp; 308.     register int ct = 0, ctu = 0; 309.     boolean confused = (Confusion || (sobj && sobj->cursed)), stale; 310.     char oclass = confused ? POTION_CLASS : FOOD_CLASS; 311.     const char *what = confused ? something : "food"; 312.     int uw = u.uinwater; 313.  314.      stale = clear_stale_map(oclass, 0); 315.  316.      for (obj = fobj; obj; obj = obj->nobj) 317. 	if (o_in(obj, oclass)) { 318. 	    if (obj->ox == u.ux && obj->oy == u.uy) ctu++; 319. 	    else ct++; 320. 	}  321.      for (mtmp = fmon; mtmp && !ct; mtmp = mtmp->nmon) { 322. 	/* no DEADMONSTER(mtmp) check needed since dmons never have inventory */ 323. 	for (obj = mtmp->minvent; obj; obj = obj->nobj) 324. 	    if (o_in(obj, oclass)) { 325. 		ct++; 326. 		break; 327. 	    }  328.      }  329.       330.      if (!ct && !ctu) { 331. 	known = stale && !confused; 332. 	if (stale) { 333. 	    docrt; 334. 	    You("sense a lack of %s nearby.", what); 335. 	    if (sobj && sobj->blessed) { 336. 		if (!u.uedibility) Your("%s starts to tingle.", body_part(NOSE)); 337. 		u.uedibility = 1; 338. 	    }  339.  	} else if (sobj) { 340. 	    char buf[BUFSZ]; 341. 	    Sprintf(buf, "Your %s twitches%s.", body_part(NOSE),  342.  			(sobj->blessed && !u.uedibility) ? " then starts to tingle" : ""); 343. 	    if (sobj->blessed && !u.uedibility) { 344. 		boolean savebeginner = flags.beginner;	/* prevent non-delivery of */ 345. 		flags.beginner = FALSE;			/* 	message            */ 346. 		strange_feeling(sobj, buf); 347. 		flags.beginner = savebeginner; 348. 		u.uedibility = 1; 349. 	    } else 350. 		strange_feeling(sobj, buf); 351. 	}  352.  	return !stale; 353.     } else if (!ct) { 354. 	known = TRUE; 355. 	You("%s %s nearby.", sobj ? "smell" : "sense", what); 356. 	if (sobj && sobj->blessed) { 357. 		if (!u.uedibility) pline("Your %s starts to tingle.", body_part(NOSE)); 358. 		u.uedibility = 1; 359. 	}  360.      } else { 361. 	struct obj *temp; 362. 	known = TRUE; 363. 	cls; 364. 	u.uinwater = 0; 365. 	for (obj = fobj; obj; obj = obj->nobj) 366. 	    if ((temp = o_in(obj, oclass)) != 0) { 367. 		if (temp != obj) { 368. 		    temp->ox = obj->ox; 369. 		    temp->oy = obj->oy; 370. 		}  371.  		map_object(temp,1); 372. 	    }  373.  	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) 374. 	    /* no DEADMONSTER(mtmp) check needed since dmons never have inventory */ 375. 	    for (obj = mtmp->minvent; obj; obj = obj->nobj) 376. 		if ((temp = o_in(obj, oclass)) != 0) { 377. 		    temp->ox = mtmp->mx; 378. 		    temp->oy = mtmp->my; 379. 		    map_object(temp,1); 380. 		    break;	/* skip rest of this monster's inventory */ 381. 		}  382.  	newsym(u.ux,u.uy); 383. 	if (sobj) { 384. 	    if (sobj->blessed) { 385. 	    	Your("%s %s to tingle and you smell %s.", body_part(NOSE),  386.  	    		u.uedibility ? "continues" : "starts", what); 387. 		u.uedibility = 1; 388. 	    } else 389. 		Your("%s tingles and you smell %s.", body_part(NOSE), what); 390. 	}  391.  	else You("sense %s.", what); 392. 	display_nhwindow(WIN_MAP, TRUE); 393. 	exercise(A_WIS, TRUE); 394. 	docrt; 395. 	u.uinwater = uw; 396. 	if (Underwater) under_water(2); 397. 	if (u.uburied) under_ground(2); 398.     }  399.      return(0); 400. }  401.   402.  /*  403.   * Used for scrolls, potions, spells, and crystal balls. Returns: 404.  *  405.   *	1 - nothing was detected 406.  *	0 - something was detected 407.  */  408.  int 409. object_detect(detector, class) 410. struct obj	*detector;	/* object doing the detecting */ 411. int		class;		/* an object class, 0 for all */ 412. {  413.      register int x, y;  414. char stuff[BUFSZ]; 415.     int is_cursed = (detector && detector->cursed); 416.     int do_dknown = (detector && (detector->oclass == POTION_CLASS || 417. 				    detector->oclass == SPBOOK_CLASS) &&  418.  			detector->blessed); 419.     int ct = 0, ctu = 0; 420.     register struct obj *obj, *otmp = (struct obj *)0; 421.     register struct monst *mtmp; 422.     int uw = u.uinwater; 423.     int sym, boulder = 0; 424.  425.      if (class < 0 || class >= MAXOCLASSES) { 426. 	impossible("object_detect:  illegal class %d", class); 427. 	class = 0; 428.     }  429.   430.      /* Special boulder symbol check - does the class symbol happen 431.      * to match iflags.bouldersym which is a user-defined? 432.      * If so, that means we aren't sure what they really wanted to  433. * detect. Rather than trump anything, show both possibilities. 434.      * We can exclude checking the buried obj chain for boulders below. 435.      */  436.      sym = class ? def_oc_syms[class] : 0; 437.     if (sym && iflags.bouldersym && sym == iflags.bouldersym) 438.     	boulder = ROCK_CLASS; 439.  440.      if (Hallucination || (Confusion && class == SCROLL_CLASS)) 441. 	Strcpy(stuff, something); 442.     else 443.     	Strcpy(stuff, class ? oclass_names[class] : "objects"); 444.     if (boulder && class != ROCK_CLASS) Strcat(stuff, " and/or large stones"); 445.  446.      if (do_dknown) for(obj = invent; obj; obj = obj->nobj) do_dknown_of(obj); 447.  448.      for (obj = fobj; obj; obj = obj->nobj) { 449. 	if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) { 450. 	    if (obj->ox == u.ux && obj->oy == u.uy) ctu++; 451. 	    else ct++; 452. 	}  453.  	if (do_dknown) do_dknown_of(obj); 454.     }  455.   456.      for (obj = level.buriedobjlist; obj; obj = obj->nobj) { 457. 	if (!class || o_in(obj, class)) { 458. 	    if (obj->ox == u.ux && obj->oy == u.uy) ctu++; 459. 	    else ct++; 460. 	}  461.  	if (do_dknown) do_dknown_of(obj); 462.     }  463.   464.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 465. 	if (DEADMONSTER(mtmp)) continue; 466. 	for (obj = mtmp->minvent; obj; obj = obj->nobj) { 467. 	    if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) ct++; 468. 	    if (do_dknown) do_dknown_of(obj); 469. 	}  470.  	if ((is_cursed && mtmp->m_ap_type == M_AP_OBJECT && 471. 	    (!class || class == objects[mtmp->mappearance].oc_class)) ||  472.  #ifndef GOLDOBJ  473.  	    (mtmp->mgold && (!class || class == COIN_CLASS))) { 474. #else 475. 	    (findgold(mtmp->minvent) && (!class || class == COIN_CLASS))) {  476.  #endif  477.  	    ct++;  478.  	    break;  479.  	}  480.      }  481.   482.      if (!clear_stale_map(!class ? ALL_CLASSES : class, 0) && !ct) {  483.  	if (!ctu) {  484.  	    if (detector)  485.  		strange_feeling(detector, "You feel a lack of something.");  486.  	    return 1;  487.  	}  488.   489.  	You("sense %s nearby.", stuff);  490.  	return 0;  491.      }  492.   493.      cls;  494.   495.      u.uinwater = 0;  496.  /*  497.   *	Map all buried objects first.  498.   */  499.      for (obj = level.buriedobjlist; obj; obj = obj->nobj)  500.  	if (!class || (otmp = o_in(obj, class))) {  501.  	    if (class) {  502.  		if (otmp != obj) {  503.  		    otmp->ox = obj->ox;  504.  		    otmp->oy = obj->oy;  505.  		}  506.  		map_object(otmp, 1);  507.  	    } else  508.  		map_object(obj, 1); 509. 	}  510.      /*  511.       * If we are mapping all objects, map only the top object of a pile or  512. * the first object in a monster's inventory. Otherwise, go looking 513.      * for a matching object class and display the first one encountered 514.      * at each location. 515.      *  516.       * Objects on the floor override buried objects. 517.      */  518.      for (x = 1; x < COLNO; x++) 519. 	for (y = 0; y < ROWNO; y++) 520. 	    for (obj = level.objects[x][y]; obj; obj = obj->nexthere) 521. 		if ((!class && !boulder) ||  522.  		    (otmp = o_in(obj, class)) || (otmp = o_in(obj, boulder))) { 523. 		    if (class || boulder) { 524. 			if (otmp != obj) { 525. 			    otmp->ox = obj->ox; 526. 			    otmp->oy = obj->oy; 527. 			}  528.  			map_object(otmp, 1); 529. 		    } else 530. 			map_object(obj, 1); 531. 		    break; 532. 		}  533.   534.      /* Objects in the monster's inventory override floor objects. */ 535.      for (mtmp = fmon ; mtmp ; mtmp = mtmp->nmon) { 536. 	if (DEADMONSTER(mtmp)) continue; 537. 	for (obj = mtmp->minvent; obj; obj = obj->nobj) 538. 	    if ((!class && !boulder) ||  539.  		 (otmp = o_in(obj, class)) || (otmp = o_in(obj, boulder))) { 540. 		if (!class && !boulder) otmp = obj; 541. 		otmp->ox = mtmp->mx;		/* at monster location */ 542. 		otmp->oy = mtmp->my; 543. 		map_object(otmp, 1); 544. 		break; 545. 	    }  546.  	/* Allow a mimic to override the detected objects it is carrying. */ 547.  	if (is_cursed && mtmp->m_ap_type == M_AP_OBJECT &&  548.  		(!class || class == objects[mtmp->mappearance].oc_class)) { 549. 	    struct obj temp; 550.  551.  	    temp.otyp = mtmp->mappearance;	/* needed for obj_to_glyph */ 552. 	    temp.ox = mtmp->mx; 553. 	    temp.oy = mtmp->my; 554. 	    temp.corpsenm = PM_TENGU;		/* if mimicing a corpse */ 555. 	    map_object(&temp, 1); 556. #ifndef GOLDOBJ 557. 	} else if (mtmp->mgold && (!class || class == COIN_CLASS)) { 558. #else 559. 	} else if (findgold(mtmp->minvent) && (!class || class == COIN_CLASS)) { 560. #endif 561. 	    struct obj gold; 562.  563.  	    gold.otyp = GOLD_PIECE; 564. 	    gold.ox = mtmp->mx; 565. 	    gold.oy = mtmp->my; 566. 	    map_object(&gold, 1); 567. 	}  568.      }  569.   570.      newsym(u.ux,u.uy); 571.     You("detect the %s of %s.", ct ? "presence" : "absence", stuff); 572.     display_nhwindow(WIN_MAP, TRUE); 573.     /*  574.       * What are we going to do when the hero does an object detect while blind 575.      * and the detected object covers a known pool? 576.      */  577.      docrt;	/* this will correctly reset vision */ 578.  579.      u.uinwater = uw; 580.     if (Underwater) under_water(2); 581.     if (u.uburied) under_ground(2); 582.     return 0; 583. }  584.   585.  /*  586.   * Used by: crystal balls, potions, fountains 587.  *  588.   * Returns 1 if nothing was detected. 589.  * Returns 0 if something was detected. 590.  */  591.  int 592. monster_detect(otmp, mclass) 593. register struct obj *otmp;	/* detecting object (if any) */ 594. int mclass;			/* monster class, 0 for all */ 595. {  596.      register struct monst *mtmp; 597.     int mcnt = 0; 598.  599.   600.      /* Note: This used to just check fmon for a non-zero value 601.      * but in versions since 3.3.0 fmon can test TRUE due to the 602.      * presence of dmons, so we have to find at least one 603.      * with positive hit-points to know for sure. 604.      */  605.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) 606.     	if (!DEADMONSTER(mtmp)) { 607. 		mcnt++; 608. 		break; 609. 	}  610.   611.      if (!mcnt) { 612. 	if (otmp) 613. 	    strange_feeling(otmp, Hallucination ?  614.  			    "You get the heebie jeebies." :  615.  			    "You feel threatened."); 616. 	return 1; 617.     } else { 618. 	boolean woken = FALSE; 619.  620.  	cls; 621. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 622. 	    if (DEADMONSTER(mtmp)) continue; 623. 	    if (!mclass || mtmp->data->mlet == mclass ||  624.  		(mtmp->data == &mons[PM_LONG_WORM] && mclass == S_WORM_TAIL)) 625. 		    if (mtmp->mx > 0) { 626. 		    	if (mclass && def_monsyms[mclass] == ' ') 627. 				show_glyph(mtmp->mx,mtmp->my,  628.  					detected_mon_to_glyph(mtmp)); 629. 			else 630. 				show_glyph(mtmp->mx,mtmp->my,mon_to_glyph(mtmp)); 631. 			/* don't be stingy - display entire worm */ 632. 			if (mtmp->data == &mons[PM_LONG_WORM]) detect_wsegs(mtmp,0); 633. 		    }  634.  	    if (otmp && otmp->cursed &&  635.  		(mtmp->msleeping || !mtmp->mcanmove)) { 636. 		mtmp->msleeping = mtmp->mfrozen = 0; 637. 		mtmp->mcanmove = 1; 638. 		woken = TRUE; 639. 	    }  640.  	}  641.  	display_self; 642. 	You("sense the presence of monsters."); 643. 	if (woken) 644. 	    pline("Monsters sense the presence of you."); 645. 	display_nhwindow(WIN_MAP, TRUE); 646. 	docrt; 647. 	if (Underwater) under_water(2); 648. 	if (u.uburied) under_ground(2); 649.     }  650.      return 0; 651. }  652.   653.  STATIC_OVL void 654. sense_trap(trap, x, y, src_cursed) 655. struct trap *trap; 656. xchar x, y;  657. int src_cursed; 658. {  659.      if (Hallucination || src_cursed) { 660. 	struct obj obj;			/* fake object */ 661. 	if (trap) { 662. 	    obj.ox = trap->tx; 663. 	    obj.oy = trap->ty; 664. 	} else { 665. 	    obj.ox = x;  666. obj.oy = y; 667. } 668.  	obj.otyp = (src_cursed) ? GOLD_PIECE : random_object; 669. 	obj.corpsenm = random_monster;	/* if otyp == CORPSE */ 670. 	map_object(&obj,1); 671.     } else if (trap) { 672. 	map_trap(trap,1); 673. 	trap->tseen = 1; 674.     } else { 675. 	struct trap temp_trap;		/* fake trap */ 676. 	temp_trap.tx = x;  677. temp_trap.ty = y; 678. temp_trap.ttyp = BEAR_TRAP;	/* some kind of trap */ 679. 	map_trap(&temp_trap,1); 680.     }  681.   682.  }  683.   684.  /* the detections are pulled out so they can	*/ 685. /* also be used in the crystal ball routine	*/ 686. /* returns 1 if nothing was detected		*/ 687. /* returns 0 if something was detected		*/ 688. int 689. trap_detect(sobj) 690. register struct obj *sobj; 691. /* sobj is null if crystal ball, *scroll if gold detection scroll */ 692. {  693.      register struct trap *ttmp; 694.     register struct obj *obj; 695.     register int door; 696.     int uw = u.uinwater; 697.     boolean found = FALSE; 698.     int x, y;  699. 700.     for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { 701. 	if (ttmp->tx != u.ux || ttmp->ty != u.uy) 702. 	    goto outtrapmap; 703. 	else found = TRUE; 704.     }  705.      for (obj = fobj; obj; obj = obj->nobj) { 706. 	if ((obj->otyp==LARGE_BOX || obj->otyp==CHEST) && obj->otrapped) { 707. 	    if (obj->ox != u.ux || obj->oy != u.uy) 708. 		goto outtrapmap; 709. 	    else found = TRUE; 710. 	}  711.      }  712.      for (door = 0; door < doorindex; door++) { 713. 	x = doors[door].x;  714. y = doors[door].y; 715. if (levl[x][y].doormask & D_TRAPPED) { 716. 	    if (x != u.ux || y != u.uy) 717. 		goto outtrapmap; 718. 	    else found = TRUE; 719. 	}  720.      }  721.      if (!found) { 722. 	char buf[42]; 723. 	Sprintf(buf, "Your %s stop itching.", makeplural(body_part(TOE))); 724. 	strange_feeling(sobj,buf); 725. 	return(1); 726.     }  727.      /* traps exist, but only under me - no separate display required */ 728.     Your("%s itch.", makeplural(body_part(TOE))); 729.     return(0); 730. outtrapmap: 731.     cls; 732.  733.      u.uinwater = 0; 734.     for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) 735. 	sense_trap(ttmp, 0, 0, sobj && sobj->cursed); 736.  737.      for (obj = fobj; obj; obj = obj->nobj) 738. 	if ((obj->otyp==LARGE_BOX || obj->otyp==CHEST) && obj->otrapped) 739. 	sense_trap((struct trap *)0, obj->ox, obj->oy, sobj && sobj->cursed); 740.  741.      for (door = 0; door < doorindex; door++) { 742. 	x = doors[door].x;  743. y = doors[door].y; 744. if (levl[x][y].doormask & D_TRAPPED) 745. 	sense_trap((struct trap *)0, x, y, sobj && sobj->cursed); 746.     }  747.   748.      newsym(u.ux,u.uy); 749.     You_feel("%s.", sobj && sobj->cursed ? "very greedy" : "entrapped"); 750.     display_nhwindow(WIN_MAP, TRUE); 751.     docrt; 752.     u.uinwater = uw; 753.     if (Underwater) under_water(2); 754.     if (u.uburied) under_ground(2); 755.     return(0); 756. }  757.   758.  const char * 759. level_distance(where) 760. d_level *where; 761. {  762.      register schar ll = depth(&u.uz) - depth(where); 763.     register boolean indun = (u.uz.dnum == where->dnum); 764.  765.      if (ll < 0) { 766. 	if (ll < (-8 - rn2(3))) { 767. 	    if (!indun)	return "far away"; 768. 	    else	return "far below"; 769. 	}  770.  	else if (ll < -1) { 771. 	    if (!indun)	return "away below you"; 772. 	    else	return "below you"; 773. 	}  774.  	else 775. 	    if (!indun)	return "in the distance"; 776. 	    else	return "just below"; 777.     } else if (ll > 0) { 778. 	if (ll > (8 + rn2(3))) { 779. 	    if (!indun)	return "far away"; 780. 	    else	return "far above"; 781. 	}  782.  	else if (ll > 1) { 783. 	    if (!indun)	return "away above you"; 784. 	    else	return "above you"; 785. 	}  786.  	else 787. 	    if (!indun)	return "in the distance"; 788. 	    else	return "just above"; 789.     } else 790. 	    if (!indun)	return "in the distance"; 791. 	    else	return "near you"; 792. }  793.   794.  static const struct { 795.     const char *what; 796.     d_level *where; 797. } level_detects[] = { 798.   { "Delphi", &oracle_level }, 799.   { "Medusa's lair", &medusa_level }, 800.   { "a castle", &stronghold_level }, 801.   { "the Wizard of Yendor's tower", &wiz1_level }, 802. };  803.   804.  void 805. use_crystal_ball(obj) 806. struct obj *obj; 807. {  808.      char ch; 809.     int oops; 810.  811.      if (Blind) { 812. 	pline("Too bad you can't see %s.", the(xname(obj))); 813. 	return; 814.     }  815.      oops = (rnd(20) > ACURR(A_INT) || obj->cursed); 816.     if (oops && (obj->spe > 0)) { 817. 	switch (rnd(obj->oartifact ? 4 : 5)) { 818.  	case 1 : pline("%s too much to comprehend!", Tobjnam(obj, "are")); 819. 	    break; 820. 	case 2 : pline("%s you!", Tobjnam(obj, "confuse")); 821. 	    make_confused(HConfusion + rnd(100),FALSE); 822. 	    break; 823. 	case 3 : if (!resists_blnd(&youmonst)) { 824. 		pline("%s your vision!", Tobjnam(obj, "damage")); 825. 		make_blinded(Blinded + rnd(100),FALSE); 826. 		if (!Blind) Your(vision_clears); 827. 	    } else { 828. 		pline("%s your vision.", Tobjnam(obj, "assault")); 829. 		You("are unaffected!"); 830. 	    }  831.  	    break; 832. 	case 4 : pline("%s your mind!", Tobjnam(obj, "zap")); 833. 	    (void) make_hallucinated(HHallucination + rnd(100),FALSE,0L); 834. 	    break; 835. 	case 5 : pline("%s!", Tobjnam(obj, "explode")); 836. 	    useup(obj); 837. 	    obj = 0;	/* it's gone */ 838. 	    losehp(rnd(30), "exploding crystal ball", KILLED_BY_AN); 839. 	    break; 840. 	}  841.  	if (obj) consume_obj_charge(obj, TRUE); 842. 	return; 843.     }  844.   845.      if (Hallucination) { 846. 	if (!obj->spe) { 847. 	    pline("All you see is funky %s haze.", hcolor((char *)0)); 848. 	} else { 849. 	    switch(rnd(6)) { 850. 	    case 1 : You("grok some groovy globs of incandescent lava."); 851. 		break; 852. 	    case 2 : pline("Whoa!  Psychedelic colors, %s!",  853.  			   poly_gender == 1 ? "babe" : "dude"); 854. 		break; 855. 	    case 3 : pline_The("crystal pulses with sinister %s light!",  856.  				hcolor((char *)0)); 857. 		break; 858. 	    case 4 : You("see goldfish swimming above fluorescent rocks."); 859. 		break; 860. 	    case 5 : You("see tiny snowflakes spinning around a miniature farmhouse."); 861. 		break; 862. 	    default: pline("Oh wow... like a kaleidoscope!"); 863. 		break; 864. 	    }  865.  	    consume_obj_charge(obj, TRUE); 866. 	}  867.  	return; 868.     }  869.   870.      /* read a single character */ 871.     if (flags.verbose) You("may look for an object or monster symbol."); 872.     ch = yn_function("What do you look for?", (char *)0, '\0'); 873.     /* Don't filter out ' ' here; it has a use */ 874.     if ((ch != def_monsyms[S_GHOST]) && index(quitchars,ch)) { 875. 	if (flags.verbose) pline(Never_mind); 876. 	return; 877.     }  878.      You("peer into %s...", the(xname(obj))); 879.     nomul(-rnd(10)); 880.     nomovemsg = ""; 881.     if (obj->spe <= 0) 882. 	pline_The("vision is unclear."); 883.     else { 884. 	int class; 885. 	int ret = 0; 886.  887.  	makeknown(CRYSTAL_BALL); 888. 	consume_obj_charge(obj, TRUE); 889.  890.  	/* special case: accept ']' as synonym for mimic 891. 	 * we have to do this before the def_char_to_objclass check 892. 	 */  893.  	if (ch == DEF_MIMIC_DEF) ch = DEF_MIMIC; 894.  895.  	if ((class = def_char_to_objclass(ch)) != MAXOCLASSES) 896. 		ret = object_detect((struct obj *)0, class); 897. 	else if ((class = def_char_to_monclass(ch)) != MAXMCLASSES) 898. 		ret = monster_detect((struct obj *)0, class); 899. 	else if (iflags.bouldersym && (ch == iflags.bouldersym)) 900. 		ret = object_detect((struct obj *)0, ROCK_CLASS); 901. 	else switch(ch) { 902. 		case '^': 903. 		    ret = trap_detect((struct obj *)0); 904. 		    break; 905. 		default: 906. 		    {  907.  		    int i = rn2(SIZE(level_detects)); 908. 		    You("see %s, %s.",  909.  			level_detects[i].what,  910.  			level_distance(level_detects[i].where)); 911. 		    }  912.  		    ret = 0; 913. 		    break; 914. 	}  915.   916.  	if (ret) { 917. 	    if (!rn2(100))  /* make them nervous */ 918. 		You("see the Wizard of Yendor gazing out at you."); 919. 	    else pline_The("vision is unclear."); 920. 	}  921.      }  922.      return; 923. }  924.   925.  STATIC_OVL void 926. show_map_spot(x, y)  927. register int x, y; 928. { 929.      register struct rm *lev; 930.  931.      if (Confusion && rn2(7)) return; 932.     lev = &levl[x][y]; 933.  934.      lev->seenv = SVALL; 935.  936.      /* Secret corridors are found, but not secret doors. */ 937.      if (lev->typ == SCORR) { 938. 	lev->typ = CORR; 939. 	unblock_point(x,y); 940.     }  941.   942.      /* if we don't remember an object or trap there, map it */ 943. #ifdef DISPLAY_LAYERS 944.     if (!lev->mem_obj && !lev->mem_trap) { 945. #else 946.     if (lev->typ == ROOM ?  947.  	    (glyph_is_cmap(lev->glyph) && !glyph_is_trap(lev->glyph) && 948. 		glyph_to_cmap(lev->glyph) != ROOM) :  949.  	    (!glyph_is_object(lev->glyph) && !glyph_is_trap(lev->glyph))) { 950. #endif 951. 	if (level.flags.hero_memory) { 952. 	    magic_map_background(x,y,0); 953. 	    newsym(x,y);			/* show it, if not blocked */ 954. 	} else { 955. 	    magic_map_background(x,y,1);	/* display it */ 956. 	}  957.      }  958.  }  959.   960.  void 961. do_mapping 962. {  963.      register int zx, zy; 964.     int uw = u.uinwater; 965.  966.      u.uinwater = 0; 967.     for (zx = 1; zx < COLNO; zx++) 968. 	for (zy = 0; zy < ROWNO; zy++) 969. 	    show_map_spot(zx, zy); 970.     exercise(A_WIS, TRUE); 971.     u.uinwater = uw; 972.     if (!level.flags.hero_memory || Underwater) { 973. 	flush_screen(1);			/* flush temp screen */ 974. 	display_nhwindow(WIN_MAP, TRUE);	/* wait */ 975. 	docrt; 976.     }  977.  }  978.   979.  void 980. do_vicinity_map 981. {  982.      register int zx, zy; 983.     int lo_y = (u.uy-5 < 0 ? 0 : u.uy-5), 984. 	hi_y = (u.uy+6 > ROWNO ? ROWNO : u.uy+6), 985. 	lo_x = (u.ux-9 < 1 ? 1 : u.ux-9),	/* avoid column 0 */ 986. 	hi_x = (u.ux+10 > COLNO ? COLNO : u.ux+10); 987.  988.      for (zx = lo_x; zx < hi_x; zx++) 989. 	for (zy = lo_y; zy < hi_y; zy++) 990. 	    show_map_spot(zx, zy); 991.  992.      if (!level.flags.hero_memory || Underwater) { 993. 	flush_screen(1);			/* flush temp screen */ 994. 	display_nhwindow(WIN_MAP, TRUE);	/* wait */ 995. 	docrt; 996.     }  997.  }  998.   999.  /* convert a secret door into a normal door */ 1000. void 1001. cvt_sdoor_to_door(lev) 1002. struct rm *lev; 1003. { 1004. 	int newmask = lev->doormask & ~WM_MASK; 1005. 1006. #ifdef REINCARNATION 1007. 	if (Is_rogue_level(&u.uz)) 1008. 	   /* rogue didn't have doors, only doorways */ 1009. 	   newmask = D_NODOOR; 1010. 	else 1011. #endif 1012. 	   /* newly exposed door is closed */ 1013. 	   if (!(newmask & D_LOCKED)) newmask |= D_CLOSED; 1014. 1015. 	lev->typ = DOOR; 1016. 	lev->doormask = newmask; 1017. } 1018.  1019. STATIC_PTR void 1020. findone(zx,zy,num) 1021. int zx,zy; 1022. genericptr_t num; 1023. { 1024. 	register struct trap *ttmp; 1025. 	register struct monst *mtmp; 1026. 1027. 	if(levl[zx][zy].typ == SDOOR) { 1028. 		cvt_sdoor_to_door(&levl[zx][zy]);	/* .typ = DOOR */ 1029. 		magic_map_background(zx, zy, 0); 1030. 		newsym(zx, zy); 1031. 		(*(int*)num)++; 1032. 	} else if(levl[zx][zy].typ == SCORR) { 1033. 		levl[zx][zy].typ = CORR; 1034. 		unblock_point(zx,zy); 1035. 		magic_map_background(zx, zy, 0); 1036. 		newsym(zx, zy); 1037. 		(*(int*)num)++; 1038. 	} else if ((ttmp = t_at(zx, zy)) != 0) { 1039. 		if(!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { 1040. 			ttmp->tseen = 1; 1041. 			newsym(zx,zy); 1042. 			(*(int*)num)++; 1043. 		} 1044. 	} else if ((mtmp = m_at(zx, zy)) != 0) { 1045. 		if(mtmp->m_ap_type) { 1046. 			seemimic(mtmp); 1047. 			(*(int*)num)++; 1048. 		} 1049. 		if (mtmp->mundetected &&  1050. 		    (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL)) { 1051. 			mtmp->mundetected = 0; 1052. 			newsym(zx, zy); 1053. 			(*(int*)num)++; 1054. 		} 1055. 		if (!canspotmon(mtmp) &&  1056. 				    !memory_is_invisible(zx, zy)) 1057. 			map_invisible(zx, zy); 1058. 	} else if (memory_is_invisible(zx, zy)) { 1059. 		unmap_object(zx, zy); 1060. 		newsym(zx, zy); 1061. 		(*(int*)num)++; 1062. 	} 1063. }  1064.  1065. STATIC_PTR void 1066. openone(zx,zy,num) 1067. int zx,zy; 1068. genericptr_t num; 1069. { 1070. 	register struct trap *ttmp; 1071. 	register struct obj *otmp; 1072. 1073. 	if(OBJ_AT(zx, zy)) { 1074. 		for(otmp = level.objects[zx][zy]; 1075. 				otmp; otmp = otmp->nexthere) { 1076. 		   if(Is_box(otmp) && otmp->olocked) { 1077. 			otmp->olocked = 0; 1078. 			(*(int*)num)++; 1079. 		   }  1080. 		}  1081. 		/* let it fall to the next cases. could be on trap. */ 1082. 	}  1083. 	if(levl[zx][zy].typ == SDOOR || (levl[zx][zy].typ == DOOR && 1084. 		     (levl[zx][zy].doormask & (D_CLOSED|D_LOCKED)))) { 1085. 		if(levl[zx][zy].typ == SDOOR) 1086. 		   cvt_sdoor_to_door(&levl[zx][zy]);	/* .typ = DOOR */ 1087. 		if(levl[zx][zy].doormask & D_TRAPPED) { 1088. 		   if(distu(zx, zy) < 3) b_trapped("door", 0); 1089. 		   else Norep("You %s an explosion!",  1090. 				cansee(zx, zy) ? "see" :  1091. 				   (flags.soundok ? "hear" : 1092. 						"feel the shock of")); 1093. 		   wake_nearto(zx, zy, 11*11); 1094. 		   levl[zx][zy].doormask = D_NODOOR; 1095. 		} else 1096. 		   levl[zx][zy].doormask = D_ISOPEN; 1097. 		unblock_point(zx, zy); 1098. 		newsym(zx, zy); 1099. 		(*(int*)num)++; 1100. 	} else if(levl[zx][zy].typ == SCORR) { 1101. 		levl[zx][zy].typ = CORR; 1102. 		unblock_point(zx, zy); 1103. 		newsym(zx, zy); 1104. 		(*(int*)num)++; 1105. 	} else if ((ttmp = t_at(zx, zy)) != 0) { 1106. 		if (!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { 1107. 		   ttmp->tseen = 1; 1108. 		   newsym(zx,zy); 1109. 		   (*(int*)num)++; 1110. 		} 1111. 	} else if (find_drawbridge(&zx, &zy)) { 1112. 		/* make sure it isn't an open drawbridge */ 1113. 		open_drawbridge(zx, zy); 1114. 		(*(int*)num)++; 1115. 	} 1116. }  1117.  1118. int 1119. findit	/* returns number of things found */ 1120. { 1121. 	int num = 0; 1122. 1123. 	if(u.uswallow) return(0); 1124. 	do_clear_area(u.ux, u.uy, BOLT_LIM, findone, (genericptr_t) &num); 1125. 	return(num); 1126. } 1127.  1128. int 1129. openit	/* returns number of things found and opened */ 1130. { 1131. 	int num = 0; 1132. 1133. 	if(u.uswallow) { 1134. 		if (is_animal(u.ustuck->data)) { 1135. 			if (Blind) pline("Its mouth opens!"); 1136. 			else pline("%s opens its mouth!", Monnam(u.ustuck)); 1137. 		} 1138. 		expels(u.ustuck, u.ustuck->data, TRUE); 1139. 		return(-1); 1140. 	} 1141.  1142. 	do_clear_area(u.ux, u.uy, BOLT_LIM, openone, (genericptr_t) &num); 1143. 	return(num); 1144. } 1145.  1146. void 1147. find_trap(trap) 1148. struct trap *trap; 1149. { 1150.     int tt = what_trap(trap->ttyp); 1151.    boolean cleared = FALSE; 1152. 1153.     trap->tseen = 1; 1154.    exercise(A_WIS, TRUE); 1155.    if (Blind) 1156. 	feel_location(trap->tx, trap->ty); 1157.    else 1158. 	newsym(trap->tx, trap->ty); 1159. 1160. #ifdef DISPLAY_LAYERS 1161.    if (levl[trap->tx][trap->ty].mem_obj ||  1162. 	    memory_is_invisible(trap->tx, trap->ty)) { 1163. #else 1164.    if (levl[trap->tx][trap->ty].glyph != trap_to_glyph(trap)) { 1165. #endif 1166.    	/* There's too much clutter to see your find otherwise */ 1167. 	cls; 1168. 	map_trap(trap, 1); 1169. 	display_self; 1170. 	cleared = TRUE; 1171.    }  1172.  1173.     You("find %s.", an(defsyms[trap_to_defsym(tt)].explanation)); 1174. 1175.     if (cleared) { 1176. 	display_nhwindow(WIN_MAP, TRUE);	/* wait */ 1177. 	docrt; 1178.    }  1179. }  1180.  1181. int 1182. dosearch0(aflag) 1183. register int aflag; 1184. { 1185. #ifdef GCC_BUG 1186. /* some versions of gcc seriously muck up nested loops. if you get strange 1187.   crashes while searching in a version compiled with gcc, try putting 1188.   #define GCC_BUG in *conf.h (or adding -DGCC_BUG to CFLAGS in the  1189.    makefile). 1190. */  1191. 	volatile xchar x, y;  1192. #else 1193. 	register xchar x, y; 1194. #endif 1195. 	register struct trap *trap; 1196. 	register struct monst *mtmp; 1197. 1198. 	if(u.uswallow) { 1199. 		if (!aflag) 1200. 			pline("What are you looking for? The exit?"); 1201. 	} else { 1202. 	   int fund = (uwep && uwep->oartifact &&  1203. 		    spec_ability(uwep, SPFX_SEARCH)) ? 1204. 		   uwep->spe : 0; 1205. 	   if (ublindf && ublindf->otyp == LENSES && !Blind) 1206. 		   fund += 2; /* JDS: lenses help searching */ 1207. 	   if (fund > 5) fund = 5; 1208. 	   for(x = u.ux-1; x < u.ux+2; x++) 1209. 	     for(y = u.uy-1; y < u.uy+2; y++) { 1210. 		if(!isok(x,y)) continue; 1211. 		if(x != u.ux || y != u.uy) { 1212. 		   if (Blind && !aflag) feel_location(x,y); 1213. 		   if(levl[x][y].typ == SDOOR) { 1214. 			if(rnl(7-fund)) continue; 1215. 			cvt_sdoor_to_door(&levl[x][y]);	/* .typ = DOOR */ 1216. 			exercise(A_WIS, TRUE); 1217. 			nomul(0); 1218. 			if (Blind && !aflag) 1219. 			   feel_location(x,y);	/* make sure it shows up */ 1220. 			else 1221. 			   newsym(x,y); 1222. 		   } else if(levl[x][y].typ == SCORR) { 1223. 			if(rnl(7-fund)) continue; 1224. 			levl[x][y].typ = CORR; 1225. 			unblock_point(x,y);	/* vision */ 1226. 			exercise(A_WIS, TRUE); 1227. 			nomul(0); 1228. 			newsym(x,y); 1229. 		   } else { 1230. 		/* Be careful not to find anything in an SCORR or SDOOR */ 1231. 			if((mtmp = m_at(x, y)) && !aflag) { 1232. 			   if(mtmp->m_ap_type) { 1233. 				seemimic(mtmp); 1234. 		find:		exercise(A_WIS, TRUE); 1235. 				if (!canspotmon(mtmp)) { 1236. 				   if (memory_is_invisible(x, y)) { 1237. 					/* found invisible monster in a square 1238. 					 * which already has an 'I' in it. 1239. 					 * Logically, this should still take 1240. 					 * time and lead to a return(1), but if 1241. * we did that the player would keep 1242. 					 * finding the same monster every turn. 1243. 					 */ 1244. 					continue; 1245. 				   } else { 1246. 					You_feel("an unseen monster!"); 1247. 					map_invisible(x, y); 1248. 				   }  1249. 				} else if (!sensemon(mtmp)) 1250. 				   You("find %s.", a_monnam(mtmp)); 1251. 				return(1); 1252. 			   }  1253. 			    if(!canspotmon(mtmp)) { 1254. 				if (mtmp->mundetected && 1255. 				   (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL)) 1256. 					mtmp->mundetected = 0; 1257. 				newsym(x,y); 1258. 				goto find; 1259. 			   }  1260. 			}  1261.  1262. 			/* see if an invisible monster has moved--if Blind, 1263. 			 * feel_location already did it 1264. */ 1265. 			if (!aflag && !mtmp && !Blind &&  1266. 				    memory_is_invisible(x, y)) { 1267. 			   unmap_object(x,y); 1268. 			   newsym(x,y); 1269. 			} 1270.  1271. 			if ((trap = t_at(x,y)) && !trap->tseen && !rnl(8)) { 1272. 			   nomul(0); 1273. 1274. 			    if (trap->ttyp == STATUE_TRAP) { 1275. 				mtmp = activate_statue_trap(trap, x, y, FALSE); 1276. 				if (mtmp != (struct monst *)0) 1277. 				   exercise(A_WIS, TRUE); 1278. 				return(1); 1279. 			   } else { 1280. 				find_trap(trap); 1281. 			   }  1282. 			}  1283. 		    }  1284. 		}  1285. 	    }  1286. 	}  1287. 	return(1); 1288. } 1289.  1290. /* Pre-map the sokoban levels */ 1291. void 1292. sokoban_detect 1293. { 1294. 	register int x, y;  1295. register struct trap *ttmp; 1296. 	register struct obj *obj; 1297. 1298. 	/* Map the background and boulders */ 1299. 	for (x = 1; x < COLNO; x++) 1300. 	   for (y = 0; y < ROWNO; y++) { 1301. 	   	levl[x][y].seenv = SVALL; 1302. 	   	levl[x][y].waslit = TRUE; 1303. 	   	map_background(x, y, 1); 1304. 	   	for (obj = level.objects[x][y]; obj; obj = obj->nexthere) 1305. 	   	    if (obj->otyp == BOULDER) 1306. 	   	    	map_object(obj, 1); 1307. 	   }  1308.  1309. 	/* Map the traps */ 1310. 	for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { 1311. 	   ttmp->tseen = 1; 1312. 	   map_trap(ttmp, 1); 1313. 	} 1314. }  1315.  1316.  1317. int 1318. dosearch 1319. { 1320. 	return(dosearch0(0)); 1321. } 1322.  1323. /*detect.c*/