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 grid
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 * ">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 -- grid 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 grid 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
82 #define feat_locked_door_random(DOOR_TYPE) \
83 (feat_door[(DOOR_TYPE)].num_locked ? \
84 feat_door[(DOOR_TYPE)].locked[randint0(feat_door[(DOOR_TYPE)].num_locked)] : feat_none)
86 #define feat_jammed_door_random(DOOR_TYPE) \
87 (feat_door[(DOOR_TYPE)].num_jammed ? \
88 feat_door[(DOOR_TYPE)].jammed[randint0(feat_door[(DOOR_TYPE)].num_jammed)] : feat_none)
91 #define set_cave_feat(FL,Y,X,F) ((FL)->grid_array[(Y)][(X)].feat = (F))
92 #define add_cave_info(FL,Y,X,I) ((FL)->grid_array[(Y)][(X)].info |= (I))
99 #define place_rubble(F,Y,X) set_cave_feat(F,Y,X,feat_rubble)
102 * @brief 指定座標がFLOOR属性を持ったマスかどうかを返す
105 * @return FLOOR属性を持っているならばTRUE
107 #define is_floor_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_FLOOR)
108 #define is_extra_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_EXTRA)
110 #define is_inner_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_INNER)
111 #define is_outer_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_OUTER)
112 #define is_solid_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_SOLID)
114 #define is_floor_grid(C) ((C)->info & CAVE_FLOOR)
115 #define is_extra_grid(C) ((C)->info & CAVE_EXTRA)
116 #define is_inner_grid(C) ((C)->info & CAVE_INNER)
117 #define is_outer_grid(C) ((C)->info & CAVE_OUTER)
118 #define is_solid_grid(C) ((C)->info & CAVE_SOLID)
120 #define place_floor_bold(F, Y, X) \
122 set_cave_feat((F), Y,X,feat_ground_type[randint0(100)]); \
123 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
124 add_cave_info((F), Y,X,CAVE_FLOOR); \
125 delete_monster(F, Y, X); \
128 #define place_extra_bold(F, Y, X) \
130 set_cave_feat((F), Y,X,feat_wall_type[randint0(100)]); \
131 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
132 add_cave_info((F), Y,X,CAVE_EXTRA); \
133 delete_monster(F, Y, X); \
136 #define place_extra_perm_bold(F, Y, X) \
138 set_cave_feat(F, Y, X,feat_permanent); \
139 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
140 add_cave_info(F, Y, X, CAVE_EXTRA); \
141 delete_monster(F, Y, X); \
144 #define place_extra_noperm_bold(F, Y, X) \
146 feature_type *_f_ptr; \
147 set_cave_feat((F), Y,X,feat_wall_type[randint0(100)]); \
148 _f_ptr = &f_info[(F)->grid_array[Y][X].feat]; \
149 if (permanent_wall(_f_ptr)) (F)->grid_array[Y][X].feat = feat_state((F)->grid_array[Y][X].feat, FF_UNPERM); \
150 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
151 add_cave_info((F), Y, X, CAVE_EXTRA); \
152 delete_monster(Y, X); \
155 #define place_inner_bold(F, Y, X) \
157 set_cave_feat((F), Y, X, feat_wall_inner); \
158 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
159 add_cave_info((F), Y, X, CAVE_INNER); \
160 delete_monster(F, Y, X); \
163 #define place_inner_perm_bold(F, Y, X) \
165 set_cave_feat(F, Y,X,feat_permanent); \
166 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
167 add_cave_info((F), Y,X,CAVE_INNER); \
168 delete_monster(F, Y, X); \
171 #define place_outer_bold(F, Y, X) \
173 set_cave_feat((F), Y, X, feat_wall_outer); \
174 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
175 add_cave_info((F), Y,X,CAVE_OUTER); \
176 delete_monster(F, Y, X); \
179 #define place_outer_perm_bold(F, Y, X) \
181 set_cave_feat(F, Y, X, feat_permanent); \
182 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
183 add_cave_info((F), Y,X,CAVE_OUTER); \
184 delete_monster(F, Y, X); \
187 #define place_outer_noperm_bold(F, Y, X) \
189 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
190 if (permanent_wall(_f_ptr)) set_cave_feat((F), Y, X, (s16b)feat_state(feat_wall_outer, FF_UNPERM)); \
191 else set_cave_feat((F), Y,X,feat_wall_outer); \
192 (F)->grid_array[Y][X].info &= ~(CAVE_MASK); \
193 add_cave_info((F), Y,X,(CAVE_OUTER | CAVE_VAULT)); \
194 delete_monster(F, Y, X); \
197 #define place_solid_bold(F, Y, X) \
199 set_cave_feat(F,Y,X,feat_wall_solid); \
200 F->grid_array[Y][X].info &= ~(CAVE_MASK); \
201 add_cave_info(F,Y,X,CAVE_SOLID); \
202 delete_monster(F, Y, X); \
205 #define place_solid_perm_bold(F, Y, X) \
207 set_cave_feat(F, Y, X, feat_permanent); \
208 F->grid_array[Y][X].info &= ~(CAVE_MASK); \
209 add_cave_info(F, Y, X, CAVE_SOLID); \
210 delete_monster(F, Y, X); \
213 #define place_solid_noperm_bold(F, Y, X) \
215 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
216 if ((F->grid_array[Y][X].info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
217 set_cave_feat(F, Y, X, feat_state(feat_wall_solid, FF_UNPERM)); \
218 else set_cave_feat(F, Y, X, feat_wall_solid); \
219 F->grid_array[Y][X].info &= ~(CAVE_MASK); \
220 add_cave_info(F, Y, X, CAVE_SOLID); \
221 delete_monster(F, Y, X); \
226 * 特殊なマス状態フラグ / Special grid flags
228 #define CAVE_MARK 0x0001 /*!< 現在プレイヤーの記憶に収まっている / memorized feature */
229 #define CAVE_GLOW 0x0002 /*!< マス自体が光源を持っている / self-illuminating */
230 #define CAVE_ICKY 0x0004 /*!< 生成されたVaultの一部である / part of a vault */
231 #define CAVE_ROOM 0x0008 /*!< 生成された部屋の一部である / part of a room */
232 #define CAVE_LITE 0x0010 /*!< 現在光に照らされている / lite flag */
233 #define CAVE_VIEW 0x0020 /*!< 現在プレイヤーの視界に収まっている / view flag */
234 #define CAVE_TEMP 0x0040 /*!< 光源に関する処理のアルゴリズム用記録フラグ / temp flag */
235 #define CAVE_XTRA 0x0080 /*!< 視界に関する処理のアルゴリズム用記録フラグ(update_view()等参照) / misc flag */
236 #define CAVE_MNLT 0x0100 /*!< モンスターの光源によって照らされている / Illuminated by monster */
237 #define CAVE_MNDK 0x8000 /*!< モンスターの暗源によって暗闇になっている / Darken by monster */
239 /* Used only while floor generation */
240 #define CAVE_FLOOR 0x0200 /*!< フロア属性のあるマス */
241 #define CAVE_EXTRA 0x0400
242 #define CAVE_INNER 0x0800
243 #define CAVE_OUTER 0x1000
244 #define CAVE_SOLID 0x2000
245 #define CAVE_VAULT 0x4000
246 #define CAVE_MASK (CAVE_FLOOR | CAVE_EXTRA | CAVE_INNER | CAVE_OUTER | CAVE_SOLID | CAVE_VAULT)
248 /* Used only after floor generation */
249 #define CAVE_KNOWN 0x0200 /* Directly viewed or map detected flag */
250 #define CAVE_NOTE 0x0400 /* Flag for delayed visual update (needs note_spot()) */
251 #define CAVE_REDRAW 0x0800 /* Flag for delayed visual update (needs lite_spot()) */
252 #define CAVE_OBJECT 0x1000 /* Mirror, glyph, etc. */
253 #define CAVE_UNSAFE 0x2000 /* Might have trap */
254 #define CAVE_IN_DETECT 0x4000 /* trap detected area (inner circle only) */
256 /* Types of conversions */
257 #define CONVERT_TYPE_FLOOR 0
258 #define CONVERT_TYPE_WALL 1
259 #define CONVERT_TYPE_INNER 2
260 #define CONVERT_TYPE_OUTER 3
261 #define CONVERT_TYPE_SOLID 4
262 #define CONVERT_TYPE_STREAM1 5
263 #define CONVERT_TYPE_STREAM2 6
267 extern bool new_player_spot(player_type *creature_ptr);
270 #define DOOR_DEFAULT -1
272 #define DOOR_GLASS_DOOR 1
273 #define DOOR_CURTAIN 2
275 #define MAX_DOOR_TYPES 3
277 extern void place_bound_perm_wall(grid_type *g_ptr);
279 extern bool is_known_trap(grid_type *g_ptr);
280 extern bool is_hidden_door(grid_type *g_ptr);
281 extern bool is_mirror_grid(grid_type *g_ptr);
282 extern bool is_glyph_grid(grid_type *g_ptr);
283 extern bool is_explosive_rune_grid(grid_type *g_ptr);
285 extern bool player_can_enter(player_type *creature_ptr, FEAT_IDX feature, BIT_FLAGS16 mode);
288 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
290 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
293 extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
294 extern void update_local_illumination(player_type *creature_ptr, POSITION y, POSITION x);
295 extern bool no_lite(player_type *creature_ptr);
296 extern void print_rel(player_type *subject_ptr, SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x);
297 extern void note_spot(POSITION y, POSITION x);
298 extern void lite_spot(POSITION y, POSITION x);
299 extern void update_flow(player_type *subject_ptr);
300 extern FEAT_IDX feat_state(FEAT_IDX feat, int action);
301 extern void cave_alter_feat(player_type *player_ptr, POSITION y, POSITION x, int action);
302 extern void remove_mirror(player_type *caster_ptr, POSITION y, POSITION x);
303 extern bool is_open(FEAT_IDX feat);
304 extern bool check_local_illumination(player_type *creature_ptr, POSITION y, POSITION x);
306 extern bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode);
307 extern bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode);
309 typedef enum place_grid_type
320 extern void place_outer_noperm_grid(grid_type *g_ptr);
321 extern void place_solid_perm_grid(grid_type *g_ptr);
322 extern void place_grid(grid_type *g_ptr, place_grid_type pg_type);
323 extern bool darkened_grid(player_type *player_ptr, grid_type *g_ptr);
326 * Get feature mimic from f_info[] (applying "mimic" field)
328 #define get_feat_mimic(C) \
329 (f_info[(C)->mimic ? (C)->mimic : (C)->feat].mimic)
332 * This macro allows us to efficiently add a grid to the "lite" array,
333 * note that we are never called for illegal grids, or for grids which
334 * have already been placed into the "lite" array, and we are never
335 * called when the "lite" array is full.
337 #define cave_lite_hack(F,Y,X) \
339 if (!((F)->grid_array[Y][X].info & (CAVE_LITE))) \
341 (F)->grid_array[Y][X].info |= (CAVE_LITE); \
342 (F)->lite_y[(F)->lite_n] = (Y); \
343 (F)->lite_x[(F)->lite_n++] = (X); \
348 * For delayed visual update
350 #define cave_note_and_redraw_later(F,C,Y,X) \
352 (C)->info |= CAVE_NOTE; \
353 cave_redraw_later((F), (C), (Y), (X)); \
357 * For delayed visual update
359 #define cave_redraw_later(F,G,Y,X) \
361 if (!((G)->info & CAVE_REDRAW)) \
363 (G)->info |= CAVE_REDRAW; \
364 (F)->redraw_y[(F)->redraw_n] = (Y); \
365 (F)->redraw_x[(F)->redraw_n++] = (X); \
370 * This macro allows us to efficiently add a grid to the "view" array,
371 * note that we are never called for illegal grids, or for grids which
372 * have already been placed into the "view" array, and we are never
373 * called when the "view" array is full.
375 #define cave_view_hack(F,C,Y,X) \
377 if (!((C)->info & (CAVE_VIEW))){\
378 (C)->info |= (CAVE_VIEW); \
379 (F)->view_y[(F)->view_n] = (Y); \
380 (F)->view_x[(F)->view_n] = (X); \