Source:NetHack 3.4.3/src/detect.c

From NetHackWiki
(Redirected from Source:Ref/find trap)
Jump to: navigation, search

Below is the full text to src/detect.c from NetHack 3.4.3. To link to a particular line, write [[detect.c#line123]], for example.

Top of file

  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. */

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. /*
  2. * Detection routines, including crystal ball, magic mapping, and search
  3. * command.
  4. */
  5.  
  6. #include "hack.h"
  7. #include "artifact.h"
  8.  
  9. extern boolean known;	/* from read.c */
  10.  
  11. STATIC_DCL void FDECL(do_dknown_of, (struct obj *));
  12. STATIC_DCL boolean FDECL(check_map_spot, (int,int,CHAR_P,unsigned));
  13. STATIC_DCL boolean FDECL(clear_stale_map, (CHAR_P,unsigned));
  14. STATIC_DCL void FDECL(sense_trap, (struct trap *,XCHAR_P,XCHAR_P,int));
  15. STATIC_DCL void FDECL(show_map_spot, (int,int));
  16. STATIC_PTR void FDECL(findone,(int,int,genericptr_t));
  17. STATIC_PTR void FDECL(openone,(int,int,genericptr_t));

o_in

  1. /* Recursively search obj for an object in class oclass and return 1st found */
  2. struct obj *
  3. o_in(obj, oclass)
  4. struct obj* obj;
  5. char oclass;
  6. {
  7. register struct obj* otmp;
  8. struct obj *temp;
  9.  
  10. if (obj->oclass == oclass) return obj;
  11.  
  12. if (Has_contents(obj)) {
  13. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj)
  14. 	    if (otmp->oclass == oclass) return otmp;
  15. 	    else if (Has_contents(otmp) && (temp = o_in(otmp, oclass)))
  16. 		return temp;
  17. }
  18. return (struct obj *) 0;
  19. }

o_material

  1. /* Recursively search obj for an object made of specified material and return 1st found */
  2. struct obj *
  3. o_material(obj, material)
  4. struct obj* obj;
  5. unsigned material;
  6. {
  7. register struct obj* otmp;
  8. struct obj *temp;
  9.  
  10. if (objects[obj->otyp].oc_material == material) return obj;
  11.  
  12. if (Has_contents(obj)) {
  13. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj)
  14. 	    if (objects[otmp->otyp].oc_material == material) return otmp;
  15. 	    else if (Has_contents(otmp) && (temp = o_material(otmp, material)))
  16. 		return temp;
  17. }
  18. return (struct obj *) 0;
  19. }

do_dknown_of

  1. STATIC_OVL void
  2. do_dknown_of(obj)
  3. struct obj *obj;
  4. {
  5. struct obj *otmp;
  6.  
  7. obj->dknown = 1;
  8. if (Has_contents(obj)) {
  9. 	for(otmp = obj->cobj; otmp; otmp = otmp->nobj)
  10. 	    do_dknown_of(otmp);
  11. }
  12. }

check_map_spot

  1. /* Check whether the location has an outdated object displayed on it. */
  2. STATIC_OVL boolean
  3. check_map_spot(x, y, oclass, material)
  4. int x, y;
  5. register char oclass;
  6. unsigned material;
  7. {
  8. 	register int glyph;
  9. 	register struct obj *otmp;
  10. 	register struct monst *mtmp;
  11.  
  12. 	glyph = glyph_at(x,y);
  13. 	if (glyph_is_object(glyph)) {
  14. 	    /* there's some object shown here */
  15. 	    if (oclass == ALL_CLASSES) {
  16. 		return((boolean)( !(level.objects[x][y] ||     /* stale if nothing here */
  17. 			    ((mtmp = m_at(x,y)) != 0 &&
  18. 				(
  19. #ifndef GOLDOBJ
  20. 				 mtmp->mgold ||
  21. #endif
  22. 						 mtmp->minvent)))));
  23. 	    } else {
  24. 		if (material && objects[glyph_to_obj(glyph)].oc_material == material) {
  25. 			/* the object shown here is of interest because material matches */
  26. 			for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  27. 				if (o_material(otmp, GOLD)) return FALSE;
  28. 			/* didn't find it; perhaps a monster is carrying it */
  29. 			if ((mtmp = m_at(x,y)) != 0) {
  30. 				for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  31. 					if (o_material(otmp, GOLD)) return FALSE;
  32. 		        }
  33. 			/* detection indicates removal of this object from the map */
  34. 			return TRUE;
  35. 		}
  36. 	        if (oclass && objects[glyph_to_obj(glyph)].oc_class == oclass) {
  37. 			/* the object shown here is of interest because its class matches */
  38. 			for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  39. 				if (o_in(otmp, oclass)) return FALSE;
  40. 			/* didn't find it; perhaps a monster is carrying it */
  41. #ifndef GOLDOBJ
  42. 			if ((mtmp = m_at(x,y)) != 0) {
  43. 				if (oclass == COIN_CLASS && mtmp->mgold)
  44. 					return FALSE;
  45. 				else for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  46. 					if (o_in(otmp, oclass)) return FALSE;
  47. 		        }
  48. #else
  49. 			if ((mtmp = m_at(x,y)) != 0) {
  50. 				for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  51. 					if (o_in(otmp, oclass)) return FALSE;
  52. 		        }
  53. #endif
  54. 			/* detection indicates removal of this object from the map */
  55. 			return TRUE;
  56. 	        }
  57. 	    }
  58. 	}
  59. 	return FALSE;
  60. }

clear_stale_map

  1. /*
  2. When doing detection, remove stale data from the map display (corpses
  3. rotted away, objects carried away by monsters, etc) so that it won't
  4. reappear after the detection has completed.  Return true if noticeable
  5. change occurs.
  6. */
  7. STATIC_OVL boolean
  8. clear_stale_map(oclass, material)
  9. register char oclass;
  10. unsigned material;
  11. {
  12. 	register int zx, zy;
  13. 	register boolean change_made = FALSE;
  14.  
  15. 	for (zx = 1; zx < COLNO; zx++)
  16. 	    for (zy = 0; zy < ROWNO; zy++)
  17. 		if (check_map_spot(zx, zy, oclass,material)) {
  18. 		    unmap_object(zx, zy);
  19. 		    change_made = TRUE;
  20. 		}
  21.  
  22. 	return change_made;
  23. }

