OSDN Git Service

[Refactor] #2798 bow_tval_ammo() をBaseitemKey::get_arrow_kind() として再定義した
authorHourier <66951241+Hourier@users.noreply.github.com>
Fri, 18 Nov 2022 10:45:41 +0000 (19:45 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Fri, 18 Nov 2022 10:53:22 +0000 (19:53 +0900)
Hengband/Hengband/Hengband.vcxproj
src/Makefile.am
src/flavor/flavor-describer.cpp
src/player/player-status.cpp
src/specific-object/bow.cpp [deleted file]
src/specific-object/bow.h [deleted file]
src/system/baseitem-info.cpp
src/system/baseitem-info.h

index b03bbb8..ce3b46e 100644 (file)
     <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-bow.cpp" />\r
     <ClCompile Include="..\..\src\object-enchant\item-magic-applier.cpp" />\r
     <ClCompile Include="..\..\src\player\eldritch-horror.cpp" />\r
-    <ClCompile Include="..\..\src\specific-object\bow.cpp" />\r
     <ClCompile Include="..\..\src\object\object-stack.cpp" />\r
     <ClCompile Include="..\..\src\object\object-value-calc.cpp" />\r
     <ClCompile Include="..\..\src\perception\object-perception.cpp" />\r
     <ClInclude Include="..\..\src\object-enchant\item-magic-applier.h" />\r
     <ClInclude Include="..\..\src\player\eldritch-horror.h" />\r
     <ClInclude Include="..\..\src\realm\realm-types.h" />\r
-    <ClInclude Include="..\..\src\specific-object\bow.h" />\r
     <ClInclude Include="..\..\src\object\object-stack.h" />\r
     <ClInclude Include="..\..\src\object\object-value-calc.h" />\r
     <ClInclude Include="..\..\src\perception\object-perception.h" />\r
index db85a76..95e2360 100644 (file)
@@ -803,7 +803,6 @@ hengband_SOURCES = \
        \
        specific-object/blade-turner.cpp specific-object/blade-turner.h \
        specific-object/bloody-moon.cpp specific-object/bloody-moon.h \
-       specific-object/bow.cpp specific-object/bow.h \
        specific-object/chest.cpp specific-object/chest.h \
        specific-object/death-crimson.cpp specific-object/death-crimson.h \
        specific-object/death-scythe.cpp specific-object/death-scythe.h \
index c8a5c99..a30ad42 100644 (file)
@@ -28,7 +28,6 @@
 #include "player/player-status.h"
 #include "smith/object-smith.h"
 #include "smith/smith-types.h"
-#include "specific-object/bow.h"
 #include "sv-definition/sv-lite-types.h"
 #include "sv-definition/sv-weapon-types.h"
 #include "system/baseitem-info.h"
@@ -547,9 +546,10 @@ void describe_flavor(PlayerType *player_ptr, char *buf, ItemEntity *o_ptr, BIT_F
     describe_named_item_tval(flavor_ptr);
     if (!(mode & OD_DEBUG)) {
         flavor_ptr->bow_ptr = &player_ptr->inventory_list[INVEN_BOW];
-        if ((flavor_ptr->bow_ptr->bi_id != 0) && (flavor_ptr->o_ptr->tval == bow_tval_ammo(flavor_ptr->bow_ptr))) {
+        const BaseitemKey key(flavor_ptr->bow_ptr->tval, flavor_ptr->bow_ptr->sval);
+        if ((flavor_ptr->bow_ptr->bi_id != 0) && (key.tval() == key.get_arrow_kind())) {
             describe_bow_power(player_ptr, flavor_ptr);
-        } else if (PlayerClass(player_ptr).equals(PlayerClassType::NINJA) && (flavor_ptr->o_ptr->tval == ItemKindType::SPIKE)) {
+        } else if (PlayerClass(player_ptr).equals(PlayerClassType::NINJA) && (key.tval() == ItemKindType::SPIKE)) {
             describe_spike_power(player_ptr, flavor_ptr);
         }
     }
index 5268738..85101cb 100644 (file)
@@ -89,7 +89,6 @@
 #include "realm/realm-hex-numbers.h"
 #include "realm/realm-names-table.h"
 #include "realm/realm-song-numbers.h"
-#include "specific-object/bow.h"
 #include "specific-object/torch.h"
 #include "spell-realm/spells-hex.h"
 #include "spell-realm/spells-song.h"
@@ -334,7 +333,8 @@ static void update_bonuses(PlayerType *player_ptr)
     update_ability_scores(player_ptr);
     o_ptr = &player_ptr->inventory_list[INVEN_BOW];
     if (o_ptr->bi_id) {
-        player_ptr->tval_ammo = bow_tval_ammo(o_ptr);
+        const BaseitemKey key(o_ptr->tval, o_ptr->sval);
+        player_ptr->tval_ammo = key.get_arrow_kind();
         player_ptr->num_fire = calc_num_fire(player_ptr, o_ptr);
     }
 
@@ -1048,7 +1048,8 @@ int16_t calc_num_fire(PlayerType *player_ptr, ItemEntity *o_ptr)
         return (int16_t)num;
     }
 
-    ItemKindType tval_ammo = bow_tval_ammo(o_ptr);
+    const BaseitemKey key(o_ptr->tval, o_ptr->sval);
+    const auto tval_ammo = key.get_arrow_kind();
     PlayerClass pc(player_ptr);
     if (pc.equals(PlayerClassType::RANGER) && (tval_ammo == ItemKindType::ARROW)) {
         num += (player_ptr->lev * 4);
diff --git a/src/specific-object/bow.cpp b/src/specific-object/bow.cpp
deleted file mode 100644 (file)
index ef43ada..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "specific-object/bow.h"
-#include "object/tval-types.h"
-#include "sv-definition/sv-bow-types.h"
-#include "system/item-entity.h"
-
-/*!
- * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す /
- * @param o_ptr 判定する射撃武器のアイテム情報参照ポインタ
- * @return 対応する矢/弾薬のベースアイテムID
- */
-ItemKindType bow_tval_ammo(ItemEntity *o_ptr)
-{
-    switch (o_ptr->sval) {
-    case SV_SLING:
-        return ItemKindType::SHOT;
-    case SV_SHORT_BOW:
-    case SV_LONG_BOW:
-    case SV_NAMAKE_BOW:
-        return ItemKindType::ARROW;
-    case SV_LIGHT_XBOW:
-    case SV_HEAVY_XBOW:
-        return ItemKindType::BOLT;
-    case SV_CRIMSON:
-    case SV_HARP:
-        return ItemKindType::NO_AMMO;
-    }
-
-    return ItemKindType::NONE;
-}
diff --git a/src/specific-object/bow.h b/src/specific-object/bow.h
deleted file mode 100644 (file)
index 1b4e4d9..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#pragma once
-
-enum class ItemKindType : short;
-class ItemEntity;
-ItemKindType bow_tval_ammo(ItemEntity *o_ptr);
index 8fad236..f14ca04 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "system/baseitem-info.h"
 #include "object/tval-types.h"
+#include "sv-definition/sv-bow-types.h"
 
 BaseitemKey::BaseitemKey(const ItemKindType type_value, const std::optional<int> &subtype_value)
     : type_value(type_value)
@@ -45,6 +46,38 @@ std::optional<int> BaseitemKey::sval() const
     return this->subtype_value;
 }
 
+/*!
+ * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す
+ * @return 対応する矢/弾薬のベースアイテムID
+ */
+ItemKindType BaseitemKey::get_arrow_kind() const
+{
+    if (this->type_value != ItemKindType::BOW) {
+        return ItemKindType::NONE;
+    }
+
+    if (!this->subtype_value.has_value()) {
+        return ItemKindType::NONE;
+    }
+
+    switch (this->subtype_value.value()) {
+    case SV_SLING:
+        return ItemKindType::SHOT;
+    case SV_SHORT_BOW:
+    case SV_LONG_BOW:
+    case SV_NAMAKE_BOW:
+        return ItemKindType::ARROW;
+    case SV_LIGHT_XBOW:
+    case SV_HEAVY_XBOW:
+        return ItemKindType::BOLT;
+    case SV_CRIMSON:
+    case SV_HARP:
+        return ItemKindType::NO_AMMO;
+    default:
+        return ItemKindType::NONE;
+    }
+}
+
 BaseitemInfo::BaseitemInfo()
     : bi_key(ItemKindType::NONE)
 {
index 6a661a2..238c993 100644 (file)
@@ -37,6 +37,8 @@ public:
     ItemKindType tval() const;
     std::optional<int> sval() const;
 
+    ItemKindType get_arrow_kind() const;
+
 private:
     ItemKindType type_value;
     std::optional<int> subtype_value;