OSDN Git Service

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