OSDN Git Service

[Refactor] #3736 get_activation_index() とhas_activation() をItemEntity のオブジェクトメソッドへ繰り込んだ
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 11 Nov 2023 11:16:43 +0000 (20:16 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Mon, 27 Nov 2023 07:42:45 +0000 (16:42 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/action/activation-execution.cpp
src/artifact/artifact-info.cpp [deleted file]
src/artifact/artifact-info.h [deleted file]
src/market/building-craft-fix.cpp
src/object/object-info.cpp
src/object/object-value-calc.cpp
src/system/item-entity.cpp
src/system/item-entity.h

index 6f97753..cb62b6f 100644 (file)
     <ClCompile Include="..\..\src\action\travel-execution.cpp" />\r
     <ClCompile Include="..\..\src\action\tunnel-execution.cpp" />\r
     <ClCompile Include="..\..\src\action\weapon-shield.cpp" />\r
-    <ClCompile Include="..\..\src\artifact\artifact-info.cpp" />\r
     <ClCompile Include="..\..\src\artifact\fixed-art-generator.cpp" />\r
     <ClCompile Include="..\..\src\artifact\random-art-activation.cpp" />\r
     <ClCompile Include="..\..\src\artifact\random-art-characteristics.cpp" />\r
     <ClInclude Include="..\..\src\action\weapon-shield.h" />\r
     <ClInclude Include="..\..\src\artifact\fixed-art-types.h" />\r
     <ClInclude Include="..\..\src\artifact\random-art-effects.h" />\r
-    <ClInclude Include="..\..\src\artifact\artifact-info.h" />\r
     <ClInclude Include="..\..\src\artifact\fixed-art-generator.h" />\r
     <ClInclude Include="..\..\src\artifact\random-art-activation.h" />\r
     <ClInclude Include="..\..\src\artifact\random-art-generator.h" />\r
index 30de6d2..b8905c2 100644 (file)
     <ClCompile Include="..\..\src\artifact\fixed-art-generator.cpp">\r
       <Filter>artifact</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="..\..\src\artifact\artifact-info.cpp">\r
-      <Filter>artifact</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="..\..\src\system\artifact-type-definition.cpp">\r
       <Filter>system</Filter>\r
     </ClCompile>\r
     <ClInclude Include="..\..\src\artifact\fixed-art-generator.h">\r
       <Filter>artifact</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="..\..\src\artifact\artifact-info.h">\r
-      <Filter>artifact</Filter>\r
-    </ClInclude>\r
     <ClInclude Include="..\..\src\system\artifact-type-definition.h">\r
       <Filter>system</Filter>\r
     </ClInclude>\r
index 7ba0646..080dff5 100644 (file)
@@ -17,7 +17,6 @@ hengband_SOURCES = \
        action/tunnel-execution.cpp action/tunnel-execution.h \
        action/weapon-shield.cpp action/weapon-shield.h \
        \
-       artifact/artifact-info.cpp artifact/artifact-info.h \
        artifact/fixed-art-generator.cpp artifact/fixed-art-generator.h \
        artifact/fixed-art-types.h \
        artifact/random-art-activation.cpp artifact/random-art-activation.h \
index f2343cf..93f69a9 100644 (file)
@@ -5,7 +5,6 @@
 
 #include "action/activation-execution.h"
 #include "action/action-limited.h"
-#include "artifact/artifact-info.h"
 #include "artifact/random-art-effects.h"
 #include "core/window-redrawer.h"
 #include "effect/attribute-types.h"
@@ -248,7 +247,7 @@ void exe_activate(PlayerType *player_ptr, INVENTORY_IDX i_idx)
 
     msg_print(_("始動させた...", "You activate it..."));
     sound(SOUND_ZAP);
-    if (activation_index(ae_ptr->o_ptr) > RandomArtActType::NONE) {
+    if (ae_ptr->o_ptr->has_activation()) {
         (void)activate_artifact(player_ptr, ae_ptr->o_ptr);
         static constexpr auto flags = {
             SubWindowRedrawingFlag::INVENTORY,
diff --git a/src/artifact/artifact-info.cpp b/src/artifact/artifact-info.cpp
deleted file mode 100644 (file)
index 183117a..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*!
- * @file artifact-info.cpp
- * @brief アーティファクトの発動効果取得関数定義
- */
-
-#include "artifact/artifact-info.h"
-#include "artifact/random-art-effects.h"
-#include "object-enchant/activation-info-table.h"
-#include "object-enchant/object-ego.h"
-#include "object-enchant/tr-types.h"
-#include "smith/object-smith.h"
-#include "system/artifact-type-definition.h"
-#include "system/baseitem-info.h"
-#include "system/item-entity.h"
-#include "util/bit-flags-calculator.h"
-#include "util/enum-converter.h"
-
-/*!
- * @brief オブジェクトから能力発動IDを取得する。
- * @details いくつかのケースで定義されている発動効果から、
- * 鍛冶師による付与>固定アーティファクト>エゴ>ランダムアーティファクト>ベースアイテムの優先順位で走査していく。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return 発動効果のIDを返す
- */
-RandomArtActType activation_index(const ItemEntity *o_ptr)
-{
-    if (auto act_idx = Smith::object_activation(o_ptr); act_idx) {
-        return *act_idx;
-    }
-
-    if (o_ptr->is_fixed_artifact()) {
-        const auto &artifact = o_ptr->get_fixed_artifact();
-        if (artifact.flags.has(TR_ACTIVATE)) {
-            return artifact.act_idx;
-        }
-    }
-
-    if (o_ptr->is_ego()) {
-        const auto &ego = o_ptr->get_ego();
-        if (ego.flags.has(TR_ACTIVATE)) {
-            return ego.act_idx;
-        }
-    }
-
-    if (!o_ptr->is_random_artifact()) {
-        const auto &baseitem = o_ptr->get_baseitem();
-        if (baseitem.flags.has(TR_ACTIVATE)) {
-            return baseitem.act_idx;
-        }
-    }
-
-    return o_ptr->activation_id;
-}
diff --git a/src/artifact/artifact-info.h b/src/artifact/artifact-info.h
deleted file mode 100644 (file)
index 6ad2e73..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/*!
- * @file artifact-info.h
- * @brief アーティファクトの発動効果取得関数ヘッダ
- */
-
-#pragma once
-
-enum class RandomArtActType : short;
-class ItemEntity;
-RandomArtActType activation_index(const ItemEntity *o_ptr);
index 591b656..7b78a15 100644 (file)
@@ -1,5 +1,4 @@
 #include "market/building-craft-fix.h"
-#include "artifact/artifact-info.h"
 #include "artifact/fixed-art-types.h"
 #include "artifact/random-art-effects.h"
 #include "core/asking-player.h"
@@ -280,7 +279,7 @@ static PRICE repair_broken_weapon_aux(PlayerType *player_ptr, PRICE bcost)
         }
 
         give_one_ability_of_object(o_ptr, mo_ptr);
-        if (activation_index(o_ptr) == RandomArtActType::NONE) {
+        if (!o_ptr->has_activation()) {
             one_activation(o_ptr);
         }
 
index 693fca0..fbbde47 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include "object/object-info.h"
-#include "artifact/artifact-info.h"
 #include "artifact/fixed-art-types.h"
 #include "artifact/random-art-effects.h"
 #include "inventory/inventory-slot-types.h"
@@ -190,7 +189,7 @@ std::string activation_explanation(const ItemEntity *o_ptr)
         return _("なし", "nothing");
     }
 
-    if (activation_index(o_ptr) > RandomArtActType::NONE) {
+    if (o_ptr->has_activation()) {
         return item_activation_aux(o_ptr);
     }
 
index c8b14a5..2ebf454 100644 (file)
@@ -1,5 +1,4 @@
 #include "object/object-value-calc.h"
-#include "artifact/artifact-info.h"
 #include "object-enchant/activation-info-table.h"
 #include "object-enchant/object-ego.h"
 #include "object-enchant/tr-types.h"
index ca142ce..416fc36 100644 (file)
@@ -7,7 +7,6 @@
  */
 
 #include "system/item-entity.h"
-#include "artifact/artifact-info.h" // 暫定的インクルード.
 #include "artifact/fixed-art-types.h"
 #include "artifact/random-art-effects.h"
 #include "monster-race/monster-race.h"
@@ -814,15 +813,13 @@ bool ItemEntity::is_inscribed() const
  */
 std::vector<activation_type>::const_iterator ItemEntity::find_activation_info() const
 {
-    const auto index = activation_index(this);
-    const auto end = activation_info.end();
-    for (auto it = activation_info.begin(); it != end; it++) {
-        if (it->index == index) {
-            return it;
-        }
-    }
+    const auto index = this->get_activation_index();
+    return std::find_if(activation_info.begin(), activation_info.end(), [index](const auto &x) { return x.index == index; });
+}
 
-    return end;
+bool ItemEntity::has_activation() const
+{
+    return this->get_activation_index() != RandomArtActType::NONE;
 }
 
 BaseitemInfo &ItemEntity::get_baseitem() const
@@ -958,3 +955,40 @@ void ItemEntity::modify_ego_lite_flags(TrFlags &flags) const
         return;
     }
 }
+
+/*!
+ * @brief オブジェクトから能力発動IDを取得する。
+ * @details いくつかのケースで定義されている発動効果から、
+ * 鍛冶師による付与>固定アーティファクト>エゴ>ランダムアーティファクト>ベースアイテムの優先順位で走査していく。
+ * @param o_ptr 対象のオブジェクト構造体ポインタ
+ * @return 発動効果のIDを返す
+ */
+RandomArtActType ItemEntity::get_activation_index() const
+{
+    if (auto act_idx = Smith::object_activation(this); act_idx) {
+        return *act_idx;
+    }
+
+    if (this->is_fixed_artifact()) {
+        const auto &artifact = this->get_fixed_artifact();
+        if (artifact.flags.has(TR_ACTIVATE)) {
+            return artifact.act_idx;
+        }
+    }
+
+    if (this->is_ego()) {
+        const auto &ego = this->get_ego();
+        if (ego.flags.has(TR_ACTIVATE)) {
+            return ego.act_idx;
+        }
+    }
+
+    if (!this->is_random_artifact()) {
+        const auto &baseitem = this->get_baseitem();
+        if (baseitem.flags.has(TR_ACTIVATE)) {
+            return baseitem.act_idx;
+        }
+    }
+
+    return this->activation_id;
+}
index 6d47c1c..2f98ba2 100644 (file)
@@ -139,6 +139,7 @@ public:
     bool is_cross_bow() const;
     bool is_inscribed() const;
     std::vector<activation_type>::const_iterator find_activation_info() const;
+    bool has_activation() const;
 
     BaseitemInfo &get_baseitem() const;
     EgoItemDefinition &get_ego() const;
@@ -154,4 +155,5 @@ private:
     int calc_figurine_value() const;
     int calc_capture_value() const;
     void modify_ego_lite_flags(TrFlags &flags) const;
+    RandomArtActType get_activation_index() const;
 };