gold_detect

  1. /* look for gold, on the floor or in monsters' possession */
  2. int
  3. gold_detect(sobj)
  4. register struct obj *sobj;
  5. {
  6. register struct obj *obj;
  7. register struct monst *mtmp;
  8. int uw = u.uinwater;
  9. struct obj *temp;
  10. boolean stale;
  11.  
  12. known = stale = clear_stale_map(COIN_CLASS,
  13. 				(unsigned)(sobj->blessed ? GOLD : 0));
  14.  
  15. /* look for gold carried by monsters (might be in a container) */
  16. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  17. 	if (DEADMONSTER(mtmp)) continue;	/* probably not needed in this case but... */
  18. #ifndef GOLDOBJ
  19. 	if (mtmp->mgold || monsndx(mtmp->data) == PM_GOLD_GOLEM) {
  20. #else
  21. 	if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) {
  22. #endif
  23. 	    known = TRUE;
  24. 	    goto outgoldmap;	/* skip further searching */
  25. 	} else for (obj = mtmp->minvent; obj; obj = obj->nobj)
  26. 	    if (sobj->blessed && o_material(obj, GOLD)) {
  27. 	    	known = TRUE;
  28. 	    	goto outgoldmap;
  29. 	    } else if (o_in(obj, COIN_CLASS)) {
  30. 		known = TRUE;
  31. 		goto outgoldmap;	/* skip further searching */
  32. 	    }
  33. }
  34.  
  35. /* look for gold objects */
  36. for (obj = fobj; obj; obj = obj->nobj) {
  37. 	if (sobj->blessed && o_material(obj, GOLD)) {
  38. 	    known = TRUE;
  39. 	    if (obj->ox != u.ux || obj->oy != u.uy) goto outgoldmap;
  40. 	} else if (o_in(obj, COIN_CLASS)) {
  41. 	    known = TRUE;
  42. 	    if (obj->ox != u.ux || obj->oy != u.uy) goto outgoldmap;
  43. 	}
  44. }
  45.  
  46. if (!known) {
  47. 	/* no gold found on floor or monster's inventory.
  48. 	   adjust message if you have gold in your inventory */
  49. 	if (sobj) {
  50. 		char buf[BUFSZ];
  51. 		if (youmonst.data == &mons[PM_GOLD_GOLEM]) {
  52. 			Sprintf(buf, "You feel like a million %s!",
  53. 				currency(2L));
  54. 		} else if (hidden_gold() ||
  55. #ifndef GOLDOBJ
  56. 				u.ugold)
  57. #else
  58. 			        money_cnt(invent))
  59. #endif
  60. 			Strcpy(buf,
  61. 				"You feel worried about your future financial situation.");
  62. 		else
  63. 			Strcpy(buf, "You feel materially poor.");
  64. 		strange_feeling(sobj, buf);
  65. }
  66. 	return(1);
  67. }
  68. /* only under me - no separate display required */
  69. if (stale) docrt();
  70. You("notice some gold between your %s.", makeplural(body_part(FOOT)));
  71. return(0);
  72.  
  73. outgoldmap:
  74. cls();
  75.  
  76. u.uinwater = 0;
  77. /* Discover gold locations. */
  78. for (obj = fobj; obj; obj = obj->nobj) {
  79. 	if (sobj->blessed && (temp = o_material(obj, GOLD))) {
  80. 	    if (temp != obj) {
  81. 		temp->ox = obj->ox;
  82. 		temp->oy = obj->oy;
  83. 	    }
  84. 	    map_object(temp,1);
  85. 	} else if ((temp = o_in(obj, COIN_CLASS))) {
  86. 	    if (temp != obj) {
  87. 		temp->ox = obj->ox;
  88. 		temp->oy = obj->oy;
  89. 	    }
  90. 	    map_object(temp,1);
  91. 	}
  92. }
  93. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  94. 	if (DEADMONSTER(mtmp)) continue;	/* probably overkill here */
  95. #ifndef GOLDOBJ
  96. 	if (mtmp->mgold || monsndx(mtmp->data) == PM_GOLD_GOLEM) {
  97. #else
  98. 	if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) {
  99. #endif
  100. 	    struct obj gold;
  101.  
  102. 	    gold.otyp = GOLD_PIECE;
  103. 	    gold.ox = mtmp->mx;
  104. 	    gold.oy = mtmp->my;
  105. 	    map_object(&gold,1);
  106. 	} else for (obj = mtmp->minvent; obj; obj = obj->nobj)
  107. 	    if (sobj->blessed && (temp = o_material(obj, GOLD))) {
  108. 		temp->ox = mtmp->mx;
  109. 		temp->oy = mtmp->my;
  110. 		map_object(temp,1);
  111. 		break;
  112. 	    } else if ((temp = o_in(obj, COIN_CLASS))) {
  113. 		temp->ox = mtmp->mx;
  114. 		temp->oy = mtmp->my;
  115. 		map_object(temp,1);
  116. 		break;
  117. 	    }
  118. }
  119.  
  120. newsym(u.ux,u.uy);
  121. You_feel("very greedy, and sense gold!");
  122. exercise(A_WIS, TRUE);
  123. display_nhwindow(WIN_MAP, TRUE);
  124. docrt();
  125. u.uinwater = uw;
  126. if (Underwater) under_water(2);
  127. if (u.uburied) under_ground(2);
  128. return(0);
  129. }

