2 * @brief モンスターの魔法によってフロアを明るくする処理及びその判定
7 #include "mspell/mspell-lite.h"
8 #include "dungeon/dungeon-flag-types.h"
9 #include "floor/cave.h"
10 #include "floor/geometry.h"
11 #include "floor/line-of-sight.h"
12 #include "monster-race/monster-race.h"
13 #include "monster-race/race-ability-mask.h"
14 #include "monster-race/race-brightness-mask.h"
15 #include "mspell/mspell-attack-util.h"
16 #include "mspell/mspell-judgement.h"
17 #include "player-base/player-class.h"
18 #include "spell/range-calc.h"
19 #include "system/angband-system.h"
20 #include "system/dungeon-info.h"
21 #include "system/floor-type-definition.h"
22 #include "system/grid-type-definition.h"
23 #include "system/monster-entity.h"
24 #include "system/monster-race-info.h"
25 #include "system/player-type-definition.h"
26 #include "system/terrain-type-definition.h"
27 #include "target/projection-path-calculator.h"
28 #include "util/bit-flags-calculator.h"
31 * @brief モンスターがプレイヤーにダメージを与えるための最適な座標を算出する /
32 * @param player_ptr プレイヤーへの参照ポインタ
33 * @param m_ptr 技能を使用するモンスター構造体の参照ポインタ
34 * @param yp 最適な目標地点のY座標を返す参照ポインタ
35 * @param xp 最適な目標地点のX座標を返す参照ポインタ
36 * @param f_flag 射線に入れるのを避ける地形の所持フラグ
37 * @param path_check 射線を判定するための関数ポインタ
38 * @return 有効な座標があった場合TRUEを返す
40 bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION *yp, POSITION *xp, TerrainCharacteristics f_flag, path_check_pf path_check)
42 static int tonari_y[4][8] = { { -1, -1, -1, 0, 0, 1, 1, 1 }, { -1, -1, -1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, -1, -1, -1 }, { 1, 1, 1, 0, 0, -1, -1, -1 } };
43 static int tonari_x[4][8] = { { -1, 0, 1, -1, 1, -1, 0, 1 }, { 1, 0, -1, 1, -1, 1, 0, -1 }, { -1, 0, 1, -1, 1, -1, 0, 1 }, { 1, 0, -1, 1, -1, 1, 0, -1 } };
46 if (m_ptr->fy < player_ptr->y && m_ptr->fx < player_ptr->x) {
48 } else if (m_ptr->fy < player_ptr->y) {
50 } else if (m_ptr->fx < player_ptr->x) {
56 for (int i = 0; i < 8; i++) {
57 int next_x = *xp + tonari_x[next][i];
58 int next_y = *yp + tonari_y[next][i];
60 g_ptr = &player_ptr->current_floor_ptr->grid_array[next_y][next_x];
61 if (!g_ptr->cave_has_flag(f_flag)) {
65 if (path_check(player_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x)) {
75 void decide_lite_range(PlayerType *player_ptr, msa_type *msa_ptr)
77 if (msa_ptr->ability_flags.has_not(MonsterAbilityType::BR_LITE)) {
81 msa_ptr->y_br_lite = msa_ptr->y;
82 msa_ptr->x_br_lite = msa_ptr->x;
83 if (los(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y_br_lite, msa_ptr->x_br_lite)) {
84 const Pos2D pos(msa_ptr->y_br_lite, msa_ptr->x_br_lite);
85 const auto &terrain = player_ptr->current_floor_ptr->get_grid(pos).get_terrain();
86 if (terrain.flags.has_not(TerrainCharacteristics::LOS) && terrain.flags.has(TerrainCharacteristics::PROJECT) && one_in_(2)) {
87 msa_ptr->ability_flags.reset(MonsterAbilityType::BR_LITE);
89 } else if (!adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y_br_lite, &msa_ptr->x_br_lite, TerrainCharacteristics::LOS, los)) {
90 msa_ptr->ability_flags.reset(MonsterAbilityType::BR_LITE);
93 if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE)) {
97 msa_ptr->y_br_lite = 0;
98 msa_ptr->x_br_lite = 0;
101 static void feature_projection(const FloorType &floor, msa_type *msa_ptr)
103 const Pos2D pos(msa_ptr->y, msa_ptr->x);
104 const auto &terrain = floor.get_grid(pos).get_terrain();
105 if (terrain.flags.has(TerrainCharacteristics::PROJECT)) {
109 if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI) && terrain.flags.has(TerrainCharacteristics::HURT_DISI) && one_in_(2)) {
110 msa_ptr->do_spell = DO_SPELL_BR_DISI;
114 if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE) && terrain.flags.has(TerrainCharacteristics::LOS) && one_in_(2)) {
115 msa_ptr->do_spell = DO_SPELL_BR_LITE;
119 static void check_lite_area_by_mspell(PlayerType *player_ptr, msa_type *msa_ptr)
121 const auto &system = AngbandSystem::get_instance();
122 auto light_by_disintegration = msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI);
123 light_by_disintegration &= msa_ptr->m_ptr->cdis < system.get_max_range() / 2;
124 light_by_disintegration &= in_disintegration_range(player_ptr->current_floor_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x);
125 light_by_disintegration &= one_in_(10) || (projectable(player_ptr, msa_ptr->y, msa_ptr->x, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx) && one_in_(2));
126 if (light_by_disintegration) {
127 msa_ptr->do_spell = DO_SPELL_BR_DISI;
128 msa_ptr->success = true;
132 auto light_by_lite = msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE);
133 light_by_lite &= msa_ptr->m_ptr->cdis < system.get_max_range() / 2;
134 light_by_lite &= los(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x);
135 light_by_lite &= one_in_(5);
137 msa_ptr->do_spell = DO_SPELL_BR_LITE;
138 msa_ptr->success = true;
142 if (msa_ptr->ability_flags.has_not(MonsterAbilityType::BA_LITE) || (msa_ptr->m_ptr->cdis > system.get_max_range())) {
146 auto by = msa_ptr->y;
147 auto bx = msa_ptr->x;
148 get_project_point(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, &by, &bx, 0L);
149 if ((distance(by, bx, msa_ptr->y, msa_ptr->x) <= 3) && los(player_ptr, by, bx, msa_ptr->y, msa_ptr->x) && one_in_(5)) {
150 msa_ptr->do_spell = DO_SPELL_BA_LITE;
151 msa_ptr->success = true;
155 static void decide_lite_breath(msa_type *msa_ptr)
157 if (msa_ptr->success) {
161 if (msa_ptr->m_ptr->target_y && msa_ptr->m_ptr->target_x) {
162 msa_ptr->y = msa_ptr->m_ptr->target_y;
163 msa_ptr->x = msa_ptr->m_ptr->target_x;
164 msa_ptr->ability_flags &= RF_ABILITY_INDIRECT_MASK;
165 msa_ptr->success = true;
168 auto should_set = msa_ptr->y_br_lite == 0;
169 should_set |= msa_ptr->x_br_lite == 0;
170 should_set |= msa_ptr->m_ptr->cdis > AngbandSystem::get_instance().get_max_range() / 2;
171 should_set |= !one_in_(5);
176 if (msa_ptr->success) {
177 msa_ptr->ability_flags.set(MonsterAbilityType::BR_LITE);
181 msa_ptr->y = msa_ptr->y_br_lite;
182 msa_ptr->x = msa_ptr->x_br_lite;
183 msa_ptr->do_spell = DO_SPELL_BR_LITE;
184 msa_ptr->success = true;
187 bool decide_lite_projection(PlayerType *player_ptr, msa_type *msa_ptr)
189 if (projectable(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x)) {
190 feature_projection(*player_ptr->current_floor_ptr, msa_ptr);
194 msa_ptr->success = false;
195 check_lite_area_by_mspell(player_ptr, msa_ptr);
196 if (!msa_ptr->success) {
197 msa_ptr->success = adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y, &msa_ptr->x, TerrainCharacteristics::PROJECT, projectable);
200 decide_lite_breath(msa_ptr);
201 return msa_ptr->success;
204 void decide_lite_area(PlayerType *player_ptr, msa_type *msa_ptr)
206 if (msa_ptr->ability_flags.has_not(MonsterAbilityType::DARKNESS)) {
210 PlayerClass pc(player_ptr);
211 auto can_use_lite_area = pc.equals(PlayerClassType::NINJA);
212 can_use_lite_area &= msa_ptr->r_ptr->kind_flags.has_not(MonsterKindType::UNDEAD);
213 can_use_lite_area &= msa_ptr->r_ptr->resistance_flags.has_not(MonsterResistanceType::HURT_LITE);
214 can_use_lite_area &= (msa_ptr->r_ptr->brightness_flags.has_none_of(dark_mask));
216 if (msa_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID)) {
220 if (player_ptr->current_floor_ptr->get_dungeon_definition().flags.has(DungeonFeatureType::DARKNESS)) {
221 msa_ptr->ability_flags.reset(MonsterAbilityType::DARKNESS);
225 if (pc.equals(PlayerClassType::NINJA) && !can_use_lite_area) {
226 msa_ptr->ability_flags.reset(MonsterAbilityType::DARKNESS);