Source:NetHack 3.4.3/src/mapglyph.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to src/mapglyph.c from NetHack 3.4.3. To link to a particular line, write [[mapglyph.c#line123]], for example.

Top of file[edit]

  1. /*	SCCS Id: @(#)mapglyph.c	3.4	2003/01/08	*/
  2. /* Copyright (c) David Cohrs, 1991				  */
  3. /* NetHack may be freely redistributed.  See license for details. */

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. #include "hack.h"
  2. #if defined(TTY_GRAPHICS)
  3. #include "wintty.h"	/* for prototype of has_color() only */
  4. #endif
  5. #include "color.h"
  6. #define HI_DOMESTIC CLR_WHITE	/* monst.c */
  7.  
  8. int explcolors[] = {
  9. 	CLR_BLACK,	/* dark    */
  10. 	CLR_GREEN,	/* noxious */
  11. 	CLR_BROWN,	/* muddy   */
  12. 	CLR_BLUE,	/* wet     */
  13. 	CLR_MAGENTA,	/* magical */
  14. 	CLR_ORANGE,	/* fiery   */
  15. 	CLR_WHITE,	/* frosty  */
  16. };
  17.  
  18. #if !defined(TTY_GRAPHICS)
  19. #define has_color(n)  TRUE
  20. #endif
  21.  
  22. #ifdef TEXTCOLOR
  23. #define zap_color(n)  color = iflags.use_color ? zapcolors[n] : NO_COLOR
  24. #define cmap_color(n) color = iflags.use_color ? defsyms[n].color : NO_COLOR
  25. #define obj_color(n)  color = iflags.use_color ? objects[n].oc_color : NO_COLOR
  26. #define mon_color(n)  color = iflags.use_color ? mons[n].mcolor : NO_COLOR
  27. #define invis_color(n) color = NO_COLOR
  28. #define pet_color(n)  color = iflags.use_color ? mons[n].mcolor : NO_COLOR
  29. #define warn_color(n) color = iflags.use_color ? def_warnsyms[n].color : NO_COLOR
  30. #define explode_color(n) color = iflags.use_color ? explcolors[n] : NO_COLOR
  31. # if defined(REINCARNATION) && defined(ASCIIGRAPH)
  32. #  define ROGUE_COLOR
  33. # endif
  34.  
  35. #else	/* no text color */
  36.  
  37. #define zap_color(n)
  38. #define cmap_color(n)
  39. #define obj_color(n)
  40. #define mon_color(n)
  41. #define invis_color(n)
  42. #define pet_color(c)
  43. #define warn_color(n)
  44. #define explode_color(n)
  45. #endif
  46.  
  47. #ifdef ROGUE_COLOR
  48. # if defined(USE_TILES) && defined(MSDOS)
  49. #define HAS_ROGUE_IBM_GRAPHICS (iflags.IBMgraphics && !iflags.grmode && \
  50. 	Is_rogue_level(&u.uz))
  51. # else
  52. #define HAS_ROGUE_IBM_GRAPHICS (iflags.IBMgraphics && Is_rogue_level(&u.uz))
  53. # endif
  54. #endif

mapglyph[edit]

  1. /*ARGSUSED*/
  2. void
  3. mapglyph(glyph, ochar, ocolor, ospecial, x, y)
  4. int glyph, *ocolor, x, y;
  5. int *ochar;
  6. unsigned *ospecial;
  7. {
  8. 	register int offset;
  9. #if defined(TEXTCOLOR) || defined(ROGUE_COLOR)
  10. 	int color = NO_COLOR;
  11. #endif
  12. 	uchar ch;
  13. 	unsigned special = 0;
  14.  
  15. /*
  16. *  Map the glyph back to a character and color.
  17. *
  18. *  Warning:  For speed, this makes an assumption on the order of
  19. *		  offsets.  The order is set in display.h.
  20. */
  21. if ((offset = (glyph - GLYPH_WARNING_OFF)) >= 0) {	/* a warning flash */
  22. 	ch = warnsyms[offset];
  23. # ifdef ROGUE_COLOR
  24. 	if (HAS_ROGUE_IBM_GRAPHICS)
  25. 	    color = NO_COLOR;
  26. 	else
  27. # endif
  28. 	    warn_color(offset);
  29. } else if ((offset = (glyph - GLYPH_SWALLOW_OFF)) >= 0) {	/* swallow */
  30. 	/* see swallow_to_glyph() in display.c */
  31. 	ch = (uchar) showsyms[S_sw_tl + (offset & 0x7)];
  32. #ifdef ROGUE_COLOR
  33. 	if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color)
  34. 	    color = NO_COLOR;
  35. 	else
  36. #endif
  37. 	    mon_color(offset >> 3);
  38. } else if ((offset = (glyph - GLYPH_ZAP_OFF)) >= 0) {	/* zap beam */
  39. 	/* see zapdir_to_glyph() in display.c */
  40. 	ch = showsyms[S_vbeam + (offset & 0x3)];
  41. #ifdef ROGUE_COLOR
  42. 	if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color)
  43. 	    color = NO_COLOR;
  44. 	else
  45. #endif
  46. 	    zap_color((offset >> 2));
  47. } else if ((offset = (glyph - GLYPH_EXPLODE_OFF)) >= 0) {	/* explosion */
  48. 	ch = showsyms[(offset % MAXEXPCHARS) + S_explode1];
  49. 	explode_color(offset / MAXEXPCHARS);
  50. } else if ((offset = (glyph - GLYPH_CMAP_OFF)) >= 0) {	/* cmap */
  51. 	ch = showsyms[offset];
  52. #ifdef ROGUE_COLOR
  53. 	if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) {
  54. 	    if (offset >= S_vwall && offset <= S_hcdoor)
  55. 		color = CLR_BROWN;
  56. 	    else if (offset >= S_arrow_trap && offset <= S_polymorph_trap)
  57. 		color = CLR_MAGENTA;
  58. 	    else if (offset == S_corr || offset == S_litcorr)
  59. 		color = CLR_GRAY;
  60. 	    else if (offset >= S_room && offset <= S_water)
  61. 		color = CLR_GREEN;
  62. 	    else
  63. 		color = NO_COLOR;
  64. 	} else
  65. #endif
  66. #ifdef TEXTCOLOR
  67. 	    /* provide a visible difference if normal and lit corridor
  68. 	     * use the same symbol */
  69. 	    if (iflags.use_color &&
  70. 		offset == S_litcorr && ch == showsyms[S_corr])
  71. 		color = CLR_WHITE;
  72. 	    else
  73. #endif
  74. 	    cmap_color(offset);
  75. } else if ((offset = (glyph - GLYPH_OBJ_OFF)) >= 0) {	/* object */
  76. 	if (offset == BOULDER && iflags.bouldersym) ch = iflags.bouldersym;
  77. 	else ch = oc_syms[(int)objects[offset].oc_class];
  78. #ifdef ROGUE_COLOR
  79. 	if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) {
  80. 	    switch(objects[offset].oc_class) {
  81. 		case COIN_CLASS: color = CLR_YELLOW; break;
  82. 		case FOOD_CLASS: color = CLR_RED; break;
  83. 		default: color = CLR_BRIGHT_BLUE; break;
  84. 	    }
  85. 	} else
  86. #endif
  87. 	    obj_color(offset);
  88. } else if ((offset = (glyph - GLYPH_RIDDEN_OFF)) >= 0) {	/* mon ridden */
  89. 	ch = monsyms[(int)mons[offset].mlet];
  90. #ifdef ROGUE_COLOR
  91. 	if (HAS_ROGUE_IBM_GRAPHICS)
  92. 	    /* This currently implies that the hero is here -- monsters */
  93. 	    /* don't ride (yet...).  Should we set it to yellow like in */
  94. 	    /* the monster case below?  There is no equivalent in rogue. */
  95. 	    color = NO_COLOR;	/* no need to check iflags.use_color */
  96. 	else
  97. #endif
  98. 	    mon_color(offset);
  99. 	    special |= MG_RIDDEN;
  100. } else if ((offset = (glyph - GLYPH_BODY_OFF)) >= 0) {	/* a corpse */
  101. 	ch = oc_syms[(int)objects[CORPSE].oc_class];
  102. #ifdef ROGUE_COLOR
  103. 	if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color)
  104. 	    color = CLR_RED;
  105. 	else
  106. #endif
  107. 	    mon_color(offset);
  108. 	    special |= MG_CORPSE;
  109. } else if ((offset = (glyph - GLYPH_DETECT_OFF)) >= 0) {	/* mon detect */
  110. 	ch = monsyms[(int)mons[offset].mlet];
  111. #ifdef ROGUE_COLOR
  112. 	if (HAS_ROGUE_IBM_GRAPHICS)
  113. 	    color = NO_COLOR;	/* no need to check iflags.use_color */
  114. 	else
  115. #endif
  116. 	    mon_color(offset);
  117. 	/* Disabled for now; anyone want to get reverse video to work? */
  118. 	/* is_reverse = TRUE; */
  119. 	    special |= MG_DETECT;
  120. } else if ((offset = (glyph - GLYPH_INVIS_OFF)) >= 0) {	/* invisible */
  121. 	ch = DEF_INVISIBLE;
  122. #ifdef ROGUE_COLOR
  123. 	if (HAS_ROGUE_IBM_GRAPHICS)
  124. 	    color = NO_COLOR;	/* no need to check iflags.use_color */
  125. 	else
  126. #endif
  127. 	    invis_color(offset);
  128. 	    special |= MG_INVIS;
  129. } else if ((offset = (glyph - GLYPH_PET_OFF)) >= 0) {	/* a pet */
  130. 	ch = monsyms[(int)mons[offset].mlet];
  131. #ifdef ROGUE_COLOR
  132. 	if (HAS_ROGUE_IBM_GRAPHICS)
  133. 	    color = NO_COLOR;	/* no need to check iflags.use_color */
  134. 	else
  135. #endif
  136. 	    pet_color(offset);
  137. 	    special |= MG_PET;
  138. } else {							/* a monster */
  139. 	ch = monsyms[(int)mons[glyph].mlet];
  140. #ifdef ROGUE_COLOR
  141. 	if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) {
  142. 	    if (x == u.ux && y == u.uy)
  143. 		/* actually player should be yellow-on-gray if in a corridor */
  144. 		color = CLR_YELLOW;
  145. 	    else
  146. 		color = NO_COLOR;
  147. 	} else
  148. #endif
  149. 	{
  150. 	    mon_color(glyph);
  151. 	    /* special case the hero for `showrace' option */
  152. #ifdef TEXTCOLOR
  153. 	    if (iflags.use_color && x == u.ux && y == u.uy &&
  154. 		    iflags.showrace && !Upolyd)
  155. 		color = HI_DOMESTIC;
  156. #endif
  157. 	}
  158. }
  159.  
  160. #ifdef TEXTCOLOR
  161. /* Turn off color if no color defined, or rogue level w/o PC graphics. */
  162. # ifdef REINCARNATION
  163. #  ifdef ASCIIGRAPH
  164. if (!has_color(color) || (Is_rogue_level(&u.uz) && !HAS_ROGUE_IBM_GRAPHICS))
  165. #  else
  166. if (!has_color(color) || Is_rogue_level(&u.uz))
  167. #  endif
  168. # else
  169. if (!has_color(color))
  170. # endif
  171. 	color = NO_COLOR;
  172. #endif
  173.  
  174. *ochar = (int)ch;
  175. *ospecial = special;
  176. #ifdef TEXTCOLOR
  177. *ocolor = color;
  178. #endif
  179. return;
  180. }
  181.  
  182. /*mapglyph.c*/