OSDN Git Service

upgrade to 3.6.2
[jnethack/source.git] / include / display.h
1 /* NetHack 3.6  display.h       $NHDT-Date: 1546212620 2018/12/30 23:30:20 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.29 $ */
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).
21  */
22 #define vobj_at(x, y) (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 mimicing other monsters.
29  */
30 #define tp_sensemon(mon) \
31     (/* The hero can always sense a monster IF:        */  \
32      /* 1. the monster has a brain to sense            */  \
33      (!mindless(mon->data))                                \
34      /* AND     2a. hero is blind and telepathic       */  \
35       && ((Blind && Blind_telepat)                         \
36           /* OR 2b. hero is using a telepathy inducing */  \
37           /*        object and in range                */  \
38           || (Unblind_telepat                              \
39               && (distu(mon->mx, mon->my) <= (BOLT_LIM * BOLT_LIM)))))
40
41 #define sensemon(mon) \
42     (tp_sensemon(mon) || Detect_monsters || MATCH_WARN_OF_MON(mon))
43
44 /*
45  * mon_warning() is used to warn of any dangerous monsters in your
46  * vicinity, and a glyph representing the warning level is displayed.
47  */
48
49 #define mon_warning(mon)                                                 \
50     (Warning && !(mon)->mpeaceful && (distu((mon)->mx, (mon)->my) < 100) \
51      && (((int) ((mon)->m_lev / 4)) >= context.warnlevel))
52
53 /*
54  * mon_visible()
55  *
56  * Returns true if the hero can see the monster.  It is assumed that the
57  * hero can physically see the location of the monster.  The function
58  * vobj_at() returns a pointer to an object that the hero can see there.
59  * Infravision is not taken into account.
60  */
61 #define mon_visible(mon) \
62     (/* The hero can see the monster IF the monster                     */ \
63      (!mon->minvis || See_invisible)  /*     1. is not invisible        */ \
64      && !mon->mundetected             /* AND 2. not an undetected hider */ \
65      && !(mon->mburied || u.uburied)) /* AND 3. neither you nor it is buried */
66
67 /*
68  * see_with_infrared()
69  *
70  * This function is true if the player can see a monster using infravision.
71  * The caller must check for invisibility (invisible monsters are also
72  * invisible to infravision), because this is usually called from within
73  * canseemon() or canspotmon() which already check that.
74  */
75 #define see_with_infrared(mon)                        \
76     (!Blind && Infravision && mon && infravisible(mon->data) \
77      && couldsee(mon->mx, mon->my))
78
79 /*
80  * canseemon()
81  *
82  * This is the globally used canseemon().  It is not called within the display
83  * routines.  Like mon_visible(), but it checks to see if the hero sees the
84  * location instead of assuming it.  (And also considers worms.)
85  */
86 #define canseemon(mon)                                                    \
87     ((mon->wormno ? worm_known(mon)                                       \
88                   : (cansee(mon->mx, mon->my) || see_with_infrared(mon))) \
89      && mon_visible(mon))
90
91 /*
92  * canspotmon(mon)
93  *
94  * This function checks whether you can either see a monster or sense it by
95  * telepathy, and is what you usually call for monsters about which nothing is
96  * known.
97  */
98 #define canspotmon(mon) (canseemon(mon) || sensemon(mon))
99
100 /* knowninvisible(mon)
101  * This one checks to see if you know a monster is both there and invisible.
102  * 1) If you can see the monster and have see invisible, it is assumed the
103  * monster is transparent, but visible in some manner.  (Earlier versions of
104  * Nethack were really inconsistent on this.)
105  * 2) If you can't see the monster, but can see its location and you have
106  * telepathy that works when you can see, you can tell that there is a
107  * creature in an apparently empty spot.
108  * Infravision is not relevant; we assume that invisible monsters are also
109  * invisible to infravision.
110  */
111 #define knowninvisible(mon)                                               \
112     (mtmp->minvis                                                         \
113      && ((cansee(mon->mx, mon->my) && (See_invisible || Detect_monsters)) \
114          || (!Blind && (HTelepat & ~INTRINSIC)                            \
115              && distu(mon->mx, mon->my) <= (BOLT_LIM * BOLT_LIM))))
116
117 /*
118  * is_safepet(mon)
119  *
120  * A special case check used in attack() and domove().  Placing the
121  * definition here is convenient.
122  */
123 #define is_safepet(mon)                                                   \
124     (mon && mon->mtame && canspotmon(mon) && flags.safe_dog && !Confusion \
125      && !Hallucination && !Stunned)
126
127 /*
128  * canseeself()
129  * senseself()
130  * canspotself()
131  *
132  * This returns true if the hero can see her/himself.
133  *
134  * Sensing yourself by touch is treated as seeing yourself, even if
135  * unable to see.  So when blind, being invisible won't affect your
136  * self-perception, and when swallowed, the enclosing monster touches.
137  */
138 #define canseeself() (Blind || u.uswallow || (!Invisible && !u.uundetected))
139 #define senseself() (Unblind_telepat || Detect_monsters)
140 #define canspotself() (canseeself() || senseself())
141
142 /*
143  * random_monster()
144  * random_object()
145  * random_trap()
146  *
147  * Respectively return a random monster, object, or trap number.
148  */
149 #define random_monster(rng) rng(NUMMONS)
150 #define random_object(rng) (rng(NUM_OBJECTS - 1) + 1)
151 #define random_trap(rng) (rng(TRAPNUM - 1) + 1)
152
153 /*
154  * what_obj()
155  * what_mon()
156  * what_trap()
157  *
158  * If hallucinating, choose a random object/monster, otherwise, use the one
159  * given. Use the given rng to handle hallucination.
160  */
161 #define what_obj(obj, rng) (Hallucination ? random_object(rng) : obj)
162 #define what_mon(mon, rng) (Hallucination ? random_monster(rng) : mon)
163 #define what_trap(trp, rng) (Hallucination ? random_trap(rng) : trp)
164
165 /*
166  * newsym_rn2
167  *
168  * An appropriate random number generator for use with newsym(), when
169  * randomness is needed there. This is currently hardcoded as
170  * rn2_on_display_rng, but is futureproofed for cases where we might
171  * want to prevent display-random objects entering the character's
172  * memory (this isn't important at present but may be if we need
173  * reproducible gameplay for some reason).
174  */
175 #define newsym_rn2 rn2_on_display_rng
176
177 /*
178  * covers_objects()
179  * covers_traps()
180  *
181  * These routines are true if what is really at the given location will
182  * "cover" any objects or traps that might be there.
183  */
184 #define covers_objects(xx, yy) \
185     ((is_pool(xx, yy) && !Underwater) || (levl[xx][yy].typ == LAVAPOOL))
186
187 #define covers_traps(xx, yy) covers_objects(xx, yy)
188
189 /*
190  * tmp_at() control calls.
191  */
192 #define DISP_BEAM    (-1) /* Keep all glyphs showing & clean up at end. */
193 #define DISP_ALL     (-2) /* Like beam, but still displayed if not visible. */
194 #define DISP_TETHER  (-3) /* Like beam, but tether glyph differs from final */
195 #define DISP_FLASH   (-4) /* Clean up each glyph before displaying new one. */
196 #define DISP_ALWAYS  (-5) /* Like flash, but still displayed if not visible. */
197 #define DISP_CHANGE  (-6) /* Change glyph. */
198 #define DISP_END     (-7) /* Clean up. */
199 #define DISP_FREEMEM (-8) /* Free all memory during exit only. */
200
201 /* Total number of cmap indices in the shield_static[] array. */
202 #define SHIELD_COUNT 21
203 #define BACKTRACK (-1)    /* flag for DISP_END to display each prior location */
204
205 /*
206  * display_self()
207  *
208  * Display the hero.  It is assumed that all checks necessary to determine
209  * _if_ the hero can be seen have already been done.
210  */
211 #define maybe_display_usteed(otherwise_self)                            \
212     ((u.usteed && mon_visible(u.usteed))                                \
213      ? ridden_mon_to_glyph(u.usteed, rn2_on_display_rng)                \
214      : (otherwise_self))
215
216 #define display_self() \
217     show_glyph(u.ux, u.uy,                                                  \
218            maybe_display_usteed((U_AP_TYPE == M_AP_NOTHING)                 \
219                                 ? hero_glyph                                \
220                                 : (U_AP_TYPE == M_AP_FURNITURE)             \
221                                   ? cmap_to_glyph(youmonst.mappearance)     \
222                                   : (U_AP_TYPE == M_AP_OBJECT)              \
223                                     ? objnum_to_glyph(youmonst.mappearance) \
224                                     /* else U_AP_TYPE == M_AP_MONSTER */    \
225                                     : monnum_to_glyph(youmonst.mappearance)))
226
227 /*
228  * A glyph is an abstraction that represents a _unique_ monster, object,
229  * dungeon part, or effect.  The uniqueness is important.  For example,
230  * It is not enough to have four (one for each "direction") zap beam glyphs,
231  * we need a set of four for each beam type.  Why go to so much trouble?
232  * Because it is possible that any given window dependent display driver
233  * [print_glyph()] can produce something different for each type of glyph.
234  * That is, a beam of cold and a beam of fire would not only be different
235  * colors, but would also be represented by different symbols.
236  *
237  * Glyphs are grouped for easy accessibility:
238  *
239  * monster      Represents all the wild (not tame) monsters.  Count: NUMMONS.
240  *
241  * pet          Represents all of the tame monsters.  Count: NUMMONS
242  *
243  * invisible    Invisible monster placeholder.  Count: 1
244  *
245  * detect       Represents all detected monsters.  Count: NUMMONS
246  *
247  * corpse       One for each monster.  Count: NUMMONS
248  *
249  * ridden       Represents all monsters being ridden.  Count: NUMMONS
250  *
251  * object       One for each object.  Count: NUM_OBJECTS
252  *
253  * cmap         One for each entry in the character map.  The character map
254  *              is the dungeon features and other miscellaneous things.
255  *              Count: MAXPCHARS
256  *
257  * explosions   A set of nine for each of the following seven explosion types:
258  *                   dark, noxious, muddy, wet, magical, fiery, frosty.
259  *              The nine positions represent those surrounding the hero.
260  *              Count: MAXEXPCHARS * EXPL_MAX (EXPL_MAX is defined in hack.h)
261  *
262  * zap beam     A set of four (there are four directions) for each beam type.
263  *              The beam type is shifted over 2 positions and the direction
264  *              is stored in the lower 2 bits.  Count: NUM_ZAP << 2
265  *
266  * swallow      A set of eight for each monster.  The eight positions rep-
267  *              resent those surrounding the hero.  The monster number is
268  *              shifted over 3 positions and the swallow position is stored
269  *              in the lower three bits.  Count: NUMMONS << 3
270  *
271  * warning      A set of six representing the different warning levels.
272  *
273  * statue       One for each monster.  Count: NUMMONS
274  *
275  * The following are offsets used to convert to and from a glyph.
276  */
277 #define NUM_ZAP 8 /* number of zap beam types */
278
279 #define GLYPH_MON_OFF     0
280 #define GLYPH_PET_OFF     (NUMMONS + GLYPH_MON_OFF)
281 #define GLYPH_INVIS_OFF   (NUMMONS + GLYPH_PET_OFF)
282 #define GLYPH_DETECT_OFF  (1 + GLYPH_INVIS_OFF)
283 #define GLYPH_BODY_OFF    (NUMMONS + GLYPH_DETECT_OFF)
284 #define GLYPH_RIDDEN_OFF  (NUMMONS + GLYPH_BODY_OFF)
285 #define GLYPH_OBJ_OFF     (NUMMONS + GLYPH_RIDDEN_OFF)
286 #define GLYPH_CMAP_OFF    (NUM_OBJECTS + GLYPH_OBJ_OFF)
287 #define GLYPH_EXPLODE_OFF ((MAXPCHARS - MAXEXPCHARS) + GLYPH_CMAP_OFF)
288 #define GLYPH_ZAP_OFF     ((MAXEXPCHARS * EXPL_MAX) + GLYPH_EXPLODE_OFF)
289 #define GLYPH_SWALLOW_OFF ((NUM_ZAP << 2) + GLYPH_ZAP_OFF)
290 #define GLYPH_WARNING_OFF ((NUMMONS << 3) + GLYPH_SWALLOW_OFF)
291 #define GLYPH_STATUE_OFF  (WARNCOUNT + GLYPH_WARNING_OFF)
292 #define MAX_GLYPH         (NUMMONS + GLYPH_STATUE_OFF)
293
294 #define NO_GLYPH          MAX_GLYPH
295 #define GLYPH_INVISIBLE   GLYPH_INVIS_OFF
296
297 #define warning_to_glyph(mwarnlev) ((mwarnlev) + GLYPH_WARNING_OFF)
298 #define mon_to_glyph(mon, rng)                                      \
299     ((int) what_mon(monsndx((mon)->data), rng) + GLYPH_MON_OFF)
300 #define detected_mon_to_glyph(mon, rng)                             \
301     ((int) what_mon(monsndx((mon)->data), rng) + GLYPH_DETECT_OFF)
302 #define ridden_mon_to_glyph(mon, rng)                               \
303     ((int) what_mon(monsndx((mon)->data), rng) + GLYPH_RIDDEN_OFF)
304 #define pet_to_glyph(mon, rng)                                      \
305     ((int) what_mon(monsndx((mon)->data), rng) + GLYPH_PET_OFF)
306
307 /* This has the unfortunate side effect of needing a global variable    */
308 /* to store a result. 'otg_temp' is defined and declared in decl.{ch}.  */
309 #define random_obj_to_glyph(rng)                \
310     ((otg_temp = random_object(rng)) == CORPSE  \
311          ? random_monster(rng) + GLYPH_BODY_OFF \
312          : otg_temp + GLYPH_OBJ_OFF)
313
314 #define obj_to_glyph(obj, rng)                                          \
315     (((obj)->otyp == STATUE)                                            \
316          ? statue_to_glyph(obj, rng)                                    \
317          : Hallucination                                                \
318                ? random_obj_to_glyph(rng)                               \
319                : ((obj)->otyp == CORPSE)                                \
320                      ? (int) (obj)->corpsenm + GLYPH_BODY_OFF           \
321                      : (int) (obj)->otyp + GLYPH_OBJ_OFF)
322
323 /* MRKR: Statues now have glyphs corresponding to the monster they    */
324 /*       represent and look like monsters when you are hallucinating. */
325
326 #define statue_to_glyph(obj, rng)                              \
327     (Hallucination ? random_monster(rng) + GLYPH_MON_OFF       \
328                    : (int) (obj)->corpsenm + GLYPH_STATUE_OFF)
329
330 #define cmap_to_glyph(cmap_idx) ((int) (cmap_idx) + GLYPH_CMAP_OFF)
331 #define explosion_to_glyph(expltype, idx) \
332     ((((expltype) * MAXEXPCHARS) + ((idx) - S_explode1)) + GLYPH_EXPLODE_OFF)
333
334 #define trap_to_glyph(trap, rng)                                \
335     cmap_to_glyph(trap_to_defsym(what_trap((trap)->ttyp, rng)))
336
337 /* Not affected by hallucination.  Gives a generic body for CORPSE */
338 /* MRKR: ...and the generic statue */
339 #define objnum_to_glyph(onum) ((int) (onum) + GLYPH_OBJ_OFF)
340 #define monnum_to_glyph(mnum) ((int) (mnum) + GLYPH_MON_OFF)
341 #define detected_monnum_to_glyph(mnum) ((int) (mnum) + GLYPH_DETECT_OFF)
342 #define ridden_monnum_to_glyph(mnum) ((int) (mnum) + GLYPH_RIDDEN_OFF)
343 #define petnum_to_glyph(mnum) ((int) (mnum) + GLYPH_PET_OFF)
344
345 /* The hero's glyph when seen as a monster.
346  */
347 #define hero_glyph                                                    \
348     monnum_to_glyph((Upolyd || !flags.showrace)                       \
349                         ? u.umonnum                                   \
350                         : (flags.female && urace.femalenum != NON_PM) \
351                               ? urace.femalenum                       \
352                               : urace.malenum)
353
354 /*
355  * Change the given glyph into it's given type.  Note:
356  *      1) Pets, detected, and ridden monsters are animals and are converted
357  *         to the proper monster number.
358  *      2) Bodies are all mapped into the generic CORPSE object
359  *      3) If handed a glyph out of range for the type, these functions
360  *         will return NO_GLYPH (see exception below)
361  *      4) glyph_to_swallow() does not return a showsyms[] index, but an
362  *         offset from the first swallow symbol.  If handed something
363  *         out of range, it will return zero (for lack of anything better
364  *         to return).
365  */
366 #define glyph_to_mon(glyph) \
367     (glyph_is_normal_monster(glyph)                             \
368          ? ((glyph) - GLYPH_MON_OFF)                            \
369          : glyph_is_pet(glyph)                                  \
370                ? ((glyph) - GLYPH_PET_OFF)                      \
371                : glyph_is_detected_monster(glyph)               \
372                      ? ((glyph) - GLYPH_DETECT_OFF)             \
373                      : glyph_is_ridden_monster(glyph)           \
374                            ? ((glyph) - GLYPH_RIDDEN_OFF)       \
375                            : glyph_is_statue(glyph)             \
376                                  ? ((glyph) - GLYPH_STATUE_OFF) \
377                                  : NO_GLYPH)
378 #define glyph_to_obj(glyph) \
379     (glyph_is_body(glyph)                        \
380          ? CORPSE                                \
381          : glyph_is_statue(glyph)                \
382                ? STATUE                          \
383                : glyph_is_normal_object(glyph)   \
384                      ? ((glyph) - GLYPH_OBJ_OFF) \
385                      : NO_GLYPH)
386 #define glyph_to_trap(glyph) \
387     (glyph_is_trap(glyph) ? ((int) defsym_to_trap((glyph) - GLYPH_CMAP_OFF)) \
388                           : NO_GLYPH)
389 #define glyph_to_cmap(glyph) \
390     (glyph_is_cmap(glyph) ? ((glyph) - GLYPH_CMAP_OFF) : NO_GLYPH)
391 #define glyph_to_swallow(glyph) \
392     (glyph_is_swallow(glyph) ? (((glyph) - GLYPH_SWALLOW_OFF) & 0x7) : 0)
393 #define glyph_to_warning(glyph) \
394     (glyph_is_warning(glyph) ? ((glyph) - GLYPH_WARNING_OFF) : NO_GLYPH);
395
396 /*
397  * Return true if the given glyph is what we want.  Note that bodies are
398  * considered objects.
399  */
400 #define glyph_is_monster(glyph)                            \
401     (glyph_is_normal_monster(glyph) || glyph_is_pet(glyph) \
402      || glyph_is_ridden_monster(glyph) || glyph_is_detected_monster(glyph))
403 #define glyph_is_normal_monster(glyph) \
404     ((glyph) >= GLYPH_MON_OFF && (glyph) < (GLYPH_MON_OFF + NUMMONS))
405 #define glyph_is_pet(glyph) \
406     ((glyph) >= GLYPH_PET_OFF && (glyph) < (GLYPH_PET_OFF + NUMMONS))
407 #define glyph_is_body(glyph) \
408     ((glyph) >= GLYPH_BODY_OFF && (glyph) < (GLYPH_BODY_OFF + NUMMONS))
409
410 #define glyph_is_statue(glyph) \
411     ((glyph) >= GLYPH_STATUE_OFF && (glyph) < (GLYPH_STATUE_OFF + NUMMONS))
412
413 #define glyph_is_ridden_monster(glyph) \
414     ((glyph) >= GLYPH_RIDDEN_OFF && (glyph) < (GLYPH_RIDDEN_OFF + NUMMONS))
415 #define glyph_is_detected_monster(glyph) \
416     ((glyph) >= GLYPH_DETECT_OFF && (glyph) < (GLYPH_DETECT_OFF + NUMMONS))
417 #define glyph_is_invisible(glyph) ((glyph) == GLYPH_INVISIBLE)
418 #define glyph_is_normal_object(glyph) \
419     ((glyph) >= GLYPH_OBJ_OFF && (glyph) < (GLYPH_OBJ_OFF + NUM_OBJECTS))
420 #define glyph_is_object(glyph)                               \
421     (glyph_is_normal_object(glyph) || glyph_is_statue(glyph) \
422      || glyph_is_body(glyph))
423 #define glyph_is_trap(glyph)                         \
424     ((glyph) >= (GLYPH_CMAP_OFF + trap_to_defsym(1)) \
425      && (glyph) < (GLYPH_CMAP_OFF + trap_to_defsym(1) + TRAPNUM))
426 #define glyph_is_cmap(glyph) \
427     ((glyph) >= GLYPH_CMAP_OFF && (glyph) < (GLYPH_CMAP_OFF + MAXPCHARS))
428 #define glyph_is_swallow(glyph)   \
429     ((glyph) >= GLYPH_SWALLOW_OFF \
430      && (glyph) < (GLYPH_SWALLOW_OFF + (NUMMONS << 3)))
431 #define glyph_is_warning(glyph)   \
432     ((glyph) >= GLYPH_WARNING_OFF \
433      && (glyph) < (GLYPH_WARNING_OFF + WARNCOUNT))
434
435 #endif /* DISPLAY_H */