OSDN Git Service

[Refactor] #4503 lore_type::has_reinforce() を実装してMonsterRaceInfo への依存性を下げた
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 18 Aug 2024 08:40:12 +0000 (17:40 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 24 Aug 2024 12:56:01 +0000 (21:56 +0900)
src/lore/lore-util.cpp
src/lore/lore-util.h
src/lore/monster-lore.cpp
src/system/monster-race-info.cpp
src/system/monster-race-info.h
src/view/display-lore.cpp

index cf210f0..e0ecb00 100644 (file)
@@ -56,6 +56,11 @@ lore_type::lore_type(MonsterRaceId r_idx, monster_lore_mode mode)
     this->misc_flags = (this->r_ptr->misc_flags & this->r_ptr->r_misc_flags);
 }
 
+bool lore_type::has_reinforce() const
+{
+    return this->r_ptr->has_reinforce();
+}
+
 /*!
  * @brief モンスターの思い出メッセージをあらかじめ指定された関数ポインタに基づき出力する
  * @param str 出力文字列
index e3eead2..7741aa9 100644 (file)
@@ -47,7 +47,6 @@ struct lore_type {
     bool sin = false;
 #endif
 
-    bool has_reinforce = false;
     bool know_everything = false;
     bool old = false;
     int count = 0;
@@ -84,6 +83,8 @@ struct lore_type {
     EnumClassFlagGroup<MonsterBrightnessType> brightness_flags;
     EnumClassFlagGroup<MonsterSpecialType> special_flags;
     EnumClassFlagGroup<MonsterMiscType> misc_flags;
+
+    bool has_reinforce() const;
 };
 
 using hook_c_roff_pf = void (*)(TERM_COLOR attr, std::string_view str);
index 84aa577..4e295ae 100644 (file)
@@ -138,12 +138,6 @@ void process_monster_lore(PlayerType *player_ptr, MonsterRaceId r_idx, monster_l
 {
     lore_type tmp_lore(r_idx, mode);
     lore_type *lore_ptr = &tmp_lore;
-    const auto end = lore_ptr->r_ptr->reinforces.end();
-    const auto it_reinforce = std::find_if(
-        lore_ptr->r_ptr->reinforces.begin(), end,
-        [](const auto &reinforce) { return reinforce.is_valid(); });
-    lore_ptr->has_reinforce = it_reinforce != end;
-
     if (cheat_know || (mode == MONSTER_LORE_RESEARCH) || (mode == MONSTER_LORE_DEBUG)) {
         lore_ptr->know_everything = true;
     }
index c7d7766..e8f2969 100644 (file)
@@ -256,6 +256,14 @@ std::string MonsterRaceInfo::build_eldritch_horror_message(std::string_view desc
     return format(fmt, horror_message.data(), description.data());
 }
 
+bool MonsterRaceInfo::has_reinforce() const
+{
+    const auto end = this->reinforces.end();
+    const auto it = std::find_if(this->reinforces.begin(), end,
+        [](const auto &reinforce) { return reinforce.is_valid(); });
+    return it != end;
+}
+
 std::optional<std::string> MonsterRaceInfo::probe_lore()
 {
     auto n = false;
index 526fe77..3b49df2 100644 (file)
@@ -151,6 +151,7 @@ public:
     int calc_figurine_value() const;
     int calc_capture_value() const;
     std::string build_eldritch_horror_message(std::string_view description) const;
+    bool has_reinforce() const;
 
     std::optional<std::string> probe_lore();
     void make_lore_treasure(int num_item, int num_drop);
index c5acaff..e1bb2e3 100644 (file)
@@ -521,7 +521,7 @@ void display_lore_this(PlayerType *player_ptr, lore_type *lore_ptr)
 
 static void display_monster_escort_contents(lore_type *lore_ptr)
 {
-    if (!lore_ptr->has_reinforce) {
+    if (!lore_ptr->has_reinforce()) {
         return;
     }
 
@@ -568,7 +568,7 @@ static void display_monster_escort_contents(lore_type *lore_ptr)
 
 void display_monster_collective(lore_type *lore_ptr)
 {
-    if (lore_ptr->misc_flags.has(MonsterMiscType::ESCORT) || lore_ptr->misc_flags.has(MonsterMiscType::MORE_ESCORT) || lore_ptr->has_reinforce) {
+    if (lore_ptr->misc_flags.has(MonsterMiscType::ESCORT) || lore_ptr->misc_flags.has(MonsterMiscType::MORE_ESCORT) || lore_ptr->has_reinforce()) {
         hooked_roff(format(_("%s^は通常護衛を伴って現れる。", "%s^ usually appears with escorts.  "), Who::who(lore_ptr->msex)));
         display_monster_escort_contents(lore_ptr);
     } else if (lore_ptr->misc_flags.has(MonsterMiscType::HAS_FRIENDS)) {