OSDN Git Service

[Refactor] #40535 Separated tunnel-execution.c/h from cmd-basic.c
[hengband/hengband.git] / src / action / tunnel-execution.c
1 #include "action/tunnel-execution.h"
2 #include "core/player-update-types.h"
3 #include "floor/floor.h"
4 #include "grid/feature.h"
5 #include "grid/grid.h"
6 #include "main/sound-definitions-table.h"
7 #include "main/sound-of-music.h"
8 #include "player/avatar.h"
9 #include "player/player-move.h"
10 #include "util/bit-flags-calculator.h"
11 #include "view/display-messages.h"
12
13 /*!
14  * @brief 「掘る」コマンドを該当のマスに行えるかの判定と結果メッセージの表示 /
15  * Determine if a given grid may be "tunneled"
16  * @param y 対象を行うマスのY座標
17  * @param x 対象を行うマスのX座標
18  * @return
19  */
20 static bool do_cmd_tunnel_test(floor_type *floor_ptr, POSITION y, POSITION x)
21 {
22     grid_type *g_ptr = &floor_ptr->grid_array[y][x];
23     if (!(g_ptr->info & CAVE_MARK)) {
24         msg_print(_("そこには何も見当たらない。", "You see nothing there."));
25         return FALSE;
26     }
27
28     if (!cave_have_flag_grid(g_ptr, FF_TUNNEL)) {
29         msg_print(_("そこには掘るものが見当たらない。", "You see nothing there to tunnel."));
30         return FALSE;
31     }
32
33     return TRUE;
34 }
35
36 /*!
37  * @brief 「掘る」動作コマンドのサブルーチン /
38  * Perform the basic "tunnel" command
39  * @param y 対象を行うマスのY座標
40  * @param x 対象を行うマスのX座標
41  * @return 実際に処理が行われた場合TRUEを返す。
42  * @details
43  * Assumes that no monster is blocking the destination
44  * Do not use twall anymore
45  * Returns TRUE if repeated commands may continue
46  */
47 bool exe_tunnel(player_type *creature_ptr, POSITION y, POSITION x)
48 {
49     grid_type *g_ptr;
50     feature_type *f_ptr, *mimic_f_ptr;
51     int power;
52     concptr name;
53     bool more = FALSE;
54     if (!do_cmd_tunnel_test(creature_ptr->current_floor_ptr, y, x))
55         return FALSE;
56
57     take_turn(creature_ptr, 100);
58     g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
59     f_ptr = &f_info[g_ptr->feat];
60     power = f_ptr->power;
61     mimic_f_ptr = &f_info[get_feat_mimic(g_ptr)];
62     name = f_name + mimic_f_ptr->name;
63     sound(SOUND_DIG);
64     if (have_flag(f_ptr->flags, FF_PERMANENT)) {
65         if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
66             msg_print(_("この岩は硬すぎて掘れないようだ。", "This seems to be permanent rock."));
67         else
68             msg_print(_("そこは掘れない!", "You can't tunnel through that!"));
69     } else if (have_flag(f_ptr->flags, FF_CAN_DIG)) {
70         if (creature_ptr->skill_dig > randint0(20 * power)) {
71             msg_format(_("%sをくずした。", "You have removed the %s."), name);
72             cave_alter_feat(creature_ptr, y, x, FF_TUNNEL);
73             creature_ptr->update |= PU_FLOW;
74         } else {
75             msg_format(_("%sをくずしている。", "You dig into the %s."), name);
76             more = TRUE;
77         }
78     } else {
79         bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
80         if (creature_ptr->skill_dig > power + randint0(40 * power)) {
81             if (tree)
82                 msg_format(_("%sを切り払った。", "You have cleared away the %s."), name);
83             else {
84                 msg_print(_("穴を掘り終えた。", "You have finished the tunnel."));
85                 creature_ptr->update |= (PU_FLOW);
86             }
87
88             if (have_flag(f_ptr->flags, FF_GLASS))
89                 sound(SOUND_GLASS);
90
91             cave_alter_feat(creature_ptr, y, x, FF_TUNNEL);
92             chg_virtue(creature_ptr, V_DILIGENCE, 1);
93             chg_virtue(creature_ptr, V_NATURE, -1);
94         } else {
95             if (tree) {
96                 msg_format(_("%sを切っている。", "You chop away at the %s."), name);
97                 if (randint0(100) < 25)
98                     search(creature_ptr);
99             } else {
100                 msg_format(_("%sに穴を掘っている。", "You tunnel into the %s."), name);
101             }
102
103             more = TRUE;
104         }
105     }
106
107     if (is_hidden_door(creature_ptr, g_ptr) && (randint0(100) < 25))
108         search(creature_ptr);
109
110     return more;
111 }