OSDN Git Service

[Refactor] #40236 Unified duplicatied functions
[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 "angband.h"
34 #include "cmd/cmd-dump.h"
35 #include "cmd/dump-util.h"
36 #include "gameterm.h"
37 #include "core.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.h"
43 #include "view/display-player.h" // 暫定。後で消す.
44 #include "player-personality.h"
45 #include "quest.h"
46 #include "artifact.h"
47 #include "floor-town.h"
48 #include "cmd/feeling-table.h"
49 #include "english.h"
50
51 #include "chuukei.h"
52
53 #ifdef JP
54 #else
55 /*!
56  * @brief Return suffix of ordinal number
57  * @param num number
58  * @return pointer of suffix string.
59  */
60 concptr get_ordinal_number_suffix(int num)
61 {
62         num = ABS(num) % 100;
63         switch (num % 10)
64         {
65         case 1:
66                 return (num == 11) ? "th" : "st";
67         case 2:
68                 return (num == 12) ? "th" : "nd";
69         case 3:
70                 return (num == 13) ? "th" : "rd";
71         default:
72                 return "th";
73         }
74 }
75 #endif
76
77 /*!
78  * @brief 画面を再描画するコマンドのメインルーチン
79  * Hack -- redraw the screen
80  * @param creature_ptr プレーヤーへの参照ポインタ
81  * @return なし
82  * @details
83  * Allow absolute file names?
84  */
85 void do_cmd_pref(player_type *creature_ptr)
86 {
87         char buf[80];
88         strcpy(buf, "");
89         if (!get_string(_("設定変更コマンド: ", "Pref: "), buf, 80)) return;
90
91         (void)interpret_pref_file(creature_ptr, buf);
92 }
93
94
95 /*
96  * Interact with "colors"
97  */
98 void do_cmd_colors(player_type *creature_ptr)
99 {
100         int i;
101         char tmp[160];
102         char buf[1024];
103         FILE *auto_dump_stream;
104         FILE_TYPE(FILE_TYPE_TEXT);
105         screen_save();
106         while (TRUE)
107         {
108                 Term_clear();
109                 prt(_("[ カラーの設定 ]", "Interact with Colors"), 2, 0);
110                 prt(_("(1) ユーザー設定ファイルのロード", "(1) Load a user pref file"), 4, 5);
111                 prt(_("(2) カラーの設定をファイルに書き出す", "(2) Dump colors"), 5, 5);
112                 prt(_("(3) カラーの設定を変更する", "(3) Modify colors"), 6, 5);
113                 prt(_("コマンド: ", "Command: "), 8, 0);
114                 i = inkey();
115                 if (i == ESCAPE) break;
116
117                 if (i == '1')
118                 {
119                         prt(_("コマンド: ユーザー設定ファイルをロードします", "Command: Load a user pref file"), 8, 0);
120                         prt(_("ファイル: ", "File: "), 10, 0);
121                         sprintf(tmp, "%s.prf", creature_ptr->base_name);
122                         if (!askfor(tmp, 70)) continue;
123
124                         (void)process_pref_file(creature_ptr, tmp);
125                         Term_xtra(TERM_XTRA_REACT, 0);
126                         Term_redraw();
127                 }
128                 else if (i == '2')
129                 {
130                         static concptr mark = "Colors";
131                         prt(_("コマンド: カラーの設定をファイルに書き出します", "Command: Dump colors"), 8, 0);
132                         prt(_("ファイル: ", "File: "), 10, 0);
133                         sprintf(tmp, "%s.prf", creature_ptr->base_name);
134                         if (!askfor(tmp, 70)) continue;
135
136                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
137                         if (!open_auto_dump(&auto_dump_stream, buf, mark)) continue;
138
139                         auto_dump_printf(auto_dump_stream, _("\n# カラーの設定\n\n", "\n# Color redefinitions\n\n"));
140                         for (i = 0; i < 256; i++)
141                         {
142                                 int kv = angband_color_table[i][0];
143                                 int rv = angband_color_table[i][1];
144                                 int gv = angband_color_table[i][2];
145                                 int bv = angband_color_table[i][3];
146
147                                 concptr name = _("未知", "unknown");
148                                 if (!kv && !rv && !gv && !bv) continue;
149
150                                 if (i < 16) name = color_names[i];
151
152                                 auto_dump_printf(auto_dump_stream, _("# カラー '%s'\n", "# Color '%s'\n"), name);
153                                 auto_dump_printf(auto_dump_stream, "V:%d:0x%02X:0x%02X:0x%02X:0x%02X\n\n",
154                                         i, kv, rv, gv, bv);
155                         }
156
157                         close_auto_dump(&auto_dump_stream, mark);
158                         msg_print(_("カラーの設定をファイルに書き出しました。", "Dumped color redefinitions."));
159                 }
160                 else if (i == '3')
161                 {
162                         static byte a = 0;
163                         prt(_("コマンド: カラーの設定を変更します", "Command: Modify colors"), 8, 0);
164                         while (TRUE)
165                         {
166                                 concptr name;
167                                 clear_from(10);
168                                 for (byte j = 0; j < 16; j++)
169                                 {
170                                         Term_putstr(j * 4, 20, -1, a, "###");
171                                         Term_putstr(j * 4, 22, -1, j, format("%3d", j));
172                                 }
173
174                                 name = ((a < 16) ? color_names[a] : _("未定義", "undefined"));
175                                 Term_putstr(5, 10, -1, TERM_WHITE,
176                                         format(_("カラー = %d, 名前 = %s", "Color = %d, Name = %s"), a, name));
177                                 Term_putstr(5, 12, -1, TERM_WHITE,
178                                         format("K = 0x%02x / R,G,B = 0x%02x,0x%02x,0x%02x",
179                                                 angband_color_table[a][0],
180                                                 angband_color_table[a][1],
181                                                 angband_color_table[a][2],
182                                                 angband_color_table[a][3]));
183                                 Term_putstr(0, 14, -1, TERM_WHITE,
184                                         _("コマンド (n/N/k/K/r/R/g/G/b/B): ", "Command (n/N/k/K/r/R/g/G/b/B): "));
185                                 i = inkey();
186                                 if (i == ESCAPE) break;
187
188                                 if (i == 'n') a = (byte)(a + 1);
189                                 if (i == 'N') a = (byte)(a - 1);
190                                 if (i == 'k') angband_color_table[a][0] = (byte)(angband_color_table[a][0] + 1);
191                                 if (i == 'K') angband_color_table[a][0] = (byte)(angband_color_table[a][0] - 1);
192                                 if (i == 'r') angband_color_table[a][1] = (byte)(angband_color_table[a][1] + 1);
193                                 if (i == 'R') angband_color_table[a][1] = (byte)(angband_color_table[a][1] - 1);
194                                 if (i == 'g') angband_color_table[a][2] = (byte)(angband_color_table[a][2] + 1);
195                                 if (i == 'G') angband_color_table[a][2] = (byte)(angband_color_table[a][2] - 1);
196                                 if (i == 'b') angband_color_table[a][3] = (byte)(angband_color_table[a][3] + 1);
197                                 if (i == 'B') angband_color_table[a][3] = (byte)(angband_color_table[a][3] - 1);
198
199                                 Term_xtra(TERM_XTRA_REACT, 0);
200                                 Term_redraw();
201                         }
202                 }
203                 else
204                 {
205                         bell();
206                 }
207
208                 msg_erase();
209         }
210
211         screen_load();
212 }
213
214
215 /*
216  * Note something in the message recall
217  */
218 void do_cmd_note(void)
219 {
220         char buf[80];
221         strcpy(buf, "");
222         if (!get_string(_("メモ: ", "Note: "), buf, 60)) return;
223         if (!buf[0] || (buf[0] == ' ')) return;
224
225         msg_format(_("メモ: %s", "Note: %s"), buf);
226 }
227
228
229 /*
230  * Mention the current version
231  */
232 void do_cmd_version(void)
233 {
234 #if FAKE_VER_EXTRA > 0
235         msg_format(_("変愚蛮怒(Hengband) %d.%d.%d.%d", "You are playing Hengband %d.%d.%d.%d."),
236                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH, FAKE_VER_EXTRA);
237 #else
238         msg_format(_("変愚蛮怒(Hengband) %d.%d.%d", "You are playing Hengband %d.%d.%d."),
239                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
240 #endif
241 }
242
243
244 /*
245  * Note that "feeling" is set to zero unless some time has passed.
246  * Note that this is done when the level is GENERATED, not entered.
247  */
248 void do_cmd_feeling(player_type *creature_ptr)
249 {
250         if (creature_ptr->wild_mode) return;
251
252         if (creature_ptr->current_floor_ptr->inside_quest && !random_quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level))
253         {
254                 msg_print(_("典型的なクエストのダンジョンのようだ。", "Looks like a typical quest level."));
255                 return;
256         }
257
258         if (creature_ptr->town_num && !creature_ptr->current_floor_ptr->dun_level)
259         {
260                 if (!strcmp(town_info[creature_ptr->town_num].name, _("荒野", "wilderness")))
261                 {
262                         msg_print(_("何かありそうな荒野のようだ。", "Looks like a strange wilderness."));
263                         return;
264                 }
265
266                 msg_print(_("典型的な町のようだ。", "Looks like a typical town."));
267                 return;
268         }
269
270         if (!creature_ptr->current_floor_ptr->dun_level)
271         {
272                 msg_print(_("典型的な荒野のようだ。", "Looks like a typical wilderness."));
273                 return;
274         }
275
276         if (creature_ptr->muta3 & MUT3_GOOD_LUCK)
277                 msg_print(do_cmd_feeling_text_lucky[creature_ptr->feeling]);
278         else if (IS_ECHIZEN(creature_ptr))
279                 msg_print(do_cmd_feeling_text_combat[creature_ptr->feeling]);
280         else
281                 msg_print(do_cmd_feeling_text[creature_ptr->feeling]);
282 }
283
284
285 /*
286  * Display the time and date
287  * @param creature_ptr プレーヤーへの参照ポインタ
288  * @return なし
289  */
290 void do_cmd_time(player_type *creature_ptr)
291 {
292         int day, hour, min;
293         extract_day_hour_min(creature_ptr, &day, &hour, &min);
294
295         char desc[1024];
296         strcpy(desc, _("変な時刻だ。", "It is a strange time."));
297
298         char day_buf[10];
299         if (day < MAX_DAYS) sprintf(day_buf, "%d", day);
300         else strcpy(day_buf, "*****");
301
302         msg_format(_("%s日目, 時刻は%d:%02d %sです。", "This is day %s. The time is %d:%02d %s."),
303                 day_buf, (hour % 12 == 0) ? 12 : (hour % 12), min, (hour < 12) ? "AM" : "PM");
304
305         char buf[1024];
306         if (!randint0(10) || creature_ptr->image)
307         {
308                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("timefun_j.txt", "timefun.txt"));
309         }
310         else
311         {
312                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("timenorm_j.txt", "timenorm.txt"));
313         }
314
315         FILE *fff;
316         fff = my_fopen(buf, "rt");
317
318         if (!fff) return;
319
320         int full = hour * 100 + min;
321         int start = 9999;
322         int end = -9999;
323         int num = 0;
324         while (!my_fgets(fff, buf, sizeof(buf)))
325         {
326                 if (!buf[0] || (buf[0] == '#')) continue;
327                 if (buf[1] != ':') continue;
328
329                 if (buf[0] == 'S')
330                 {
331                         start = atoi(buf + 2);
332                         end = start + 59;
333                         continue;
334                 }
335
336                 if (buf[0] == 'E')
337                 {
338                         end = atoi(buf + 2);
339                         continue;
340                 }
341
342                 if ((start > full) || (full > end)) continue;
343
344                 if (buf[0] == 'D')
345                 {
346                         num++;
347                         if (!randint0(num)) strcpy(desc, buf + 2);
348
349                         continue;
350                 }
351         }
352
353         msg_print(desc);
354         my_fclose(fff);
355 }