food_detect

  1. /* returns 1 if nothing was detected		*/
  2. /* returns 0 if something was detected		*/
  3. int
  4. food_detect(sobj)
  5. register struct obj	*sobj;
  6. {
  7. register struct obj *obj;
  8. register struct monst *mtmp;
  9. register int ct = 0, ctu = 0;
  10. boolean confused = (Confusion || (sobj && sobj->cursed)), stale;
  11. char oclass = confused ? POTION_CLASS : FOOD_CLASS;
  12. const char *what = confused ? something : "food";
  13. int uw = u.uinwater;
  14.  
  15. stale = clear_stale_map(oclass, 0);
  16.  
  17. for (obj = fobj; obj; obj = obj->nobj)
  18. 	if (o_in(obj, oclass)) {
  19. 	    if (obj->ox == u.ux && obj->oy == u.uy) ctu++;
  20. 	    else ct++;
  21. 	}
  22. for (mtmp = fmon; mtmp && !ct; mtmp = mtmp->nmon) {
  23. 	/* no DEADMONSTER(mtmp) check needed since dmons never have inventory */
  24. 	for (obj = mtmp->minvent; obj; obj = obj->nobj)
  25. 	    if (o_in(obj, oclass)) {
  26. 		ct++;
  27. 		break;
  28. 	    }
  29. }
  30.  
  31. if (!ct && !ctu) {
  32. 	known = stale && !confused;
  33. 	if (stale) {
  34. 	    docrt();
  35. 	    You("sense a lack of %s nearby.", what);
  36. 	    if (sobj && sobj->blessed) {
  37. 		if (!u.uedibility) Your("%s starts to tingle.", body_part(NOSE));
  38. 		u.uedibility = 1;
  39. 	    }
  40. 	} else if (sobj) {
  41. 	    char buf[BUFSZ];
  42. 	    Sprintf(buf, "Your %s twitches%s.", body_part(NOSE),
  43. 			(sobj->blessed && !u.uedibility) ? " then starts to tingle" : "");
  44. 	    if (sobj->blessed && !u.uedibility) {
  45. 		boolean savebeginner = flags.beginner;	/* prevent non-delivery of */
  46. 		flags.beginner = FALSE;			/* 	message            */
  47. 		strange_feeling(sobj, buf);
  48. 		flags.beginner = savebeginner;
  49. 		u.uedibility = 1;
  50. 	    } else
  51. 		strange_feeling(sobj, buf);
  52. 	}
  53. 	return !stale;
  54. } else if (!ct) {
  55. 	known = TRUE;
  56. 	You("%s %s nearby.", sobj ? "smell" : "sense", what);
  57. 	if (sobj && sobj->blessed) {
  58. 		if (!u.uedibility) pline("Your %s starts to tingle.", body_part(NOSE));
  59. 		u.uedibility = 1;
  60. 	}
  61. } else {
  62. 	struct obj *temp;
  63. 	known = TRUE;
  64. 	cls();
  65. 	u.uinwater = 0;
  66. 	for (obj = fobj; obj; obj = obj->nobj)
  67. 	    if ((temp = o_in(obj, oclass)) != 0) {
  68. 		if (temp != obj) {
  69. 		    temp->ox = obj->ox;
  70. 		    temp->oy = obj->oy;
  71. 		}
  72. 		map_object(temp,1);
  73. 	    }
  74. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  75. 	    /* no DEADMONSTER(mtmp) check needed since dmons never have inventory */
  76. 	    for (obj = mtmp->minvent; obj; obj = obj->nobj)
  77. 		if ((temp = o_in(obj, oclass)) != 0) {
  78. 		    temp->ox = mtmp->mx;
  79. 		    temp->oy = mtmp->my;
  80. 		    map_object(temp,1);
  81. 		    break;	/* skip rest of this monster's inventory */
  82. 		}
  83. 	newsym(u.ux,u.uy);
  84. 	if (sobj) {
  85. 	    if (sobj->blessed) {
  86. 	    	Your("%s %s to tingle and you smell %s.", body_part(NOSE),
  87. 	    		u.uedibility ? "continues" : "starts", what);
  88. 		u.uedibility = 1;
  89. 	    } else
  90. 		Your("%s tingles and you smell %s.", body_part(NOSE), what);
  91. 	}
  92. 	else You("sense %s.", what);
  93. 	display_nhwindow(WIN_MAP, TRUE);
  94. 	exercise(A_WIS, TRUE);
  95. 	docrt();
  96. 	u.uinwater = uw;
  97. 	if (Underwater) under_water(2);
  98. 	if (u.uburied) under_ground(2);
  99. }
  100. return(0);
  101. }

