OSDN Git Service

[Refactor] #38862 Moved feature.c/h, grid.c/h and trap.c/h to grid/
[hengbandforosx/hengbandosx.git] / src / grid / grid.h
1 #pragma once
2
3 /*!
4  * @file grid.h
5  * @brief ダンジョンの生成処理の基幹部分ヘッダーファイル
6  * @date 2014/08/15
7  * @details
8  * Purpose: header file for grid.c, used only in dungeon generation
9  * files (generate.c, rooms.c)
10  * @author
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.
15  */
16
17 #include "spell/spells-util.h"
18
19  /*
20   * A single "grid" in a Cave
21   *
22   * Note that several aspects of the code restrict the actual grid
23   * to a max size of 256 by 256.  In partcular, locations are often
24   * saved as bytes, limiting each coordinate to the 0-255 range.
25   *
26   * The "o_idx" and "m_idx" fields are very interesting.  There are
27   * many places in the code where we need quick access to the actual
28   * monster or object(s) in a given grid.  The easiest way to
29   * do this is to simply keep the index of the monster and object
30   * (if any) with the grid, but this takes 198*66*4 bytes of memory.
31   * Several other methods come to mind, which require only half this
32   * amound of memory, but they all seem rather complicated, and would
33   * probably add enough code that the savings would be lost.  So for
34   * these reasons, we simply store an index into the "o_list" and
35   * ">m_list" arrays, using "zero" when no monster/object is present.
36   *
37   * Note that "o_idx" is the index of the top object in a stack of
38   * objects, using the "next_o_idx" field of objects (see below) to
39   * create the singly linked list of objects.  If "o_idx" is zero
40   * then there are no objects in the grid.
41   *
42   * Note the special fields for the "MONSTER_FLOW" code.
43   */
44
45 typedef struct grid_type grid_type;
46
47 struct grid_type
48 {
49         BIT_FLAGS info;         /* Hack -- grid flags */
50
51         FEAT_IDX feat;          /* Hack -- feature type */
52         OBJECT_IDX o_idx;               /* Object in this grid */
53         MONSTER_IDX m_idx;              /* Monster in this grid */
54
55         /*! 地形の特別な情報を保存する / Special grid info
56          * 具体的な使用一覧はクエスト行き階段の移行先クエストID、
57          * 各ダンジョン入口の移行先ダンジョンID、
58          *
59          */
60         s16b special;
61
62         FEAT_IDX mimic;         /* Feature to mimic */
63
64         byte cost;              /* Hack -- cost of flowing */
65         byte dist;              /* Hack -- distance from player */
66         byte when;              /* Hack -- when cost was computed */
67 };
68
69 /*
70  *  A structure type for terrain template of saving dungeon floor
71  */
72 typedef struct
73 {
74         BIT_FLAGS info;
75         FEAT_IDX feat;
76         FEAT_IDX mimic;
77         s16b special;
78         u16b occurrence;
79 } grid_template_type;
80
81 #define feat_locked_door_random(DOOR_TYPE) \
82         (feat_door[(DOOR_TYPE)].num_locked ? \
83          feat_door[(DOOR_TYPE)].locked[randint0(feat_door[(DOOR_TYPE)].num_locked)] : feat_none)
84
85 #define feat_jammed_door_random(DOOR_TYPE) \
86         (feat_door[(DOOR_TYPE)].num_jammed ? \
87          feat_door[(DOOR_TYPE)].jammed[randint0(feat_door[(DOOR_TYPE)].num_jammed)] : feat_none)
88
89 /* Macros */
90 #define set_cave_feat(FL,Y,X,F)    ((FL)->grid_array[(Y)][(X)].feat = (F))
91 #define add_cave_info(FL,Y,X,I)    ((FL)->grid_array[(Y)][(X)].info |= (I))
92
93 /*!
94  * @brief 指定座標に瓦礫を配置する
95  * @param Y 指定Y座標
96  * @param X 指定X座標
97  */
98 #define place_rubble(F,Y,X)       set_cave_feat(F,Y,X,feat_rubble)
99
100 /*!
101  * @brief 指定座標がFLOOR属性を持ったマスかどうかを返す
102  * @param Y 指定Y座標
103  * @param X 指定X座標
104  * @return FLOOR属性を持っているならばTRUE
105  */
106 #define is_floor_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_FLOOR)
107 #define is_extra_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_EXTRA)
108
109 #define is_inner_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_INNER)
110 #define is_outer_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_OUTER)
111 #define is_solid_bold(F,Y,X) (F->grid_array[Y][X].info & CAVE_SOLID)
112
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)
118
119 /*
120  * 特殊なマス状態フラグ / Special grid flags
121  */
122 #define CAVE_MARK       0x0001    /*!< 現在プレイヤーの記憶に収まっている / memorized feature */
123 #define CAVE_GLOW       0x0002    /*!< マス自体が光源を持っている / self-illuminating */
124 #define CAVE_ICKY       0x0004    /*!< 生成されたVaultの一部である / part of a vault */
125 #define CAVE_ROOM       0x0008    /*!< 生成された部屋の一部である / part of a room */
126 #define CAVE_LITE       0x0010    /*!< 現在光に照らされている / lite flag  */
127 #define CAVE_VIEW       0x0020    /*!< 現在プレイヤーの視界に収まっている / view flag */
128 #define CAVE_TEMP       0x0040    /*!< 光源に関する処理のアルゴリズム用記録フラグ / temp flag */
129 #define CAVE_XTRA       0x0080    /*!< 視界に関する処理のアルゴリズム用記録フラグ(update_view()等参照) / misc flag */
130 #define CAVE_MNLT       0x0100    /*!< モンスターの光源によって照らされている / Illuminated by monster */
131 #define CAVE_MNDK       0x8000    /*!< モンスターの暗源によって暗闇になっている / Darken by monster */
132
133 /* Used only while floor generation */
134 #define CAVE_FLOOR      0x0200  /*!< フロア属性のあるマス */
135 #define CAVE_EXTRA      0x0400
136 #define CAVE_INNER      0x0800
137 #define CAVE_OUTER      0x1000
138 #define CAVE_SOLID      0x2000
139 #define CAVE_VAULT      0x4000
140 #define CAVE_MASK (CAVE_FLOOR | CAVE_EXTRA | CAVE_INNER | CAVE_OUTER | CAVE_SOLID | CAVE_VAULT)
141
142 /* Used only after floor generation */
143 #define CAVE_KNOWN      0x0200    /* Directly viewed or map detected flag */
144 #define CAVE_NOTE       0x0400    /* Flag for delayed visual update (needs note_spot()) */
145 #define CAVE_REDRAW     0x0800    /* Flag for delayed visual update (needs lite_spot()) */
146 #define CAVE_OBJECT     0x1000    /* Mirror, glyph, etc. */
147 #define CAVE_UNSAFE     0x2000    /* Might have trap */
148 #define CAVE_IN_DETECT  0x4000    /* trap detected area (inner circle only) */
149
150 /* Types of conversions */
151 #define CONVERT_TYPE_FLOOR   0
152 #define CONVERT_TYPE_WALL    1
153 #define CONVERT_TYPE_INNER   2
154 #define CONVERT_TYPE_OUTER   3
155 #define CONVERT_TYPE_SOLID   4
156 #define CONVERT_TYPE_STREAM1 5
157 #define CONVERT_TYPE_STREAM2 6
158
159 /* Externs */
160
161 extern bool new_player_spot(player_type *creature_ptr);
162
163 /* Types of doors */
164 #define DOOR_DEFAULT    -1
165 #define DOOR_DOOR        0
166 #define DOOR_GLASS_DOOR  1
167 #define DOOR_CURTAIN     2
168
169 #define MAX_DOOR_TYPES   3
170
171 extern void place_bound_perm_wall(player_type *player_ptr, grid_type *g_ptr);
172
173 extern bool is_known_trap(player_type *player_ptr, grid_type *g_ptr);
174 extern bool is_hidden_door(player_type *player_ptr, grid_type *g_ptr);
175 extern bool is_mirror_grid(grid_type *g_ptr);
176 extern bool is_glyph_grid(grid_type *g_ptr);
177 extern bool is_explosive_rune_grid(grid_type *g_ptr);
178
179 extern bool player_can_enter(player_type *creature_ptr, FEAT_IDX feature, BIT_FLAGS16 mode);
180
181 /*!
182  * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
183  */
184 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
185
186 /*!
187  * grids.c
188  * ここにfloor_type を引数として加えるとコンパイルエラー
189  */
190 extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
191 extern void update_local_illumination(player_type *creature_ptr, POSITION y, POSITION x);
192 extern bool no_lite(player_type *creature_ptr);
193 extern void print_rel(player_type *subject_ptr, SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x);
194 extern void note_spot(player_type *player_ptr, POSITION y, POSITION x);
195 extern void lite_spot(player_type *player_ptr, POSITION y, POSITION x);
196 extern void update_flow(player_type *subject_ptr);
197 extern FEAT_IDX feat_state(player_type *player_ptr, FEAT_IDX feat, int action);
198 extern void cave_alter_feat(player_type *player_ptr, POSITION y, POSITION x, int action);
199 extern void remove_mirror(player_type *caster_ptr, POSITION y, POSITION x);
200 extern bool is_open(player_type *player_ptr, FEAT_IDX feat);
201 extern bool check_local_illumination(player_type *creature_ptr, POSITION y, POSITION x);
202
203 extern bool cave_monster_teleportable_bold(player_type *player_ptr, MONSTER_IDX m_idx, POSITION y, POSITION x, teleport_flags mode);
204 extern bool cave_player_teleportable_bold(player_type *player_ptr, POSITION y, POSITION x, teleport_flags mode);
205
206 typedef enum
207 {
208         GB_FLOOR,
209         GB_EXTRA,
210         GB_EXTRA_PERM,
211         GB_INNER,
212         GB_INNER_PERM,
213         GB_OUTER,
214         GB_OUTER_NOPERM,
215         GB_SOLID,
216         GB_SOLID_PERM,
217         GB_SOLID_NOPERM
218 } grid_bold_type;
219
220 extern void place_grid(player_type *player_ptr, grid_type *g_ptr, grid_bold_type pg_type);
221 extern bool darkened_grid(player_type *player_ptr, grid_type *g_ptr);
222 extern void delete_monster(player_type *player_ptr, POSITION y, POSITION x);
223 extern void place_bold(player_type *player_ptr, POSITION y, POSITION x, grid_bold_type gh_type);
224
225 /*
226  * Get feature mimic from f_info[] (applying "mimic" field)
227  */
228 #define get_feat_mimic(C) \
229         (f_info[(C)->mimic ? (C)->mimic : (C)->feat].mimic)
230
231 /*
232  * This macro allows us to efficiently add a grid to the "lite" array,
233  * note that we are never called for illegal grids, or for grids which
234  * have already been placed into the "lite" array, and we are never
235  * called when the "lite" array is full.
236  */
237 #define cave_lite_hack(F,Y,X) \
238 {\
239         if (!((F)->grid_array[Y][X].info & (CAVE_LITE))) \
240         { \
241                 (F)->grid_array[Y][X].info |= (CAVE_LITE); \
242                 (F)->lite_y[(F)->lite_n] = (Y); \
243                 (F)->lite_x[(F)->lite_n++] = (X); \
244         } \
245 }
246
247 /*
248  * For delayed visual update
249  */
250 #define cave_note_and_redraw_later(F,C,Y,X) \
251 {\
252         (C)->info |= CAVE_NOTE; \
253         cave_redraw_later((F), (C), (Y), (X)); \
254 }
255
256 /*
257 * For delayed visual update
258 */
259 #define cave_redraw_later(F,G,Y,X) \
260 {\
261         if (!((G)->info & CAVE_REDRAW)) \
262         { \
263                 (G)->info |= CAVE_REDRAW; \
264                 (F)->redraw_y[(F)->redraw_n] = (Y); \
265                 (F)->redraw_x[(F)->redraw_n++] = (X); \
266         } \
267 }
268
269 /*
270  * This macro allows us to efficiently add a grid to the "view" array,
271  * note that we are never called for illegal grids, or for grids which
272  * have already been placed into the "view" array, and we are never
273  * called when the "view" array is full.
274  */
275 #define cave_view_hack(F,C,Y,X) \
276 {\
277     if (!((C)->info & (CAVE_VIEW))){\
278     (C)->info |= (CAVE_VIEW); \
279     (F)->view_y[(F)->view_n] = (Y); \
280     (F)->view_x[(F)->view_n] = (X); \
281     (F)->view_n++;}\
282 }