1 #include "cmd-action/cmd-open-close.h"
2 #include "action/open-close-execution.h"
3 #include "action/open-util.h"
4 #include "cmd-action/cmd-attack.h"
5 #include "core/disturbance.h"
6 #include "core/player-redraw-types.h"
7 #include "floor/geometry.h"
8 #include "game-option/disturbance-options.h"
9 #include "game-option/input-options.h"
10 #include "grid/feature.h"
11 #include "grid/grid.h"
12 #include "inventory/inventory-object.h"
13 #include "inventory/inventory-slot-types.h"
14 #include "io/input-key-requester.h"
15 #include "player-status/player-energy.h"
16 #include "player/attack-defense-types.h"
17 #include "player/special-defense-types.h"
18 #include "specific-object/chest.h"
19 #include "status/action-setter.h"
20 #include "status/experience.h"
21 #include "system/floor-type-definition.h"
22 #include "system/grid-type-definition.h"
23 #include "system/object-type-definition.h"
24 #include "system/player-type-definition.h"
25 #include "target/target-getter.h"
26 #include "term/screen-processor.h"
27 #include "util/bit-flags-calculator.h"
28 #include "view/display-messages.h"
32 * Attempt to open the given chest at the given location
33 * @param y 箱の存在するマスのY座標
34 * @param x 箱の存在するマスのX座標
35 * @param o_idx 箱のオブジェクトID
36 * @return 箱が開かなかった場合TRUE / Returns TRUE if repeated commands may continue
38 * Assume there is no monster blocking the destination
40 static bool exe_open_chest(player_type *player_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
44 object_type *o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
45 PlayerEnergy(player_ptr).set_player_turn_energy(100);
46 if (o_ptr->pval > 0) {
48 int i = player_ptr->skill_dis;
49 if (player_ptr->blind || no_lite(player_ptr))
52 if (player_ptr->confused || player_ptr->image)
55 int j = i - o_ptr->pval;
59 if (randint0(100) < j) {
60 msg_print(_("鍵をはずした。", "You have picked the lock."));
61 gain_exp(player_ptr, 1);
68 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
73 chest_trap(player_ptr, y, x, o_idx);
74 chest_death(player_ptr, false, y, x, o_idx);
81 * @brief 「開ける」コマンドのメインルーチン /
82 * Open a closed/locked/jammed door or a closed/locked chest.
84 * Unlocking a locked door/chest is worth one experience point.
86 void do_cmd_open(player_type *player_ptr)
92 if (player_ptr->wild_mode)
95 if (player_ptr->special_defense & KATA_MUSOU)
96 set_action(player_ptr, ACTION_NONE);
99 int num_doors = count_dt(player_ptr, &y, &x, is_closed_door, false);
100 int num_chests = count_chests(player_ptr, &y, &x, false);
101 if (num_doors || num_chests) {
102 bool too_many = (num_doors && num_chests) || (num_doors > 1) || (num_chests > 1);
104 command_dir = coords_to_dir(player_ptr, y, x);
109 command_rep = command_arg - 1;
110 player_ptr->redraw |= PR_STATE;
114 if (get_rep_dir(player_ptr, &dir, true)) {
117 y = player_ptr->y + ddy[dir];
118 x = player_ptr->x + ddx[dir];
119 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
120 feat = g_ptr->get_feat_mimic();
121 o_idx = chest_check(player_ptr->current_floor_ptr, y, x, false);
122 if (f_info[feat].flags.has_not(FF::OPEN) && !o_idx) {
123 msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
124 } else if (g_ptr->m_idx && player_ptr->riding != g_ptr->m_idx) {
125 PlayerEnergy(player_ptr).set_player_turn_energy(100);
126 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
127 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
129 more = exe_open_chest(player_ptr, y, x, o_idx);
131 more = exe_open(player_ptr, y, x);
136 disturb(player_ptr, false, false);
140 * @brief 「閉じる」コマンドのメインルーチン /
141 * Close an open door.
143 * Unlocking a locked door/chest is worth one experience point.
145 void do_cmd_close(player_type *player_ptr)
150 if (player_ptr->wild_mode)
153 if (player_ptr->special_defense & KATA_MUSOU)
154 set_action(player_ptr, ACTION_NONE);
156 if (easy_open && (count_dt(player_ptr, &y, &x, is_open, false) == 1))
157 command_dir = coords_to_dir(player_ptr, y, x);
160 command_rep = command_arg - 1;
161 player_ptr->redraw |= (PR_STATE);
165 if (get_rep_dir(player_ptr, &dir, false)) {
168 y = player_ptr->y + ddy[dir];
169 x = player_ptr->x + ddx[dir];
170 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
171 feat = g_ptr->get_feat_mimic();
172 if (f_info[feat].flags.has_not(FF::CLOSE)) {
173 msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
174 } else if (g_ptr->m_idx) {
175 PlayerEnergy(player_ptr).set_player_turn_energy(100);
176 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
177 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
179 more = exe_close(player_ptr, y, x);
184 disturb(player_ptr, false, false);
188 * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
189 * Disarms a trap, or chest
191 void do_cmd_disarm(player_type *player_ptr)
197 if (player_ptr->wild_mode)
200 if (player_ptr->special_defense & KATA_MUSOU)
201 set_action(player_ptr, ACTION_NONE);
204 int num_traps = count_dt(player_ptr, &y, &x, is_trap, true);
205 int num_chests = count_chests(player_ptr, &y, &x, true);
206 if (num_traps || num_chests) {
207 bool too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
209 command_dir = coords_to_dir(player_ptr, y, x);
214 command_rep = command_arg - 1;
215 player_ptr->redraw |= (PR_STATE);
219 if (get_rep_dir(player_ptr, &dir, true)) {
222 y = player_ptr->y + ddy[dir];
223 x = player_ptr->x + ddx[dir];
224 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
225 feat = g_ptr->get_feat_mimic();
226 o_idx = chest_check(player_ptr->current_floor_ptr, y, x, true);
227 if (!is_trap(player_ptr, feat) && !o_idx) {
228 msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
229 } else if (g_ptr->m_idx && player_ptr->riding != g_ptr->m_idx) {
230 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
231 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
233 more = exe_disarm_chest(player_ptr, y, x, o_idx);
235 more = exe_disarm(player_ptr, y, x, dir);
240 disturb(player_ptr, false, false);
244 * @brief 「打ち破る」動作コマンドのメインルーチン /
245 * Bash open a door, success based on character strength
248 * For a closed door, pval is positive if locked; negative if stuck.
250 * For an open door, pval is positive for a broken door.
252 * A closed door can be opened - harder if locked. Any door might be
253 * bashed open (and thereby broken). Bashing a door is (potentially)
254 * faster! You move into the door way. To open a stuck door, it must
255 * be bashed. A closed door can be jammed (see do_cmd_spike()).
257 * Creatures can also open or bash doors, see elsewhere.
260 void do_cmd_bash(player_type *player_ptr)
266 if (player_ptr->wild_mode)
269 if (player_ptr->special_defense & KATA_MUSOU)
270 set_action(player_ptr, ACTION_NONE);
273 command_rep = command_arg - 1;
274 player_ptr->redraw |= (PR_STATE);
278 if (get_rep_dir(player_ptr, &dir, false)) {
280 y = player_ptr->y + ddy[dir];
281 x = player_ptr->x + ddx[dir];
282 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
283 feat = g_ptr->get_feat_mimic();
284 if (f_info[feat].flags.has_not(FF::BASH)) {
285 msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
286 } else if (g_ptr->m_idx) {
287 PlayerEnergy(player_ptr).set_player_turn_energy(100);
288 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
289 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
291 more = exe_bash(player_ptr, y, x, dir);
296 disturb(player_ptr, false, false);
301 * @brief 「くさびを打つ」ために必要なオブジェクトを所持しているかどうかの判定を返す /
302 * Find the index of some "spikes", if possible.
303 * @param ip くさびとして打てるオブジェクトのID
304 * @return オブジェクトがある場合TRUEを返す
307 * Let user choose a pile of spikes, perhaps?
310 static bool get_spike(player_type *player_ptr, INVENTORY_IDX *ip)
312 for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
313 object_type *o_ptr = &player_ptr->inventory_list[i];
317 if (o_ptr->tval == TV_SPIKE) {
327 * @brief 「くさびを打つ」動作コマンドのメインルーチン /
328 * Jam a closed door with a spike
329 * @param player_ptr プレーヤーへの参照ポインタ
332 * This command may NOT be repeated
335 void do_cmd_spike(player_type *player_ptr)
338 if (player_ptr->wild_mode)
341 if (player_ptr->special_defense & KATA_MUSOU)
342 set_action(player_ptr, ACTION_NONE);
344 if (!get_rep_dir(player_ptr, &dir, false))
347 POSITION y = player_ptr->y + ddy[dir];
348 POSITION x = player_ptr->x + ddx[dir];
350 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
351 FEAT_IDX feat = g_ptr->get_feat_mimic();
353 if (f_info[feat].flags.has_not(FF::SPIKE)) {
354 msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
355 } else if (!get_spike(player_ptr, &item)) {
356 msg_print(_("くさびを持っていない!", "You have no spikes!"));
357 } else if (g_ptr->m_idx) {
358 PlayerEnergy(player_ptr).set_player_turn_energy(100);
359 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
360 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
362 PlayerEnergy(player_ptr).set_player_turn_energy(100);
363 msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_info[feat].name.c_str());
364 cave_alter_feat(player_ptr, y, x, FF::SPIKE);
365 vary_item(player_ptr, item, -1);