OSDN Git Service

[Change] 変愚蛮怒名義を馬鹿馬鹿蛮怒名義に変更. / Change naming from Hengband to Bakabakaband.
[hengband/hengband.git] / src / wizard / wizard-spoiler.c
1 /*!
2  * @brief スポイラー出力処理 (行数の都合でモンスター進化ツリーもここに入っている)
3  * @date 2014/02/17
4  * @author
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.
11  */
12
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"
28
29 /*!
30  * @brief int配列でstrncmp()と似た比較処理を行う /
31  * Compare two int-type array like strncmp() and return TRUE if equals
32  * @param a 比較するint配列1
33  * @param b 比較するint配列2
34  * @param length
35  * @return 両者の値が等しければTRUEを返す
36  */
37 static bool int_n_cmp(int *a, int *b, int length)
38 {
39     if (!length)
40         return TRUE;
41
42     do {
43         if (*a != *(b++))
44             return FALSE;
45         if (!(*(a++)))
46             break;
47     } while (--length);
48
49     return TRUE;
50 }
51
52 /*!
53  * @brief ある木が指定された木の部分木かどうかを返す /
54  * Returns TRUE if an evolution tree is "partial tree"
55  * @param tree 元となる木構造リスト
56  * @param partial_tree 部分木かどうか判定したい木構造リスト
57  * @return 部分木ならばTRUEを返す
58  */
59 static bool is_partial_tree(int *tree, int *partial_tree)
60 {
61     int pt_head = *(partial_tree++);
62     int pt_len = 0;
63     while (partial_tree[pt_len])
64         pt_len++;
65
66     while (*tree) {
67         if (*(tree++) == pt_head) {
68             if (int_n_cmp(tree, partial_tree, pt_len))
69                 return TRUE;
70         }
71     }
72
73     return FALSE;
74 }
75
76 /*!
77  * @brief 進化ツリーをスポイラー出力するメインルーチン /
78  * Print monsters' evolution information to file
79  * @param fname 出力ファイル名
80  * @return なし
81  */
82 static void spoil_mon_evol(player_type *player_ptr, concptr fname)
83 {
84     char buf[1024];
85     monster_race *r_ptr;
86     int **evol_tree, i, j, n, r_idx;
87     int *evol_tree_zero; /* For C_KILL() */
88     path_build(buf, sizeof buf, ANGBAND_DIR_USER, fname);
89     spoiler_file = angband_fopen(buf, "w");
90     if (!spoiler_file) {
91         msg_print("Cannot create spoiler file.");
92         return;
93     }
94
95     sprintf(buf, "Monster Spoilers for Bakabakaband Version %d.%d.%d\n", FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
96     spoil_out(buf);
97     spoil_out("------------------------------------------\n\n");
98     C_MAKE(evol_tree, max_r_idx, int *);
99     C_MAKE(*evol_tree, max_r_idx * (max_evolution_depth + 1), int);
100     for (i = 1; i < max_r_idx; i++)
101         evol_tree[i] = *evol_tree + i * (max_evolution_depth + 1);
102
103     evol_tree_zero = *evol_tree;
104     for (i = 1; i < max_r_idx; i++) {
105         r_ptr = &r_info[i];
106         if (!r_ptr->next_exp)
107             continue;
108
109         n = 0;
110         evol_tree[i][n++] = i;
111         do {
112             evol_tree[i][n++] = r_ptr->next_r_idx;
113             r_ptr = &r_info[r_ptr->next_r_idx];
114         } while (r_ptr->next_exp && (n < max_evolution_depth));
115     }
116
117     for (i = 1; i < max_r_idx; i++) {
118         if (!evol_tree[i][0])
119             continue;
120
121         for (j = 1; j < max_r_idx; j++) {
122             if (i == j)
123                 continue;
124
125             if (!evol_tree[j][0])
126                 continue;
127
128             if (is_partial_tree(evol_tree[j], evol_tree[i])) {
129                 evol_tree[i][0] = 0;
130                 break;
131             }
132         }
133     }
134
135     ang_sort(player_ptr, evol_tree, NULL, max_r_idx, ang_sort_comp_evol_tree, ang_sort_swap_evol_tree);
136     for (i = 0; i < max_r_idx; i++) {
137         r_idx = evol_tree[i][0];
138         if (!r_idx)
139             continue;
140
141         r_ptr = &r_info[r_idx];
142         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);
143         for (n = 1; r_ptr->next_exp; n++) {
144             fprintf(spoiler_file, "%*s-(%ld)-> ", n * 2, "", (long int)r_ptr->next_exp);
145             fprintf(spoiler_file, "[%d]: ", r_ptr->next_r_idx);
146             r_ptr = &r_info[r_ptr->next_r_idx];
147             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);
148         }
149
150         fputc('\n', spoiler_file);
151     }
152
153     C_KILL(evol_tree_zero, max_r_idx * (max_evolution_depth + 1), int);
154     C_KILL(evol_tree, max_r_idx, int *);
155     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
156         msg_print("Cannot close spoiler file.");
157         return;
158     }
159
160     msg_print("Successfully created a spoiler file.");
161 }
162
163 /*!
164  * @brief スポイラー出力を行うコマンドのメインルーチン /
165  * Create Spoiler files -BEN-
166  * @return なし
167  */
168 void exe_output_spoilers(player_type *player_ptr)
169 {
170     screen_save();
171     while (TRUE) {
172         term_clear();
173         prt("Create a spoiler file.", 2, 0);
174         prt("(1) Brief Object Info (obj-desc.txt)", 5, 5);
175         prt("(2) Brief Artifact Info (artifact.txt)", 6, 5);
176         prt("(3) Brief Monster Info (mon-desc.txt)", 7, 5);
177         prt("(4) Full Monster Info (mon-info.txt)", 8, 5);
178         prt("(5) Monster Evolution Info (mon-evol.txt)", 9, 5);
179         prt(_("コマンド:", "Command: "), _(18, 12), 0);
180         switch (inkey()) {
181         case ESCAPE:
182             screen_load();
183             return;
184         case '1':
185             spoil_obj_desc(player_ptr, "obj-desc.txt");
186             break;
187         case '2':
188             spoil_fixed_artifact(player_ptr, "artifact.txt");
189             break;
190         case '3':
191             spoil_mon_desc(player_ptr, "mon-desc.txt");
192             break;
193         case '4':
194             spoil_mon_info(player_ptr, "mon-info.txt");
195             break;
196         case '5':
197             spoil_mon_evol(player_ptr, "mon-evol.txt");
198             break;
199         default:
200             bell();
201             break;
202         }
203
204         msg_erase();
205     }
206 }