OSDN Git Service

[Refactor] #37353 targeting.h と japanese.h コミットし忘れ修正.
[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 /*
69  *  A structure type for terrain template of saving dungeon floor
70  */
71 typedef struct
72 {
73         BIT_FLAGS info;
74         FEAT_IDX feat;
75         FEAT_IDX mimic;
76         s16b special;
77         u16b occurrence;
78 } grid_template_type;
79
80 /* Macros */
81
82 #define set_cave_feat(Y,X,F)    (current_floor_ptr->grid_array[(Y)][(X)].feat = (F))
83 #define add_cave_info(Y,X,I)    (current_floor_ptr->grid_array[(Y)][(X)].info |= (I))
84
85 /* This should not be used */
86 /*#define set_cave_info(Y,X,I)    (current_floor_ptr->grid_array[(Y)][(X)].info = (I)) */
87
88 /*!
89  * @brief 指定座標が瓦礫かどうかを返す
90  * @param Y 指定Y座標
91  * @param X 指定X座標
92  * @return 瓦礫ならばTRUE
93  */
94 #define place_rubble(Y,X)       set_cave_feat(Y,X,feat_rubble)
95
96 /*!
97  * @brief 指定座標が上り階段かどうかを返す
98  * @param Y 指定Y座標
99  * @param X 指定X座標
100  * @return 上り階段ならばTRUE
101  */
102 #define place_up_stairs(Y,X)    set_cave_feat(Y,X,feat_up_stair)
103
104 /*!
105  * @brief 指定座標が下り階段かどうかを返す
106  * @param Y 指定Y座標
107  * @param X 指定X座標
108  * @return 下り階段ならばTRUE
109  */
110 #define place_down_stairs(Y,X)  set_cave_feat(Y,X,feat_down_stair)
111
112 /*!
113  * @brief 指定座標がFLOOR属性を持ったマスかどうかを返す
114  * @param Y 指定Y座標
115  * @param X 指定X座標
116  * @return FLOOR属性を持っているならばTRUE
117  */
118 #define is_floor_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_FLOOR)
119 #define is_extra_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_EXTRA)
120
121 #define is_inner_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_INNER)
122 #define is_outer_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_OUTER)
123 #define is_solid_bold(Y,X) (current_floor_ptr->grid_array[Y][X].info & CAVE_SOLID)
124
125 #define is_floor_grid(C) ((C)->info & CAVE_FLOOR)
126 #define is_extra_grid(C) ((C)->info & CAVE_EXTRA)
127 #define is_inner_grid(C) ((C)->info & CAVE_INNER)
128 #define is_outer_grid(C) ((C)->info & CAVE_OUTER)
129 #define is_solid_grid(C) ((C)->info & CAVE_SOLID)
130
131 #define place_floor_bold(Y, X) \
132 { \
133         set_cave_feat(Y,X,feat_ground_type[randint0(100)]); \
134         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
135         add_cave_info(Y,X,CAVE_FLOOR); \
136         delete_monster(Y, X); \
137 }
138
139 #define place_floor_grid(C) \
140 { \
141         (C)->feat = feat_ground_type[randint0(100)]; \
142         (C)->info &= ~(CAVE_MASK); \
143         (C)->info |= CAVE_FLOOR; \
144         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
145 }
146
147 #define place_extra_bold(Y, X) \
148 { \
149         set_cave_feat(Y,X,feat_wall_type[randint0(100)]); \
150         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
151         add_cave_info(Y,X,CAVE_EXTRA); \
152         delete_monster(Y, X); \
153 }
154
155 #define place_extra_grid(C) \
156 { \
157         (C)->feat = feat_wall_type[randint0(100)]; \
158         (C)->info &= ~(CAVE_MASK); \
159         (C)->info |= CAVE_EXTRA; \
160         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
161 }
162
163 #define place_extra_perm_bold(Y, X) \
164 { \
165         set_cave_feat(Y,X,feat_permanent); \
166         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
167         add_cave_info(Y,X,CAVE_EXTRA); \
168         delete_monster(Y, X); \
169 }
170
171 #define place_extra_perm_grid(C) \
172 { \
173         (C)->feat = feat_permanent; \
174         (C)->info &= ~(CAVE_MASK); \
175         (C)->info |= CAVE_EXTRA; \
176         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
177 }
178
179 #define place_extra_noperm_bold(Y, X) \
180 { \
181         feature_type *_f_ptr; \
182         set_cave_feat(Y,X,feat_wall_type[randint0(100)]); \
183         _f_ptr = &f_info[current_floor_ptr->grid_array[Y][X].feat]; \
184         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); \
185         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
186         add_cave_info(Y,X,CAVE_EXTRA); \
187         delete_monster(Y, X); \
188 }
189
190 #define place_inner_bold(Y, X) \
191 { \
192         set_cave_feat(Y,X,feat_wall_inner); \
193         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
194         add_cave_info(Y,X,CAVE_INNER); \
195         delete_monster(Y, X); \
196 }
197
198 #define place_inner_grid(C) \
199 { \
200         (C)->feat = feat_wall_inner; \
201         (C)->info &= ~(CAVE_MASK); \
202         (C)->info |= CAVE_INNER; \
203         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
204 }
205
206 #define place_inner_perm_bold(Y, X) \
207 { \
208         set_cave_feat(Y,X,feat_permanent); \
209         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
210         add_cave_info(Y,X,CAVE_INNER); \
211         delete_monster(Y, X); \
212 }
213
214 #define place_inner_perm_grid(C) \
215 { \
216         (C)->feat = feat_permanent; \
217         (C)->info &= ~(CAVE_MASK); \
218         (C)->info |= CAVE_INNER; \
219         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
220 }
221
222 #define place_outer_bold(Y, X) \
223 { \
224         set_cave_feat(Y,X,feat_wall_outer); \
225         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
226         add_cave_info(Y,X,CAVE_OUTER); \
227         delete_monster(Y, X); \
228 }
229
230 #define place_outer_grid(C) \
231 { \
232         (C)->feat = feat_wall_outer; \
233         (C)->info &= ~(CAVE_MASK); \
234         (C)->info |= CAVE_OUTER; \
235         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
236 }
237
238 #define place_outer_perm_bold(Y, X) \
239 { \
240         set_cave_feat(Y,X,feat_permanent); \
241         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
242         add_cave_info(Y,X,CAVE_OUTER); \
243         delete_monster(Y, X); \
244 }
245
246 #define place_outer_perm_grid(C) \
247 { \
248         (C)->feat = feat_permanent; \
249         (C)->info &= ~(CAVE_MASK); \
250         (C)->info |= CAVE_OUTER; \
251         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
252 }
253
254 #define place_outer_noperm_bold(Y, X) \
255 { \
256         feature_type *_f_ptr = &f_info[feat_wall_outer]; \
257         if (permanent_wall(_f_ptr)) set_cave_feat(Y, X, (s16b)feat_state(feat_wall_outer, FF_UNPERM)); \
258         else set_cave_feat(Y,X,feat_wall_outer); \
259         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
260         add_cave_info(Y,X,(CAVE_OUTER | CAVE_VAULT)); \
261         delete_monster(Y, X); \
262 }
263
264 #define place_outer_noperm_grid(C) \
265 { \
266         feature_type *_f_ptr = &f_info[feat_wall_outer]; \
267         if (permanent_wall(_f_ptr)) (C)->feat = (s16b)feat_state(feat_wall_outer, FF_UNPERM); \
268         else (C)->feat = feat_wall_outer; \
269         (C)->info &= ~(CAVE_MASK); \
270         (C)->info |= (CAVE_OUTER | CAVE_VAULT); \
271         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
272 }
273
274 #define place_solid_bold(Y, X) \
275 { \
276         set_cave_feat(Y,X,feat_wall_solid); \
277         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
278         add_cave_info(Y,X,CAVE_SOLID); \
279         delete_monster(Y, X); \
280 }
281
282 #define place_solid_grid(C) \
283 { \
284         (C)->feat = feat_wall_solid; \
285         (C)->info &= ~(CAVE_MASK); \
286         (C)->info |= CAVE_SOLID; \
287         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
288 }
289
290 #define place_solid_perm_bold(Y, X) \
291 { \
292         set_cave_feat(Y,X,feat_permanent); \
293         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
294         add_cave_info(Y,X,CAVE_SOLID); \
295         delete_monster(Y, X); \
296 }
297
298 #define place_solid_perm_grid(C) \
299 { \
300         (C)->feat = feat_permanent; \
301         (C)->info &= ~(CAVE_MASK); \
302         (C)->info |= CAVE_SOLID; \
303         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
304 }
305
306 #define place_solid_noperm_bold(Y, X) \
307 { \
308         feature_type *_f_ptr = &f_info[feat_wall_solid]; \
309         if ((current_floor_ptr->grid_array[Y][X].info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
310                 set_cave_feat(Y, X, feat_state(feat_wall_solid, FF_UNPERM)); \
311         else set_cave_feat(Y,X,feat_wall_solid); \
312         current_floor_ptr->grid_array[Y][X].info &= ~(CAVE_MASK); \
313         add_cave_info(Y,X,CAVE_SOLID); \
314         delete_monster(Y, X); \
315 }
316
317 #define place_solid_noperm_grid(C) \
318 { \
319         feature_type *_f_ptr = &f_info[feat_wall_solid]; \
320         if (((C)->info & CAVE_VAULT) && permanent_wall(_f_ptr)) \
321                 (C)->feat = feat_state(feat_wall_solid, FF_UNPERM); \
322         else (C)->feat = feat_wall_solid; \
323         (C)->info &= ~(CAVE_MASK); \
324         (C)->info |= CAVE_SOLID; \
325         if ((C)->m_idx) delete_monster_idx((C)->m_idx); \
326 }
327
328
329 /*
330  * 特殊なマス状態フラグ / Special grid flags
331  */
332 #define CAVE_MARK       0x0001    /*!< 現在プレイヤーの記憶に収まっている / memorized feature */
333 #define CAVE_GLOW       0x0002    /*!< マス自体が光源を持っている / self-illuminating */
334 #define CAVE_ICKY       0x0004    /*!< 生成されたVaultの一部である / part of a vault */
335 #define CAVE_ROOM       0x0008    /*!< 生成された部屋の一部である / part of a room */
336 #define CAVE_LITE       0x0010    /*!< 現在光に照らされている / lite flag  */
337 #define CAVE_VIEW       0x0020    /*!< 現在プレイヤーの視界に収まっている / view flag */
338 #define CAVE_TEMP       0x0040    /*!< 光源に関する処理のアルゴリズム用記録フラグ / temp flag */
339 #define CAVE_XTRA       0x0080    /*!< 視界に関する処理のアルゴリズム用記録フラグ(update_view()等参照) / misc flag */
340 #define CAVE_MNLT       0x0100    /*!< モンスターの光源によって照らされている / Illuminated by monster */
341 #define CAVE_MNDK       0x8000    /*!< モンスターの暗源によって暗闇になっている / Darken by monster */
342
343  /* Used only while current_floor_ptr->grid_array generation */
344 #define CAVE_FLOOR      0x0200  /*!< フロア属性のあるマス */
345 #define CAVE_EXTRA      0x0400
346 #define CAVE_INNER      0x0800
347 #define CAVE_OUTER      0x1000
348 #define CAVE_SOLID      0x2000
349 #define CAVE_VAULT      0x4000
350 #define CAVE_MASK (CAVE_FLOOR | CAVE_EXTRA | CAVE_INNER | CAVE_OUTER | CAVE_SOLID | CAVE_VAULT)
351
352 /* Used only after current_floor_ptr->grid_array generation */
353 #define CAVE_KNOWN      0x0200    /* Directly viewed or map detected flag */
354 #define CAVE_NOTE       0x0400    /* Flag for delayed visual update (needs note_spot()) */
355 #define CAVE_REDRAW     0x0800    /* Flag for delayed visual update (needs lite_spot()) */
356 #define CAVE_OBJECT     0x1000    /* Mirror, glyph, etc. */
357 #define CAVE_UNSAFE     0x2000    /* Might have trap */
358 #define CAVE_IN_DETECT  0x4000    /* trap detected area (inner circle only) */
359
360 /* Externs */
361
362 extern bool new_player_spot(void);
363
364 extern void place_random_stairs(POSITION y, POSITION x);
365 extern void place_random_door(POSITION y, POSITION x, bool room);
366 extern void place_closed_door(POSITION y, POSITION x, int type);
367 extern void add_door(POSITION x, POSITION y);
368 extern void place_secret_door(POSITION y, POSITION x, int type);
369 extern void place_locked_door(POSITION y, POSITION x);
370 extern void try_door(POSITION y, POSITION x);
371 extern void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
372 extern void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light);
373 extern void vault_monsters(POSITION y1, POSITION x1, int num);
374 extern void vault_objects(POSITION y, POSITION x, int num);
375 extern void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd);
376 extern void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num);
377
378 extern bool get_is_floor(POSITION x, POSITION y);
379 extern void set_floor(POSITION x, POSITION y);
380 extern void place_bound_perm_wall(grid_type *g_ptr);
381
382 extern bool is_known_trap(grid_type *g_ptr);
383 extern bool is_hidden_door(grid_type *g_ptr);
384 extern bool is_mirror_grid(grid_type *g_ptr);
385 extern bool is_glyph_grid(grid_type *g_ptr);
386 extern bool is_explosive_rune_grid(grid_type *g_ptr);
387
388 extern bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode);
389
390 /*!
391  * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
392  */
393 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
394
395 /* grids.c */
396 extern POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
397 extern bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
398 extern void update_local_illumination(POSITION y, POSITION x);
399 extern bool player_can_see_bold(POSITION y, POSITION x);
400 extern bool cave_valid_bold(POSITION y, POSITION x);
401 extern bool no_lite(void);
402 extern void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp);
403 extern void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x);
404 extern void note_spot(POSITION y, POSITION x);
405 extern void lite_spot(POSITION y, POSITION x);
406 extern void prt_map(void);
407 extern void display_map(int *cy, int *cx);
408 extern void delayed_visual_update(void);
409 extern void forget_flow(void);
410 extern void update_flow(void);
411 extern void update_smell(void);
412 extern void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat);
413 extern FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat);
414 extern FEAT_IDX feat_state(FEAT_IDX feat, int action);
415 extern void cave_alter_feat(POSITION y, POSITION x, int action);
416 extern void remove_mirror(POSITION y, POSITION x);
417 extern bool is_open(FEAT_IDX feat);
418 extern bool check_local_illumination(POSITION y, POSITION x);
419
420 extern bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode);
421 extern bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode);
422
423
424 /*!
425  * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
426  */
427 #define darkened_grid(C) \
428         ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
429         !p_ptr->see_nocto)
430
431 /*
432  * Get feature mimic from f_info[] (applying "mimic" field)
433  */
434 #define get_feat_mimic(C) \
435         (f_info[(C)->mimic ? (C)->mimic : (C)->feat].mimic)
436
437 /*
438  * This macro allows us to efficiently add a grid to the "lite" array,
439  * note that we are never called for illegal grids, or for grids which
440  * have already been placed into the "lite" array, and we are never
441  * called when the "lite" array is full.
442  */
443 #define cave_lite_hack(Y,X) \
444 {\
445         if (!(current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
446         { \
447                 current_floor_ptr->grid_array[Y][X].info |= (CAVE_LITE); \
448                 current_floor_ptr->lite_y[current_floor_ptr->lite_n] = (Y); \
449                 current_floor_ptr->lite_x[current_floor_ptr->lite_n++] = (X); \
450         } \
451 }
452
453 /*
454  * For delayed visual update
455  */
456 #define cave_note_and_redraw_later(C,Y,X) \
457 {\
458         (C)->info |= CAVE_NOTE; \
459         cave_redraw_later((C), (Y), (X)); \
460 }
461
462 /*
463  * For delayed visual update
464  */
465 #define cave_redraw_later(C,Y,X) \
466 {\
467         if (!((C)->info & CAVE_REDRAW)) \
468         { \
469                 (C)->info |= CAVE_REDRAW; \
470                 current_floor_ptr->redraw_y[current_floor_ptr->redraw_n] = (Y); \
471                 current_floor_ptr->redraw_x[current_floor_ptr->redraw_n++] = (X); \
472         } \
473 }
474
475  /*
476   * This macro allows us to efficiently add a grid to the "view" array,
477   * note that we are never called for illegal grids, or for grids which
478   * have already been placed into the "view" array, and we are never
479   * called when the "view" array is full.
480   */
481 #define cave_view_hack(C,Y,X) \
482 {\
483     if (!((C)->info & (CAVE_VIEW))){\
484     (C)->info |= (CAVE_VIEW); \
485     current_floor_ptr->view_y[current_floor_ptr->view_n] = (Y); \
486     current_floor_ptr->view_x[current_floor_ptr->view_n] = (X); \
487     current_floor_ptr->view_n++;}\
488 }
489