object_detect

  1. /*
  2. * Used for scrolls, potions, spells, and crystal balls.  Returns:
  3. *
  4. *	1 - nothing was detected
  5. *	0 - something was detected
  6. */
  7. int
  8. object_detect(detector, class)
  9. struct obj	*detector;	/* object doing the detecting */
  10. int		class;		/* an object class, 0 for all */
  11. {
  12. register int x, y;
  13. char stuff[BUFSZ];
  14. int is_cursed = (detector && detector->cursed);
  15. int do_dknown = (detector && (detector->oclass == POTION_CLASS ||
  16. 				    detector->oclass == SPBOOK_CLASS) &&
  17. 			detector->blessed);
  18. int ct = 0, ctu = 0;
  19. register struct obj *obj, *otmp = (struct obj *)0;
  20. register struct monst *mtmp;
  21. int uw = u.uinwater;
  22. int sym, boulder = 0;
  23.  
  24. if (class < 0 || class >= MAXOCLASSES) {
  25. 	impossible("object_detect:  illegal class %d", class);
  26. 	class = 0;
  27. }
  28.  
  29. /* Special boulder symbol check - does the class symbol happen
  30. * to match iflags.bouldersym which is a user-defined?
  31. * If so, that means we aren't sure what they really wanted to
  32. * detect. Rather than trump anything, show both possibilities.
  33. * We can exclude checking the buried obj chain for boulders below.
  34. */
  35. sym = class ? def_oc_syms[class] : 0;
  36. if (sym && iflags.bouldersym && sym == iflags.bouldersym)
  37. 	boulder = ROCK_CLASS;
  38.  
  39. if (Hallucination || (Confusion && class == SCROLL_CLASS))
  40. 	Strcpy(stuff, something);
  41. else
  42. 	Strcpy(stuff, class ? oclass_names[class] : "objects");
  43. if (boulder && class != ROCK_CLASS) Strcat(stuff, " and/or large stones");
  44.  
  45. if (do_dknown) for(obj = invent; obj; obj = obj->nobj) do_dknown_of(obj);
  46.  
  47. for (obj = fobj; obj; obj = obj->nobj) {
  48. 	if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) {
  49. 	    if (obj->ox == u.ux && obj->oy == u.uy) ctu++;
  50. 	    else ct++;
  51. 	}
  52. 	if (do_dknown) do_dknown_of(obj);
  53. }
  54.  
  55. for (obj = level.buriedobjlist; obj; obj = obj->nobj) {
  56. 	if (!class || o_in(obj, class)) {
  57. 	    if (obj->ox == u.ux && obj->oy == u.uy) ctu++;
  58. 	    else ct++;
  59. 	}
  60. 	if (do_dknown) do_dknown_of(obj);
  61. }
  62.  
  63. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  64. 	if (DEADMONSTER(mtmp)) continue;
  65. 	for (obj = mtmp->minvent; obj; obj = obj->nobj) {
  66. 	    if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) ct++;
  67. 	    if (do_dknown) do_dknown_of(obj);
  68. 	}
  69. 	if ((is_cursed && mtmp->m_ap_type == M_AP_OBJECT &&
  70. 	    (!class || class == objects[mtmp->mappearance].oc_class)) ||
  71. #ifndef GOLDOBJ
  72. 	    (mtmp->mgold && (!class || class == COIN_CLASS))) {
  73. #else
  74. 	    (findgold(mtmp->minvent) && (!class || class == COIN_CLASS))) {
  75. #endif
  76. 	    ct++;
  77. 	    break;
  78. 	}
  79. }
  80.  
  81. if (!clear_stale_map(!class ? ALL_CLASSES : class, 0) && !ct) {
  82. 	if (!ctu) {
  83. 	    if (detector)
  84. 		strange_feeling(detector, "You feel a lack of something.");
  85. 	    return 1;
  86. 	}
  87.  
  88. 	You("sense %s nearby.", stuff);
  89. 	return 0;
  90. }
  91.  
  92. cls();
  93.  
  94. u.uinwater = 0;
  95. /*
  96. *	Map all buried objects first.
  97. */
  98. for (obj = level.buriedobjlist; obj; obj = obj->nobj)
  99. 	if (!class || (otmp = o_in(obj, class))) {
  100. 	    if (class) {
  101. 		if (otmp != obj) {
  102. 		    otmp->ox = obj->ox;
  103. 		    otmp->oy = obj->oy;
  104. 		}
  105. 		map_object(otmp, 1);
  106. 	    } else
  107. 		map_object(obj, 1);
  108. 	}
  109. /*
  110. * If we are mapping all objects, map only the top object of a pile or
  111. * the first object in a monster's inventory.  Otherwise, go looking
  112. * for a matching object class and display the first one encountered
  113. * at each location.
  114. *
  115. * Objects on the floor override buried objects.
  116. */
  117. for (x = 1; x < COLNO; x++)
  118. 	for (y = 0; y < ROWNO; y++)
  119. 	    for (obj = level.objects[x][y]; obj; obj = obj->nexthere)
  120. 		if ((!class && !boulder) ||
  121. 		    (otmp = o_in(obj, class)) || (otmp = o_in(obj, boulder))) {
  122. 		    if (class || boulder) {
  123. 			if (otmp != obj) {
  124. 			    otmp->ox = obj->ox;
  125. 			    otmp->oy = obj->oy;
  126. 			}
  127. 			map_object(otmp, 1);
  128. 		    } else
  129. 			map_object(obj, 1);
  130. 		    break;
  131. 		}
  132.  
  133. /* Objects in the monster's inventory override floor objects. */
  134. for (mtmp = fmon ; mtmp ; mtmp = mtmp->nmon) {
  135. 	if (DEADMONSTER(mtmp)) continue;
  136. 	for (obj = mtmp->minvent; obj; obj = obj->nobj)
  137. 	    if ((!class && !boulder) ||
  138. 		 (otmp = o_in(obj, class)) || (otmp = o_in(obj, boulder))) {
  139. 		if (!class && !boulder) otmp = obj;
  140. 		otmp->ox = mtmp->mx;		/* at monster location */
  141. 		otmp->oy = mtmp->my;
  142. 		map_object(otmp, 1);
  143. 		break;
  144. 	    }
  145. 	/* Allow a mimic to override the detected objects it is carrying. */
  146. 	if (is_cursed && mtmp->m_ap_type == M_AP_OBJECT &&
  147. 		(!class || class == objects[mtmp->mappearance].oc_class)) {
  148. 	    struct obj temp;
  149.  
  150. 	    temp.otyp = mtmp->mappearance;	/* needed for obj_to_glyph() */
  151. 	    temp.ox = mtmp->mx;
  152. 	    temp.oy = mtmp->my;
  153. 	    temp.corpsenm = PM_TENGU;		/* if mimicing a corpse */
  154. 	    map_object(&temp, 1);
  155. #ifndef GOLDOBJ
  156. 	} else if (mtmp->mgold && (!class || class == COIN_CLASS)) {
  157. #else
  158. 	} else if (findgold(mtmp->minvent) && (!class || class == COIN_CLASS)) {
  159. #endif
  160. 	    struct obj gold;
  161.  
  162. 	    gold.otyp = GOLD_PIECE;
  163. 	    gold.ox = mtmp->mx;
  164. 	    gold.oy = mtmp->my;
  165. 	    map_object(&gold, 1);
  166. 	}
  167. }
  168.  
  169. newsym(u.ux,u.uy);
  170. You("detect the %s of %s.", ct ? "presence" : "absence", stuff);
  171. display_nhwindow(WIN_MAP, TRUE);
  172. /*
  173. * What are we going to do when the hero does an object detect while blind
  174. * and the detected object covers a known pool?
  175. */
  176. docrt();	/* this will correctly reset vision */
  177.  
  178. u.uinwater = uw;
  179. if (Underwater) under_water(2);
  180. if (u.uburied) under_ground(2);
  181. return 0;
  182. }

monster_detect

  1. /*
  2. * Used by: crystal balls, potions, fountains
  3. *
  4. * Returns 1 if nothing was detected.
  5. * Returns 0 if something was detected.
  6. */
  7. int
  8. monster_detect(otmp, mclass)
  9. register struct obj *otmp;	/* detecting object (if any) */
  10. int mclass;			/* monster class, 0 for all */
  11. {
  12. register struct monst *mtmp;
  13. int mcnt = 0;
  14.  
  15.  
  16. /* Note: This used to just check fmon for a non-zero value
  17. * but in versions since 3.3.0 fmon can test TRUE due to the
  18. * presence of dmons, so we have to find at least one
  19. * with positive hit-points to know for sure.
  20. */
  21. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  22. 	if (!DEADMONSTER(mtmp)) {
  23. 		mcnt++;
  24. 		break;
  25. 	}
  26.  
  27. if (!mcnt) {
  28. 	if (otmp)
  29. 	    strange_feeling(otmp, Hallucination ?
  30. 			    "You get the heebie jeebies." :
  31. 			    "You feel threatened.");
  32. 	return 1;
  33. } else {
  34. 	boolean woken = FALSE;
  35.  
  36. 	cls();
  37. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  38. 	    if (DEADMONSTER(mtmp)) continue;
  39. 	    if (!mclass || mtmp->data->mlet == mclass ||
  40. 		(mtmp->data == &mons[PM_LONG_WORM] && mclass == S_WORM_TAIL))
  41. 		    if (mtmp->mx > 0) {
  42. 		    	if (mclass && def_monsyms[mclass] == ' ')
  43. 				show_glyph(mtmp->mx,mtmp->my,
  44. 					detected_mon_to_glyph(mtmp));
  45. 			else
  46. 				show_glyph(mtmp->mx,mtmp->my,mon_to_glyph(mtmp));
  47. 			/* don't be stingy - display entire worm */
  48. 			if (mtmp->data == &mons[PM_LONG_WORM]) detect_wsegs(mtmp,0);
  49. 		    }
  50. 	    if (otmp && otmp->cursed &&
  51. 		(mtmp->msleeping || !mtmp->mcanmove)) {
  52. 		mtmp->msleeping = mtmp->mfrozen = 0;
  53. 		mtmp->mcanmove = 1;
  54. 		woken = TRUE;
  55. 	    }
  56. 	}
  57. 	display_self();
  58. 	You("sense the presence of monsters.");
  59. 	if (woken)
  60. 	    pline("Monsters sense the presence of you.");
  61. 	display_nhwindow(WIN_MAP, TRUE);
  62. 	docrt();
  63. 	if (Underwater) under_water(2);
  64. 	if (u.uburied) under_ground(2);
  65. }
  66. return 0;
  67. }

