Wikia

Wikihack

Source:SLASH'EM 0.0.7E7F2/display.h

2,032pages on
this wiki
Talk0

Below is the full text to display.h from the source code of SLASH'EM 0.0.7E7F2. To link to a particular line, write [[SLASH'EM 0.0.7E7F2/display.h#line123]], for example.

The latest source code for vanilla NetHack is at Source code.


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

Around Wikia's network

Random Wiki