OSDN Git Service

5bcd0f97392bceb48e6a1359ec356c6bc7b63403
[hengbandforosx/hengbandosx.git] / src / action / travel-execution.cpp
1 /*!
2  * @file travel-execution.cpp
3  * @brief トラベル移動処理実装
4  */
5
6 #include "action/travel-execution.h"
7 #include "action/movement-execution.h"
8 #include "action/run-execution.h"
9 #include "core/disturbance.h"
10 #include "floor/geometry.h"
11 #include "game-option/disturbance-options.h"
12 #include "game-option/input-options.h"
13 #include "game-option/special-options.h"
14 #include "grid/feature.h"
15 #include "grid/grid.h"
16 #include "player-status/player-energy.h"
17 #include "player/player-move.h"
18 #include "system/floor-type-definition.h"
19 #include "system/grid-type-definition.h"
20 #include "system/monster-type-definition.h"
21 #include "system/player-type-definition.h"
22 #include "view/display-messages.h"
23
24 travel_type travel;
25
26 /*!
27  * @brief トラベル機能の判定処理 /
28  * Test for traveling
29  * @param player_ptr    プレイヤーへの参照ポインタ
30  * @param prev_dir 前回移動を行った元の方角ID
31  * @return 次の方向
32  */
33 static DIRECTION travel_test(PlayerType *player_ptr, DIRECTION prev_dir)
34 {
35     if (player_ptr->blind || no_lite(player_ptr)) {
36         msg_print(_("目が見えない!", "You cannot see!"));
37         return 0;
38     }
39
40     auto *floor_ptr = player_ptr->current_floor_ptr;
41     if ((disturb_trap_detect || alert_trap_detect) && player_ptr->dtrap && !(floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_IN_DETECT)) {
42         player_ptr->dtrap = false;
43         if (!(floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_UNSAFE)) {
44             if (alert_trap_detect) {
45                 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
46             }
47
48             if (disturb_trap_detect) {
49                 return 0;
50             }
51         }
52     }
53
54     int max = (prev_dir & 0x01) + 1;
55     const grid_type *g_ptr;
56     for (int i = -max; i <= max; i++) {
57         DIRECTION dir = cycle[chome[prev_dir] + i];
58         POSITION row = player_ptr->y + ddy[dir];
59         POSITION col = player_ptr->x + ddx[dir];
60         g_ptr = &floor_ptr->grid_array[row][col];
61         if (g_ptr->m_idx) {
62             auto *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
63             if (m_ptr->ml) {
64                 return 0;
65             }
66         }
67     }
68
69     int cost = travel.cost[player_ptr->y][player_ptr->x];
70     DIRECTION new_dir = 0;
71     for (int i = 0; i < 8; ++i) {
72         int dir_cost = travel.cost[player_ptr->y + ddy_ddd[i]][player_ptr->x + ddx_ddd[i]];
73         if (dir_cost < cost) {
74             new_dir = ddd[i];
75             cost = dir_cost;
76         }
77     }
78
79     if (!new_dir) {
80         return 0;
81     }
82
83     g_ptr = &floor_ptr->grid_array[player_ptr->y + ddy[new_dir]][player_ptr->x + ddx[new_dir]];
84     if (!easy_open && is_closed_door(player_ptr, g_ptr->feat)) {
85         return 0;
86     }
87
88     if (!g_ptr->mimic && !trap_can_be_ignored(player_ptr, g_ptr->feat)) {
89         return 0;
90     }
91
92     return new_dir;
93 }
94
95 /*!
96  * @brief トラベル機能の実装 /
97  * Travel command
98  * @param player_ptr    プレイヤーへの参照ポインタ
99  */
100 void travel_step(PlayerType *player_ptr)
101 {
102     travel.dir = travel_test(player_ptr, travel.dir);
103     if (!travel.dir) {
104         if (travel.run == 255) {
105             msg_print(_("道筋が見つかりません!", "No route is found!"));
106             travel.y = travel.x = 0;
107         }
108
109         disturb(player_ptr, false, true);
110         return;
111     }
112
113     PlayerEnergy(player_ptr).set_player_turn_energy(100);
114     exe_movement(player_ptr, travel.dir, always_pickup, false);
115     if ((player_ptr->y == travel.y) && (player_ptr->x == travel.x)) {
116         travel.run = 0;
117         travel.y = travel.x = 0;
118     } else if (travel.run > 0) {
119         travel.run--;
120     }
121
122     term_xtra(TERM_XTRA_DELAY, delay_factor);
123 }
124
125 /*!
126  * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information
127  * @param player_ptr    プレイヤーへの参照ポインタ
128  */
129 void forget_travel_flow(floor_type *floor_ptr)
130 {
131     for (POSITION y = 0; y < floor_ptr->height; y++) {
132         for (POSITION x = 0; x < floor_ptr->width; x++) {
133             travel.cost[y][x] = MAX_SHORT;
134         }
135     }
136
137     travel.y = travel.x = 0;
138 }