1 /* aNetHack 0.0.1 detect.c $ANH-Date: 1463191981 2016/05/14 02:13:01 $ $ANH-Branch: master $:$ANH-Revision: 1.70 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* aNetHack may be freely redistributed. See license for details. */
6 * Detection routines, including crystal ball, magic mapping, and search
13 extern boolean known
; /* from read.c */
15 STATIC_DCL boolean
NDECL(unconstrain_map
);
16 STATIC_DCL
void NDECL(reconstrain_map
);
17 STATIC_DCL
void FDECL(browse_map
, (int, const char *));
18 STATIC_DCL
void FDECL(map_monst
, (struct monst
*, BOOLEAN_P
));
19 STATIC_DCL
void FDECL(do_dknown_of
, (struct obj
*));
20 STATIC_DCL boolean
FDECL(check_map_spot
, (int, int, CHAR_P
, unsigned));
21 STATIC_DCL boolean
FDECL(clear_stale_map
, (CHAR_P
, unsigned));
22 STATIC_DCL
void FDECL(sense_trap
, (struct trap
*, XCHAR_P
, XCHAR_P
, int));
23 STATIC_DCL
int FDECL(detect_obj_traps
, (struct obj
*, BOOLEAN_P
, int));
24 STATIC_DCL
void FDECL(show_map_spot
, (int, int));
25 STATIC_PTR
void FDECL(findone
, (int, int, genericptr_t
));
26 STATIC_PTR
void FDECL(openone
, (int, int, genericptr_t
));
27 STATIC_DCL
int FDECL(mfind0
, (struct monst
*, BOOLEAN_P
));
28 STATIC_DCL
int FDECL(reveal_terrain_getglyph
, (int, int, int,
31 /* bring hero out from underwater or underground or being engulfed;
32 return True iff any change occurred */
36 boolean res
= u
.uinwater
|| u
.uburied
|| u
.uswallow
;
38 /* bring Underwater, buried, or swallowed hero to normal map */
39 iflags
.save_uinwater
= u
.uinwater
, u
.uinwater
= 0;
40 iflags
.save_uburied
= u
.uburied
, u
.uburied
= 0;
41 iflags
.save_uswallow
= u
.uswallow
, u
.uswallow
= 0;
46 /* put hero back underwater or underground or engulfed */
50 u
.uinwater
= iflags
.save_uinwater
, iflags
.save_uinwater
= 0;
51 u
.uburied
= iflags
.save_uburied
, iflags
.save_uburied
= 0;
52 u
.uswallow
= iflags
.save_uswallow
, iflags
.save_uswallow
= 0;
55 /* use getpos()'s 'autodescribe' to view whatever is currently shown on map */
57 browse_map(ter_typ
, ter_explain
)
59 const char *ter_explain
;
61 coord dummy_pos
; /* don't care whether player actually picks a spot */
63 dummy_pos
.x
= u
.ux
, dummy_pos
.y
= u
.uy
; /* starting spot for getpos() */
64 iflags
.autodescribe
= TRUE
;
65 iflags
.terrainmode
= ter_typ
;
66 getpos(&dummy_pos
, FALSE
, ter_explain
);
67 iflags
.terrainmode
= 0;
68 /* leave iflags.autodescribe 'on' even if previously 'off' */
71 /* extracted from monster_detection() so can be shared by do_vicinity_map() */
73 map_monst(mtmp
, showtail
)
77 if (def_monsyms
[(int) mtmp
->data
->mlet
].sym
== ' ')
78 show_glyph(mtmp
->mx
, mtmp
->my
, detected_mon_to_glyph(mtmp
));
80 show_glyph(mtmp
->mx
, mtmp
->my
,
81 mtmp
->mtame
? pet_to_glyph(mtmp
) : mon_to_glyph(mtmp
));
83 if (showtail
&& mtmp
->data
== &mons
[PM_LONG_WORM
])
84 detect_wsegs(mtmp
, 0);
87 /* this is checking whether a trap symbol represents a trapped chest,
88 not whether a trapped chest is actually present */
90 trapped_chest_at(ttyp
, x
, y
)
97 if (!glyph_is_trap(glyph_at(x
, y
)))
99 if (ttyp
!= BEAR_TRAP
|| (Hallucination
&& rn2(20)))
103 * TODO? We should check containers recursively like the trap
104 * detecting routine does. Chests and large boxes do not nest in
105 * themselves or each other, but could be contained inside statues.
107 * For farlook, we should also check for buried containers, but
108 * for '^' command to examine adjacent trap glyph, we shouldn't.
111 /* on map, presence of any trappable container will do */
112 if (sobj_at(CHEST
, x
, y
) || sobj_at(LARGE_BOX
, x
, y
))
114 /* in inventory, we need to find one which is actually trapped */
115 if (x
== u
.ux
&& y
== u
.uy
) {
116 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
117 if (Is_box(otmp
) && otmp
->otrapped
)
119 if (u
.usteed
) { /* steed isn't on map so won't be found by m_at() */
120 for (otmp
= u
.usteed
->minvent
; otmp
; otmp
= otmp
->nobj
)
121 if (Is_box(otmp
) && otmp
->otrapped
)
125 if ((mtmp
= m_at(x
, y
)) != 0)
126 for (otmp
= mtmp
->minvent
; otmp
; otmp
= otmp
->nobj
)
127 if (Is_box(otmp
) && otmp
->otrapped
)
132 /* this is checking whether a trap symbol represents a trapped door,
133 not whether the door here is actually trapped */
135 trapped_door_at(ttyp
, x
, y
)
141 if (!glyph_is_trap(glyph_at(x
, y
)))
143 if (ttyp
!= BEAR_TRAP
|| (Hallucination
&& rn2(20)))
146 if (!IS_DOOR(lev
->typ
))
148 if ((lev
->doormask
& (D_NODOOR
| D_BROKEN
| D_ISOPEN
)) != 0
149 && trapped_chest_at(ttyp
, x
, y
))
154 /* recursively search obj for an object in class oclass, return 1st found */
160 register struct obj
*otmp
;
163 if (obj
->oclass
== oclass
)
166 if (Has_contents(obj
)) {
167 for (otmp
= obj
->cobj
; otmp
; otmp
= otmp
->nobj
)
168 if (otmp
->oclass
== oclass
)
170 else if (Has_contents(otmp
) && (temp
= o_in(otmp
, oclass
)) != 0)
173 return (struct obj
*) 0;
176 /* Recursively search obj for an object made of specified material.
177 * Return first found.
180 o_material(obj
, material
)
184 register struct obj
*otmp
;
187 if (objects
[obj
->otyp
].oc_material
== material
)
190 if (Has_contents(obj
)) {
191 for (otmp
= obj
->cobj
; otmp
; otmp
= otmp
->nobj
)
192 if (objects
[otmp
->otyp
].oc_material
== material
)
194 else if (Has_contents(otmp
)
195 && (temp
= o_material(otmp
, material
)) != 0)
198 return (struct obj
*) 0;
208 if (Has_contents(obj
)) {
209 for (otmp
= obj
->cobj
; otmp
; otmp
= otmp
->nobj
)
214 /* Check whether the location has an outdated object displayed on it. */
216 check_map_spot(x
, y
, oclass
, material
)
222 register struct obj
*otmp
;
223 register struct monst
*mtmp
;
225 glyph
= glyph_at(x
, y
);
226 if (glyph_is_object(glyph
)) {
227 /* there's some object shown here */
228 if (oclass
== ALL_CLASSES
) {
229 return (boolean
) !(level
.objects
[x
][y
] /* stale if nothing here */
230 || ((mtmp
= m_at(x
, y
)) != 0 && mtmp
->minvent
));
233 && objects
[glyph_to_obj(glyph
)].oc_material
== material
) {
234 /* object shown here is of interest because material matches */
235 for (otmp
= level
.objects
[x
][y
]; otmp
; otmp
= otmp
->nexthere
)
236 if (o_material(otmp
, GOLD
))
238 /* didn't find it; perhaps a monster is carrying it */
239 if ((mtmp
= m_at(x
, y
)) != 0) {
240 for (otmp
= mtmp
->minvent
; otmp
; otmp
= otmp
->nobj
)
241 if (o_material(otmp
, GOLD
))
244 /* detection indicates removal of this object from the map */
247 if (oclass
&& objects
[glyph_to_obj(glyph
)].oc_class
== oclass
) {
248 /* obj shown here is of interest because its class matches */
249 for (otmp
= level
.objects
[x
][y
]; otmp
; otmp
= otmp
->nexthere
)
250 if (o_in(otmp
, oclass
))
252 /* didn't find it; perhaps a monster is carrying it */
253 if ((mtmp
= m_at(x
, y
)) != 0) {
254 for (otmp
= mtmp
->minvent
; otmp
; otmp
= otmp
->nobj
)
255 if (o_in(otmp
, oclass
))
258 /* detection indicates removal of this object from the map */
267 * When doing detection, remove stale data from the map display (corpses
268 * rotted away, objects carried away by monsters, etc) so that it won't
269 * reappear after the detection has completed. Return true if noticeable
273 clear_stale_map(oclass
, material
)
278 boolean change_made
= FALSE
;
280 for (zx
= 1; zx
< COLNO
; zx
++)
281 for (zy
= 0; zy
< ROWNO
; zy
++)
282 if (check_map_spot(zx
, zy
, oclass
, material
)) {
283 unmap_object(zx
, zy
);
290 /* look for gold, on the floor or in monsters' possession */
293 register struct obj
*sobj
;
295 register struct obj
*obj
;
296 register struct monst
*mtmp
;
297 struct obj gold
, *temp
= 0;
298 boolean stale
, ugold
= FALSE
, steedgold
= FALSE
;
299 int ter_typ
= TER_DETECT
| TER_OBJ
;
301 known
= stale
= clear_stale_map(COIN_CLASS
,
302 (unsigned) (sobj
->blessed
? GOLD
: 0));
304 /* look for gold carried by monsters (might be in a container) */
305 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
306 if (DEADMONSTER(mtmp
))
307 continue; /* probably not needed in this case but... */
308 if (findgold(mtmp
->minvent
) || monsndx(mtmp
->data
) == PM_GOLD_GOLEM
) {
309 if (mtmp
== u
.usteed
) {
313 goto outgoldmap
; /* skip further searching */
316 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
317 if ((sobj
->blessed
&& o_material(obj
, GOLD
))
318 || o_in(obj
, COIN_CLASS
)) {
319 if (mtmp
== u
.usteed
) {
323 goto outgoldmap
; /* skip further searching */
329 /* look for gold objects */
330 for (obj
= fobj
; obj
; obj
= obj
->nobj
) {
331 if (sobj
->blessed
&& o_material(obj
, GOLD
)) {
333 if (obj
->ox
!= u
.ux
|| obj
->oy
!= u
.uy
)
335 } else if (o_in(obj
, COIN_CLASS
)) {
337 if (obj
->ox
!= u
.ux
|| obj
->oy
!= u
.uy
)
343 /* no gold found on floor or monster's inventory.
344 adjust message if you have gold in your inventory */
348 if (youmonst
.data
== &mons
[PM_GOLD_GOLEM
])
349 Sprintf(buf
, "You feel like a million %s!", currency(2L));
350 else if (money_cnt(invent
) || hidden_gold())
352 "You feel worried about your future financial situation.");
354 Sprintf(buf
, "You feel interested in %s financial situation.",
355 s_suffix(x_monnam(u
.usteed
,
356 u
.usteed
->mtame
? ARTICLE_YOUR
359 SUPPRESS_SADDLE
, FALSE
)));
361 Strcpy(buf
, "You feel materially poor.");
363 strange_feeling(sobj
, buf
);
367 /* only under me - no separate display required */
370 You("notice some gold between your %s.", makeplural(body_part(FOOT
)));
376 (void) unconstrain_map();
377 /* Discover gold locations. */
378 for (obj
= fobj
; obj
; obj
= obj
->nobj
) {
379 if (sobj
->blessed
&& (temp
= o_material(obj
, GOLD
)) != 0) {
385 } else if ((temp
= o_in(obj
, COIN_CLASS
)) != 0) {
392 if (temp
&& temp
->ox
== u
.ux
&& temp
->oy
== u
.uy
)
395 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
396 if (DEADMONSTER(mtmp
))
397 continue; /* probably overkill here */
399 if (findgold(mtmp
->minvent
) || monsndx(mtmp
->data
) == PM_GOLD_GOLEM
) {
400 gold
= zeroobj
; /* ensure oextra is cleared too */
401 gold
.otyp
= GOLD_PIECE
;
402 gold
.quan
= (long) rnd(10); /* usually more than 1 */
405 map_object(&gold
, 1);
408 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
409 if (sobj
->blessed
&& (temp
= o_material(obj
, GOLD
)) != 0) {
414 } else if ((temp
= o_in(obj
, COIN_CLASS
)) != 0) {
421 if (temp
&& temp
->ox
== u
.ux
&& temp
->oy
== u
.uy
)
426 ter_typ
|= TER_MON
; /* so autodescribe will recognize hero */
428 You_feel("very greedy, and sense gold!");
429 exercise(A_WIS
, TRUE
);
431 browse_map(ter_typ
, "gold");
442 /* returns 1 if nothing was detected */
443 /* returns 0 if something was detected */
446 register struct obj
*sobj
;
448 register struct obj
*obj
;
449 register struct monst
*mtmp
;
450 register int ct
= 0, ctu
= 0;
451 boolean confused
= (Confusion
|| (sobj
&& sobj
->cursed
)), stale
;
452 char oclass
= confused
? POTION_CLASS
: FOOD_CLASS
;
453 const char *what
= confused
? something
: "food";
455 stale
= clear_stale_map(oclass
, 0);
456 if (u
.usteed
) /* some situations leave steed with stale coordinates */
457 u
.usteed
->mx
= u
.ux
, u
.usteed
->my
= u
.uy
;
459 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
460 if (o_in(obj
, oclass
)) {
461 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
466 for (mtmp
= fmon
; mtmp
&& (!ct
|| !ctu
); mtmp
= mtmp
->nmon
) {
467 /* no DEADMONSTER(mtmp) check needed -- dmons never have inventory */
468 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
469 if (o_in(obj
, oclass
)) {
470 if (mtmp
->mx
== u
.ux
&& mtmp
->my
== u
.uy
)
471 ctu
++; /* steed or an engulfer with inventory */
479 known
= stale
&& !confused
;
482 You("sense a lack of %s nearby.", what
);
483 if (sobj
&& sobj
->blessed
) {
485 Your("%s starts to tingle.", body_part(NOSE
));
491 Sprintf(buf
, "Your %s twitches%s.", body_part(NOSE
),
492 (sobj
->blessed
&& !u
.uedibility
)
493 ? " then starts to tingle"
495 if (sobj
->blessed
&& !u
.uedibility
) {
496 boolean savebeginner
= flags
.beginner
;
498 flags
.beginner
= FALSE
; /* prevent non-delivery of message */
499 strange_feeling(sobj
, buf
);
500 flags
.beginner
= savebeginner
;
503 strange_feeling(sobj
, buf
);
508 You("%s %s nearby.", sobj
? "smell" : "sense", what
);
509 if (sobj
&& sobj
->blessed
) {
511 pline("Your %s starts to tingle.", body_part(NOSE
));
516 int ter_typ
= TER_DETECT
| TER_OBJ
;
520 (void) unconstrain_map();
521 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
522 if ((temp
= o_in(obj
, oclass
)) != 0) {
529 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
530 /* no DEADMONSTER() check needed -- dmons never have inventory */
531 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
532 if ((temp
= o_in(obj
, oclass
)) != 0) {
536 break; /* skip rest of this monster's inventory */
540 ter_typ
|= TER_MON
; /* for autodescribe of self */
544 Your("%s %s to tingle and you smell %s.", body_part(NOSE
),
545 u
.uedibility
? "continues" : "starts", what
);
548 Your("%s tingles and you smell %s.", body_part(NOSE
), what
);
550 You("sense %s.", what
);
551 exercise(A_WIS
, TRUE
);
553 browse_map(ter_typ
, "food");
566 * Used for scrolls, potions, spells, and crystal balls. Returns:
568 * 1 - nothing was detected
569 * 0 - something was detected
572 object_detect(detector
, class)
573 struct obj
*detector
; /* object doing the detecting */
574 int class; /* an object class, 0 for all */
578 int is_cursed
= (detector
&& detector
->cursed
);
579 int do_dknown
= (detector
&& (detector
->oclass
== POTION_CLASS
580 || detector
->oclass
== SPBOOK_CLASS
)
581 && detector
->blessed
);
583 register struct obj
*obj
, *otmp
= (struct obj
*) 0;
584 register struct monst
*mtmp
;
585 int sym
, boulder
= 0, ter_typ
= TER_DETECT
| TER_OBJ
;
587 if (class < 0 || class >= MAXOCLASSES
) {
588 impossible("object_detect: illegal class %d", class);
592 /* Special boulder symbol check - does the class symbol happen
593 * to match iflags.bouldersym which is a user-defined?
594 * If so, that means we aren't sure what they really wanted to
595 * detect. Rather than trump anything, show both possibilities.
596 * We can exclude checking the buried obj chain for boulders below.
598 sym
= class ? def_oc_syms
[class].sym
: 0;
599 if (sym
&& iflags
.bouldersym
&& sym
== iflags
.bouldersym
)
600 boulder
= ROCK_CLASS
;
602 if (Hallucination
|| (Confusion
&& class == SCROLL_CLASS
))
603 Strcpy(stuff
, something
);
605 Strcpy(stuff
, class ? def_oc_syms
[class].name
: "objects");
606 if (boulder
&& class != ROCK_CLASS
)
607 Strcat(stuff
, " and/or large stones");
610 for (obj
= invent
; obj
; obj
= obj
->nobj
)
613 for (obj
= fobj
; obj
; obj
= obj
->nobj
) {
614 if ((!class && !boulder
) || o_in(obj
, class) || o_in(obj
, boulder
)) {
615 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
624 for (obj
= level
.buriedobjlist
; obj
; obj
= obj
->nobj
) {
625 if (!class || o_in(obj
, class)) {
626 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
636 u
.usteed
->mx
= u
.ux
, u
.usteed
->my
= u
.uy
;
638 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
639 if (DEADMONSTER(mtmp
))
641 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
) {
642 if ((!class && !boulder
) || o_in(obj
, class)
643 || o_in(obj
, boulder
))
648 if ((is_cursed
&& mtmp
->m_ap_type
== M_AP_OBJECT
649 && (!class || class == objects
[mtmp
->mappearance
].oc_class
))
650 || (findgold(mtmp
->minvent
) && (!class || class == COIN_CLASS
))) {
656 if (!clear_stale_map(!class ? ALL_CLASSES
: class, 0) && !ct
) {
659 strange_feeling(detector
, "You feel a lack of something.");
663 You("sense %s nearby.", stuff
);
669 (void) unconstrain_map();
671 * Map all buried objects first.
673 for (obj
= level
.buriedobjlist
; obj
; obj
= obj
->nobj
)
674 if (!class || (otmp
= o_in(obj
, class)) != 0) {
685 * If we are mapping all objects, map only the top object of a pile or
686 * the first object in a monster's inventory. Otherwise, go looking
687 * for a matching object class and display the first one encountered
690 * Objects on the floor override buried objects.
692 for (x
= 1; x
< COLNO
; x
++)
693 for (y
= 0; y
< ROWNO
; y
++)
694 for (obj
= level
.objects
[x
][y
]; obj
; obj
= obj
->nexthere
)
695 if ((!class && !boulder
) || (otmp
= o_in(obj
, class)) != 0
696 || (otmp
= o_in(obj
, boulder
)) != 0) {
697 if (class || boulder
) {
708 /* Objects in the monster's inventory override floor objects. */
709 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
710 if (DEADMONSTER(mtmp
))
712 for (obj
= mtmp
->minvent
; obj
; obj
= obj
->nobj
)
713 if ((!class && !boulder
) || (otmp
= o_in(obj
, class)) != 0
714 || (otmp
= o_in(obj
, boulder
)) != 0) {
715 if (!class && !boulder
)
717 otmp
->ox
= mtmp
->mx
; /* at monster location */
722 /* Allow a mimic to override the detected objects it is carrying. */
723 if (is_cursed
&& mtmp
->m_ap_type
== M_AP_OBJECT
724 && (!class || class == objects
[mtmp
->mappearance
].oc_class
)) {
728 temp
.otyp
= mtmp
->mappearance
; /* needed for obj_to_glyph() */
732 temp
.corpsenm
= PM_TENGU
; /* if mimicing a corpse */
733 map_object(&temp
, 1);
734 } else if (findgold(mtmp
->minvent
)
735 && (!class || class == COIN_CLASS
)) {
738 gold
= zeroobj
; /* ensure oextra is cleared too */
739 gold
.otyp
= GOLD_PIECE
;
740 gold
.quan
= (long) rnd(10); /* usually more than 1 */
743 map_object(&gold
, 1);
746 if (!glyph_is_object(glyph_at(u
.ux
, u
.uy
))) {
750 You("detect the %s of %s.", ct
? "presence" : "absence", stuff
);
753 display_nhwindow(WIN_MAP
, TRUE
);
755 browse_map(ter_typ
, "object");
758 docrt(); /* this will correctly reset vision */
767 * Used by: crystal balls, potions, fountains
769 * Returns 1 if nothing was detected.
770 * Returns 0 if something was detected.
773 monster_detect(otmp
, mclass
)
774 register struct obj
*otmp
; /* detecting object (if any) */
775 int mclass
; /* monster class, 0 for all */
777 register struct monst
*mtmp
;
780 /* Note: This used to just check fmon for a non-zero value
781 * but in versions since 3.3.0 fmon can test TRUE due to the
782 * presence of dmons, so we have to find at least one
783 * with positive hit-points to know for sure.
785 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
786 if (!DEADMONSTER(mtmp
)) {
793 strange_feeling(otmp
, Hallucination
794 ? "You get the heebie jeebies."
795 : "You feel threatened.");
798 boolean unconstrained
, woken
= FALSE
;
799 unsigned swallowed
= u
.uswallow
; /* before unconstrain_map() */
802 unconstrained
= unconstrain_map();
803 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
804 if (DEADMONSTER(mtmp
))
806 if (!mclass
|| mtmp
->data
->mlet
== mclass
807 || (mtmp
->data
== &mons
[PM_LONG_WORM
]
808 && mclass
== S_WORM_TAIL
))
809 map_monst(mtmp
, TRUE
);
811 if (otmp
&& otmp
->cursed
812 && (mtmp
->msleeping
|| !mtmp
->mcanmove
)) {
813 mtmp
->msleeping
= mtmp
->mfrozen
= 0;
820 You("sense the presence of monsters.");
822 pline("Monsters sense the presence of you.");
824 if ((otmp
&& otmp
->blessed
) && !unconstrained
) {
825 /* persistent detection--just show updated map */
826 display_nhwindow(WIN_MAP
, TRUE
);
828 /* one-shot detection--allow player to move cursor around and
829 get autodescribe feedback */
830 EDetect_monsters
|= I_SPECIAL
;
831 browse_map(TER_DETECT
| TER_MON
, "monster of interest");
832 EDetect_monsters
&= ~I_SPECIAL
;
836 docrt(); /* redraw the screen to remove unseen monsters from map */
846 sense_trap(trap
, x
, y
, src_cursed
)
851 if (Hallucination
|| src_cursed
) {
852 struct obj obj
; /* fake object */
862 obj
.otyp
= !Hallucination
? GOLD_PIECE
: random_object();
863 obj
.quan
= (long) ((obj
.otyp
== GOLD_PIECE
) ? rnd(10)
864 : objects
[obj
.otyp
].oc_merge
? rnd(2) : 1);
865 obj
.corpsenm
= random_monster(); /* if otyp == CORPSE */
870 } else { /* trapped door or trapped chest */
871 struct trap temp_trap
; /* fake trap */
873 (void) memset((genericptr_t
) &temp_trap
, 0, sizeof temp_trap
);
876 temp_trap
.ttyp
= BEAR_TRAP
; /* some kind of trap */
877 map_trap(&temp_trap
, 1);
881 #define OTRAP_NONE 0 /* nothing found */
882 #define OTRAP_HERE 1 /* found at hero's location */
883 #define OTRAP_THERE 2 /* found at any other location */
885 /* check a list of objects for chest traps; return 1 if found at <ux,uy>,
886 2 if found at some other spot, 3 if both, 0 otherwise; optionally
887 update the map to show where such traps were found */
889 detect_obj_traps(objlist
, show_them
, how
)
892 int how
; /* 1 for misleading map feedback */
896 int result
= OTRAP_NONE
;
899 * TODO? Display locations of unarmed land mine and beartrap objects.
900 * If so, should they be displayed as objects or as traps?
903 for (otmp
= objlist
; otmp
; otmp
= otmp
->nobj
) {
904 if (Is_box(otmp
) && otmp
->otrapped
905 && get_obj_location(otmp
, &x
, &y
, BURIED_TOO
| CONTAINED_TOO
)) {
906 result
|= (x
== u
.ux
&& y
== u
.uy
) ? OTRAP_HERE
: OTRAP_THERE
;
908 sense_trap((struct trap
*) 0, x
, y
, how
);
910 if (Has_contents(otmp
))
911 result
|= detect_obj_traps(otmp
->cobj
, show_them
, how
);
916 /* the detections are pulled out so they can
917 * also be used in the crystal ball routine
918 * returns 1 if nothing was detected
919 * returns 0 if something was detected
923 struct obj
*sobj
; /* null if crystal ball, *scroll if gold detection scroll */
925 register struct trap
*ttmp
;
927 int door
, glyph
, tr
, ter_typ
= TER_DETECT
| TER_TRP
;
928 int cursed_src
= sobj
&& sobj
->cursed
;
929 boolean found
= FALSE
;
933 u
.usteed
->mx
= u
.ux
, u
.usteed
->my
= u
.uy
;
935 /* floor/ceiling traps */
936 for (ttmp
= ftrap
; ttmp
; ttmp
= ttmp
->ntrap
) {
937 if (ttmp
->tx
!= u
.ux
|| ttmp
->ty
!= u
.uy
)
942 /* chest traps (might be buried or carried) */
943 if ((tr
= detect_obj_traps(fobj
, FALSE
, 0)) != OTRAP_NONE
) {
944 if (tr
& OTRAP_THERE
)
949 if ((tr
= detect_obj_traps(level
.buriedobjlist
, FALSE
, 0)) != OTRAP_NONE
) {
950 if (tr
& OTRAP_THERE
)
955 for (mon
= fmon
; mon
; mon
= mon
->nmon
) {
956 if (DEADMONSTER(mon
))
958 if ((tr
= detect_obj_traps(mon
->minvent
, FALSE
, 0)) != OTRAP_NONE
) {
959 if (tr
& OTRAP_THERE
)
965 if (detect_obj_traps(invent
, FALSE
, 0) != OTRAP_NONE
)
968 for (door
= 0; door
< doorindex
; door
++) {
970 if (levl
[cc
.x
][cc
.y
].doormask
& D_TRAPPED
) {
971 if (cc
.x
!= u
.ux
|| cc
.y
!= u
.uy
)
980 Sprintf(buf
, "Your %s stop itching.", makeplural(body_part(TOE
)));
981 strange_feeling(sobj
, buf
);
984 /* traps exist, but only under me - no separate display required */
985 Your("%s itch.", makeplural(body_part(TOE
)));
991 (void) unconstrain_map();
992 /* show chest traps first, so that subsequent floor trap display
993 will override if both types are present at the same location */
994 (void) detect_obj_traps(fobj
, TRUE
, cursed_src
);
995 (void) detect_obj_traps(level
.buriedobjlist
, TRUE
, cursed_src
);
996 for (mon
= fmon
; mon
; mon
= mon
->nmon
) {
997 if (DEADMONSTER(mon
))
999 (void) detect_obj_traps(mon
->minvent
, TRUE
, cursed_src
);
1001 (void) detect_obj_traps(invent
, TRUE
, cursed_src
);
1003 for (ttmp
= ftrap
; ttmp
; ttmp
= ttmp
->ntrap
)
1004 sense_trap(ttmp
, 0, 0, cursed_src
);
1006 for (door
= 0; door
< doorindex
; door
++) {
1008 if (levl
[cc
.x
][cc
.y
].doormask
& D_TRAPPED
)
1009 sense_trap((struct trap
*) 0, cc
.x
, cc
.y
, cursed_src
);
1012 /* redisplay hero unless sense_trap() revealed something at <ux,uy> */
1013 glyph
= glyph_at(u
.ux
, u
.uy
);
1014 if (!(glyph_is_trap(glyph
) || glyph_is_object(glyph
))) {
1016 ter_typ
|= TER_MON
; /* for autodescribe at <u.ux,u.uy> */
1018 You_feel("%s.", cursed_src
? "very greedy" : "entrapped");
1020 browse_map(ter_typ
, "trap of interest");
1023 docrt(); /* redraw the screen to remove unseen traps from the map */
1032 level_distance(where
)
1035 register schar ll
= depth(&u
.uz
) - depth(where
);
1036 register boolean indun
= (u
.uz
.dnum
== where
->dnum
);
1039 if (ll
< (-8 - rn2(3)))
1046 return "away below you";
1050 return "in the distance";
1052 return "just below";
1053 } else if (ll
> 0) {
1054 if (ll
> (8 + rn2(3)))
1061 return "away above you";
1065 return "in the distance";
1067 return "just above";
1069 return "in the distance";
1074 static const struct {
1077 } level_detects
[] = {
1078 { "Delphi", &oracle_level
},
1079 { "Medusa's lair", &medusa_level
},
1080 { "a castle", &stronghold_level
},
1081 { "the Wizard of Yendor's tower", &wiz1_level
},
1085 use_crystal_ball(optr
)
1090 struct obj
*obj
= *optr
;
1093 pline("Too bad you can't see %s.", the(xname(obj
)));
1096 oops
= (rnd(20) > ACURR(A_INT
) || obj
->cursed
);
1097 if (oops
&& (obj
->spe
> 0)) {
1098 switch (rnd(obj
->oartifact
? 4 : 5)) {
1100 pline("%s too much to comprehend!", Tobjnam(obj
, "are"));
1103 pline("%s you!", Tobjnam(obj
, "confuse"));
1104 make_confused((HConfusion
& TIMEOUT
) + (long) rnd(100), FALSE
);
1107 if (!resists_blnd(&youmonst
)) {
1108 pline("%s your vision!", Tobjnam(obj
, "damage"));
1109 make_blinded((Blinded
& TIMEOUT
) + (long) rnd(100), FALSE
);
1111 Your1(vision_clears
);
1113 pline("%s your vision.", Tobjnam(obj
, "assault"));
1114 You("are unaffected!");
1118 pline("%s your mind!", Tobjnam(obj
, "zap"));
1119 (void) make_hallucinated(
1120 (HHallucination
& TIMEOUT
) + (long) rnd(100), FALSE
, 0L);
1123 pline("%s!", Tobjnam(obj
, "explode"));
1125 *optr
= obj
= 0; /* it's gone */
1126 /* physical damage cause by the shards and force */
1127 losehp(Maybe_Half_Phys(rnd(30)), "exploding crystal ball",
1132 consume_obj_charge(obj
, TRUE
);
1136 if (Hallucination
) {
1138 pline("All you see is funky %s haze.", hcolor((char *) 0));
1142 You("grok some groovy globs of incandescent lava.");
1145 pline("Whoa! Psychedelic colors, %s!",
1146 poly_gender() == 1 ? "babe" : "dude");
1149 pline_The("crystal pulses with sinister %s light!",
1150 hcolor((char *) 0));
1153 You_see("goldfish swimming above fluorescent rocks.");
1157 "tiny snowflakes spinning around a miniature farmhouse.");
1160 pline("Oh wow... like a kaleidoscope!");
1163 consume_obj_charge(obj
, TRUE
);
1168 /* read a single character */
1170 You("may look for an object or monster symbol.");
1171 ch
= yn_function("What do you look for?", (char *) 0, '\0');
1172 /* Don't filter out ' ' here; it has a use */
1173 if ((ch
!= def_monsyms
[S_GHOST
].sym
) && index(quitchars
, ch
)) {
1178 You("peer into %s...", the(xname(obj
)));
1180 multi_reason
= "gazing into a crystal ball";
1182 if (obj
->spe
<= 0) {
1183 pline_The("vision is unclear.");
1188 makeknown(CRYSTAL_BALL
);
1189 consume_obj_charge(obj
, TRUE
);
1191 /* special case: accept ']' as synonym for mimic
1192 * we have to do this before the def_char_to_objclass check
1194 if (ch
== DEF_MIMIC_DEF
)
1197 if ((class = def_char_to_objclass(ch
)) != MAXOCLASSES
)
1198 ret
= object_detect((struct obj
*) 0, class);
1199 else if ((class = def_char_to_monclass(ch
)) != MAXMCLASSES
)
1200 ret
= monster_detect((struct obj
*) 0, class);
1201 else if (iflags
.bouldersym
&& (ch
== iflags
.bouldersym
))
1202 ret
= object_detect((struct obj
*) 0, ROCK_CLASS
);
1206 ret
= trap_detect((struct obj
*) 0);
1209 i
= rn2(SIZE(level_detects
));
1210 You_see("%s, %s.", level_detects
[i
].what
,
1211 level_distance(level_detects
[i
].where
));
1217 if (!rn2(100)) /* make them nervous */
1218 You_see("the Wizard of Yendor gazing out at you.");
1220 pline_The("vision is unclear.");
1234 if (Confusion
&& rn2(7))
1240 /* Secret corridors are found, but not secret doors. */
1241 if (lev
->typ
== SCORR
) {
1243 unblock_point(x
, y
);
1247 * Force the real background, then if it's not furniture and there's
1248 * a known trap there, display the trap, else if there was an object
1249 * shown there, redisplay the object. So during mapping, furniture
1250 * takes precedence over traps, which take precedence over objects,
1251 * opposite to how normal vision behaves.
1253 oldglyph
= glyph_at(x
, y
);
1254 if (level
.flags
.hero_memory
) {
1255 magic_map_background(x
, y
, 0);
1256 newsym(x
, y
); /* show it, if not blocked */
1258 magic_map_background(x
, y
, 1); /* display it */
1260 if (!IS_FURNITURE(lev
->typ
)) {
1261 if ((t
= t_at(x
, y
)) != 0 && t
->tseen
) {
1263 } else if (glyph_is_trap(oldglyph
) || glyph_is_object(oldglyph
)) {
1264 show_glyph(x
, y
, oldglyph
);
1265 if (level
.flags
.hero_memory
)
1266 lev
->glyph
= oldglyph
;
1274 register int zx
, zy
;
1275 boolean unconstrained
;
1277 unconstrained
= unconstrain_map();
1278 for (zx
= 1; zx
< COLNO
; zx
++)
1279 for (zy
= 0; zy
< ROWNO
; zy
++)
1280 show_map_spot(zx
, zy
);
1282 if (!level
.flags
.hero_memory
|| unconstrained
) {
1283 flush_screen(1); /* flush temp screen */
1284 /* browse_map() instead of display_nhwindow(WIN_MAP, TRUE) */
1285 browse_map(TER_DETECT
| TER_MAP
| TER_TRP
| TER_OBJ
,
1286 "anything of interest");
1290 exercise(A_WIS
, TRUE
);
1295 do_vicinity_map(sobj
)
1296 struct obj
*sobj
; /* scroll--actually fake spellbook--object */
1298 register int zx
, zy
;
1300 boolean unconstrained
, refresh
= FALSE
, mdetected
= FALSE
,
1301 extended
= (sobj
&& sobj
->blessed
);
1302 int lo_y
= ((u
.uy
- 5 < 0) ? 0 : u
.uy
- 5),
1303 hi_y
= ((u
.uy
+ 6 >= ROWNO
) ? ROWNO
- 1 : u
.uy
+ 6),
1304 lo_x
= ((u
.ux
- 9 < 1) ? 1 : u
.ux
- 9), /* avoid column 0 */
1305 hi_x
= ((u
.ux
+ 10 >= COLNO
) ? COLNO
- 1 : u
.ux
+ 10),
1306 ter_typ
= TER_DETECT
| TER_MAP
| TER_TRP
| TER_OBJ
;
1308 unconstrained
= unconstrain_map();
1309 for (zx
= lo_x
; zx
<= hi_x
; zx
++)
1310 for (zy
= lo_y
; zy
<= hi_y
; zy
++) {
1311 show_map_spot(zx
, zy
);
1313 if (extended
&& (mtmp
= m_at(zx
, zy
)) != 0
1314 && mtmp
->mx
== zx
&& mtmp
->my
== zy
) { /* skip worm tails */
1315 int oldglyph
= glyph_at(zx
, zy
);
1317 map_monst(mtmp
, FALSE
);
1318 if (glyph_at(zx
, zy
) != oldglyph
)
1323 if (!level
.flags
.hero_memory
|| unconstrained
|| mdetected
) {
1324 flush_screen(1); /* flush temp screen */
1325 if (extended
|| glyph_is_monster(glyph_at(u
.ux
, u
.uy
)))
1328 EDetect_monsters
|= I_SPECIAL
;
1329 browse_map(ter_typ
, "anything of interest");
1330 EDetect_monsters
&= ~I_SPECIAL
;
1338 /* convert a secret door into a normal door */
1340 cvt_sdoor_to_door(lev
)
1343 int newmask
= lev
->doormask
& ~WM_MASK
;
1345 if (Is_rogue_level(&u
.uz
))
1346 /* rogue didn't have doors, only doorways */
1349 /* newly exposed door is closed */
1350 if (!(newmask
& D_LOCKED
))
1351 newmask
|= D_CLOSED
;
1354 lev
->doormask
= newmask
;
1358 findone(zx
, zy
, num
)
1362 register struct trap
*ttmp
;
1363 register struct monst
*mtmp
;
1365 if (levl
[zx
][zy
].typ
== SDOOR
) {
1366 cvt_sdoor_to_door(&levl
[zx
][zy
]); /* .typ = DOOR */
1367 magic_map_background(zx
, zy
, 0);
1370 } else if (levl
[zx
][zy
].typ
== SCORR
) {
1371 levl
[zx
][zy
].typ
= CORR
;
1372 unblock_point(zx
, zy
);
1373 magic_map_background(zx
, zy
, 0);
1376 } else if ((ttmp
= t_at(zx
, zy
)) != 0) {
1377 if (!ttmp
->tseen
&& ttmp
->ttyp
!= STATUE_TRAP
) {
1382 } else if ((mtmp
= m_at(zx
, zy
)) != 0) {
1383 if (mtmp
->m_ap_type
) {
1387 if (mtmp
->mundetected
1388 && (is_hider(mtmp
->data
) || mtmp
->data
->mlet
== S_EEL
)) {
1389 mtmp
->mundetected
= 0;
1393 if (!canspotmon(mtmp
) && !glyph_is_invisible(levl
[zx
][zy
].glyph
))
1394 map_invisible(zx
, zy
);
1395 } else if (glyph_is_invisible(levl
[zx
][zy
].glyph
)) {
1396 unmap_object(zx
, zy
);
1403 openone(zx
, zy
, num
)
1407 register struct trap
*ttmp
;
1408 register struct obj
*otmp
;
1409 int *num_p
= (int *) num
;
1411 if (OBJ_AT(zx
, zy
)) {
1412 for (otmp
= level
.objects
[zx
][zy
]; otmp
; otmp
= otmp
->nexthere
) {
1413 if (Is_box(otmp
) && otmp
->olocked
) {
1418 /* let it fall to the next cases. could be on trap. */
1420 if (levl
[zx
][zy
].typ
== SDOOR
1421 || (levl
[zx
][zy
].typ
== DOOR
1422 && (levl
[zx
][zy
].doormask
& (D_CLOSED
| D_LOCKED
)))) {
1423 if (levl
[zx
][zy
].typ
== SDOOR
)
1424 cvt_sdoor_to_door(&levl
[zx
][zy
]); /* .typ = DOOR */
1425 if (levl
[zx
][zy
].doormask
& D_TRAPPED
) {
1426 if (distu(zx
, zy
) < 3)
1427 b_trapped("door", 0);
1429 Norep("You %s an explosion!",
1430 cansee(zx
, zy
) ? "see" : (!Deaf
? "hear"
1431 : "feel the shock of"));
1432 wake_nearto(zx
, zy
, 11 * 11);
1433 levl
[zx
][zy
].doormask
= D_NODOOR
;
1435 levl
[zx
][zy
].doormask
= D_ISOPEN
;
1436 unblock_point(zx
, zy
);
1439 } else if (levl
[zx
][zy
].typ
== SCORR
) {
1440 levl
[zx
][zy
].typ
= CORR
;
1441 unblock_point(zx
, zy
);
1444 } else if ((ttmp
= t_at(zx
, zy
)) != 0) {
1446 boolean dummy
; /* unneeded "you notice it arg" */
1448 if (!ttmp
->tseen
&& ttmp
->ttyp
!= STATUE_TRAP
) {
1453 mon
= (zx
== u
.ux
&& zy
== u
.uy
) ? &youmonst
: m_at(zx
, zy
);
1454 if (openholdingtrap(mon
, &dummy
)
1455 || openfallingtrap(mon
, TRUE
, &dummy
))
1457 } else if (find_drawbridge(&zx
, &zy
)) {
1458 /* make sure it isn't an open drawbridge */
1459 open_drawbridge(zx
, zy
);
1464 /* returns number of things found */
1472 do_clear_area(u
.ux
, u
.uy
, BOLT_LIM
, findone
, (genericptr_t
) &num
);
1476 /* returns number of things found and opened */
1483 if (is_animal(u
.ustuck
->data
)) {
1485 pline("Its mouth opens!");
1487 pline("%s opens its mouth!", Monnam(u
.ustuck
));
1489 expels(u
.ustuck
, u
.ustuck
->data
, TRUE
);
1493 do_clear_area(u
.ux
, u
.uy
, BOLT_LIM
, openone
, (genericptr_t
) &num
);
1497 /* callback hack for overriding vision in do_clear_area() */
1500 void FDECL((*func
), (int, int, genericptr_t
));
1502 return (func
== findone
|| func
== openone
);
1509 int tt
= what_trap(trap
->ttyp
);
1510 boolean cleared
= FALSE
;
1513 exercise(A_WIS
, TRUE
);
1514 feel_newsym(trap
->tx
, trap
->ty
);
1516 if (levl
[trap
->tx
][trap
->ty
].glyph
!= trap_to_glyph(trap
)) {
1517 /* There's too much clutter to see your find otherwise */
1524 You("find %s.", an(defsyms
[trap_to_defsym(tt
)].explanation
));
1527 display_nhwindow(WIN_MAP
, TRUE
); /* wait */
1533 mfind0(mtmp
, via_warning
)
1535 boolean via_warning
;
1540 if (via_warning
&& !warning_of(mtmp
))
1543 if (mtmp
->m_ap_type
) {
1546 exercise(A_WIS
, TRUE
);
1547 if (!canspotmon(mtmp
)) {
1548 if (glyph_is_invisible(levl
[x
][y
].glyph
)) {
1549 /* Found invisible monster in a square which already has
1550 * an 'I' in it. Logically, this should still take time
1551 * and lead to a return 1, but if we did that the player
1552 * would keep finding the same monster every turn.
1556 You_feel("an unseen monster!");
1557 map_invisible(x
, y
);
1559 } else if (!sensemon(mtmp
))
1561 mtmp
->mtame
? y_monnam(mtmp
) : a_monnam(mtmp
));
1564 if (!canspotmon(mtmp
)) {
1565 if (mtmp
->mundetected
1566 && (is_hider(mtmp
->data
) || mtmp
->data
->mlet
== S_EEL
))
1568 Your("warning senses cause you to take a second %s.",
1569 Blind
? "to check nearby" : "look close by");
1570 display_nhwindow(WIN_MESSAGE
, FALSE
); /* flush messages */
1572 mtmp
->mundetected
= 0;
1581 register int aflag
; /* intrinsic autosearch vs explicit searching */
1584 /* Some old versions of gcc seriously muck up nested loops. If you get
1585 * strange crashes while searching in a version compiled with gcc, try
1586 * putting #define GCC_BUG in *conf.h (or adding -DGCC_BUG to CFLAGS in
1589 volatile xchar x
, y
;
1591 register xchar x
, y
;
1593 register struct trap
*trap
;
1594 register struct monst
*mtmp
;
1598 pline("What are you looking for? The exit?");
1600 int fund
= (uwep
&& uwep
->oartifact
1601 && spec_ability(uwep
, SPFX_SEARCH
)) ? uwep
->spe
: 0;
1603 if (ublindf
&& ublindf
->otyp
== LENSES
&& !Blind
)
1604 fund
+= 2; /* JDS: lenses help searching */
1607 for (x
= u
.ux
- 1; x
< u
.ux
+ 2; x
++)
1608 for (y
= u
.uy
- 1; y
< u
.uy
+ 2; y
++) {
1611 if (x
== u
.ux
&& y
== u
.uy
)
1614 if (Blind
&& !aflag
)
1615 feel_location(x
, y
);
1616 if (levl
[x
][y
].typ
== SDOOR
) {
1619 cvt_sdoor_to_door(&levl
[x
][y
]); /* .typ = DOOR */
1620 exercise(A_WIS
, TRUE
);
1622 feel_location(x
, y
); /* make sure it shows up */
1623 You("find a hidden door.");
1624 } else if (levl
[x
][y
].typ
== SCORR
) {
1627 levl
[x
][y
].typ
= CORR
;
1628 unblock_point(x
, y
); /* vision */
1629 exercise(A_WIS
, TRUE
);
1631 feel_newsym(x
, y
); /* make sure it shows up */
1632 You("find a hidden passage.");
1634 /* Be careful not to find anything in an SCORR or SDOOR */
1635 if ((mtmp
= m_at(x
, y
)) != 0 && !aflag
) {
1636 int mfres
= mfind0(mtmp
, 0);
1644 /* see if an invisible monster has moved--if Blind,
1645 * feel_location() already did it
1647 if (!aflag
&& !mtmp
&& !Blind
1648 && glyph_is_invisible(levl
[x
][y
].glyph
)) {
1653 if ((trap
= t_at(x
, y
)) && !trap
->tseen
&& !rnl(8)) {
1655 if (trap
->ttyp
== STATUE_TRAP
) {
1656 if (activate_statue_trap(trap
, x
, y
, FALSE
))
1657 exercise(A_WIS
, TRUE
);
1669 /* the 's' command -- explicit searching */
1673 return dosearch0(0);
1682 for (x
= u
.ux
- 1; x
<= u
.ux
+ 1; x
++)
1683 for (y
= u
.uy
- 1; y
<= u
.uy
+ 1; y
++) {
1684 if (!isok(x
, y
) || (x
== u
.ux
&& y
== u
.uy
))
1686 if ((mtmp
= m_at(x
, y
)) != 0
1687 && warning_of(mtmp
) && mtmp
->mundetected
)
1688 (void) mfind0(mtmp
, 1); /* via_warning */
1692 /* Pre-map the sokoban levels */
1697 register struct trap
*ttmp
;
1698 register struct obj
*obj
;
1700 /* Map the background and boulders */
1701 for (x
= 1; x
< COLNO
; x
++)
1702 for (y
= 0; y
< ROWNO
; y
++) {
1703 levl
[x
][y
].seenv
= SVALL
;
1704 levl
[x
][y
].waslit
= TRUE
;
1705 map_background(x
, y
, 1);
1706 if ((obj
= sobj_at(BOULDER
, x
, y
)) != 0)
1711 for (ttmp
= ftrap
; ttmp
; ttmp
= ttmp
->ntrap
) {
1714 /* set sokoban_rules when there is at least one pit or hole */
1715 if (ttmp
->ttyp
== PIT
|| ttmp
->ttyp
== HOLE
)
1721 reveal_terrain_getglyph(x
, y
, full
, swallowed
, default_glyph
, which_subset
)
1724 int default_glyph
, which_subset
;
1726 int glyph
, levl_glyph
;
1728 boolean keep_traps
= (which_subset
& TER_TRP
) !=0,
1729 keep_objs
= (which_subset
& TER_OBJ
) != 0,
1730 keep_mons
= (which_subset
& TER_MON
) != 0;
1734 /* for 'full', show the actual terrain for the entire level,
1735 otherwise what the hero remembers for seen locations with
1736 monsters, objects, and/or traps removed as caller dictates */
1737 seenv
= (full
|| level
.flags
.hero_memory
)
1738 ? levl
[x
][y
].seenv
: cansee(x
, y
) ? SVALL
: 0;
1740 levl
[x
][y
].seenv
= SVALL
;
1741 glyph
= back_to_glyph(x
, y
);
1742 levl
[x
][y
].seenv
= seenv
;
1744 levl_glyph
= level
.flags
.hero_memory
1746 : seenv
? back_to_glyph(x
, y
): default_glyph
;
1747 /* glyph_at() returns the displayed glyph, which might
1748 be a monster. levl[][].glyph contains the remembered
1749 glyph, which will never be a monster (unless it is
1750 the invisible monster glyph, which is handled like
1751 an object, replacing any object or trap at its spot) */
1752 glyph
= !swallowed
? glyph_at(x
, y
) : levl_glyph
;
1753 if (keep_mons
&& x
== u
.ux
&& y
== u
.uy
&& swallowed
)
1754 glyph
= mon_to_glyph(u
.ustuck
);
1755 else if (((glyph_is_monster(glyph
)
1756 || glyph_is_warning(glyph
)) && !keep_mons
)
1757 || glyph_is_swallow(glyph
))
1759 if (((glyph_is_object(glyph
) && !keep_objs
)
1760 || glyph_is_invisible(glyph
))
1761 && keep_traps
&& !covers_traps(x
, y
)) {
1762 if ((t
= t_at(x
, y
)) != 0 && t
->tseen
)
1763 glyph
= trap_to_glyph(t
);
1765 if ((glyph_is_object(glyph
) && !keep_objs
)
1766 || (glyph_is_trap(glyph
) && !keep_traps
)
1767 || glyph_is_invisible(glyph
)) {
1769 glyph
= default_glyph
;
1770 } else if (lastseentyp
[x
][y
] == levl
[x
][y
].typ
) {
1771 glyph
= back_to_glyph(x
, y
);
1773 /* look for a mimic here posing as furniture;
1774 if we don't find one, we'll have to fake it */
1775 if ((mtmp
= m_at(x
, y
)) != 0
1776 && mtmp
->m_ap_type
== M_AP_FURNITURE
) {
1777 glyph
= cmap_to_glyph(mtmp
->mappearance
);
1779 /* we have a topology type but we want a screen
1780 symbol in order to derive a glyph; some screen
1781 symbols need the flags field of levl[][] in
1782 addition to the type (to disambiguate STAIRS to
1783 S_upstair or S_dnstair, for example; current
1784 flags might not be intended for remembered type,
1785 but we've got no other choice) */
1786 schar save_typ
= levl
[x
][y
].typ
;
1788 levl
[x
][y
].typ
= lastseentyp
[x
][y
];
1789 glyph
= back_to_glyph(x
, y
);
1790 levl
[x
][y
].typ
= save_typ
;
1795 if (glyph
== cmap_to_glyph(S_darkroom
))
1796 glyph
= cmap_to_glyph(S_room
); /* FIXME: dirty hack */
1804 int subset
= TER_MAP
| TER_TRP
| TER_OBJ
| TER_MON
;
1805 int default_glyph
= cmap_to_glyph(level
.flags
.arboreal
? S_tree
: S_stone
);
1808 for (y
= 0; y
< ROWNO
; y
++) {
1809 for (x
= 1; x
< COLNO
; x
++) {
1813 glyph
= reveal_terrain_getglyph(x
,y
, FALSE
, u
.uswallow
,
1814 default_glyph
, subset
);
1815 (void) mapglyph(glyph
, &ch
, &color
, &special
, x
, y
);
1823 /* idea from crawl; show known portion of map without any monsters,
1824 objects, or traps occluding the view of the underlying terrain */
1826 reveal_terrain(full
, which_subset
)
1827 int full
; /* wizard|explore modes allow player to request full map */
1828 int which_subset
; /* when not full, whether to suppress objs and/or traps */
1830 if ((Hallucination
|| Stunned
|| Confusion
) && !full
) {
1831 You("are too disoriented for this.");
1833 int x
, y
, glyph
, default_glyph
;
1835 /* there is a TER_MAP bit too; we always show map regardless of it */
1836 boolean keep_traps
= (which_subset
& TER_TRP
) !=0,
1837 keep_objs
= (which_subset
& TER_OBJ
) != 0,
1838 keep_mons
= (which_subset
& TER_MON
) != 0; /* not used */
1839 unsigned swallowed
= u
.uswallow
; /* before unconstrain_map() */
1841 if (unconstrain_map())
1843 default_glyph
= cmap_to_glyph(level
.flags
.arboreal
? S_tree
: S_stone
);
1845 for (x
= 1; x
< COLNO
; x
++)
1846 for (y
= 0; y
< ROWNO
; y
++) {
1847 glyph
= reveal_terrain_getglyph(x
,y
, full
, swallowed
,
1848 default_glyph
, which_subset
);
1849 show_glyph(x
, y
, glyph
);
1852 /* hero's location is not highlighted, but getpos() starts with
1853 cursor there, and after moving it anywhere '@' moves it back */
1856 Strcpy(buf
, "underlying terrain");
1858 Strcpy(buf
, "known terrain");
1860 Sprintf(eos(buf
), "%s traps",
1861 (keep_objs
|| keep_mons
) ? "," : " and");
1863 Sprintf(eos(buf
), "%s%s objects",
1864 (keep_traps
|| keep_mons
) ? "," : "",
1865 keep_mons
? "" : " and");
1867 Sprintf(eos(buf
), "%s and monsters",
1868 (keep_traps
|| keep_objs
) ? "," : "");
1870 pline("Showing %s only...", buf
);
1872 /* allow player to move cursor around and get autodescribe feedback
1873 based on what is visible now rather than what is on 'real' map */
1874 which_subset
|= TER_MAP
; /* guarantee non-zero */
1875 browse_map(which_subset
, "anything of interest");
1878 docrt(); /* redraw the screen, restoring regular map */