sense_trap

  1. STATIC_OVL void
  2. sense_trap(trap, x, y, src_cursed)
  3. struct trap *trap;
  4. xchar x, y;
  5. int src_cursed;
  6. {
  7. if (Hallucination || src_cursed) {
  8. 	struct obj obj;			/* fake object */
  9. 	if (trap) {
  10. 	    obj.ox = trap->tx;
  11. 	    obj.oy = trap->ty;
  12. 	} else {
  13. 	    obj.ox = x;
  14. 	    obj.oy = y;
  15. 	}
  16. 	obj.otyp = (src_cursed) ? GOLD_PIECE : random_object();
  17. 	obj.corpsenm = random_monster();	/* if otyp == CORPSE */
  18. 	map_object(&obj,1);
  19. } else if (trap) {
  20. 	map_trap(trap,1);
  21. 	trap->tseen = 1;
  22. } else {
  23. 	struct trap temp_trap;		/* fake trap */
  24. 	temp_trap.tx = x;
  25. 	temp_trap.ty = y;
  26. 	temp_trap.ttyp = BEAR_TRAP;	/* some kind of trap */
  27. 	map_trap(&temp_trap,1);
  28. }
  29.  
  30. }

trap_detect

  1. /* the detections are pulled out so they can	*/
  2. /* also be used in the crystal ball routine	*/
  3. /* returns 1 if nothing was detected		*/
  4. /* returns 0 if something was detected		*/
  5. int
  6. trap_detect(sobj)
  7. register struct obj *sobj;
  8. /* sobj is null if crystal ball, *scroll if gold detection scroll */
  9. {
  10. register struct trap *ttmp;
  11. register struct obj *obj;
  12. register int door;
  13. int uw = u.uinwater;
  14. boolean found = FALSE;
  15. coord cc;
  16.  
  17. for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) {
  18. 	if (ttmp->tx != u.ux || ttmp->ty != u.uy)
  19. 	    goto outtrapmap;
  20. 	else found = TRUE;
  21. }
  22. for (obj = fobj; obj; obj = obj->nobj) {
  23. 	if ((obj->otyp==LARGE_BOX || obj->otyp==CHEST) && obj->otrapped) {
  24. 	    if (obj->ox != u.ux || obj->oy != u.uy)
  25. 		goto outtrapmap;
  26. 	    else found = TRUE;
  27. 	}
  28. }
  29. for (door = 0; door < doorindex; door++) {
  30. 	cc = doors[door];
  31. 	if (levl[cc.x][cc.y].doormask & D_TRAPPED) {
  32. 	    if (cc.x != u.ux || cc.y != u.uy)
  33. 		goto outtrapmap;
  34. 	    else found = TRUE;
  35. 	}
  36. }
  37. if (!found) {
  38. 	char buf[42];
  39. 	Sprintf(buf, "Your %s stop itching.", makeplural(body_part(TOE)));
  40. 	strange_feeling(sobj,buf);
  41. 	return(1);
  42. }
  43. /* traps exist, but only under me - no separate display required */
  44. Your("%s itch.", makeplural(body_part(TOE)));
  45. return(0);
  46. outtrapmap:
  47. cls();
  48.  
  49. u.uinwater = 0;
  50. for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap)
  51. 	sense_trap(ttmp, 0, 0, sobj && sobj->cursed);
  52.  
  53. for (obj = fobj; obj; obj = obj->nobj)
  54. 	if ((obj->otyp==LARGE_BOX || obj->otyp==CHEST) && obj->otrapped)
  55. 	sense_trap((struct trap *)0, obj->ox, obj->oy, sobj && sobj->cursed);
  56.  
  57. for (door = 0; door < doorindex; door++) {
  58. 	cc = doors[door];
  59. 	if (levl[cc.x][cc.y].doormask & D_TRAPPED)
  60. 	sense_trap((struct trap *)0, cc.x, cc.y, sobj && sobj->cursed);
  61. }
  62.  
  63. newsym(u.ux,u.uy);
  64. You_feel("%s.", sobj && sobj->cursed ? "very greedy" : "entrapped");
  65. display_nhwindow(WIN_MAP, TRUE);
  66. docrt();
  67. u.uinwater = uw;
  68. if (Underwater) under_water(2);
  69. if (u.uburied) under_ground(2);
  70. return(0);
  71. }

level_distance

  1. const char *
  2. level_distance(where)
  3. d_level *where;
  4. {
  5. register schar ll = depth(&u.uz) - depth(where);
  6. register boolean indun = (u.uz.dnum == where->dnum);
  7.  
  8. if (ll < 0) {
  9. 	if (ll < (-8 - rn2(3)))
  10. 	    if (!indun)	return "far away";
  11. 	    else	return "far below";
  12. 	else if (ll < -1)
  13. 	    if (!indun)	return "away below you";
  14. 	    else	return "below you";
  15. 	else
  16. 	    if (!indun)	return "in the distance";
  17. 	    else	return "just below";
  18. } else if (ll > 0) {
  19. 	if (ll > (8 + rn2(3)))
  20. 	    if (!indun)	return "far away";
  21. 	    else	return "far above";
  22. 	else if (ll > 1)
  23. 	    if (!indun)	return "away above you";
  24. 	    else	return "above you";
  25. 	else
  26. 	    if (!indun)	return "in the distance";
  27. 	    else	return "just above";
  28. } else
  29. 	    if (!indun)	return "in the distance";
  30. 	    else	return "near you";
  31. }

