5 * @brief ダンジョンの生成処理の基幹部分ヘッダーファイル
8 * Purpose: header file for grid.c, used only in dungeon generation
9 * files (generate.c, rooms.c)
11 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
12 * This software may be copied and distributed for educational, research, and
13 * not for profit purposes provided that this copyright and statement are
14 * included in all such copies.
19 * A single "grid" in a Cave
21 * Note that several aspects of the code restrict the actual p_ptr->current_floor_ptr->grid_array
22 * to a max size of 256 by 256. In partcular, locations are often
23 * saved as bytes, limiting each coordinate to the 0-255 range.
25 * The "o_idx" and "m_idx" fields are very interesting. There are
26 * many places in the code where we need quick access to the actual
27 * monster or object(s) in a given grid. The easiest way to
28 * do this is to simply keep the index of the monster and object
29 * (if any) with the grid, but this takes 198*66*4 bytes of memory.
30 * Several other methods come to mind, which require only half this
31 * amound of memory, but they all seem rather complicated, and would
32 * probably add enough code that the savings would be lost. So for
33 * these reasons, we simply store an index into the "o_list" and
34 * "p_ptr->current_floor_ptr->m_list" arrays, using "zero" when no monster/object is present.
36 * Note that "o_idx" is the index of the top object in a stack of
37 * objects, using the "next_o_idx" field of objects (see below) to
38 * create the singly linked list of objects. If "o_idx" is zero
39 * then there are no objects in the grid.
41 * Note the special fields for the "MONSTER_FLOW" code.
44 typedef struct player_type player_type;
47 typedef struct grid_type grid_type;
51 BIT_FLAGS info; /* Hack -- p_ptr->current_floor_ptr->grid_array flags */
53 FEAT_IDX feat; /* Hack -- feature type */
54 OBJECT_IDX o_idx; /* Object in this grid */
55 MONSTER_IDX m_idx; /* Monster in this grid */
57 /*! 地形の特別な情報を保存する / Special p_ptr->current_floor_ptr->grid_array info
58 * 具体的な使用一覧はクエスト行き階段の移行先クエストID、
59 * 各ダンジョン入口の移行先ダンジョンID、
64 FEAT_IDX mimic; /* Feature to mimic */
66 byte cost; /* Hack -- cost of flowing */
67 byte dist; /* Hack -- distance from player */
68 byte when; /* Hack -- when cost was computed */
72 * A structure type for terrain template of saving dungeon floor
84 #define set_cave_feat(FL,Y,X,F) ((FL)->grid_array[(Y)][(X)].feat = (F))
85 #define add_cave_info(Y,X,I) (p_ptr->current_floor_ptr->grid_array[(Y)][(X)].info |= (I))
87 /* This should not be used */
88 /*#define set_cave_info(Y,X,I) (p_ptr->current_floor_ptr->grid_array[(Y)][(X)].info = (I)) */
95 #define place_rubble(Y,X) set_cave_feat(p_ptr->current_floor_ptr,Y,X,feat_rubble)
98 * @brief 指定座標がFLOOR属性を持ったマスかどうかを返す
101 * @return FLOOR属性を持っているならばTRUE
103 #define is_floor_bold(Y,X) (p_ptr->current_floor_ptr->grid_array[Y][X].info & CAVE_FLOOR)
104 #define is_extra_bold(Y,X) (p_ptr->current_floor_ptr->grid_array[Y][X].info & CAVE_EXTRA)
106 #define is_inner_bold(Y,X) (p_ptr->current_floor_ptr->grid_array[Y][X].info & CAVE_INNER)
107 #define is_outer_bold(Y,X) (p_ptr->current_floor_ptr->grid_array[Y][X].info & CAVE_OUTER)
108 #define is_solid_bold(Y,X) (p_ptr->current_floor_ptr->grid_array[Y][X].info & CAVE_SOLID)
110 #define is_floor_grid(C) ((C)->info & CAVE_FLOOR)
111 #define is_extra_grid(C) ((C)->info & CAVE_EXTRA)
112 #define is_inner_grid(C) ((C)->info & CAVE_INNER)
113 #define is_outer_grid(C) ((C)->info & CAVE_OUTER)
114 #define is_solid_grid(C) ((C)->info & CAVE_SOLID)
116 #define place_floor_bold(Y, X) \
118 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_ground_type[randint0(100)]); \
119 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
120 add_cave_info(Y,X,CAVE_FLOOR); \
121 delete_monster(Y, X); \
124 #define place_floor_grid(C) \
126 (C)->feat = feat_ground_type[randint0(100)]; \
127 (C)->info &= ~(CAVE_MASK); \
128 (C)->info |= CAVE_FLOOR; \
129 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
132 #define place_extra_bold(Y, X) \
134 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_type[randint0(100)]); \
135 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
136 add_cave_info(Y,X,CAVE_EXTRA); \
137 delete_monster(Y, X); \
140 #define place_extra_grid(C) \
142 (C)->feat = feat_wall_type[randint0(100)]; \
143 (C)->info &= ~(CAVE_MASK); \
144 (C)->info |= CAVE_EXTRA; \
145 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
148 #define place_extra_perm_bold(Y, X) \
150 set_cave_feat(floor_ptr, Y,X,feat_permanent); \
151 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
152 add_cave_info(Y,X,CAVE_EXTRA); \
153 delete_monster(Y, X); \
156 #define place_extra_perm_grid(C) \
158 (C)->feat = feat_permanent; \
159 (C)->info &= ~(CAVE_MASK); \
160 (C)->info |= CAVE_EXTRA; \
161 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
164 #define place_extra_noperm_bold(Y, X) \
166 feature_type *_f_ptr; \
167 set_cave_feat(floor_ptr, Y,X,feat_wall_type[randint0(100)]); \
168 _f_ptr = &f_info[p_ptr->current_floor_ptr->grid_array[Y][X].feat]; \
169 if (permanent_wall(_f_ptr)) p_ptr->current_floor_ptr->grid_array[Y][X].feat = feat_state(p_ptr->current_floor_ptr->grid_array[Y][X].feat, FF_UNPERM); \
170 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
171 add_cave_info(Y,X,CAVE_EXTRA); \
172 delete_monster(Y, X); \
175 #define place_inner_bold(Y, X) \
177 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_inner); \
178 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
179 add_cave_info(Y,X,CAVE_INNER); \
180 delete_monster(Y, X); \
183 #define place_inner_grid(C) \
185 (C)->feat = feat_wall_inner; \
186 (C)->info &= ~(CAVE_MASK); \
187 (C)->info |= CAVE_INNER; \
188 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
191 #define place_inner_perm_bold(Y, X) \
193 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_permanent); \
194 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
195 add_cave_info(Y,X,CAVE_INNER); \
196 delete_monster(Y, X); \
199 #define place_inner_perm_grid(C) \
201 (C)->feat = feat_permanent; \
202 (C)->info &= ~(CAVE_MASK); \
203 (C)->info |= CAVE_INNER; \
204 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
207 #define place_outer_bold(Y, X) \
209 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_outer); \
210 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
211 add_cave_info(Y,X,CAVE_OUTER); \
212 delete_monster(Y, X); \
215 #define place_outer_grid(C) \
217 (C)->feat = feat_wall_outer; \
218 (C)->info &= ~(CAVE_MASK); \
219 (C)->info |= CAVE_OUTER; \
220 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
223 #define place_outer_perm_bold(Y, X) \
225 set_cave_feat(floor_ptr, Y,X,feat_permanent); \
226 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
227 add_cave_info(Y,X,CAVE_OUTER); \
228 delete_monster(Y, X); \
231 #define place_outer_perm_grid(C) \
233 (C)->feat = feat_permanent; \
234 (C)->info &= ~(CAVE_MASK); \
235 (C)->info |= CAVE_OUTER; \
236 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
239 #define place_outer_noperm_bold(Y, X) \
241 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
242 if (permanent_wall(_f_ptr)) set_cave_feat(p_ptr->current_floor_ptr, Y, X, (s16b)feat_state(feat_wall_outer, FF_UNPERM)); \
243 else set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_outer); \
244 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
245 add_cave_info(Y,X,(CAVE_OUTER | CAVE_VAULT)); \
246 delete_monster(Y, X); \
249 #define place_outer_noperm_grid(C) \
251 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
252 if (permanent_wall(_f_ptr)) (C)->feat = (s16b)feat_state(feat_wall_outer, FF_UNPERM); \
253 else (C)->feat = feat_wall_outer; \
254 (C)->info &= ~(CAVE_MASK); \
255 (C)->info |= (CAVE_OUTER | CAVE_VAULT); \
256 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
259 #define place_solid_bold(Y, X) \
261 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_solid); \
262 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
263 add_cave_info(Y,X,CAVE_SOLID); \
264 delete_monster(Y, X); \
267 #define place_solid_grid(C) \
269 (C)->feat = feat_wall_solid; \
270 (C)->info &= ~(CAVE_MASK); \
271 (C)->info |= CAVE_SOLID; \
272 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
275 #define place_solid_perm_bold(Y, X) \
277 set_cave_feat(floor_ptr, Y,X,feat_permanent); \
278 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
279 add_cave_info(Y,X,CAVE_SOLID); \
280 delete_monster(Y, X); \
283 #define place_solid_perm_grid(C) \
285 (C)->feat = feat_permanent; \
286 (C)->info &= ~(CAVE_MASK); \
287 (C)->info |= CAVE_SOLID; \
288 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
291 #define place_solid_noperm_bold(Y, X) \
293 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
294 if ((p_ptr->current_floor_ptr->grid_array[Y][X].info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
295 set_cave_feat(p_ptr->current_floor_ptr, Y, X, feat_state(feat_wall_solid, FF_UNPERM)); \
296 else set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_solid); \
297 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
298 add_cave_info(Y,X,CAVE_SOLID); \
299 delete_monster(Y, X); \
302 #define place_solid_noperm_grid(C) \
304 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
305 if (((C)->info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
306 (C)->feat = feat_state(feat_wall_solid, FF_UNPERM); \
307 else (C)->feat = feat_wall_solid; \
308 (C)->info &= ~(CAVE_MASK); \
309 (C)->info |= CAVE_SOLID; \
310 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
315 * 特殊なマス状態フラグ / Special grid flags
317 #define CAVE_MARK 0x0001 /*!< 現在プレイヤーの記憶に収まっている / memorized feature */
318 #define CAVE_GLOW 0x0002 /*!< マス自体が光源を持っている / self-illuminating */
319 #define CAVE_ICKY 0x0004 /*!< 生成されたVaultの一部である / part of a vault */
320 #define CAVE_ROOM 0x0008 /*!< 生成された部屋の一部である / part of a room */
321 #define CAVE_LITE 0x0010 /*!< 現在光に照らされている / lite flag */
322 #define CAVE_VIEW 0x0020 /*!< 現在プレイヤーの視界に収まっている / view flag */
323 #define CAVE_TEMP 0x0040 /*!< 光源に関する処理のアルゴリズム用記録フラグ / temp flag */
324 #define CAVE_XTRA 0x0080 /*!< 視界に関する処理のアルゴリズム用記録フラグ(update_view()等参照) / misc flag */
325 #define CAVE_MNLT 0x0100 /*!< モンスターの光源によって照らされている / Illuminated by monster */
326 #define CAVE_MNDK 0x8000 /*!< モンスターの暗源によって暗闇になっている / Darken by monster */
328 /* Used only while p_ptr->current_floor_ptr->grid_array generation */
329 #define CAVE_FLOOR 0x0200 /*!< フロア属性のあるマス */
330 #define CAVE_EXTRA 0x0400
331 #define CAVE_INNER 0x0800
332 #define CAVE_OUTER 0x1000
333 #define CAVE_SOLID 0x2000
334 #define CAVE_VAULT 0x4000
335 #define CAVE_MASK (CAVE_FLOOR | CAVE_EXTRA | CAVE_INNER | CAVE_OUTER | CAVE_SOLID | CAVE_VAULT)
337 /* Used only after p_ptr->current_floor_ptr->grid_array generation */
338 #define CAVE_KNOWN 0x0200 /* Directly viewed or map detected flag */
339 #define CAVE_NOTE 0x0400 /* Flag for delayed visual update (needs note_spot()) */
340 #define CAVE_REDRAW 0x0800 /* Flag for delayed visual update (needs lite_spot()) */
341 #define CAVE_OBJECT 0x1000 /* Mirror, glyph, etc. */
342 #define CAVE_UNSAFE 0x2000 /* Might have trap */
343 #define CAVE_IN_DETECT 0x4000 /* trap detected area (inner circle only) */
345 /* Types of conversions */
346 #define CONVERT_TYPE_FLOOR 0
347 #define CONVERT_TYPE_WALL 1
348 #define CONVERT_TYPE_INNER 2
349 #define CONVERT_TYPE_OUTER 3
350 #define CONVERT_TYPE_SOLID 4
351 #define CONVERT_TYPE_STREAM1 5
352 #define CONVERT_TYPE_STREAM2 6
356 extern bool new_player_spot(void);
358 extern void place_random_stairs(POSITION y, POSITION x);
359 extern void place_random_door(POSITION y, POSITION x, bool room);
360 extern void add_door(POSITION x, POSITION y);
363 #define DOOR_DEFAULT -1
365 #define DOOR_GLASS_DOOR 1
366 #define DOOR_CURTAIN 2
368 #define MAX_DOOR_TYPES 3
369 extern void place_closed_door(POSITION y, POSITION x, int type);
370 extern void place_secret_door(POSITION y, POSITION x, int type);
372 extern void place_locked_door(POSITION y, POSITION x);
373 extern void try_door(POSITION y, POSITION x);
374 extern void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
375 extern void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
376 extern void vault_monsters(POSITION y1, POSITION x1, int num);
377 extern void vault_objects(POSITION y, POSITION x, int num);
378 extern void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd);
379 extern void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num);
381 extern bool get_is_floor(POSITION x, POSITION y);
382 extern void set_floor(POSITION x, POSITION y);
383 extern void place_bound_perm_wall(grid_type *g_ptr);
385 extern bool is_known_trap(grid_type *g_ptr);
386 extern bool is_hidden_door(grid_type *g_ptr);
387 extern bool is_mirror_grid(grid_type *g_ptr);
388 extern bool is_glyph_grid(grid_type *g_ptr);
389 extern bool is_explosive_rune_grid(grid_type *g_ptr);
391 extern bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode);
394 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
396 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
399 extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
400 extern bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
401 extern void update_local_illumination(player_type *creature_ptr, POSITION y, POSITION x);
402 extern bool player_can_see_bold(POSITION y, POSITION x);
403 extern bool cave_valid_bold(POSITION y, POSITION x);
404 extern bool no_lite(void);
405 extern void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp);
406 extern void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x);
407 extern void note_spot(POSITION y, POSITION x);
408 extern void lite_spot(POSITION y, POSITION x);
409 extern void delayed_visual_update(void);
410 extern void forget_flow(void);
411 extern void update_flow(void);
412 extern void update_smell(void);
413 extern void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat);
414 extern FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat);
415 extern FEAT_IDX feat_state(FEAT_IDX feat, int action);
416 extern void cave_alter_feat(POSITION y, POSITION x, int action);
417 extern void remove_mirror(POSITION y, POSITION x);
418 extern bool is_open(FEAT_IDX feat);
419 extern bool check_local_illumination(POSITION y, POSITION x);
421 extern bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode);
422 extern bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode);
426 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
428 #define darkened_grid(C) \
429 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
433 * Get feature mimic from f_info[] (applying "mimic" field)
435 #define get_feat_mimic(C) \
436 (f_info[(C)->mimic ? (C)->mimic : (C)->feat].mimic)
439 * This macro allows us to efficiently add a grid to the "lite" array,
440 * note that we are never called for illegal grids, or for grids which
441 * have already been placed into the "lite" array, and we are never
442 * called when the "lite" array is full.
444 #define cave_lite_hack(Y,X) \
446 if (!(p_ptr->current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
448 p_ptr->current_floor_ptr->grid_array[Y][X].info |= (CAVE_LITE); \
449 p_ptr->current_floor_ptr->lite_y[p_ptr->current_floor_ptr->lite_n] = (Y); \
450 p_ptr->current_floor_ptr->lite_x[p_ptr->current_floor_ptr->lite_n++] = (X); \
455 * For delayed visual update
457 #define cave_note_and_redraw_later(C,Y,X) \
459 (C)->info |= CAVE_NOTE; \
460 cave_redraw_later((C), (Y), (X)); \
464 * For delayed visual update
466 #define cave_redraw_later(C,Y,X) \
468 if (!((C)->info & CAVE_REDRAW)) \
470 (C)->info |= CAVE_REDRAW; \
471 p_ptr->current_floor_ptr->redraw_y[p_ptr->current_floor_ptr->redraw_n] = (Y); \
472 p_ptr->current_floor_ptr->redraw_x[p_ptr->current_floor_ptr->redraw_n++] = (X); \
477 * This macro allows us to efficiently add a grid to the "view" array,
478 * note that we are never called for illegal grids, or for grids which
479 * have already been placed into the "view" array, and we are never
480 * called when the "view" array is full.
482 #define cave_view_hack(C,Y,X) \
484 if (!((C)->info & (CAVE_VIEW))){\
485 (C)->info |= (CAVE_VIEW); \
486 p_ptr->current_floor_ptr->view_y[p_ptr->current_floor_ptr->view_n] = (Y); \
487 p_ptr->current_floor_ptr->view_x[p_ptr->current_floor_ptr->view_n] = (X); \
488 p_ptr->current_floor_ptr->view_n++;}\