OSDN Git Service

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