Source:NetHack 5.0.0/include/display.h

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to display.h from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/include/display.h#line12]], for example.

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. /* NetHack 5.0	display.h	$NHDT-Date: 1725653008 2024/09/06 20:03:28 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.106 $ */
2. /* Copyright (c) Dean Luick, with acknowledgements to Kevin Darcy */
3. /* and Dave Cohrs, 1990.                                          */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #ifndef DISPLAY_H
7. #define DISPLAY_H
8. 
9. #ifndef VISION_H
10. #include "vision.h"
11. #endif
12. #ifndef MONDATA_H
13. #include "mondata.h" /* for mindless() */
14. #endif
15. 
16. /*
17.  * vobj_at()
18.  *
19.  * Returns the head of the list of objects that the player can see
20.  * at location (x,y).  [Vestige of unimplemented invisible objects.]
21.  */
22. #define vobj_at(x, y) (svl.level.objects[x][y])
23. 
24. /*
25.  * sensemon()
26.  *
27.  * Returns true if the hero can sense the given monster.  This includes
28.  * monsters that are hiding or mimicking other monsters.
29.  *
30.  * [5.0] Note: the map doesn't display any monsters when hero is swallowed
31.  * (or display non-adjacent, non-submerged ones when hero is underwater),
32.  * so treat those situations as blocking telepathy, detection, and warning
33.  * even though conceptually they shouldn't do so.
34.  *
35.  * [5.0 also] The macros whose name begins with an underscore have been
36.  * converted to functions in order to have compilers generate smaller code.
37.  * The retained underscore versions are still used in display.c but should
38.  * only be used in other situations if the function calls actually produce
39.  * noticeably slower processing.
40.  */
41. #define _tp_sensemon(mon) \
42.     (/* The hero can always sense a monster IF:        */  \
43.      /* 1. the monster has a brain to sense            */  \
44.      (!mindless(mon->data))                                \
45.      /* AND     2a. hero is blind and telepathic       */  \
46.       && ((Blind && Blind_telepat)                         \
47.           /* OR 2b. hero is using a telepathy inducing */  \
48.           /*        object and in range                */  \
49.           || (Unblind_telepat                              \
50.               && (mdistu(mon) <= u.unblind_telepat_range))))
51. 
52. /* organized to perform cheaper tests first;
53.    is_pool() vs is_pool_or_lava(): hero who is underwater can see adjacent
54.    lava, but presumably any monster there is on top so not sensed */
55. #define _sensemon(mon) \
56.     (   (!u.uswallow || (mon) == u.ustuck)                                   \
57.      && (!Underwater || (mdistu(mon) <= 2 && is_pool((mon)->mx, (mon)->my))) \
58.      && (Detect_monsters || tp_sensemon(mon) || MATCH_WARN_OF_MON(mon))   )
59. 
60. /*
61.  * mon_warning() is used to warn of any dangerous monsters in your
62.  * vicinity, and a glyph representing the warning level is displayed.
63.  */
64. #define _mon_warning(mon) \
65.     (Warning && !(mon)->mpeaceful && (mdistu(mon) < 100)     \
66.      && (((int) ((mon)->m_lev / 4)) >= svc.context.warnlevel))
67. 
68. /*
69.  * mon_visible()
70.  *
71.  * Returns true if the hero can see the monster.  It is assumed that the
72.  * hero can physically see the location of the monster.  The function
73.  * vobj_at() returns a pointer to an object that the hero can see there.
74.  * Infravision is not taken into account.
75.  *
76.  * Note:  not reliable for concealed mimics.  They don't have
77.  * 'mon->mundetected' set even when mimicking objects or furniture.
78.  * [Fixing this with a pair of mon->m_ap_type checks here (via either
79.  * 'typ!=object && typ!=furniture' or 'typ==nothing || typ==monster')
80.  * will require reviewing every instance of mon_visible(), canseemon(),
81.  * canspotmon(), is_safemon() and perhaps others.  Fixing it by setting
82.  * mon->mundetected when concealed would be better but also require
83.  * reviewing all those instances and also existing mundetected instances.]
84.  */
85. #if 0
86. #define _mon_visible(mon) \
87.     (/* The hero can see the monster IF the monster                     */ \
88.      (!mon->minvis || See_invisible)  /*     1. is not invisible        */ \
89.      && !mon->mundetected             /* AND 2. not an undetected hider */ \
90.      && !(mon->mburied || u.uburied)) /* AND 3. neither you nor it buried */
91. #else   /* without 'mburied' and 'uburied' */
92. #define _mon_visible(mon) \
93.     (/* The hero can see the monster IF the monster                     */ \
94.      (!mon->minvis || See_invisible)  /*     1. is not invisible        */ \
95.      && !mon->mundetected)            /* AND 2. not an undetected hider */
96. #endif
97. 
98. /*
99.  * see_with_infrared()
100.  *
101.  * This function is true if the player can see a monster using infravision.
102.  * The caller must check for invisibility (invisible monsters are also
103.  * invisible to infravision), because this is usually called from within
104.  * canseemon() or canspotmon() which already check that.
105.  */
106. #define _see_with_infrared(mon) \
107.     (!Blind && Infravision && infravisible(mon->data) \
108.      && couldsee(mon->mx, mon->my))
109. 
110. /*
111.  * canseemon()
112.  *
113.  * This is the globally used canseemon().  It is not called within the display
114.  * routines.  Like mon_visible(), but it checks to see if the hero sees the
115.  * location instead of assuming it.  (And also considers worms.)
116.  */
117. #define _canseemon(mon) \
118.     ((mon->wormno ? worm_known(mon)                                       \
119.                   : (cansee(mon->mx, mon->my) || see_with_infrared(mon))) \
120.      && mon_visible(mon))
121. 
122. /*
123.  * canspotmon(mon)
124.  *
125.  * This function checks whether you can either see a monster or sense it by
126.  * telepathy, and is what you usually call for monsters about which nothing is
127.  * known.
128.  */
129. #define canspotmon(mon) (canseemon(mon) || sensemon(mon))
130. 
131. /* knowninvisible(mon)
132.  * This one checks to see if you know a monster is both there and invisible.
133.  * 1) If you can see the monster and have see invisible, it is assumed the
134.  * monster is transparent, but visible in some manner.  (Earlier versions of
135.  * Nethack were really inconsistent on this.)
136.  * 2) If you can't see the monster, but can see its location and you have
137.  * telepathy that works when you can see, you can tell that there is a
138.  * creature in an apparently empty spot.
139.  * Infravision is not relevant; we assume that invisible monsters are also
140.  * invisible to infravision.
141.  * [5.0: the macro definition erroneously started with 'mtmp->minvis' for
142.  * over 20 years.  The one place it's used called it as knowninvisible(mtmp)
143.  * so worked by coincidence when there was no argument expansion involved
144.  * on the first line.]
145.  */
146. #define _knowninvisible(mon) \
147.     ((mon)->minvis                                                      \
148.      && ((cansee((mon)->mx, (mon)->my)                                  \
149.           && (See_invisible || Detect_monsters))                        \
150.          || (!Blind && (HTelepat & ~INTRINSIC)                          \
151.              && mdistu(mon) <= (BOLT_LIM * BOLT_LIM))))
152. 
153. /*
154.  * is_safemon(mon)
155.  *
156.  * A special case check used in attack() and domove().  Placing the
157.  * definition here is convenient.  No longer limited to pets.
158.  */
159. #define _is_safemon(mon) \
160.     (flags.safe_dog && (mon)->mpeaceful && canspotmon(mon)              \
161.      && !Confusion && !Hallucination && !Stunned)
162. 
163. /*
164.  * canseeself()
165.  * senseself()
166.  * canspotself()
167.  *
168.  * This returns true if the hero can see her/himself.
169.  *
170.  * Sensing yourself by touch is treated as seeing yourself, even if
171.  * unable to see.  So when blind, being invisible won't affect your
172.  * self-perception, and when swallowed, the enclosing monster touches.
173.  */
174. #define canseeself() (Blind || u.uswallow || (!Invisible && !u.uundetected))
175. #define senseself() (Unblind_telepat || Detect_monsters)
176. #define canspotself() (canseeself() || senseself())
177. 
178. /*
179.  * random_monster()
180.  * random_object()
181.  *
182.  * Respectively return a random monster or object.
183.  * random_object() won't return STRANGE_OBJECT or the generic objects.
184.  * -/+ FIRST_OBJECT is used to skip it and them.
185.  */
186. #define random_monster(rng) ((*rng)(NUMMONS))
187. #define random_object(rng) ((*rng)(NUM_OBJECTS - FIRST_OBJECT) + FIRST_OBJECT)
188. 
189. /*
190.  * what_obj()
191.  * what_mon()
192.  *
193.  * If hallucinating, choose a random object/monster, otherwise, use the one
194.  * given. Use the given rng to handle hallucination.
195.  */
196. #define what_obj(obj, rng) (Hallucination ? random_object(rng) : obj)
197. #define what_mon(mon, rng) (Hallucination ? random_monster(rng) : mon)
198. 
199. /*
200.  * newsym_rn2
201.  *
202.  * An appropriate random number generator for use with newsym(), when
203.  * randomness is needed there. This is currently hardcoded as
204.  * rn2_on_display_rng, but is futureproofed for cases where we might
205.  * want to prevent display-random objects entering the character's
206.  * memory (this isn't important at present but may be if we need
207.  * reproducible gameplay for some reason).
208.  */
209. #define newsym_rn2 rn2_on_display_rng
210. 
211. /*
212.  * covers_objects()
213.  * covers_traps()
214.  *
215.  * These routines are true if what is really at the given location will
216.  * "cover" any objects or traps that might be there.
217.  */
218. #define covers_objects(xx, yy) \
219.     ((is_pool(xx, yy) && !Underwater) || (levl[xx][yy].typ == LAVAPOOL) \
220.       || (levl[xx][yy].typ == LAVAWALL))
221. 
222. #define covers_traps(xx, yy) covers_objects(xx, yy)
223. 
224. /*
225.  * tmp_at() control calls.
226.  */
227. #define DISP_BEAM    (-1) /* Keep all glyphs showing & clean up at end. */
228. #define DISP_ALL     (-2) /* Like beam, but still displayed if not visible. */
229. #define DISP_TETHER  (-3) /* Like beam, but tether glyph differs from final */
230. #define DISP_FLASH   (-4) /* Clean up each glyph before displaying new one. */
231. #define DISP_ALWAYS  (-5) /* Like flash, but still displayed if not visible */
232. #define DISP_CHANGE  (-6) /* Change glyph. */
233. #define DISP_END     (-7) /* Clean up. */
234. #define DISP_FREEMEM (-8) /* Free all memory during exit only. */
235. 
236. /* Total number of cmap indices in the shield_static[] array. */
237. #define SHIELD_COUNT 21
238. #define BACKTRACK    (-1) /* for DISP_END to display each prior location */
239. 
240. /*
241.  * display_self()
242.  *
243.  * Display the hero.  It is assumed that all checks necessary to determine
244.  * _if_ the hero can be seen have already been done.
245.  */
246. #define maybe_display_usteed(otherwise_self)                 \
247.     ((u.usteed && mon_visible(u.usteed))                     \
248.          ? ridden_mon_to_glyph(u.usteed, rn2_on_display_rng) \
249.          : (otherwise_self))
250. 
251. #define display_self() \
252.     show_glyph(u.ux, u.uy, maybe_display_usteed(                        \
253.         ((int) U_AP_TYPE == M_AP_NOTHING)                               \
254.         ? hero_glyph                                                    \
255.         : ((int) U_AP_TYPE == M_AP_FURNITURE)                           \
256.           ? cmap_to_glyph((int) gy.youmonst.mappearance)                \
257.           : ((int) U_AP_TYPE == M_AP_OBJECT)                            \
258.             ? objnum_to_glyph((int) gy.youmonst.mappearance)            \
259.             /* else U_AP_TYPE == M_AP_MONSTER */                        \
260.             : monnum_to_glyph((int) gy.youmonst.mappearance, Ugender)))
261. 
262. /*
263.  * NetHack glyphs
264.  *
265.  * A glyph is an abstraction that represents a _unique_ monster, object,
266.  * dungeon part, or effect.  The uniqueness is important.  For example,
267.  * It is not enough to have four (one for each "direction") zap beam glyphs,
268.  * we need a set of four for each beam type.  Why go to so much trouble?
269.  * Because it is possible that any given window dependent display driver
270.  * [print_glyph()] can produce something different for each type of glyph.
271.  * That is, a beam of cold and a beam of fire would not only be different
272.  * colors, but would also be represented by different symbols.
273.  */
274. 
275. 
276. #include "color.h"
277. /* 3.6.3: poison gas zap used to be yellow and acid zap was green,
278.    which conflicted with the corresponding dragon colors */
279. enum zap_colors {
280.     zap_color_missile    = HI_ZAP,
281.     zap_color_fire       = CLR_ORANGE,
282.     zap_color_frost      = CLR_WHITE,
283.     zap_color_sleep      = HI_ZAP,
284.     zap_color_death      = CLR_BLACK,
285.     zap_color_lightning  = CLR_WHITE,
286.     zap_color_poison_gas = CLR_GREEN,
287.     zap_color_acid       = CLR_YELLOW
288. };
289. 
290. enum altar_colors {
291.     altar_color_unaligned = CLR_RED,
292. #if defined(USE_GENERAL_ALTAR_COLORS)
293.         /* On OSX with TERM=xterm-color256 these render as
294.          *  white -> tty: gray, curses: ok
295.          *  gray  -> both tty and curses: black
296.          *  black -> both tty and curses: blue
297.          *  red   -> both tty and curses: ok.
298.          * Since the colors have specific associations (with the
299.          * unicorns matched with each alignment), we shouldn't use
300.          * scrambled colors and we don't have sufficient information
301.          * to handle platform-specific color variations.
302.          */
303.     altar_color_chaotic = CLR_BLACK,
304.     altar_color_neutral = CLR_GRAY,
305.     altar_color_lawful  = CLR_WHITE,
306. #else
307.     altar_color_chaotic = CLR_GRAY,
308.     altar_color_neutral = CLR_GRAY,
309.     altar_color_lawful  = CLR_GRAY,
310. #endif
311.     altar_color_other = CLR_BRIGHT_MAGENTA,
312. };
313. 
314. /* types of explosions */
315. enum explosion_types {
316.     EXPL_DARK = 0,
317.     EXPL_NOXIOUS = 1,
318.     EXPL_MUDDY = 2,
319.     EXPL_WET = 3,
320.     EXPL_MAGICAL = 4,
321.     EXPL_FIERY = 5,
322.     EXPL_FROSTY = 6,
323.     EXPL_MAX = 7
324. };
325. 
326. /* above plus this redundant? */
327. enum expl_types {
328.     expl_dark,
329.     expl_noxious,
330.     expl_muddy,
331.     expl_wet,
332.     expl_magical,
333.     expl_fiery,
334.     expl_frosty,
335. };
336. 
337. enum explode_colors {
338.     explode_color_dark = CLR_BLACK,
339.     explode_color_noxious = CLR_GREEN,
340.     explode_color_muddy = CLR_BROWN,
341.     explode_color_wet = CLR_BLUE,
342.     explode_color_magical = CLR_MAGENTA,
343.     explode_color_fiery = CLR_ORANGE,
344.     explode_color_frosty = CLR_WHITE
345. };
346. enum altar_types {
347.     altar_unaligned,
348.     altar_chaotic,
349.     altar_neutral,
350.     altar_lawful,
351.     altar_other
352. };
353. enum level_walls  { main_walls, mines_walls, gehennom_walls,
354.                     knox_walls, sokoban_walls };
355. enum { GM_FLAGS, GM_TTYCHAR, GM_COLOR, NUM_GLYPHMOD }; /* glyphmod entries */
356. enum glyphmap_change_triggers { gm_nochange, gm_newgame, gm_levelchange,
357.                                 gm_optionchange, gm_symchange,
358.                                 gm_accessibility_change };
359. #define NUM_ZAP 8 /* number of zap beam types */
360. 
361. /*
362.  * Glyphs are grouped for easy accessibility:
363.  *
364.  * male monsters    Represents all the wild (not tame) male monsters.
365.  *                  Count: NUMMONS.
366.  *
367.  * female monsters  Represents all the wild (not tame) female monsters.
368.  *                  Count: NUMMONS.
369.  *
370.  * male pets        Represents all of the male tame monsters.
371.  *                  Count: NUMMONS.
372.  *
373.  * female pets      Represents all of the female tame monsters.
374.  *                  Count: NUMMONS.
375.  *
376.  * invisible        Invisible monster placeholder.
377.  *                  Count: 1.
378.  *
379.  * detect (male)    Represents all detected male monsters.
380.  *                  Count: NUMMONS.
381.  *
382.  * detect (female)  Represents all detected female monsters.
383.  *                  Count: NUMMONS.
384.  *
385.  * corpse           One for each monster (male/female not differentiated).
386.  *                  Count: NUMMONS.
387.  *
388.  * ridden (male)    Represents all male monsters being ridden.
389.  *                  Count: NUMMONS
390.  *
391.  * ridden (female)  Represents all female monsters being ridden.
392.  *                  Count: NUMMONS
393.  *
394.  * object           One for each type of object.  The first entry is
395.  *                  'strange object', the next 1..MAXOCLASSES-1 entries
396.  *                  are generic (one for each class, including one for
397.  *                  strange object's 'illobj class'), the rest are
398.  *                  regular objects.  Some members of the generic
399.  *                  subset are used to prevent color of potions, gems,
400.  *                  and spellbooks from being revealed when obj->dknown
401.  *                  hasn't been set, avoiding a bug which had been
402.  *                  present since day one of color support.
403.  *                  Count: NUM_OBJECTS
404.  *
405.  * Stone            Stone
406.  *                  Count: 1
407.  *
408.  * main walls       level walls (main)
409.  *                  Count: (S_trwall - S_vwall) + 1 = 11
410.  *
411.  * mines walls      level walls (mines)
412.  *                  Count: (S_trwall - S_vwall) + 1 = 11
413.  *
414.  * gehennom walls   level walls (gehennom)
415.  *                  Count: (S_trwall - S_vwall) + 1 = 11
416.  *
417.  * knox walls       level walls (knox)
418.  *                  Count: (S_trwall - S_vwall) + 1 = 11
419.  *
420.  * sokoban walls    level walls (sokoban)
421.  *                  Count: (S_trwall - S_vwall) + 1 = 11
422.  *
423.  * cmap A           S_ndoor through S_brdnladder
424.  *                  Count: (S_brdnladder - S_ndoor) + 1 = 19
425.  *
426.  * Altars           Altar (unaligned, chaotic, neutral, lawful, other)
427.  *                  Count: 5
428.  *
429.  * cmap B           S_grave through S_arrow_trap + TRAPNUM - 1
430.  *                  Count: (S_arrow_trap + (TRAPNUM - 1) - S_grave) = 39
431.  *
432.  * zap beams        set of four (there are four directions) HI_ZAP.
433.  *                  Count: 4 * NUM_ZAP
434.  *
435.  * cmap C           S_digbeam through S_goodpos
436.  *                  Count: (S_goodpos - S_digbeam) + 1 = 10
437.  *
438.  * swallow          A set of eight for each monster.  The eight positions
439.  *                  represent those surrounding the hero.  The monster
440.  *                  number is shifted over 3 positions and the swallow
441.  *                  position is stored in the lower three bits.
442.  *                  Count: NUMMONS << 3
443.  *
444.  * dark explosions        A set of nine.
445.  *                        Count: MAXEXPCHAR
446.  *
447.  * noxious explosions     A set of nine.
448.  *                        Count: MAXEXPCHAR
449.  *
450.  * muddy explosions       A set of nine.
451.  *                        Count: MAXEXPCHAR
452.  *
453.  * wet explosions         A set of nine.
454.  *                        Count: MAXEXPCHAR
455.  *
456.  * magical explosions     A set of nine.
457.  *                        Count: MAXEXPCHAR
458.  *
459.  * fiery explosions       A set of nine.
460.  *                        Count: MAXEXPCHAR
461.  *
462.  * frosty explosions      A set of nine.
463.  *                        Count: MAXEXPCHAR
464.  *
465.  * warning                A set of six representing the different warning
466.  *                        levels.
467.  *                        Count: 6
468.  *
469.  * statues (male)         One for each male monster.
470.  *                        Count: NUMMONS
471.  *
472.  * statues (female)       One for each female mo nster.
473.  *                        Count: NUMMONS
474.  *
475.  * objects piletop        Represents the top of a pile as well as
476.  *                        the object.
477.  *                        Count: NUM_OBJECTS
478.  *
479.  * bodies piletop         Represents the top of a pile as well as
480.  *                        the object, corpse in this case.
481.  *                        Count: NUMMONS
482.  *
483.  * male statues piletop   Represents the top of a pile as well as
484.  *                        the statue of a male monster.
485.  *                        Count: NUMMONS
486.  *
487.  * female statues piletop Represents the top of a pile as well as
488.  *                        the statue of a female monster.
489.  *                        Count: NUMMONS
490.  *
491.  * unexplored             One for unexplored areas of the map
492.  * nothing                Nothing but background
493.  *
494.  * The following are offsets used to convert to and from a glyph.
495.  */
496. 
497. enum glyph_offsets {
498.     GLYPH_MON_OFF = 0,
499.     GLYPH_MON_MALE_OFF = (GLYPH_MON_OFF),
500.     GLYPH_MON_FEM_OFF = (NUMMONS + GLYPH_MON_MALE_OFF),
501.     GLYPH_PET_OFF = (NUMMONS + GLYPH_MON_FEM_OFF),
502.     GLYPH_PET_MALE_OFF = (GLYPH_PET_OFF),
503.     GLYPH_PET_FEM_OFF = (NUMMONS + GLYPH_PET_MALE_OFF),
504.     GLYPH_INVIS_OFF = (NUMMONS + GLYPH_PET_FEM_OFF),
505.     GLYPH_DETECT_OFF = (1 + GLYPH_INVIS_OFF),
506.     GLYPH_DETECT_MALE_OFF = (GLYPH_DETECT_OFF),
507.     GLYPH_DETECT_FEM_OFF = (NUMMONS + GLYPH_DETECT_MALE_OFF),
508.     GLYPH_BODY_OFF = (NUMMONS + GLYPH_DETECT_FEM_OFF),
509.     GLYPH_RIDDEN_OFF = (NUMMONS + GLYPH_BODY_OFF),
510.     GLYPH_RIDDEN_MALE_OFF = (GLYPH_RIDDEN_OFF),
511.     GLYPH_RIDDEN_FEM_OFF = (NUMMONS + GLYPH_RIDDEN_MALE_OFF),
512.     GLYPH_OBJ_OFF = (NUMMONS + GLYPH_RIDDEN_FEM_OFF),
513.     GLYPH_CMAP_OFF = (NUM_OBJECTS + GLYPH_OBJ_OFF),
514.     GLYPH_CMAP_STONE_OFF = (GLYPH_CMAP_OFF),
515.     GLYPH_CMAP_MAIN_OFF = (1 + GLYPH_CMAP_STONE_OFF),
516.     GLYPH_CMAP_MINES_OFF = (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_MAIN_OFF),
517.     GLYPH_CMAP_GEH_OFF = (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_MINES_OFF),
518.     GLYPH_CMAP_KNOX_OFF = (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_GEH_OFF),
519.     GLYPH_CMAP_SOKO_OFF = (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_KNOX_OFF),
520.     GLYPH_CMAP_A_OFF = (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_SOKO_OFF),
521.     GLYPH_ALTAR_OFF = (((S_brdnladder - S_ndoor) + 1) + GLYPH_CMAP_A_OFF),
522.     GLYPH_CMAP_B_OFF = (5 + GLYPH_ALTAR_OFF),
523.     GLYPH_ZAP_OFF = ((S_arrow_trap + MAXTCHARS - S_grave) + GLYPH_CMAP_B_OFF),
524.     GLYPH_CMAP_C_OFF = ((NUM_ZAP << 2) + GLYPH_ZAP_OFF),
525.     GLYPH_SWALLOW_OFF = (((S_goodpos - S_digbeam) + 1) + GLYPH_CMAP_C_OFF),
526.     GLYPH_EXPLODE_OFF = ((NUMMONS << 3) + GLYPH_SWALLOW_OFF),
527.     GLYPH_EXPLODE_DARK_OFF = (GLYPH_EXPLODE_OFF),
528.     GLYPH_EXPLODE_NOXIOUS_OFF = (MAXEXPCHARS + GLYPH_EXPLODE_DARK_OFF),
529.     GLYPH_EXPLODE_MUDDY_OFF = (MAXEXPCHARS + GLYPH_EXPLODE_NOXIOUS_OFF),
530.     GLYPH_EXPLODE_WET_OFF = (MAXEXPCHARS + GLYPH_EXPLODE_MUDDY_OFF),
531.     GLYPH_EXPLODE_MAGICAL_OFF = (MAXEXPCHARS + GLYPH_EXPLODE_WET_OFF),
532.     GLYPH_EXPLODE_FIERY_OFF = (MAXEXPCHARS + GLYPH_EXPLODE_MAGICAL_OFF),
533.     GLYPH_EXPLODE_FROSTY_OFF = (MAXEXPCHARS + GLYPH_EXPLODE_FIERY_OFF),
534.     GLYPH_WARNING_OFF = (MAXEXPCHARS + GLYPH_EXPLODE_FROSTY_OFF),
535.     GLYPH_STATUE_OFF = (WARNCOUNT + GLYPH_WARNING_OFF),
536.     GLYPH_STATUE_MALE_OFF = (GLYPH_STATUE_OFF),
537.     GLYPH_STATUE_FEM_OFF = (NUMMONS + GLYPH_STATUE_MALE_OFF),
538.     GLYPH_PILETOP_OFF = (NUMMONS + GLYPH_STATUE_FEM_OFF),
539.     GLYPH_OBJ_PILETOP_OFF = (GLYPH_PILETOP_OFF),
540.     GLYPH_BODY_PILETOP_OFF = (NUM_OBJECTS + GLYPH_OBJ_PILETOP_OFF),
541.     GLYPH_STATUE_MALE_PILETOP_OFF = (NUMMONS + GLYPH_BODY_PILETOP_OFF),
542.     GLYPH_STATUE_FEM_PILETOP_OFF = (NUMMONS + GLYPH_STATUE_MALE_PILETOP_OFF),
543.     GLYPH_UNEXPLORED_OFF = (NUMMONS + GLYPH_STATUE_FEM_PILETOP_OFF),
544.     GLYPH_NOTHING_OFF = (GLYPH_UNEXPLORED_OFF + 1),
545.     MAX_GLYPH
546. };
547. 
548. #define NO_GLYPH          MAX_GLYPH
549. #define GLYPH_INVISIBLE   GLYPH_INVIS_OFF
550. #define GLYPH_UNEXPLORED  GLYPH_UNEXPLORED_OFF
551. #define GLYPH_NOTHING     GLYPH_NOTHING_OFF
552. 
553. #define warning_to_glyph(mwarnlev) ((mwarnlev) + GLYPH_WARNING_OFF)
554. #define mon_to_glyph(mon, rng) \
555.     ((int) what_mon(monsndx((mon)->data), rng)                          \
556.      + (((mon)->female == 0) ?  GLYPH_MON_MALE_OFF : GLYPH_MON_FEM_OFF))
557. #define detected_mon_to_glyph(mon, rng) \
558.     ((int) what_mon(monsndx((mon)->data), rng)                          \
559.      + (((mon)->female == 0) ?  GLYPH_DETECT_MALE_OFF : GLYPH_DETECT_FEM_OFF))
560. #define ridden_mon_to_glyph(mon, rng) \
561.     ((int) what_mon(monsndx((mon)->data), rng)                          \
562.      + (((mon)->female == 0) ?  GLYPH_RIDDEN_MALE_OFF : GLYPH_RIDDEN_FEM_OFF))
563. #define pet_to_glyph(mon, rng) \
564.     ((int) what_mon(monsndx((mon)->data), rng)                          \
565.      + (((mon)->female == 0) ? GLYPH_PET_MALE_OFF : GLYPH_PET_FEM_OFF))
566. 
567. /* treat unaligned as the default instead of explicitly checking for it;
568.    altar alignment uses 3 bits with 4 defined values and 4 unused ones */
569. #define altar_to_glyph(amsk) \
570.     ((((amsk) & AM_SANCTUM) == AM_SANCTUM)                \
571.       ? (GLYPH_ALTAR_OFF + altar_other)                   \
572.       : (((amsk) & AM_MASK) == AM_LAWFUL)                 \
573.          ? (GLYPH_ALTAR_OFF + altar_lawful)               \
574.          : (((amsk) & AM_MASK) == AM_NEUTRAL)             \
575.             ? (GLYPH_ALTAR_OFF + altar_neutral)           \
576.             : (((amsk) & AM_MASK) == AM_CHAOTIC)          \
577.                ? (GLYPH_ALTAR_OFF + altar_chaotic)        \
578.                /* (((amsk) & AM_MASK) == AM_UNALIGNED) */ \
579.                : (GLYPH_ALTAR_OFF + altar_unaligned))
580. 
581. /* not used, nor is it correct
582. #define zap_to_glyph(zaptype, cmap_idx) \
583.     ((((cmap_idx) - S_vbeam) + 1) + GLYPH_ZAP_OFF)
584. */
585. 
586. /* EXPL_FIERY is the default explosion type */
587. #define explosion_to_glyph(expltyp, idx) \
588.     ((idx) - S_expl_tl                                                  \
589.      + (((expltyp) == EXPL_FROSTY) ? GLYPH_EXPLODE_FROSTY_OFF           \
590.         : ((expltyp) == EXPL_MAGICAL) ? GLYPH_EXPLODE_MAGICAL_OFF       \
591.           : ((expltyp) == EXPL_WET) ? GLYPH_EXPLODE_WET_OFF             \
592.            : ((expltyp) == EXPL_MUDDY) ? GLYPH_EXPLODE_MUDDY_OFF        \
593.              : ((expltyp) == EXPL_NOXIOUS) ? GLYPH_EXPLODE_NOXIOUS_OFF  \
594.                : GLYPH_EXPLODE_FIERY_OFF))
595. 
596. /* cmap_walls_to_glyph(): return the glyph number for specified wall
597.    symbol; result varies by dungeon branch */
598. #define cmap_walls_to_glyph(cmap_idx) \
599.     ((cmap_idx) - S_vwall                               \
600.      + (In_mines(&u.uz) ? GLYPH_CMAP_MINES_OFF          \
601.         : In_hell(&u.uz) ? GLYPH_CMAP_GEH_OFF           \
602.           : Is_knox(&u.uz) ? GLYPH_CMAP_KNOX_OFF        \
603.             : In_sokoban(&u.uz) ? GLYPH_CMAP_SOKO_OFF   \
604.               : GLYPH_CMAP_MAIN_OFF))
605. 
606. /* cmap_D0walls_to_glyph(): simpler version of cmap_walls_to_glyph()
607.    which returns the glyph that would be used in the main dungeon,
608.    regardless of hero's current location */
609. #define cmap_D0walls_to_glyph(cmap_idx) \
610.     ((cmap_idx) - S_vwall + GLYPH_CMAP_MAIN_OFF)
611. 
612. #define cmap_a_to_glyph(cmap_idx) \
613.     (((cmap_idx) - S_ndoor) + GLYPH_CMAP_A_OFF)
614. 
615. #define cmap_b_to_glyph(cmap_idx) \
616.     (((cmap_idx) - S_grave) + GLYPH_CMAP_B_OFF)
617. 
618. #define cmap_c_to_glyph(cmap_idx) \
619.     (((cmap_idx) - S_digbeam) + GLYPH_CMAP_C_OFF)
620. 
621. #define cmap_to_glyph(cmap_idx) \
622.     ( ((cmap_idx) == S_stone)   ? GLYPH_CMAP_STONE_OFF                      \
623.     : ((cmap_idx) <= S_trwall)  ? cmap_walls_to_glyph(cmap_idx)             \
624.     : ((cmap_idx) <  S_altar)   ? cmap_a_to_glyph(cmap_idx)                 \
625.     : ((cmap_idx) == S_altar)   ? altar_to_glyph(AM_NEUTRAL)                \
626.     : ((cmap_idx) <  S_arrow_trap + MAXTCHARS) ? cmap_b_to_glyph(cmap_idx)  \
627.     : ((cmap_idx) <= S_goodpos) ? cmap_c_to_glyph(cmap_idx)                 \
628.       : NO_GLYPH )
629. 
630. #define trap_to_glyph(trap)                                \
631.     cmap_to_glyph(trap_to_defsym(((int) (trap)->ttyp)))
632. 
633. #define engraving_to_glyph(ep)                             \
634.     cmap_to_glyph(engraving_to_defsym(ep))
635. 
636. /* Not affected by hallucination.  Gives a generic body for CORPSE */
637. /* MRKR: ...and the generic statue */
638. #define objnum_to_glyph(onum) ((int) (onum) + GLYPH_OBJ_OFF)
639. #define monnum_to_glyph(mnum,gnd) \
640.     ((int) (mnum) + (((gnd) == MALE) ? GLYPH_MON_MALE_OFF       \
641.                                      : GLYPH_MON_FEM_OFF))
642. #define detected_monnum_to_glyph(mnum,gnd) \
643.     ((int) (mnum) + (((gnd) == MALE) ? GLYPH_DETECT_MALE_OFF    \
644.                                      : GLYPH_DETECT_FEM_OFF))
645. #define ridden_monnum_to_glyph(mnum,gnd) \
646.     ((int) (mnum) + (((gnd) == MALE) ? GLYPH_RIDDEN_MALE_OFF    \
647.                                      : GLYPH_RIDDEN_FEM_OFF))
648. #define petnum_to_glyph(mnum,gnd) \
649.     ((int) (mnum) + (((gnd) == MALE) ? GLYPH_PET_MALE_OFF       \
650.                                      : GLYPH_PET_FEM_OFF))
651. 
652. /* The hero's glyph when seen as a monster.
653.  */
654. #define hero_glyph \
655.     monnum_to_glyph((Upolyd || !flags.showrace) ? u.umonnum : gu.urace.mnum, \
656.                     (Ugender))
657. 
658. /*
659.  * Change the given glyph into its given type.  Note:
660.  *      1) Pets, detected, and ridden monsters are animals and are converted
661.  *         to the proper monster number.
662.  *      2) Bodies are all mapped into the generic CORPSE object
663.  *      3) If handed a glyph out of range for the type, these functions
664.  *         will return NO_GLYPH (see exception below)
665.  *      4) glyph_to_swallow() does not return a showsyms[] index, but an
666.  *         offset from the first swallow symbol.  If handed something
667.  *         out of range, it will return zero (for lack of anything better
668.  *         to return).
669.  */
670. 
671. #define glyph_to_trap(glyph) \
672.     (glyph_is_trap(glyph)                                                   \
673.         ? ((int) defsym_to_trap(((glyph) - GLYPH_TRAP_OFF) + S_arrow_trap)) \
674.         : NO_GLYPH)
675. 
676. #define glyph_is_cmap_main(glyph) \
677.     ((glyph) >= GLYPH_CMAP_MAIN_OFF                                     \
678.      && (glyph) < (((S_trwall - S_vwall) +1) + GLYPH_CMAP_MAIN_OFF))
679. #define glyph_is_cmap_mines(glyph) \
680.     ((glyph) >= GLYPH_CMAP_MINES_OFF                                    \
681.      && (glyph) < (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_MINES_OFF))
682. #define glyph_is_cmap_gehennom(glyph) \
683.     ((glyph) >= GLYPH_CMAP_GEH_OFF                                      \
684.      && (glyph) < (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_GEH_OFF))
685. #define glyph_is_cmap_knox(glyph) \
686.     ((glyph) >= GLYPH_CMAP_KNOX_OFF                                     \
687.      && (glyph) < (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_KNOX_OFF))
688. #define glyph_is_cmap_sokoban(glyph) \
689.     ((glyph) >= GLYPH_CMAP_SOKO_OFF                                     \
690.      && (glyph) < (((S_trwall - S_vwall) + 1) + GLYPH_CMAP_SOKO_OFF))
691. #define glyph_is_cmap_a(glyph) \
692.     ((glyph) >= GLYPH_CMAP_A_OFF                                        \
693.      && (glyph) < (((S_brdnladder - S_ndoor) + 1) + GLYPH_CMAP_A_OFF))
694. #define glyph_is_cmap_altar(glyph) \
695.     ((glyph) >= GLYPH_ALTAR_OFF && (glyph) < (5 + GLYPH_ALTAR_OFF))
696. #define glyph_is_cmap_b(glyph) \
697.     ((glyph) >= GLYPH_CMAP_B_OFF                                        \
698.      && ((glyph) < ((S_arrow_trap + MAXTCHARS - S_grave) + GLYPH_CMAP_B_OFF)))
699. #define glyph_is_cmap_zap(glyph) \
700.     ((glyph) >= GLYPH_ZAP_OFF && (glyph) < ((NUM_ZAP << 2) + GLYPH_ZAP_OFF))
701. #define glyph_is_cmap_c(glyph) \
702.     ((glyph) >= GLYPH_CMAP_C_OFF                                        \
703.      && (glyph) < (((S_goodpos - S_digbeam) + 1) + GLYPH_CMAP_C_OFF))
704. #define glyph_is_swallow(glyph) \
705.     ((glyph) >= GLYPH_SWALLOW_OFF                                       \
706.      && (glyph) < (((NUMMONS << 3) + GLYPH_SWALLOW_OFF)))
707. #define glyph_is_explosion(glyph) \
708.     ((glyph) >= GLYPH_EXPLODE_OFF                                       \
709.      && (glyph) < (MAXEXPCHARS + GLYPH_EXPLODE_FROSTY_OFF))
710. #if 0   /* this is more precise but expands to a lot of unnecessary code */
711. #define glyph_is_cmap(glyph) \
712.     (((glyph) == GLYPH_CMAP_STONE_OFF) \
713.      || glyph_is_cmap_main(glyph)      \
714.      || glyph_is_cmap_mines(glyph)     \
715.      || glyph_is_cmap_gehennom(glyph)  \
716.      || glyph_is_cmap_knox(glyph)      \
717.      || glyph_is_cmap_sokoban(glyph)   \
718.      || glyph_is_cmap_a(glyph)         \
719.      || glyph_is_cmap_altar(glyph)     \
720.      || glyph_is_cmap_b(glyph)         \
721.      || glyph_is_cmap_c(glyph))
722. #endif
723. #define glyph_is_cmap(glyph) \
724.     ((glyph) >= GLYPH_CMAP_STONE_OFF \
725.      && (glyph) < (GLYPH_CMAP_C_OFF + ((S_goodpos - S_digbeam) + 1)))
726. #define glyph_to_swallow(glyph) \
727.     (glyph_is_swallow(glyph) ? (((glyph) - GLYPH_SWALLOW_OFF) & 0x7) : 0)
728. #define glyph_to_explosion(glyph) \
729.     (glyph_is_explosion(glyph) ? (((glyph) - GLYPH_EXPLODE_OFF) % (S_expl_br - S_expl_tl + 1)) : 0)
730. #define glyph_to_warning(glyph) \
731.     (glyph_is_warning(glyph) ? ((glyph) - GLYPH_WARNING_OFF) : 0)
732. 
733. /*
734.  * Return true if the given glyph is what we want.  Note that bodies are
735.  * considered objects.
736.  */
737. #define glyph_is_normal_male_monster(glyph) \
738.     ((glyph) >= GLYPH_MON_MALE_OFF                      \
739.      && (glyph) < (GLYPH_MON_MALE_OFF + NUMMONS))
740. #define glyph_is_normal_female_monster(glyph) \
741.     ((glyph) >= GLYPH_MON_FEM_OFF && (glyph) < (GLYPH_MON_FEM_OFF + NUMMONS))
742. #define glyph_is_normal_monster(glyph) \
743.     (glyph_is_normal_male_monster(glyph)                \
744.      || glyph_is_normal_female_monster(glyph))
745. #define glyph_is_female_pet(glyph) \
746.     ((glyph) >= GLYPH_PET_FEM_OFF && (glyph) < (GLYPH_PET_FEM_OFF + NUMMONS))
747. #define glyph_is_male_pet(glyph) \
748.     ((glyph) >= GLYPH_PET_MALE_OFF                      \
749.      && (glyph) < (GLYPH_PET_MALE_OFF + NUMMONS))
750. #define glyph_is_pet(glyph) \
751.     (glyph_is_male_pet(glyph) || glyph_is_female_pet(glyph))
752. #define glyph_is_ridden_female_monster(glyph) \
753.     ((glyph) >= GLYPH_RIDDEN_FEM_OFF                    \
754.      && (glyph) < (GLYPH_RIDDEN_FEM_OFF + NUMMONS))
755. #define glyph_is_ridden_male_monster(glyph) \
756.     ((glyph) >= GLYPH_RIDDEN_MALE_OFF                   \
757.      && (glyph) < (GLYPH_RIDDEN_MALE_OFF + NUMMONS))
758. #define glyph_is_ridden_monster(glyph) \
759.     (glyph_is_ridden_male_monster(glyph)                \
760.      || glyph_is_ridden_female_monster(glyph))
761. #define glyph_is_detected_female_monster(glyph) \
762.     ((glyph) >= GLYPH_DETECT_FEM_OFF                    \
763.      && (glyph) < (GLYPH_DETECT_FEM_OFF + NUMMONS))
764. #define glyph_is_detected_male_monster(glyph) \
765.     ((glyph) >= GLYPH_DETECT_MALE_OFF                   \
766.      && (glyph) < (GLYPH_DETECT_MALE_OFF + NUMMONS))
767. #define glyph_is_detected_monster(glyph) \
768.     (glyph_is_detected_male_monster(glyph)              \
769.         || glyph_is_detected_female_monster(glyph))
770. #define glyph_is_monster(glyph) \
771.     (glyph_is_normal_monster(glyph) || glyph_is_pet(glyph)              \
772.      || glyph_is_ridden_monster(glyph) || glyph_is_detected_monster(glyph))
773. #define glyph_is_invisible(glyph) ((glyph) == GLYPH_INVISIBLE)
774. 
775. /* final NUMMONS is legal array index because of trailing fencepost entry */
776. #define glyph_to_mon(glyph) \
777.        (glyph_is_normal_female_monster(glyph)                  \
778.          ? ((glyph) - GLYPH_MON_FEM_OFF)                       \
779.          : glyph_is_normal_male_monster(glyph)                 \
780.            ? ((glyph) - GLYPH_MON_MALE_OFF)                    \
781.            : glyph_is_female_pet(glyph)                        \
782.              ? ((glyph) - GLYPH_PET_FEM_OFF)                   \
783.              : glyph_is_male_pet(glyph)                        \
784.                ? ((glyph) - GLYPH_PET_MALE_OFF)                \
785.                : glyph_is_detected_female_monster(glyph)       \
786.                  ? ((glyph) - GLYPH_DETECT_FEM_OFF)            \
787.                  : glyph_is_detected_male_monster(glyph)       \
788.                    ? ((glyph) - GLYPH_DETECT_MALE_OFF)         \
789.                    : glyph_is_ridden_female_monster(glyph)     \
790.                      ? ((glyph) - GLYPH_RIDDEN_FEM_OFF)        \
791.                      : glyph_is_ridden_male_monster(glyph)     \
792.                        ? ((glyph) - GLYPH_RIDDEN_MALE_OFF)     \
793.                        : NUMMONS)
794. 
795. /* boulder hides pile except when on top of another boulder;
796.    the otg_otmp assignment might occur multiple times in the same
797.    expression but there will always be sequence points in between */
798. #define obj_is_piletop(obj) \
799.     ((obj)->where == OBJ_FLOOR                                             \
800.      && ((go.otg_otmp = svl.level.objects[(obj)->ox][(obj)->oy]->nexthere) \
801.          != 0)                                                             \
802.      && ((obj)->otyp != BOULDER || go.otg_otmp->otyp == BOULDER))
803. /* used to hide info such as potion and gem color when not seen yet;
804.    stones and rock are excluded for gem class; LAST_SPELL includes blank
805.    spellbook but excludes novel and the Book of the Dead */
806. #define obj_is_generic(obj) \
807.     (!(obj)->dknown                                             \
808.      && ((obj)->oclass == POTION_CLASS                          \
809.          || ((obj)->otyp >= FIRST_REAL_GEM                      \
810.              && ((obj)->otyp <= LAST_GLASS_GEM))                \
811.          || ((obj)->otyp >= FIRST_SPELL                         \
812.              && ((obj)->otyp <= LAST_SPELL))))
813. 
814. #define glyph_is_body_piletop(glyph) \
815.     (((glyph) >= GLYPH_BODY_PILETOP_OFF)                        \
816.      && ((glyph) < (GLYPH_BODY_PILETOP_OFF + NUMMONS)))
817. #define glyph_is_body(glyph) \
818.     ((((glyph) >= GLYPH_BODY_OFF) && ((glyph) < (GLYPH_BODY_OFF + NUMMONS))) \
819.      || glyph_is_body_piletop(glyph))
820. 
821. #define glyph_is_fem_statue_piletop(glyph) \
822.     (((glyph) >= GLYPH_STATUE_FEM_PILETOP_OFF)                  \
823.       && ((glyph) < (GLYPH_STATUE_FEM_PILETOP_OFF + NUMMONS)))
824. #define glyph_is_male_statue_piletop(glyph) \
825.     (((glyph) >= GLYPH_STATUE_MALE_PILETOP_OFF)                 \
826.          && ((glyph) < (GLYPH_STATUE_MALE_PILETOP_OFF + NUMMONS)))
827. #define glyph_is_fem_statue(glyph) \
828.     ((((glyph) >= GLYPH_STATUE_FEM_OFF)                         \
829.       && ((glyph) < (GLYPH_STATUE_FEM_OFF + NUMMONS)))          \
830.      || glyph_is_fem_statue_piletop(glyph))
831. #define glyph_is_male_statue(glyph) \
832.     ((((glyph) >= GLYPH_STATUE_MALE_OFF)                        \
833.       && ((glyph) < (GLYPH_STATUE_MALE_OFF + NUMMONS)))         \
834.      || glyph_is_male_statue_piletop(glyph))
835. #define glyph_is_statue(glyph) \
836.     (glyph_is_male_statue(glyph) || glyph_is_fem_statue(glyph))
837. /* generic objects are after strange object (GLYPH_OBJ_OFF) and before
838.    other objects (GLYPH_OBJ_OFF + FIRST_OBJECT) */
839. #define glyph_is_normal_generic_obj(glyph) \
840.     ((glyph) > GLYPH_OBJ_OFF && (glyph) < GLYPH_OBJ_OFF + FIRST_OBJECT - 1)
841. #define glyph_is_piletop_generic_obj(glyph) \
842.     ((glyph) > GLYPH_OBJ_PILETOP_OFF                            \
843.      && (glyph) < GLYPH_OBJ_PILETOP_OFF + FIRST_OBJECT - 1)
844. #define glyph_is_generic_object(glyph) \
845.     (glyph_is_normal_generic_obj(glyph)                         \
846.      || glyph_is_piletop_generic_obj(glyph))
847. #define glyph_is_normal_piletop_obj(glyph) \
848.     ((glyph) == GLYPH_OBJ_PILETOP_OFF                           \
849.      || ((glyph) > GLYPH_OBJ_PILETOP_OFF + FIRST_OBJECT - 1     \
850.          && (glyph) < (GLYPH_OBJ_PILETOP_OFF + NUM_OBJECTS)))
851. #define glyph_is_normal_object(glyph) \
852.     ((glyph) == GLYPH_OBJ_OFF                                   \
853.      || ((glyph) >= GLYPH_OBJ_OFF + FIRST_OBJECT - 1            \
854.          && (glyph) < (GLYPH_OBJ_OFF + NUM_OBJECTS))            \
855.      || glyph_is_normal_piletop_obj(glyph))
856. 
857. #if 0   /* [note: out of date] */
858. #define glyph_is_object(glyph) \
859.   (   (((glyph) >= GLYPH_OBJ_OFF)                                       \
860.        && ((glyph) < (GLYPH_OBJ_OFF + NUM_OBJECTS)))                    \
861.    || (((glyph) >= GLYPH_OBJ_PILETOP_OFF)                               \
862.        && ((glyph) < (GLYPH_OBJ_PILETOP_OFF + NUM_OBJECTS)))            \
863.    || (((glyph) >= GLYPH_STATUE_MALE_OFF)                               \
864.        && ((glyph) < (GLYPH_STATUE_MALE_OFF + NUMMONS)))                \
865.    || (((glyph) >= GLYPH_STATUE_MALE_PILETOP_OFF)                       \
866.        && ((glyph) < (GLYPH_STATUE_MALE_PILETOP_OFF + NUMMONS)))        \
867.    || (((glyph) >= GLYPH_STATUE_FEM_OFF)                                \
868.        && ((glyph) < (GLYPH_STATUE_FEM_OFF + NUMMONS)))                 \
869.    || (((glyph) >= GLYPH_STATUE_FEM_PILETOP_OFF)                        \
870.        && ((glyph) < (GLYPH_STATUE_FEM_PILETOP_OFF + NUMMONS)))         \
871.    || (((glyph) >= GLYPH_BODY_OFF)                                      \
872.        && ((glyph) < (GLYPH_BODY_OFF + NUMMONS)))                       \
873.    || (((glyph) >= GLYPH_BODY_PILETOP_OFF)                              \
874.        && ((glyph) < (GLYPH_BODY_PILETOP_OFF + NUMMONS)))               \
875.   )
876. #endif
877. #define glyph_is_object(glyph) \
878.     (glyph_is_normal_object(glyph) || glyph_is_generic_object(glyph)    \
879.      || glyph_is_statue(glyph) || glyph_is_body(glyph))
880. 
881. /* briefly used for Qt's "paper doll" inventory which shows map tiles for
882.    equipped objects; those vary like floor items during hallucination now
883.    so this isn't used anywhere [note: out of date since generic objs added] */
884. #define obj_to_true_glyph(obj)                                  \
885.     (((obj)->otyp == STATUE)                                    \
886.      ? ((int) (obj)->corpsenm                                   \
887.         + (((obj)->spe & CORPSTAT_GENDER) == CORPSTAT_FEMALE)   \
888.              ? (obj_is_piletop(obj)                             \
889.                 ? (GLYPH_STATUE_FEM_PILETOP_OFF)                \
890.                 : (GLYPH_STATUE_FEM_OFF))                       \
891.              : (obj_is_piletop(obj)                             \
892.                 ? (GLYPH_STATUE_MALE_PILETOP_OFF)               \
893.                 : (GLYPH_STATUE_MALE_OFF))                      \
894.      : (((obj)->otyp == CORPSE)                                 \
895.          ? ((int) (obj)->corpsenm                               \
896.             + (obj_is_piletop(obj)                              \
897.                 ? (GLYPH_BODY_PILETOP_OFF)                      \
898.                 ? (GLYPH_BODY_OFF)))                            \
899.          : ((int) (obj)->otyp + GLYPH_OBJ_OFF))))
900. 
901. /* final NUM_OBJECTS is legal array idx because of trailing fencepost entry */
902. #define glyph_to_obj(glyph) \
903.     (glyph_is_body(glyph) ? CORPSE                              \
904.      : glyph_is_statue(glyph) ? STATUE                          \
905.        : glyph_is_generic_object(glyph)                         \
906.          ? ((glyph) - (glyph_is_piletop_generic_obj(glyph)      \
907.                        ? GLYPH_OBJ_PILETOP_OFF                  \
908.                        : GLYPH_OBJ_OFF))                        \
909.          : glyph_is_normal_object(glyph)                        \
910.            ? ((glyph) - (glyph_is_normal_piletop_obj(glyph)     \
911.                          ? GLYPH_OBJ_PILETOP_OFF                \
912.                          : GLYPH_OBJ_OFF))                      \
913.            : NUM_OBJECTS)
914. 
915. #define glyph_to_body_corpsenm(glyph) \
916.     (glyph_is_body_piletop(glyph)                       \
917.        ? ((glyph) - GLYPH_BODY_PILETOP_OFF)             \
918.        : ((glyph) - GLYPH_BODY_OFF))
919. 
920. #define glyph_to_statue_corpsenm(glyph) \
921.     (glyph_is_fem_statue_piletop(glyph)                 \
922.        ? ((glyph) - GLYPH_STATUE_FEM_PILETOP_OFF)       \
923.        : glyph_is_male_statue_piletop(glyph)            \
924.            ? ((glyph) - GLYPH_STATUE_MALE_PILETOP_OFF)  \
925.            : glyph_is_fem_statue(glyph)                 \
926.                ? ((glyph) - GLYPH_STATUE_FEM_OFF)       \
927.                : glyph_is_male_statue(glyph)            \
928.                    ? ((glyph) - GLYPH_STATUE_MALE_OFF)  \
929.                    : NO_GLYPH)
930. 
931. /* This has the unfortunate side effect of needing a global variable
932.    to store a result. 'otg_temp' is defined and declared in decl.{ch}.  */
933. #define random_obj_to_glyph(rng) \
934.     (((go.otg_temp = random_object(rng)) == CORPSE)     \
935.          ? (random_monster(rng) + GLYPH_BODY_OFF)       \
936.          : (go.otg_temp + GLYPH_OBJ_OFF))
937. #define corpse_to_glyph(obj) \
938.     ((int) ((obj)->corpsenm                             \
939.           + (obj_is_piletop(obj) ? GLYPH_BODY_PILETOP_OFF : GLYPH_BODY_OFF)))
940. #define generic_obj_to_glyph(obj) \
941.     ((int) ((obj)->oclass                               \
942.             + (obj_is_piletop(obj) ? GLYPH_OBJ_PILETOP_OFF : GLYPH_OBJ_OFF)))
943. #define normal_obj_to_glyph(obj) \
944.     ((int) ((obj)->otyp                                 \
945.             + (obj_is_piletop(obj) ? GLYPH_OBJ_PILETOP_OFF : GLYPH_OBJ_OFF)))
946. 
947. /* MRKR: Statues now have glyphs corresponding to the monster they    */
948. /*       represent and look like monsters when you are hallucinating. */
949. 
950. #define statue_to_glyph(obj, rng) \
951.     ((Hallucination)                                                \
952.      ? ((random_monster(rng))                                       \
953.         + ((!(rng)(2)) ? GLYPH_MON_MALE_OFF : GLYPH_MON_FEM_OFF))   \
954.      : ((int) (obj)->corpsenm                                       \
955.         + ((((obj)->spe & CORPSTAT_GENDER) == CORPSTAT_FEMALE)      \
956.            ? (obj_is_piletop(obj)                                   \
957.               ? GLYPH_STATUE_FEM_PILETOP_OFF                        \
958.               : GLYPH_STATUE_FEM_OFF)                               \
959.            : (obj_is_piletop(obj)                                   \
960.               ? GLYPH_STATUE_MALE_PILETOP_OFF                       \
961.               : GLYPH_STATUE_MALE_OFF))))
962. 
963. #define obj_to_glyph(obj, rng) \
964.     (((obj)->otyp == STATUE) ? statue_to_glyph(obj, rng)            \
965.      : (Hallucination) ? random_obj_to_glyph(rng)                   \
966.        : ((obj)->otyp == CORPSE) ? corpse_to_glyph(obj)             \
967.          : obj_is_generic(obj) ? generic_obj_to_glyph(obj)          \
968.            : normal_obj_to_glyph(obj))
969. 
970. #define GLYPH_TRAP_OFF \
971.     (GLYPH_CMAP_B_OFF + (S_arrow_trap - S_grave))
972. #define glyph_is_trap(glyph) \
973.     ((glyph) >= (GLYPH_TRAP_OFF)                        \
974.      && (glyph) < ((GLYPH_TRAP_OFF) + MAXTCHARS))
975. #define glyph_is_warning(glyph) \
976.     ((glyph) >= GLYPH_WARNING_OFF                       \
977.      && (glyph) < (GLYPH_WARNING_OFF + WARNCOUNT))
978. #define glyph_is_unexplored(glyph) ((glyph) == GLYPH_UNEXPLORED)
979. #define glyph_is_nothing(glyph) ((glyph) == GLYPH_NOTHING)
980. 
981. #if 0
982. #define glyph_is_piletop(glyph) \
983.     (glyph_is_body_piletop(glyph)           \
984.      || glyph_is_fem_statue_piletop(glyph)  \
985.      || glyph_is_male_statue_piletop(glyph) \
986.      || glyph_is_piletop_generic_obj(glyph) \
987.      || glyph_is_normal_piletop_obj(glyph))
988. #endif
989. 
990. /* mgflags for altering map_glyphinfo() internal behavior */
991. #define MG_FLAG_NORMAL     0x00
992. #define MG_FLAG_NOOVERRIDE 0x01 /* disregard accessibility override values */
993. 
994. /* Special mapped glyphflags encoded by reset_glyphmap() + map_glyphinfo() */
995. #define MG_HERO    0x00001  /* represents the hero */
996. #define MG_CORPSE  0x00002  /* represents a body */
997. #define MG_INVIS   0x00004  /* represents invisible monster */
998. #define MG_DETECT  0x00008  /* represents a detected monster */
999. #define MG_PET     0x00010  /* represents a pet */
1000. #define MG_RIDDEN  0x00020  /* represents a ridden monster */
1001. #define MG_STATUE  0x00040  /* represents a statue */
1002. #define MG_OBJPILE 0x00080  /* more than one stack of objects */
1003. #define MG_BW_LAVA 0x00100  /* 'black & white lava': highlight lava if it
1004.                              * can't be distinguished from water by color */
1005. #define MG_BW_ICE  0x00200  /* similar for ice vs floor */
1006. #define MG_BW_SINK 0x00200  /* identical for sink vs fountain [note: someday
1007.                              * this may become a distinct flag */
1008. #define MG_BW_ENGR 0x00200  /* likewise for corridor engravings */
1009. #define MG_NOTHING 0x00400  /* char represents GLYPH_NOTHING */
1010. #define MG_UNEXPL  0x00800  /* char represents GLYPH_UNEXPLORED */
1011. #define MG_MALE    0x01000  /* represents a male mon or statue of one */
1012. #define MG_FEMALE  0x02000  /* represents a female mon or statue of one */
1013. #define MG_BADXY   0x04000  /* bad coordinates were passed */
1014. 
1015. /* docrt(): re-draw whole screen; docrt_flags(): docrt() with more control */
1016. enum docrt_flags_bits {
1017.     docrtRecalc  = 0, /* full docrt(), recalculate what the map should show */
1018.     docrtRefresh = 1, /* redraw_map(), draw what we think the map shows */
1019.     docrtMapOnly = 2, /* ORed with Recalc or Refresh; draw the map but not
1020.                        * status or perminv */
1021.     docrtNocls = 4,
1022. };
1023. 
1024. typedef struct {
1025.     xint8 gnew; /* perhaps move this bit into the rm structure. */
1026.     glyph_info glyphinfo;
1027. } gbuf_entry;
1028. 
1029. extern const int altarcolors[];
1030. extern const int zapcolors[];
1031. extern const int explodecolors[];
1032. extern int wallcolors[];
1033. 
1034. /* If TILES_IN_GLYPHMAP is defined during build, this is defined
1035.  * in the generated tile.c, complete with appropriate tile references in
1036.  * the initialization.  Otherwise, it gets defined in display.c.
1037.  */
1038. extern const glyph_info nul_glyphinfo;
1039. 
1040. #endif /* DISPLAY_H */