OSDN Git Service

[Refactor] #3529 pval の分析処理をParameterValueInfo クラスへ移動させた
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 9 Jul 2023 10:24:31 +0000 (19:24 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Tue, 11 Jul 2023 11:43:34 +0000 (20:43 +0900)
src/wizard/artifact-analyzer.cpp
src/wizard/spoiler-util.cpp
src/wizard/spoiler-util.h

index 154d48d..9dc4de0 100644 (file)
 #include "wizard/spoiler-util.h"
 
 /*!
- * @brief
- * @param art_flags 出力するアーティファクトの特性一覧
- * @param definitions 表記対象の特性一覧
- * @return 表記すべき特性一覧
- */
-static std::vector<std::string> extract_spoiler_flags(const TrFlags &art_flags, const std::vector<flag_desc> definitions)
-{
-    std::vector<std::string> descriptions{};
-    for (const auto &definition : definitions) {
-        if (art_flags.has(definition.flag)) {
-            descriptions.push_back(definition.desc);
-        }
-    }
-
-    return descriptions;
-}
-
-/*!
  * @brief アーティファクトの特性一覧を出力する /
  * Write a line to the spoiler file and then "underline" it with hypens
  * @param art_flags アーティファクトのフラグ群
@@ -76,34 +58,6 @@ static std::string analyze_general(PlayerType *player_ptr, ItemEntity *o_ptr)
 }
 
 /*!
- * @brief アーティファクトがプレイヤーに与えるpval修正を構造体に収める /
- * List "player traits" altered by an artifact's pval. These include stats,
- * speed, infravision, tunneling, stealth, searching, and extra attacks.
- * @param o_ptr オブジェクト構造体の参照ポインタ
- * @param pi_ptr pval修正構造体の参照ポインタ
- */
-static void analyze_pval(ItemEntity *o_ptr, ParameterValueInfo *pi_ptr)
-{
-    if (!o_ptr->pval) {
-        return;
-    }
-
-    auto flags = object_flags(o_ptr);
-    pi_ptr->pval_desc = format("%s%d", o_ptr->pval >= 0 ? "+" : "", o_ptr->pval);
-    std::vector<std::string> pval_descriptions;
-    if (flags.has_all_of(EnumRange(TR_STR, TR_CHR))) {
-        pval_descriptions.push_back(_("全能力", "All stats"));
-    } else if (flags.has_any_of(EnumRange(TR_STR, TR_CHR))) {
-        const auto descriptions_stat = extract_spoiler_flags(flags, stat_flags_desc);
-        pval_descriptions.insert(pval_descriptions.end(), descriptions_stat.begin(), descriptions_stat.end());
-    }
-
-    const auto descriptions_pval1 = extract_spoiler_flags(flags, pval_flags1_desc);
-    pval_descriptions.insert(pval_descriptions.end(), descriptions_pval1.begin(), descriptions_pval1.end());
-    pi_ptr->pval_affects = pval_descriptions;
-}
-
-/*!
  * @brief アーティファクトの種族スレイ特性を構造体に収める /
  * Note the slaying specialties of a weapon
  * @param o_ptr オブジェクト構造体の参照ポインタ
@@ -323,9 +277,7 @@ static void analyze_misc(ItemEntity *o_ptr, char *misc_desc, size_t misc_desc_sz
 }
 
 /*!
- * @brief アーティファクトの情報全体を構造体に収める /
- * Fill in an object description structure for a given object
- * and its value in gold pieces
+ * @brief アーティファクトの情報全体を構造体に収める
  * @param player_ptr プレイヤーへの参照ポインタ
  * @param o_ptr オブジェクト構造体の参照ポインタ
  * @param desc_ptr 全アーティファクト情報を収める文字列参照ポインタ
@@ -333,7 +285,7 @@ static void analyze_misc(ItemEntity *o_ptr, char *misc_desc, size_t misc_desc_sz
 void object_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *desc_ptr)
 {
     angband_strcpy(desc_ptr->description, analyze_general(player_ptr, o_ptr), MAX_NLEN);
-    analyze_pval(o_ptr, &desc_ptr->pval_info);
+    desc_ptr->pval_info.analyze(*o_ptr);
     analyze_brand(o_ptr, desc_ptr->brands);
     analyze_slay(o_ptr, desc_ptr->slays);
     analyze_immune(o_ptr, desc_ptr->immunities);
@@ -347,8 +299,7 @@ void object_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *de
 }
 
 /*!
- * @brief ランダムアーティファクト1件を解析する /
- * Fill in an object description structure for a given object
+ * @brief ランダムアーティファクト1件を解析する
  * @param player_ptr プレイヤーへの参照ポインタ
  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
  * @param desc_ptr 記述内容を収める構造体参照ポインタ
@@ -356,7 +307,7 @@ void object_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *de
 void random_artifact_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *desc_ptr)
 {
     angband_strcpy(desc_ptr->description, analyze_general(player_ptr, o_ptr), MAX_NLEN);
-    analyze_pval(o_ptr, &desc_ptr->pval_info);
+    desc_ptr->pval_info.analyze(*o_ptr);
     analyze_brand(o_ptr, desc_ptr->brands);
     analyze_slay(o_ptr, desc_ptr->slays);
     analyze_immune(o_ptr, desc_ptr->immunities);
index e04e6e3..a476252 100644 (file)
@@ -1,4 +1,6 @@
 #include "wizard/spoiler-util.h"
+#include "object/object-flags.h"
+#include "system/item-entity.h"
 
 const char item_separator = ',';
 const char list_separator = _(',', ';');
@@ -9,6 +11,24 @@ concptr spoiler_indent = "    ";
 FILE *spoiler_file = nullptr;
 
 /*!
+ * @brief 特性フラグ定義から表記すべき特性を抽出する
+ * @param art_flags 出力するアーティファクトの特性一覧
+ * @param definitions 表記対象の特性一覧
+ * @return 表記すべき特性一覧
+ */
+std::vector<std::string> extract_spoiler_flags(const TrFlags &art_flags, const std::vector<flag_desc> &definitions)
+{
+    std::vector<std::string> descriptions{};
+    for (const auto &definition : definitions) {
+        if (art_flags.has(definition.flag)) {
+            descriptions.push_back(definition.desc);
+        }
+    }
+
+    return descriptions;
+}
+
+/*!
  * @brief ファイルポインタ先に同じ文字を複数出力する /
  * Write out `n' of the character `c' to the spoiler file
  * @param n 出力する数
@@ -222,3 +242,22 @@ void spoil_out(std::string_view sv, bool flush_buffer)
         *roff_p++ = ch;
     }
 }
+
+void ParameterValueInfo::analyze(const ItemEntity &item)
+{
+    if (item.pval == 0) {
+        return;
+    }
+
+    auto flags = object_flags(&item);
+    this->pval_desc = format("%s%d", item.pval >= 0 ? "+" : "", item.pval);
+    if (flags.has_all_of(EnumRange(TR_STR, TR_CHR))) {
+        this->pval_affects.push_back(_("全能力", "All stats"));
+    } else if (flags.has_any_of(EnumRange(TR_STR, TR_CHR))) {
+        const auto descriptions_stat = extract_spoiler_flags(flags, stat_flags_desc);
+        this->pval_affects.insert(this->pval_affects.end(), descriptions_stat.begin(), descriptions_stat.end());
+    }
+
+    const auto descriptions_pval1 = extract_spoiler_flags(flags, pval_flags1_desc);
+    this->pval_affects.insert(this->pval_affects.end(), descriptions_pval1.begin(), descriptions_pval1.end());
+}
index c74a26a..f8cebfb 100644 (file)
@@ -1,5 +1,6 @@
 #pragma once
 
+#include "object-enchant/tr-flags.h"
 #include "system/angband.h"
 #include "wizard/spoiler-table.h"
 #include <string>
@@ -19,6 +20,7 @@ enum class SpoilerOutputResultType {
     FILE_CLOSE_FAILED,
 };
 
+class ItemEntity;
 class ParameterValueInfo {
 public:
     ParameterValueInfo() = default;
@@ -27,6 +29,8 @@ public:
 
     /* A list of various player traits affected by an object's pval such as stats, speed, stealth, etc. */
     std::vector<std::string> pval_affects{};
+
+    void analyze(const ItemEntity &item);
 };
 
 struct obj_desc_list {
@@ -51,6 +55,8 @@ extern const int max_evolution_depth;
 extern concptr spoiler_indent;
 extern FILE *spoiler_file;
 
+struct flag_desc;
+std::vector<std::string> extract_spoiler_flags(const TrFlags &art_flags, const std::vector<flag_desc> &definitions);
 void spoiler_blanklines(int n);
 void spoiler_underline(concptr str);
 void spoil_out(std::string_view sv, bool flush_buffer = false);