OSDN Git Service

[Refactor] #40742 Removed CHUUKEI preprocessor because it's no longer unused
[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 "system/angband-version.h"
28 #include "system/floor-type-definition.h"
29 #include "term/gameterm.h"
30 #include "term/screen-processor.h"
31 #include "term/term-color-types.h"
32 #include "util/angband-files.h"
33 #include "util/int-char-converter.h"
34 #include "view/display-messages.h"
35 #include "view/display-player.h" // 暫定。後で消す.
36 #include "world/world.h"
37 #include "player/player-status-flags.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)) return;
52
53         (void)interpret_pref_file(creature_ptr, buf);
54 }
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         {
69                 term_clear();
70                 prt(_("[ カラーの設定 ]", "Interact with Colors"), 2, 0);
71                 prt(_("(1) ユーザー設定ファイルのロード", "(1) Load a user pref file"), 4, 5);
72                 prt(_("(2) カラーの設定をファイルに書き出す", "(2) Dump colors"), 5, 5);
73                 prt(_("(3) カラーの設定を変更する", "(3) Modify colors"), 6, 5);
74                 prt(_("コマンド: ", "Command: "), 8, 0);
75                 i = inkey();
76                 if (i == ESCAPE) break;
77
78                 if (i == '1')
79                 {
80                         prt(_("コマンド: ユーザー設定ファイルをロードします", "Command: Load a user pref file"), 8, 0);
81                         prt(_("ファイル: ", "File: "), 10, 0);
82                         sprintf(tmp, "%s.prf", creature_ptr->base_name);
83                         if (!askfor(tmp, 70)) 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                 }
89                 else if (i == '2')
90                 {
91                         static concptr mark = "Colors";
92                         prt(_("コマンド: カラーの設定をファイルに書き出します", "Command: Dump colors"), 8, 0);
93                         prt(_("ファイル: ", "File: "), 10, 0);
94                         sprintf(tmp, "%s.prf", creature_ptr->base_name);
95                         if (!askfor(tmp, 70)) continue;
96
97                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
98                         if (!open_auto_dump(&auto_dump_stream, buf, mark)) 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                         {
103                                 int kv = angband_color_table[i][0];
104                                 int rv = angband_color_table[i][1];
105                                 int gv = angband_color_table[i][2];
106                                 int bv = angband_color_table[i][3];
107
108                                 concptr name = _("未知", "unknown");
109                                 if (!kv && !rv && !gv && !bv) continue;
110
111                                 if (i < 16) name = color_names[i];
112
113                                 auto_dump_printf(auto_dump_stream, _("# カラー '%s'\n", "# Color '%s'\n"), name);
114                                 auto_dump_printf(auto_dump_stream, "V:%d:0x%02X:0x%02X:0x%02X:0x%02X\n\n",
115                                         i, kv, rv, gv, bv);
116                         }
117
118                         close_auto_dump(&auto_dump_stream, mark);
119                         msg_print(_("カラーの設定をファイルに書き出しました。", "Dumped color redefinitions."));
120                 }
121                 else if (i == '3')
122                 {
123                         static byte a = 0;
124                         prt(_("コマンド: カラーの設定を変更します", "Command: Modify colors"), 8, 0);
125                         while (TRUE)
126                         {
127                                 concptr name;
128                                 clear_from(10);
129                                 for (byte j = 0; j < 16; j++)
130                                 {
131                                         term_putstr(j * 4, 20, -1, a, "###");
132                                         term_putstr(j * 4, 22, -1, j, format("%3d", j));
133                                 }
134
135                                 name = ((a < 16) ? color_names[a] : _("未定義", "undefined"));
136                                 term_putstr(5, 10, -1, TERM_WHITE,
137                                         format(_("カラー = %d, 名前 = %s", "Color = %d, Name = %s"), a, name));
138                                 term_putstr(5, 12, -1, TERM_WHITE,
139                                         format("K = 0x%02x / R,G,B = 0x%02x,0x%02x,0x%02x",
140                                                 angband_color_table[a][0],
141                                                 angband_color_table[a][1],
142                                                 angband_color_table[a][2],
143                                                 angband_color_table[a][3]));
144                                 term_putstr(0, 14, -1, TERM_WHITE,
145                                         _("コマンド (n/N/k/K/r/R/g/G/b/B): ", "Command (n/N/k/K/r/R/g/G/b/B): "));
146                                 i = inkey();
147                                 if (i == ESCAPE) break;
148
149                                 if (i == 'n') a = (byte)(a + 1);
150                                 if (i == 'N') a = (byte)(a - 1);
151                                 if (i == 'k') angband_color_table[a][0] = (byte)(angband_color_table[a][0] + 1);
152                                 if (i == 'K') angband_color_table[a][0] = (byte)(angband_color_table[a][0] - 1);
153                                 if (i == 'r') angband_color_table[a][1] = (byte)(angband_color_table[a][1] + 1);
154                                 if (i == 'R') angband_color_table[a][1] = (byte)(angband_color_table[a][1] - 1);
155                                 if (i == 'g') angband_color_table[a][2] = (byte)(angband_color_table[a][2] + 1);
156                                 if (i == 'G') angband_color_table[a][2] = (byte)(angband_color_table[a][2] - 1);
157                                 if (i == 'b') angband_color_table[a][3] = (byte)(angband_color_table[a][3] + 1);
158                                 if (i == 'B') angband_color_table[a][3] = (byte)(angband_color_table[a][3] - 1);
159
160                                 term_xtra(TERM_XTRA_REACT, 0);
161                                 term_redraw();
162                         }
163                 }
164                 else
165                 {
166                         bell();
167                 }
168
169                 msg_erase();
170         }
171
172         screen_load();
173 }
174
175
176 /*
177  * Note something in the message recall
178  */
179 void do_cmd_note(void)
180 {
181         char buf[80];
182         strcpy(buf, "");
183         if (!get_string(_("メモ: ", "Note: "), buf, 60)) return;
184         if (!buf[0] || (buf[0] == ' ')) return;
185
186         msg_format(_("メモ: %s", "Note: %s"), buf);
187 }
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(_("変愚蛮怒(Hengband) %d.%d.%d.%d", "You are playing Hengband %d.%d.%d.%d."),
197                 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."),
200                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
201 #endif
202 }
203
204
205 /*
206  * Note that "feeling" is set to zero unless some time has passed.
207  * Note that this is done when the level is GENERATED, not entered.
208  */
209 void do_cmd_feeling(player_type *creature_ptr)
210 {
211         if (creature_ptr->wild_mode) return;
212
213         if (creature_ptr->current_floor_ptr->inside_quest && !random_quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level))
214         {
215                 msg_print(_("典型的なクエストのダンジョンのようだ。", "Looks like a typical quest level."));
216                 return;
217         }
218
219         if (creature_ptr->town_num && !creature_ptr->current_floor_ptr->dun_level)
220         {
221                 if (!strcmp(town_info[creature_ptr->town_num].name, _("荒野", "wilderness")))
222                 {
223                         msg_print(_("何かありそうな荒野のようだ。", "Looks like a strange wilderness."));
224                         return;
225                 }
226
227                 msg_print(_("典型的な町のようだ。", "Looks like a typical town."));
228                 return;
229         }
230
231         if (!creature_ptr->current_floor_ptr->dun_level)
232         {
233                 msg_print(_("典型的な荒野のようだ。", "Looks like a typical wilderness."));
234                 return;
235         }
236
237         if (has_good_luck(creature_ptr))
238                 msg_print(do_cmd_feeling_text_lucky[creature_ptr->feeling]);
239         else if (is_echizen(creature_ptr))
240                 msg_print(do_cmd_feeling_text_combat[creature_ptr->feeling]);
241         else
242                 msg_print(do_cmd_feeling_text[creature_ptr->feeling]);
243 }
244
245
246 /*
247  * Display the time and date
248  * @param creature_ptr プレーヤーへの参照ポインタ
249  * @return なし
250  */
251 void do_cmd_time(player_type *creature_ptr)
252 {
253         int day, hour, min;
254         extract_day_hour_min(creature_ptr, &day, &hour, &min);
255
256         char desc[1024];
257         strcpy(desc, _("変な時刻だ。", "It is a strange time."));
258
259         char day_buf[10];
260         if (day < MAX_DAYS) sprintf(day_buf, "%d", day);
261         else strcpy(day_buf, "*****");
262
263         msg_format(_("%s日目, 時刻は%d:%02d %sです。", "This is day %s. The time is %d:%02d %s."),
264                 day_buf, (hour % 12 == 0) ? 12 : (hour % 12), min, (hour < 12) ? "AM" : "PM");
265
266         char buf[1024];
267         if (!randint0(10) || creature_ptr->image)
268         {
269                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("timefun_j.txt", "timefun.txt"));
270         }
271         else
272         {
273                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("timenorm_j.txt", "timenorm.txt"));
274         }
275
276         FILE *fff;
277         fff = angband_fopen(buf, "rt");
278
279         if (!fff) return;
280
281         int full = hour * 100 + min;
282         int start = 9999;
283         int end = -9999;
284         int num = 0;
285         while (!angband_fgets(fff, buf, sizeof(buf)))
286         {
287                 if (!buf[0] || (buf[0] == '#')) continue;
288                 if (buf[1] != ':') continue;
289
290                 if (buf[0] == 'S')
291                 {
292                         start = atoi(buf + 2);
293                         end = start + 59;
294                         continue;
295                 }
296
297                 if (buf[0] == 'E')
298                 {
299                         end = atoi(buf + 2);
300                         continue;
301                 }
302
303                 if ((start > full) || (full > end)) continue;
304
305                 if (buf[0] == 'D')
306                 {
307                         num++;
308                         if (!randint0(num)) strcpy(desc, buf + 2);
309
310                         continue;
311                 }
312         }
313
314         msg_print(desc);
315         angband_fclose(fff);
316 }