OSDN Git Service

Merge branch 'master' of https://github.com/hengband/hengband
[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, const ArtifactsDumpInfo *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     if (!o_ptr->is_known() || !o_ptr->is_random_artifact() || (o_ptr->bi_key.tval() != tval)) {
62         return;
63     }
64
65     const auto artifacts_list = random_artifact_analyze(player_ptr, o_ptr);
66     spoiler_print_randart(o_ptr, &artifacts_list, ofs);
67 }
68
69 /*!
70  * @brief ランダムアーティファクト内容をスポイラー出力するメインルーチン
71  * @param player_ptr プレイヤーへの参照ポインタ
72  */
73 void spoil_random_artifact(PlayerType *player_ptr)
74 {
75     const auto path = path_build(ANGBAND_DIR_USER, "randifact.txt");
76     std::ofstream ofs(path);
77     if (!ofs) {
78         msg_print("Cannot create list file.");
79         return;
80     }
81
82     spoiler_underline("Random artifacts list.\r", ofs);
83     for (const auto &[tval_list, name] : group_artifact_list) {
84         for (auto tval : tval_list) {
85             for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
86                 auto *q_ptr = &player_ptr->inventory_list[i];
87                 spoil_random_artifact_aux(player_ptr, q_ptr, tval, ofs);
88             }
89
90             for (int i = 0; i < INVEN_PACK; i++) {
91                 auto *q_ptr = &player_ptr->inventory_list[i];
92                 spoil_random_artifact_aux(player_ptr, q_ptr, tval, ofs);
93             }
94
95             const auto *store_ptr = &towns_info[1].stores[StoreSaleType::HOME];
96             for (int i = 0; i < store_ptr->stock_num; i++) {
97                 auto *q_ptr = &store_ptr->stock[i];
98                 spoil_random_artifact_aux(player_ptr, q_ptr, tval, ofs);
99             }
100
101             store_ptr = &towns_info[1].stores[StoreSaleType::MUSEUM];
102             for (int i = 0; i < store_ptr->stock_num; i++) {
103                 auto *q_ptr = &store_ptr->stock[i];
104                 spoil_random_artifact_aux(player_ptr, q_ptr, tval, ofs);
105             }
106         }
107     }
108
109     const auto mes = ofs.good() ? "Successfully created a list file." : "Failed to create a list file.";
110     msg_print(mes);
111 }