OSDN Git Service

[Refactor] #919 Removed cave_los_grid() and moved cave_has_los_grid() from cave.cpp...
[hengbandforosx/hengbandosx.git] / src / floor / cave.cpp
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 "system/grid-type-definition.h"
14 #include "system/player-type-definition.h"
15 #include "util/bit-flags-calculator.h"
16 #include "world/world.h"
17
18 /*
19  * Determines if a map location is fully inside the outer walls
20  */
21 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); }
22
23 /*
24  * Determines if a map location is on or inside the outer walls
25  */
26 bool in_bounds2(floor_type *floor_ptr, POSITION y, POSITION x) { return (y >= 0) && (x >= 0) && (y < floor_ptr->height) && (x < floor_ptr->width); }
27
28 /*
29  * Determines if a map location is on or inside the outer walls
30  * (unsigned version)
31  */
32 bool in_bounds2u(floor_type *floor_ptr, POSITION y, POSITION x) { return (y < floor_ptr->height) && (x < floor_ptr->width); }
33
34 /*
35  * Determine if a "legal" grid is an "empty" floor grid
36  * Determine if monsters are allowed to move into a grid
37  *
38  * Line 1 -- forbid non-placement grids
39  * Line 2 -- forbid normal monsters
40  * Line 3 -- forbid the player
41  */
42 bool is_cave_empty_bold(player_type *player_ptr, POSITION y, POSITION x)
43 {
44     floor_type *floor_ptr = player_ptr->current_floor_ptr;
45     bool is_empty_grid = cave_has_flag_bold(floor_ptr, y, x, FF_PLACE);
46     is_empty_grid &= !(floor_ptr->grid_array[y][x].m_idx);
47     is_empty_grid &= !player_bold(player_ptr, y, x);
48     return is_empty_grid;
49 }
50
51 /*
52  * Determine if a "legal" grid is an "empty" floor grid
53  * Determine if monster generation is allowed in a grid
54  *
55  * Line 1 -- forbid non-empty grids
56  * Line 2 -- forbid trees while dungeon generation
57  */
58 bool is_cave_empty_bold2(player_type *player_ptr, POSITION y, POSITION x)
59 {
60     bool is_empty_grid = is_cave_empty_bold(player_ptr, y, x);
61     is_empty_grid &= current_world_ptr->character_dungeon || !cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, FF_TREE);
62     return is_empty_grid;
63 }
64
65 bool cave_has_flag_bold(floor_type *floor_ptr, POSITION y, POSITION x, feature_flag_type f_idx)
66 {
67     return has_flag(f_info[floor_ptr->grid_array[y][x].feat].flags, f_idx);
68 }
69
70 /*
71  * Determine if a "legal" grid is within "los" of the player
72  */
73 bool player_has_los_bold(player_type *player_ptr, POSITION y, POSITION x)
74 {
75     return ((player_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_VIEW) != 0) || player_ptr->phase_out;
76 }
77
78 /*
79  * Determine if player is on this grid
80  */
81 bool player_bold(player_type *player_ptr, POSITION y, POSITION x) { return (y == player_ptr->y) && (x == player_ptr->x); }
82
83 /*
84  * Does the grid stop disintegration?
85  */
86 bool cave_stop_disintegration(floor_type *floor_ptr, POSITION y, POSITION x)
87 {
88     return !cave_has_flag_bold(floor_ptr, y, x, FF_PROJECT)
89         && (!cave_has_flag_bold(floor_ptr, y, x, FF_HURT_DISI) || cave_has_flag_bold(floor_ptr, y, x, FF_PERMANENT));
90 }
91
92 /*
93  * @brief 指定のマスが光を通すか(LOSフラグを持つか)を返す。 / Aux function -- see below
94  * @param floor_ptr 配置するフロアの参照ポインタ
95  * @param y 指定Y座標
96  * @param x 指定X座標
97  * @return 光を通すならばtrueを返す。
98  */
99 bool cave_los_bold(floor_type *floor_ptr, POSITION y, POSITION x) { return feat_supports_los(floor_ptr->grid_array[y][x].feat); }
100
101 /*
102  * Determine if a "feature" supports "los"
103  */
104 bool feat_supports_los(FEAT_IDX f_idx) { return has_flag(f_info[f_idx].flags, FF_LOS); }
105
106 /*
107  * Determine if a "legal" grid is a "clean" floor grid
108  * Determine if terrain-change spells are allowed in a grid.
109  *
110  * Line 1 -- forbid non-floors
111  * Line 2 -- forbid object terrains
112  * Line 3 -- forbid normal objects
113  */
114 bool cave_clean_bold(floor_type *floor_ptr, POSITION y, POSITION x)
115 {
116     return cave_has_flag_bold(floor_ptr, y, x, FF_FLOOR) && ((floor_ptr->grid_array[y][x].is_object()) == 0)
117         && floor_ptr->grid_array[y][x].o_idx_list.empty();
118 }
119
120 /*
121  * Determine if an object can be dropped on a "legal" grid
122  *
123  * Line 1 -- forbid non-drops
124  * Line 2 -- forbid object terrains
125  */
126 bool cave_drop_bold(floor_type *floor_ptr, POSITION y, POSITION x)
127 {
128     return cave_has_flag_bold(floor_ptr, y, x, FF_DROP) && ((floor_ptr->grid_array[y][x].is_object()) == 0);
129 }
130
131 bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x) { return cave_has_flag_bold(floor_ptr, y, x, FF_PATTERN); }