2 * @file open-close-execution.cpp
8 #include "action/open-close-execution.h"
9 #include "action/movement-execution.h"
10 #include "combat/attack-power-table.h"
11 #include "game-option/disturbance-options.h"
12 #include "game-option/input-options.h"
13 #include "grid/feature.h"
14 #include "grid/grid.h"
15 #include "grid/trap.h"
16 #include "main/sound-definitions-table.h"
17 #include "main/sound-of-music.h"
18 #include "perception/object-perception.h"
19 #include "player-base/player-class.h"
20 #include "player-status/player-energy.h"
21 #include "player/player-status-table.h"
22 #include "specific-object/chest.h"
23 #include "status/bad-status-setter.h"
24 #include "status/experience.h"
25 #include "system/floor-type-definition.h"
26 #include "system/grid-type-definition.h"
27 #include "system/object-type-definition.h"
28 #include "system/player-type-definition.h"
29 #include "term/screen-processor.h"
30 #include "timed-effect/player-confusion.h"
31 #include "timed-effect/player-hallucination.h"
32 #include "timed-effect/timed-effects.h"
33 #include "util/bit-flags-calculator.h"
34 #include "view/display-messages.h"
37 * @brief 「開ける」動作コマンドのサブルーチン /
38 * Perform the basic "open" command on doors
39 * @param y 対象を行うマスのY座標
40 * @param x 対象を行うマスのX座標
41 * @return 連続でコマンドを実行する時のみTRUE、1回きりの時はFALSE
43 bool exe_open(PlayerType *player_ptr, POSITION y, POSITION x)
45 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
46 auto *f_ptr = &f_info[g_ptr->feat];
47 PlayerEnergy(player_ptr).set_player_turn_energy(100);
48 if (f_ptr->flags.has_not(FloorFeatureType::OPEN)) {
49 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_info[g_ptr->get_feat_mimic()].name.c_str());
54 cave_alter_feat(player_ptr, y, x, FloorFeatureType::OPEN);
55 sound(SOUND_OPENDOOR);
59 int i = player_ptr->skill_dis;
60 if (player_ptr->blind || no_lite(player_ptr)) {
64 auto effects = player_ptr->effects();
65 if (effects->confusion()->is_confused() || effects->hallucination()->is_hallucinated()) {
75 if (randint0(100) >= j) {
80 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
84 msg_print(_("鍵をはずした。", "You have picked the lock."));
85 cave_alter_feat(player_ptr, y, x, FloorFeatureType::OPEN);
86 sound(SOUND_OPENDOOR);
87 gain_exp(player_ptr, 1);
92 * @brief 「閉じる」動作コマンドのサブルーチン /
93 * Perform the basic "close" command
94 * @param y 対象を行うマスのY座標
95 * @param x 対象を行うマスのX座標
96 * @return 実際に処理が行われた場合TRUEを返す。
98 * Assume destination is an open/broken door
99 * Assume there is no monster blocking the destination
100 * Returns TRUE if repeated commands may continue
101 * @todo 常にFALSEを返している
103 bool exe_close(PlayerType *player_ptr, POSITION y, POSITION x)
105 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
106 FEAT_IDX old_feat = g_ptr->feat;
108 PlayerEnergy(player_ptr).set_player_turn_energy(100);
109 if (f_info[old_feat].flags.has_not(FloorFeatureType::CLOSE)) {
113 int16_t closed_feat = feat_state(player_ptr->current_floor_ptr, old_feat, FloorFeatureType::CLOSE);
114 if ((!g_ptr->o_idx_list.empty() || g_ptr->is_object()) && (closed_feat != old_feat) && f_info[closed_feat].flags.has_not(FloorFeatureType::DROP)) {
115 msg_print(_("何かがつっかえて閉まらない。", "Something prevents it from closing."));
119 cave_alter_feat(player_ptr, y, x, FloorFeatureType::CLOSE);
120 if (old_feat == g_ptr->feat) {
121 msg_print(_("ドアは壊れてしまっている。", "The door appears to be broken."));
123 sound(SOUND_SHUTDOOR);
130 * @brief 移動処理による簡易な「開く」処理 /
132 * @return 開く処理が実際に試みられた場合TRUEを返す
135 * If there is a jammed/closed/locked door at the given location,
136 * then attempt to unlock/open it. Return TRUE if an attempt was
137 * made (successful or not), otherwise return FALSE.
139 * The code here should be nearly identical to that in
140 * do_cmd_open_test() and exe_open().
143 bool easy_open_door(PlayerType *player_ptr, POSITION y, POSITION x)
146 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
147 auto *f_ptr = &f_info[g_ptr->feat];
148 if (!is_closed_door(player_ptr, g_ptr->feat)) {
152 if (f_ptr->flags.has_not(FloorFeatureType::OPEN)) {
153 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_info[g_ptr->get_feat_mimic()].name.c_str());
154 } else if (f_ptr->power) {
155 i = player_ptr->skill_dis;
156 if (player_ptr->blind || no_lite(player_ptr)) {
160 auto effects = player_ptr->effects();
161 if (effects->confusion()->is_confused() || effects->hallucination()->is_hallucinated()) {
171 if (randint0(100) < j) {
172 msg_print(_("鍵をはずした。", "You have picked the lock."));
173 cave_alter_feat(player_ptr, y, x, FloorFeatureType::OPEN);
174 sound(SOUND_OPENDOOR);
175 gain_exp(player_ptr, 1);
181 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
184 cave_alter_feat(player_ptr, y, x, FloorFeatureType::OPEN);
185 sound(SOUND_OPENDOOR);
192 * @brief 箱のトラップを解除する実行処理 /
193 * Perform the basic "disarm" command
194 * @param y 解除を行うマスのY座標
195 * @param x 解除を行うマスのX座標
196 * @param o_idx 箱のオブジェクトID
197 * @return ターンを消費する処理が行われた場合TRUEを返す
200 * Assume destination is a visible trap
201 * Assume there is no monster blocking the destination
202 * Returns TRUE if repeated commands may continue
205 bool exe_disarm_chest(PlayerType *player_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
208 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
209 PlayerEnergy(player_ptr).set_player_turn_energy(100);
210 int i = player_ptr->skill_dis;
211 if (player_ptr->blind || no_lite(player_ptr)) {
215 auto effects = player_ptr->effects();
216 if (effects->confusion()->is_confused() || effects->hallucination()->is_hallucinated()) {
220 int j = i - o_ptr->pval;
225 if (!o_ptr->is_known()) {
226 msg_print(_("トラップが見あたらない。", "I don't see any traps."));
227 } else if (o_ptr->pval <= 0) {
228 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
229 } else if (chest_traps[o_ptr->pval].none()) {
230 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
231 } else if (randint0(100) < j) {
232 msg_print(_("箱に仕掛けられていたトラップを解除した。", "You have disarmed the chest."));
233 gain_exp(player_ptr, o_ptr->pval);
234 o_ptr->pval = (0 - o_ptr->pval);
235 } else if ((i > 5) && (randint1(i) > 5)) {
241 msg_print(_("箱のトラップ解除に失敗した。", "You failed to disarm the chest."));
243 msg_print(_("トラップを作動させてしまった!", "You set off a trap!"));
245 Chest(player_ptr).chest_trap(y, x, o_idx);
252 * @brief 箱のトラップを解除するコマンドのサブルーチン /
253 * Perform the basic "disarm" command
254 * @param y 解除を行うマスのY座標
255 * @param x 解除を行うマスのX座標
256 * @param dir プレイヤーからみた方向ID
257 * @return ターンを消費する処理が行われた場合TRUEを返す
260 * Assume destination is a visible trap
261 * Assume there is no monster blocking the destination
262 * Returns TRUE if repeated commands may continue
266 bool exe_disarm(PlayerType *player_ptr, POSITION y, POSITION x, DIRECTION dir)
268 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
269 auto *f_ptr = &f_info[g_ptr->feat];
270 concptr name = f_ptr->name.c_str();
271 int power = f_ptr->power;
273 int i = player_ptr->skill_dis;
274 PlayerEnergy(player_ptr).set_player_turn_energy(100);
275 if (player_ptr->blind || no_lite(player_ptr)) {
279 auto effects = player_ptr->effects();
280 if (effects->confusion()->is_confused() || effects->hallucination()->is_hallucinated()) {
289 if (randint0(100) < j) {
290 msg_format(_("%sを解除した。", "You have disarmed the %s."), name);
291 gain_exp(player_ptr, power);
292 cave_alter_feat(player_ptr, y, x, FloorFeatureType::DISARM);
293 exe_movement(player_ptr, dir, easy_disarm, false);
294 } else if ((i > 5) && (randint1(i) > 5)) {
299 msg_format(_("%sの解除に失敗した。", "You failed to disarm the %s."), name);
302 msg_format(_("%sを作動させてしまった!", "You set off the %s!"), name);
303 exe_movement(player_ptr, dir, easy_disarm, false);
310 * @brief 「打ち破る」動作コマンドのサブルーチン /
311 * Perform the basic "bash" command
312 * @param y 対象を行うマスのY座標
313 * @param x 対象を行うマスのX座標
314 * @param dir プレイヤーから見たターゲットの方角ID
315 * @return 実際に処理が行われた場合TRUEを返す。
318 * Assume destination is a closed/locked/jammed door
319 * Assume there is no monster blocking the destination
320 * Returns TRUE if repeated commands may continue
323 bool exe_bash(PlayerType *player_ptr, POSITION y, POSITION x, DIRECTION dir)
325 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
326 auto *f_ptr = &f_info[g_ptr->feat];
327 int bash = adj_str_blow[player_ptr->stat_index[A_STR]];
328 int temp = f_ptr->power;
330 concptr name = f_info[g_ptr->get_feat_mimic()].name.c_str();
331 PlayerEnergy(player_ptr).set_player_turn_energy(100);
332 msg_format(_("%sに体当たりをした!", "You smash into the %s!"), name);
333 temp = (bash - (temp * 10));
334 if (PlayerClass(player_ptr).equals(PlayerClassType::BERSERKER)) {
342 if (randint0(100) < temp) {
343 msg_format(_("%sを壊した!", "The %s crashes open!"), name);
344 sound(f_ptr->flags.has(FloorFeatureType::GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
345 if ((randint0(100) < 50) || (feat_state(player_ptr->current_floor_ptr, g_ptr->feat, FloorFeatureType::OPEN) == g_ptr->feat) || f_ptr->flags.has(FloorFeatureType::GLASS)) {
346 cave_alter_feat(player_ptr, y, x, FloorFeatureType::BASH);
348 cave_alter_feat(player_ptr, y, x, FloorFeatureType::OPEN);
351 exe_movement(player_ptr, dir, false, false);
352 } else if (randint0(100) < adj_dex_safe[player_ptr->stat_index[A_DEX]] + player_ptr->lev) {
353 msg_format(_("この%sは頑丈だ。", "The %s holds firm."), name);
356 msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
357 (void)BadStatusSetter(player_ptr).mod_paralysis(2 + randint0(2));