OSDN Git Service

Merge pull request #3569 from sikabane-works/release/3.0.0.88-alpha
[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, std::ofstream &ofs)
25 {
26     const auto finalizer = util::make_finalizer([art_ptr, &ofs]() {
27         ofs << spoiler_indent << art_ptr->misc_desc << "\n\n";
28     });
29     const auto *pval_ptr = &art_ptr->pval_info;
30     ofs << art_ptr->description << '\n';
31     if (!o_ptr->is_fully_known()) {
32         ofs << format(_("%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, ofs);
40     }
41
42     spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator, ofs);
43     spoiler_outlist(_("武器属性:", ""), art_ptr->brands, list_separator, ofs);
44     spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, item_separator, ofs);
45     spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, item_separator, ofs);
46     spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustenances, item_separator, ofs);
47     spoiler_outlist("", art_ptr->misc_magic, list_separator, ofs);
48     if (!art_ptr->activation.empty()) {
49         ofs << format(_("%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, std::ofstream &ofs)
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, ofs);
68 }
69
70 /*!
71  * @brief ランダムアーティファクト内容をスポイラー出力するメインルーチン
72  * @param player_ptr プレイヤーへの参照ポインタ
73  */
74 void spoil_random_artifact(PlayerType *player_ptr)
75 {
76     const auto &path = path_build(ANGBAND_DIR_USER, "randifact.txt");
77     std::ofstream ofs(path);
78     if (!ofs) {
79         msg_print("Cannot create list file.");
80         return;
81     }
82
83     spoiler_underline("Random artifacts list.\r", ofs);
84     for (const auto &[tval_list, name] : group_artifact_list) {
85         for (auto tval : tval_list) {
86             for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
87                 auto *q_ptr = &player_ptr->inventory_list[i];
88                 spoil_random_artifact_aux(player_ptr, q_ptr, tval, ofs);
89             }
90
91             for (int i = 0; i < INVEN_PACK; i++) {
92                 auto *q_ptr = &player_ptr->inventory_list[i];
93                 spoil_random_artifact_aux(player_ptr, q_ptr, tval, ofs);
94             }
95
96             const auto *store_ptr = &towns_info[1].stores[StoreSaleType::HOME];
97             for (int i = 0; i < store_ptr->stock_num; i++) {
98                 auto *q_ptr = &store_ptr->stock[i];
99                 spoil_random_artifact_aux(player_ptr, q_ptr, tval, ofs);
100             }
101
102             store_ptr = &towns_info[1].stores[StoreSaleType::MUSEUM];
103             for (int i = 0; i < store_ptr->stock_num; i++) {
104                 auto *q_ptr = &store_ptr->stock[i];
105                 spoil_random_artifact_aux(player_ptr, q_ptr, tval, ofs);
106             }
107         }
108     }
109
110     const auto mes = ofs.good() ? "Successfully created a list file." : "Failed to create a list file.";
111     msg_print(mes);
112 }