use_crystal_ball

  1. static const struct {
  2. const char *what;
  3. d_level *where;
  4. } level_detects[] = {
  5. { "Delphi", &oracle_level },
  6. { "Medusa's lair", &medusa_level },
  7. { "a castle", &stronghold_level },
  8. { "the Wizard of Yendor's tower", &wiz1_level },
  9. };
  10.  
  11. void
  12. use_crystal_ball(obj)
  13. struct obj *obj;
  14. {
  15. char ch;
  16. int oops;
  17.  
  18. if (Blind) {
  19. 	pline("Too bad you can't see %s.", the(xname(obj)));
  20. 	return;
  21. }
  22. oops = (rnd(20) > ACURR(A_INT) || obj->cursed);
  23. if (oops && (obj->spe > 0)) {
  24. 	switch (rnd(obj->oartifact ? 4 : 5)) {
  25. 	case 1 : pline("%s too much to comprehend!", Tobjnam(obj, "are"));
  26. 	    break;
  27. 	case 2 : pline("%s you!", Tobjnam(obj, "confuse"));
  28. 	    make_confused(HConfusion + rnd(100),FALSE);
  29. 	    break;
  30. 	case 3 : if (!resists_blnd(&youmonst)) {
  31. 		pline("%s your vision!", Tobjnam(obj, "damage"));
  32. 		make_blinded(Blinded + rnd(100),FALSE);
  33. 		if (!Blind) Your(vision_clears);
  34. 	    } else {
  35. 		pline("%s your vision.", Tobjnam(obj, "assault"));
  36. 		You("are unaffected!");
  37. 	    }
  38. 	    break;
  39. 	case 4 : pline("%s your mind!", Tobjnam(obj, "zap"));
  40. 	    (void) make_hallucinated(HHallucination + rnd(100),FALSE,0L);
  41. 	    break;
  42. 	case 5 : pline("%s!", Tobjnam(obj, "explode"));
  43. 	    useup(obj);
  44. 	    obj = 0;	/* it's gone */
  45. 	    losehp(rnd(30), "exploding crystal ball", KILLED_BY_AN);
  46. 	    break;
  47. 	}
  48. 	if (obj) consume_obj_charge(obj, TRUE);
  49. 	return;
  50. }
  51.  
  52. if (Hallucination) {
  53. 	if (!obj->spe) {
  54. 	    pline("All you see is funky %s haze.", hcolor((char *)0));
  55. 	} else {
  56. 	    switch(rnd(6)) {
  57. 	    case 1 : You("grok some groovy globs of incandescent lava.");
  58. 		break;
  59. 	    case 2 : pline("Whoa!  Psychedelic colors, %s!",
  60. 			   poly_gender() == 1 ? "babe" : "dude");
  61. 		break;
  62. 	    case 3 : pline_The("crystal pulses with sinister %s light!",
  63. 				hcolor((char *)0));
  64. 		break;
  65. 	    case 4 : You("see goldfish swimming above fluorescent rocks.");
  66. 		break;
  67. 	    case 5 : You("see tiny snowflakes spinning around a miniature farmhouse.");
  68. 		break;
  69. 	    default: pline("Oh wow... like a kaleidoscope!");
  70. 		break;
  71. 	    }
  72. 	    consume_obj_charge(obj, TRUE);
  73. 	}
  74. 	return;
  75. }
  76.  
  77. /* read a single character */
  78. if (flags.verbose) You("may look for an object or monster symbol.");
  79. ch = yn_function("What do you look for?", (char *)0, '\0');
  80. /* Don't filter out ' ' here; it has a use */
  81. if ((ch != def_monsyms[S_GHOST]) && index(quitchars,ch)) { 
  82. 	if (flags.verbose) pline(Never_mind);
  83. 	return;
  84. }
  85. You("peer into %s...", the(xname(obj)));
  86. nomul(-rnd(10));
  87. nomovemsg = "";
  88. if (obj->spe <= 0)
  89. 	pline_The("vision is unclear.");
  90. else {
  91. 	int class;
  92. 	int ret = 0;
  93.  
  94. 	makeknown(CRYSTAL_BALL);
  95. 	consume_obj_charge(obj, TRUE);
  96.  
  97. 	/* special case: accept ']' as synonym for mimic
  98. 	 * we have to do this before the def_char_to_objclass check
  99. 	 */
  100. 	if (ch == DEF_MIMIC_DEF) ch = DEF_MIMIC;
  101.  
  102. 	if ((class = def_char_to_objclass(ch)) != MAXOCLASSES)
  103. 		ret = object_detect((struct obj *)0, class);
  104. 	else if ((class = def_char_to_monclass(ch)) != MAXMCLASSES)
  105. 		ret = monster_detect((struct obj *)0, class);
  106. 	else if (iflags.bouldersym && (ch == iflags.bouldersym))
  107. 		ret = object_detect((struct obj *)0, ROCK_CLASS);
  108. 	else switch(ch) {
  109. 		case '^':
  110. 		    ret = trap_detect((struct obj *)0);
  111. 		    break;
  112. 		default:
  113. 		    {
  114. 		    int i = rn2(SIZE(level_detects));
  115. 		    You("see %s, %s.",
  116. 			level_detects[i].what,
  117. 			level_distance(level_detects[i].where));
  118. 		    }
  119. 		    ret = 0;
  120. 		    break;
  121. 	}
  122.  
  123. 	if (ret) {
  124. 	    if (!rn2(100))  /* make them nervous */
  125. 		You("see the Wizard of Yendor gazing out at you.");
  126. 	    else pline_The("vision is unclear.");
  127. 	}
  128. }
  129. return;
  130. }

show_map_spot

  1. STATIC_OVL void
  2. show_map_spot(x, y)
  3. register int x, y;
  4. {
  5. register struct rm *lev;
  6.  
  7. if (Confusion && rn2(7)) return;
  8. lev = &levl[x][y];
  9.  
  10. lev->seenv = SVALL;
  11.  
  12. /* Secret corridors are found, but not secret doors. */
  13. if (lev->typ == SCORR) {
  14. 	lev->typ = CORR;
  15. 	unblock_point(x,y);
  16. }
  17.  
  18. /* if we don't remember an object or trap there, map it */
  19. if (lev->typ == ROOM ?
  20. 	    (glyph_is_cmap(lev->glyph) && !glyph_is_trap(lev->glyph) &&
  21. 		glyph_to_cmap(lev->glyph) != ROOM) :
  22. 	    (!glyph_is_object(lev->glyph) && !glyph_is_trap(lev->glyph))) {
  23. 	if (level.flags.hero_memory) {
  24. 	    magic_map_background(x,y,0);
  25. 	    newsym(x,y);			/* show it, if not blocked */
  26. 	} else {
  27. 	    magic_map_background(x,y,1);	/* display it */
  28. 	}
  29. }
  30. }

do_mapping

  1. void
  2. do_mapping()
  3. {
  4. register int zx, zy;
  5. int uw = u.uinwater;
  6.  
  7. u.uinwater = 0;
  8. for (zx = 1; zx < COLNO; zx++)
  9. 	for (zy = 0; zy < ROWNO; zy++)
  10. 	    show_map_spot(zx, zy);
  11. exercise(A_WIS, TRUE);
  12. u.uinwater = uw;
  13. if (!level.flags.hero_memory || Underwater) {
  14. 	flush_screen(1);			/* flush temp screen */
  15. 	display_nhwindow(WIN_MAP, TRUE);	/* wait */
  16. 	docrt();
  17. }
  18. }

