OSDN Git Service

[Refactor] #2824 BaseitemKey::is_ammo() を定義した
authorHourier <66951241+Hourier@users.noreply.github.com>
Wed, 23 Nov 2022 09:47:02 +0000 (18:47 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Fri, 25 Nov 2022 13:44:51 +0000 (22:44 +0900)
src/artifact/random-art-pval-investor.cpp
src/object-enchant/weapon/abstract-weapon-enchanter.cpp
src/object/tval-types.h
src/smith/object-smith.cpp
src/system/baseitem-info.cpp
src/system/baseitem-info.h
src/system/item-entity.cpp

index 1e80cdc..46be401 100644 (file)
@@ -156,7 +156,7 @@ void random_plus(ItemEntity *o_ptr)
         return;
     }
 
-    int this_type = o_ptr->is_weapon_ammo() ? 23 : 19;
+    const auto this_type = o_ptr->is_weapon_ammo() ? 23 : 19;
     switch (randint1(this_type)) {
     case 1:
     case 2:
index 551a8b5..5a0aae8 100644 (file)
@@ -32,7 +32,7 @@ void AbstractWeaponEnchanter::give_killing_bonus()
     auto tohit2 = static_cast<short>(m_bonus(10, this->level));
     auto todam2 = static_cast<short>(m_bonus(10, this->level));
 
-    if ((this->o_ptr->tval == ItemKindType::BOLT) || (this->o_ptr->tval == ItemKindType::ARROW) || (this->o_ptr->tval == ItemKindType::SHOT)) {
+    if (this->o_ptr->is_ammo()) {
         tohit2 = (tohit2 + 1) / 2;
         todam2 = (todam2 + 1) / 2;
     }
index 3ee1240..630421b 100644 (file)
@@ -76,8 +76,6 @@ enum class ItemKindType : short {
 
 #define TV_EQUIP_BEGIN ItemKindType::SHOT
 #define TV_EQUIP_END ItemKindType::CARD
-#define TV_MISSILE_BEGIN ItemKindType::SHOT
-#define TV_MISSILE_END ItemKindType::BOLT
 #define TV_WEARABLE_BEGIN ItemKindType::BOW
 #define TV_WEARABLE_END ItemKindType::CARD
 #define TV_WEAPON_BEGIN ItemKindType::BOW
index 0d216c7..9f30255 100644 (file)
@@ -167,7 +167,7 @@ int Smith::get_essence_consumption(SmithEffectType effect, const ItemEntity *o_p
         return consumption;
     }
 
-    if ((o_ptr->tval >= ItemKindType::SHOT) && (o_ptr->tval <= ItemKindType::BOLT)) {
+    if (o_ptr->is_ammo()) {
         consumption = (consumption + 9) / 10;
     }
 
index f622295..1dda277 100644 (file)
@@ -126,6 +126,18 @@ bool BaseitemKey::is_melee_weapon() const
     }
 }
 
+bool BaseitemKey::is_ammo() const
+{
+    switch (this->type_value) {
+    case ItemKindType::SHOT:
+    case ItemKindType::ARROW:
+    case ItemKindType::BOLT:
+        return true;
+    default:
+        return false;
+    }
+}
+
 BaseitemInfo::BaseitemInfo()
     : bi_key(ItemKindType::NONE)
 {
index 84ccc85..ff4404f 100644 (file)
@@ -41,6 +41,7 @@ public:
     bool is_spell_book() const;
     bool is_high_level_book() const;
     bool is_melee_weapon() const;
+    bool is_ammo() const;
 
 private:
     ItemKindType type_value;
index 9dac478..2dce046 100644 (file)
@@ -117,13 +117,12 @@ bool ItemEntity::is_weapon() const
 }
 
 /*!
- * @brief アイテムが武器や矢弾として使用できるかを返す / Check if an object is weapon (including bows and ammo)
- * Rare weapons/aromors including Blade of Chaos, Dragon armors, etc.
+ * @brief アイテムが武器や矢弾として使用できるかを返す
  * @return 武器や矢弾として使えるならばtrueを返す
  */
 bool ItemEntity::is_weapon_ammo() const
 {
-    return (TV_MISSILE_BEGIN <= this->tval) && (this->tval <= TV_WEAPON_END);
+    return this->is_weapon() || this->is_ammo();
 }
 
 /*!
@@ -302,7 +301,7 @@ bool ItemEntity::allow_two_hands_wielding() const
  */
 bool ItemEntity::is_ammo() const
 {
-    return (TV_MISSILE_BEGIN <= this->tval) && (this->tval <= TV_MISSILE_END);
+    return BaseitemKey(this->tval).is_ammo();
 }
 
 /*!