OSDN Git Service

[Refactor] #2647 is_hostile() をmonster_type のオブジェクトメソッドとして再定義した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 17 Sep 2022 02:39:21 +0000 (11:39 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 18 Sep 2022 11:06:52 +0000 (20:06 +0900)
18 files changed:
src/action/movement-execution.cpp
src/cmd-action/cmd-attack.cpp
src/dungeon/quest-completion-checker.cpp
src/effect/effect-monster-charm.cpp
src/floor/wild.cpp
src/melee/melee-spell-flags-checker.cpp
src/monster-attack/monster-attack-player.cpp
src/monster-floor/monster-direction.cpp
src/monster-floor/monster-move.cpp
src/monster-floor/monster-sweep-grid.cpp
src/monster/monster-info.cpp
src/monster/monster-info.h
src/monster/monster-update.cpp
src/mspell/mspell-attack.cpp
src/mspell/mspell-floor.cpp
src/object/warning.cpp
src/system/monster-type-definition.cpp
src/system/monster-type-definition.h

index 0e18963..ae13b8a 100644 (file)
@@ -175,7 +175,7 @@ void exe_movement(PlayerType *player_ptr, DIRECTION dir, bool do_pickup, bool br
         can_cast &= m_ptr->ml;
         can_cast &= !is_stunned;
         can_cast &= player_ptr->muta.has_not(PlayerMutationType::BERS_RAGE) || !is_shero(player_ptr);
-        if (!is_hostile(m_ptr) && can_cast && pattern_seq(player_ptr, player_ptr->y, player_ptr->x, y, x) && (p_can_enter || p_can_kill_walls)) {
+        if (!m_ptr->is_hostile() && can_cast && pattern_seq(player_ptr, player_ptr->y, player_ptr->x, y, x) && (p_can_enter || p_can_kill_walls)) {
             (void)set_monster_csleep(player_ptr, g_ptr->m_idx, 0);
             monster_desc(player_ptr, m_name, m_ptr, 0);
             if (m_ptr->ml) {
index 03c8965..4fa818a 100644 (file)
@@ -219,7 +219,7 @@ bool do_cmd_attack(PlayerType *player_ptr, POSITION y, POSITION x, combat_option
         return false;
     }
 
-    if (!is_hostile(m_ptr) && !(is_stunned || is_confused || is_hallucinated || is_shero(player_ptr) || !m_ptr->ml)) {
+    if (!m_ptr->is_hostile() && !(is_stunned || is_confused || is_hallucinated || is_shero(player_ptr) || !m_ptr->ml)) {
         constexpr auto stormbringer = FixedArtifactId::STORMBRINGER;
         auto is_stormbringer = false;
         if (player_ptr->inventory_list[INVEN_MAIN_HAND].fixed_artifact_idx == stormbringer) {
index 3269f3d..ce8a7ef 100644 (file)
@@ -137,7 +137,7 @@ void QuestCompletionChecker::complete_kill_number()
 
 void QuestCompletionChecker::complete_kill_all()
 {
-    if (!is_hostile(this->m_ptr) || (this->count_all_hostile_monsters() != 1)) {
+    if (!this->m_ptr->is_hostile() || (this->count_all_hostile_monsters() != 1)) {
         return;
     }
 
@@ -182,7 +182,7 @@ std::tuple<bool, bool> QuestCompletionChecker::complete_random()
 void QuestCompletionChecker::complete_tower()
 {
     const auto &quest_list = QuestList::get_instance();
-    if (!is_hostile(this->m_ptr)) {
+    if (!this->m_ptr->is_hostile()) {
         return;
     }
 
@@ -210,7 +210,7 @@ int QuestCompletionChecker::count_all_hostile_monsters()
     for (auto x = 0; x < floor_ptr->width; ++x) {
         for (auto y = 0; y < floor_ptr->height; ++y) {
             auto m_idx = floor_ptr->grid_array[y][x].m_idx;
-            if ((m_idx > 0) && is_hostile(&floor_ptr->m_list[m_idx])) {
+            if ((m_idx > 0) && floor_ptr->m_list[m_idx].is_hostile()) {
                 ++number_mon;
             }
         }
index 8accb6a..78705c5 100644 (file)
@@ -289,7 +289,7 @@ static void effect_monster_domination_addition(effect_monster_type *em_ptr)
 
 ProcessResult effect_monster_domination(PlayerType *player_ptr, effect_monster_type *em_ptr)
 {
-    if (!is_hostile(em_ptr->m_ptr)) {
+    if (!em_ptr->m_ptr->is_hostile()) {
         return ProcessResult::PROCESS_CONTINUE;
     }
 
@@ -297,7 +297,10 @@ ProcessResult effect_monster_domination(PlayerType *player_ptr, effect_monster_t
         em_ptr->obvious = true;
     }
 
-    if (em_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE) || any_bits(em_ptr->r_ptr->flags1, RF1_QUESTOR) || (em_ptr->r_ptr->flags3 & RF3_NO_CONF) || (em_ptr->r_ptr->level > randint1((em_ptr->dam - 10) < 1 ? 1 : (em_ptr->dam - 10)) + 10)) {
+    const auto is_unique = em_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE);
+    const auto is_questor = any_bits(em_ptr->r_ptr->flags1, RF1_QUESTOR);
+    const auto is_no_confusion = any_bits(em_ptr->r_ptr->flags3, RF3_NO_CONF);
+    if (is_unique || is_questor || is_no_confusion || (em_ptr->r_ptr->level > randint1((em_ptr->dam - 10) < 1 ? 1 : (em_ptr->dam - 10)) + 10)) {
         if (((em_ptr->r_ptr->flags3 & RF3_NO_CONF) != 0) && is_original_ap_and_seen(player_ptr, em_ptr->m_ptr)) {
             em_ptr->r_ptr->r_flags3 |= (RF3_NO_CONF);
         }
index 85a0496..4c8496d 100644 (file)
@@ -926,7 +926,7 @@ bool change_wild_mode(PlayerType *player_ptr, bool encount)
             has_pet = true;
         }
 
-        if (monster_csleep_remaining(m_ptr) || (m_ptr->cdis > MAX_SIGHT) || !is_hostile(m_ptr)) {
+        if (monster_csleep_remaining(m_ptr) || (m_ptr->cdis > MAX_SIGHT) || !m_ptr->is_hostile()) {
             continue;
         }
 
index c35936f..01d018c 100644 (file)
@@ -110,7 +110,7 @@ static void check_darkness(PlayerType *player_ptr, melee_spell_type *ms_ptr)
         return;
     }
 
-    bool vs_ninja = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) && !is_hostile(ms_ptr->t_ptr);
+    bool vs_ninja = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) && !ms_ptr->t_ptr->is_hostile();
     bool can_use_lite_area = vs_ninja && ms_ptr->r_ptr->kind_flags.has_not(MonsterKindType::UNDEAD) && ms_ptr->r_ptr->resistance_flags.has_not(MonsterResistanceType::HURT_LITE) && !(ms_ptr->r_ptr->flags7 & RF7_DARK_MASK);
     if (ms_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID)) {
         return;
index 92c0879..671f13a 100644 (file)
@@ -134,7 +134,7 @@ bool MonsterAttackPlayer::check_no_blow()
         return false;
     }
 
-    return is_hostile(this->m_ptr);
+    return this->m_ptr->is_hostile();
 }
 
 /*!
index 80d5a61..c88fae6 100644 (file)
@@ -255,7 +255,7 @@ bool decide_monster_movement_direction(PlayerType *player_ptr, DIRECTION *mm, MO
         return true;
     }
 
-    if (!is_hostile(m_ptr)) {
+    if (!m_ptr->is_hostile()) {
         mm[0] = mm[1] = mm[2] = mm[3] = 5;
         get_enemy_dir(player_ptr, m_idx, mm);
         return true;
index 194b0f2..95f4950 100644 (file)
@@ -440,7 +440,7 @@ bool process_monster_movement(PlayerType *player_ptr, turn_flags *turn_flags_ptr
 
         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
         if (m_ptr->ml && (disturb_move || (disturb_near && m_ptr->mflag.has(MonsterTemporaryFlagType::VIEW) && projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx)) || (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= player_ptr->lev))) {
-            if (is_hostile(m_ptr)) {
+            if (m_ptr->is_hostile()) {
                 disturb(player_ptr, false, true);
             }
         }
index 97363e7..a8f1940 100644 (file)
@@ -134,7 +134,7 @@ void MonsterSweepGrid::check_hiding_grid(POSITION *y, POSITION *x, POSITION *y2,
     auto *floor_ptr = this->player_ptr->current_floor_ptr;
     auto *m_ptr = &floor_ptr->m_list[this->m_idx];
     auto *r_ptr = &r_info[m_ptr->r_idx];
-    if (this->done || this->will_run || !is_hostile(m_ptr) || none_bits(r_ptr->flags1, RF1_FRIENDS)) {
+    if (this->done || this->will_run || !m_ptr->is_hostile() || none_bits(r_ptr->flags1, RF1_FRIENDS)) {
         return;
     }
 
index 517a075..20d2b71 100644 (file)
@@ -209,7 +209,7 @@ bool are_enemies(PlayerType *player_ptr, monster_type *m_ptr, monster_type *n_pt
         }
     }
 
-    if (is_hostile(m_ptr) != is_hostile(n_ptr)) {
+    if (m_ptr->is_hostile() != n_ptr->is_hostile()) {
         return true;
     }
 
@@ -272,11 +272,6 @@ bool is_original_ap(const monster_type *m_ptr)
     return m_ptr->ap_r_idx == m_ptr->r_idx;
 }
 
-bool is_hostile(const monster_type *m_ptr)
-{
-    return !m_ptr->is_friendly() && !m_ptr->is_pet();
-}
-
 /*!
  * @brief モンスターがアイテム類に擬態しているかどうかを返す
  *
index e494cc2..bf716e3 100644 (file)
@@ -17,7 +17,6 @@ bool are_enemies(PlayerType *player_ptr, monster_type *m_ptr1, monster_type *m_p
 bool monster_has_hostile_align(PlayerType *player_ptr, monster_type *m_ptr, int pa_good, int pa_evil, monster_race *r_ptr);
 bool is_original_ap_and_seen(PlayerType *player_ptr, monster_type *m_ptr);
 
-bool is_hostile(const monster_type *m_ptr);
 bool is_original_ap(const monster_type *m_ptr);
 bool is_mimicry(monster_type *m_ptr);
 
index 79fc955..96863b7 100644 (file)
@@ -507,8 +507,11 @@ static void update_invisible_monster(PlayerType *player_ptr, um_type *um_ptr, MO
         um_ptr->m_ptr->mflag.set(MonsterTemporaryFlagType::SANITY_BLAST);
     }
 
-    if (disturb_near && (projectable(player_ptr, um_ptr->m_ptr->fy, um_ptr->m_ptr->fx, player_ptr->y, player_ptr->x) && projectable(player_ptr, player_ptr->y, player_ptr->x, um_ptr->m_ptr->fy, um_ptr->m_ptr->fx))) {
-        if (disturb_pets || is_hostile(um_ptr->m_ptr)) {
+    const auto &m_ref = *um_ptr->m_ptr;
+    const auto projectable_from_monster = projectable(player_ptr, m_ref.fy, m_ref.fx, player_ptr->y, player_ptr->x);
+    const auto projectable_from_player = projectable(player_ptr, player_ptr->y, player_ptr->x, m_ref.fy, m_ref.fx);
+    if (disturb_near && projectable_from_monster && projectable_from_player) {
+        if (disturb_pets || m_ref.is_hostile()) {
             disturb(player_ptr, true, true);
         }
     }
@@ -531,7 +534,7 @@ static void update_visible_monster(PlayerType *player_ptr, um_type *um_ptr, MONS
         player_ptr->redraw |= PR_UHEALTH;
     }
 
-    if (um_ptr->do_disturb && (disturb_pets || is_hostile(um_ptr->m_ptr))) {
+    if (um_ptr->do_disturb && (disturb_pets || um_ptr->m_ptr->is_hostile())) {
         disturb(player_ptr, true, true);
     }
 }
@@ -544,7 +547,7 @@ static bool update_clear_monster(PlayerType *player_ptr, um_type *um_ptr)
 
     if (um_ptr->m_ptr->mflag.has_not(MonsterTemporaryFlagType::VIEW)) {
         um_ptr->m_ptr->mflag.set(MonsterTemporaryFlagType::VIEW);
-        if (um_ptr->do_disturb && (disturb_pets || is_hostile(um_ptr->m_ptr))) {
+        if (um_ptr->do_disturb && (disturb_pets || um_ptr->m_ptr->is_hostile())) {
             disturb(player_ptr, true, true);
         }
     }
@@ -584,7 +587,7 @@ void update_monster(PlayerType *player_ptr, MONSTER_IDX m_idx, bool full)
     }
 
     um_ptr->m_ptr->mflag.reset(MonsterTemporaryFlagType::VIEW);
-    if (um_ptr->do_disturb && (disturb_pets || is_hostile(um_ptr->m_ptr))) {
+    if (um_ptr->do_disturb && (disturb_pets || um_ptr->m_ptr->is_hostile())) {
         disturb(player_ptr, true, true);
     }
 }
index f621853..04f9308 100644 (file)
@@ -325,7 +325,8 @@ bool make_attack_spell(PlayerType *player_ptr, MONSTER_IDX m_idx)
         return false;
     }
 
-    if (msa_ptr->m_ptr->mflag.has(MonsterTemporaryFlagType::PREVENT_MAGIC) || !is_hostile(msa_ptr->m_ptr) || ((msa_ptr->m_ptr->cdis > get_max_range(player_ptr)) && !msa_ptr->m_ptr->target_y)) {
+    const auto &m_ref = *msa_ptr->m_ptr;
+    if (m_ref.mflag.has(MonsterTemporaryFlagType::PREVENT_MAGIC) || !m_ref.is_hostile() || ((m_ref.cdis > get_max_range(player_ptr)) && !m_ref.target_y)) {
         return false;
     }
 
index 8135360..cbb38b7 100644 (file)
@@ -396,7 +396,6 @@ MonsterSpellResult spell_RF6_DARKNESS(PlayerType *player_ptr, POSITION y, POSITI
     concptr msg_done;
     auto *floor_ptr = player_ptr->current_floor_ptr;
     auto *m_ptr = &floor_ptr->m_list[m_idx];
-    monster_type *t_ptr = &floor_ptr->m_list[t_idx];
     auto *r_ptr = &r_info[m_ptr->r_idx];
     bool can_use_lite_area = false;
     bool monster_to_monster = target_type == MONSTER_TO_MONSTER;
@@ -404,11 +403,15 @@ MonsterSpellResult spell_RF6_DARKNESS(PlayerType *player_ptr, POSITION y, POSITI
     GAME_TEXT t_name[MAX_NLEN];
     monster_name(player_ptr, t_idx, t_name);
 
-    if (PlayerClass(player_ptr).equals(PlayerClassType::NINJA) && r_ptr->kind_flags.has_not(MonsterKindType::UNDEAD) && r_ptr->resistance_flags.has_not(MonsterResistanceType::HURT_LITE) && !(r_ptr->flags7 & RF7_DARK_MASK)) {
+    const auto is_ninja = PlayerClass(player_ptr).equals(PlayerClassType::NINJA);
+    const auto is_living_monster = r_ptr->kind_flags.has_not(MonsterKindType::UNDEAD);
+    const auto is_not_weak_lite = r_ptr->resistance_flags.has_not(MonsterResistanceType::HURT_LITE);
+    if (is_ninja && is_living_monster && is_not_weak_lite && none_bits(r_ptr->flags7, RF7_DARK_MASK)) {
         can_use_lite_area = true;
     }
 
-    if (monster_to_monster && !is_hostile(t_ptr)) {
+    const auto &t_ref = floor_ptr->m_list[t_idx];
+    if (monster_to_monster && !t_ref.is_hostile()) {
         can_use_lite_area = false;
     }
 
index 4cc4cf3..5e71c7a 100644 (file)
@@ -385,7 +385,7 @@ bool process_warning(PlayerType *player_ptr, POSITION xx, POSITION yy)
             if (monster_csleep_remaining(m_ptr)) {
                 continue;
             }
-            if (!is_hostile(m_ptr)) {
+            if (!m_ptr->is_hostile()) {
                 continue;
             }
 
index ee51e20..1707a05 100644 (file)
@@ -9,3 +9,8 @@ bool monster_type::is_pet() const
 {
     return this->mflag2.has(MonsterConstantFlagType::PET);
 }
+
+bool monster_type::is_hostile() const
+{
+    return !this->is_friendly() && !this->is_pet();
+}
index 7f27c05..8b01bee 100644 (file)
@@ -54,4 +54,5 @@ struct monster_type {
 
     bool is_friendly() const;
     bool is_pet() const;
+    bool is_hostile() const;
 };