1 #include "action/run-execution.h"
2 #include "action/movement-execution.h"
3 #include "core/disturbance.h"
4 #include "floor/floor.h"
5 #include "game-option/disturbance-options.h"
6 #include "grid/feature.h"
8 #include "main/sound-definitions-table.h"
9 #include "main/sound-of-music.h"
10 #include "object/object-mark-types.h"
11 #include "system/object-type-definition.h"
12 #include "util/bit-flags-calculator.h"
13 #include "view/display-messages.h"
15 bool ignore_avoid_run;
17 /* Allow quick "cycling" through the legal directions */
18 byte cycle[MAX_RUN_CYCLES] = { 1, 2, 3, 6, 9, 8, 7, 4, 1, 2, 3, 6, 9, 8, 7, 4, 1 };
20 /* Map each direction into the "middle" of the "cycle[]" array */
21 byte chome[MAX_RUN_CHOME] = { 0, 8, 9, 10, 7, 0, 11, 6, 5, 4 };
23 /* The direction we are running */
24 static DIRECTION find_current;
26 /* The direction we came from */
27 static DIRECTION find_prevdir;
29 static bool find_openarea;
31 /* We are looking for a break */
32 static bool find_breakright;
33 static bool find_breakleft;
36 * @brief ダッシュ移動処理中、移動先のマスが既知の壁かどうかを判定する /
37 * Hack -- Check for a "known wall" (see below)
38 * @param creature_ptr プレーヤーへの参照ポインタ
39 * @param dir 想定する移動方向ID
42 * @return 移動先が既知の壁ならばTRUE
44 static bool see_wall(player_type *creature_ptr, DIRECTION dir, POSITION y, POSITION x)
48 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
49 if (!in_bounds2(floor_ptr, y, x))
53 g_ptr = &floor_ptr->grid_array[y][x];
54 if (!(g_ptr->info & CAVE_MARK))
57 s16b feat = get_feat_mimic(g_ptr);
58 feature_type *f_ptr = &f_info[feat];
59 if (!player_can_enter(creature_ptr, feat, 0))
60 return !have_flag(f_ptr->flags, FF_DOOR);
62 if (have_flag(f_ptr->flags, FF_AVOID_RUN) && !ignore_avoid_run)
65 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
66 return !have_flag(f_ptr->flags, FF_DOOR);
73 * Initialize the running algorithm for a new direction.
74 * @param creature_ptr プレーヤーへの参照ポインタ
77 * Diagonal Corridor -- allow diaginal entry into corridors.\n
79 * Blunt Corridor -- If there is a wall two spaces ahead and\n
80 * we seem to be in a corridor, then force a turn into the side\n
81 * corridor, must be moving straight into a corridor here. ???\n
83 * Diagonal Corridor Blunt Corridor (?)\n
88 static void run_init(player_type *creature_ptr, DIRECTION dir)
93 find_breakright = find_breakleft = FALSE;
94 bool deepleft = FALSE;
95 bool deepright = FALSE;
96 bool shortright = FALSE;
97 bool shortleft = FALSE;
98 creature_ptr->run_py = creature_ptr->y;
99 creature_ptr->run_px = creature_ptr->x;
100 int row = creature_ptr->y + ddy[dir];
101 int col = creature_ptr->x + ddx[dir];
102 ignore_avoid_run = cave_have_flag_bold(creature_ptr->current_floor_ptr, row, col, FF_AVOID_RUN);
104 if (see_wall(creature_ptr, cycle[i + 1], creature_ptr->y, creature_ptr->x)) {
105 find_breakleft = TRUE;
107 } else if (see_wall(creature_ptr, cycle[i + 1], row, col)) {
108 find_breakleft = TRUE;
112 if (see_wall(creature_ptr, cycle[i - 1], creature_ptr->y, creature_ptr->x)) {
113 find_breakright = TRUE;
115 } else if (see_wall(creature_ptr, cycle[i - 1], row, col)) {
116 find_breakright = TRUE;
120 if (!find_breakleft || !find_breakright)
123 find_openarea = FALSE;
125 if (deepleft && !deepright) {
126 find_prevdir = cycle[i - 1];
127 } else if (deepright && !deepleft) {
128 find_prevdir = cycle[i + 1];
134 if (!see_wall(creature_ptr, cycle[i], row, col))
137 if (shortleft && !shortright) {
138 find_prevdir = cycle[i - 2];
139 } else if (shortright && !shortleft) {
140 find_prevdir = cycle[i + 2];
145 * @brief ダッシュ移動処理中、移動先のマスか未知の地形かどうかを判定する /
146 * Hack -- Check for an "unknown corner" (see below)
147 * @param creature_ptr プレーヤーへの参照ポインタ
148 * @param dir 想定する移動方向ID
151 * @return 移動先が未知の地形ならばTRUE
153 static bool see_nothing(player_type *creature_ptr, DIRECTION dir, POSITION y, POSITION x)
158 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
159 if (!in_bounds2(floor_ptr, y, x))
162 if (floor_ptr->grid_array[y][x].info & (CAVE_MARK))
165 if (player_can_see_bold(creature_ptr, y, x))
172 * @brief ダッシュ移動が継続できるかどうかの判定 /
173 * Update the current "run" path
174 * @param creature_ptr プレーヤーへの参照ポインタ
175 * @return 立ち止まるべき条件が満たされたらTRUE
176 * ダッシュ移動が継続できるならばTRUEを返す。
177 * Return TRUE if the running should be stopped
179 static bool run_test(player_type *creature_ptr)
181 DIRECTION prev_dir = find_prevdir;
182 int max = (prev_dir & 0x01) + 1;
183 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
184 if ((disturb_trap_detect || alert_trap_detect) && creature_ptr->dtrap && !(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_IN_DETECT)) {
185 creature_ptr->dtrap = FALSE;
186 if (!(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_UNSAFE)) {
187 if (alert_trap_detect) {
188 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
191 if (disturb_trap_detect) {
198 DIRECTION check_dir = 0;
199 int option = 0, option2 = 0;
200 for (int i = -max; i <= max; i++) {
201 OBJECT_IDX this_o_idx, next_o_idx = 0;
202 DIRECTION new_dir = cycle[chome[prev_dir] + i];
203 int row = creature_ptr->y + ddy[new_dir];
204 int col = creature_ptr->x + ddx[new_dir];
206 g_ptr = &floor_ptr->grid_array[row][col];
207 FEAT_IDX feat = get_feat_mimic(g_ptr);
209 f_ptr = &f_info[feat];
211 monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
216 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
218 o_ptr = &floor_ptr->o_list[this_o_idx];
219 next_o_idx = o_ptr->next_o_idx;
220 if (o_ptr->marked & OM_FOUND)
225 if (g_ptr->info & (CAVE_MARK)) {
226 bool notice = have_flag(f_ptr->flags, FF_NOTICE);
227 if (notice && have_flag(f_ptr->flags, FF_MOVE)) {
228 if (find_ignore_doors && have_flag(f_ptr->flags, FF_DOOR) && have_flag(f_ptr->flags, FF_CLOSE)) {
230 } else if (find_ignore_stairs && have_flag(f_ptr->flags, FF_STAIRS)) {
232 } else if (have_flag(f_ptr->flags, FF_LAVA) && (creature_ptr->immune_fire || is_invuln(creature_ptr))) {
234 } else if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP)
235 && (creature_ptr->levitation || creature_ptr->can_swim || (creature_ptr->total_weight <= weight_limit(creature_ptr)))) {
246 if (!inv && see_wall(creature_ptr, 0, row, col)) {
249 find_breakright = TRUE;
251 find_breakleft = TRUE;
269 if (option != cycle[chome[prev_dir] + i - 1])
272 if (new_dir & 0x01) {
273 check_dir = cycle[chome[prev_dir] + i - 2];
278 check_dir = cycle[chome[prev_dir] + i + 1];
284 for (int i = -max; i < 0; i++) {
285 if (!see_wall(creature_ptr, cycle[chome[prev_dir] + i], creature_ptr->y, creature_ptr->x)) {
294 for (int i = max; i > 0; i--) {
295 if (!see_wall(creature_ptr, cycle[chome[prev_dir] + i], creature_ptr->y, creature_ptr->x)) {
304 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
311 find_current = option;
312 find_prevdir = option;
313 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
314 } else if (!find_cut) {
315 find_current = option;
316 find_prevdir = option2;
317 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
320 int row = creature_ptr->y + ddy[option];
321 int col = creature_ptr->x + ddx[option];
322 if (!see_wall(creature_ptr, option, row, col) || !see_wall(creature_ptr, check_dir, row, col)) {
323 if (see_nothing(creature_ptr, option, row, col) && see_nothing(creature_ptr, option2, row, col)) {
324 find_current = option;
325 find_prevdir = option2;
326 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
333 find_current = option2;
334 find_prevdir = option2;
335 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
338 find_current = option;
339 find_prevdir = option2;
340 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
344 * @brief 継続的なダッシュ処理 /
345 * Take one step along the current "run" path
346 * @param creature_ptr プレーヤーへの参照ポインタ
347 * @param dir 移動を試みる方向ID
350 void run_step(player_type *creature_ptr, DIRECTION dir)
353 ignore_avoid_run = TRUE;
354 if (see_wall(creature_ptr, dir, creature_ptr->y, creature_ptr->x)) {
355 sound(SOUND_HITWALL);
356 msg_print(_("その方向には走れません。", "You cannot run in that direction."));
357 disturb(creature_ptr, FALSE, FALSE);
361 run_init(creature_ptr, dir);
363 if (run_test(creature_ptr)) {
364 disturb(creature_ptr, FALSE, FALSE);
369 if (--creature_ptr->running <= 0)
372 take_turn(creature_ptr, 100);
373 exe_movement(creature_ptr, find_current, FALSE, FALSE);
374 if (player_bold(creature_ptr, creature_ptr->run_py, creature_ptr->run_px)) {
375 creature_ptr->run_py = 0;
376 creature_ptr->run_px = 0;
377 disturb(creature_ptr, FALSE, FALSE);