2 * @brief スポイラー出力処理 (行数の都合でモンスター進化ツリーもここに入っている)
5 * Copyright (c) 1997 Ben Harrison, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
9 * 2013 Deskull rearranged comment for Doxygen.
10 * 2020 Hourier rearranged for decreasing lines.
13 #include "wizard/wizard-spoiler.h"
14 #include "io/files-util.h"
15 #include "io/input-key-acceptor.h"
16 #include "main/sound-of-music.h"
17 #include "monster-race/monster-race.h"
18 #include "system/angband-version.h"
19 #include "term/screen-processor.h"
20 #include "util/angband-files.h"
21 #include "util/int-char-converter.h"
22 #include "util/sort.h"
23 #include "view/display-messages.h"
24 #include "wizard/fixed-artifacts-spoiler.h"
25 #include "wizard/items-spoiler.h"
26 #include "wizard/monster-info-spoiler.h"
27 #include "wizard/spoiler-util.h"
30 * @brief int配列でstrncmp()と似た比較処理を行う /
31 * Compare two int-type array like strncmp() and return TRUE if equals
35 * @return 両者の値が等しければTRUEを返す
37 static bool int_n_cmp(int *a, int *b, int length)
53 * @brief ある木が指定された木の部分木かどうかを返す /
54 * Returns TRUE if an evolution tree is "partial tree"
55 * @param tree 元となる木構造リスト
56 * @param partial_tree 部分木かどうか判定したい木構造リスト
57 * @return 部分木ならばTRUEを返す
59 static bool is_partial_tree(int *tree, int *partial_tree)
61 int pt_head = *(partial_tree++);
63 while (partial_tree[pt_len])
67 if (*(tree++) == pt_head) {
68 if (int_n_cmp(tree, partial_tree, pt_len))
77 * @brief 進化ツリーをスポイラー出力するメインルーチン /
78 * Print monsters' evolution information to file
79 * @param fname 出力ファイル名
82 static spoiler_output_status spoil_mon_evol(concptr fname)
87 int **evol_tree, i, j, n, r_idx;
88 int *evol_tree_zero; /* For C_KILL() */
89 path_build(buf, sizeof buf, ANGBAND_DIR_USER, fname);
90 spoiler_file = angband_fopen(buf, "w");
92 return SPOILER_OUTPUT_FAIL_FOPEN;
97 sprintf(buf, "Monster Spoilers for %s\n", title);
100 spoil_out("------------------------------------------\n\n");
101 C_MAKE(evol_tree, max_r_idx, int *);
102 C_MAKE(*evol_tree, max_r_idx * (max_evolution_depth + 1), int);
103 for (i = 1; i < max_r_idx; i++)
104 evol_tree[i] = *evol_tree + i * (max_evolution_depth + 1);
106 evol_tree_zero = *evol_tree;
107 for (i = 1; i < max_r_idx; i++) {
109 if (!r_ptr->next_exp)
113 evol_tree[i][n++] = i;
115 evol_tree[i][n++] = r_ptr->next_r_idx;
116 r_ptr = &r_info[r_ptr->next_r_idx];
117 } while (r_ptr->next_exp && (n < max_evolution_depth));
120 for (i = 1; i < max_r_idx; i++) {
121 if (!evol_tree[i][0])
124 for (j = 1; j < max_r_idx; j++) {
128 if (!evol_tree[j][0])
131 if (is_partial_tree(evol_tree[j], evol_tree[i])) {
138 ang_sort(&dummy, evol_tree, NULL, max_r_idx, ang_sort_comp_evol_tree, ang_sort_swap_evol_tree);
139 for (i = 0; i < max_r_idx; i++) {
140 r_idx = evol_tree[i][0];
144 r_ptr = &r_info[r_idx];
145 fprintf(spoiler_file, _("[%d]: %s (レベル%d, '%c')\n", "[%d]: %s (Level %d, '%c')\n"), r_idx, r_name + r_ptr->name, (int)r_ptr->level, r_ptr->d_char);
146 for (n = 1; r_ptr->next_exp; n++) {
147 fprintf(spoiler_file, "%*s-(%ld)-> ", n * 2, "", (long int)r_ptr->next_exp);
148 fprintf(spoiler_file, "[%d]: ", r_ptr->next_r_idx);
149 r_ptr = &r_info[r_ptr->next_r_idx];
150 fprintf(spoiler_file, _("%s (レベル%d, '%c')\n", "%s (Level %d, '%c')\n"), r_name + r_ptr->name, (int)r_ptr->level, r_ptr->d_char);
153 fputc('\n', spoiler_file);
156 C_KILL(evol_tree_zero, max_r_idx * (max_evolution_depth + 1), int);
157 C_KILL(evol_tree, max_r_idx, int *);
158 if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
159 return SPOILER_OUTPUT_FAIL_FCLOSE;
161 return SPOILER_OUTPUT_SUCCESS;
165 * @brief スポイラー出力を行うコマンドのメインルーチン /
166 * Create Spoiler files -BEN-
169 void exe_output_spoilers(void)
173 spoiler_output_status status = SPOILER_OUTPUT_CANCEL;
175 prt("Create a spoiler file.", 2, 0);
176 prt("(1) Brief Object Info (obj-desc.txt)", 5, 5);
177 prt("(2) Brief Artifact Info (artifact.txt)", 6, 5);
178 prt("(3) Brief Monster Info (mon-desc.txt)", 7, 5);
179 prt("(4) Full Monster Info (mon-info.txt)", 8, 5);
180 prt("(5) Monster Evolution Info (mon-evol.txt)", 9, 5);
181 prt(_("コマンド:", "Command: "), _(18, 12), 0);
187 status = spoil_obj_desc("obj-desc.txt");
190 status = spoil_fixed_artifact("artifact.txt");
193 status = spoil_mon_desc("mon-desc.txt");
196 status = spoil_mon_info("mon-info.txt");
199 status = spoil_mon_evol("mon-evol.txt");
207 case SPOILER_OUTPUT_FAIL_FOPEN:
208 msg_print("Cannot create spoiler file.");
210 case SPOILER_OUTPUT_FAIL_FCLOSE:
211 msg_print("Cannot close spoiler file.");
213 case SPOILER_OUTPUT_SUCCESS:
214 msg_print("Successfully created a spoiler file.");