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 */
70 #define set_cave_feat(Y,X,F) (current_floor_ptr->grid_array[(Y)][(X)].feat = (F))
71 #define add_cave_info(Y,X,I) (current_floor_ptr->grid_array[(Y)][(X)].info |= (I))
73 /* This should not be used */
74 /*#define set_cave_info(Y,X,I) (current_floor_ptr->grid_array[(Y)][(X)].info = (I)) */
77 * @brief 指定座標が瓦礫かどうかを返す
82 #define place_rubble(Y,X) set_cave_feat(Y,X,feat_rubble)
85 * @brief 指定座標が上り階段かどうかを返す
90 #define place_up_stairs(Y,X) set_cave_feat(Y,X,feat_up_stair)
93 * @brief 指定座標が下り階段かどうかを返す
98 #define place_down_stairs(Y,X) set_cave_feat(Y,X,feat_down_stair)
101 * @brief 指定座標がFLOOR属性を持ったマスかどうかを返す
104 * @return FLOOR属性を持っているならばTRUE
106 #define is_floor_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_FLOOR)
107 #define is_extra_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_EXTRA)
109 #define is_inner_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_INNER)
110 #define is_outer_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_OUTER)
111 #define is_solid_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_SOLID)
113 #define is_floor_grid(C) ((C)->info & CAVE_FLOOR)
114 #define is_extra_grid(C) ((C)->info & CAVE_EXTRA)
115 #define is_inner_grid(C) ((C)->info & CAVE_INNER)
116 #define is_outer_grid(C) ((C)->info & CAVE_OUTER)
117 #define is_solid_grid(C) ((C)->info & CAVE_SOLID)
119 #define place_floor_bold(Y, X) \
121 set_cave_feat(Y,X,feat_ground_type[randint0(100)]); \
122 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
123 add_cave_info(Y,X,CAVE_FLOOR); \
124 delete_monster(Y, X); \
127 #define place_floor_grid(C) \
129 (C)->feat = feat_ground_type[randint0(100)]; \
130 (C)->info &= ~(CAVE_MASK); \
131 (C)->info |= CAVE_FLOOR; \
132 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
135 #define place_extra_bold(Y, X) \
137 set_cave_feat(Y,X,feat_wall_type[randint0(100)]); \
138 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
139 add_cave_info(Y,X,CAVE_EXTRA); \
140 delete_monster(Y, X); \
143 #define place_extra_grid(C) \
145 (C)->feat = feat_wall_type[randint0(100)]; \
146 (C)->info &= ~(CAVE_MASK); \
147 (C)->info |= CAVE_EXTRA; \
148 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
151 #define place_extra_perm_bold(Y, X) \
153 set_cave_feat(Y,X,feat_permanent); \
154 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
155 add_cave_info(Y,X,CAVE_EXTRA); \
156 delete_monster(Y, X); \
159 #define place_extra_perm_grid(C) \
161 (C)->feat = feat_permanent; \
162 (C)->info &= ~(CAVE_MASK); \
163 (C)->info |= CAVE_EXTRA; \
164 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
167 #define place_extra_noperm_bold(Y, X) \
169 feature_type *_f_ptr; \
170 set_cave_feat(Y,X,feat_wall_type[randint0(100)]); \
171 _f_ptr = &f_info[current_floor_ptr->grid_array[Y][X].feat]; \
172 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); \
173 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
174 add_cave_info(Y,X,CAVE_EXTRA); \
175 delete_monster(Y, X); \
178 #define place_inner_bold(Y, X) \
180 set_cave_feat(Y,X,feat_wall_inner); \
181 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
182 add_cave_info(Y,X,CAVE_INNER); \
183 delete_monster(Y, X); \
186 #define place_inner_grid(C) \
188 (C)->feat = feat_wall_inner; \
189 (C)->info &= ~(CAVE_MASK); \
190 (C)->info |= CAVE_INNER; \
191 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
194 #define place_inner_perm_bold(Y, X) \
196 set_cave_feat(Y,X,feat_permanent); \
197 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
198 add_cave_info(Y,X,CAVE_INNER); \
199 delete_monster(Y, X); \
202 #define place_inner_perm_grid(C) \
204 (C)->feat = feat_permanent; \
205 (C)->info &= ~(CAVE_MASK); \
206 (C)->info |= CAVE_INNER; \
207 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
210 #define place_outer_bold(Y, X) \
212 set_cave_feat(Y,X,feat_wall_outer); \
213 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
214 add_cave_info(Y,X,CAVE_OUTER); \
215 delete_monster(Y, X); \
218 #define place_outer_grid(C) \
220 (C)->feat = feat_wall_outer; \
221 (C)->info &= ~(CAVE_MASK); \
222 (C)->info |= CAVE_OUTER; \
223 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
226 #define place_outer_perm_bold(Y, X) \
228 set_cave_feat(Y,X,feat_permanent); \
229 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
230 add_cave_info(Y,X,CAVE_OUTER); \
231 delete_monster(Y, X); \
234 #define place_outer_perm_grid(C) \
236 (C)->feat = feat_permanent; \
237 (C)->info &= ~(CAVE_MASK); \
238 (C)->info |= CAVE_OUTER; \
239 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
242 #define place_outer_noperm_bold(Y, X) \
244 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
245 if (permanent_wall(_f_ptr)) set_cave_feat(Y, X, (s16b)feat_state(feat_wall_outer, FF_UNPERM)); \
246 else set_cave_feat(Y,X,feat_wall_outer); \
247 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
248 add_cave_info(Y,X,(CAVE_OUTER | CAVE_VAULT)); \
249 delete_monster(Y, X); \
252 #define place_outer_noperm_grid(C) \
254 feature_type *_f_ptr = &f_info[feat_wall_outer]; \
255 if (permanent_wall(_f_ptr)) (C)->feat = (s16b)feat_state(feat_wall_outer, FF_UNPERM); \
256 else (C)->feat = feat_wall_outer; \
257 (C)->info &= ~(CAVE_MASK); \
258 (C)->info |= (CAVE_OUTER | CAVE_VAULT); \
259 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
262 #define place_solid_bold(Y, X) \
264 set_cave_feat(Y,X,feat_wall_solid); \
265 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
266 add_cave_info(Y,X,CAVE_SOLID); \
267 delete_monster(Y, X); \
270 #define place_solid_grid(C) \
272 (C)->feat = feat_wall_solid; \
273 (C)->info &= ~(CAVE_MASK); \
274 (C)->info |= CAVE_SOLID; \
275 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
278 #define place_solid_perm_bold(Y, X) \
280 set_cave_feat(Y,X,feat_permanent); \
281 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
282 add_cave_info(Y,X,CAVE_SOLID); \
283 delete_monster(Y, X); \
286 #define place_solid_perm_grid(C) \
288 (C)->feat = feat_permanent; \
289 (C)->info &= ~(CAVE_MASK); \
290 (C)->info |= CAVE_SOLID; \
291 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
294 #define place_solid_noperm_bold(Y, X) \
296 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
297 if ((current_floor_ptr->grid_array[Y][X].info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
298 set_cave_feat(Y, X, feat_state(feat_wall_solid, FF_UNPERM)); \
299 else set_cave_feat(Y,X,feat_wall_solid); \
300 current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
301 add_cave_info(Y,X,CAVE_SOLID); \
302 delete_monster(Y, X); \
305 #define place_solid_noperm_grid(C) \
307 feature_type *_f_ptr = &f_info[feat_wall_solid]; \
308 if (((C)->info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
309 (C)->feat = feat_state(feat_wall_solid, FF_UNPERM); \
310 else (C)->feat = feat_wall_solid; \
311 (C)->info &= ~(CAVE_MASK); \
312 (C)->info |= CAVE_SOLID; \
313 if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
318 * 特殊なマス状態フラグ / Special grid flags
320 #define CAVE_MARK 0x0001 /*!< 現在プレイヤーの記憶に収まっている / memorized feature */
321 #define CAVE_GLOW 0x0002 /*!< マス自体が光源を持っている / self-illuminating */
322 #define CAVE_ICKY 0x0004 /*!< 生成されたVaultの一部である / part of a vault */
323 #define CAVE_ROOM 0x0008 /*!< 生成された部屋の一部である / part of a room */
324 #define CAVE_LITE 0x0010 /*!< 現在光に照らされている / lite flag */
325 #define CAVE_VIEW 0x0020 /*!< 現在プレイヤーの視界に収まっている / view flag */
326 #define CAVE_TEMP 0x0040 /*!< 光源に関する処理のアルゴリズム用記録フラグ / temp flag */
327 #define CAVE_XTRA 0x0080 /*!< 視界に関する処理のアルゴリズム用記録フラグ(update_view()等参照) / misc flag */
328 #define CAVE_MNLT 0x0100 /*!< モンスターの光源によって照らされている / Illuminated by monster */
329 #define CAVE_MNDK 0x8000 /*!< モンスターの暗源によって暗闇になっている / Darken by monster */
331 /* Used only while current_floor_ptr->grid_array generation */
332 #define CAVE_FLOOR 0x0200 /*!< フロア属性のあるマス */
333 #define CAVE_EXTRA 0x0400
334 #define CAVE_INNER 0x0800
335 #define CAVE_OUTER 0x1000
336 #define CAVE_SOLID 0x2000
337 #define CAVE_VAULT 0x4000
338 #define CAVE_MASK (CAVE_FLOOR | CAVE_EXTRA | CAVE_INNER | CAVE_OUTER | CAVE_SOLID | CAVE_VAULT)
340 /* Used only after current_floor_ptr->grid_array generation */
341 #define CAVE_KNOWN 0x0200 /* Directly viewed or map detected flag */
342 #define CAVE_NOTE 0x0400 /* Flag for delayed visual update (needs note_spot()) */
343 #define CAVE_REDRAW 0x0800 /* Flag for delayed visual update (needs lite_spot()) */
344 #define CAVE_OBJECT 0x1000 /* Mirror, glyph, etc. */
345 #define CAVE_UNSAFE 0x2000 /* Might have trap */
346 #define CAVE_IN_DETECT 0x4000 /* trap detected area (inner circle only) */
350 extern bool new_player_spot(void);
352 extern void place_random_stairs(POSITION y, POSITION x);
353 extern void place_random_door(POSITION y, POSITION x, bool room);
354 extern void place_closed_door(POSITION y, POSITION x, int type);
355 extern void add_door(POSITION x, POSITION y);
356 extern void place_secret_door(POSITION y, POSITION x, int type);
357 extern void place_locked_door(POSITION y, POSITION x);
358 extern void try_door(POSITION y, POSITION x);
359 extern void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
360 extern void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
361 extern void vault_monsters(POSITION y1, POSITION x1, int num);
362 extern void vault_objects(POSITION y, POSITION x, int num);
363 extern void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd);
364 extern void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num);
366 extern bool get_is_floor(POSITION x, POSITION y);
367 extern void set_floor(POSITION x, POSITION y);
368 extern void place_bound_perm_wall(grid_type *g_ptr);
370 extern bool is_known_trap(grid_type *g_ptr);
371 extern bool is_hidden_door(grid_type *g_ptr);
372 extern bool is_mirror_grid(grid_type *g_ptr);
373 extern bool is_glyph_grid(grid_type *g_ptr);
374 extern bool is_explosive_rune_grid(grid_type *g_ptr);
376 extern bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode);
379 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
381 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
384 extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
385 extern bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
386 extern void update_local_illumination(POSITION y, POSITION x);
387 extern bool player_can_see_bold(POSITION y, POSITION x);
388 extern bool cave_valid_bold(POSITION y, POSITION x);
389 extern bool no_lite(void);
390 extern void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp);
391 extern void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x);
392 extern void note_spot(POSITION y, POSITION x);
393 extern void lite_spot(POSITION y, POSITION x);
394 extern void prt_map(void);
395 extern void display_map(int *cy, int *cx);
396 extern void delayed_visual_update(void);
397 extern void forget_flow(void);
398 extern void update_flow(void);
399 extern void update_smell(void);
400 extern void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat);
401 extern FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat);
402 extern FEAT_IDX feat_state(FEAT_IDX feat, int action);
403 extern void cave_alter_feat(POSITION y, POSITION x, int action);
404 extern void remove_mirror(POSITION y, POSITION x);
405 extern bool is_open(FEAT_IDX feat);
406 extern bool check_local_illumination(POSITION y, POSITION x);
409 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
411 #define darkened_grid(C) \
412 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
416 * Get feature mimic from f_info[] (applying "mimic" field)
418 #define get_feat_mimic(C) \
419 (f_info[(C)->mimic ? (C)->mimic : (C)->feat].mimic)
422 * This macro allows us to efficiently add a grid to the "lite" array,
423 * note that we are never called for illegal grids, or for grids which
424 * have already been placed into the "lite" array, and we are never
425 * called when the "lite" array is full.
427 #define cave_lite_hack(Y,X) \
429 if (!(current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
431 current_floor_ptr->grid_array[Y][X].info |= (CAVE_LITE); \
432 current_floor_ptr->lite_y[current_floor_ptr->lite_n] = (Y); \
433 current_floor_ptr->lite_x[current_floor_ptr->lite_n++] = (X); \
438 * For delayed visual update
440 #define cave_note_and_redraw_later(C,Y,X) \
442 (C)->info |= CAVE_NOTE; \
443 cave_redraw_later((C), (Y), (X)); \
447 * For delayed visual update
449 #define cave_redraw_later(C,Y,X) \
451 if (!((C)->info & CAVE_REDRAW)) \
453 (C)->info |= CAVE_REDRAW; \
454 current_floor_ptr->redraw_y[current_floor_ptr->redraw_n] = (Y); \
455 current_floor_ptr->redraw_x[current_floor_ptr->redraw_n++] = (X); \
460 * This macro allows us to efficiently add a grid to the "view" array,
461 * note that we are never called for illegal grids, or for grids which
462 * have already been placed into the "view" array, and we are never
463 * called when the "view" array is full.
465 #define cave_view_hack(C,Y,X) \
467 if (!((C)->info & (CAVE_VIEW))){\
468 (C)->info |= (CAVE_VIEW); \
469 current_floor_ptr->view_y[current_floor_ptr->view_n] = (Y); \
470 current_floor_ptr->view_x[current_floor_ptr->view_n] = (X); \
471 current_floor_ptr->view_n++;}\