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 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 * "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 grid_type grid_type;
48 BIT_FLAGS info; /* Hack -- current_floor_ptr->grid_array flags */
50 FEAT_IDX feat; /* Hack -- feature type */
51 OBJECT_IDX o_idx; /* Object in this grid */
52 MONSTER_IDX m_idx; /* Monster in this grid */
54 /*! 地形の特別な情報を保存する / Special current_floor_ptr->grid_array info
55 * 具体的な使用一覧はクエスト行き階段の移行先クエストID、
56 * 各ダンジョン入口の移行先ダンジョンID、
61 FEAT_IDX mimic; /* Feature to mimic */
63 byte cost; /* Hack -- cost of flowing */
64 byte dist; /* Hack -- distance from player */
65 byte when; /* Hack -- when cost was computed */
69 * A structure type for terrain template of saving dungeon floor
81 #define set_cave_feat(Y,X,F) (current_floor_ptr->grid_array[(Y)][(X)].feat = (F))
82 #define add_cave_info(Y,X,I) (current_floor_ptr->grid_array[(Y)][(X)].info |= (I))
84 /* This should not be used */
85 /*#define set_cave_info(Y,X,I) (current_floor_ptr->grid_array[(Y)][(X)].info = (I)) */
92 #define place_rubble(Y,X) set_cave_feat(Y,X,feat_rubble)
95 * @brief 指定座標がFLOOR属性を持ったマスかどうかを返す
98 * @return FLOOR属性を持っているならばTRUE
100 #define is_floor_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_FLOOR)
101 #define is_extra_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_EXTRA)
103 #define is_inner_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_INNER)
104 #define is_outer_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_OUTER)
105 #define is_solid_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_SOLID)
107 #define is_floor_grid(C) ((C)->info & CAVE_FLOOR)
108 #define is_extra_grid(C) ((C)->info & CAVE_EXTRA)
109 #define is_inner_grid(C) ((C)->info & CAVE_INNER)
110 #define is_outer_grid(C) ((C)->info & CAVE_OUTER)
111 #define is_solid_grid(C) ((C)->info & CAVE_SOLID)
113 #define place_floor_bold(Y, X) \
115 set_cave_feat(Y,X,feat_ground_type[randint0(100)]); \
116 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
117 add_cave_info(Y,X,CAVE_FLOOR); \
118 delete_monster(Y, X); \
121 #define place_floor_grid(C) \
123 (C)->feat = feat_ground_type[randint0(100)]; \
124 (C)->info &= ~(CAVE_MASK); \
125 (C)->info |= CAVE_FLOOR; \
126 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
129 #define place_extra_bold(Y, X) \
131 set_cave_feat(Y,X,feat_wall_type[randint0(100)]); \
132 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
133 add_cave_info(Y,X,CAVE_EXTRA); \
134 delete_monster(Y, X); \
137 #define place_extra_grid(C) \
139 (C)->feat = feat_wall_type[randint0(100)]; \
140 (C)->info &= ~(CAVE_MASK); \
141 (C)->info |= CAVE_EXTRA; \
142 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
145 #define place_extra_perm_bold(Y, X) \
147 set_cave_feat(Y,X,feat_permanent); \
148 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
149 add_cave_info(Y,X,CAVE_EXTRA); \
150 delete_monster(Y, X); \
153 #define place_extra_perm_grid(C) \
155 (C)->feat = feat_permanent; \
156 (C)->info &= ~(CAVE_MASK); \
157 (C)->info |= CAVE_EXTRA; \
158 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
161 #define place_extra_noperm_bold(Y, X) \
163 feature_type *_f_ptr; \
164 set_cave_feat(Y,X,feat_wall_type[randint0(100)]); \
165 _f_ptr = &f_info[current_floor_ptr->grid_array[Y][X].feat]; \
166 if (permanent_wall(_f_ptr)) current_floor_ptr->grid_array[Y][X].feat = feat_state(current_floor_ptr->grid_array[Y][X].feat, FF_UNPERM); \
167 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
168 add_cave_info(Y,X,CAVE_EXTRA); \
169 delete_monster(Y, X); \
172 #define place_inner_bold(Y, X) \
174 set_cave_feat(Y,X,feat_wall_inner); \
175 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
176 add_cave_info(Y,X,CAVE_INNER); \
177 delete_monster(Y, X); \
180 #define place_inner_grid(C) \
182 (C)->feat = feat_wall_inner; \
183 (C)->info &= ~(CAVE_MASK); \
184 (C)->info |= CAVE_INNER; \
185 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
188 #define place_inner_perm_bold(Y, X) \
190 set_cave_feat(Y,X,feat_permanent); \
191 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
192 add_cave_info(Y,X,CAVE_INNER); \
193 delete_monster(Y, X); \
196 #define place_inner_perm_grid(C) \
198 (C)->feat = feat_permanent; \
199 (C)->info &= ~(CAVE_MASK); \
200 (C)->info |= CAVE_INNER; \
201 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
204 #define place_outer_bold(Y, X) \
206 set_cave_feat(Y,X,feat_wall_outer); \
207 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
208 add_cave_info(Y,X,CAVE_OUTER); \
209 delete_monster(Y, X); \
212 #define place_outer_grid(C) \
214 (C)->feat = feat_wall_outer; \
215 (C)->info &= ~(CAVE_MASK); \
216 (C)->info |= CAVE_OUTER; \
217 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
220 #define place_outer_perm_bold(Y, X) \
222 set_cave_feat(Y,X,feat_permanent); \
223 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
224 add_cave_info(Y,X,CAVE_OUTER); \
225 delete_monster(Y, X); \
228 #define place_outer_perm_grid(C) \
230 (C)->feat = feat_permanent; \
231 (C)->info &= ~(CAVE_MASK); \
232 (C)->info |= CAVE_OUTER; \
233 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
236 #define place_outer_noperm_bold(Y, X) \
238 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
239 if (permanent_wall(_f_ptr)) set_cave_feat(Y, X, (s16b)feat_state(feat_wall_outer, FF_UNPERM)); \
240 else set_cave_feat(Y,X,feat_wall_outer); \
241 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
242 add_cave_info(Y,X,(CAVE_OUTER | CAVE_VAULT)); \
243 delete_monster(Y, X); \
246 #define place_outer_noperm_grid(C) \
248 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
249 if (permanent_wall(_f_ptr)) (C)->feat = (s16b)feat_state(feat_wall_outer, FF_UNPERM); \
250 else (C)->feat = feat_wall_outer; \
251 (C)->info &= ~(CAVE_MASK); \
252 (C)->info |= (CAVE_OUTER | CAVE_VAULT); \
253 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
256 #define place_solid_bold(Y, X) \
258 set_cave_feat(Y,X,feat_wall_solid); \
259 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
260 add_cave_info(Y,X,CAVE_SOLID); \
261 delete_monster(Y, X); \
264 #define place_solid_grid(C) \
266 (C)->feat = feat_wall_solid; \
267 (C)->info &= ~(CAVE_MASK); \
268 (C)->info |= CAVE_SOLID; \
269 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
272 #define place_solid_perm_bold(Y, X) \
274 set_cave_feat(Y,X,feat_permanent); \
275 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
276 add_cave_info(Y,X,CAVE_SOLID); \
277 delete_monster(Y, X); \
280 #define place_solid_perm_grid(C) \
282 (C)->feat = feat_permanent; \
283 (C)->info &= ~(CAVE_MASK); \
284 (C)->info |= CAVE_SOLID; \
285 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
288 #define place_solid_noperm_bold(Y, X) \
290 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
291 if ((current_floor_ptr->grid_array[Y][X].info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
292 set_cave_feat(Y, X, feat_state(feat_wall_solid, FF_UNPERM)); \
293 else set_cave_feat(Y,X,feat_wall_solid); \
294 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
295 add_cave_info(Y,X,CAVE_SOLID); \
296 delete_monster(Y, X); \
299 #define place_solid_noperm_grid(C) \
301 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
302 if (((C)->info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
303 (C)->feat = feat_state(feat_wall_solid, FF_UNPERM); \
304 else (C)->feat = feat_wall_solid; \
305 (C)->info &= ~(CAVE_MASK); \
306 (C)->info |= CAVE_SOLID; \
307 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
312 * 特殊なマス状態フラグ / Special grid flags
314 #define CAVE_MARK 0x0001 /*!< 現在プレイヤーの記憶に収まっている / memorized feature */
315 #define CAVE_GLOW 0x0002 /*!< マス自体が光源を持っている / self-illuminating */
316 #define CAVE_ICKY 0x0004 /*!< 生成されたVaultの一部である / part of a vault */
317 #define CAVE_ROOM 0x0008 /*!< 生成された部屋の一部である / part of a room */
318 #define CAVE_LITE 0x0010 /*!< 現在光に照らされている / lite flag */
319 #define CAVE_VIEW 0x0020 /*!< 現在プレイヤーの視界に収まっている / view flag */
320 #define CAVE_TEMP 0x0040 /*!< 光源に関する処理のアルゴリズム用記録フラグ / temp flag */
321 #define CAVE_XTRA 0x0080 /*!< 視界に関する処理のアルゴリズム用記録フラグ(update_view()等参照) / misc flag */
322 #define CAVE_MNLT 0x0100 /*!< モンスターの光源によって照らされている / Illuminated by monster */
323 #define CAVE_MNDK 0x8000 /*!< モンスターの暗源によって暗闇になっている / Darken by monster */
325 /* Used only while current_floor_ptr->grid_array generation */
326 #define CAVE_FLOOR 0x0200 /*!< フロア属性のあるマス */
327 #define CAVE_EXTRA 0x0400
328 #define CAVE_INNER 0x0800
329 #define CAVE_OUTER 0x1000
330 #define CAVE_SOLID 0x2000
331 #define CAVE_VAULT 0x4000
332 #define CAVE_MASK (CAVE_FLOOR | CAVE_EXTRA | CAVE_INNER | CAVE_OUTER | CAVE_SOLID | CAVE_VAULT)
334 /* Used only after current_floor_ptr->grid_array generation */
335 #define CAVE_KNOWN 0x0200 /* Directly viewed or map detected flag */
336 #define CAVE_NOTE 0x0400 /* Flag for delayed visual update (needs note_spot()) */
337 #define CAVE_REDRAW 0x0800 /* Flag for delayed visual update (needs lite_spot()) */
338 #define CAVE_OBJECT 0x1000 /* Mirror, glyph, etc. */
339 #define CAVE_UNSAFE 0x2000 /* Might have trap */
340 #define CAVE_IN_DETECT 0x4000 /* trap detected area (inner circle only) */
342 /* Types of conversions */
343 #define CONVERT_TYPE_FLOOR 0
344 #define CONVERT_TYPE_WALL 1
345 #define CONVERT_TYPE_INNER 2
346 #define CONVERT_TYPE_OUTER 3
347 #define CONVERT_TYPE_SOLID 4
348 #define CONVERT_TYPE_STREAM1 5
349 #define CONVERT_TYPE_STREAM2 6
353 extern bool new_player_spot(void);
355 extern void place_random_stairs(POSITION y, POSITION x);
356 extern void place_random_door(POSITION y, POSITION x, bool room);
357 extern void add_door(POSITION x, POSITION y);
360 #define DOOR_DEFAULT -1
362 #define DOOR_GLASS_DOOR 1
363 #define DOOR_CURTAIN 2
365 #define MAX_DOOR_TYPES 3
366 extern void place_closed_door(POSITION y, POSITION x, int type);
367 extern void place_secret_door(POSITION y, POSITION x, int type);
369 extern void place_locked_door(POSITION y, POSITION x);
370 extern void try_door(POSITION y, POSITION x);
371 extern void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
372 extern void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
373 extern void vault_monsters(POSITION y1, POSITION x1, int num);
374 extern void vault_objects(POSITION y, POSITION x, int num);
375 extern void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd);
376 extern void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num);
378 extern bool get_is_floor(POSITION x, POSITION y);
379 extern void set_floor(POSITION x, POSITION y);
380 extern void place_bound_perm_wall(grid_type *g_ptr);
382 extern bool is_known_trap(grid_type *g_ptr);
383 extern bool is_hidden_door(grid_type *g_ptr);
384 extern bool is_mirror_grid(grid_type *g_ptr);
385 extern bool is_glyph_grid(grid_type *g_ptr);
386 extern bool is_explosive_rune_grid(grid_type *g_ptr);
388 extern bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode);
391 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
393 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
396 extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
397 extern bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
398 extern void update_local_illumination(POSITION y, POSITION x);
399 extern bool player_can_see_bold(POSITION y, POSITION x);
400 extern bool cave_valid_bold(POSITION y, POSITION x);
401 extern bool no_lite(void);
402 extern void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp);
403 extern void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x);
404 extern void note_spot(POSITION y, POSITION x);
405 extern void lite_spot(POSITION y, POSITION x);
406 extern void delayed_visual_update(void);
407 extern void forget_flow(void);
408 extern void update_flow(void);
409 extern void update_smell(void);
410 extern void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat);
411 extern FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat);
412 extern FEAT_IDX feat_state(FEAT_IDX feat, int action);
413 extern void cave_alter_feat(POSITION y, POSITION x, int action);
414 extern void remove_mirror(POSITION y, POSITION x);
415 extern bool is_open(FEAT_IDX feat);
416 extern bool check_local_illumination(POSITION y, POSITION x);
418 extern bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode);
419 extern bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode);
423 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
425 #define darkened_grid(C) \
426 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
430 * Get feature mimic from f_info[] (applying "mimic" field)
432 #define get_feat_mimic(C) \
433 (f_info[(C)->mimic ? (C)->mimic : (C)->feat].mimic)
436 * This macro allows us to efficiently add a grid to the "lite" array,
437 * note that we are never called for illegal grids, or for grids which
438 * have already been placed into the "lite" array, and we are never
439 * called when the "lite" array is full.
441 #define cave_lite_hack(Y,X) \
443 if (!(current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
445 current_floor_ptr->grid_array[Y][X].info |= (CAVE_LITE); \
446 current_floor_ptr->lite_y[current_floor_ptr->lite_n] = (Y); \
447 current_floor_ptr->lite_x[current_floor_ptr->lite_n++] = (X); \
452 * For delayed visual update
454 #define cave_note_and_redraw_later(C,Y,X) \
456 (C)->info |= CAVE_NOTE; \
457 cave_redraw_later((C), (Y), (X)); \
461 * For delayed visual update
463 #define cave_redraw_later(C,Y,X) \
465 if (!((C)->info & CAVE_REDRAW)) \
467 (C)->info |= CAVE_REDRAW; \
468 current_floor_ptr->redraw_y[current_floor_ptr->redraw_n] = (Y); \
469 current_floor_ptr->redraw_x[current_floor_ptr->redraw_n++] = (X); \
474 * This macro allows us to efficiently add a grid to the "view" array,
475 * note that we are never called for illegal grids, or for grids which
476 * have already been placed into the "view" array, and we are never
477 * called when the "view" array is full.
479 #define cave_view_hack(C,Y,X) \
481 if (!((C)->info & (CAVE_VIEW))){\
482 (C)->info |= (CAVE_VIEW); \
483 current_floor_ptr->view_y[current_floor_ptr->view_n] = (Y); \
484 current_floor_ptr->view_x[current_floor_ptr->view_n] = (X); \
485 current_floor_ptr->view_n++;}\