do_vicinity_map

  1. void
  2. do_vicinity_map()
  3. {
  4. register int zx, zy;
  5. int lo_y = (u.uy-5 < 0 ? 0 : u.uy-5),
  6. 	hi_y = (u.uy+6 > ROWNO ? ROWNO : u.uy+6),
  7. 	lo_x = (u.ux-9 < 1 ? 1 : u.ux-9),	/* avoid column 0 */
  8. 	hi_x = (u.ux+10 > COLNO ? COLNO : u.ux+10);
  9.  
  10. for (zx = lo_x; zx < hi_x; zx++)
  11. 	for (zy = lo_y; zy < hi_y; zy++)
  12. 	    show_map_spot(zx, zy);
  13.  
  14. if (!level.flags.hero_memory || Underwater) {
  15. 	flush_screen(1);			/* flush temp screen */
  16. 	display_nhwindow(WIN_MAP, TRUE);	/* wait */
  17. 	docrt();
  18. }
  19. }

cvt_sdoor_to_door

  1. /* convert a secret door into a normal door */
  2. void
  3. cvt_sdoor_to_door(lev)
  4. struct rm *lev;
  5. {
  6. 	int newmask = lev->doormask & ~WM_MASK;
  7.  
  8. #ifdef REINCARNATION
  9. 	if (Is_rogue_level(&u.uz))
  10. 	    /* rogue didn't have doors, only doorways */
  11. 	    newmask = D_NODOOR;
  12. 	else
  13. #endif
  14. 	    /* newly exposed door is closed */
  15. 	    if (!(newmask & D_LOCKED)) newmask |= D_CLOSED;
  16.  
  17. 	lev->typ = DOOR;
  18. 	lev->doormask = newmask;
  19. }

findone

  1. STATIC_PTR void
  2. findone(zx,zy,num)
  3. int zx,zy;
  4. genericptr_t num;
  5. {
  6. 	register struct trap *ttmp;
  7. 	register struct monst *mtmp;
  8.  
  9. 	if(levl[zx][zy].typ == SDOOR) {
  10. 		cvt_sdoor_to_door(&levl[zx][zy]);	/* .typ = DOOR */
  11. 		magic_map_background(zx, zy, 0);
  12. 		newsym(zx, zy);
  13. 		(*(int*)num)++;
  14. 	} else if(levl[zx][zy].typ == SCORR) {
  15. 		levl[zx][zy].typ = CORR;
  16. 		unblock_point(zx,zy);
  17. 		magic_map_background(zx, zy, 0);
  18. 		newsym(zx, zy);
  19. 		(*(int*)num)++;
  20. 	} else if ((ttmp = t_at(zx, zy)) != 0) {
  21. 		if(!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) {
  22. 			ttmp->tseen = 1;
  23. 			newsym(zx,zy);
  24. 			(*(int*)num)++;
  25. 		}
  26. 	} else if ((mtmp = m_at(zx, zy)) != 0) {
  27. 		if(mtmp->m_ap_type) {
  28. 			seemimic(mtmp);
  29. 			(*(int*)num)++;
  30. 		}
  31. 		if (mtmp->mundetected &&
  32. 		    (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL)) {
  33. 			mtmp->mundetected = 0;
  34. 			newsym(zx, zy);
  35. 			(*(int*)num)++;
  36. 		}
  37. 		if (!canspotmon(mtmp) &&
  38. 				    !glyph_is_invisible(levl[zx][zy].glyph))
  39. 			map_invisible(zx, zy);
  40. 	} else if (glyph_is_invisible(levl[zx][zy].glyph)) {
  41. 		unmap_object(zx, zy);
  42. 		newsym(zx, zy);
  43. 		(*(int*)num)++;
  44. 	}
  45. }

openone

  1. STATIC_PTR void
  2. openone(zx,zy,num)
  3. int zx,zy;
  4. genericptr_t num;
  5. {
  6. 	register struct trap *ttmp;
  7. 	register struct obj *otmp;
  8.  
  9. 	if(OBJ_AT(zx, zy)) {
  10. 		for(otmp = level.objects[zx][zy];
  11. 				otmp; otmp = otmp->nexthere) {
  12. 		    if(Is_box(otmp) && otmp->olocked) {
  13. 			otmp->olocked = 0;
  14. 			(*(int*)num)++;
  15. 		    }
  16. 		}
  17. 		/* let it fall to the next cases. could be on trap. */
  18. 	}
  19. 	if(levl[zx][zy].typ == SDOOR || (levl[zx][zy].typ == DOOR &&
  20. 		      (levl[zx][zy].doormask & (D_CLOSED|D_LOCKED)))) {
  21. 		if(levl[zx][zy].typ == SDOOR)
  22. 		    cvt_sdoor_to_door(&levl[zx][zy]);	/* .typ = DOOR */
  23. 		if(levl[zx][zy].doormask & D_TRAPPED) {
  24. 		    if(distu(zx, zy) < 3) b_trapped("door", 0);
  25. 		    else Norep("You %s an explosion!",
  26. 				cansee(zx, zy) ? "see" :
  27. 				   (flags.soundok ? "hear" :
  28. 						"feel the shock of"));
  29. 		    wake_nearto(zx, zy, 11*11);
  30. 		    levl[zx][zy].doormask = D_NODOOR;
  31. 		} else
  32. 		    levl[zx][zy].doormask = D_ISOPEN;
  33. 		unblock_point(zx, zy);
  34. 		newsym(zx, zy);
  35. 		(*(int*)num)++;
  36. 	} else if(levl[zx][zy].typ == SCORR) {
  37. 		levl[zx][zy].typ = CORR;
  38. 		unblock_point(zx, zy);
  39. 		newsym(zx, zy);
  40. 		(*(int*)num)++;
  41. 	} else if ((ttmp = t_at(zx, zy)) != 0) {
  42. 		if (!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) {
  43. 		    ttmp->tseen = 1;
  44. 		    newsym(zx,zy);
  45. 		    (*(int*)num)++;
  46. 		}
  47. 	} else if (find_drawbridge(&zx, &zy)) {
  48. 		/* make sure it isn't an open drawbridge */
  49. 		open_drawbridge(zx, zy);
  50. 		(*(int*)num)++;
  51. 	}
  52. }

findit

  1. int
  2. findit()	/* returns number of things found */
  3. {
  4. 	int num = 0;
  5.  
  6. 	if(u.uswallow) return(0);
  7. 	do_clear_area(u.ux, u.uy, BOLT_LIM, findone, (genericptr_t) &num);
  8. 	return(num);
  9. }

openit

  1. int
  2. openit()	/* returns number of things found and opened */
  3. {
  4. 	int num = 0;
  5.  
  6. 	if(u.uswallow) {
  7. 		if (is_animal(u.ustuck->data)) {
  8. 			if (Blind) pline("Its mouth opens!");
  9. 			else pline("%s opens its mouth!", Monnam(u.ustuck));
  10. 		}
  11. 		expels(u.ustuck, u.ustuck->data, TRUE);
  12. 		return(-1);
  13. 	}
  14.  
  15. 	do_clear_area(u.ux, u.uy, BOLT_LIM, openone, (genericptr_t) &num);
  16. 	return(num);
  17. }

