OSDN Git Service

ad5580fdb93baaa98ba5e7e7ae804ca7c6025111
[hengband/hengband.git] / src / 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
18  /*
19   * A single "grid" in a Cave
20   *
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.
24   *
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.
35   *
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.
40   *
41   * Note the special fields for the "MONSTER_FLOW" code.
42   */
43
44 typedef struct grid_type grid_type;
45
46 struct grid_type
47 {
48         BIT_FLAGS info;         /* Hack -- current_floor_ptr->grid_array flags */
49
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 */
53
54         /*! 地形の特別な情報を保存する / Special current_floor_ptr->grid_array info
55          * 具体的な使用一覧はクエスト行き階段の移行先クエストID、
56          * 各ダンジョン入口の移行先ダンジョンID、
57          *
58          */
59         s16b special;
60
61         FEAT_IDX mimic;         /* Feature to mimic */
62
63         byte cost;              /* Hack -- cost of flowing */
64         byte dist;              /* Hack -- distance from player */
65         byte when;              /* Hack -- when cost was computed */
66 };
67
68 /* Macros */
69
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))
72
73 /* This should not be used */
74 /*#define set_cave_info(Y,X,I)    (current_floor_ptr->grid_array[(Y)][(X)].info = (I)) */
75
76 /*!
77  * @brief 指定座標が瓦礫かどうかを返す
78  * @param Y 指定Y座標
79  * @param X 指定X座標
80  * @return 瓦礫ならばTRUE
81  */
82 #define place_rubble(Y,X)       set_cave_feat(Y,X,feat_rubble)
83
84 /*!
85  * @brief 指定座標が上り階段かどうかを返す
86  * @param Y 指定Y座標
87  * @param X 指定X座標
88  * @return 上り階段ならばTRUE
89  */
90 #define place_up_stairs(Y,X)    set_cave_feat(Y,X,feat_up_stair)
91
92 /*!
93  * @brief 指定座標が下り階段かどうかを返す
94  * @param Y 指定Y座標
95  * @param X 指定X座標
96  * @return 下り階段ならばTRUE
97  */
98 #define place_down_stairs(Y,X)  set_cave_feat(Y,X,feat_down_stair)
99
100 /*!
101  * @brief 指定座標がFLOOR属性を持ったマスかどうかを返す
102  * @param Y 指定Y座標
103  * @param X 指定X座標
104  * @return FLOOR属性を持っているならばTRUE
105  */
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)
108
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)
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 #define place_floor_bold(Y, X) \
120 { \
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); \
125 }
126
127 #define place_floor_grid(C) \
128 { \
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); \
133 }
134
135 #define place_extra_bold(Y, X) \
136 { \
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); \
141 }
142
143 #define place_extra_grid(C) \
144 { \
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); \
149 }
150
151 #define place_extra_perm_bold(Y, X) \
152 { \
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); \
157 }
158
159 #define place_extra_perm_grid(C) \
160 { \
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); \
165 }
166
167 #define place_extra_noperm_bold(Y, X) \
168 { \
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); \
176 }
177
178 #define place_inner_bold(Y, X) \
179 { \
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); \
184 }
185
186 #define place_inner_grid(C) \
187 { \
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); \
192 }
193
194 #define place_inner_perm_bold(Y, X) \
195 { \
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); \
200 }
201
202 #define place_inner_perm_grid(C) \
203 { \
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); \
208 }
209
210 #define place_outer_bold(Y, X) \
211 { \
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); \
216 }
217
218 #define place_outer_grid(C) \
219 { \
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); \
224 }
225
226 #define place_outer_perm_bold(Y, X) \
227 { \
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); \
232 }
233
234 #define place_outer_perm_grid(C) \
235 { \
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); \
240 }
241
242 #define place_outer_noperm_bold(Y, X) \
243 { \
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); \
250 }
251
252 #define place_outer_noperm_grid(C) \
253 { \
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); \
260 }
261
262 #define place_solid_bold(Y, X) \
263 { \
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); \
268 }
269
270 #define place_solid_grid(C) \
271 { \
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); \
276 }
277
278 #define place_solid_perm_bold(Y, X) \
279 { \
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); \
284 }
285
286 #define place_solid_perm_grid(C) \
287 { \
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); \
292 }
293
294 #define place_solid_noperm_bold(Y, X) \
295 { \
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); \
303 }
304
305 #define place_solid_noperm_grid(C) \
306 { \
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); \
314 }
315
316
317 /*
318  * 特殊なマス状態フラグ / Special grid flags
319  */
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 */
330
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)
339
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) */
347
348 /* Externs */
349
350 extern bool new_player_spot(void);
351
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);
365
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);
369
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);
375
376 extern bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode);
377
378 /*!
379  * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
380  */
381 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
382
383 /* grids.c */
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);
407
408 /*!
409  * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
410  */
411 #define darkened_grid(C) \
412         ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
413         !p_ptr->see_nocto)
414
415 /*
416  * Get feature mimic from f_info[] (applying "mimic" field)
417  */
418 #define get_feat_mimic(C) \
419         (f_info[(C)->mimic ? (C)->mimic : (C)->feat].mimic)
420
421 /*
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.
426  */
427 #define cave_lite_hack(Y,X) \
428 {\
429         if (!(current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
430         { \
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); \
434         } \
435 }
436
437 /*
438  * For delayed visual update
439  */
440 #define cave_note_and_redraw_later(C,Y,X) \
441 {\
442         (C)->info |= CAVE_NOTE; \
443         cave_redraw_later((C), (Y), (X)); \
444 }
445
446 /*
447  * For delayed visual update
448  */
449 #define cave_redraw_later(C,Y,X) \
450 {\
451         if (!((C)->info & CAVE_REDRAW)) \
452         { \
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); \
456         } \
457 }
458
459  /*
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.
464   */
465 #define cave_view_hack(C,Y,X) \
466 {\
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++;}\
472 }
473