OSDN Git Service

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