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; // TODO: Delete Finally.
46 typedef struct grid_type grid_type;
50 BIT_FLAGS info; /* Hack -- p_ptr->current_floor_ptr->grid_array flags */
52 FEAT_IDX feat; /* Hack -- feature type */
53 OBJECT_IDX o_idx; /* Object in this grid */
54 MONSTER_IDX m_idx; /* Monster in this grid */
56 /*! 地形の特別な情報を保存する / Special p_ptr->current_floor_ptr->grid_array info
57 * 具体的な使用一覧はクエスト行き階段の移行先クエストID、
58 * 各ダンジョン入口の移行先ダンジョンID、
63 FEAT_IDX mimic; /* Feature to mimic */
65 byte cost; /* Hack -- cost of flowing */
66 byte dist; /* Hack -- distance from player */
67 byte when; /* Hack -- when cost was computed */
71 * A structure type for terrain template of saving dungeon floor
83 #define set_cave_feat(FL,Y,X,F) ((FL)->grid_array[(Y)][(X)].feat = (F))
84 #define add_cave_info(FL,Y,X,I) ((FL)->grid_array[(Y)][(X)].info |= (I))
86 /* This should not be used */
87 /*#define set_cave_info(Y,X,I) (p_ptr->current_floor_ptr->grid_array[(Y)][(X)].info = (I)) */
94 #define place_rubble(F,Y,X) set_cave_feat(F,Y,X,feat_rubble)
97 * @brief 指定座標がFLOOR属性を持ったマスかどうかを返す
100 * @return FLOOR属性を持っているならばTRUE
102 #define is_floor_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_FLOOR)
103 #define is_extra_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_EXTRA)
105 #define is_inner_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_INNER)
106 #define is_outer_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_OUTER)
107 #define is_solid_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_SOLID)
109 #define is_floor_grid(C) ((C)->info & CAVE_FLOOR)
110 #define is_extra_grid(C) ((C)->info & CAVE_EXTRA)
111 #define is_inner_grid(C) ((C)->info & CAVE_INNER)
112 #define is_outer_grid(C) ((C)->info & CAVE_OUTER)
113 #define is_solid_grid(C) ((C)->info & CAVE_SOLID)
115 #define place_floor_bold(Y, X) \
117 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_ground_type[randint0(100)]); \
118 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
119 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_FLOOR); \
120 delete_monster(Y, X); \
123 #define place_floor_grid(C) \
125 (C)->feat = feat_ground_type[randint0(100)]; \
126 (C)->info &= ~(CAVE_MASK); \
127 (C)->info |= CAVE_FLOOR; \
128 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
131 #define place_extra_bold(Y, X) \
133 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_type[randint0(100)]); \
134 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
135 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_EXTRA); \
136 delete_monster(Y, X); \
139 #define place_extra_grid(C) \
141 (C)->feat = feat_wall_type[randint0(100)]; \
142 (C)->info &= ~(CAVE_MASK); \
143 (C)->info |= CAVE_EXTRA; \
144 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
147 #define place_extra_perm_bold(Y, X) \
149 set_cave_feat(floor_ptr, Y,X,feat_permanent); \
150 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
151 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_EXTRA); \
152 delete_monster(Y, X); \
155 #define place_extra_perm_grid(C) \
157 (C)->feat = feat_permanent; \
158 (C)->info &= ~(CAVE_MASK); \
159 (C)->info |= CAVE_EXTRA; \
160 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
163 #define place_extra_noperm_bold(Y, X) \
165 feature_type *_f_ptr; \
166 set_cave_feat(floor_ptr, Y,X,feat_wall_type[randint0(100)]); \
167 _f_ptr = &f_info[p_ptr->current_floor_ptr->grid_array[Y][X].feat]; \
168 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); \
169 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
170 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_EXTRA); \
171 delete_monster(Y, X); \
174 #define place_inner_bold(Y, X) \
176 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_inner); \
177 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
178 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_INNER); \
179 delete_monster(Y, X); \
182 #define place_inner_grid(C) \
184 (C)->feat = feat_wall_inner; \
185 (C)->info &= ~(CAVE_MASK); \
186 (C)->info |= CAVE_INNER; \
187 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
190 #define place_inner_perm_bold(Y, X) \
192 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_permanent); \
193 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
194 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_INNER); \
195 delete_monster(Y, X); \
198 #define place_inner_perm_grid(C) \
200 (C)->feat = feat_permanent; \
201 (C)->info &= ~(CAVE_MASK); \
202 (C)->info |= CAVE_INNER; \
203 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
206 #define place_outer_bold(Y, X) \
208 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_outer); \
209 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
210 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_OUTER); \
211 delete_monster(Y, X); \
214 #define place_outer_grid(C) \
216 (C)->feat = feat_wall_outer; \
217 (C)->info &= ~(CAVE_MASK); \
218 (C)->info |= CAVE_OUTER; \
219 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
222 #define place_outer_perm_bold(Y, X) \
224 set_cave_feat(floor_ptr, Y,X,feat_permanent); \
225 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
226 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_OUTER); \
227 delete_monster(Y, X); \
230 #define place_outer_perm_grid(C) \
232 (C)->feat = feat_permanent; \
233 (C)->info &= ~(CAVE_MASK); \
234 (C)->info |= CAVE_OUTER; \
235 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
238 #define place_outer_noperm_bold(Y, X) \
240 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
241 if (permanent_wall(_f_ptr)) set_cave_feat(p_ptr->current_floor_ptr, Y, X, (s16b)feat_state(feat_wall_outer, FF_UNPERM)); \
242 else set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_outer); \
243 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
244 add_cave_info(p_ptr->current_floor_ptr, Y,X,(CAVE_OUTER | CAVE_VAULT)); \
245 delete_monster(Y, X); \
248 #define place_outer_noperm_grid(C) \
250 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
251 if (permanent_wall(_f_ptr)) (C)->feat = (s16b)feat_state(feat_wall_outer, FF_UNPERM); \
252 else (C)->feat = feat_wall_outer; \
253 (C)->info &= ~(CAVE_MASK); \
254 (C)->info |= (CAVE_OUTER | CAVE_VAULT); \
255 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
258 #define place_solid_bold(Y, X) \
260 set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_solid); \
261 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
262 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_SOLID); \
263 delete_monster(Y, X); \
266 #define place_solid_grid(C) \
268 (C)->feat = feat_wall_solid; \
269 (C)->info &= ~(CAVE_MASK); \
270 (C)->info |= CAVE_SOLID; \
271 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
274 #define place_solid_perm_bold(Y, X) \
276 set_cave_feat(floor_ptr, Y,X,feat_permanent); \
277 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
278 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_SOLID); \
279 delete_monster(Y, X); \
282 #define place_solid_perm_grid(C) \
284 (C)->feat = feat_permanent; \
285 (C)->info &= ~(CAVE_MASK); \
286 (C)->info |= CAVE_SOLID; \
287 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
290 #define place_solid_noperm_bold(Y, X) \
292 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
293 if ((p_ptr->current_floor_ptr->grid_array[Y][X].info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
294 set_cave_feat(p_ptr->current_floor_ptr, Y, X, feat_state(feat_wall_solid, FF_UNPERM)); \
295 else set_cave_feat(p_ptr->current_floor_ptr, Y,X,feat_wall_solid); \
296 p_ptr->current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
297 add_cave_info(p_ptr->current_floor_ptr, Y,X,CAVE_SOLID); \
298 delete_monster(Y, X); \
301 #define place_solid_noperm_grid(C) \
303 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
304 if (((C)->info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
305 (C)->feat = feat_state(feat_wall_solid, FF_UNPERM); \
306 else (C)->feat = feat_wall_solid; \
307 (C)->info &= ~(CAVE_MASK); \
308 (C)->info |= CAVE_SOLID; \
309 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
314 * 特殊なマス状態フラグ / Special grid flags
316 #define CAVE_MARK 0x0001 /*!< 現在プレイヤーの記憶に収まっている / memorized feature */
317 #define CAVE_GLOW 0x0002 /*!< マス自体が光源を持っている / self-illuminating */
318 #define CAVE_ICKY 0x0004 /*!< 生成されたVaultの一部である / part of a vault */
319 #define CAVE_ROOM 0x0008 /*!< 生成された部屋の一部である / part of a room */
320 #define CAVE_LITE 0x0010 /*!< 現在光に照らされている / lite flag */
321 #define CAVE_VIEW 0x0020 /*!< 現在プレイヤーの視界に収まっている / view flag */
322 #define CAVE_TEMP 0x0040 /*!< 光源に関する処理のアルゴリズム用記録フラグ / temp flag */
323 #define CAVE_XTRA 0x0080 /*!< 視界に関する処理のアルゴリズム用記録フラグ(update_view()等参照) / misc flag */
324 #define CAVE_MNLT 0x0100 /*!< モンスターの光源によって照らされている / Illuminated by monster */
325 #define CAVE_MNDK 0x8000 /*!< モンスターの暗源によって暗闇になっている / Darken by monster */
327 /* Used only while p_ptr->current_floor_ptr->grid_array generation */
328 #define CAVE_FLOOR 0x0200 /*!< フロア属性のあるマス */
329 #define CAVE_EXTRA 0x0400
330 #define CAVE_INNER 0x0800
331 #define CAVE_OUTER 0x1000
332 #define CAVE_SOLID 0x2000
333 #define CAVE_VAULT 0x4000
334 #define CAVE_MASK (CAVE_FLOOR | CAVE_EXTRA | CAVE_INNER | CAVE_OUTER | CAVE_SOLID | CAVE_VAULT)
336 /* Used only after p_ptr->current_floor_ptr->grid_array generation */
337 #define CAVE_KNOWN 0x0200 /* Directly viewed or map detected flag */
338 #define CAVE_NOTE 0x0400 /* Flag for delayed visual update (needs note_spot()) */
339 #define CAVE_REDRAW 0x0800 /* Flag for delayed visual update (needs lite_spot()) */
340 #define CAVE_OBJECT 0x1000 /* Mirror, glyph, etc. */
341 #define CAVE_UNSAFE 0x2000 /* Might have trap */
342 #define CAVE_IN_DETECT 0x4000 /* trap detected area (inner circle only) */
344 /* Types of conversions */
345 #define CONVERT_TYPE_FLOOR 0
346 #define CONVERT_TYPE_WALL 1
347 #define CONVERT_TYPE_INNER 2
348 #define CONVERT_TYPE_OUTER 3
349 #define CONVERT_TYPE_SOLID 4
350 #define CONVERT_TYPE_STREAM1 5
351 #define CONVERT_TYPE_STREAM2 6
355 extern bool new_player_spot(void);
357 extern void place_random_stairs(POSITION y, POSITION x);
358 extern void place_random_door(POSITION y, POSITION x, bool room);
359 extern void add_door(POSITION x, POSITION y);
362 #define DOOR_DEFAULT -1
364 #define DOOR_GLASS_DOOR 1
365 #define DOOR_CURTAIN 2
367 #define MAX_DOOR_TYPES 3
368 extern void place_closed_door(POSITION y, POSITION x, int type);
369 extern void place_secret_door(POSITION y, POSITION x, int type);
371 extern void place_locked_door(POSITION y, POSITION x);
372 extern void try_door(POSITION y, POSITION x);
373 extern void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
374 extern void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
375 extern void vault_monsters(POSITION y1, POSITION x1, int num);
376 extern void vault_objects(POSITION y, POSITION x, int num);
377 extern void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd);
378 extern void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num);
380 extern bool get_is_floor(POSITION x, POSITION y);
381 extern void set_floor(POSITION x, POSITION y);
382 extern void place_bound_perm_wall(grid_type *g_ptr);
384 extern bool is_known_trap(grid_type *g_ptr);
385 extern bool is_hidden_door(grid_type *g_ptr);
386 extern bool is_mirror_grid(grid_type *g_ptr);
387 extern bool is_glyph_grid(grid_type *g_ptr);
388 extern bool is_explosive_rune_grid(grid_type *g_ptr);
390 extern bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode);
393 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
395 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
398 extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
399 extern bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
400 extern void update_local_illumination(player_type *creature_ptr, POSITION y, POSITION x);
401 extern bool player_can_see_bold(POSITION y, POSITION x);
402 extern bool cave_valid_bold(POSITION y, POSITION x);
403 extern bool no_lite(void);
404 extern void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp);
405 extern void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x);
406 extern void note_spot(POSITION y, POSITION x);
407 extern void lite_spot(POSITION y, POSITION x);
408 extern void delayed_visual_update(void);
409 extern void forget_flow(void);
410 extern void update_flow(void);
411 extern void update_smell(void);
412 extern void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat);
413 extern FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat);
414 extern FEAT_IDX feat_state(FEAT_IDX feat, int action);
415 extern void cave_alter_feat(POSITION y, POSITION x, int action);
416 extern void remove_mirror(POSITION y, POSITION x);
417 extern bool is_open(FEAT_IDX feat);
418 extern bool check_local_illumination(POSITION y, POSITION x);
420 extern bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode);
421 extern bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode);
425 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
427 #define darkened_grid(C) \
428 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
432 * Get feature mimic from f_info[] (applying "mimic" field)
434 #define get_feat_mimic(C) \
435 (f_info[(C)->mimic ? (C)->mimic : (C)->feat].mimic)
438 * This macro allows us to efficiently add a grid to the "lite" array,
439 * note that we are never called for illegal grids, or for grids which
440 * have already been placed into the "lite" array, and we are never
441 * called when the "lite" array is full.
443 #define cave_lite_hack(F, Y,X) \
445 if (!((F)->grid_array[Y][X].info & (CAVE_LITE))) \
447 (F)->grid_array[Y][X].info |= (CAVE_LITE); \
448 (F)->lite_y[p_ptr->current_floor_ptr->lite_n] = (Y); \
449 (F)->lite_x[p_ptr->current_floor_ptr->lite_n++] = (X); \
454 * For delayed visual update
456 #define cave_note_and_redraw_later(C,Y,X) \
458 (C)->info |= CAVE_NOTE; \
459 cave_redraw_later((C), (Y), (X)); \
463 * For delayed visual update
465 #define cave_redraw_later(C,Y,X) \
467 if (!((C)->info & CAVE_REDRAW)) \
469 (C)->info |= CAVE_REDRAW; \
470 p_ptr->current_floor_ptr->redraw_y[p_ptr->current_floor_ptr->redraw_n] = (Y); \
471 p_ptr->current_floor_ptr->redraw_x[p_ptr->current_floor_ptr->redraw_n++] = (X); \
476 * This macro allows us to efficiently add a grid to the "view" array,
477 * note that we are never called for illegal grids, or for grids which
478 * have already been placed into the "view" array, and we are never
479 * called when the "view" array is full.
481 #define cave_view_hack(C,Y,X) \
483 if (!((C)->info & (CAVE_VIEW))){\
484 (C)->info |= (CAVE_VIEW); \
485 p_ptr->current_floor_ptr->view_y[p_ptr->current_floor_ptr->view_n] = (Y); \
486 p_ptr->current_floor_ptr->view_x[p_ptr->current_floor_ptr->view_n] = (X); \
487 p_ptr->current_floor_ptr->view_n++;}\