OSDN Git Service

[Refactor] #2403 Separated apply-magic-arrow.cpp/h from apply-magic.cpp
authorHourier <66951241+Hourier@users.noreply.github.com>
Fri, 11 Mar 2022 13:51:57 +0000 (22:51 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 13 Mar 2022 14:15:04 +0000 (23:15 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/object-enchant/apply-magic.cpp
src/object-enchant/weapon/apply-magic-arrow.cpp [new file with mode: 0644]
src/object-enchant/weapon/apply-magic-arrow.h [new file with mode: 0644]
src/object-enchant/weapon/apply-magic-weapon.cpp

index f8f2b9a..5a0de93 100644 (file)
     <ClCompile Include="..\..\src\object-enchant\protector\apply-magic-hard-armor.cpp" />\r
     <ClCompile Include="..\..\src\object-enchant\weapon\abstract-weapon-enchanter.cpp" />\r
     <ClCompile Include="..\..\src\object-use\quaff\quaff-effects.cpp" />\r
+    <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-arrow.cpp" />\r
     <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-digging.cpp" />\r
     <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-sword.cpp" />\r
     <ClCompile Include="..\..\src\object-use\read\gbh-shirt-read-executor.cpp" />\r
     <ClInclude Include="..\..\src\object-enchant\protector\apply-magic-hard-armor.h" />\r
     <ClInclude Include="..\..\src\object-enchant\weapon\abstract-weapon-enchanter.h" />\r
     <ClInclude Include="..\..\src\object-use\quaff\quaff-effects.h" />\r
+    <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-arrow.h" />\r
     <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-digging.h" />\r
     <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-sword.h" />\r
     <ClInclude Include="..\..\src\object-use\read\gbh-shirt-read-executor.h" />\r
index 5ea3138..700fc14 100644 (file)
     <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-digging.cpp">\r
       <Filter>object-enchant\weapon</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-arrow.cpp">\r
+      <Filter>object-enchant\weapon</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\src\combat\shoot.h">\r
     <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-digging.h">\r
       <Filter>object-enchant\weapon</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-arrow.h">\r
+      <Filter>object-enchant\weapon</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <None Include="..\..\src\wall.bmp" />\r
index 462cfcd..27a9d8e 100644 (file)
@@ -619,6 +619,7 @@ hengband_SOURCES = \
        object-enchant/protector/apply-magic-soft-armor.cpp object-enchant/protector/apply-magic-soft-armor.h \
        \
        object-enchant/weapon/abstract-weapon-enchanter.cpp object-enchant/weapon/abstract-weapon-enchanter.h \
+       object-enchant/weapon/apply-magic-arrow.cpp object-enchant/weapon/apply-magic-arrow.h \
        object-enchant/weapon/apply-magic-digging.cpp object-enchant/weapon/apply-magic-digging.h \
        object-enchant/weapon/apply-magic-sword.cpp object-enchant/weapon/apply-magic-sword.h \
        object-enchant/weapon/apply-magic-weapon.cpp object-enchant/weapon/apply-magic-weapon.h \
index eeef971..de6a899 100644 (file)
@@ -31,6 +31,7 @@
 #include "object-enchant/tr-types.h"
 #include "object-enchant/trc-types.h"
 #include "object-enchant/trg-types.h"
+#include "object-enchant/weapon/apply-magic-arrow.h"
 #include "object-enchant/weapon/apply-magic-digging.h"
 #include "object-enchant/weapon/apply-magic-sword.h"
 #include "object-enchant/weapon/apply-magic-weapon.h"
@@ -143,10 +144,12 @@ void apply_magic_to_object(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH lev,
         DiggingEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
         break;
     case ItemKindType::BOW:
+        WeaponEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
+        break;
     case ItemKindType::SHOT:
     case ItemKindType::ARROW:
     case ItemKindType::BOLT:
-        WeaponEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
+        ArrowEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
         break;
     case ItemKindType::HAFTED:
     case ItemKindType::POLEARM:
diff --git a/src/object-enchant/weapon/apply-magic-arrow.cpp b/src/object-enchant/weapon/apply-magic-arrow.cpp
new file mode 100644 (file)
index 0000000..cd1bed4
--- /dev/null
@@ -0,0 +1,60 @@
+/*!
+ * @brief 矢類のアイテムを強化する処理
+ * @date 2022/03/11
+ * @author Hourier
+ */
+
+#include "object-enchant/weapon/apply-magic-arrow.h"
+#include "artifact/random-art-generator.h"
+#include "floor/floor-base-definitions.h"
+#include "inventory/inventory-slot-types.h"
+#include "system/object-type-definition.h"
+#include "system/player-type-definition.h"
+
+/*!
+ * @brief 矢類強化クラスのコンストラクタ
+ * @param player_ptr プレイヤーへの参照ポインタ
+ * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
+ * @param level 生成基準階
+ * @param power 生成ランク
+ */
+ArrowEnchanter::ArrowEnchanter(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH level, int power)
+    : AbstractWeaponEnchanter(o_ptr, level, power)
+    , player_ptr(player_ptr)
+{
+}
+
+/*!
+ * @brief 矢類に生成ランクごとの強化を与えるサブルーチン
+ * @details power > 2はデバッグ専用.
+ */
+void ArrowEnchanter::apply_magic()
+{
+    if (this->should_skip) {
+        return;
+    }
+
+    if (this->power > 1) {
+        if (this->power > 2) {
+            become_random_artifact(this->player_ptr, this->o_ptr, false);
+            return;
+        }
+
+        this->o_ptr->ego_idx = get_random_ego(INVEN_AMMO, true);
+        while (one_in_(10 * this->o_ptr->dd * this->o_ptr->ds)) {
+            this->o_ptr->dd++;
+        }
+
+        if (this->o_ptr->dd > 9) {
+            this->o_ptr->dd = 9;
+        }
+
+        return;
+    }
+
+    if (this->power < -1) {
+        if (randint0(MAX_DEPTH) < this->level) {
+            this->o_ptr->ego_idx = get_random_ego(INVEN_AMMO, false);
+        }
+    }
+}
diff --git a/src/object-enchant/weapon/apply-magic-arrow.h b/src/object-enchant/weapon/apply-magic-arrow.h
new file mode 100644 (file)
index 0000000..fabeaf5
--- /dev/null
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "object-enchant/weapon/abstract-weapon-enchanter.h"
+#include "system/angband.h"
+
+class ObjectType;
+class PlayerType;
+class ArrowEnchanter : AbstractWeaponEnchanter {
+public:
+    ArrowEnchanter(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH level, int power);
+    void apply_magic() override;
+
+protected:
+    void sval_enchant() override{};
+    void give_ego_index() override{};
+    void give_high_ego_index() override{};
+    void give_cursed() override{};
+
+private:
+    PlayerType *player_ptr;
+};
index 7323862..ac4c8fb 100644 (file)
@@ -42,49 +42,12 @@ void WeaponEnchanter::apply_magic()
         return;
     }
 
-    switch (this->o_ptr->tval) {
-    case ItemKindType::BOW: {
-        if (this->power > 1) {
-            if ((this->power > 2) || one_in_(20)) {
-                become_random_artifact(this->player_ptr, this->o_ptr, false);
-                break;
-            }
-
-            this->o_ptr->ego_idx = get_random_ego(INVEN_BOW, true);
-        }
-
-        break;
-    }
-    case ItemKindType::BOLT:
-    case ItemKindType::ARROW:
-    case ItemKindType::SHOT: {
-        if (this->power > 1) {
-            if (this->power > 2) {
-                become_random_artifact(this->player_ptr, this->o_ptr, false);
-                break;
-            }
-
-            this->o_ptr->ego_idx = get_random_ego(INVEN_AMMO, true);
-            while (one_in_(10L * this->o_ptr->dd * this->o_ptr->ds)) {
-                this->o_ptr->dd++;
-            }
-
-            if (this->o_ptr->dd > 9) {
-                this->o_ptr->dd = 9;
-            }
-
-            break;
+    if (this->power > 1) {
+        if ((this->power > 2) || one_in_(20)) {
+            become_random_artifact(this->player_ptr, this->o_ptr, false);
+            return;
         }
 
-        if (this->power < -1) {
-            if (randint0(MAX_DEPTH) < this->level) {
-                this->o_ptr->ego_idx = get_random_ego(INVEN_AMMO, false);
-            }
-        }
-
-        break;
-    }
-    default:
-        break;
+        this->o_ptr->ego_idx = get_random_ego(INVEN_BOW, true);
     }
 }