OSDN Git Service

[Refactor] #2773 SV_ROD_MIN_DIRECTION 定数を廃止し、新たにBaseitemKey::is_aiming_rod() を定義した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 26 Nov 2022 06:07:25 +0000 (15:07 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 26 Nov 2022 11:03:20 +0000 (20:03 +0900)
src/cmd-item/cmd-magiceat.cpp
src/object-use/zaprod-execution.cpp
src/system/baseitem-info.cpp
src/system/baseitem-info.h
src/system/item-entity.cpp
src/system/item-entity.h

index 3142b94..d725609 100644 (file)
@@ -72,8 +72,6 @@
 #include "player-status/player-energy.h"
 #include "player/player-status-table.h"
 #include "spell/spell-info.h"
-#include "sv-definition/sv-other-types.h"
-#include "sv-definition/sv-rod-types.h"
 #include "system/baseitem-info.h"
 #include "system/player-type-definition.h"
 #include "target/target-getter.h"
@@ -598,14 +596,11 @@ bool do_cmd_magic_eater(PlayerType *player_ptr, bool only_browse, bool powerful)
                 return false;
             }
 
-            const auto sval = opt_sval.value();
-            if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE)) {
-                if (!get_aim_dir(player_ptr, &dir)) {
-                    return false;
-                }
+            if (baseitem.is_aiming_rod() && !get_aim_dir(player_ptr, &dir)) {
+                return false;
             }
 
-            (void)rod_effect(player_ptr, sval, dir, &use_charge, powerful);
+            (void)rod_effect(player_ptr, opt_sval.value(), dir, &use_charge, powerful);
             if (!use_charge) {
                 return false;
             }
index a832b1d..cda7c80 100644 (file)
@@ -53,7 +53,7 @@ void ObjectZapRodEntity::execute(INVENTORY_IDX item)
         return;
     }
 
-    if (((o_ptr->sval >= SV_ROD_MIN_DIRECTION) && (o_ptr->sval != SV_ROD_HAVOC) && (o_ptr->sval != SV_ROD_AGGRAVATE) && (o_ptr->sval != SV_ROD_PESTICIDE)) || !o_ptr->is_aware()) {
+    if (o_ptr->is_aiming_rod() || !o_ptr->is_aware()) {
         if (!get_aim_dir(this->player_ptr, &dir)) {
             return;
         }
index da72f25..eefa52f 100644 (file)
 #include "sv-definition/sv-bow-types.h"
 #include "sv-definition/sv-food-types.h"
 #include "sv-definition/sv-protector-types.h"
+#include "sv-definition/sv-rod-types.h"
 #include "sv-definition/sv-weapon-types.h"
 #include <set>
 #include <unordered_map>
 
 namespace {
 constexpr auto ITEM_NOT_BOW = "This item is not a bow!";
+constexpr auto ITEM_NOT_ROD = "This item is not a rod!";
 }
 
 BaseitemKey::BaseitemKey(const ItemKindType type_value, const std::optional<int> &subtype_value)
@@ -453,6 +455,35 @@ int BaseitemKey::get_arrow_magnification() const
     }
 }
 
+bool BaseitemKey::is_aiming_rod() const
+{
+    if ((this->type_value != ItemKindType::ROD) || !this->subtype_value.has_value()) {
+        throw std::logic_error(ITEM_NOT_ROD);
+    }
+
+    switch (this->subtype_value.value()) {
+    case SV_ROD_TELEPORT_AWAY:
+    case SV_ROD_DISARMING:
+    case SV_ROD_LITE:
+    case SV_ROD_SLEEP_MONSTER:
+    case SV_ROD_SLOW_MONSTER:
+    case SV_ROD_HYPODYNAMIA:
+    case SV_ROD_POLYMORPH:
+    case SV_ROD_ACID_BOLT:
+    case SV_ROD_ELEC_BOLT:
+    case SV_ROD_FIRE_BOLT:
+    case SV_ROD_COLD_BOLT:
+    case SV_ROD_ACID_BALL:
+    case SV_ROD_ELEC_BALL:
+    case SV_ROD_FIRE_BALL:
+    case SV_ROD_COLD_BALL:
+    case SV_ROD_STONE_TO_MUD:
+        return true;
+    default:
+        return false;
+    }
+}
+
 bool BaseitemKey::is_mushrooms() const
 {
     if (!this->subtype_value.has_value()) {
index 9393239..11fa650 100644 (file)
@@ -59,6 +59,7 @@ public:
     bool is_rare() const;
     short get_bow_energy() const;
     int get_arrow_magnification() const;
+    bool is_aiming_rod() const;
 
 private:
     ItemKindType type_value;
index 2b50c66..aa56088 100644 (file)
@@ -773,3 +773,8 @@ int ItemEntity::get_arrow_magnification() const
 {
     return BaseitemKey(this->tval, this->sval).get_arrow_magnification();
 }
+
+bool ItemEntity::is_aiming_rod() const
+{
+    return BaseitemKey(this->tval, this->sval).is_aiming_rod();
+}
index f1f883b..ec0991c 100644 (file)
@@ -128,6 +128,7 @@ public:
     bool is_wand_staff() const;
     short get_bow_energy() const;
     int get_arrow_magnification() const;
+    bool is_aiming_rod() const;
 
 private:
     int get_baseitem_price() const;