OSDN Git Service

0594dc62b0cc9b75d5d88c9515a0cbf5018da923
[hengband/hengband.git] / src / floor / cave.c
1 /*!
2  * @brief ダンジョンの壁等に関する判定関数の集合
3  * @date 2020/07/18
4  * @author Hourier
5  * @details
6  * Dance with a colorless dress. Shout with a withered voice.
7  */
8
9 #include "floor/cave.h"
10 #include "grid/feature.h"
11 #include "grid/grid.h"
12 #include "system/floor-type-definition.h"
13 #include "util/bit-flags-calculator.h"
14 #include "world/world.h"
15
16 /*
17  * Determines if a map location is fully inside the outer walls
18  */
19 bool in_bounds(floor_type *floor_ptr, POSITION y, POSITION x) { return (y > 0) && (x > 0) && (y < floor_ptr->height - 1) && (x < floor_ptr->width - 1); }
20
21 /*
22  * Determines if a map location is on or inside the outer walls
23  */
24 bool in_bounds2(floor_type *floor_ptr, POSITION y, POSITION x) { return (y >= 0) && (x >= 0) && (y < floor_ptr->height) && (x < floor_ptr->width); }
25
26 /*
27  * Determines if a map location is on or inside the outer walls
28  * (unsigned version)
29  */
30 bool in_bounds2u(floor_type *floor_ptr, POSITION y, POSITION x) { return (y < floor_ptr->height) && (x < floor_ptr->width); }
31
32 /*
33  * Determine if a "legal" grid is an "empty" floor grid
34  * Determine if monsters are allowed to move into a grid
35  *
36  * Line 1 -- forbid non-placement grids
37  * Line 2 -- forbid normal monsters
38  * Line 3 -- forbid the player
39  */
40 bool is_cave_empty_bold(player_type *player_ptr, POSITION y, POSITION x)
41 {
42     floor_type *floor_ptr = player_ptr->current_floor_ptr;
43     bool is_empty_grid = cave_have_flag_bold(floor_ptr, y, x, FF_PLACE);
44     is_empty_grid &= !(floor_ptr->grid_array[y][x].m_idx);
45     is_empty_grid &= !player_bold(player_ptr, y, x);
46     return is_empty_grid;
47 }
48
49 /*
50  * Determine if a "legal" grid is an "empty" floor grid
51  * Determine if monster generation is allowed in a grid
52  *
53  * Line 1 -- forbid non-empty grids
54  * Line 2 -- forbid trees while dungeon generation
55  */
56 bool is_cave_empty_bold2(player_type *player_ptr, POSITION y, POSITION x)
57 {
58     bool is_empty_grid = is_cave_empty_bold(player_ptr, y, x);
59     is_empty_grid &= current_world_ptr->character_dungeon || !cave_have_flag_bold(player_ptr->current_floor_ptr, y, x, FF_TREE);
60     return is_empty_grid;
61 }
62
63 bool cave_have_flag_bold(floor_type *floor_ptr, POSITION y, POSITION x, feature_flag_type f_idx)
64 {
65     return have_flag(f_info[floor_ptr->grid_array[y][x].feat].flags, f_idx);
66 }
67
68 /*
69  * Determine if a "legal" grid is within "los" of the player
70  */
71 bool player_has_los_bold(player_type *player_ptr, POSITION y, POSITION x)
72 {
73     return ((player_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_VIEW) != 0) || player_ptr->phase_out;
74 }
75
76 /*
77  * Determine if player is on this grid
78  */
79 bool player_bold(player_type *player_ptr, POSITION y, POSITION x) { return (y == player_ptr->y) && (x == player_ptr->x); }
80
81 /*
82  * Does the grid stop disintegration?
83  */
84 bool cave_stop_disintegration(floor_type *floor_ptr, POSITION y, POSITION x)
85 {
86     return !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)
87         && (!cave_have_flag_bold(floor_ptr, y, x, FF_HURT_DISI) || cave_have_flag_bold(floor_ptr, y, x, FF_PERMANENT));
88 }
89
90 /*
91  * @brief 指定のマスが光を通すか(LOSフラグを持つか)を返す。 / Aux function -- see below
92  * @param floor_ptr 配置するフロアの参照ポインタ
93  * @param y 指定Y座標
94  * @param x 指定X座標
95  * @return 光を通すならばtrueを返す。
96  */
97 bool cave_los_bold(floor_type *floor_ptr, POSITION y, POSITION x) { return feat_supports_los(floor_ptr->grid_array[y][x].feat); }
98
99 /*
100  * Determine if a "feature" supports "los"
101  */
102 bool feat_supports_los(FEAT_IDX f_idx) { return have_flag(f_info[f_idx].flags, FF_LOS); }
103
104 bool cave_los_grid(grid_type *grid_ptr) { return feat_supports_los(grid_ptr->feat); }
105
106 bool cave_have_flag_grid(grid_type *grid_ptr, int feature_flags) { return have_flag(f_info[grid_ptr->feat].flags, feature_flags); }