OSDN Git Service

[Refactor] #38862 Moved english/japanese.c/h to locale/
[hengband/hengband.git] / src / cmd / cmd-dump.c
1 /*!
2  * @file cmd-dump.c
3  * @brief プレイヤーのインターフェイスに関するコマンドの実装 / Interface commands
4  * @date 2014/01/02
5  * @author
6  * <pre>
7  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  * </pre>
12  * @details
13  * <pre>
14  * A set of functions to maintain automatic dumps of various kinds.
15  * The dump commands of original Angband simply add new lines to
16  * existing files; these files will become bigger and bigger unless
17  * an user deletes some or all of these files by hand at some
18  * point.
19  * These three functions automatically delete old dumped lines
20  * before adding new ones.  Since there are various kinds of automatic
21  * dumps in a single file, we add a header and a footer with a type
22  * name for every automatic dump, and kill old lines only when the
23  * lines have the correct type of header and footer.
24  * We need to be quite paranoid about correctness; the user might
25  * (mistakenly) edit the file by hand, and see all their work come
26  * to nothing on the next auto dump otherwise.  The current code only
27  * detects changes by noting inconsistencies between the actual number
28  * of lines and the number written in the footer.  Note that this will
29  * not catch single-line edits.
30  * </pre>
31  */
32
33 #include "system/angband.h"
34 #include "cmd/cmd-dump.h"
35 #include "cmd/dump-util.h"
36 #include "gameterm.h"
37 #include "core/angband-version.h"
38 #include "io/dump-remover.h"
39 #include "io/read-pref-file.h"
40 #include "io/interpret-pref-file.h"
41
42 #include "world/world.h"
43 #include "view/display-player.h" // 暫定。後で消す.
44 #include "player/player-personality.h"
45 #include "quest.h"
46 #include "artifact.h"
47 #include "floor/floor-town.h"
48 #include "cmd/feeling-table.h"
49 #include "locale/english.h"
50
51 #include "chuukei.h"
52
53 /*!
54  * @brief 画面を再描画するコマンドのメインルーチン
55  * Hack -- redraw the screen
56  * @param creature_ptr プレーヤーへの参照ポインタ
57  * @return なし
58  * @details
59  * Allow absolute file names?
60  */
61 void do_cmd_pref(player_type *creature_ptr)
62 {
63         char buf[80];
64         strcpy(buf, "");
65         if (!get_string(_("設定変更コマンド: ", "Pref: "), buf, 80)) return;
66
67         (void)interpret_pref_file(creature_ptr, buf);
68 }
69
70
71 /*
72  * Interact with "colors"
73  */
74 void do_cmd_colors(player_type *creature_ptr, void(*process_autopick_file_command)(char*))
75 {
76         int i;
77         char tmp[160];
78         char buf[1024];
79         FILE *auto_dump_stream;
80         FILE_TYPE(FILE_TYPE_TEXT);
81         screen_save();
82         while (TRUE)
83         {
84                 Term_clear();
85                 prt(_("[ カラーの設定 ]", "Interact with Colors"), 2, 0);
86                 prt(_("(1) ユーザー設定ファイルのロード", "(1) Load a user pref file"), 4, 5);
87                 prt(_("(2) カラーの設定をファイルに書き出す", "(2) Dump colors"), 5, 5);
88                 prt(_("(3) カラーの設定を変更する", "(3) Modify colors"), 6, 5);
89                 prt(_("コマンド: ", "Command: "), 8, 0);
90                 i = inkey();
91                 if (i == ESCAPE) break;
92
93                 if (i == '1')
94                 {
95                         prt(_("コマンド: ユーザー設定ファイルをロードします", "Command: Load a user pref file"), 8, 0);
96                         prt(_("ファイル: ", "File: "), 10, 0);
97                         sprintf(tmp, "%s.prf", creature_ptr->base_name);
98                         if (!askfor(tmp, 70)) continue;
99
100                         (void)process_pref_file(creature_ptr, tmp, process_autopick_file_command);
101                         Term_xtra(TERM_XTRA_REACT, 0);
102                         Term_redraw();
103                 }
104                 else if (i == '2')
105                 {
106                         static concptr mark = "Colors";
107                         prt(_("コマンド: カラーの設定をファイルに書き出します", "Command: Dump colors"), 8, 0);
108                         prt(_("ファイル: ", "File: "), 10, 0);
109                         sprintf(tmp, "%s.prf", creature_ptr->base_name);
110                         if (!askfor(tmp, 70)) continue;
111
112                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
113                         if (!open_auto_dump(&auto_dump_stream, buf, mark)) continue;
114
115                         auto_dump_printf(auto_dump_stream, _("\n# カラーの設定\n\n", "\n# Color redefinitions\n\n"));
116                         for (i = 0; i < 256; i++)
117                         {
118                                 int kv = angband_color_table[i][0];
119                                 int rv = angband_color_table[i][1];
120                                 int gv = angband_color_table[i][2];
121                                 int bv = angband_color_table[i][3];
122
123                                 concptr name = _("未知", "unknown");
124                                 if (!kv && !rv && !gv && !bv) continue;
125
126                                 if (i < 16) name = color_names[i];
127
128                                 auto_dump_printf(auto_dump_stream, _("# カラー '%s'\n", "# Color '%s'\n"), name);
129                                 auto_dump_printf(auto_dump_stream, "V:%d:0x%02X:0x%02X:0x%02X:0x%02X\n\n",
130                                         i, kv, rv, gv, bv);
131                         }
132
133                         close_auto_dump(&auto_dump_stream, mark);
134                         msg_print(_("カラーの設定をファイルに書き出しました。", "Dumped color redefinitions."));
135                 }
136                 else if (i == '3')
137                 {
138                         static byte a = 0;
139                         prt(_("コマンド: カラーの設定を変更します", "Command: Modify colors"), 8, 0);
140                         while (TRUE)
141                         {
142                                 concptr name;
143                                 clear_from(10);
144                                 for (byte j = 0; j < 16; j++)
145                                 {
146                                         Term_putstr(j * 4, 20, -1, a, "###");
147                                         Term_putstr(j * 4, 22, -1, j, format("%3d", j));
148                                 }
149
150                                 name = ((a < 16) ? color_names[a] : _("未定義", "undefined"));
151                                 Term_putstr(5, 10, -1, TERM_WHITE,
152                                         format(_("カラー = %d, 名前 = %s", "Color = %d, Name = %s"), a, name));
153                                 Term_putstr(5, 12, -1, TERM_WHITE,
154                                         format("K = 0x%02x / R,G,B = 0x%02x,0x%02x,0x%02x",
155                                                 angband_color_table[a][0],
156                                                 angband_color_table[a][1],
157                                                 angband_color_table[a][2],
158                                                 angband_color_table[a][3]));
159                                 Term_putstr(0, 14, -1, TERM_WHITE,
160                                         _("コマンド (n/N/k/K/r/R/g/G/b/B): ", "Command (n/N/k/K/r/R/g/G/b/B): "));
161                                 i = inkey();
162                                 if (i == ESCAPE) break;
163
164                                 if (i == 'n') a = (byte)(a + 1);
165                                 if (i == 'N') a = (byte)(a - 1);
166                                 if (i == 'k') angband_color_table[a][0] = (byte)(angband_color_table[a][0] + 1);
167                                 if (i == 'K') angband_color_table[a][0] = (byte)(angband_color_table[a][0] - 1);
168                                 if (i == 'r') angband_color_table[a][1] = (byte)(angband_color_table[a][1] + 1);
169                                 if (i == 'R') angband_color_table[a][1] = (byte)(angband_color_table[a][1] - 1);
170                                 if (i == 'g') angband_color_table[a][2] = (byte)(angband_color_table[a][2] + 1);
171                                 if (i == 'G') angband_color_table[a][2] = (byte)(angband_color_table[a][2] - 1);
172                                 if (i == 'b') angband_color_table[a][3] = (byte)(angband_color_table[a][3] + 1);
173                                 if (i == 'B') angband_color_table[a][3] = (byte)(angband_color_table[a][3] - 1);
174
175                                 Term_xtra(TERM_XTRA_REACT, 0);
176                                 Term_redraw();
177                         }
178                 }
179                 else
180                 {
181                         bell();
182                 }
183
184                 msg_erase();
185         }
186
187         screen_load();
188 }
189
190
191 /*
192  * Note something in the message recall
193  */
194 void do_cmd_note(void)
195 {
196         char buf[80];
197         strcpy(buf, "");
198         if (!get_string(_("メモ: ", "Note: "), buf, 60)) return;
199         if (!buf[0] || (buf[0] == ' ')) return;
200
201         msg_format(_("メモ: %s", "Note: %s"), buf);
202 }
203
204
205 /*
206  * Mention the current version
207  */
208 void do_cmd_version(void)
209 {
210 #if FAKE_VER_EXTRA > 0
211         msg_format(_("変愚蛮怒(Hengband) %d.%d.%d.%d", "You are playing Hengband %d.%d.%d.%d."),
212                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH, FAKE_VER_EXTRA);
213 #else
214         msg_format(_("変愚蛮怒(Hengband) %d.%d.%d", "You are playing Hengband %d.%d.%d."),
215                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
216 #endif
217 }
218
219
220 /*
221  * Note that "feeling" is set to zero unless some time has passed.
222  * Note that this is done when the level is GENERATED, not entered.
223  */
224 void do_cmd_feeling(player_type *creature_ptr)
225 {
226         if (creature_ptr->wild_mode) return;
227
228         if (creature_ptr->current_floor_ptr->inside_quest && !random_quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level))
229         {
230                 msg_print(_("典型的なクエストのダンジョンのようだ。", "Looks like a typical quest level."));
231                 return;
232         }
233
234         if (creature_ptr->town_num && !creature_ptr->current_floor_ptr->dun_level)
235         {
236                 if (!strcmp(town_info[creature_ptr->town_num].name, _("荒野", "wilderness")))
237                 {
238                         msg_print(_("何かありそうな荒野のようだ。", "Looks like a strange wilderness."));
239                         return;
240                 }
241
242                 msg_print(_("典型的な町のようだ。", "Looks like a typical town."));
243                 return;
244         }
245
246         if (!creature_ptr->current_floor_ptr->dun_level)
247         {
248                 msg_print(_("典型的な荒野のようだ。", "Looks like a typical wilderness."));
249                 return;
250         }
251
252         if (creature_ptr->muta3 & MUT3_GOOD_LUCK)
253                 msg_print(do_cmd_feeling_text_lucky[creature_ptr->feeling]);
254         else if (IS_ECHIZEN(creature_ptr))
255                 msg_print(do_cmd_feeling_text_combat[creature_ptr->feeling]);
256         else
257                 msg_print(do_cmd_feeling_text[creature_ptr->feeling]);
258 }
259
260
261 /*
262  * Display the time and date
263  * @param creature_ptr プレーヤーへの参照ポインタ
264  * @return なし
265  */
266 void do_cmd_time(player_type *creature_ptr)
267 {
268         int day, hour, min;
269         extract_day_hour_min(creature_ptr, &day, &hour, &min);
270
271         char desc[1024];
272         strcpy(desc, _("変な時刻だ。", "It is a strange time."));
273
274         char day_buf[10];
275         if (day < MAX_DAYS) sprintf(day_buf, "%d", day);
276         else strcpy(day_buf, "*****");
277
278         msg_format(_("%s日目, 時刻は%d:%02d %sです。", "This is day %s. The time is %d:%02d %s."),
279                 day_buf, (hour % 12 == 0) ? 12 : (hour % 12), min, (hour < 12) ? "AM" : "PM");
280
281         char buf[1024];
282         if (!randint0(10) || creature_ptr->image)
283         {
284                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("timefun_j.txt", "timefun.txt"));
285         }
286         else
287         {
288                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("timenorm_j.txt", "timenorm.txt"));
289         }
290
291         FILE *fff;
292         fff = my_fopen(buf, "rt");
293
294         if (!fff) return;
295
296         int full = hour * 100 + min;
297         int start = 9999;
298         int end = -9999;
299         int num = 0;
300         while (!my_fgets(fff, buf, sizeof(buf)))
301         {
302                 if (!buf[0] || (buf[0] == '#')) continue;
303                 if (buf[1] != ':') continue;
304
305                 if (buf[0] == 'S')
306                 {
307                         start = atoi(buf + 2);
308                         end = start + 59;
309                         continue;
310                 }
311
312                 if (buf[0] == 'E')
313                 {
314                         end = atoi(buf + 2);
315                         continue;
316                 }
317
318                 if ((start > full) || (full > end)) continue;
319
320                 if (buf[0] == 'D')
321                 {
322                         num++;
323                         if (!randint0(num)) strcpy(desc, buf + 2);
324
325                         continue;
326                 }
327         }
328
329         msg_print(desc);
330         my_fclose(fff);
331 }