OSDN Git Service

Reworded English description of the sniper's SP_PIERCE ability.
[hengband/hengband.git] / src / wizard / fixed-artifacts-spoiler.c
1 #include "wizard/fixed-artifacts-spoiler.h"
2 #include "io/files-util.h"
3 #include "object/object-generator.h"
4 #include "object/object-kind-hook.h"
5 #include "system/angband-version.h"
6 #include "system/artifact-type-definition.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/spoiler-util.h"
12
13 /*!
14  * todo 固定アーティファクトとランダムアーティファクトで共用、ここに置くべきかは要調整.
15  * @brief フラグ名称を出力する汎用関数
16  * @param header ヘッダに出力するフラグ群の名前
17  * @param list フラグ名リスト
18  * @param separator フラグ表示の区切り記号
19  * @return なし
20  */
21 void spoiler_outlist(concptr header, concptr *list, char separator)
22 {
23     char line[MAX_LINE_LEN + 1], buf[80];
24     if (*list == NULL)
25         return;
26
27     strcpy(line, spoiler_indent);
28     if (header && (header[0])) {
29         strcat(line, header);
30         strcat(line, " ");
31     }
32
33     int buf_len;
34     int line_len = strlen(line);
35     while (TRUE) {
36         strcpy(buf, *list);
37         buf_len = strlen(buf);
38         if (list[1]) {
39             sprintf(buf + buf_len, "%c ", separator);
40             buf_len += 2;
41         }
42
43         if (line_len + buf_len <= MAX_LINE_LEN) {
44             strcat(line, buf);
45             line_len += buf_len;
46         } else {
47             if (line_len > 1 && line[line_len - 1] == ' ' && line[line_len - 2] == list_separator) {
48                 line[line_len - 2] = '\0';
49                 fprintf(spoiler_file, "%s\n", line);
50                 sprintf(line, "%s%s", spoiler_indent, buf);
51             } else {
52                 fprintf(spoiler_file, "%s\n", line);
53                 concptr ident2 = "      ";
54                 sprintf(line, "%s%s", ident2, buf);
55             }
56
57             line_len = strlen(line);
58         }
59
60         if (!*++list)
61             break;
62     }
63
64     fprintf(spoiler_file, "%s\n", line);
65 }
66
67 /*!
68  * @brief バッファにアーティファクト出力情報ヘッダを収める /
69  * @return なし
70  */
71 static void print_header(void)
72 {
73     char buf[180];
74     char title[180];
75     put_version(title);
76     sprintf(buf, "Artifact Spoilers for Hengband Version %s", title);
77     spoiler_underline(buf);
78 }
79
80 /*!
81  * @brief アーティファクト情報を出力するためにダミー生成を行う /
82  * Hack -- Create a "forged" artifact
83  * @param o_ptr 一時生成先を保管するオブジェクト構造体
84  * @param name1 生成するアーティファクトID
85  * @return 生成が成功した場合TRUEを返す
86  */
87 static bool make_fake_artifact(player_type *player_ptr, object_type *o_ptr, ARTIFACT_IDX name1)
88 {
89     artifact_type *a_ptr = &a_info[name1];
90     if (!a_ptr->name)
91         return FALSE;
92
93     OBJECT_IDX i = lookup_kind(a_ptr->tval, a_ptr->sval);
94     if (!i)
95         return FALSE;
96
97     object_prep(player_ptr, o_ptr, i);
98     o_ptr->name1 = (byte)name1;
99     o_ptr->pval = a_ptr->pval;
100     o_ptr->ac = a_ptr->ac;
101     o_ptr->dd = a_ptr->dd;
102     o_ptr->ds = a_ptr->ds;
103     o_ptr->to_a = a_ptr->to_a;
104     o_ptr->to_h = a_ptr->to_h;
105     o_ptr->to_d = a_ptr->to_d;
106     o_ptr->weight = a_ptr->weight;
107     return TRUE;
108 }
109
110 /*!
111  * @brief アーティファクト一件をスポイラー出力する /
112  * Create a spoiler file entry for an artifact
113  * @param art_ptr アーティファクト情報をまとめた構造体の参照ポインタ
114  * @return なし
115  */
116 static void spoiler_print_art(obj_desc_list *art_ptr)
117 {
118     pval_info_type *pval_ptr = &art_ptr->pval_info;
119     char buf[80];
120     fprintf(spoiler_file, "%s\n", art_ptr->description);
121     if (pval_ptr->pval_desc[0]) {
122         sprintf(buf, _("%sの修正:", "%s to"), pval_ptr->pval_desc);
123         spoiler_outlist(buf, pval_ptr->pval_affects, item_separator);
124     }
125
126     spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator);
127     spoiler_outlist(_("武器属性:", ""), art_ptr->brands, list_separator);
128     spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, item_separator);
129     spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, item_separator);
130     spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustains, item_separator);
131     spoiler_outlist("", art_ptr->misc_magic, list_separator);
132
133     if (art_ptr->addition[0])
134         fprintf(spoiler_file, _("%s追加: %s\n", "%sAdditional %s\n"), spoiler_indent, art_ptr->addition);
135
136     if (art_ptr->activation)
137         fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent, art_ptr->activation);
138
139     fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc);
140 }
141
142 /*!
143  * @brief アーティファクト情報のスポイラー出力を行うメインルーチン /
144  * Create a spoiler file for artifacts
145  * @param player_ptr プレーヤーへの参照ポインタ
146  * @param fname 生成ファイル名
147  * @return なし
148  */
149 void spoil_fixed_artifact(player_type *player_ptr, concptr fname)
150 {
151     object_type forge;
152     object_type *q_ptr;
153     obj_desc_list artifact;
154     char buf[1024];
155     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
156     spoiler_file = angband_fopen(buf, "w");
157     if (!spoiler_file) {
158         msg_print("Cannot create spoiler file.");
159         return;
160     }
161
162     print_header();
163     for (int i = 0; group_artifact[i].tval; i++) {
164         if (group_artifact[i].name) {
165             spoiler_blanklines(2);
166             spoiler_underline(group_artifact[i].name);
167             spoiler_blanklines(1);
168         }
169
170         for (ARTIFACT_IDX j = 1; j < max_a_idx; ++j) {
171             artifact_type *a_ptr = &a_info[j];
172             if (a_ptr->tval != group_artifact[i].tval)
173                 continue;
174
175             q_ptr = &forge;
176             object_wipe(q_ptr);
177             if (!make_fake_artifact(player_ptr, q_ptr, j))
178                 continue;
179
180             object_analyze(player_ptr, q_ptr, &artifact);
181             spoiler_print_art(&artifact);
182         }
183     }
184
185     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
186         msg_print("Cannot close spoiler file.");
187         return;
188     }
189
190     msg_print("Successfully created a spoiler file.");
191 }