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 "player/player-status.h"
20 #include "system/floor-type-definition.h"
21 #include "system/monster-type-definition.h"
22 #include "system/object-type-definition.h"
23 #include "system/player-type-definition.h"
24 #include "util/bit-flags-calculator.h"
25 #include "view/display-messages.h"
27 bool ignore_avoid_run;
29 /* Allow quick "cycling" through the legal directions */
30 byte cycle[MAX_RUN_CYCLES] = { 1, 2, 3, 6, 9, 8, 7, 4, 1, 2, 3, 6, 9, 8, 7, 4, 1 };
32 /* Map each direction into the "middle" of the "cycle[]" array */
33 byte chome[MAX_RUN_CHOME] = { 0, 8, 9, 10, 7, 0, 11, 6, 5, 4 };
35 /* The direction we are running */
36 static DIRECTION find_current;
38 /* The direction we came from */
39 static DIRECTION find_prevdir;
41 static bool find_openarea;
43 /* We are looking for a break */
44 static bool find_breakright;
45 static bool find_breakleft;
48 * @brief ダッシュ移動処理中、移動先のマスが既知の壁かどうかを判定する /
49 * Hack -- Check for a "known wall" (see below)
50 * @param creature_ptr プレーヤーへの参照ポインタ
51 * @param dir 想定する移動方向ID
54 * @return 移動先が既知の壁ならばTRUE
56 static bool see_wall(player_type *creature_ptr, DIRECTION dir, POSITION y, POSITION x)
60 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
61 if (!in_bounds2(floor_ptr, y, x))
65 g_ptr = &floor_ptr->grid_array[y][x];
66 if (!(g_ptr->info & CAVE_MARK))
69 s16b feat = get_feat_mimic(g_ptr);
70 feature_type *f_ptr = &f_info[feat];
71 if (!player_can_enter(creature_ptr, feat, 0))
72 return !has_flag(f_ptr->flags, FF_DOOR);
74 if (has_flag(f_ptr->flags, FF_AVOID_RUN) && !ignore_avoid_run)
77 if (!has_flag(f_ptr->flags, FF_MOVE) && !has_flag(f_ptr->flags, FF_CAN_FLY))
78 return !has_flag(f_ptr->flags, FF_DOOR);
85 * Initialize the running algorithm for a new direction.
86 * @param creature_ptr プレーヤーへの参照ポインタ
89 * Diagonal Corridor -- allow diaginal entry into corridors.\n
91 * Blunt Corridor -- If there is a wall two spaces ahead and\n
92 * we seem to be in a corridor, then force a turn into the side\n
93 * corridor, must be moving straight into a corridor here. ???\n
95 * Diagonal Corridor Blunt Corridor (?)\n
100 static void run_init(player_type *creature_ptr, DIRECTION dir)
104 find_openarea = TRUE;
105 find_breakright = find_breakleft = FALSE;
106 bool deepleft = FALSE;
107 bool deepright = FALSE;
108 bool shortright = FALSE;
109 bool shortleft = FALSE;
110 creature_ptr->run_py = creature_ptr->y;
111 creature_ptr->run_px = creature_ptr->x;
112 int row = creature_ptr->y + ddy[dir];
113 int col = creature_ptr->x + ddx[dir];
114 ignore_avoid_run = cave_has_flag_bold(creature_ptr->current_floor_ptr, row, col, FF_AVOID_RUN);
116 if (see_wall(creature_ptr, cycle[i + 1], creature_ptr->y, creature_ptr->x)) {
117 find_breakleft = TRUE;
119 } else if (see_wall(creature_ptr, cycle[i + 1], row, col)) {
120 find_breakleft = TRUE;
124 if (see_wall(creature_ptr, cycle[i - 1], creature_ptr->y, creature_ptr->x)) {
125 find_breakright = TRUE;
127 } else if (see_wall(creature_ptr, cycle[i - 1], row, col)) {
128 find_breakright = TRUE;
132 if (!find_breakleft || !find_breakright)
135 find_openarea = FALSE;
137 if (deepleft && !deepright) {
138 find_prevdir = cycle[i - 1];
139 } else if (deepright && !deepleft) {
140 find_prevdir = cycle[i + 1];
146 if (!see_wall(creature_ptr, cycle[i], row, col))
149 if (shortleft && !shortright) {
150 find_prevdir = cycle[i - 2];
151 } else if (shortright && !shortleft) {
152 find_prevdir = cycle[i + 2];
157 * @brief ダッシュ移動処理中、移動先のマスか未知の地形かどうかを判定する /
158 * Hack -- Check for an "unknown corner" (see below)
159 * @param creature_ptr プレーヤーへの参照ポインタ
160 * @param dir 想定する移動方向ID
163 * @return 移動先が未知の地形ならばTRUE
165 static bool see_nothing(player_type *creature_ptr, DIRECTION dir, POSITION y, POSITION x)
170 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
171 if (!in_bounds2(floor_ptr, y, x))
174 if (floor_ptr->grid_array[y][x].info & (CAVE_MARK))
177 if (player_can_see_bold(creature_ptr, y, x))
184 * @brief ダッシュ移動が継続できるかどうかの判定 /
185 * Update the current "run" path
186 * @param creature_ptr プレーヤーへの参照ポインタ
187 * @return 立ち止まるべき条件が満たされたらTRUE
188 * ダッシュ移動が継続できるならばTRUEを返す。
189 * Return TRUE if the running should be stopped
191 static bool run_test(player_type *creature_ptr)
193 DIRECTION prev_dir = find_prevdir;
194 int max = (prev_dir & 0x01) + 1;
195 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
196 if ((disturb_trap_detect || alert_trap_detect) && creature_ptr->dtrap && !(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_IN_DETECT)) {
197 creature_ptr->dtrap = FALSE;
198 if (!(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_UNSAFE)) {
199 if (alert_trap_detect) {
200 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
203 if (disturb_trap_detect) {
210 DIRECTION check_dir = 0;
211 int option = 0, option2 = 0;
212 for (int i = -max; i <= max; i++) {
213 OBJECT_IDX this_o_idx, next_o_idx = 0;
214 DIRECTION new_dir = cycle[chome[prev_dir] + i];
215 int row = creature_ptr->y + ddy[new_dir];
216 int col = creature_ptr->x + ddx[new_dir];
218 g_ptr = &floor_ptr->grid_array[row][col];
219 FEAT_IDX feat = get_feat_mimic(g_ptr);
221 f_ptr = &f_info[feat];
223 monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
228 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
230 o_ptr = &floor_ptr->o_list[this_o_idx];
231 next_o_idx = o_ptr->next_o_idx;
232 if (o_ptr->marked & OM_FOUND)
237 if (g_ptr->info & (CAVE_MARK)) {
238 bool notice = has_flag(f_ptr->flags, FF_NOTICE);
239 if (notice && has_flag(f_ptr->flags, FF_MOVE)) {
240 if (find_ignore_doors && has_flag(f_ptr->flags, FF_DOOR) && has_flag(f_ptr->flags, FF_CLOSE)) {
242 } else if (find_ignore_stairs && has_flag(f_ptr->flags, FF_STAIRS)) {
244 } else if (has_flag(f_ptr->flags, FF_LAVA) && (has_immune_fire(creature_ptr) || is_invuln(creature_ptr))) {
246 } else if (has_flag(f_ptr->flags, FF_WATER) && has_flag(f_ptr->flags, FF_DEEP)
247 && (creature_ptr->levitation || creature_ptr->can_swim || (calc_inventory_weight(creature_ptr) <= calc_weight_limit(creature_ptr)))) {
258 if (!inv && see_wall(creature_ptr, 0, row, col)) {
261 find_breakright = TRUE;
263 find_breakleft = TRUE;
281 if (option != cycle[chome[prev_dir] + i - 1])
284 if (new_dir & 0x01) {
285 check_dir = cycle[chome[prev_dir] + i - 2];
290 check_dir = cycle[chome[prev_dir] + i + 1];
296 for (int i = -max; i < 0; i++) {
297 if (!see_wall(creature_ptr, cycle[chome[prev_dir] + i], creature_ptr->y, creature_ptr->x)) {
306 for (int i = max; i > 0; i--) {
307 if (!see_wall(creature_ptr, cycle[chome[prev_dir] + i], creature_ptr->y, creature_ptr->x)) {
316 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
323 find_current = option;
324 find_prevdir = option;
325 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
326 } else if (!find_cut) {
327 find_current = option;
328 find_prevdir = option2;
329 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
332 int row = creature_ptr->y + ddy[option];
333 int col = creature_ptr->x + ddx[option];
334 if (!see_wall(creature_ptr, option, row, col) || !see_wall(creature_ptr, check_dir, row, col)) {
335 if (see_nothing(creature_ptr, option, row, col) && see_nothing(creature_ptr, option2, row, col)) {
336 find_current = option;
337 find_prevdir = option2;
338 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
345 find_current = option2;
346 find_prevdir = option2;
347 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
350 find_current = option;
351 find_prevdir = option2;
352 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
356 * @brief 継続的なダッシュ処理 /
357 * Take one step along the current "run" path
358 * @param creature_ptr プレーヤーへの参照ポインタ
359 * @param dir 移動を試みる方向ID
362 void run_step(player_type *creature_ptr, DIRECTION dir)
365 ignore_avoid_run = TRUE;
366 if (see_wall(creature_ptr, dir, creature_ptr->y, creature_ptr->x)) {
367 sound(SOUND_HITWALL);
368 msg_print(_("その方向には走れません。", "You cannot run in that direction."));
369 disturb(creature_ptr, FALSE, FALSE);
373 run_init(creature_ptr, dir);
375 if (run_test(creature_ptr)) {
376 disturb(creature_ptr, FALSE, FALSE);
381 if (--creature_ptr->running <= 0)
384 take_turn(creature_ptr, 100);
385 exe_movement(creature_ptr, find_current, FALSE, FALSE);
386 if (player_bold(creature_ptr, creature_ptr->run_py, creature_ptr->run_px)) {
387 creature_ptr->run_py = 0;
388 creature_ptr->run_px = 0;
389 disturb(creature_ptr, FALSE, FALSE);