OSDN Git Service

[Change] 変愚蛮怒名義を馬鹿馬鹿蛮怒名義に変更. / Change naming from Hengband to Bakabakaband.
[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[80];
74     sprintf(buf, "Artifact Spoilers for Bakabakaband Version %d.%d.%d", FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
75     spoiler_underline(buf);
76 }
77
78 /*!
79  * @brief アーティファクト情報を出力するためにダミー生成を行う /
80  * Hack -- Create a "forged" artifact
81  * @param o_ptr 一時生成先を保管するオブジェクト構造体
82  * @param name1 生成するアーティファクトID
83  * @return 生成が成功した場合TRUEを返す
84  */
85 static bool make_fake_artifact(player_type *player_ptr, object_type *o_ptr, IDX name1)
86 {
87     artifact_type *a_ptr = &a_info[name1];
88     if (!a_ptr->name)
89         return FALSE;
90
91     OBJECT_IDX i = lookup_kind(a_ptr->tval, a_ptr->sval);
92     if (!i)
93         return FALSE;
94
95     object_prep(player_ptr, o_ptr, i);
96     o_ptr->name1 = (byte)name1;
97     o_ptr->pval = a_ptr->pval;
98     o_ptr->ac = a_ptr->ac;
99     o_ptr->dd = a_ptr->dd;
100     o_ptr->ds = a_ptr->ds;
101     o_ptr->to_a = a_ptr->to_a;
102     o_ptr->to_h = a_ptr->to_h;
103     o_ptr->to_d = a_ptr->to_d;
104     o_ptr->weight = a_ptr->weight;
105     return TRUE;
106 }
107
108 /*!
109  * @brief アーティファクト一件をスポイラー出力する /
110  * Create a spoiler file entry for an artifact
111  * @param art_ptr アーティファクト情報をまとめた構造体の参照ポインタ
112  * @return なし
113  */
114 static void spoiler_print_art(obj_desc_list *art_ptr)
115 {
116     pval_info_type *pval_ptr = &art_ptr->pval_info;
117     char buf[80];
118     fprintf(spoiler_file, "%s\n", art_ptr->description);
119     if (pval_ptr->pval_desc[0]) {
120         sprintf(buf, _("%sの修正:", "%s to"), pval_ptr->pval_desc);
121         spoiler_outlist(buf, pval_ptr->pval_affects, item_separator);
122     }
123
124     spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator);
125     spoiler_outlist(_("武器属性:", ""), art_ptr->brands, list_separator);
126     spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, item_separator);
127     spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, item_separator);
128     spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustains, item_separator);
129     spoiler_outlist("", art_ptr->misc_magic, list_separator);
130
131     if (art_ptr->addition[0])
132         fprintf(spoiler_file, _("%s追加: %s\n", "%sAdditional %s\n"), spoiler_indent, art_ptr->addition);
133
134     if (art_ptr->activation)
135         fprintf(spoiler_file, _("%s発動: %s\n", "%sActivates for %s\n"), spoiler_indent, art_ptr->activation);
136
137     fprintf(spoiler_file, "%s%s\n\n", spoiler_indent, art_ptr->misc_desc);
138 }
139
140 /*!
141  * @brief アーティファクト情報のスポイラー出力を行うメインルーチン /
142  * Create a spoiler file for artifacts
143  * @param player_ptr プレーヤーへの参照ポインタ
144  * @param fname 生成ファイル名
145  * @return なし
146  */
147 void spoil_fixed_artifact(player_type *player_ptr, concptr fname)
148 {
149     object_type forge;
150     object_type *q_ptr;
151     obj_desc_list artifact;
152     char buf[1024];
153     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
154     spoiler_file = angband_fopen(buf, "w");
155     if (!spoiler_file) {
156         msg_print("Cannot create spoiler file.");
157         return;
158     }
159
160     print_header();
161     for (int i = 0; group_artifact[i].tval; i++) {
162         if (group_artifact[i].name) {
163             spoiler_blanklines(2);
164             spoiler_underline(group_artifact[i].name);
165             spoiler_blanklines(1);
166         }
167
168         for (ARTIFACT_IDX j = 1; j < max_a_idx; ++j) {
169             artifact_type *a_ptr = &a_info[j];
170             if (a_ptr->tval != group_artifact[i].tval)
171                 continue;
172
173             q_ptr = &forge;
174             object_wipe(q_ptr);
175             if (!make_fake_artifact(player_ptr, q_ptr, j))
176                 continue;
177
178             object_analyze(player_ptr, q_ptr, &artifact);
179             spoiler_print_art(&artifact);
180         }
181     }
182
183     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
184         msg_print("Cannot close spoiler file.");
185         return;
186     }
187
188     msg_print("Successfully created a spoiler file.");
189 }