OSDN Git Service

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