OSDN Git Service

[Refactor] race-flags#.h のインクルードを削除
[hengbandforosx/hengbandosx.git] / src / mspell / mspell-lite.cpp
index c4896cd..d548ac0 100644 (file)
@@ -1,4 +1,4 @@
-/*!
+/*!
  * @brief モンスターの魔法によってフロアを明るくする処理及びその判定
  * @date 2020/07/23
  * @author Hourier
 #include "monster-race/monster-race.h"
 #include "monster-race/race-ability-mask.h"
 #include "monster-race/race-brightness-mask.h"
-#include "monster-race/race-flags2.h"
-#include "monster-race/race-flags3.h"
-#include "monster-race/race-flags7.h"
 #include "mspell/mspell-attack-util.h"
 #include "mspell/mspell-judgement.h"
 #include "player-base/player-class.h"
 #include "spell/range-calc.h"
+#include "system/angband-system.h"
 #include "system/dungeon-info.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
@@ -58,7 +56,7 @@ bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION
     for (int i = 0; i < 8; i++) {
         int next_x = *xp + tonari_x[next][i];
         int next_y = *yp + tonari_y[next][i];
-        grid_type *g_ptr;
+        Grid *g_ptr;
         g_ptr = &player_ptr->current_floor_ptr->grid_array[next_y][next_x];
         if (!g_ptr->cave_has_flag(f_flag)) {
             continue;
@@ -83,8 +81,9 @@ void decide_lite_range(PlayerType *player_ptr, msa_type *msa_ptr)
     msa_ptr->y_br_lite = msa_ptr->y;
     msa_ptr->x_br_lite = msa_ptr->x;
     if (los(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y_br_lite, msa_ptr->x_br_lite)) {
-        auto *f_ptr = &terrains_info[player_ptr->current_floor_ptr->grid_array[msa_ptr->y_br_lite][msa_ptr->x_br_lite].feat];
-        if (f_ptr->flags.has_not(TerrainCharacteristics::LOS) && f_ptr->flags.has(TerrainCharacteristics::PROJECT) && one_in_(2)) {
+        const Pos2D pos(msa_ptr->y_br_lite, msa_ptr->x_br_lite);
+        const auto &terrain = player_ptr->current_floor_ptr->get_grid(pos).get_terrain();
+        if (terrain.flags.has_not(TerrainCharacteristics::LOS) && terrain.flags.has(TerrainCharacteristics::PROJECT) && one_in_(2)) {
             msa_ptr->ability_flags.reset(MonsterAbilityType::BR_LITE);
         }
     } else if (!adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y_br_lite, &msa_ptr->x_br_lite, TerrainCharacteristics::LOS, los)) {
@@ -99,42 +98,53 @@ void decide_lite_range(PlayerType *player_ptr, msa_type *msa_ptr)
     msa_ptr->x_br_lite = 0;
 }
 
-static void feature_projection(FloorType *floor_ptr, msa_type *msa_ptr)
+static void feature_projection(const FloorType &floor, msa_type *msa_ptr)
 {
-    auto *f_ptr = &terrains_info[floor_ptr->grid_array[msa_ptr->y][msa_ptr->x].feat];
-    if (f_ptr->flags.has(TerrainCharacteristics::PROJECT)) {
+    const Pos2D pos(msa_ptr->y, msa_ptr->x);
+    const auto &terrain = floor.get_grid(pos).get_terrain();
+    if (terrain.flags.has(TerrainCharacteristics::PROJECT)) {
         return;
     }
 
-    if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI) && f_ptr->flags.has(TerrainCharacteristics::HURT_DISI) && one_in_(2)) {
+    if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI) && terrain.flags.has(TerrainCharacteristics::HURT_DISI) && one_in_(2)) {
         msa_ptr->do_spell = DO_SPELL_BR_DISI;
         return;
     }
 
-    if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE) && f_ptr->flags.has(TerrainCharacteristics::LOS) && one_in_(2)) {
+    if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE) && terrain.flags.has(TerrainCharacteristics::LOS) && one_in_(2)) {
         msa_ptr->do_spell = DO_SPELL_BR_LITE;
     }
 }
 
 static void check_lite_area_by_mspell(PlayerType *player_ptr, msa_type *msa_ptr)
 {
-    if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI) && (msa_ptr->m_ptr->cdis < get_max_range(player_ptr) / 2) && in_disintegration_range(player_ptr->current_floor_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x) && (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)))) {
+    const auto &system = AngbandSystem::get_instance();
+    auto light_by_disintegration = msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI);
+    light_by_disintegration &= msa_ptr->m_ptr->cdis < system.get_max_range() / 2;
+    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);
+    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));
+    if (light_by_disintegration) {
         msa_ptr->do_spell = DO_SPELL_BR_DISI;
         msa_ptr->success = true;
         return;
     }
 
-    if (msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE) && (msa_ptr->m_ptr->cdis < get_max_range(player_ptr) / 2) && los(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x) && one_in_(5)) {
+    auto light_by_lite = msa_ptr->ability_flags.has(MonsterAbilityType::BR_LITE);
+    light_by_lite &= msa_ptr->m_ptr->cdis < system.get_max_range() / 2;
+    light_by_lite &= los(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x);
+    light_by_lite &= one_in_(5);
+    if (light_by_lite) {
         msa_ptr->do_spell = DO_SPELL_BR_LITE;
         msa_ptr->success = true;
         return;
     }
 
-    if (msa_ptr->ability_flags.has_not(MonsterAbilityType::BA_LITE) || (msa_ptr->m_ptr->cdis > get_max_range(player_ptr))) {
+    if (msa_ptr->ability_flags.has_not(MonsterAbilityType::BA_LITE) || (msa_ptr->m_ptr->cdis > system.get_max_range())) {
         return;
     }
 
-    POSITION by = msa_ptr->y, bx = msa_ptr->x;
+    auto by = msa_ptr->y;
+    auto bx = msa_ptr->x;
     get_project_point(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, &by, &bx, 0L);
     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)) {
         msa_ptr->do_spell = DO_SPELL_BA_LITE;
@@ -142,7 +152,7 @@ static void check_lite_area_by_mspell(PlayerType *player_ptr, msa_type *msa_ptr)
     }
 }
 
-static void decide_lite_breath(PlayerType *player_ptr, msa_type *msa_ptr)
+static void decide_lite_breath(msa_type *msa_ptr)
 {
     if (msa_ptr->success) {
         return;
@@ -155,7 +165,11 @@ static void decide_lite_breath(PlayerType *player_ptr, msa_type *msa_ptr)
         msa_ptr->success = true;
     }
 
-    if ((msa_ptr->y_br_lite == 0) || (msa_ptr->x_br_lite == 0) || (msa_ptr->m_ptr->cdis > get_max_range(player_ptr) / 2) || !one_in_(5)) {
+    auto should_set = msa_ptr->y_br_lite == 0;
+    should_set |= msa_ptr->x_br_lite == 0;
+    should_set |= msa_ptr->m_ptr->cdis > AngbandSystem::get_instance().get_max_range() / 2;
+    should_set |= !one_in_(5);
+    if (should_set) {
         return;
     }
 
@@ -173,7 +187,7 @@ static void decide_lite_breath(PlayerType *player_ptr, msa_type *msa_ptr)
 bool decide_lite_projection(PlayerType *player_ptr, msa_type *msa_ptr)
 {
     if (projectable(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x)) {
-        feature_projection(player_ptr->current_floor_ptr, msa_ptr);
+        feature_projection(*player_ptr->current_floor_ptr, msa_ptr);
         return true;
     }
 
@@ -183,7 +197,7 @@ bool decide_lite_projection(PlayerType *player_ptr, msa_type *msa_ptr)
         msa_ptr->success = adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y, &msa_ptr->x, TerrainCharacteristics::PROJECT, projectable);
     }
 
-    decide_lite_breath(player_ptr, msa_ptr);
+    decide_lite_breath(msa_ptr);
     return msa_ptr->success;
 }