OSDN Git Service

Merge pull request #41491 (taotao/hengband/fix-impure_calc_num_blow into develop).
[hengband/hengband.git] / src / cmd-io / cmd-diary.c
1 #include "cmd-io/cmd-diary.h"
2 #include "cmd-io/diary-subtitle-table.h"
3 #include "core/asking-player.h"
4 #include "core/show-file.h"
5 #include "game-option/play-record-options.h"
6 #include "io/record-play-movie.h"
7 #include "io/files-util.h"
8 #include "io/input-key-acceptor.h"
9 #include "io/write-diary.h"
10 #include "main/sound-of-music.h"
11 #include "player/player-personality.h"
12 #include "player/player-realm.h"
13 #include "term/screen-processor.h"
14 #include "util/angband-files.h"
15 #include "util/int-char-converter.h"
16 #include "view/display-messages.h"
17 #include "world/world.h"
18
19 /*!
20  * @brief 日記のタイトル表記と内容出力
21  * @param creature_ptr プレーヤーへの参照ポインタ
22  * @return なし
23  */
24 static void display_diary(player_type *creature_ptr)
25 {
26     char diary_title[256];
27     GAME_TEXT file_name[MAX_NLEN];
28     char buf[1024];
29     char tmp[80];
30     sprintf(file_name, _("playrecord-%s.txt", "playrec-%s.txt"), savefile_base);
31     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
32
33     if (creature_ptr->pclass == CLASS_WARRIOR || creature_ptr->pclass == CLASS_MONK || creature_ptr->pclass == CLASS_SAMURAI
34         || creature_ptr->pclass == CLASS_BERSERKER)
35         strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 1)]);
36     else if (is_wizard_class(creature_ptr))
37         strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 1) + 1]);
38     else
39         strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 2) + 1]);
40
41 #ifdef JP
42     sprintf(diary_title, "「%s%s%sの伝説 -%s-」", ap_ptr->title, ap_ptr->no ? "の" : "", creature_ptr->name, tmp);
43 #else
44     sprintf(diary_title, "Legend of %s %s '%s'", ap_ptr->title, creature_ptr->name, tmp);
45 #endif
46
47     (void)show_file(creature_ptr, FALSE, buf, diary_title, -1, 0);
48 }
49
50 /*!
51  * @brief 日記に任意の内容を表記するコマンドのメインルーチン /
52  * @return なし
53  */
54 static void add_diary_note(player_type *creature_ptr)
55 {
56     char tmp[80] = "\0";
57     char bunshou[80] = "\0";
58     if (get_string(_("内容: ", "diary note: "), tmp, 79)) {
59         strcpy(bunshou, tmp);
60         exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, bunshou);
61     }
62 }
63
64 /*!
65  * @brief 最後に取得したアイテムの情報を日記に追加するメインルーチン /
66  * @return なし
67  */
68 static void do_cmd_last_get(player_type *creaute_ptr)
69 {
70     if (record_o_name[0] == '\0')
71         return;
72
73     char buf[256];
74     sprintf(buf, _("%sの入手を記録します。", "Do you really want to record getting %s? "), record_o_name);
75     if (!get_check(buf))
76         return;
77
78     GAME_TURN turn_tmp = current_world_ptr->game_turn;
79     current_world_ptr->game_turn = record_turn;
80     sprintf(buf, _("%sを手に入れた。", "discover %s."), record_o_name);
81     exe_write_diary(creaute_ptr, DIARY_DESCRIPTION, 0, buf);
82     current_world_ptr->game_turn = turn_tmp;
83 }
84
85 /*!
86  * @brief ファイル中の全日記記録を消去する /
87  * @return なし
88  */
89 static void do_cmd_erase_diary(void)
90 {
91     GAME_TEXT file_name[MAX_NLEN];
92     char buf[256];
93     FILE *fff = NULL;
94
95     if (!get_check(_("本当に記録を消去しますか?", "Do you really want to delete all your records? ")))
96         return;
97     sprintf(file_name, _("playrecord-%s.txt", "playrec-%s.txt"), savefile_base);
98     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
99     fd_kill(buf);
100
101     fff = angband_fopen(buf, "w");
102     if (fff) {
103         angband_fclose(fff);
104         msg_format(_("記録を消去しました。", "deleted record."));
105     } else {
106         msg_format(_("%s の消去に失敗しました。", "failed to delete %s."), buf);
107     }
108
109     msg_print(NULL);
110 }
111
112 /*!
113  * @brief 日記コマンド
114  * @param crerature_ptr プレーヤーへの参照ポインタ
115  * @return なし
116  */
117 void do_cmd_diary(player_type *creature_ptr)
118 {
119     screen_save();
120     while (TRUE) {
121         term_clear();
122         prt(_("[ 記録の設定 ]", "[ Play Record ]"), 2, 0);
123         prt(_("(1) 記録を見る", "(1) Display your record"), 4, 5);
124         prt(_("(2) 文章を記録する", "(2) Add record"), 5, 5);
125         prt(_("(3) 直前に入手又は鑑定したものを記録する", "(3) Record the last item you got or identified"), 6, 5);
126         prt(_("(4) 記録を消去する", "(4) Delete your record"), 7, 5);
127         prt(_("(R) プレイ動画を記録する/中止する", "(R) Record playing movie / or stop it"), 9, 5);
128         prt(_("コマンド:", "Command: "), 18, 0);
129         int i = inkey();
130         if (i == ESCAPE)
131             break;
132
133         switch (i) {
134         case '1':
135             display_diary(creature_ptr);
136             break;
137         case '2':
138             add_diary_note(creature_ptr);
139             break;
140         case '3':
141             do_cmd_last_get(creature_ptr);
142             break;
143         case '4':
144             do_cmd_erase_diary();
145             break;
146         case 'r':
147         case 'R':
148             screen_load();
149             prepare_movie_hooks(creature_ptr);
150             return;
151         default:
152             bell();
153         }
154
155         msg_erase();
156     }
157
158     screen_load();
159 }