OSDN Git Service

[Refactor] #3541 obj_desc_list::misc_desc の型をchar[] からstring に変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Tue, 11 Jul 2023 14:17:38 +0000 (23:17 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Fri, 14 Jul 2023 23:36:32 +0000 (08:36 +0900)
src/io-dump/random-art-info-dumper.cpp
src/wizard/artifact-analyzer.cpp
src/wizard/fixed-artifacts-spoiler.cpp
src/wizard/spoiler-util.h

index d1c8d72..b043453 100644 (file)
@@ -24,7 +24,7 @@
 static void spoiler_print_randart(ItemEntity *o_ptr, obj_desc_list *art_ptr)
 {
     const auto finalizer = util::make_finalizer([art_ptr]() {
-        fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc);
+        fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc.data());
     });
     const auto *pval_ptr = &art_ptr->pval_info;
     fprintf(spoiler_file, "%s\n", art_ptr->description.data());
index 97ae46a..af92755 100644 (file)
@@ -239,12 +239,13 @@ static std::string analyze_addition(ItemEntity *o_ptr)
  * @param misc_desc 基本情報を収める文字列参照ポインタ
  * @param misc_desc_sz misc_desc に書き込めるバイト数
  */
-static void analyze_misc(ItemEntity *o_ptr, char *misc_desc, size_t misc_desc_sz)
+static std::string analyze_misc(ItemEntity *o_ptr)
 {
     const auto &artifact = o_ptr->get_fixed_artifact();
-    const auto *mes = _("レベル %d, 希少度 %u, %d.%d kg, $%ld", "Level %d, Rarity %u, %d.%d lbs, %ld Gold");
-    strnfmt(misc_desc, misc_desc_sz, mes, (int)artifact.level, artifact.rarity,
-        _(lb_to_kg_integer(artifact.weight), artifact.weight / 10), _(lb_to_kg_fraction(artifact.weight), artifact.weight % 10), (long int)artifact.cost);
+    constexpr auto fmt = _("レベル %d, 希少度 %u, %d.%d kg, $%d", "Level %d, Rarity %u, %d.%d lbs, %d Gold");
+    const auto weight_integer = _(lb_to_kg_integer(artifact.weight), artifact.weight / 10);
+    const auto weight_fraction = _(lb_to_kg_fraction(artifact.weight), artifact.weight % 10);
+    return format(fmt, artifact.level, artifact.rarity, weight_integer, weight_fraction, artifact.cost);
 }
 
 /*!
@@ -265,7 +266,7 @@ void object_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc_list *de
     desc_ptr->sustenances = analyze_sustains(o_ptr);
     desc_ptr->misc_magic = analyze_misc_magic(o_ptr);
     desc_ptr->addition = analyze_addition(o_ptr);
-    analyze_misc(o_ptr, desc_ptr->misc_desc, sizeof(desc_ptr->misc_desc));
+    desc_ptr->misc_desc = analyze_misc(o_ptr);
     desc_ptr->activation = activation_explanation(o_ptr);
 }
 
@@ -287,6 +288,8 @@ void random_artifact_analyze(PlayerType *player_ptr, ItemEntity *o_ptr, obj_desc
     desc_ptr->sustenances = analyze_sustains(o_ptr);
     desc_ptr->misc_magic = analyze_misc_magic(o_ptr);
     desc_ptr->activation = activation_explanation(o_ptr);
-    strnfmt(desc_ptr->misc_desc, sizeof(desc_ptr->misc_desc), _("重さ %d.%d kg", "Weight %d.%d lbs"), _(lb_to_kg_integer(o_ptr->weight), o_ptr->weight / 10),
-        _(lb_to_kg_fraction(o_ptr->weight), o_ptr->weight % 10));
+    constexpr auto weight_mes = _("重さ %d.%d kg", "Weight %d.%d lbs");
+    const auto weight_integer = _(lb_to_kg_integer(o_ptr->weight), o_ptr->weight / 10);
+    const auto weight_fraction = _(lb_to_kg_fraction(o_ptr->weight), o_ptr->weight % 10);
+    desc_ptr->misc_desc = format(weight_mes, weight_integer, weight_fraction);
 }
index 0e01141..0d18e58 100644 (file)
@@ -119,7 +119,7 @@ static void spoiler_print_art(obj_desc_list *art_ptr)
         fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent, art_ptr->activation.data());
     }
 
-    fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc);
+    fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc.data());
 }
 
 /*!
index e379eff..d0ecca0 100644 (file)
@@ -43,7 +43,7 @@ struct obj_desc_list {
 
     std::string addition = ""; /* Additional ability or resistance */
     std::string activation = ""; /* A string describing an artifact's activation */
-    char misc_desc[80] = ""; /* "Level 20, Rarity 30, 3.0 lbs, 20000 Gold" */
+    std::string misc_desc = ""; /* "Level 20, Rarity 30, 3.0 lbs, 20000 Gold" */
 };
 
 extern const char item_separator;