OSDN Git Service

[Refactor] #3541 obj_desc_list::immunities の型をconcptr[] からvector<string> に変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Tue, 11 Jul 2023 13:52:23 +0000 (22:52 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Fri, 14 Jul 2023 12:56:14 +0000 (21:56 +0900)
src/wizard/artifact-analyzer.cpp
src/wizard/fixed-artifacts-spoiler.cpp
src/wizard/fixed-artifacts-spoiler.h
src/wizard/spoiler-table.cpp
src/wizard/spoiler-table.h
src/wizard/spoiler-util.h

index 427af45..38179a5 100644 (file)
 #include "wizard/spoiler-util.h"
 
 /*!
- * @brief アーティファクトの特性一覧を出力する /
- * Write a line to the spoiler file and then "underline" it with hypens
- * @param art_flags アーティファクトのフラグ群
- * @param flag_ptr フラグ記述情報の参照ポインタ
- * @param desc_ptr 記述内容を返すための文字列参照ポインタ
- * @param n_elmnts フラグの要素数
- * @return desc_ptrと同じアドレス
- * @details
- * <pre>
- * This function does most of the actual "analysis". Given a set of bit flags
- * (which will be from one of the flags fields from the object in question),
- * a "flag description structure", a "description list", and the number of
- * elements in the "flag description structure", this function sets the
- * "description list" members to the appropriate descriptions contained in
- * the "flag description structure".
- * The possibly updated description pointer is returned.
- * </pre>
- */
-static concptr *spoiler_flag_aux(const TrFlags &art_flags, const flag_desc *flag_ptr, concptr *desc_ptr, const int n_elmnts)
-{
-    for (int i = 0; i < n_elmnts; ++i) {
-        if (art_flags.has(flag_ptr[i].flag)) {
-            *desc_ptr++ = flag_ptr[i].desc;
-        }
-    }
-
-    return desc_ptr;
-}
-
-/*!
  * @brief アイテムの特定記述内容を返す /
  * Acquire a "basic" description "The Cloak of Death [1,+10]"
  * @param o_ptr 記述を得たいオブジェクトの参照ポインタ
@@ -99,11 +69,10 @@ static std::vector<std::string> analyze_resist(ItemEntity *o_ptr)
  * @param o_ptr オブジェクト構造体の参照ポインタ
  * @param immune_list 免疫構造体の参照ポインタ
  */
-static void analyze_immune(ItemEntity *o_ptr, concptr *immune_list)
+static std::vector<std::string> analyze_immune(ItemEntity *o_ptr)
 {
     auto flags = object_flags(o_ptr);
-    immune_list = spoiler_flag_aux(flags, immune_flags_desc, immune_list, N_ELEMENTS(immune_flags_desc));
-    *immune_list = nullptr;
+    return extract_spoiler_flags(flags, immune_flags_desc);
 }
 
 /*!
@@ -286,7 +255,7 @@ void object_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *de
     desc_ptr->pval_info.analyze(*o_ptr);
     desc_ptr->brands = analyze_brand(o_ptr);
     desc_ptr->slays = analyze_slay(o_ptr);
-    analyze_immune(o_ptr, desc_ptr->immunities);
+    desc_ptr->immunities = analyze_immune(o_ptr);
     desc_ptr->resistances = analyze_resist(o_ptr);
     desc_ptr->vulnerabilities = analyze_vulnerable(o_ptr);
     desc_ptr->sustenances = analyze_sustains(o_ptr);
@@ -308,7 +277,7 @@ void random_artifact_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc
     desc_ptr->pval_info.analyze(*o_ptr);
     desc_ptr->brands = analyze_brand(o_ptr);
     desc_ptr->slays = analyze_slay(o_ptr);
-    analyze_immune(o_ptr, desc_ptr->immunities);
+    desc_ptr->immunities = analyze_immune(o_ptr);
     desc_ptr->resistances = analyze_resist(o_ptr);
     desc_ptr->vulnerabilities = analyze_vulnerable(o_ptr);
     desc_ptr->sustenances = analyze_sustains(o_ptr);
index 65af441..9def5bd 100644 (file)
@@ -57,55 +57,6 @@ void spoiler_outlist(std::string_view header, const std::vector<std::string> &de
 }
 
 /*!
- * @brief フラグ名称を出力する汎用関数
- * @param header ヘッダに出力するフラグ群の名前
- * @param list フラグ名リスト
- * @param separator フラグ表示の区切り記号
- * @todo 固定アーティファクトとランダムアーティファクトで共用、ここに置くべきかは要調整.
- * @todo いずれ上で定義したオーバーロードに吸収合併させてこれは消滅させる予定
- */
-void spoiler_outlist(concptr header, concptr *list, char separator)
-{
-    if (*list == nullptr) {
-        return;
-    }
-
-    std::string line = spoiler_indent;
-    if (header && (header[0])) {
-        line.append(header).append(" ");
-    }
-
-    while (true) {
-        std::string elem = *list;
-        if (list[1]) {
-            elem.push_back(separator);
-            elem.push_back(' ');
-        }
-
-        if (line.length() + elem.length() <= MAX_LINE_LEN) {
-            line.append(elem);
-        } else {
-            if (line.length() > 1 && line[line.length() - 1] == ' ' && line[line.length() - 2] == list_separator) {
-                line[line.length() - 2] = '\0';
-                fprintf(spoiler_file, "%s\n", line.data());
-                line = spoiler_indent;
-                line.append(elem);
-            } else {
-                fprintf(spoiler_file, "%s\n", line.data());
-                line = "      ";
-                line.append(elem);
-            }
-        }
-
-        if (!*++list) {
-            break;
-        }
-    }
-
-    fprintf(spoiler_file, "%s\n", line.data());
-}
-
-/*!
  * @brief アーティファクト情報を出力するためにダミー生成を行う /
  * Hack -- Create a "forged" artifact
  * @param o_ptr 一時生成先を保管するオブジェクト構造体
index d14a598..f915dbf 100644 (file)
@@ -4,5 +4,4 @@
 #include "wizard/spoiler-util.h"
 
 void spoiler_outlist(std::string_view header, const std::vector<std::string> &descriptions, char seperator);
-void spoiler_outlist(concptr header, concptr *list, char separator);
 SpoilerOutputResultType spoil_fixed_artifact(concptr fname);
index b91bb18..e1623b5 100644 (file)
@@ -146,7 +146,7 @@ const std::vector<flag_desc> vulnerable_flags_desc = {
 };
 
 /* Elemental immunities (along with poison) */
