OSDN Git Service

[Refactor] #3650 Grid::get_feat_mimic() から地形特性を得ていた箇所をget_terrain_mimic() に置換した
[hengbandforosx/hengbandosx.git] / src / cmd-action / cmd-tunnel.cpp
1 #include "cmd-action/cmd-tunnel.h"
2 #include "action/tunnel-execution.h"
3 #include "cmd-action/cmd-attack.h"
4 #include "core/disturbance.h"
5 #include "floor/geometry.h"
6 #include "grid/grid.h"
7 #include "io/input-key-requester.h"
8 #include "player-base/player-class.h"
9 #include "player-info/samurai-data-type.h"
10 #include "player-status/player-energy.h"
11 #include "player/attack-defense-types.h"
12 #include "player/special-defense-types.h"
13 #include "status/action-setter.h"
14 #include "system/floor-type-definition.h"
15 #include "system/grid-type-definition.h"
16 #include "system/player-type-definition.h"
17 #include "system/redrawing-flags-updater.h"
18 #include "system/terrain-type-definition.h"
19 #include "target/target-getter.h"
20 #include "util/bit-flags-calculator.h"
21 #include "view/display-messages.h"
22
23 /*!
24  * @brief 「掘る」動作コマンドのメインルーチン /
25  * Tunnels through "walls" (including rubble and closed doors)
26  * @details
27  * <pre>
28  * Note that you must tunnel in order to hit invisible monsters
29  * in walls, though moving into walls still takes a turn anyway.
30  *
31  * Digging is very difficult without a "digger" weapon, but can be
32  * accomplished by strong players using heavy weapons.
33  * </pre>
34  */
35 void do_cmd_tunnel(PlayerType *player_ptr)
36 {
37     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
38
39     if (command_arg) {
40         command_rep = command_arg - 1;
41         RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::ACTION);
42         command_arg = 0;
43     }
44
45     int dir;
46     if (!get_rep_dir(player_ptr, &dir)) {
47         disturb(player_ptr, false, false);
48         return;
49     }
50
51     auto more = false;
52     const Pos2D pos(player_ptr->y + ddy[dir], player_ptr->x + ddx[dir]);
53     const auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
54     const auto &terrain_mimic = grid.get_terrain_mimic();
55     if (terrain_mimic.flags.has(TerrainCharacteristics::DOOR)) {
56         msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
57     } else if (terrain_mimic.flags.has_not(TerrainCharacteristics::TUNNEL)) {
58         msg_print(_("そこは掘れない。", "You can't tunnel through that."));
59     } else if (grid.m_idx) {
60         PlayerEnergy(player_ptr).set_player_turn_energy(100);
61         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
62         do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
63     } else {
64         more = exe_tunnel(player_ptr, pos.y, pos.x);
65     }
66
67     if (!more) {
68         disturb(player_ptr, false, false);
69     }
70 }