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