Source:NetHack 5.0.0/include/rm.h
Jump to navigation
Jump to search
Below is the full text to rm.h from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/include/rm.h#line12]], for example.
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. /* NetHack 5.0 rm.h $NHDT-Date: 1745114235 2025/04/19 17:57:15 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.120 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Pasi Kallinen, 2017. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #ifndef RM_H 7. #define RM_H 8. 9. /* 10. * The dungeon presentation graphics code and data structures were rewritten 11. * and generalized for NetHack's release 2 by Eric S. Raymond (eric@snark) 12. * building on Don G Kneller's MS-DOS implementation. See drawing.c for 13. * the code that permits the user to set the contents of the symbol structure. 14. * 15. * The door representation was changed by 16. * Ari Huttunen(ahuttune@niksula.hut.fi). 17. */ 18. 19. /* 20. * TLCORNER TDWALL TRCORNER 21. * +- -+- -+ 22. * | | | 23. * 24. * TRWALL CROSSWALL TLWALL HWALL 25. * | | | 26. * +- -+- -+ --- 27. * | | | 28. * 29. * BLCORNER TUWALL BRCORNER VWALL 30. * | | | | 31. * +- -+- -+ | 32. */ 33. 34. /* 35. * Level location types, values for 'level.locations[x][y].typ'. 36. * 37. * These are different from display symbols and while there is 38. * similarity between the cmap subset of those, there isn't any 39. * one-to-one correspondence between the two encodings. For instance, 40. * the DOOR type has multiple symbols (closed|open|gone); so does the 41. * STAIRS type (down|up). Conversely, DRAWBRIDGE_UP represents the 42. * location of the projected span if the drawbridge were down but 43. * there is no symbol for that; it is displayed as water, ice, lava, or 44. * floor depending on what is at that spot when the bridge is 'closed'. 45. * 46. * [Some debugging code in src/display.c defines array type_names[] 47. * which contains an entry for each of these, so needs to be kept in 48. * sync if any new types are added or existing ones renumbered. The 49. * #terrain command also has a menu choice to display each map spot by 50. * a letter derived from these numeric values and another choice to 51. * display a legend showing the letter-to-type correspondence. If any 52. * types are added, removed, or reordered, that needs to be updated to 53. * keep in synch.] 54. */ 55. enum levl_typ_types { 56. STONE = 0, 57. VWALL = 1, 58. HWALL = 2, 59. TLCORNER = 3, 60. TRCORNER = 4, 61. BLCORNER = 5, 62. BRCORNER = 6, 63. CROSSWALL = 7, /* For pretty mazes and special levels */ 64. TUWALL = 8, 65. TDWALL = 9, 66. TLWALL = 10, 67. TRWALL = 11, 68. DBWALL = 12, 69. TREE = 13, /* KMH */ 70. SDOOR = 14, 71. SCORR = 15, 72. POOL = 16, 73. MOAT = 17, /* pool that doesn't boil, adjust messages */ 74. WATER = 18, 75. DRAWBRIDGE_UP = 19, 76. LAVAPOOL = 20, 77. LAVAWALL = 21, 78. IRONBARS = 22, /* KMH */ 79. DOOR = 23, 80. CORR = 24, 81. ROOM = 25, 82. STAIRS = 26, 83. LADDER = 27, 84. FOUNTAIN = 28, 85. THRONE = 29, 86. SINK = 30, 87. GRAVE = 31, 88. ALTAR = 32, 89. ICE = 33, 90. DRAWBRIDGE_DOWN = 34, 91. AIR = 35, 92. CLOUD = 36, 93. 94. MAX_TYPE = 37, 95. /* for special levels */ 96. MATCH_WALL = 38, 97. 98. /* these aren't levl[][].typ values, they're additional indices 99. into terrain_descr[] for status feedback */ 100. xFLOOR = 39, 101. xGROUND = 40, 102. xOPENDOOR = 41, 103. xSHUTDOOR = 42, 104. xSWAMP = 43, 105. xSUBMERGED = 44, 106. xSEA = 45, 107. xWATERWALL = 46, 108. 109. INVALID_TYPE = 127 110. }; 111. 112. /* 113. * Avoid using the level types in inequalities: 114. * these types are subject to change. 115. * Instead, use one of the macros below. 116. */ 117. #define IS_WALL(typ) ((typ) && (typ) <= DBWALL) 118. #define IS_STWALL(typ) ((typ) <= DBWALL) /* STONE <= (typ) <= DBWALL */ 119. #define IS_OBSTRUCTED(typ) ((typ) < POOL) /* absolutely nonaccessible */ 120. #define IS_SDOOR(typ) ((typ) == SDOOR) 121. #define IS_DOOR(typ) ((typ) == DOOR) 122. #define IS_DOORJOIN(typ) (IS_OBSTRUCTED(typ) || (typ) == IRONBARS) 123. #define IS_TREE(typ) \ 124. ((typ) == TREE || (svl.level.flags.arboreal && (typ) == STONE)) 125. #define ACCESSIBLE(typ) ((typ) >= DOOR) /* good position */ 126. #define IS_ROOM(typ) ((typ) >= ROOM) /* ROOM, STAIRS, furniture.. */ 127. #define ZAP_POS(typ) ((typ) >= POOL) 128. #define SPACE_POS(typ) ((typ) > DOOR) 129. #define IS_POOL(typ) ((typ) >= POOL && (typ) <= DRAWBRIDGE_UP) 130. #define IS_LAVA(typ) ((typ) == LAVAPOOL || (typ) == LAVAWALL) 131. #define IS_THRONE(typ) ((typ) == THRONE) 132. #define IS_FOUNTAIN(typ) ((typ) == FOUNTAIN) 133. #define IS_SINK(typ) ((typ) == SINK) 134. #define IS_GRAVE(typ) ((typ) == GRAVE) 135. #define IS_ALTAR(typ) ((typ) == ALTAR) 136. #define IS_DRAWBRIDGE(typ) \ 137. ((typ) == DRAWBRIDGE_UP || (typ) == DRAWBRIDGE_DOWN) 138. #define IS_FURNITURE(typ) ((typ) >= STAIRS && (typ) <= ALTAR) 139. #define IS_AIR(typ) ((typ) == AIR || (typ) == CLOUD) 140. #define IS_SOFT(typ) ((typ) == AIR || (typ) == CLOUD || IS_POOL(typ)) 141. #define IS_WATERWALL(typ) ((typ) == WATER) 142. /* for surface checks when it's unknown whether a drawbridge is involved; 143. drawbridge_up is the spot in front of a closed drawbridge and not the 144. current surface at that spot; caveat: this evaluates its arguments more 145. than once and might make a function call */ 146. #define SURFACE_AT(x,y) \ 147. ((levl[x][y].typ == DRAWBRIDGE_UP) \ 148. ? db_under_typ(levl[x][y].drawbridgemask) \ 149. : levl[x][y].typ) 150. 151. /* 152. * The structure describing a coordinate position. 153. * Before adding fields, remember that this will significantly affect 154. * the size of temporary files and save files. 155. * 156. * Also remember that the run-length encoding for some ports in save.c 157. * must be updated to consider the field. 158. */ 159. struct rm { 160. int glyph; /* what the hero thinks is there */ 161. schar typ; /* what is really there [why is this signed?] */ 162. uchar seenv; /* seen vector */ 163. Bitfield(flags, 5); /* extra information for typ */ 164. Bitfield(horizontal, 1); /* wall/door/etc is horiz. (more typ info) */ 165. Bitfield(lit, 1); /* speed hack for lit rooms */ 166. Bitfield(waslit, 1); /* remember if a location was lit */ 167. 168. Bitfield(roomno, 6); /* room # for special rooms */ 169. Bitfield(edge, 1); /* marks boundaries for special rooms*/ 170. Bitfield(candig, 1); /* Exception to Can_dig_down; was a trapdoor */ 171. }; 172. 173. /* 174. * rm flags field overloads: 175. * 176. * +-------------+-------------+------------+------------+------------+ 177. * | bit5 | bit4 | bit3 | bit2 | bit1 | 178. * | 0x10 | 0x8 | 0x4 | 0x2 | 0x1 | 179. * +-------------+-------------+------------+------------+------------+ 180. * wall |W_NONPASSWALL|W_NONDIGGABLE| W_MASK | W_MASK | W_MASK | 181. * door |D_TRAPPED | D_LOCKED | D_CLOSED | D_ISOPEN | D_BROKEN | 182. * |D_WARNED | | | | | 183. * sdoor |D_TRAPPED | D_LOCKED | W_MASK | W_MASK | W_MASK | 184. * drawbr. |DB_FLOOR | DB_ICE | DB_LAVA | DB_DIR | DB_DIR | 185. * sink | | | S_LRING | S_LDWASHER | S_LPUDDING | 186. * tree | | | | TREE_SWARM | TREE_LOOTED| 187. * throne | | | | | T_LOOTED | 188. * fountain| | | | F_WARNED | F_LOOTED | 189. * ladder | | | | LA_DOWN | LA_UP | 190. * pool |ICED_MOAT | ICED_POOL | | | | 191. * grave | | | | | emptygrave | 192. * altar |AM_SANCTUM | AM_SHRINE | AM_MASK | AM_MASK | AM_MASK | 193. * | | | | | | 194. * +-------------+-------------+------------+------------+------------+ 195. * 196. * 197. * If these get changed or expanded, make sure wizard-mode wishing becomes 198. * aware of the new usage 199. * 200. * Note: secret doors (SDOOR) want to use both rm.doormask and 201. * rm.wall_info but those both overload rm.flags. SDOOR only 202. * has 2 states (closed or locked). However, it can't specify 203. * D_CLOSED due to that conflicting with WM_MASK (below). When 204. * a secret door is revealed, the door gets set to D_CLOSED iff 205. * it isn't set to D_LOCKED (see cvt_sdoor_to_door() in detect.c). 206. * 207. * D_LOCKED conflicts with W_NONDIGGABLE but the latter is not 208. * expected to be used on door locations. 209. * D_TRAPPED conflicts with W_NONPASSWALL. 210. * D_SECRET would not fit within struct rm's 5-bit 'flags' field. 211. */ 212. 213. #define doormask flags /* door, sdoor (note conflict with wall_info) */ 214. #define altarmask flags /* alignment and maybe temple */ 215. #define wall_info flags /* wall, sdoor (note conflict with doormask) */ 216. #define ladder flags /* up or down */ 217. #define drawbridgemask flags /* what's underneath when the span is open */ 218. #define looted flags /* used for throne, tree, fountain, sink, door */ 219. #define icedpool flags /* used for ice (in case it melts) */ 220. #define emptygrave flags /* no corpse in grave */ 221. 222. /* candig is used for floor trap locations so is available for overload 223. on walls, doors, secret doors, and furniture */ 224. #define arboreal_sdoor candig 225. 226. /* 227. * The 5 possible states of doors. 228. * For historical reasons they are numbered as mask bits rather than 0..4. 229. * The trapped flag is OR'd onto the state and only valid if that state 230. * is closed or locked. 231. * The no-door state allows egress when moving diagonally, others do not. 232. */ 233. #define D_NODOOR 0x00 234. #define D_BROKEN 0x01 235. #define D_ISOPEN 0x02 236. #define D_CLOSED 0x04 237. #define D_LOCKED 0x08 238. 239. #define D_TRAPPED 0x10 240. #define D_SECRET 0x20 /* only used by sp_lev.c, NOT in rm-struct */ 241. 242. /* 243. * Thrones should only be looted once. 244. */ 245. #define T_LOOTED 1 246. 247. /* 248. * Trees have more than one kick result. 249. */ 250. #define TREE_LOOTED 1 251. #define TREE_SWARM 2 252. 253. /* 254. * Fountains have limits, and special warnings. 255. */ 256. #define F_LOOTED 1 257. #define F_WARNED 2 258. #define FOUNTAIN_IS_WARNED(x, y) (levl[x][y].looted & F_WARNED) 259. #define FOUNTAIN_IS_LOOTED(x, y) (levl[x][y].looted & F_LOOTED) 260. #define SET_FOUNTAIN_WARNED(x, y) levl[x][y].looted |= F_WARNED; 261. #define SET_FOUNTAIN_LOOTED(x, y) levl[x][y].looted |= F_LOOTED; 262. #define CLEAR_FOUNTAIN_WARNED(x, y) levl[x][y].looted &= ~F_WARNED; 263. #define CLEAR_FOUNTAIN_LOOTED(x, y) levl[x][y].looted &= ~F_LOOTED; 264. 265. /* 266. * doors are even worse :-) The special warning has a side effect 267. * of instantly trapping the door, and if it was defined as trapped, 268. * the guards consider that you have already been warned! 269. */ 270. #define D_WARNED 16 271. 272. /* 273. * Sinks have 3 different types of loot that shouldn't be abused 274. */ 275. #define S_LPUDDING 1 276. #define S_LDWASHER 2 277. #define S_LRING 4 278. 279. /* 280. * The four directions for a DrawBridge. 281. */ 282. #define DB_NORTH 0 283. #define DB_SOUTH 1 284. #define DB_EAST 2 285. #define DB_WEST 3 286. #define DB_DIR 3 /* mask for direction */ 287. 288. /* 289. * What's under a drawbridge. 290. */ 291. #define DB_MOAT 0 292. #define DB_LAVA 4 293. #define DB_ICE 8 294. #define DB_FLOOR 16 295. #define DB_UNDER 28 /* mask for underneath */ 296. 297. /* 298. * Wall information. Nondiggable also applies to iron bars. 299. */ 300. #define WM_MASK 0x07 /* wall mode (bottom three bits) */ 301. #define W_NONDIGGABLE 0x08 302. #define W_NONPASSWALL 0x10 303. 304. /* 305. * Ladders (in Vlad's tower) may be up or down. 306. */ 307. #define LA_UP 1 308. #define LA_DOWN 2 309. 310. /* 311. * Room areas may be iced pools 312. */ 313. #define ICED_POOL 8 314. #define ICED_MOAT 16 315. 316. /* light states for terrain replacements, for set_levltyp_lit */ 317. #define SET_LIT_RANDOM -1 318. #define SET_LIT_NOCHANGE -2 319. 320. #define CAN_OVERWRITE_TERRAIN(ttyp) \ 321. (iflags.debug_overwrite_stairs || !((ttyp) == LADDER || (ttyp) == STAIRS)) 322. 323. /* 324. * Add wall angle viewing by defining "modes" for each wall type. Each 325. * mode describes which parts of a wall are finished (seen as wall) 326. * and which are unfinished (seen as rock). 327. * 328. * We use the bottom 3 bits of the flags field for the mode. This comes 329. * in conflict with secret doors, but we avoid problems because until 330. * a secret door becomes discovered, we know what sdoor's bottom three 331. * bits are. 332. * 333. * The following should cover all of the cases. 334. * 335. * type mode Examples: R=rock, F=finished 336. * ----- ---- ---------------------------- 337. * WALL: 0 none hwall, mode 1 338. * 1 left/top (1/2 rock) RRR 339. * 2 right/bottom (1/2 rock) --- 340. * FFF 341. * 342. * CORNER: 0 none trcorn, mode 2 343. * 1 outer (3/4 rock) FFF 344. * 2 inner (1/4 rock) F+- 345. * F|R 346. * 347. * TWALL: 0 none tlwall, mode 3 348. * 1 long edge (1/2 rock) F|F 349. * 2 bottom left (on a tdwall) -+F 350. * 3 bottom right (on a tdwall) R|F 351. * 352. * CRWALL: 0 none crwall, mode 5 353. * 1 top left (1/4 rock) R|F 354. * 2 top right (1/4 rock) -+- 355. * 3 bottom left (1/4 rock) F|R 356. * 4 bottom right (1/4 rock) 357. * 5 top left & bottom right (1/2 rock) 358. * 6 bottom left & top right (1/2 rock) 359. */ 360. 361. #define WM_W_LEFT 1 /* vertical or horizontal wall */ 362. #define WM_W_RIGHT 2 363. #define WM_W_TOP WM_W_LEFT 364. #define WM_W_BOTTOM WM_W_RIGHT 365. 366. #define WM_C_OUTER 1 /* corner wall */ 367. #define WM_C_INNER 2 368. 369. #define WM_T_LONG 1 /* T wall */ 370. #define WM_T_BL 2 371. #define WM_T_BR 3 372. 373. #define WM_X_TL 1 /* cross wall */ 374. #define WM_X_TR 2 375. #define WM_X_BL 3 376. #define WM_X_BR 4 377. #define WM_X_TLBR 5 378. #define WM_X_BLTR 6 379. 380. /* 381. * Seen vector values. The seen vector is an array of 8 bits, one for each 382. * octant around a given center x: 383. * 384. * 0 1 2 385. * 7 x 3 386. * 6 5 4 387. * 388. * In the case of walls, a single wall square can be viewed from 8 possible 389. * directions. If we know the type of wall and the directions from which 390. * it has been seen, then we can determine what it looks like to the hero. 391. */ 392. #define SV0 ((seenV) 0x01) 393. #define SV1 ((seenV) 0x02) 394. #define SV2 ((seenV) 0x04) 395. #define SV3 ((seenV) 0x08) 396. #define SV4 ((seenV) 0x10) 397. #define SV5 ((seenV) 0x20) 398. #define SV6 ((seenV) 0x40) 399. #define SV7 ((seenV) 0x80) 400. #define SVALL ((seenV) 0xFF) 401. 402. /* horizontal applies to walls, doors (including sdoor); also to iron bars 403. even though they don't have separate symbols for horizontal and vertical */ 404. #define blessedftn horizontal /* a fountain that grants attribs */ 405. #define disturbed horizontal /* kicking or engraving on a grave's headstone 406. * has summoned a ghoul */ 407. 408. struct damage { 409. struct damage *next; 410. long when, cost; 411. coord place; 412. schar typ; /* from struct rm */ 413. uchar flags; /* also from struct rm; an unsigned 5-bit field there */ 414. }; 415. 416. /* for bones levels: identify the dead character, who might have died on 417. an existing bones level; if so, most recent victim will be first in list */ 418. struct cemetery { 419. struct cemetery *next; /* next struct is previous dead character... */ 420. /* "svp.plname" + "-ROLe" + "-RACe" + "-GENder" + "-ALIgnment" + \0 */ 421. char who[PL_NSIZ + 4 * (1 + 3) + 1]; 422. /* death reason, same as in score/log file */ 423. char how[100 + 1]; /* [DTHSZ+1] */ 424. /* date+time in string of digits rather than binary */ 425. char when[4 + 2 + 2 + 2 + 2 + 2 + 1]; /* "YYYYMMDDhhmmss\0" */ 426. /* final resting place spot */ 427. coordxy frpx, frpy; 428. boolean bonesknown; 429. }; 430. 431. struct levelflags { 432. uchar nfountains; /* number of fountains on level */ 433. uchar nsinks; /* number of sinks on the level */ 434. /* Several flags that give hints about what's on the level */ 435. Bitfield(has_shop, 1); 436. Bitfield(has_vault, 1); 437. Bitfield(has_zoo, 1); 438. Bitfield(has_court, 1); 439. Bitfield(has_morgue, 1); 440. Bitfield(has_beehive, 1); 441. Bitfield(has_barracks, 1); 442. Bitfield(has_temple, 1); 443. 444. Bitfield(has_swamp, 1); 445. Bitfield(noteleport, 1); 446. Bitfield(hardfloor, 1); 447. Bitfield(nommap, 1); 448. Bitfield(hero_memory, 1); /* hero has memory */ 449. Bitfield(shortsighted, 1); /* monsters are shortsighted */ 450. Bitfield(graveyard, 1); /* has_morgue, but remains set */ 451. Bitfield(sokoban_rules, 1); /* fill pits and holes w/ boulders */ 452. 453. Bitfield(is_maze_lev, 1); 454. Bitfield(is_cavernous_lev, 1); 455. Bitfield(arboreal, 1); /* Trees replace rock */ 456. Bitfield(has_town, 1); /* level contains a town */ 457. Bitfield(wizard_bones, 1); /* set if level came from a bones file 458. * which was created in wizard mode (or 459. * normal mode descendant of such) */ 460. Bitfield(corrmaze, 1); /* Whether corridors are used for the maze 461. * rather than ROOM */ 462. Bitfield(rndmongen, 1); /* random monster generation allowed? */ 463. Bitfield(deathdrops, 1); /* monsters may drop corpses/death drops */ 464. 465. Bitfield(noautosearch, 1); /* automatic searching disabled */ 466. Bitfield(fumaroles, 1); /* lava emits poison gas at random */ 467. Bitfield(stormy, 1); /* clouds create lightning bolts at random */ 468. 469. schar temperature; /* +1 == hot, -1 == cold */ 470. long stasis_until; /* wand of stasis effect lasts until when? */ 471. }; 472. 473. typedef struct { 474. struct rm locations[COLNO][ROWNO]; 475. struct obj *objects[COLNO][ROWNO]; 476. struct monst *monsters[COLNO][ROWNO]; 477. struct obj *objlist; 478. struct obj *buriedobjlist; 479. struct monst *monlist; 480. struct damage *damagelist; 481. struct cemetery *bonesinfo; 482. struct levelflags flags; 483. } dlevel_t; 484. 485. /* 486. * Macros for compatibility with old code. Someday these will go away. 487. */ 488. #define levl svl.level.locations 489. #define fobj svl.level.objlist 490. #define fmon svl.level.monlist 491. 492. /* 493. * Convert a trap number into the defsym graphics array. 494. * Convert a defsym number into a trap number. 495. * Assumes that arrow trap will always be the first trap. 496. */ 497. #define trap_to_defsym(t) (S_arrow_trap + (t) - 1) 498. #define defsym_to_trap(d) ((d) - S_arrow_trap + 1) 499. 500. #define OBJ_AT(x, y) (svl.level.objects[x][y] != (struct obj *) 0) 501. /* 502. * Macros for encapsulation of level.monsters references. 503. */ 504. #if 0 505. /* these wouldn't allow buried monster and surface monster at same location */ 506. #define MON_AT(x, y) \ 507. (svl.level.monsters[x][y] && !svl.level.monsters[x][y]->mburied) 508. #define MON_BURIED_AT(x, y) \ 509. (svl.level.monsters[x][y] && svl.level.monsters[x][y]->mburied) 510. #define m_at(x, y) \ 511. (MON_AT(x, y) ? svl.level.monsters[x][y] : (struct monst *) 0) 512. #define m_buried_at(x, y) \ 513. (MON_BURIED_AT(x, y) ? svl.level.monsters[x][y] : (struct monst *) 0) 514. #else /* without 'mburied' */ 515. #define MON_AT(x, y) (svl.level.monsters[x][y] != (struct monst *) 0) 516. #define m_at(x, y) (svl.level.monsters[x][y]) 517. #define m_buried_at(x, y) ((struct monst *) 0) 518. #endif 519. #ifdef EXTRA_SANITY_CHECKS 520. #define place_worm_seg(m, x, y) \ 521. do { \ 522. if (svl.level.monsters[x][y] && svl.level.monsters[x][y] != m) \ 523. impossible("place_worm_seg over mon"); \ 524. svl.level.monsters[x][y] = m; \ 525. } while(0) 526. #define remove_monster(x, y) \ 527. do { \ 528. if (!svl.level.monsters[x][y]) \ 529. impossible("no monster to remove"); \ 530. svl.level.monsters[x][y] = (struct monst *) 0; \ 531. } while(0) 532. #else 533. #define place_worm_seg(m, x, y) svl.level.monsters[x][y] = m 534. #define remove_monster(x, y) svl.level.monsters[x][y] = (struct monst *) 0 535. #endif 536. 537. /* restricted movement, potential luck penalties */ 538. #define Sokoban svl.level.flags.sokoban_rules 539. 540. /* 541. * These prototypes are in extern.h but some of the code which uses them 542. * includes config.h instead of hack.h so doesn't see extern.h. 543. */ 544. /* ### drawing.c ### */ 545. extern int def_char_to_objclass(char); 546. extern int def_char_to_monclass(char); 547. extern int def_char_is_furniture(char); 548. 549. #endif /* RM_H */