OSDN Git Service

[Refactor] feature_flag_type の enum class 化
[hengbandforosx/hengbandosx.git] / src / cmd-action / cmd-others.cpp
1 /*!
2  * @brief その他の小さなコマンド処理群 (探索、汎用グリッド処理、自殺/引退/切腹)
3  * @date 2014/01/02
4  * @author
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6  *
7  * This software may be copied and distributed for educational, research,
8  * and not for profit purposes provided that this copyright and statement
9  * are included in all such copies.  Other copyrights may also apply.
10  */
11
12 #include "cmd-action/cmd-others.h"
13 #include "action/open-close-execution.h"
14 #include "action/tunnel-execution.h"
15 #include "cmd-action/cmd-attack.h"
16 #include "core/asking-player.h"
17 #include "core/disturbance.h"
18 #include "core/player-redraw-types.h"
19 #include "floor/geometry.h"
20 #include "game-option/game-play-options.h"
21 #include "grid/feature.h"
22 #include "grid/grid.h"
23 #include "io/input-key-acceptor.h"
24 #include "io/input-key-requester.h"
25 #include "io/write-diary.h"
26 #include "main/music-definitions-table.h"
27 #include "main/sound-of-music.h"
28 #include "player-status/player-energy.h"
29 #include "player/attack-defense-types.h"
30 #include "player/player-move.h"
31 #include "player/special-defense-types.h"
32 #include "status/action-setter.h"
33 #include "system/floor-type-definition.h"
34 #include "system/grid-type-definition.h"
35 #include "system/player-type-definition.h"
36 #include "target/target-getter.h"
37 #include "term/screen-processor.h"
38 #include "util/bit-flags-calculator.h"
39 #include "view/display-messages.h"
40 #include "world/world.h"
41
42 /*!
43  * @brief 探索コマンドのメインルーチン / Simple command to "search" for one turn
44  */
45 void do_cmd_search(player_type *creature_ptr)
46 {
47     if (command_arg) {
48         command_rep = command_arg - 1;
49         creature_ptr->redraw |= PR_STATE;
50         command_arg = 0;
51     }
52
53     PlayerEnergy(creature_ptr).set_player_turn_energy(100);
54     search(creature_ptr);
55
56     if (creature_ptr->action == ACTION_SEARCH)
57         search(creature_ptr);
58 }
59
60 static bool exe_alter(player_type *creature_ptr)
61 {
62     DIRECTION dir;
63     if (!get_rep_dir(creature_ptr, &dir, true))
64         return false;
65
66     POSITION y = creature_ptr->y + ddy[dir];
67     POSITION x = creature_ptr->x + ddx[dir];
68     grid_type *g_ptr;
69     g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
70     FEAT_IDX feat = g_ptr->get_feat_mimic();
71     feature_type *f_ptr;
72     f_ptr = &f_info[feat];
73     PlayerEnergy(creature_ptr).set_player_turn_energy(100);
74     if (g_ptr->m_idx) {
75         do_cmd_attack(creature_ptr, y, x, HISSATSU_NONE);
76         return false;
77     }
78     
79     if (f_ptr->flags.has(FF::OPEN))
80         return exe_open(creature_ptr, y, x);
81     
82     if (f_ptr->flags.has(FF::BASH))
83         return exe_bash(creature_ptr, y, x, dir);
84     
85     if (f_ptr->flags.has(FF::TUNNEL))
86         return exe_tunnel(creature_ptr, y, x);
87     
88     if (f_ptr->flags.has(FF::CLOSE))
89         return exe_close(creature_ptr, y, x);
90     
91     if (f_ptr->flags.has(FF::DISARM))
92         return exe_disarm(creature_ptr, y, x, dir);
93
94     msg_print(_("何もない空中を攻撃した。", "You attack the empty air."));
95     return false;
96 }
97
98 /*!
99  * @brief 特定のマスに影響を及ぼすための汎用的コマンド / Manipulate an adjacent grid in some way
100  * @details
101  */
102 void do_cmd_alter(player_type *creature_ptr)
103 {
104     if (creature_ptr->special_defense & KATA_MUSOU)
105         set_action(creature_ptr, ACTION_NONE);
106
107     if (command_arg) {
108         command_rep = command_arg - 1;
109         creature_ptr->redraw |= PR_STATE;
110         command_arg = 0;
111     }
112
113     if (!exe_alter(creature_ptr))
114         disturb(creature_ptr, false, false);
115 }
116
117 /*!
118  * @brief 自殺/引退/切腹の確認
119  * @param なし
120  * @return 自殺/引退/切腹を実施するならTRUE、キャンセルならFALSE
121  */
122 static bool decide_suicide(void)
123 {
124     if (current_world_ptr->noscore)
125         return true;
126
127     prt(_("確認のため '@' を押して下さい。", "Please verify SUICIDE by typing the '@' sign: "), 0, 0);
128     flush();
129     int i = inkey();
130     prt("", 0, 0);
131     return i == '@';
132 }
133
134 static void accept_winner_message(player_type *creature_ptr)
135 {
136     if (!current_world_ptr->total_winner || !last_words)
137         return;
138
139     char buf[1024] = "";
140     play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WINNER);
141     do {
142         while (!get_string(_("*勝利*メッセージ: ", "*Winning* message: "), buf, sizeof(buf)))
143             ;
144     } while (!get_check_strict(creature_ptr, _("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
145
146     if (buf[0]) {
147         creature_ptr->last_message = string_make(buf);
148         msg_print(creature_ptr->last_message);
149     }
150 }
151
152 /*!
153  * @brief 自殺するコマンドのメインルーチン
154  * commit suicide
155  * @details
156  */
157 void do_cmd_suicide(player_type *creature_ptr)
158 {
159     flush();
160     if (current_world_ptr->total_winner) {
161         if (!get_check_strict(creature_ptr, _("引退しますか? ", "Do you want to retire? "), CHECK_NO_HISTORY))
162             return;
163     } else {
164         if (!get_check(_("本当に自殺しますか?", "Do you really want to commit suicide? ")))
165             return;
166     }
167
168     if (!decide_suicide())
169         return;
170
171     if (creature_ptr->last_message)
172         string_free(creature_ptr->last_message);
173
174     creature_ptr->last_message = NULL;
175     creature_ptr->playing = false;
176     creature_ptr->is_dead = true;
177     creature_ptr->leaving = true;
178     if (current_world_ptr->total_winner) {
179         accept_winner_message(creature_ptr);
180         add_retired_class(creature_ptr->pclass);
181     } else {
182         play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
183         exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, _("ダンジョンの探索に絶望して自殺した。", "gave up all hope to commit suicide."));
184         exe_write_diary(creature_ptr, DIARY_GAMESTART, 1, _("-------- ゲームオーバー --------", "--------   Game  Over   --------"));
185         exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, "\n\n\n\n");
186     }
187
188     (void)strcpy(creature_ptr->died_from, _("途中終了", "Quitting"));
189 }