OSDN Git Service

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