OSDN Git Service

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