dumplog's saved_plines[]
[aNetHack.git] / include / display.h
blob4bd8cf924766c7c9bd6bf90d139c6924cd03f057
1 /* NetHack 3.6 display.h $NHDT-Date: 1447729027 2015/11/17 02:57:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.26 $ */
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. */
6 #ifndef DISPLAY_H
7 #define DISPLAY_H
9 #ifndef VISION_H
10 #include "vision.h"
11 #endif
12 #ifndef MONDATA_H
13 #include "mondata.h" /* for mindless() */
14 #endif
17 * vobj_at()
19 * Returns the head of the list of objects that the player can see
20 * at location (x,y).
22 #define vobj_at(x, y) (level.objects[x][y])
25 * sensemon()
27 * Returns true if the hero can sense the given monster. This includes
28 * monsters that are hiding or mimicing other monsters.
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)))))
41 #define sensemon(mon) \
42 (tp_sensemon(mon) || Detect_monsters || MATCH_WARN_OF_MON(mon))
45 * mon_warning() is used to warn of any dangerous monsters in your
46 * vicinity, and a glyph representing the warning level is displayed.
49 #define mon_warning(mon) \
50 (Warning && !(mon)->mpeaceful && (distu((mon)->mx, (mon)->my) < 100) \
51 && (((int) ((mon)->m_lev / 4)) >= context.warnlevel))
54 * mon_visible()
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.
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 */
68 * see_with_infrared()
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.
75 #define see_with_infrared(mon) \
76 (!Blind && Infravision && mon && infravisible(mon->data) \
77 && couldsee(mon->mx, mon->my))
80 * canseemon()
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.)
86 #define canseemon(mon) \
87 ((mon->wormno ? worm_known(mon) \
88 : (cansee(mon->mx, mon->my) || see_with_infrared(mon))) \
89 && mon_visible(mon))
92 * canspotmon(mon)
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.
98 #define canspotmon(mon) (canseemon(mon) || sensemon(mon))
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.
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))))
118 * is_safepet(mon)
120 * A special case check used in attack() and domove(). Placing the
121 * definition here is convenient.
123 #define is_safepet(mon) \
124 (mon && mon->mtame && canspotmon(mon) && flags.safe_dog && !Confusion \
125 && !Hallucination && !Stunned)
128 * canseeself()
129 * senseself()
130 * canspotself()
132 * This returns true if the hero can see her/himself.
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.
138 #define canseeself() (Blind || u.uswallow || (!Invisible && !u.uundetected))
139 #define senseself() (Unblind_telepat || Detect_monsters)
140 #define canspotself() (canseeself() || senseself())
143 * random_monster()
144 * random_object()
145 * random_trap()
147 * Respectively return a random monster, object, or trap number.
149 #define random_monster() rn2(NUMMONS)
150 #define random_object() rn1(NUM_OBJECTS - 1, 1)
151 #define random_trap() rn1(TRAPNUM - 1, 1)
154 * what_obj()
155 * what_mon()
156 * what_trap()
158 * If hallucinating, choose a random object/monster, otherwise, use the one
159 * given.
161 #define what_obj(obj) (Hallucination ? random_object() : obj)
162 #define what_mon(mon) (Hallucination ? random_monster() : mon)
163 #define what_trap(trp) (Hallucination ? random_trap() : trp)
166 * covers_objects()
167 * covers_traps()
169 * These routines are true if what is really at the given location will
170 * "cover" any objects or traps that might be there.
172 #define covers_objects(xx, yy) \
173 ((is_pool(xx, yy) && !Underwater) || (levl[xx][yy].typ == LAVAPOOL))
175 #define covers_traps(xx, yy) covers_objects(xx, yy)
178 * tmp_at() control calls.
180 #define DISP_BEAM (-1) /* Keep all glyphs showing & clean up at end. */
181 #define DISP_ALL (-2) /* Like beam, but still displayed if not visible. */
182 #define DISP_FLASH (-3) /* Clean up each glyph before displaying new one. */
183 #define DISP_ALWAYS (-4) /* Like flash, but still displayed if not visible. */
184 #define DISP_CHANGE (-5) /* Change glyph. */
185 #define DISP_END (-6) /* Clean up. */
186 #define DISP_FREEMEM (-7) /* Free all memory during exit only. */
188 /* Total number of cmap indices in the shield_static[] array. */
189 #define SHIELD_COUNT 21
192 * display_self()
194 * Display the hero. It is assumed that all checks necessary to determine
195 * _if_ the hero can be seen have already been done.
197 #define maybe_display_usteed(otherwise_self) \
198 ((u.usteed && mon_visible(u.usteed)) ? ridden_mon_to_glyph(u.usteed) \
199 : (otherwise_self))
201 #define display_self() \
202 show_glyph(u.ux, u.uy, \
203 maybe_display_usteed((youmonst.m_ap_type == M_AP_NOTHING) \
204 ? hero_glyph \
205 : (youmonst.m_ap_type == M_AP_FURNITURE) \
206 ? cmap_to_glyph(youmonst.mappearance) \
207 : (youmonst.m_ap_type == M_AP_OBJECT) \
208 ? objnum_to_glyph(youmonst.mappearance) \
209 /* else M_AP_MONSTER */ \
210 : monnum_to_glyph(youmonst.mappearance)))
213 * A glyph is an abstraction that represents a _unique_ monster, object,
214 * dungeon part, or effect. The uniqueness is important. For example,
215 * It is not enough to have four (one for each "direction") zap beam glyphs,
216 * we need a set of four for each beam type. Why go to so much trouble?
217 * Because it is possible that any given window dependent display driver
218 * [print_glyph()] can produce something different for each type of glyph.
219 * That is, a beam of cold and a beam of fire would not only be different
220 * colors, but would also be represented by different symbols.
222 * Glyphs are grouped for easy accessibility:
224 * monster Represents all the wild (not tame) monsters. Count: NUMMONS.
226 * pet Represents all of the tame monsters. Count: NUMMONS
228 * invisible Invisible monster placeholder. Count: 1
230 * detect Represents all detected monsters. Count: NUMMONS
232 * corpse One for each monster. Count: NUMMONS
234 * ridden Represents all monsters being ridden. Count: NUMMONS
236 * object One for each object. Count: NUM_OBJECTS
238 * cmap One for each entry in the character map. The character map
239 * is the dungeon features and other miscellaneous things.
240 * Count: MAXPCHARS
242 * explosions A set of nine for each of the following seven explosion types:
243 * dark, noxious, muddy, wet, magical, fiery, frosty.
244 * The nine positions represent those surrounding the hero.
245 * Count: MAXEXPCHARS * EXPL_MAX (EXPL_MAX is defined in hack.h)
247 * zap beam A set of four (there are four directions) for each beam type.
248 * The beam type is shifted over 2 positions and the direction
249 * is stored in the lower 2 bits. Count: NUM_ZAP << 2
251 * swallow A set of eight for each monster. The eight positions rep-
252 * resent those surrounding the hero. The monster number is
253 * shifted over 3 positions and the swallow position is stored
254 * in the lower three bits. Count: NUMMONS << 3
256 * warning A set of six representing the different warning levels.
258 * The following are offsets used to convert to and from a glyph.
260 #define NUM_ZAP 8 /* number of zap beam types */
262 #define GLYPH_MON_OFF 0
263 #define GLYPH_PET_OFF (NUMMONS + GLYPH_MON_OFF)
264 #define GLYPH_INVIS_OFF (NUMMONS + GLYPH_PET_OFF)
265 #define GLYPH_DETECT_OFF (1 + GLYPH_INVIS_OFF)
266 #define GLYPH_BODY_OFF (NUMMONS + GLYPH_DETECT_OFF)
267 #define GLYPH_RIDDEN_OFF (NUMMONS + GLYPH_BODY_OFF)
268 #define GLYPH_OBJ_OFF (NUMMONS + GLYPH_RIDDEN_OFF)
269 #define GLYPH_CMAP_OFF (NUM_OBJECTS + GLYPH_OBJ_OFF)
270 #define GLYPH_EXPLODE_OFF ((MAXPCHARS - MAXEXPCHARS) + GLYPH_CMAP_OFF)
271 #define GLYPH_ZAP_OFF ((MAXEXPCHARS * EXPL_MAX) + GLYPH_EXPLODE_OFF)
272 #define GLYPH_SWALLOW_OFF ((NUM_ZAP << 2) + GLYPH_ZAP_OFF)
273 #define GLYPH_WARNING_OFF ((NUMMONS << 3) + GLYPH_SWALLOW_OFF)
274 #define GLYPH_STATUE_OFF (WARNCOUNT + GLYPH_WARNING_OFF)
275 #define MAX_GLYPH (NUMMONS + GLYPH_STATUE_OFF)
277 #define NO_GLYPH MAX_GLYPH
278 #define GLYPH_INVISIBLE GLYPH_INVIS_OFF
280 #define warning_to_glyph(mwarnlev) ((mwarnlev) + GLYPH_WARNING_OFF)
281 #define mon_to_glyph(mon) \
282 ((int) what_mon(monsndx((mon)->data)) + GLYPH_MON_OFF)
283 #define detected_mon_to_glyph(mon) \
284 ((int) what_mon(monsndx((mon)->data)) + GLYPH_DETECT_OFF)
285 #define ridden_mon_to_glyph(mon) \
286 ((int) what_mon(monsndx((mon)->data)) + GLYPH_RIDDEN_OFF)
287 #define pet_to_glyph(mon) \
288 ((int) what_mon(monsndx((mon)->data)) + GLYPH_PET_OFF)
290 /* This has the unfortunate side effect of needing a global variable */
291 /* to store a result. 'otg_temp' is defined and declared in decl.{ch}. */
292 #define random_obj_to_glyph() \
293 ((otg_temp = random_object()) == CORPSE \
294 ? random_monster() + GLYPH_BODY_OFF \
295 : otg_temp + GLYPH_OBJ_OFF)
297 #define obj_to_glyph(obj) \
298 (((obj)->otyp == STATUE) \
299 ? statue_to_glyph(obj) \
300 : Hallucination \
301 ? random_obj_to_glyph() \
302 : ((obj)->otyp == CORPSE) \
303 ? (int) (obj)->corpsenm + GLYPH_BODY_OFF \
304 : (int) (obj)->otyp + GLYPH_OBJ_OFF)
306 /* MRKR: Statues now have glyphs corresponding to the monster they */
307 /* represent and look like monsters when you are hallucinating. */
309 #define statue_to_glyph(obj) \
310 (Hallucination ? random_monster() + GLYPH_MON_OFF \
311 : (int) (obj)->corpsenm + GLYPH_STATUE_OFF)
313 #define cmap_to_glyph(cmap_idx) ((int) (cmap_idx) + GLYPH_CMAP_OFF)
314 #define explosion_to_glyph(expltype, idx) \
315 ((((expltype) * MAXEXPCHARS) + ((idx) - S_explode1)) + GLYPH_EXPLODE_OFF)
317 #define trap_to_glyph(trap) \
318 cmap_to_glyph(trap_to_defsym(what_trap((trap)->ttyp)))
320 /* Not affected by hallucination. Gives a generic body for CORPSE */
321 /* MRKR: ...and the generic statue */
322 #define objnum_to_glyph(onum) ((int) (onum) + GLYPH_OBJ_OFF)
323 #define monnum_to_glyph(mnum) ((int) (mnum) + GLYPH_MON_OFF)
324 #define detected_monnum_to_glyph(mnum) ((int) (mnum) + GLYPH_DETECT_OFF)
325 #define ridden_monnum_to_glyph(mnum) ((int) (mnum) + GLYPH_RIDDEN_OFF)
326 #define petnum_to_glyph(mnum) ((int) (mnum) + GLYPH_PET_OFF)
328 /* The hero's glyph when seen as a monster.
330 #define hero_glyph \
331 monnum_to_glyph((Upolyd || !flags.showrace) \
332 ? u.umonnum \
333 : (flags.female && urace.femalenum != NON_PM) \
334 ? urace.femalenum \
335 : urace.malenum)
338 * Change the given glyph into it's given type. Note:
339 * 1) Pets, detected, and ridden monsters are animals and are converted
340 * to the proper monster number.
341 * 2) Bodies are all mapped into the generic CORPSE object
342 * 3) If handed a glyph out of range for the type, these functions
343 * will return NO_GLYPH (see exception below)
344 * 4) glyph_to_swallow() does not return a showsyms[] index, but an
345 * offset from the first swallow symbol. If handed something
346 * out of range, it will return zero (for lack of anything better
347 * to return).
349 #define glyph_to_mon(glyph) \
350 (glyph_is_normal_monster(glyph) \
351 ? ((glyph) - GLYPH_MON_OFF) \
352 : glyph_is_pet(glyph) \
353 ? ((glyph) - GLYPH_PET_OFF) \
354 : glyph_is_detected_monster(glyph) \
355 ? ((glyph) - GLYPH_DETECT_OFF) \
356 : glyph_is_ridden_monster(glyph) \
357 ? ((glyph) - GLYPH_RIDDEN_OFF) \
358 : glyph_is_statue(glyph) \
359 ? ((glyph) - GLYPH_STATUE_OFF) \
360 : NO_GLYPH)
361 #define glyph_to_obj(glyph) \
362 (glyph_is_body(glyph) \
363 ? CORPSE \
364 : glyph_is_statue(glyph) \
365 ? STATUE \
366 : glyph_is_normal_object(glyph) \
367 ? ((glyph) - GLYPH_OBJ_OFF) \
368 : NO_GLYPH)
369 #define glyph_to_trap(glyph) \
370 (glyph_is_trap(glyph) ? ((int) defsym_to_trap((glyph) - GLYPH_CMAP_OFF)) \
371 : NO_GLYPH)
372 #define glyph_to_cmap(glyph) \
373 (glyph_is_cmap(glyph) ? ((glyph) - GLYPH_CMAP_OFF) : NO_GLYPH)
374 #define glyph_to_swallow(glyph) \
375 (glyph_is_swallow(glyph) ? (((glyph) - GLYPH_SWALLOW_OFF) & 0x7) : 0)
376 #define glyph_to_warning(glyph) \
377 (glyph_is_warning(glyph) ? ((glyph) - GLYPH_WARNING_OFF) : NO_GLYPH);
380 * Return true if the given glyph is what we want. Note that bodies are
381 * considered objects.
383 #define glyph_is_monster(glyph) \
384 (glyph_is_normal_monster(glyph) || glyph_is_pet(glyph) \
385 || glyph_is_ridden_monster(glyph) || glyph_is_detected_monster(glyph))
386 #define glyph_is_normal_monster(glyph) \
387 ((glyph) >= GLYPH_MON_OFF && (glyph) < (GLYPH_MON_OFF + NUMMONS))
388 #define glyph_is_pet(glyph) \
389 ((glyph) >= GLYPH_PET_OFF && (glyph) < (GLYPH_PET_OFF + NUMMONS))
390 #define glyph_is_body(glyph) \
391 ((glyph) >= GLYPH_BODY_OFF && (glyph) < (GLYPH_BODY_OFF + NUMMONS))
393 #define glyph_is_statue(glyph) \
394 ((glyph) >= GLYPH_STATUE_OFF && (glyph) < (GLYPH_STATUE_OFF + NUMMONS))
396 #define glyph_is_ridden_monster(glyph) \
397 ((glyph) >= GLYPH_RIDDEN_OFF && (glyph) < (GLYPH_RIDDEN_OFF + NUMMONS))
398 #define glyph_is_detected_monster(glyph) \
399 ((glyph) >= GLYPH_DETECT_OFF && (glyph) < (GLYPH_DETECT_OFF + NUMMONS))
400 #define glyph_is_invisible(glyph) ((glyph) == GLYPH_INVISIBLE)
401 #define glyph_is_normal_object(glyph) \
402 ((glyph) >= GLYPH_OBJ_OFF && (glyph) < (GLYPH_OBJ_OFF + NUM_OBJECTS))
403 #define glyph_is_object(glyph) \
404 (glyph_is_normal_object(glyph) || glyph_is_statue(glyph) \
405 || glyph_is_body(glyph))
406 #define glyph_is_trap(glyph) \
407 ((glyph) >= (GLYPH_CMAP_OFF + trap_to_defsym(1)) \
408 && (glyph) < (GLYPH_CMAP_OFF + trap_to_defsym(1) + TRAPNUM))
409 #define glyph_is_cmap(glyph) \
410 ((glyph) >= GLYPH_CMAP_OFF && (glyph) < (GLYPH_CMAP_OFF + MAXPCHARS))
411 #define glyph_is_swallow(glyph) \
412 ((glyph) >= GLYPH_SWALLOW_OFF \
413 && (glyph) < (GLYPH_SWALLOW_OFF + (NUMMONS << 3)))
414 #define glyph_is_warning(glyph) \
415 ((glyph) >= GLYPH_WARNING_OFF \
416 && (glyph) < (GLYPH_WARNING_OFF + WARNCOUNT))
418 #endif /* DISPLAY_H */