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 "monster-race/race-flags2.h"
16 #include "monster-race/race-flags3.h"
17 #include "monster-race/race-flags7.h"
18 #include "mspell/mspell-attack-util.h"
19 #include "mspell/mspell-judgement.h"
20 #include "player-base/player-class.h"
21 #include "spell/range-calc.h"
22 #include "system/angband-system.h"
23 #include "system/dungeon-info.h"
24 #include "system/floor-type-definition.h"
25 #include "system/grid-type-definition.h"
26 #include "system/monster-entity.h"
27 #include "system/monster-race-info.h"
28 #include "system/player-type-definition.h"
29 #include "system/terrain-type-definition.h"
30 #include "target/projection-path-calculator.h"
31 #include "util/bit-flags-calculator.h"
34 * @brief モンスターがプレイヤーにダメージを与えるための最適な座標を算出する /
35 * @param player_ptr プレイヤーへの参照ポインタ
36 * @param m_ptr 技能を使用するモンスター構造体の参照ポインタ
37 * @param yp 最適な目標地点のY座標を返す参照ポインタ
38 * @param xp 最適な目標地点のX座標を返す参照ポインタ
39 * @param f_flag 射線に入れるのを避ける地形の所持フラグ
40 * @param path_check 射線を判定するための関数ポインタ
41 * @return 有効な座標があった場合TRUEを返す
43 bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION *yp, POSITION *xp, TerrainCharacteristics f_flag, path_check_pf path_check)
45 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 } };
46 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 } };
49 if (m_ptr->fy < player_ptr->y && m_ptr->fx < player_ptr->x) {
51 } else if (m_ptr->fy < player_ptr->y) {
53 } else if (m_ptr->fx < player_ptr->x) {
59 for (int i = 0; i < 8; i++) {
60 int next_x = *xp + tonari_x[next][i];
61 int next_y = *yp + tonari_y[next][i];
63 g_ptr = &player_ptr->current_floor_ptr->grid_array[next_y][next_x];
64 if (!g_ptr->cave_has_flag(f_flag)) {
68 if (path_check(player_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x)) {
78 void decide_lite_range(PlayerType *player_ptr, msa_type *msa_ptr)
80 if (msa_ptr->ability_flags.has_not(MonsterAbilityType::BR_LITE)) {
84 msa_ptr->y_br_lite = msa_ptr->y;
85 msa_ptr->x_br_lite = msa_ptr->x;
86 if (los(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y_br_lite, msa_ptr->x_br_lite)) {
87 auto *f_ptr = &terrains_info[player_ptr->current_floor_ptr->grid_array[msa_ptr->y_br_lite][msa_ptr->x_br_lite].feat];
88 if (f_ptr->flags.has_not(TerrainCharacteristics::LOS) && f_ptr->flags.has(TerrainCharacteristics::PROJECT) && one_in_(2)) {
89 msa_ptr->ability_flags.reset(MonsterAbilityType::BR_LITE);
91 } else if (!adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y_br_lite, &msa_ptr->x_br_lite, TerrainCharacteristics::LOS, los)) {
92 msa_ptr->ability_flags.reset(MonsterAbilityType::BR_LITE);
95 if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE)) {
99 msa_ptr->y_br_lite = 0;
100 msa_ptr->x_br_lite = 0;
103 static void feature_projection(FloorType *floor_ptr, msa_type *msa_ptr)
105 auto *f_ptr = &terrains_info[floor_ptr->grid_array[msa_ptr->y][msa_ptr->x].feat];
106 if (f_ptr->flags.has(TerrainCharacteristics::PROJECT)) {
110 if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI) && f_ptr->flags.has(TerrainCharacteristics::HURT_DISI) && one_in_(2)) {
111 msa_ptr->do_spell = DO_SPELL_BR_DISI;
115 if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE) && f_ptr->flags.has(TerrainCharacteristics::LOS) && one_in_(2)) {
116 msa_ptr->do_spell = DO_SPELL_BR_LITE;
120 static void check_lite_area_by_mspell(PlayerType *player_ptr, msa_type *msa_ptr)
122 const auto &system = AngbandSystem::get_instance();
123 auto light_by_disintegration = msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI);
124 light_by_disintegration &= msa_ptr->m_ptr->cdis < system.get_max_range() / 2;
125 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);
126 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));
127 if (light_by_disintegration) {
128 msa_ptr->do_spell = DO_SPELL_BR_DISI;
129 msa_ptr->success = true;
133 auto light_by_lite = msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE);
134 light_by_lite &= msa_ptr->m_ptr->cdis < system.get_max_range() / 2;
135 light_by_lite &= los(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x);
136 light_by_lite &= one_in_(5);
138 msa_ptr->do_spell = DO_SPELL_BR_LITE;
139 msa_ptr->success = true;
143 if (msa_ptr->ability_flags.has_not(MonsterAbilityType::BA_LITE) || (msa_ptr->m_ptr->cdis > system.get_max_range())) {
147 auto by = msa_ptr->y;
148 auto bx = msa_ptr->x;
149 get_project_point(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, &by, &bx, 0L);
150 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)) {
151 msa_ptr->do_spell = DO_SPELL_BA_LITE;
152 msa_ptr->success = true;
156 static void decide_lite_breath(PlayerType *player_ptr, msa_type *msa_ptr)
158 if (msa_ptr->success) {
162 if (msa_ptr->m_ptr->target_y && msa_ptr->m_ptr->target_x) {
163 msa_ptr->y = msa_ptr->m_ptr->target_y;
164 msa_ptr->x = msa_ptr->m_ptr->target_x;
165 msa_ptr->ability_flags &= RF_ABILITY_INDIRECT_MASK;
166 msa_ptr->success = true;
169 auto should_set = msa_ptr->y_br_lite == 0;
170 should_set |= msa_ptr->x_br_lite == 0;
171 should_set |= msa_ptr->m_ptr->cdis > AngbandSystem::get_instance().get_max_range() / 2;
172 should_set |= !one_in_(5);
177 if (msa_ptr->success) {
178 msa_ptr->ability_flags.set(MonsterAbilityType::BR_LITE);
182 msa_ptr->y = msa_ptr->y_br_lite;
183 msa_ptr->x = msa_ptr->x_br_lite;
184 msa_ptr->do_spell = DO_SPELL_BR_LITE;
185 msa_ptr->success = true;
188 bool decide_lite_projection(PlayerType *player_ptr, msa_type *msa_ptr)
190 if (projectable(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x)) {
191 feature_projection(player_ptr->current_floor_ptr, msa_ptr);
195 msa_ptr->success = false;
196 check_lite_area_by_mspell(player_ptr, msa_ptr);
197 if (!msa_ptr->success) {
198 msa_ptr->success = adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y, &msa_ptr->x, TerrainCharacteristics::PROJECT, projectable);
201 decide_lite_breath(player_ptr, msa_ptr);
202 return msa_ptr->success;
205 void decide_lite_area(PlayerType *player_ptr, msa_type *msa_ptr)
207 if (msa_ptr->ability_flags.has_not(MonsterAbilityType::DARKNESS)) {
211 PlayerClass pc(player_ptr);
212 auto can_use_lite_area = pc.equals(PlayerClassType::NINJA);
213 can_use_lite_area &= msa_ptr->r_ptr->kind_flags.has_not(MonsterKindType::UNDEAD);
214 can_use_lite_area &= msa_ptr->r_ptr->resistance_flags.has_not(MonsterResistanceType::HURT_LITE);
215 can_use_lite_area &= (msa_ptr->r_ptr->brightness_flags.has_none_of(dark_mask));
217 if (msa_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID)) {
221 if (player_ptr->current_floor_ptr->get_dungeon_definition().flags.has(DungeonFeatureType::DARKNESS)) {
222 msa_ptr->ability_flags.reset(MonsterAbilityType::DARKNESS);
226 if (pc.equals(PlayerClassType::NINJA) && !can_use_lite_area) {
227 msa_ptr->ability_flags.reset(MonsterAbilityType::DARKNESS);