OSDN Git Service

91b2b1c5cd3bdf91b6d9fae6c8af21af2430980b
[hengbandforosx/hengbandosx.git] / src / core / game-closer.c
1 #include "core/game-closer.h"
2 #include "cmd-io/cmd-save.h"
3 #include "core/asking-player.h"
4 #include "core/scores.h"
5 #include "core/stuff-handler.h"
6 #include "game-option/cheat-options.h"
7 #include "io/input-key-acceptor.h"
8 #include "io/signal-handlers.h"
9 #include "io/uid-checker.h"
10 #include "main/music-definitions-table.h"
11 #include "main/sound-of-music.h"
12 #include "player/process-death.h"
13 #include "save/save.h"
14 #include "term/screen-processor.h"
15 #include "util/angband-files.h"
16 #include "util/int-char-converter.h"
17 #include "view/display-messages.h"
18 #include "view/display-player.h"
19 #include "world/world.h"
20
21 static void clear_floor(player_type *player_ptr)
22 {
23     (void)fd_close(highscore_fd);
24     highscore_fd = -1;
25     clear_saved_floor_files(player_ptr);
26     signals_handle_tstp();
27 }
28
29 static void send_world_score_on_closing(player_type *player_ptr, bool do_send)
30 {
31     if (send_world_score(player_ptr, do_send, update_playtime, display_player))
32         return;
33
34     if (!get_check_strict(
35             player_ptr, _("後でスコアを登録するために待機しますか?", "Stand by for later score registration? "), (CHECK_NO_ESCAPE | CHECK_NO_HISTORY)))
36         return;
37
38     player_ptr->wait_report_score = TRUE;
39     player_ptr->is_dead = FALSE;
40     if (!save_player(player_ptr))
41         msg_print(_("セーブ失敗!", "death save failed!"));
42 }
43
44 static bool check_death(player_type *player_ptr)
45 {
46     if (player_ptr->is_dead)
47         return TRUE;
48
49     do_cmd_save_game(player_ptr, FALSE);
50     prt(_("リターンキーか ESC キーを押して下さい。", "Press Return (or Escape)."), 0, 40);
51     play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_EXIT);
52     if (inkey() != ESCAPE)
53         predict_score(player_ptr);
54
55     clear_floor(player_ptr);
56     return FALSE;
57 }
58
59 /*!
60  * @brief ゲーム終了処理 /
61  * Close up the current game (player may or may not be dead)
62  * @param creature_ptr プレーヤーへの参照ポインタ
63  * @return なし
64  * @details
65  * <pre>
66  * This function is called only from "main.c" and "signals.c".
67  * </pre>
68  */
69 void close_game(player_type *player_ptr)
70 {
71     bool do_send = TRUE;
72     handle_stuff(player_ptr);
73     msg_print(NULL);
74     flush();
75     signals_ignore_tstp();
76
77     current_world_ptr->character_icky = TRUE;
78     char buf[1024];
79     path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
80     safe_setuid_grab(player_ptr);
81     highscore_fd = fd_open(buf, O_RDWR);
82     safe_setuid_drop();
83
84     if (!check_death(player_ptr))
85         return;
86
87     if (current_world_ptr->total_winner)
88         kingly(player_ptr);
89
90     if (!cheat_save || get_check(_("死んだデータをセーブしますか? ", "Save death? "))) {
91         if (!save_player(player_ptr))
92             msg_print(_("セーブ失敗!", "death save failed!"));
93     } else
94         do_send = FALSE;
95
96     print_tomb(player_ptr);
97     flush();
98     show_death_info(player_ptr, update_playtime, display_player);
99     term_clear();
100     if (check_score(player_ptr)) {
101         send_world_score_on_closing(player_ptr, do_send);
102         if (!player_ptr->wait_report_score)
103             (void)top_twenty(player_ptr);
104     } else if (highscore_fd >= 0) {
105         display_scores_aux(0, 10, -1, NULL);
106     }
107
108     clear_floor(player_ptr);
109 }