OSDN Git Service

[Refactor] #3772 dragonbreath_info をvector に置き換えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 2 Dec 2023 11:26:57 +0000 (20:26 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Mon, 4 Dec 2023 10:46:56 +0000 (19:46 +0900)
src/object-activation/activation-breath.cpp
src/object-enchant/dragon-breaths-table.cpp
src/object-enchant/dragon-breaths-table.h
src/object-enchant/tr-types.h
src/smith/smith-tables.h
src/system/item-entity.cpp

index 47fb99f..b3bd750 100644 (file)
@@ -13,6 +13,8 @@
 #include "target/target-getter.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
+#include <utility>
+#include <vector>
 
 /*!
  * @brief 発動によるブレスの属性をアイテムの耐性から選択し、実行を処理する。/ Dragon breath activation
@@ -28,20 +30,15 @@ bool activate_dragon_breath(PlayerType *player_ptr, ItemEntity *o_ptr)
         return false;
     }
 
-    const auto resistance_flags = o_ptr->get_flags();
-
-    AttributeType type[20];
-    int n = 0;
-    concptr name[20];
-    for (int i = 0; dragonbreath_info[i].flag != 0; i++) {
-        if (resistance_flags.has(dragonbreath_info[i].flag)) {
-            type[n] = dragonbreath_info[i].type;
-            name[n] = dragonbreath_info[i].name;
-            n++;
+    const auto flags = o_ptr->get_flags();
+    std::vector<std::pair<AttributeType, std::string>> breaths;
+    for (const auto &dragon_breath : dragonbreath_info) {
+        if (flags.has(dragon_breath.flag)) {
+            breaths.push_back({ dragon_breath.type, dragon_breath.name });
         }
     }
 
-    if (n == 0) {
+    if (breaths.empty()) {
         return false;
     }
 
@@ -53,9 +50,9 @@ bool activate_dragon_breath(PlayerType *player_ptr, ItemEntity *o_ptr)
         (void)SpellHex(player_ptr).stop_all_spells();
     }
 
-    int t = randint0(n);
-    msg_format(_("あなたは%sのブレスを吐いた。", "You breathe %s."), name[t]);
-    fire_breath(player_ptr, type[t], dir, 250, 4);
+    const auto t = randint0(breaths.size());
+    msg_format(_("あなたは%sのブレスを吐いた。", "You breathe %s."), breaths[t].second.data());
+    fire_breath(player_ptr, breaths[t].first, dir, 250, 4);
     return true;
 }
 
index 482cd37..2b47584 100644 (file)
@@ -1,11 +1,13 @@
 #include "object-enchant/dragon-breaths-table.h"
 #include "effect/attribute-types.h"
+#include "locale/language-switcher.h"
+#include "object-enchant/tr-types.h"
 
 /*!
  * @brief 装備耐性に準じたブレス効果の選択テーブル /
  * Define flags, effect type, name for dragon breath activation
  */
-const dragonbreath_type dragonbreath_info[] = {
+const std::vector<dragonbreath_type> dragonbreath_info = {
     { TR_RES_ACID, AttributeType::ACID, _("酸", "acid") },
     { TR_RES_ELEC, AttributeType::ELEC, _("電撃", "lightning") },
     { TR_RES_FIRE, AttributeType::FIRE, _("火炎", "fire") },
@@ -20,5 +22,4 @@ const dragonbreath_type dragonbreath_info[] = {
     { TR_RES_NETHER, AttributeType::NETHER, _("地獄", "nether") },
     { TR_RES_CHAOS, AttributeType::CHAOS, _("カオス", "chaos") },
     { TR_RES_DISEN, AttributeType::DISENCHANT, _("劣化", "disenchantment") },
-    { TR_STR, AttributeType::NONE, nullptr }
 };
index cf909d4..c13e3ee 100644 (file)
@@ -1,13 +1,13 @@
 #pragma once
 
-#include "effect/attribute-types.h"
-#include "object-enchant/tr-types.h"
-#include "system/angband.h"
+#include <vector>
 
+enum tr_type : int;
+enum class AttributeType;
 struct dragonbreath_type {
     tr_type flag;
     AttributeType type;
-    concptr name;
+    std::string name;
 };
 
-extern const dragonbreath_type dragonbreath_info[];
+extern const std::vector<dragonbreath_type> dragonbreath_info;
index 4d223e9..6dfc445 100644 (file)
@@ -1,13 +1,11 @@
 #pragma once
 
-#include "system/angband.h"
-
 #include <array>
 
 /*!
  * @todo TRが何の略か分かる人、補足求む
  */
-enum tr_type : int32_t {
+enum tr_type : int {
     TR_STR = 0, /* STR += "pval" */
     TR_INT = 1, /* INT += "pval" */
     TR_WIS = 2, /* WIS += "pval" */
index 618b85d..6efa2b5 100644 (file)
@@ -5,7 +5,7 @@
 #include <vector>
 
 enum class SmithEssenceType : int16_t;
-enum tr_type : int32_t;
+enum tr_type : int;
 
 /*!
  * @brief エッセンス抽出情報構造体
index 968bbfe..e8e684a 100644 (file)
@@ -1066,19 +1066,21 @@ std::string ItemEntity::build_activation_description(const ActivationType &act)
  */
 std::string ItemEntity::build_activation_description_dragon_breath() const
 {
+    const auto flags = this->get_flags();
     std::stringstream ss;
     ss << _("", "breathe ");
-    auto n = 0;
-    const auto flags = this->get_flags();
-    for (auto i = 0; dragonbreath_info[i].flag != 0; i++) {
-        if (flags.has(dragonbreath_info[i].flag)) {
-            if (n > 0) {
-                ss << _("、", ", ");
-            }
-
-            ss << dragonbreath_info[i].name;
-            n++;
+    auto has_multi_breaths = false;
+    for (const auto &dragon_breath : dragonbreath_info) {
+        if (flags.has_not(dragon_breath.flag)) {
+            continue;
         }
+
+        if (has_multi_breaths) {
+            ss << _("、", ", ");
+        }
+
+        ss << dragon_breath.name;
+        has_multi_breaths = true;
     }
 
     ss << _("のブレス(250)", " (250)");