-const flag_desc immune_flags_desc[MAX_IMMUNITY_FLAGS_DESCRIPTION] = {
+const std::vector<flag_desc> immune_flags_desc = {
     { TR_IM_ACID, _("酸", "Acid") },
     { TR_IM_ELEC, _("電撃", "Lightning") },
     { TR_IM_FIRE, _("火炎", "Fire") },
index 50b83ee..f0731f2 100644 (file)
@@ -5,8 +5,6 @@
 #include "system/angband.h"
 #include <vector>
 
-#define MAX_IMMUNITY_FLAGS_DESCRIPTION 4
-
 /* A tval grouper */
 struct grouper {
     std::vector<ItemKindType> tval_set;
@@ -32,7 +30,7 @@ extern const std::vector<flag_desc> slay_flags_desc;
 extern const std::vector<flag_desc> brand_flags_desc;
 extern const std::vector<flag_desc> resist_flags_desc;
 extern const std::vector<flag_desc> vulnerable_flags_desc;
-extern const flag_desc immune_flags_desc[MAX_IMMUNITY_FLAGS_DESCRIPTION];
+extern const std::vector<flag_desc> immune_flags_desc;
 extern const std::vector<flag_desc> sustain_flags_desc;
 extern const std::vector<flag_desc> misc_flags2_desc;
 extern const std::vector<flag_desc> misc_flags3_desc;
index 7d95f23..01d7ea7 100644 (file)
@@ -10,9 +10,6 @@
 /* MAX_LINE_LEN specifies when a line should wrap. */
 #define MAX_LINE_LEN 75
 
-/* Given an array, determine how many elements are in the array */
-#define N_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
-
 enum class SpoilerOutputResultType {
     CANCELED,
     SUCCESSFUL,
@@ -38,7 +35,7 @@ struct obj_desc_list {
     ParameterValueInfo pval_info{}; /* Description of what is affected by an object's pval */
     std::vector<std::string> slays{}; /* A list of an object's slaying preferences */
     std::vector<std::string> brands{}; /* A list if an object's elemental brands */
-    concptr immunities[N_ELEMENTS(immune_flags_desc) + 1]{}; /* A list of immunities granted by an object */
+    std::vector<std::string> immunities{}; /* A list of immunities granted by an object */
     std::vector<std::string> resistances{}; /* A list of resistances granted by an object */
     std::vector<std::string> vulnerabilities{}; /* A list of resistances granted by an object */
     std::vector<std::string> sustenances{}; /* A list of stats sustained by an object */