OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Fix-saved-floor-exceed' into...
[hengband/hengband.git] / src / io-dump / random-art-info-dumper.c
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/object-type-definition.h"
8 #include "util/angband-files.h"
9 #include "view/display-messages.h"
10 #include "wizard/artifact-analyzer.h"
11 #include "wizard/fixed-artifacts-spoiler.h"
12 #include "wizard/spoiler-util.h"
13
14 /*!
15  * @brief ランダムアーティファクト1件をスポイラー出力する /
16  * Create a spoiler file entry for an artifact
17  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
18  * @param art_ptr 記述内容を収めた構造体参照ポインタ
19  * Fill in an object description structure for a given object
20  * @return なし
21  */
22 static void spoiler_print_randart(object_type *o_ptr, obj_desc_list *art_ptr)
23 {
24     pval_info_type *pval_ptr = &art_ptr->pval_info;
25     char buf[80];
26     fprintf(spoiler_file, "%s\n", art_ptr->description);
27     if (!object_is_fully_known(o_ptr)) {
28         fprintf(spoiler_file, _("%s不明\n", "%sUnknown\n"), spoiler_indent);
29     } else {
30         if (pval_ptr->pval_desc[0]) {
31             sprintf(buf, _("%sの修正:", "%s to"), pval_ptr->pval_desc);
32             spoiler_outlist(buf, pval_ptr->pval_affects, item_separator);
33         }
34
35         spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator);
36         spoiler_outlist(_("武器属性:", ""), art_ptr->brands, list_separator);
37         spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, item_separator);
38         spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, item_separator);
39         spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustains, item_separator);
40         spoiler_outlist("", art_ptr->misc_magic, list_separator);
41         if (art_ptr->activation) {
42             fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent, art_ptr->activation);
43         }
44     }
45
46     fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc);
47 }
48
49 /*!
50  * @brief ランダムアーティファクト内容をスポイラー出力するサブルーチン /
51  * @param player_ptr プレーヤーへの参照ポインタ
52  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
53  * @param i 出力したい記録ランダムアーティファクトID
54  * @return なし
55  */
56 static void spoil_random_artifact_aux(player_type *player_ptr, object_type *o_ptr, int i)
57 {
58     obj_desc_list artifact;
59     if (!object_is_known(o_ptr) || !o_ptr->art_name || o_ptr->tval != group_artifact[i].tval)
60         return;
61
62     random_artifact_analyze(player_ptr, o_ptr, &artifact);
63     spoiler_print_randart(o_ptr, &artifact);
64 }
65
66 /*!
67  * @brief ランダムアーティファクト内容をスポイラー出力するメインルーチン /
68  * Create a list file for random artifacts
69  * @param fname 出力ファイル名
70  * @return なし
71  */
72 void spoil_random_artifact(player_type *creature_ptr, concptr fname)
73 {
74     store_type *store_ptr;
75     object_type *q_ptr;
76     char buf[1024];
77     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
78     spoiler_file = angband_fopen(buf, "w");
79     if (!spoiler_file) {
80         msg_print("Cannot create list file.");
81         return;
82     }
83
84     sprintf(buf, "Random artifacts list.\r");
85     spoiler_underline(buf);
86     for (int j = 0; group_artifact[j].tval; j++) {
87         for (inventory_slot_type i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
88             q_ptr = &creature_ptr->inventory_list[i];
89             spoil_random_artifact_aux(creature_ptr, q_ptr, j);
90         }
91
92         for (int i = 0; i < INVEN_PACK; i++) {
93             q_ptr = &creature_ptr->inventory_list[i];
94             spoil_random_artifact_aux(creature_ptr, q_ptr, j);
95         }
96
97         store_ptr = &town_info[1].store[STORE_HOME];
98         for (int i = 0; i < store_ptr->stock_num; i++) {
99             q_ptr = &store_ptr->stock[i];
100             spoil_random_artifact_aux(creature_ptr, q_ptr, j);
101         }
102
103         store_ptr = &town_info[1].store[STORE_MUSEUM];
104         for (int i = 0; i < store_ptr->stock_num; i++) {
105             q_ptr = &store_ptr->stock[i];
106             spoil_random_artifact_aux(creature_ptr, q_ptr, j);
107         }
108     }
109
110     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
111         msg_print("Cannot close list file.");
112         return;
113     }
114
115     msg_print("Successfully created a list file.");
116 }