OSDN Git Service

[Refactor] #2647 is_mimicry() をmonster_type のオブジェクトメソッドとして再定義した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 17 Sep 2022 03:32:03 +0000 (12:32 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 18 Sep 2022 11:06:53 +0000 (20:06 +0900)
src/monster/monster-info.cpp
src/monster/monster-info.h
src/monster/monster-status.cpp
src/monster/monster-status.h
src/system/monster-type-definition.cpp
src/system/monster-type-definition.h
src/target/target-preparation.cpp

index 1cb6b67..7540153 100644 (file)
@@ -267,39 +267,6 @@ bool is_original_ap_and_seen(PlayerType *player_ptr, monster_type *m_ptr)
 }
 
 /*!
- * @brief モンスターがアイテム類に擬態しているかどうかを返す
- *
- * モンスターがアイテム類に擬態しているかどうかを返す。
- * 擬態の条件:
- * - シンボルが以下のいずれかであること: /|\()[]=$,.!?&`#%<>+~
- * - 動かない、もしくは眠っていること
- *
- * 但し、以下のモンスターは例外的に擬態しているとする
- * それ・生ける虚無『ヌル』・ビハインダー
- *
- * @param m_ptr モンスターの参照ポインタ
- * @return モンスターがアイテム類に擬態しているならTRUE、そうでなければFALSE
- */
-bool is_mimicry(monster_type *m_ptr)
-{
-    if (m_ptr->ap_r_idx == MonsterRaceId::IT || m_ptr->ap_r_idx == MonsterRaceId::NULL_ || m_ptr->ap_r_idx == MonsterRaceId::BEHINDER) {
-        return true;
-    }
-
-    auto *r_ptr = &r_info[m_ptr->ap_r_idx];
-
-    if (angband_strchr("/|\\()[]=$,.!?&`#%<>+~", r_ptr->d_char) == nullptr) {
-        return false;
-    }
-
-    if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_MOVE) && !monster_csleep_remaining(m_ptr)) {
-        return false;
-    }
-
-    return true;
-}
-
-/*!
  * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
  * @param m_ptr モンスターの参照ポインタ
  * @return 本当のモンスター種族参照ポインタ
index ff510aa..22bf1e9 100644 (file)
@@ -17,8 +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_mimicry(monster_type *m_ptr);
-
 monster_race *real_r_ptr(monster_type *m_ptr);
 MonsterRaceId real_r_idx(monster_type *m_ptr);
 void monster_name(PlayerType *player_ptr, MONSTER_IDX m_idx, char *m_name);
index 3f10e03..9a188fc 100644 (file)
@@ -528,7 +528,7 @@ bool monster_is_valid(monster_type *m_ptr)
     return MonsterRace(m_ptr->r_idx).is_valid();
 }
 
-TIME_EFFECT monster_csleep_remaining(monster_type *m_ptr)
+TIME_EFFECT monster_csleep_remaining(const monster_type *m_ptr)
 {
     return m_ptr->mtimed[MTIMED_CSLEEP];
 }
index 38346e2..c16414f 100644 (file)
@@ -17,7 +17,7 @@ void monster_gain_exp(PlayerType *player_ptr, MONSTER_IDX m_idx, MonsterRaceId s
 
 void process_monsters_mtimed(PlayerType *player_ptr, int mtimed_idx);
 
-TIME_EFFECT monster_csleep_remaining(monster_type *m_ptr);
+TIME_EFFECT monster_csleep_remaining(const monster_type *m_ptr);
 TIME_EFFECT monster_fast_remaining(monster_type *m_ptr);
 TIME_EFFECT monster_slow_remaining(monster_type *m_ptr);
 TIME_EFFECT monster_stunned_remaining(monster_type *m_ptr);
index 73624e1..1235d18 100644 (file)
@@ -1,4 +1,10 @@
 #include "system/monster-type-definition.h"
+#include "monster-race/monster-race.h"
+#include "monster-race/race-indice-types.h"
+#include "monster-race/race-kind-flags.h"
+#include "monster/monster-status.h"
+#include "system/monster-race-definition.h"
+#include "util/string-processor.h"
 
 bool monster_type::is_friendly() const
 {
@@ -19,3 +25,36 @@ bool monster_type::is_original_ap() const
 {
     return this->ap_r_idx == this->r_idx;
 }
+
+/*!
+ * @brief モンスターがアイテム類に擬態しているかどうかを返す
+ *
+ * モンスターがアイテム類に擬態しているかどうかを返す。
+ * 擬態の条件:
+ * - シンボルが以下のいずれかであること: /|\()[]=$,.!?&`#%<>+~
+ * - 動かない、もしくは眠っていること
+ *
+ * 但し、以下のモンスターは例外的に擬態しているとする
+ * それ・生ける虚無『ヌル』・ビハインダー
+ *
+ * @param m_ptr モンスターの参照ポインタ
+ * @return モンスターがアイテム類に擬態しているならTRUE、そうでなければFALSE
+ */
+bool monster_type::is_mimicry() const
+{
+    if (this->ap_r_idx == MonsterRaceId::IT || this->ap_r_idx == MonsterRaceId::NULL_ || this->ap_r_idx == MonsterRaceId::BEHINDER) {
+        return true;
+    }
+
+    auto *r_ptr = &r_info[this->ap_r_idx];
+
+    if (angband_strchr("/|\\()[]=$,.!?&`#%<>+~", r_ptr->d_char) == nullptr) {
+        return false;
+    }
+
+    if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_MOVE) && !monster_csleep_remaining(this)) {
+        return false;
+    }
+
+    return true;
+}
index 95764c4..718fb1c 100644 (file)
@@ -56,4 +56,5 @@ struct monster_type {
     bool is_pet() const;
     bool is_hostile() const;
     bool is_original_ap() const;
+    bool is_mimicry() const;
 };
index afde241..e9e2584 100644 (file)
@@ -196,7 +196,7 @@ void target_sensing_monsters_prepare(PlayerType *player_ptr, std::vector<MONSTER
         }
 
         // 感知魔法/スキルやESPで感知していない擬態モンスターはモンスター一覧に表示しない
-        if (is_mimicry(m_ptr) && m_ptr->mflag2.has_none_of({ MonsterConstantFlagType::MARK, MonsterConstantFlagType::SHOW }) && m_ptr->mflag.has_not(MonsterTemporaryFlagType::ESP)) {
+        if (m_ptr->is_mimicry() && m_ptr->mflag2.has_none_of({ MonsterConstantFlagType::MARK, MonsterConstantFlagType::SHOW }) && m_ptr->mflag.has_not(MonsterTemporaryFlagType::ESP)) {
             continue;
         }