NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / include / rm.h
blobfd77034c2dfd7c1231db0ba213d0a554826708c2
1 /* aNetHack 0.0.1 rm.h $ANH-Date: 1432512776 2015/05/25 00:12:56 $ $ANH-Branch: master $:$ANH-Revision: 1.41 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* aNetHack may be freely redistributed. See license for details. */
5 #ifndef RM_H
6 #define RM_H
8 /*
9 * The dungeon presentation graphics code and data structures were rewritten
10 * and generalized for aNetHack's release 2 by Eric S. Raymond (eric@snark)
11 * building on Don G. Kneller's MS-DOS implementation. See drawing.c for
12 * the code that permits the user to set the contents of the symbol structure.
14 * The door representation was changed by Ari
15 * Huttunen(ahuttune@niksula.hut.fi)
19 * TLCORNER TDWALL TRCORNER
20 * +- -+- -+
21 * | | |
23 * TRWALL CROSSWALL TLWALL HWALL
24 * | | |
25 * +- -+- -+ ---
26 * | | |
28 * BLCORNER TUWALL BRCORNER VWALL
29 * | | | |
30 * +- -+- -+ |
33 /* Level location types. [Some debugging code in src/display.c
34 defines array type_names[] which contains an entry for each of
35 these, so needs to be kept in sync if any new types are added
36 or existing ones renumbered.] */
37 enum levl_typ_types {
38 STONE = 0,
39 VWALL,
40 HWALL,
41 TLCORNER,
42 TRCORNER,
43 BLCORNER,
44 BRCORNER,
45 CROSSWALL, /* For pretty mazes and special levels */
46 TUWALL,
47 TDWALL,
48 TLWALL,
49 TRWALL,
50 DBWALL,
51 TREE, /* KMH */
52 SDOOR,
53 SCORR,
54 POOL,
55 MOAT, /* pool that doesn't boil, adjust messages */
56 WATER,
57 DRAWBRIDGE_UP,
58 LAVAPOOL,
59 IRONBARS, /* KMH */
60 DOOR,
61 CORR,
62 ROOM,
63 STAIRS,
64 LADDER,
65 FOUNTAIN,
66 THRONE,
67 SINK,
68 GRAVE,
69 ALTAR,
70 ICE,
71 DRAWBRIDGE_DOWN,
72 AIR,
73 CLOUD,
75 MAX_TYPE,
76 INVALID_TYPE = 127
80 * Avoid using the level types in inequalities:
81 * these types are subject to change.
82 * Instead, use one of the macros below.
84 #define IS_WALL(typ) ((typ) && (typ) <= DBWALL)
85 #define IS_STWALL(typ) ((typ) <= DBWALL) /* STONE <= (typ) <= DBWALL */
86 #define IS_ROCK(typ) ((typ) < POOL) /* absolutely nonaccessible */
87 #define IS_DOOR(typ) ((typ) == DOOR)
88 #define IS_TREE(typ) \
89 ((typ) == TREE || (level.flags.arboreal && (typ) == STONE))
90 #define ACCESSIBLE(typ) ((typ) >= DOOR) /* good position */
91 #define IS_ROOM(typ) ((typ) >= ROOM) /* ROOM, STAIRS, furniture.. */
92 #define ZAP_POS(typ) ((typ) >= POOL)
93 #define SPACE_POS(typ) ((typ) > DOOR)
94 #define IS_POOL(typ) ((typ) >= POOL && (typ) <= DRAWBRIDGE_UP)
95 #define IS_THRONE(typ) ((typ) == THRONE)
96 #define IS_FOUNTAIN(typ) ((typ) == FOUNTAIN)
97 #define IS_SINK(typ) ((typ) == SINK)
98 #define IS_GRAVE(typ) ((typ) == GRAVE)
99 #define IS_ALTAR(typ) ((typ) == ALTAR)
100 #define IS_DRAWBRIDGE(typ) \
101 ((typ) == DRAWBRIDGE_UP || (typ) == DRAWBRIDGE_DOWN)
102 #define IS_FURNITURE(typ) ((typ) >= STAIRS && (typ) <= ALTAR)
103 #define IS_AIR(typ) ((typ) == AIR || (typ) == CLOUD)
104 #define IS_SOFT(typ) ((typ) == AIR || (typ) == CLOUD || IS_POOL(typ))
107 * The screen symbols may be the default or defined at game startup time.
108 * See drawing.c for defaults.
109 * Note: {ibm|dec}_graphics[] arrays (also in drawing.c) must be kept in
110 * synch.
113 /* begin dungeon characters */
114 enum screen_symbols {
115 S_stone = 0,
116 S_vwall,
117 S_hwall,
118 S_tlcorn,
119 S_trcorn,
120 S_blcorn,
121 S_brcorn,
122 S_crwall,
123 S_tuwall,
124 S_tdwall,
125 S_tlwall,
126 S_trwall,
127 S_ndoor,
128 S_vodoor,
129 S_hodoor,
130 S_vcdoor, /* closed door, vertical wall */
131 S_hcdoor, /* closed door, horizontal wall */
132 S_bars, /* KMH -- iron bars */
133 S_tree, /* KMH */
134 S_room,
135 S_darkroom,
136 S_corr,
137 S_litcorr,
138 S_upstair,
139 S_dnstair,
140 S_upladder,
141 S_dnladder,
142 S_altar,
143 S_grave,
144 S_throne,
145 S_sink,
146 S_fountain,
147 S_pool,
148 S_ice,
149 S_lava,
150 S_vodbridge,
151 S_hodbridge,
152 S_vcdbridge, /* closed drawbridge, vertical wall */
153 S_hcdbridge, /* closed drawbridge, horizontal wall */
154 S_air,
155 S_cloud,
156 S_water,
158 /* end dungeon characters, begin traps */
160 S_arrow_trap,
161 S_dart_trap,
162 S_falling_rock_trap,
163 S_squeaky_board,
164 S_bear_trap,
165 S_land_mine,
166 S_rolling_boulder_trap,
167 S_sleeping_gas_trap,
168 S_rust_trap,
169 S_fire_trap,
170 S_pit,
171 S_spiked_pit,
172 S_hole,
173 S_trap_door,
174 S_teleportation_trap,
175 S_level_teleporter,
176 S_magic_portal,
177 S_web,
178 S_statue_trap,
179 S_magic_trap,
180 S_anti_magic_trap,
181 S_polymorph_trap,
182 S_vibrating_square,
184 /* end traps, begin special effects */
186 S_vbeam, /* The 4 zap beam symbols. Do NOT separate. */
187 S_hbeam, /* To change order or add, see function */
188 S_lslant, /* zapdir_to_glyph() in display.c. */
189 S_rslant,
190 S_digbeam, /* dig beam symbol */
191 S_flashbeam, /* camera flash symbol */
192 S_boomleft, /* thrown boomerang, open left, e.g ')' */
193 S_boomright, /* thrown boomerang, open right, e.g. '(' */
194 S_ss1, /* 4 magic shield glyphs */
195 S_ss2,
196 S_ss3,
197 S_ss4,
198 S_poisoncloud,
199 S_goodpos, /* valid position for targeting */
201 /* The 8 swallow symbols. Do NOT separate. To change order or add, see */
202 /* the function swallow_to_glyph() in display.c. */
203 S_sw_tl, /* swallow top left [1] */
204 S_sw_tc, /* swallow top center [2] Order: */
205 S_sw_tr, /* swallow top right [3] */
206 S_sw_ml, /* swallow middle left [4] 1 2 3 */
207 S_sw_mr, /* swallow middle right [6] 4 5 6 */
208 S_sw_bl, /* swallow bottom left [7] 7 8 9 */
209 S_sw_bc, /* swallow bottom center [8] */
210 S_sw_br, /* swallow bottom right [9] */
212 S_explode1, /* explosion top left */
213 S_explode2, /* explosion top center */
214 S_explode3, /* explosion top right Ex. */
215 S_explode4, /* explosion middle left */
216 S_explode5, /* explosion middle center /-\ */
217 S_explode6, /* explosion middle right |@| */
218 S_explode7, /* explosion bottom left \-/ */
219 S_explode8, /* explosion bottom center */
220 S_explode9, /* explosion bottom right */
222 /* end effects */
224 MAXPCHARS /* maximum number of mapped characters */
227 #define MAXDCHARS (S_water - S_stone + 1) /* maximum of mapped dungeon characters */
228 #define MAXTCHARS (S_vibrating_square - S_arrow_trap + 1) /* maximum of mapped trap characters */
229 #define MAXECHARS (S_explode9 - S_vbeam + 1) /* maximum of mapped effects characters */
230 #define MAXEXPCHARS 9 /* number of explosion characters */
232 #define DARKROOMSYM (Is_rogue_level(&u.uz) ? S_stone : S_darkroom)
234 #define is_cmap_trap(i) ((i) >= S_arrow_trap && (i) <= S_polymorph_trap)
235 #define is_cmap_drawbridge(i) ((i) >= S_vodbridge && (i) <= S_hcdbridge)
236 #define is_cmap_door(i) ((i) >= S_vodoor && (i) <= S_hcdoor)
237 #define is_cmap_wall(i) ((i) >= S_stone && (i) <= S_trwall)
239 struct symdef {
240 uchar sym;
241 const char *explanation;
242 #ifdef TEXTCOLOR
243 uchar color;
244 #endif
247 struct symparse {
248 unsigned range;
249 #define SYM_CONTROL 1 /* start/finish markers */
250 #define SYM_PCHAR 2 /* index into showsyms */
251 #define SYM_OC 3 /* index into oc_syms */
252 #define SYM_MON 4 /* index into monsyms */
253 #define SYM_OTH 5 /* misc */
254 int idx;
255 const char *name;
258 /* misc symbol definitions */
259 #define SYM_BOULDER 0
260 #define SYM_INVISIBLE 1
261 #define MAXOTHER 2
263 /* linked list of symsets and their characteristics */
264 struct symsetentry {
265 struct symsetentry *next; /* next in list */
266 char *name; /* ptr to symset name */
267 char *desc; /* ptr to description */
268 int idx; /* an index value */
269 int handling; /* known handlers value */
270 Bitfield(nocolor, 1); /* don't use color if set */
271 Bitfield(primary, 1); /* restricted for use as primary set */
272 Bitfield(rogue, 1); /* restricted for use as rogue lev set */
273 /* 5 free bits */
277 * Graphics sets for display symbols
279 #define DEFAULT_GRAPHICS 0 /* regular characters: '-', '+', &c */
280 #define PRIMARY 0 /* primary graphics set */
281 #define ROGUESET 1 /* rogue graphics set */
282 #define NUM_GRAPHICS 2
285 * special symbol set handling types ( for invoking callbacks, etc.)
286 * Must match the order of the known_handlers strings
287 * in drawing.c
289 #define H_UNK 0
290 #define H_IBM 1
291 #define H_DEC 2
293 extern const struct symdef defsyms[MAXPCHARS]; /* defaults */
294 extern const struct symdef def_warnsyms[WARNCOUNT];
295 extern int currentgraphics; /* from drawing.c */
296 extern nhsym showsyms[];
298 extern struct symsetentry symset[NUM_GRAPHICS]; /* from drawing.c */
299 #define SYMHANDLING(ht) (symset[currentgraphics].handling == (ht))
302 * The 5 possible states of doors
305 #define D_NODOOR 0
306 #define D_BROKEN 1
307 #define D_ISOPEN 2
308 #define D_CLOSED 4
309 #define D_LOCKED 8
310 #define D_TRAPPED 16
311 #define D_SECRET 32 /* only used by sp_lev.c, NOT in rm-struct */
314 * Some altars are considered as shrines, so we need a flag.
316 #define AM_SHRINE 8
319 * Thrones should only be looted once.
321 #define T_LOOTED 1
324 * Trees have more than one kick result.
326 #define TREE_LOOTED 1
327 #define TREE_SWARM 2
330 * Fountains have limits, and special warnings.
332 #define F_LOOTED 1
333 #define F_WARNED 2
334 #define FOUNTAIN_IS_WARNED(x, y) (levl[x][y].looted & F_WARNED)
335 #define FOUNTAIN_IS_LOOTED(x, y) (levl[x][y].looted & F_LOOTED)
336 #define SET_FOUNTAIN_WARNED(x, y) levl[x][y].looted |= F_WARNED;
337 #define SET_FOUNTAIN_LOOTED(x, y) levl[x][y].looted |= F_LOOTED;
338 #define CLEAR_FOUNTAIN_WARNED(x, y) levl[x][y].looted &= ~F_WARNED;
339 #define CLEAR_FOUNTAIN_LOOTED(x, y) levl[x][y].looted &= ~F_LOOTED;
342 * Doors are even worse :-) The special warning has a side effect
343 * of instantly trapping the door, and if it was defined as trapped,
344 * the guards consider that you have already been warned!
346 #define D_WARNED 16
349 * Sinks have 3 different types of loot that shouldn't be abused
351 #define S_LPUDDING 1
352 #define S_LDWASHER 2
353 #define S_LRING 4
356 * The four directions for a DrawBridge.
358 #define DB_NORTH 0
359 #define DB_SOUTH 1
360 #define DB_EAST 2
361 #define DB_WEST 3
362 #define DB_DIR 3 /* mask for direction */
365 * What's under a drawbridge.
367 #define DB_MOAT 0
368 #define DB_LAVA 4
369 #define DB_ICE 8
370 #define DB_FLOOR 16
371 #define DB_UNDER 28 /* mask for underneath */
374 * Wall information.
376 #define WM_MASK 0x07 /* wall mode (bottom three bits) */
377 #define W_NONDIGGABLE 0x08
378 #define W_NONPASSWALL 0x10
381 * Ladders (in Vlad's tower) may be up or down.
383 #define LA_UP 1
384 #define LA_DOWN 2
387 * Room areas may be iced pools
389 #define ICED_POOL 8
390 #define ICED_MOAT 16
393 * The structure describing a coordinate position.
394 * Before adding fields, remember that this will significantly affect
395 * the size of temporary files and save files.
397 * Also remember that the run-length encoding for some ports in save.c
398 * must be updated to consider the field.
400 struct rm {
401 int glyph; /* what the hero thinks is there */
402 schar typ; /* what is really there */
403 uchar seenv; /* seen vector */
404 Bitfield(flags, 5); /* extra information for typ */
405 Bitfield(horizontal, 1); /* wall/door/etc is horiz. (more typ info) */
406 Bitfield(lit, 1); /* speed hack for lit rooms */
407 Bitfield(waslit, 1); /* remember if a location was lit */
409 Bitfield(roomno, 6); /* room # for special rooms */
410 Bitfield(edge, 1); /* marks boundaries for special rooms*/
411 Bitfield(candig, 1); /* Exception to Can_dig_down; was a trapdoor */
414 #define SET_TYPLIT(x, y, ttyp, llit) \
416 if ((x) >= 0 && (y) >= 0 && (x) < COLNO && (y) < ROWNO) { \
417 if ((ttyp) < MAX_TYPE) \
418 levl[(x)][(y)].typ = (ttyp); \
419 if ((ttyp) == LAVAPOOL) \
420 levl[(x)][(y)].lit = 1; \
421 else if ((schar)(llit) != -2) { \
422 if ((schar)(llit) == -1) \
423 levl[(x)][(y)].lit = rn2(2); \
424 else \
425 levl[(x)][(y)].lit = (llit); \
431 * Add wall angle viewing by defining "modes" for each wall type. Each
432 * mode describes which parts of a wall are finished (seen as as wall)
433 * and which are unfinished (seen as rock).
435 * We use the bottom 3 bits of the flags field for the mode. This comes
436 * in conflict with secret doors, but we avoid problems because until
437 * a secret door becomes discovered, we know what sdoor's bottom three
438 * bits are.
440 * The following should cover all of the cases.
442 * type mode Examples: R=rock, F=finished
443 * ----- ---- ----------------------------
444 * WALL: 0 none hwall, mode 1
445 * 1 left/top (1/2 rock) RRR
446 * 2 right/bottom (1/2 rock) ---
447 * FFF
449 * CORNER: 0 none trcorn, mode 2
450 * 1 outer (3/4 rock) FFF
451 * 2 inner (1/4 rock) F+-
452 * F|R
454 * TWALL: 0 none tlwall, mode 3
455 * 1 long edge (1/2 rock) F|F
456 * 2 bottom left (on a tdwall) -+F
457 * 3 bottom right (on a tdwall) R|F
459 * CRWALL: 0 none crwall, mode 5
460 * 1 top left (1/4 rock) R|F
461 * 2 top right (1/4 rock) -+-
462 * 3 bottom left (1/4 rock) F|R
463 * 4 bottom right (1/4 rock)
464 * 5 top left & bottom right (1/2 rock)
465 * 6 bottom left & top right (1/2 rock)
468 #define WM_W_LEFT 1 /* vertical or horizontal wall */
469 #define WM_W_RIGHT 2
470 #define WM_W_TOP WM_W_LEFT
471 #define WM_W_BOTTOM WM_W_RIGHT
473 #define WM_C_OUTER 1 /* corner wall */
474 #define WM_C_INNER 2
476 #define WM_T_LONG 1 /* T wall */
477 #define WM_T_BL 2
478 #define WM_T_BR 3
480 #define WM_X_TL 1 /* cross wall */
481 #define WM_X_TR 2
482 #define WM_X_BL 3
483 #define WM_X_BR 4
484 #define WM_X_TLBR 5
485 #define WM_X_BLTR 6
488 * Seen vector values. The seen vector is an array of 8 bits, one for each
489 * octant around a given center x:
491 * 0 1 2
492 * 7 x 3
493 * 6 5 4
495 * In the case of walls, a single wall square can be viewed from 8 possible
496 * directions. If we know the type of wall and the directions from which
497 * it has been seen, then we can determine what it looks like to the hero.
499 #define SV0 0x1
500 #define SV1 0x2
501 #define SV2 0x4
502 #define SV3 0x8
503 #define SV4 0x10
504 #define SV5 0x20
505 #define SV6 0x40
506 #define SV7 0x80
507 #define SVALL 0xFF
509 #define doormask flags
510 #define altarmask flags
511 #define wall_info flags
512 #define ladder flags
513 #define drawbridgemask flags
514 #define looted flags
515 #define icedpool flags
517 #define blessedftn horizontal /* a fountain that grants attribs */
518 #define disturbed horizontal /* a grave that has been disturbed */
520 struct damage {
521 struct damage *next;
522 long when, cost;
523 coord place;
524 schar typ;
527 /* for bones levels: identify the dead character, who might have died on
528 an existing bones level; if so, most recent victim will be first in list */
529 struct cemetery {
530 struct cemetery *next; /* next struct is previous dead character... */
531 /* "plname" + "-ROLe" + "-RACe" + "-GENder" + "-ALIgnment" + \0 */
532 char who[PL_NSIZ + 4 * (1 + 3) + 1];
533 /* death reason, same as in score/log file */
534 char how[100 + 1]; /* [DTHSZ+1] */
535 /* date+time in string of digits rather than binary */
536 char when[4 + 2 + 2 + 2 + 2 + 2 + 1]; /* "YYYYMMDDhhmmss\0" */
537 /* final resting place spot */
538 schar frpx, frpy;
539 boolean bonesknown;
542 struct levelflags {
543 uchar nfountains; /* number of fountains on level */
544 uchar nsinks; /* number of sinks on the level */
545 /* Several flags that give hints about what's on the level */
546 Bitfield(has_shop, 1);
547 Bitfield(has_vault, 1);
548 Bitfield(has_zoo, 1);
549 Bitfield(has_court, 1);
550 Bitfield(has_morgue, 1);
551 Bitfield(has_beehive, 1);
552 Bitfield(has_barracks, 1);
553 Bitfield(has_temple, 1);
555 Bitfield(has_swamp, 1);
556 Bitfield(noteleport, 1);
557 Bitfield(hardfloor, 1);
558 Bitfield(nommap, 1);
559 Bitfield(hero_memory, 1); /* hero has memory */
560 Bitfield(shortsighted, 1); /* monsters are shortsighted */
561 Bitfield(graveyard, 1); /* has_morgue, but remains set */
562 Bitfield(sokoban_rules, 1); /* fill pits and holes w/ boulders */
564 Bitfield(is_maze_lev, 1);
565 Bitfield(is_cavernous_lev, 1);
566 Bitfield(arboreal, 1); /* Trees replace rock */
567 Bitfield(wizard_bones, 1); /* set if level came from a bones file
568 which was created in wizard mode (or
569 normal mode descendant of such) */
570 Bitfield(corrmaze, 1); /* Whether corridors are used for the maze
571 rather than ROOM */
574 typedef struct {
575 struct rm locations[COLNO][ROWNO];
576 #ifndef MICROPORT_BUG
577 struct obj *objects[COLNO][ROWNO];
578 struct monst *monsters[COLNO][ROWNO];
579 #else
580 struct obj *objects[1][ROWNO];
581 char *yuk1[COLNO - 1][ROWNO];
582 struct monst *monsters[1][ROWNO];
583 char *yuk2[COLNO - 1][ROWNO];
584 #endif
585 struct obj *objlist;
586 struct obj *buriedobjlist;
587 struct monst *monlist;
588 struct damage *damagelist;
589 struct cemetery *bonesinfo;
590 struct levelflags flags;
591 } dlevel_t;
593 extern schar lastseentyp[COLNO][ROWNO]; /* last seen/touched dungeon typ */
595 extern dlevel_t level; /* structure describing the current level */
598 * Macros for compatibility with old code. Someday these will go away.
600 #define levl level.locations
601 #define fobj level.objlist
602 #define fmon level.monlist
605 * Covert a trap number into the defsym graphics array.
606 * Convert a defsym number into a trap number.
607 * Assumes that arrow trap will always be the first trap.
609 #define trap_to_defsym(t) (S_arrow_trap + (t) -1)
610 #define defsym_to_trap(d) ((d) -S_arrow_trap + 1)
612 #define OBJ_AT(x, y) (level.objects[x][y] != (struct obj *) 0)
614 * Macros for encapsulation of level.monsters references.
616 #define MON_AT(x, y) \
617 (level.monsters[x][y] != (struct monst *) 0 \
618 && !(level.monsters[x][y])->mburied)
619 #define MON_BURIED_AT(x, y) \
620 (level.monsters[x][y] != (struct monst *) 0 \
621 && (level.monsters[x][y])->mburied)
622 #define place_worm_seg(m, x, y) level.monsters[x][y] = m
623 #define remove_monster(x, y) level.monsters[x][y] = (struct monst *) 0
624 #define m_at(x, y) (MON_AT(x, y) ? level.monsters[x][y] : (struct monst *) 0)
625 #define m_buried_at(x, y) \
626 (MON_BURIED_AT(x, y) ? level.monsters[x][y] : (struct monst *) 0)
628 /* restricted movement, potential luck penalties */
629 #define Sokoban level.flags.sokoban_rules
631 #endif /* RM_H */