find_trap

  1. void
  2. find_trap(trap)
  3. struct trap *trap;
  4. {
  5. int tt = what_trap(trap->ttyp);
  6. boolean cleared = FALSE;
  7.  
  8. trap->tseen = 1;
  9. exercise(A_WIS, TRUE);
  10. if (Blind)
  11. 	feel_location(trap->tx, trap->ty);
  12. else
  13. 	newsym(trap->tx, trap->ty);
  14.  
  15. if (levl[trap->tx][trap->ty].glyph != trap_to_glyph(trap)) {
  16. 	/* There's too much clutter to see your find otherwise */
  17. 	cls();
  18. 	map_trap(trap, 1);
  19. 	display_self();
  20. 	cleared = TRUE;
  21. }
  22.  
  23. You("find %s.", an(defsyms[trap_to_defsym(tt)].explanation));
  24.  
  25. if (cleared) {
  26. 	display_nhwindow(WIN_MAP, TRUE);	/* wait */
  27. 	docrt();
  28. }
  29. }

dosearch0

  1. int
  2. dosearch0(aflag)
  3. register int aflag;
  4. {
  5. #ifdef GCC_BUG
  6. /* some versions of gcc seriously muck up nested loops. if you get strange
  7. crashes while searching in a version compiled with gcc, try putting
  8. #define GCC_BUG in *conf.h (or adding -DGCC_BUG to CFLAGS in the
  9. makefile).
  10. */
  11. 	volatile xchar x, y;
  12. #else
  13. 	register xchar x, y;
  14. #endif
  15. 	register struct trap *trap;
  16. 	register struct monst *mtmp;
  17.  
  18. 	if(u.uswallow) {
  19. 		if (!aflag)
  20. 			pline("What are you looking for?  The exit?");
  21. 	} else {
  22. 	    int fund = (uwep && uwep->oartifact &&
  23. 		    spec_ability(uwep, SPFX_SEARCH)) ?
  24. 		    uwep->spe : 0;
  25. 	    if (ublindf && ublindf->otyp == LENSES && !Blind)
  26. 		    fund += 2; /* JDS: lenses help searching */
  27. 	    if (fund > 5) fund = 5;
  28. 	    for(x = u.ux-1; x < u.ux+2; x++)
  29. 	      for(y = u.uy-1; y < u.uy+2; y++) {
  30. 		if(!isok(x,y)) continue;
  31. 		if(x != u.ux || y != u.uy) {
  32. 		    if (Blind && !aflag) feel_location(x,y);
  33. 		    if(levl[x][y].typ == SDOOR) {
  34. 			if(rnl(7-fund)) continue;
  35. 			cvt_sdoor_to_door(&levl[x][y]);	/* .typ = DOOR */
  36. 			exercise(A_WIS, TRUE);
  37. 			nomul(0);
  38. 			if (Blind && !aflag)
  39. 			    feel_location(x,y);	/* make sure it shows up */
  40. 			else
  41. 			    newsym(x,y);
  42. 		    } else if(levl[x][y].typ == SCORR) {
  43. 			if(rnl(7-fund)) continue;
  44. 			levl[x][y].typ = CORR;
  45. 			unblock_point(x,y);	/* vision */
  46. 			exercise(A_WIS, TRUE);
  47. 			nomul(0);
  48. 			newsym(x,y);
  49. 		    } else {
  50. 		/* Be careful not to find anything in an SCORR or SDOOR */
  51. 			if((mtmp = m_at(x, y)) && !aflag) {
  52. 			    if(mtmp->m_ap_type) {
  53. 				seemimic(mtmp);
  54. 		find:		exercise(A_WIS, TRUE);
  55. 				if (!canspotmon(mtmp)) {
  56. 				    if (glyph_is_invisible(levl[x][y].glyph)) {
  57. 					/* found invisible monster in a square
  58. 					 * which already has an 'I' in it.
  59. 					 * Logically, this should still take
  60. 					 * time and lead to a return(1), but if
  61. 					 * we did that the player would keep
  62. 					 * finding the same monster every turn.
  63. 					 */
  64. 					continue;
  65. 				    } else {
  66. 					You_feel("an unseen monster!");
  67. 					map_invisible(x, y);
  68. 				    }
  69. 				} else if (!sensemon(mtmp))
  70. 				    You("find %s.", a_monnam(mtmp));
  71. 				return(1);
  72. 			    }
  73. 			    if(!canspotmon(mtmp)) {
  74. 				if (mtmp->mundetected &&
  75. 				   (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL))
  76. 					mtmp->mundetected = 0;
  77. 				newsym(x,y);
  78. 				goto find;
  79. 			    }
  80. 			}
  81.  
  82. 			/* see if an invisible monster has moved--if Blind,
  83. 			 * feel_location() already did it
  84. 			 */
  85. 			if (!aflag && !mtmp && !Blind &&
  86. 				    glyph_is_invisible(levl[x][y].glyph)) {
  87. 			    unmap_object(x,y);
  88. 			    newsym(x,y);
  89. 			}
  90.  
  91. 			if ((trap = t_at(x,y)) && !trap->tseen && !rnl(8)) {
  92. 			    nomul(0);
  93.  
  94. 			    if (trap->ttyp == STATUE_TRAP) {
  95. 				if (activate_statue_trap(trap, x, y, FALSE))
  96. 				    exercise(A_WIS, TRUE);
  97. 				return(1);
  98. 			    } else {
  99. 				find_trap(trap);
  100. 			    }
  101. 			}
  102. 		    }
  103. 		}
  104. 	    }
  105. 	}
  106. 	return(1);
  107. }

dosearch

  1. int
  2. dosearch()
  3. {
  4. 	return(dosearch0(0));
  5. }

sokoban_detect

  1. /* Pre-map the sokoban levels */
  2. void
  3. sokoban_detect()
  4. {
  5. 	register int x, y;
  6. 	register struct trap *ttmp;
  7. 	register struct obj *obj;
  8.  
  9. 	/* Map the background and boulders */
  10. 	for (x = 1; x < COLNO; x++)
  11. 	    for (y = 0; y < ROWNO; y++) {
  12. 	    	levl[x][y].seenv = SVALL;
  13. 	    	levl[x][y].waslit = TRUE;
  14. 	    	map_background(x, y, 1);
  15. 	    	for (obj = level.objects[x][y]; obj; obj = obj->nexthere)
  16. 	    	    if (obj->otyp == BOULDER)
  17. 	    	    	map_object(obj, 1);
  18. 	    }
  19.  
  20. 	/* Map the traps */
  21. 	for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) {
  22. 	    ttmp->tseen = 1;
  23. 	    map_trap(ttmp, 1);
  24. 	}
  25. }
  26.  
  27.  
  28. /*detect.c*/