Source:NetHack 3.4.0/mapglyph.c
Jump to navigation
Jump to search
Below is the full text to mapglyph.c from the source code of NetHack 3.4.0. To link to a particular line, write [[NetHack 3.4.0/mapglyph.c#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: @(#)mapglyph.c 3.4 2000/08/18 */ 2. /* Copyright (c) David Cohrs, 1991 */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. #if defined(TTY_GRAPHICS) 7. #include "wintty.h" /* for prototype of has_color() only */ 8. #endif 9. #include "color.h" 10. 11. int explcolors[] = { 12. CLR_BLACK, /* dark */ 13. CLR_GREEN, /* noxious */ 14. CLR_BROWN, /* muddy */ 15. CLR_BLUE, /* wet */ 16. CLR_MAGENTA, /* magical */ 17. CLR_ORANGE, /* fiery */ 18. CLR_WHITE, /* frosty */ 19. }; 20. 21. #if !defined(TTY_GRAPHICS) 22. #define has_color(n) TRUE 23. #endif 24. 25. #ifdef TEXTCOLOR 26. #define zap_color(n) color = iflags.use_color ? zapcolors[n] : NO_COLOR 27. #define cmap_color(n) color = iflags.use_color ? defsyms[n].color : NO_COLOR 28. #define obj_color(n) color = iflags.use_color ? objects[n].oc_color : NO_COLOR 29. #define mon_color(n) color = iflags.use_color ? mons[n].mcolor : NO_COLOR 30. #define invis_color(n) color = NO_COLOR 31. #define pet_color(n) color = iflags.use_color ? mons[n].mcolor : NO_COLOR 32. #define warn_color(n) color = iflags.use_color ? def_warnsyms[n].color : NO_COLOR 33. #define explode_color(n) color = iflags.use_color ? explcolors[n] : NO_COLOR 34. # if defined(REINCARNATION) && defined(ASCIIGRAPH) 35. # define ROGUE_COLOR 36. # endif 37. 38. #else /* no text color */ 39. 40. #define zap_color(n) 41. #define cmap_color(n) 42. #define obj_color(n) 43. #define mon_color(n) 44. #define invis_color(n) 45. #define pet_color(c) 46. #define warn_color(n) 47. #define explode_color(n) 48. #endif 49. 50. #ifdef ROGUE_COLOR 51. # if defined(USE_TILES) && defined(MSDOS) 52. #define HAS_ROGUE_IBM_GRAPHICS (iflags.IBMgraphics && !iflags.grmode && \ 53. Is_rogue_level(&u.uz)) 54. # else 55. #define HAS_ROGUE_IBM_GRAPHICS (iflags.IBMgraphics && Is_rogue_level(&u.uz)) 56. # endif 57. #endif 58. 59. /*ARGSUSED*/ 60. void 61. mapglyph(glyph, ochar, ocolor, ospecial, x, y) 62. int glyph, *ocolor, x, y; 63. int *ochar; 64. unsigned *ospecial; 65. { 66. register int offset; 67. int color = NO_COLOR; 68. uchar ch; 69. unsigned special = 0; 70. 71. /* 72. * Map the glyph back to a character and color. 73. * 74. * Warning: For speed, this makes an assumption on the order of 75. * offsets. The order is set in display.h. 76. */ 77. if ((offset = (glyph - GLYPH_WARNING_OFF)) >= 0) { /* a warning flash */ 78. ch = warnsyms[offset]; 79. # ifdef ROGUE_COLOR 80. if (HAS_ROGUE_IBM_GRAPHICS) 81. color = NO_COLOR; 82. else 83. # endif 84. warn_color(offset); 85. } else if ((offset = (glyph - GLYPH_SWALLOW_OFF)) >= 0) { /* swallow */ 86. /* see swallow_to_glyph() in display.c */ 87. ch = (uchar) showsyms[S_sw_tl + (offset & 0x7)]; 88. #ifdef ROGUE_COLOR 89. if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) 90. color = NO_COLOR; 91. else 92. #endif 93. mon_color(offset >> 3); 94. } else if ((offset = (glyph - GLYPH_ZAP_OFF)) >= 0) { /* zap beam */ 95. /* see zapdir_to_glyph() in display.c */ 96. ch = showsyms[S_vbeam + (offset & 0x3)]; 97. #ifdef ROGUE_COLOR 98. if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) 99. color = NO_COLOR; 100. else 101. #endif 102. zap_color((offset >> 2)); 103. } else if ((offset = (glyph - GLYPH_EXPLODE_OFF)) >= 0) { /* explosion */ 104. ch = showsyms[(offset % MAXEXPCHARS) + S_explode1]; 105. explode_color(offset / MAXEXPCHARS); 106. } else if ((offset = (glyph - GLYPH_CMAP_OFF)) >= 0) { /* cmap */ 107. ch = showsyms[offset]; 108. #ifdef ROGUE_COLOR 109. if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) { 110. if (offset >= S_vwall && offset <= S_hcdoor) 111. color = CLR_BROWN; 112. else if (offset >= S_arrow_trap && offset <= S_polymorph_trap) 113. color = CLR_MAGENTA; 114. else if (offset == S_corr || offset == S_litcorr) 115. color = CLR_GRAY; 116. else if (offset >= S_room && offset <= S_water) 117. color = CLR_GREEN; 118. else 119. color = NO_COLOR; 120. } else 121. #endif 122. cmap_color(offset); 123. } else if ((offset = (glyph - GLYPH_OBJ_OFF)) >= 0) { /* object */ 124. if (offset == BOULDER && iflags.bouldersym) ch = iflags.bouldersym; 125. else ch = oc_syms[(int)objects[offset].oc_class]; 126. #ifdef ROGUE_COLOR 127. if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) { 128. switch(objects[offset].oc_class) { 129. case GOLD_CLASS: color = CLR_YELLOW; break; 130. case FOOD_CLASS: color = CLR_RED; break; 131. default: color = CLR_BRIGHT_BLUE; break; 132. } 133. } else 134. #endif 135. obj_color(offset); 136. } else if ((offset = (glyph - GLYPH_RIDDEN_OFF)) >= 0) { /* mon ridden */ 137. ch = monsyms[(int)mons[offset].mlet]; 138. #ifdef ROGUE_COLOR 139. if (HAS_ROGUE_IBM_GRAPHICS) 140. /* This currently implies that the hero is here -- monsters */ 141. /* don't ride (yet...). Should we set it to yellow like in */ 142. /* the monster case below? There is no equivalent in rogue. */ 143. color = NO_COLOR; /* no need to check iflags.use_color */ 144. else 145. #endif 146. mon_color(offset); 147. special |= MG_RIDDEN; 148. } else if ((offset = (glyph - GLYPH_BODY_OFF)) >= 0) { /* a corpse */ 149. ch = oc_syms[(int)objects[CORPSE].oc_class]; 150. #ifdef ROGUE_COLOR 151. if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) 152. color = CLR_RED; 153. else 154. #endif 155. mon_color(offset); 156. special |= MG_CORPSE; 157. } else if ((offset = (glyph - GLYPH_DETECT_OFF)) >= 0) { /* mon detect */ 158. ch = monsyms[(int)mons[offset].mlet]; 159. #ifdef ROGUE_COLOR 160. if (HAS_ROGUE_IBM_GRAPHICS) 161. color = NO_COLOR; /* no need to check iflags.use_color */ 162. else 163. #endif 164. mon_color(offset); 165. /* Disabled for now; anyone want to get reverse video to work? */ 166. /* is_reverse = TRUE; */ 167. special |= MG_DETECT; 168. } else if ((offset = (glyph - GLYPH_INVIS_OFF)) >= 0) { /* invisible */ 169. ch = DEF_INVISIBLE; 170. #ifdef ROGUE_COLOR 171. if (HAS_ROGUE_IBM_GRAPHICS) 172. color = NO_COLOR; /* no need to check iflags.use_color */ 173. else 174. #endif 175. invis_color(offset); 176. special |= MG_INVIS; 177. } else if ((offset = (glyph - GLYPH_PET_OFF)) >= 0) { /* a pet */ 178. ch = monsyms[(int)mons[offset].mlet]; 179. #ifdef ROGUE_COLOR 180. if (HAS_ROGUE_IBM_GRAPHICS) 181. color = NO_COLOR; /* no need to check iflags.use_color */ 182. else 183. #endif 184. pet_color(offset); 185. special |= MG_PET; 186. } else { /* a monster */ 187. ch = monsyms[(int)mons[glyph].mlet]; 188. #ifdef ROGUE_COLOR 189. if (HAS_ROGUE_IBM_GRAPHICS && iflags.use_color) { 190. if (x == u.ux && y == u.uy) 191. /* actually player should be yellow-on-gray if in a corridor */ 192. color = CLR_YELLOW; 193. else 194. color = NO_COLOR; 195. } else 196. #endif 197. mon_color(glyph); 198. } 199. 200. #ifdef TEXTCOLOR 201. /* Turn off color if no color defined, or rogue level w/o PC graphics. */ 202. # ifdef REINCARNATION 203. # ifdef ASCIIGRAPH 204. if (!has_color(color) || (Is_rogue_level(&u.uz) && !HAS_ROGUE_IBM_GRAPHICS)) 205. # else 206. if (!has_color(color) || Is_rogue_level(&u.uz)) 207. # endif 208. # else 209. if (!has_color(color)) 210. # endif 211. color = NO_COLOR; 212. #endif 213. if (ochar) 214. *ochar = (int)ch; 215. else 216. impossible("glyphmap(): Invalid output character buffer."); 217. 218. if (ospecial) 219. *ospecial = special; 220. else 221. impossible("glyphmap(): Invalid special feature return buffer."); 222. 223. #ifdef TEXTCOLOR 224. if (ocolor) 225. *ocolor = color; 226. else 227. impossible("glyphmap(): Invalid color buffer."); 228. #endif 229. return; 230. } 231. 232. /*mapglyph.c*/