OSDN Git Service

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