OSDN Git Service

Merge remote-tracking branch 'remotes/origin/For3.0.0-Change-Weird-Telepathy-Spec...
[hengband/hengband.git] / src / cmd-io / cmd-dump.c
1 /*!
2  * @brief プレイヤーのインターフェイスに関するコマンドの実装 / Interface commands
3  * @date 2014/01/02
4  * @author
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
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  * 2020 Hourier Rearranged
10  */
11
12 #include "cmd-io/cmd-dump.h"
13 #include "cmd-io/feeling-table.h"
14 #include "core/asking-player.h"
15 #include "dungeon/quest.h"
16 #include "floor/floor-town.h"
17 #include "io-dump/dump-remover.h"
18 #include "io-dump/dump-util.h"
19 #include "io/files-util.h"
20 #include "io/input-key-acceptor.h"
21 #include "io/interpret-pref-file.h"
22 #include "io/read-pref-file.h"
23 #include "locale/english.h"
24 #include "main/sound-of-music.h"
25 #include "mutation/mutation-flag-types.h"
26 #include "player/player-personalities-types.h"
27 #include "player/player-status-flags.h"
28 #include "system/angband-version.h"
29 #include "system/floor-type-definition.h"
30 #include "term/gameterm.h"
31 #include "term/screen-processor.h"
32 #include "term/term-color-types.h"
33 #include "util/angband-files.h"
34 #include "util/int-char-converter.h"
35 #include "view/display-messages.h"
36 #include "view/display-player.h" // 暫定。後で消す.
37 #include "world/world.h"
38
39 /*!
40  * @brief 画面を再描画するコマンドのメインルーチン
41  * Hack -- redraw the screen
42  * @param creature_ptr プレーヤーへの参照ポインタ
43  * @return なし
44  * @details
45  * Allow absolute file names?
46  */
47 void do_cmd_pref(player_type *creature_ptr)
48 {
49     char buf[80];
50     strcpy(buf, "");
51     if (!get_string(_("設定変更コマンド: ", "Pref: "), buf, 80))
52         return;
53
54     (void)interpret_pref_file(creature_ptr, buf);
55 }
56
57 /*
58  * Interact with "colors"
59  */
60 void do_cmd_colors(player_type *creature_ptr, void (*process_autopick_file_command)(char *))
61 {
62     int i;
63     char tmp[160];
64     char buf[1024];
65     FILE *auto_dump_stream;
66     screen_save();
67     while (TRUE) {
68         term_clear();
69         prt(_("[ カラーの設定 ]", "Interact with Colors"), 2, 0);
70         prt(_("(1) ユーザー設定ファイルのロード", "(1) Load a user pref file"), 4, 5);
71         prt(_("(2) カラーの設定をファイルに書き出す", "(2) Dump colors"), 5, 5);
72         prt(_("(3) カラーの設定を変更する", "(3) Modify colors"), 6, 5);
73         prt(_("コマンド: ", "Command: "), 8, 0);
74         i = inkey();
75         if (i == ESCAPE)
76             break;
77
78         if (i == '1') {
79             prt(_("コマンド: ユーザー設定ファイルをロードします", "Command: Load a user pref file"), 8, 0);
80             prt(_("ファイル: ", "File: "), 10, 0);
81             sprintf(tmp, "%s.prf", creature_ptr->base_name);
82             if (!askfor(tmp, 70))
83                 continue;
84
85             (void)process_pref_file(creature_ptr, tmp, process_autopick_file_command);
86             term_xtra(TERM_XTRA_REACT, 0);
87             term_redraw();
88         } else if (i == '2') {
89             static concptr mark = "Colors";
90             prt(_("コマンド: カラーの設定をファイルに書き出します", "Command: Dump colors"), 8, 0);
91             prt(_("ファイル: ", "File: "), 10, 0);
92             sprintf(tmp, "%s.prf", creature_ptr->base_name);
93             if (!askfor(tmp, 70))
94                 continue;
95
96             path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
97             if (!open_auto_dump(&auto_dump_stream, buf, mark))
98                 continue;
99
100             auto_dump_printf(auto_dump_stream, _("\n# カラーの設定\n\n", "\n# Color redefinitions\n\n"));
101             for (i = 0; i < 256; i++) {
102                 int kv = angband_color_table[i][0];
103                 int rv = angband_color_table[i][1];
104                 int gv = angband_color_table[i][2];
105                 int bv = angband_color_table[i][3];
106
107                 concptr name = _("未知", "unknown");
108                 if (!kv && !rv && !gv && !bv)
109                     continue;
110
111                 if (i < 16)
112                     name = color_names[i];
113
114                 auto_dump_printf(auto_dump_stream, _("# カラー '%s'\n", "# Color '%s'\n"), name);
115                 auto_dump_printf(auto_dump_stream, "V:%d:0x%02X:0x%02X:0x%02X:0x%02X\n\n", i, kv, rv, gv, bv);
116             }
117
118             close_auto_dump(&auto_dump_stream, mark);
119             msg_print(_("カラーの設定をファイルに書き出しました。", "Dumped color redefinitions."));
120         } else if (i == '3') {
121             static byte a = 0;
122             prt(_("コマンド: カラーの設定を変更します", "Command: Modify colors"), 8, 0);
123             while (TRUE) {
124                 concptr name;
125                 clear_from(10);
126                 for (byte j = 0; j < 16; j++) {
127                     term_putstr(j * 4, 20, -1, a, "###");
128                     term_putstr(j * 4, 22, -1, j, format("%3d", j));
129                 }
130
131                 name = ((a < 16) ? color_names[a] : _("未定義", "undefined"));
132                 term_putstr(5, 10, -1, TERM_WHITE, format(_("カラー = %d, 名前 = %s", "Color = %d, Name = %s"), a, name));
133                 term_putstr(5, 12, -1, TERM_WHITE,
134                     format("K = 0x%02x / R,G,B = 0x%02x,0x%02x,0x%02x", angband_color_table[a][0], angband_color_table[a][1], angband_color_table[a][2],
135                         angband_color_table[a][3]));
136                 term_putstr(0, 14, -1, TERM_WHITE, _("コマンド (n/N/k/K/r/R/g/G/b/B): ", "Command (n/N/k/K/r/R/g/G/b/B): "));
137                 i = inkey();
138                 if (i == ESCAPE)
139                     break;
140
141                 if (i == 'n')
142                     a = (byte)(a + 1);
143                 if (i == 'N')
144                     a = (byte)(a - 1);
145                 if (i == 'k')
146                     angband_color_table[a][0] = (byte)(angband_color_table[a][0] + 1);
147                 if (i == 'K')
148                     angband_color_table[a][0] = (byte)(angband_color_table[a][0] - 1);
149                 if (i == 'r')
150                     angband_color_table[a][1] = (byte)(angband_color_table[a][1] + 1);
151                 if (i == 'R')
152                     angband_color_table[a][1] = (byte)(angband_color_table[a][1] - 1);
153                 if (i == 'g')
154                     angband_color_table[a][2] = (byte)(angband_color_table[a][2] + 1);
155                 if (i == 'G')
156                     angband_color_table[a][2] = (byte)(angband_color_table[a][2] - 1);
157                 if (i == 'b')
158                     angband_color_table[a][3] = (byte)(angband_color_table[a][3] + 1);
159                 if (i == 'B')
160                     angband_color_table[a][3] = (byte)(angband_color_table[a][3] - 1);
161
162                 term_xtra(TERM_XTRA_REACT, 0);
163                 term_redraw();
164             }
165         } else {
166             bell();
167         }
168
169         msg_erase();
170     }
171
172     screen_load();
173 }
174
175 /*
176  * Note something in the message recall
177  */
178 void do_cmd_note(void)
179 {
180     char buf[80];
181     strcpy(buf, "");
182     if (!get_string(_("メモ: ", "Note: "), buf, 60))
183         return;
184     if (!buf[0] || (buf[0] == ' '))
185         return;
186
187     msg_format(_("メモ: %s", "Note: %s"), buf);
188 }
189
190 /*
191  * Mention the current version
192  */
193 void do_cmd_version(void)
194 {
195 #if FAKE_VER_EXTRA > 0
196     msg_format(
197         _("変愚蛮怒(Hengband) %d.%d.%d.%d", "You are playing Hengband %d.%d.%d.%d."), FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH, FAKE_VER_EXTRA);
198 #else
199     msg_format(_("変愚蛮怒(Hengband) %d.%d.%d", "You are playing Hengband %d.%d.%d."), FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
200 #endif
201 }
202
203 /*
204  * Note that "feeling" is set to zero unless some time has passed.
205  * Note that this is done when the level is GENERATED, not entered.
206  */
207 void do_cmd_feeling(player_type *creature_ptr)
208 {
209     if (creature_ptr->wild_mode)
210         return;
211
212     if (creature_ptr->current_floor_ptr->inside_quest && !random_quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level)) {
213         msg_print(_("典型的なクエストのダンジョンのようだ。", "Looks like a typical quest level."));
214         return;
215     }
216
217     if (creature_ptr->town_num && !creature_ptr->current_floor_ptr->dun_level) {
218         if (!strcmp(town_info[creature_ptr->town_num].name, _("荒野", "wilderness"))) {
219             msg_print(_("何かありそうな荒野のようだ。", "Looks like a strange wilderness."));
220             return;
221         }
222
223         msg_print(_("典型的な町のようだ。", "Looks like a typical town."));
224         return;
225     }
226
227     if (!creature_ptr->current_floor_ptr->dun_level) {
228         msg_print(_("典型的な荒野のようだ。", "Looks like a typical wilderness."));
229         return;
230     }
231
232     if (has_good_luck(creature_ptr))
233         msg_print(do_cmd_feeling_text_lucky[creature_ptr->feeling]);
234     else if (is_echizen(creature_ptr))
235         msg_print(do_cmd_feeling_text_combat[creature_ptr->feeling]);
236     else
237         msg_print(do_cmd_feeling_text[creature_ptr->feeling]);
238 }
239
240 /*
241  * Display the time and date
242  * @param creature_ptr プレーヤーへの参照ポインタ
243  * @return なし
244  */
245 void do_cmd_time(player_type *creature_ptr)
246 {
247     int day, hour, min;
248     extract_day_hour_min(creature_ptr, &day, &hour, &min);
249
250     char desc[1024];
251     strcpy(desc, _("変な時刻だ。", "It is a strange time."));
252
253     char day_buf[10];
254     if (day < MAX_DAYS)
255         sprintf(day_buf, "%d", day);
256     else
257         strcpy(day_buf, "*****");
258
259     msg_format(_("%s日目, 時刻は%d:%02d %sです。", "This is day %s. The time is %d:%02d %s."), day_buf, (hour % 12 == 0) ? 12 : (hour % 12), min,
260         (hour < 12) ? "AM" : "PM");
261
262     char buf[1024];
263     if (!randint0(10) || creature_ptr->image) {
264         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("timefun_j.txt", "timefun.txt"));
265     } else {
266         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("timenorm_j.txt", "timenorm.txt"));
267     }
268
269     FILE *fff;
270     fff = angband_fopen(buf, "rt");
271
272     if (!fff)
273         return;
274
275     int full = hour * 100 + min;
276     int start = 9999;
277     int end = -9999;
278     int num = 0;
279     while (!angband_fgets(fff, buf, sizeof(buf))) {
280         if (!buf[0] || (buf[0] == '#'))
281             continue;
282         if (buf[1] != ':')
283             continue;
284
285         if (buf[0] == 'S') {
286             start = atoi(buf + 2);
287             end = start + 59;
288             continue;
289         }
290
291         if (buf[0] == 'E') {
292             end = atoi(buf + 2);
293             continue;
294         }
295
296         if ((start > full) || (full > end))
297             continue;
298
299         if (buf[0] == 'D') {
300             num++;
301             if (!randint0(num))
302                 strcpy(desc, buf + 2);
303
304             continue;
305         }
306     }
307
308     msg_print(desc);
309     angband_fclose(fff);
310 }