OSDN Git Service

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