OSDN Git Service

Merge pull request #3561 from Hourier/Change-Signature-Terms
[hengbandforosx/hengbandosx.git] / src / io-dump / random-art-info-dumper.cpp
1 #include "io-dump/random-art-info-dumper.h"
2 #include "floor/floor-town.h"
3 #include "inventory/inventory-slot-types.h"
4 #include "io/files-util.h"
5 #include "perception/object-perception.h"
6 #include "store/store-util.h"
7 #include "system/item-entity.h"
8 #include "system/player-type-definition.h"
9 #include "util/angband-files.h"
10 #include "util/finalizer.h"
11 #include "view/display-messages.h"
12 #include "wizard/artifact-analyzer.h"
13 #include "wizard/fixed-artifacts-spoiler.h"
14 #include "wizard/spoiler-util.h"
15 #include <sstream>
16
17 /*!
18  * @brief ランダムアーティファクト1件をスポイラー出力する /
19  * Create a spoiler file entry for an artifact
20  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
21  * @param art_ptr 記述内容を収めた構造体参照ポインタ
22  * Fill in an object description structure for a given object
23  */
24 static void spoiler_print_randart(ItemEntity *o_ptr, obj_desc_list *art_ptr)
25 {
26     const auto finalizer = util::make_finalizer([art_ptr]() {
27         fprintf(spoiler_file, "%s%s\n\n", spoiler_indent.data(), art_ptr->misc_desc.data());
28     });
29     const auto *pval_ptr = &art_ptr->pval_info;
30     fprintf(spoiler_file, "%s\n", art_ptr->description.data());
31     if (!o_ptr->is_fully_known()) {
32         fprintf(spoiler_file, _("%s不明\n", "%sUnknown\n"), spoiler_indent.data());
33         return;
34     }
35
36     if (!pval_ptr->pval_desc.empty()) {
37         std::stringstream ss;
38         ss << pval_ptr->pval_desc << _("の修正:", " to");
39         spoiler_outlist(ss.str(), pval_ptr->pval_affects, item_separator);
40     }
41
42     spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator);
43     spoiler_outlist(_("武器属性:", ""), art_ptr->brands, list_separator);
44     spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, item_separator);
45     spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, item_separator);
46     spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustenances, item_separator);
47     spoiler_outlist("", art_ptr->misc_magic, list_separator);
48     if (!art_ptr->activation.empty()) {
49         fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent.data(), art_ptr->activation.data());
50     }
51 }
52
53 /*!
54  * @brief ランダムアーティファクト内容をスポイラー出力するサブルーチン /
55  * @param player_ptr プレイヤーへの参照ポインタ
56  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
57  * @param tval 出力したいランダムアーティファクトの種類
58  */
59 static void spoil_random_artifact_aux(PlayerType *player_ptr, ItemEntity *o_ptr, ItemKindType tval)
60 {
61     obj_desc_list artifact;
62     if (!o_ptr->is_known() || !o_ptr->is_random_artifact() || (o_ptr->bi_key.tval() != tval)) {
63         return;
64     }
65
66     random_artifact_analyze(player_ptr, o_ptr, &artifact);
67     spoiler_print_randart(o_ptr, &artifact);
68 }
69
70 /*!
71  * @brief ランダムアーティファクト内容をスポイラー出力するメインルーチン /
72  * Create a list file for random artifacts
73  * @param fname 出力ファイル名
74  */
75 void spoil_random_artifact(PlayerType *player_ptr, concptr fname)
76 {
77     const auto &path = path_build(ANGBAND_DIR_USER, fname);
78     spoiler_file = angband_fopen(path, FileOpenMode::WRITE);
79     if (!spoiler_file) {
80         msg_print("Cannot create list file.");
81         return;
82     }
83
84     spoiler_underline("Random artifacts list.\r");
85     for (const auto &[tval_list, name] : group_artifact_list) {
86         for (auto tval : tval_list) {
87             for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
88                 auto *q_ptr = &player_ptr->inventory_list[i];
89                 spoil_random_artifact_aux(player_ptr, q_ptr, tval);
90             }
91
92             for (int i = 0; i < INVEN_PACK; i++) {
93                 auto *q_ptr = &player_ptr->inventory_list[i];
94                 spoil_random_artifact_aux(player_ptr, q_ptr, tval);
95             }
96
97             const auto *store_ptr = &towns_info[1].stores[StoreSaleType::HOME];
98             for (int i = 0; i < store_ptr->stock_num; i++) {
99                 auto *q_ptr = &store_ptr->stock[i];
100                 spoil_random_artifact_aux(player_ptr, q_ptr, tval);
101             }
102
103             store_ptr = &towns_info[1].stores[StoreSaleType::MUSEUM];
104             for (int i = 0; i < store_ptr->stock_num; i++) {
105                 auto *q_ptr = &store_ptr->stock[i];
106                 spoil_random_artifact_aux(player_ptr, q_ptr, tval);
107             }
108         }
109     }
110
111     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
112         msg_print("Cannot close list file.");
113         return;
114     }
115
116     msg_print("Successfully created a list file.");
117 }