2 * @file run-execution.cpp
6 #include "action/run-execution.h"
7 #include "action/movement-execution.h"
8 #include "core/disturbance.h"
9 #include "floor/cave.h"
10 #include "floor/floor-util.h"
11 #include "floor/geometry.h"
12 #include "game-option/disturbance-options.h"
13 #include "grid/feature.h"
14 #include "grid/grid.h"
15 #include "main/sound-definitions-table.h"
16 #include "main/sound-of-music.h"
17 #include "object/object-mark-types.h"
18 #include "player/player-status-flags.h"
19 #include "system/floor-type-definition.h"
20 #include "system/monster-type-definition.h"
21 #include "system/object-type-definition.h"
22 #include "system/player-type-definition.h"
23 #include "util/bit-flags-calculator.h"
24 #include "view/display-messages.h"
26 bool ignore_avoid_run;
28 /* Allow quick "cycling" through the legal directions */
29 byte cycle[MAX_RUN_CYCLES] = { 1, 2, 3, 6, 9, 8, 7, 4, 1, 2, 3, 6, 9, 8, 7, 4, 1 };
31 /* Map each direction into the "middle" of the "cycle[]" array */
32 byte chome[MAX_RUN_CHOME] = { 0, 8, 9, 10, 7, 0, 11, 6, 5, 4 };
34 /* The direction we are running */
35 static DIRECTION find_current;
37 /* The direction we came from */
38 static DIRECTION find_prevdir;
40 static bool find_openarea;
42 /* We are looking for a break */
43 static bool find_breakright;
44 static bool find_breakleft;
47 * @brief ダッシュ移動処理中、移動先のマスが既知の壁かどうかを判定する /
48 * Hack -- Check for a "known wall" (see below)
49 * @param creature_ptr プレーヤーへの参照ポインタ
50 * @param dir 想定する移動方向ID
53 * @return 移動先が既知の壁ならばTRUE
55 static bool see_wall(player_type *creature_ptr, DIRECTION dir, POSITION y, POSITION x)
59 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
60 if (!in_bounds2(floor_ptr, y, x))
64 g_ptr = &floor_ptr->grid_array[y][x];
65 if (!(g_ptr->info & CAVE_MARK))
68 s16b feat = get_feat_mimic(g_ptr);
69 feature_type *f_ptr = &f_info[feat];
70 if (!player_can_enter(creature_ptr, feat, 0))
71 return !has_flag(f_ptr->flags, FF_DOOR);
73 if (has_flag(f_ptr->flags, FF_AVOID_RUN) && !ignore_avoid_run)
76 if (!has_flag(f_ptr->flags, FF_MOVE) && !has_flag(f_ptr->flags, FF_CAN_FLY))
77 return !has_flag(f_ptr->flags, FF_DOOR);
84 * Initialize the running algorithm for a new direction.
85 * @param creature_ptr プレーヤーへの参照ポインタ
88 * Diagonal Corridor -- allow diaginal entry into corridors.\n
90 * Blunt Corridor -- If there is a wall two spaces ahead and\n
91 * we seem to be in a corridor, then force a turn into the side\n
92 * corridor, must be moving straight into a corridor here. ???\n
94 * Diagonal Corridor Blunt Corridor (?)\n
99 static void run_init(player_type *creature_ptr, DIRECTION dir)
103 find_openarea = TRUE;
104 find_breakright = find_breakleft = FALSE;
105 bool deepleft = FALSE;
106 bool deepright = FALSE;
107 bool shortright = FALSE;
108 bool shortleft = FALSE;
109 creature_ptr->run_py = creature_ptr->y;
110 creature_ptr->run_px = creature_ptr->x;
111 int row = creature_ptr->y + ddy[dir];
112 int col = creature_ptr->x + ddx[dir];
113 ignore_avoid_run = cave_has_flag_bold(creature_ptr->current_floor_ptr, row, col, FF_AVOID_RUN);
115 if (see_wall(creature_ptr, cycle[i + 1], creature_ptr->y, creature_ptr->x)) {
116 find_breakleft = TRUE;
118 } else if (see_wall(creature_ptr, cycle[i + 1], row, col)) {
119 find_breakleft = TRUE;
123 if (see_wall(creature_ptr, cycle[i - 1], creature_ptr->y, creature_ptr->x)) {
124 find_breakright = TRUE;
126 } else if (see_wall(creature_ptr, cycle[i - 1], row, col)) {
127 find_breakright = TRUE;
131 if (!find_breakleft || !find_breakright)
134 find_openarea = FALSE;
136 if (deepleft && !deepright) {
137 find_prevdir = cycle[i - 1];
138 } else if (deepright && !deepleft) {
139 find_prevdir = cycle[i + 1];
145 if (!see_wall(creature_ptr, cycle[i], row, col))
148 if (shortleft && !shortright) {
149 find_prevdir = cycle[i - 2];
150 } else if (shortright && !shortleft) {
151 find_prevdir = cycle[i + 2];
156 * @brief ダッシュ移動処理中、移動先のマスか未知の地形かどうかを判定する /
157 * Hack -- Check for an "unknown corner" (see below)
158 * @param creature_ptr プレーヤーへの参照ポインタ
159 * @param dir 想定する移動方向ID
162 * @return 移動先が未知の地形ならばTRUE
164 static bool see_nothing(player_type *creature_ptr, DIRECTION dir, POSITION y, POSITION x)
169 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
170 if (!in_bounds2(floor_ptr, y, x))
173 if (floor_ptr->grid_array[y][x].info & (CAVE_MARK))
176 if (player_can_see_bold(creature_ptr, y, x))
183 * @brief ダッシュ移動が継続できるかどうかの判定 /
184 * Update the current "run" path
185 * @param creature_ptr プレーヤーへの参照ポインタ
186 * @return 立ち止まるべき条件が満たされたらTRUE
187 * ダッシュ移動が継続できるならばTRUEを返す。
188 * Return TRUE if the running should be stopped
190 static bool run_test(player_type *creature_ptr)
192 DIRECTION prev_dir = find_prevdir;
193 int max = (prev_dir & 0x01) + 1;
194 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
195 if ((disturb_trap_detect || alert_trap_detect) && creature_ptr->dtrap && !(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_IN_DETECT)) {
196 creature_ptr->dtrap = FALSE;
197 if (!(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_UNSAFE)) {
198 if (alert_trap_detect) {
199 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
202 if (disturb_trap_detect) {
209 DIRECTION check_dir = 0;
210 int option = 0, option2 = 0;
211 for (int i = -max; i <= max; i++) {
212 OBJECT_IDX this_o_idx, next_o_idx = 0;
213 DIRECTION new_dir = cycle[chome[prev_dir] + i];
214 int row = creature_ptr->y + ddy[new_dir];
215 int col = creature_ptr->x + ddx[new_dir];
217 g_ptr = &floor_ptr->grid_array[row][col];
218 FEAT_IDX feat = get_feat_mimic(g_ptr);
220 f_ptr = &f_info[feat];
222 monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
227 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
229 o_ptr = &floor_ptr->o_list[this_o_idx];
230 next_o_idx = o_ptr->next_o_idx;
231 if (o_ptr->marked & OM_FOUND)
236 if (g_ptr->info & (CAVE_MARK)) {
237 bool notice = has_flag(f_ptr->flags, FF_NOTICE);
238 if (notice && has_flag(f_ptr->flags, FF_MOVE)) {
239 if (find_ignore_doors && has_flag(f_ptr->flags, FF_DOOR) && has_flag(f_ptr->flags, FF_CLOSE)) {
241 } else if (find_ignore_stairs && has_flag(f_ptr->flags, FF_STAIRS)) {
243 } else if (has_flag(f_ptr->flags, FF_LAVA) && (has_immune_fire(creature_ptr) || is_invuln(creature_ptr))) {
245 } else if (has_flag(f_ptr->flags, FF_WATER) && has_flag(f_ptr->flags, FF_DEEP)
246 && (creature_ptr->levitation || creature_ptr->can_swim || (calc_inventory_weight(creature_ptr) <= calc_weight_limit(creature_ptr)))) {
257 if (!inv && see_wall(creature_ptr, 0, row, col)) {
260 find_breakright = TRUE;
262 find_breakleft = TRUE;
280 if (option != cycle[chome[prev_dir] + i - 1])
283 if (new_dir & 0x01) {
284 check_dir = cycle[chome[prev_dir] + i - 2];
289 check_dir = cycle[chome[prev_dir] + i + 1];
295 for (int i = -max; i < 0; i++) {
296 if (!see_wall(creature_ptr, cycle[chome[prev_dir] + i], creature_ptr->y, creature_ptr->x)) {
305 for (int i = max; i > 0; i--) {
306 if (!see_wall(creature_ptr, cycle[chome[prev_dir] + i], creature_ptr->y, creature_ptr->x)) {
315 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
322 find_current = option;
323 find_prevdir = option;
324 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
325 } else if (!find_cut) {
326 find_current = option;
327 find_prevdir = option2;
328 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
331 int row = creature_ptr->y + ddy[option];
332 int col = creature_ptr->x + ddx[option];
333 if (!see_wall(creature_ptr, option, row, col) || !see_wall(creature_ptr, check_dir, row, col)) {
334 if (see_nothing(creature_ptr, option, row, col) && see_nothing(creature_ptr, option2, row, col)) {
335 find_current = option;
336 find_prevdir = option2;
337 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
344 find_current = option2;
345 find_prevdir = option2;
346 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
349 find_current = option;
350 find_prevdir = option2;
351 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
355 * @brief 継続的なダッシュ処理 /
356 * Take one step along the current "run" path
357 * @param creature_ptr プレーヤーへの参照ポインタ
358 * @param dir 移動を試みる方向ID
361 void run_step(player_type *creature_ptr, DIRECTION dir)
364 ignore_avoid_run = TRUE;
365 if (see_wall(creature_ptr, dir, creature_ptr->y, creature_ptr->x)) {
366 sound(SOUND_HITWALL);
367 msg_print(_("その方向には走れません。", "You cannot run in that direction."));
368 disturb(creature_ptr, FALSE, FALSE);
372 run_init(creature_ptr, dir);
374 if (run_test(creature_ptr)) {
375 disturb(creature_ptr, FALSE, FALSE);
380 if (--creature_ptr->running <= 0)
383 take_turn(creature_ptr, 100);
384 exe_movement(creature_ptr, find_current, FALSE, FALSE);
385 if (player_bold(creature_ptr, creature_ptr->run_py, creature_ptr->run_px)) {
386 creature_ptr->run_py = 0;
387 creature_ptr->run_px = 0;
388 disturb(creature_ptr, FALSE, FALSE);