Source:NetHack 3.2.0/display.h

From NetHackWiki
Revision as of 08:20, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 3.2.0/display.h moved to Source:NetHack 3.2.0/display.h: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to display.h from the source code of NetHack 3.2.0. To link to a particular line, write [[NetHack 3.2.0/display.h#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

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.    /*	SCCS Id: @(#)display.h	3.2	95/04/23	*/
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 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 && Telepat) ||	/* 2a. hero is blind and telepathic OR      */\
30.   				/* 2b. hero is using a telepathy inducing   */\
31.   				/*	 object and in range		    */\
32.         ((HTelepat & ~INTRINSIC) &&					      \
33.   	(distu(mon->mx, mon->my) <= (BOLT_LIM * BOLT_LIM))))		      \
34.   )
35.   
36.   
37.   /*
38.    * mon_visible()
39.    *
40.    * Returns true if the hero can see the monster.  It is assumed that the
41.    * hero can physically see the location of the monster.  The function
42.    * vobj_at() returns a pointer to an object that the hero can see there.
43.    */
44.   #define mon_visible(mon) (		/* The hero can see the monster	    */\
45.   					/* IF the monster		    */\
46.       (!mon->minvis || See_invisible) &&	/* 1. is not invisible AND	    */\
47.       (!mon->mundetected)	&&		/* 2. not an undetected hider	    */\
48.       (!(mon->mburied || u.uburied))	/* 3. neither you or it is buried   */\
49.   )
50.   
51.   
52.   /*
53.    * canseemon()
54.    *
55.    * This is the globally used canseemon().  It is not called within the display
56.    * routines.  Like mon_visible(), but it checks to see if the hero sees the
57.    * location instead of assuming it.  (And also considers worms.)
58.    */
59.   #define canseemon(mon) ((mon->wormno ? worm_known(mon) : \
60.   	cansee(mon->mx, mon->my)) && mon_visible(mon))
61.   
62.   
63.   /*
64.    * canspotmon(mon)
65.    *
66.    * This function checks whether you can either see a monster or sense it by
67.    * telepathy, and is what you usually call for monsters about which nothing is
68.    * known.
69.    */
70.   #define canspotmon(mon)	\
71.   	(canseemon(mon) || sensemon(mon))
72.   
73.   /*
74.    * is_safepet(mon)
75.    *
76.    * A special case check used in attack() and domove().  Placing the
77.    * definition here is convenient.
78.    */
79.   #define is_safepet(mon)	\
80.   	(mon && mon->mtame && canspotmon(mon) && flags.safe_dog \
81.   		&& !Confusion && !Hallucination && !Stunned)
82.   
83.   
84.   /*
85.    * canseeself()
86.    *
87.    * This returns true if the hero can see her/himself.
88.    *
89.    * The u.uswallow check assumes that you can see yourself even if you are
90.    * invisible.  If not, then we don't need the check.
91.    */
92.   #define canseeself()	(Blind || u.uswallow || (!Invisible && !u.uundetected))
93.   
94.   
95.   /*
96.    * random_monster()
97.    * random_object()
98.    *
99.    * Respectively return a random monster or object number.
100.   */
101.  #define random_monster() rn2(NUMMONS)
102.  #define random_object()  (rn2(NUM_OBJECTS-1) + 1)
103.  
104.  
105.  /*
106.   * what_obj()
107.   * what_mon()
108.   *
109.   * If hallucinating, choose a random object/monster, otherwise, use the one
110.   * given.
111.   */
112.  #define what_obj(obj)	(Hallucination ? random_object()  : obj)
113.  #define what_mon(mon)	(Hallucination ? random_monster() : mon)
114.  
115.  
116.  /*
117.   * covers_objects()
118.   * covers_traps()
119.   *
120.   * These routines are true if what is really at the given location will
121.   * "cover" any objects or traps that might be there.
122.   */
123.  #define covers_objects(xx,yy)						      \
124.      ((is_pool(xx,yy) && !Underwater) || (levl[xx][yy].typ == LAVAPOOL))
125.  
126.  #define covers_traps(xx,yy)	covers_objects(xx,yy)
127.  
128.  
129.  /*
130.   * tmp_at() control calls.
131.   */
132.  #define DISP_BEAM   (-1)  /* Keep all glyphs showing & clean up at end. */
133.  #define DISP_FLASH  (-2)  /* Clean up each glyph before displaying new one. */
134.  #define DISP_ALWAYS (-3)  /* Like flash, but still displayed if not visible. */
135.  #define DISP_CHANGE (-4)  /* Change glyph. */
136.  #define DISP_END    (-5)  /* Clean up. */
137.  
138.  
139.  /* Total number of cmap indices in the sheild_static[] array. */
140.  #define SHIELD_COUNT 21
141.  
142.  
143.  /*
144.   *  display_self()
145.   *
146.   *  Display the hero.  This has degenerated down to this.  Perhaps there is
147.   *  more needed here, but I can't think of any cases.
148.   */
149.  #define display_self()						\
150.      show_glyph(u.ux, u.uy,					\
151.  	u.usym == 0 ? objnum_to_glyph(GOLD_PIECE) :		\
152.  	monnum_to_glyph((Upolyd ? u.umonnum : u.umonster)))
153.  
154.  
155.  /*
156.   * A glyph is an abstraction that represents a _unique_ monster, object,
157.   * dungeon part, or effect.  The uniqueness is important.  For example,
158.   * It is not enough to have four (one for each "direction") zap beam glyphs,
159.   * we need a set of four for each beam type.  Why go to so much trouble?
160.   * Because it is possible that any given window dependent display driver
161.   * [print_glyph()] can produce something different for each type of glyph.
162.   * That is, a beam of cold and a beam of fire would not only be different
163.   * colors, but would also be represented by different symbols.
164.   *
165.   * Glyphs are grouped for easy accessibility:
166.   *
167.   * monster	Represents all the wild (not tame) monsters.  Count: NUMMONS.
168.   *
169.   * pet		Represents all of the tame monsters.  Count: NUMMONS
170.   *
171.   * corpse	One for each monster.  Count: NUMMONS
172.   *
173.   * object	One for each object.  Count: NUM_OBJECTS
174.   *
175.   * cmap		One for each entry in the character map.  The character map
176.   *		is the dungeon features and other miscellaneous things.
177.   *		Count: MAXPCHARS
178.   *
179.   * zap beam	A set of four (there are four directions) for each beam type.
180.   *		The beam type is shifted over 2 positions and the direction
181.   *		is stored in the lower 2 bits.  Count: NUM_ZAP << 2
182.   *
183.   * swallow	A set of eight for each monster.  The eight positions rep-
184.   *		resent those surrounding the hero.  The monster number is
185.   *		shifted over 3 positions and the swallow position is stored
186.   *		in the lower three bits.  Count: NUMMONS << 3
187.   *
188.   * The following are offsets used to convert to and from a glyph.
189.   */
190.  #define NUM_ZAP	8	/* number of zap beam types */
191.  
192.  #define GLYPH_MON_OFF	  0
193.  #define GLYPH_PET_OFF	  (NUMMONS        + GLYPH_MON_OFF)
194.  #define GLYPH_BODY_OFF	  (NUMMONS        + GLYPH_PET_OFF)
195.  #define GLYPH_OBJ_OFF	  (NUMMONS        + GLYPH_BODY_OFF)
196.  #define GLYPH_CMAP_OFF	  (NUM_OBJECTS	  + GLYPH_OBJ_OFF)
197.  #define GLYPH_ZAP_OFF	  (MAXPCHARS      + GLYPH_CMAP_OFF)
198.  #define GLYPH_SWALLOW_OFF ((NUM_ZAP << 2) + GLYPH_ZAP_OFF)
199.  
200.  #define MAX_GLYPH	  ((NUMMONS << 3) + GLYPH_SWALLOW_OFF)
201.  #define NO_GLYPH MAX_GLYPH
202.  
203.  
204.  #define mon_to_glyph(mon) ((int) what_mon(monsndx((mon)->data))+GLYPH_MON_OFF)
205.  #define pet_to_glyph(mon) ((int) what_mon(monsndx((mon)->data))+GLYPH_PET_OFF)
206.  
207.  /* This has the unfortunate side effect of needing a global variable	*/
208.  /* to store a result. 'otg_temp' is defined and declared in decl.{ch}.	*/
209.  #define obj_to_glyph(obj)						      \
210.      (Hallucination ?							      \
211.  	((otg_temp = random_object()) == CORPSE ?			      \
212.  	    random_monster() + GLYPH_BODY_OFF :				      \
213.  	    otg_temp + GLYPH_OBJ_OFF)	:				      \
214.  	((obj)->otyp == CORPSE ?					      \
215.  	    (int) (obj)->corpsenm + GLYPH_BODY_OFF :			      \
216.  	    (int) (obj)->otyp + GLYPH_OBJ_OFF))
217.  
218.  #define cmap_to_glyph(cmap_idx)	((int) (cmap_idx)   + GLYPH_CMAP_OFF)
219.  #define trap_to_glyph(trap) cmap_to_glyph(trap_to_defsym((trap)->ttyp))
220.  
221.  /* Not affected by hallucination.  Gives a generic body for CORPSE */
222.  #define objnum_to_glyph(onum)	((int) (onum) + GLYPH_OBJ_OFF)
223.  #define monnum_to_glyph(mnum)	((int) (mnum) + GLYPH_MON_OFF)
224.  #define petnum_to_glyph(mnum)	((int) (mnum) + GLYPH_PET_OFF)
225.  
226.  
227.  /*
228.   * Change the given glyph into it's given type.  Note:
229.   *	1) Pets are animals and are converted to the proper monster number.
230.   *	2) Bodies are all mapped into the generic CORPSE object
231.   *	3) glyph_to_swallow() does not return a showsyms[] index, but an
232.   *	   offset from the first swallow symbol.
233.   *	4) These functions assume that the glyph type has already been
234.   *	   determined.  That is, you have checked it with a glyph_is_XXXX()
235.   *	   call.
236.   */
237.  #define glyph_to_mon(glyph)	((int) ((glyph) < GLYPH_PET_OFF ?	      \
238.  				glyph - GLYPH_MON_OFF : glyph - GLYPH_PET_OFF))
239.  #define glyph_to_obj(glyph)	((int) ((glyph) < GLYPH_OBJ_OFF ?	      \
240.  				CORPSE : (glyph) - GLYPH_OBJ_OFF))
241.  #define glyph_to_trap(glyph)	((int) defsym_to_trap((glyph) - GLYPH_CMAP_OFF))
242.  #define glyph_to_cmap(glyph)	((int) (glyph) - GLYPH_CMAP_OFF)
243.  #define glyph_to_swallow(glyph) (((glyph) - GLYPH_SWALLOW_OFF) & 0x7)
244.  
245.  /*
246.   * Return true if the given glyph is what we want.  Note that bodies are
247.   * considered objects.
248.   */
249.  #define glyph_is_monster(glyph)						      \
250.      ((glyph) >= GLYPH_MON_OFF && (glyph) < GLYPH_BODY_OFF)
251.  #define glyph_is_pet(glyph)						      \
252.      ((glyph) >= GLYPH_PET_OFF && (glyph) < GLYPH_BODY_OFF)
253.  #define glyph_is_object(glyph)						      \
254.      ((glyph) >= GLYPH_BODY_OFF && (glyph) < GLYPH_CMAP_OFF)
255.  #define glyph_is_trap(glyph)						      \
256.      ((glyph) >= (GLYPH_CMAP_OFF+trap_to_defsym(1)) &&			      \
257.       (glyph) <  (GLYPH_CMAP_OFF+trap_to_defsym(1)+TRAPNUM))
258.  #define glyph_is_cmap(glyph)						      \
259.      ((glyph) >= GLYPH_CMAP_OFF && (glyph) < GLYPH_ZAP_OFF)
260.  #define glyph_is_swallow(glyph) \
261.      ((glyph) >= GLYPH_SWALLOW_OFF && (glyph) < MAX_GLYPH)
262.  
263.  #endif /* DISPLAY_H */