3 * @brief プレイヤーのコマンド処理1 / Movement commands (part 1)
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
13 * The running algorithm: -CJS-
15 * In the diagrams below, the player has just arrived in the
16 * grid marked as '@', and he has just come from a grid marked
17 * as 'o', and he is about to enter the grid marked as 'x'.
19 * Of course, if the "requested" move was impossible, then you
20 * will of course be blocked, and will stop.
22 * Overview: You keep moving until something interesting happens.
23 * If you are in an enclosed space, you follow corners. This is
24 * the usual corridor scheme. If you are in an open space, you go
25 * straight, but stop before entering enclosed space. This is
26 * analogous to reaching doorways. If you have enclosed space on
27 * one side only (that is, running along side a wall) stop if
28 * your wall opens out, or your open space closes in. Either case
29 * corresponds to a doorway.
31 * What happens depends on what you can really SEE. (i.e. if you
32 * have no light, then running along a dark corridor is JUST like
33 * running in a dark room.) The algorithm works equally well in
34 * corridors, rooms, mine tailings, earthquake rubble, etc, etc.
36 * These conditions are kept in static memory:
37 * find_openarea You are in the open on at least one
39 * find_breakleft You have a wall on the left, and will
41 * find_breakright You have a wall on the right, and will
44 * To initialize these conditions, we examine the grids adjacent
45 * to the grid marked 'x', two on each side (marked 'L' and 'R').
46 * If either one of the two grids on a given side is seen to be
47 * closed, then that side is considered to be closed. If both
48 * sides are closed, then it is an enclosed (corridor) run.
54 * Looking at more than just the immediate squares is
55 * significant. Consider the following case. A run along the
56 * corridor will stop just before entering the center point,
57 * because a choice is clearly established. Running in any of
58 * three available directions will be defined as a corridor run.
59 * Note that a minor hack is inserted to make the angled corridor
60 * entry (with one side blocked near and the other side blocked
61 * further away from the runner) work correctly. The runner moves
62 * diagonally, but then saves the previous direction as being
63 * straight into the gap. Otherwise, the tail end of the other
64 * entry would be perceived as an alternative on the next move.
72 * Likewise, a run along a wall, and then into a doorway (two
73 * runs) will work correctly. A single run rightwards from \@ will
74 * stop at 1. Another run right and down will enter the corridor
75 * and make the corner, stopping at the 2.
77 * \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
79 * \#\#\#\#\#\#\#\#\#\#\# \#\#\#\#\#\#
81 * \#\#\#\#\#\#\#\#\#\#\#\#\#
83 * After any move, the function area_affect is called to
84 * determine the new surroundings, and the direction of
85 * subsequent moves. It examines the current player location
86 * (at which the runner has just arrived) and the previous
87 * direction (from which the runner is considered to have come).
89 * Moving one square in some direction places you adjacent to
90 * three or five new squares (for straight and diagonal moves
91 * respectively) to which you were not previously adjacent,
92 * marked as '!' in the diagrams below.
95 * .o@@! (normal) .o.! (diagonal)
96 * ...! (east) ..@@! (south east)
99 * You STOP if any of the new squares are interesting in any way:
100 * for example, if they contain visible monsters or treasure.
102 * You STOP if any of the newly adjacent squares seem to be open,
103 * and you are also looking for a break on that side. (that is,
104 * find_openarea AND find_break).
106 * You STOP if any of the newly adjacent squares do NOT seem to be
107 * open and you are in an open area, and that side was previously
110 * Corners: If you are not in the open (i.e. you are in a corridor)
111 * and there is only one way to go in the new squares, then current_world_ptr->game_turn in
112 * that direction. If there are more than two new ways to go, STOP.
113 * If there are two ways to go, and those ways are separated by a
114 * square which does not seem to be open, then STOP.
116 * Otherwise, we have a potential corner. There are two new open
117 * squares, which are also adjacent. One of the new squares is
118 * diagonally located, the other is straight on (as in the diagram).
119 * We consider two more squares further out (marked below as ?).
121 * We assign "option" to the straight-on grid, and "option2" to the
122 * diagonal grid, and "check_dir" to the grid marked 's'.
128 * If they are both seen to be closed, then it is seen that no benefit
129 * is gained from moving straight. It is a known corner. To cut the
130 * corner, go diagonally, otherwise go straight, but pretend you
131 * stepped diagonally into that next location for a full view next
132 * time. Conversely, if one of the ? squares is not seen to be closed,
133 * then there is a potential choice. We check to see whether it is a
134 * potential corner or an intersection/room entrance. If the square
135 * two spaces straight ahead, and the space marked with 's' are both
136 * unknown space, then it is a potential corner and enter if
137 * find_examine is set, otherwise must stop because it is not a
138 * corner. (find_examine option is removed and always is TRUE.)
151 #include "artifact.h"
152 #include "player-move.h"
153 #include "player-status.h"
154 #include "player-effects.h"
155 #include "spells-floor.h"
159 #include "monster-spell.h"
160 #include "monster-status.h"
161 #include "object-hook.h"
162 #include "object-flavor.h"
164 #include "cmd-basic.h"
165 #include "view-mainwindow.h"
171 * @brief 地形やその上のアイテムの隠された要素を明かす /
172 * Search for hidden things
173 * @param y 対象となるマスのY座標
174 * @param x 対象となるマスのX座標
177 static void discover_hidden_things(POSITION y, POSITION x)
179 OBJECT_IDX this_o_idx, next_o_idx = 0;
181 g_ptr = ¤t_floor_ptr->grid_array[y][x];
184 if (g_ptr->mimic && is_trap(g_ptr->feat))
189 msg_print(_("トラップを発見した。", "You have found a trap."));
191 disturb(FALSE, TRUE);
195 if (is_hidden_door(g_ptr))
197 msg_print(_("隠しドアを発見した。", "You have found a secret door."));
202 disturb(FALSE, FALSE);
205 /* Scan all objects in the grid */
206 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
209 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
210 next_o_idx = o_ptr->next_o_idx;
212 /* Skip non-chests */
213 if (o_ptr->tval != TV_CHEST) continue;
215 /* Skip non-trapped chests */
216 if (!chest_traps[o_ptr->pval]) continue;
219 if (!object_is_known(o_ptr))
221 msg_print(_("箱に仕掛けられたトラップを発見した!", "You have discovered a trap on the chest!"));
227 disturb(FALSE, FALSE);
233 * @brief プレイヤーの探索処理判定
241 /* Start with base search ability */
242 chance = p_ptr->skill_srh;
244 /* Penalize various conditions */
245 if (p_ptr->blind || no_lite()) chance = chance / 10;
246 if (p_ptr->confused || p_ptr->image) chance = chance / 10;
248 /* Search the nearby grids, which are always in bounds */
249 for (i = 0; i < 9; ++ i)
251 /* Sometimes, notice things */
252 if (randint0(100) < chance)
254 discover_hidden_things(p_ptr->y + ddy_ddd[i], p_ptr->x + ddx_ddd[i]);
261 * @brief プレイヤーがオブジェクトを拾った際のメッセージ表示処理 /
262 * Helper routine for py_pickup() and py_pickup_floor().
263 * @param o_idx 取得したオブジェクトの参照ID
266 * アイテムを拾った際に「2つのケーキを持っている」\n
267 * "You have two cakes." とアイテムを拾った後の合計のみの表示がオリジナル\n
269 * あるという指摘をうけたので、「~を拾った、~を持っている」という表示\n
271 * Add the given dungeon object to the character's inventory.\n
272 * Delete the object afterwards.\n
274 void py_pickup_aux(OBJECT_IDX o_idx)
279 GAME_TEXT o_name[MAX_NLEN];
280 GAME_TEXT old_name[MAX_NLEN];
284 GAME_TEXT o_name[MAX_NLEN];
289 o_ptr = ¤t_floor_ptr->o_list[o_idx];
292 object_desc(old_name, o_ptr, OD_NAME_ONLY);
293 object_desc_kosuu(kazu_str, o_ptr);
294 hirottakazu = o_ptr->number;
296 /* Carry the object */
297 slot = inven_carry(o_ptr);
299 /* Get the object again */
300 o_ptr = &inventory[slot];
302 delete_object_idx(o_idx);
304 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
306 bool old_known = identify_item(o_ptr);
308 /* Auto-inscription/destroy */
309 autopick_alter_item(slot, (bool)(destroy_identify && !old_known));
311 /* If it is destroyed, don't pick it up */
312 if (o_ptr->marked & OM_AUTODESTROY) return;
315 object_desc(o_name, o_ptr, 0);
318 if ((o_ptr->name1 == ART_CRIMSON) && (p_ptr->pseikaku == SEIKAKU_COMBAT))
320 msg_format("こうして、%sは『クリムゾン』を手に入れた。", p_ptr->name);
321 msg_print("しかし今、『混沌のサーペント』の放ったモンスターが、");
322 msg_format("%sに襲いかかる...", p_ptr->name);
328 msg_format("%s(%c)を持っている。",o_name, index_to_label(slot));
332 if (o_ptr->number > hirottakazu) {
333 msg_format("%s拾って、%s(%c)を持っている。",
334 kazu_str, o_name, index_to_label(slot));
336 msg_format("%s(%c)を拾った。", o_name, index_to_label(slot));
340 strcpy(record_o_name, old_name);
342 msg_format("You have %s (%c).", o_name, index_to_label(slot));
343 strcpy(record_o_name, o_name);
345 record_turn = current_world_ptr->game_turn;
348 check_find_art_quest_completion(o_ptr);
353 * @brief プレイヤーがオブジェクト上に乗った際の表示処理
354 * @param pickup 自動拾い処理を行うならばTRUEとする
357 * Player "wants" to pick up an object or gold.
358 * Note that we ONLY handle things that can be picked up.
359 * See "move_player()" for handling of other things.
361 void carry(bool pickup)
363 grid_type *g_ptr = ¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
365 OBJECT_IDX this_o_idx, next_o_idx = 0;
367 GAME_TEXT o_name[MAX_NLEN];
369 /* Recenter the map around the player */
372 p_ptr->update |= (PU_MONSTERS);
373 p_ptr->redraw |= (PR_MAP);
374 p_ptr->window |= (PW_OVERHEAD);
377 /* Automatically pickup/destroy/inscribe items */
378 autopick_pickup_items(g_ptr);
382 py_pickup_floor(pickup);
386 /* Scan the pile of objects */
387 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
390 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
392 #ifdef ALLOW_EASY_SENSE /* TNB */
394 /* Option: Make item sensing easy */
397 /* Sense the object */
398 (void)sense_object(o_ptr);
401 #endif /* ALLOW_EASY_SENSE -- TNB */
403 object_desc(o_name, o_ptr, 0);
404 next_o_idx = o_ptr->next_o_idx;
406 disturb(FALSE, FALSE);
409 if (o_ptr->tval == TV_GOLD)
411 int value = (long)o_ptr->pval;
413 /* Delete the gold */
414 delete_object_idx(this_o_idx);
416 msg_format(_(" $%ld の価値がある%sを見つけた。", "You collect %ld gold pieces worth of %s."),
417 (long)value, o_name);
421 /* Collect the gold */
425 p_ptr->redraw |= (PR_GOLD);
426 p_ptr->window |= (PW_PLAYER);
429 /* Pick up objects */
432 /* Hack - some objects were handled in autopick_pickup_items(). */
433 if (o_ptr->marked & OM_NOMSG)
435 /* Clear the flag. */
436 o_ptr->marked &= ~OM_NOMSG;
440 msg_format(_("%sがある。", "You see %s."), o_name);
443 /* Note that the pack is too full */
444 else if (!inven_carry_okay(o_ptr))
446 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
449 /* Pick up the item (if requested and allowed) */
454 /* Hack -- query every item */
455 if (carry_query_flag)
457 char out_val[MAX_NLEN+20];
458 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
459 okay = get_check(out_val);
462 /* Attempt to pick up an object. */
465 /* Pick up the object */
466 py_pickup_aux(this_o_idx);
475 * @brief パターンによる移動制限処理
476 * @param c_y プレイヤーの移動元Y座標
477 * @param c_x プレイヤーの移動元X座標
478 * @param n_y プレイヤーの移動先Y座標
479 * @param n_x プレイヤーの移動先X座標
480 * @return 移動処理が可能である場合(可能な場合に選択した場合)TRUEを返す。
482 bool pattern_seq(POSITION c_y, POSITION c_x, POSITION n_y, POSITION n_x)
484 feature_type *cur_f_ptr = &f_info[current_floor_ptr->grid_array[c_y][c_x].feat];
485 feature_type *new_f_ptr = &f_info[current_floor_ptr->grid_array[n_y][n_x].feat];
486 bool is_pattern_tile_cur = have_flag(cur_f_ptr->flags, FF_PATTERN);
487 bool is_pattern_tile_new = have_flag(new_f_ptr->flags, FF_PATTERN);
488 int pattern_type_cur, pattern_type_new;
490 if (!is_pattern_tile_cur && !is_pattern_tile_new) return TRUE;
492 pattern_type_cur = is_pattern_tile_cur ? cur_f_ptr->subtype : NOT_PATTERN_TILE;
493 pattern_type_new = is_pattern_tile_new ? new_f_ptr->subtype : NOT_PATTERN_TILE;
495 if (pattern_type_new == PATTERN_TILE_START)
497 if (!is_pattern_tile_cur && !p_ptr->confused && !p_ptr->stun && !p_ptr->image)
499 if (get_check(_("パターンの上を歩き始めると、全てを歩かなければなりません。いいですか?",
500 "If you start walking the Pattern, you must walk the whole way. Ok? ")))
508 else if ((pattern_type_new == PATTERN_TILE_OLD) ||
509 (pattern_type_new == PATTERN_TILE_END) ||
510 (pattern_type_new == PATTERN_TILE_WRECKED))
512 if (is_pattern_tile_cur)
518 msg_print(_("パターンの上を歩くにはスタート地点から歩き始めなくてはなりません。",
519 "You must start walking the Pattern from the startpoint."));
524 else if ((pattern_type_new == PATTERN_TILE_TELEPORT) ||
525 (pattern_type_cur == PATTERN_TILE_TELEPORT))
529 else if (pattern_type_cur == PATTERN_TILE_START)
531 if (is_pattern_tile_new)
535 msg_print(_("パターンの上は正しい順序で歩かねばなりません。", "You must walk the Pattern in correct order."));
539 else if ((pattern_type_cur == PATTERN_TILE_OLD) ||
540 (pattern_type_cur == PATTERN_TILE_END) ||
541 (pattern_type_cur == PATTERN_TILE_WRECKED))
543 if (!is_pattern_tile_new)
545 msg_print(_("パターンを踏み外してはいけません。", "You may not step off from the Pattern."));
555 if (!is_pattern_tile_cur)
557 msg_print(_("パターンの上を歩くにはスタート地点から歩き始めなくてはなりません。",
558 "You must start walking the Pattern from the startpoint."));
564 byte ok_move = PATTERN_TILE_START;
565 switch (pattern_type_cur)
568 ok_move = PATTERN_TILE_2;
571 ok_move = PATTERN_TILE_3;
574 ok_move = PATTERN_TILE_4;
577 ok_move = PATTERN_TILE_1;
581 msg_format(_("おかしなパターン歩行、%d。", "Funny Pattern walking, %d."), pattern_type_cur);
583 return TRUE; /* Goof-up */
586 if ((pattern_type_new == ok_move) || (pattern_type_new == pattern_type_cur))
590 if (!is_pattern_tile_new)
591 msg_print(_("パターンを踏み外してはいけません。", "You may not step off from the Pattern."));
593 msg_print(_("パターンの上は正しい順序で歩かねばなりません。", "You must walk the Pattern in correct order."));
602 * @brief 移動に伴うプレイヤーのステータス変化処理
605 * @param mpe_mode 移動オプションフラグ
606 * @return プレイヤーが死亡やフロア離脱を行わず、実際に移動が可能ならばTRUEを返す。
608 bool move_player_effect(POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
610 POSITION oy = p_ptr->y;
611 POSITION ox = p_ptr->x;
612 grid_type *g_ptr = ¤t_floor_ptr->grid_array[ny][nx];
613 grid_type *oc_ptr = ¤t_floor_ptr->grid_array[oy][ox];
614 feature_type *f_ptr = &f_info[g_ptr->feat];
615 feature_type *of_ptr = &f_info[oc_ptr->feat];
617 if (!(mpe_mode & MPE_STAYING))
619 MONSTER_IDX om_idx = oc_ptr->m_idx;
620 MONSTER_IDX nm_idx = g_ptr->m_idx;
625 /* Hack -- For moving monster or riding player's moving */
626 if (!(mpe_mode & MPE_DONT_SWAP_MON))
628 /* Swap two monsters */
629 g_ptr->m_idx = om_idx;
630 oc_ptr->m_idx = nm_idx;
632 if (om_idx > 0) /* Monster on old spot (or p_ptr->riding) */
634 monster_type *om_ptr = ¤t_floor_ptr->m_list[om_idx];
637 update_monster(om_idx, TRUE);
640 if (nm_idx > 0) /* Monster on new spot */
642 monster_type *nm_ptr = ¤t_floor_ptr->m_list[nm_idx];
645 update_monster(nm_idx, TRUE);
652 /* Check for new panel (redraw map) */
655 if (mpe_mode & MPE_FORGET_FLOW)
659 p_ptr->update |= (PU_UN_VIEW);
660 p_ptr->redraw |= (PR_MAP);
663 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_DISTANCE);
664 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
666 /* Remove "unsafe" flag */
667 if ((!p_ptr->blind && !no_lite()) || !is_trap(g_ptr->feat)) g_ptr->info &= ~(CAVE_UNSAFE);
669 /* For get everything when requested hehe I'm *NASTY* */
670 if (current_floor_ptr->dun_level && (d_info[p_ptr->dungeon_idx].flags1 & DF1_FORGET)) wiz_dark();
671 if (mpe_mode & MPE_HANDLE_STUFF) handle_stuff();
673 if (p_ptr->pclass == CLASS_NINJA)
675 if (g_ptr->info & (CAVE_GLOW)) set_superstealth(FALSE);
676 else if (p_ptr->cur_lite <= 0) set_superstealth(TRUE);
679 if ((p_ptr->action == ACTION_HAYAGAKE) &&
680 (!have_flag(f_ptr->flags, FF_PROJECT) ||
681 (!p_ptr->levitation && have_flag(f_ptr->flags, FF_DEEP))))
683 msg_print(_("ここでは素早く動けない。", "You cannot run in here."));
684 set_action(ACTION_NONE);
686 if (p_ptr->prace == RACE_MERFOLK)
688 if(have_flag(f_ptr->flags, FF_WATER) ^ have_flag(of_ptr->flags, FF_WATER))
690 p_ptr->update |= PU_BONUS;
691 update_creature(p_ptr);
696 if (mpe_mode & MPE_ENERGY_USE)
698 if (music_singing(MUSIC_WALL))
700 (void)project(0, 0, p_ptr->y, p_ptr->x, (60 + p_ptr->lev), GF_DISINTEGRATE,
701 PROJECT_KILL | PROJECT_ITEM, -1);
703 if (!player_bold(ny, nx) || p_ptr->is_dead || p_ptr->leaving) return FALSE;
706 /* Spontaneous Searching */
707 if ((p_ptr->skill_fos >= 50) || (0 == randint0(50 - p_ptr->skill_fos)))
712 /* Continuous Searching */
713 if (p_ptr->action == ACTION_SEARCH)
719 /* Handle "objects" */
720 if (!(mpe_mode & MPE_DONT_PICKUP))
722 carry((mpe_mode & MPE_DO_PICKUP) ? TRUE : FALSE);
725 /* Handle "store doors" */
726 if (have_flag(f_ptr->flags, FF_STORE))
728 disturb(FALSE, TRUE);
731 /* Hack -- Enter store */
732 command_new = SPECIAL_KEY_STORE;
735 /* Handle "building doors" -KMW- */
736 else if (have_flag(f_ptr->flags, FF_BLDG))
738 disturb(FALSE, TRUE);
741 /* Hack -- Enter building */
742 command_new = SPECIAL_KEY_BUILDING;
745 /* Handle quest areas -KMW- */
746 else if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
748 disturb(FALSE, TRUE);
751 /* Hack -- Enter quest level */
752 command_new = SPECIAL_KEY_QUEST;
755 else if (have_flag(f_ptr->flags, FF_QUEST_EXIT))
757 if (quest[p_ptr->inside_quest].type == QUEST_TYPE_FIND_EXIT)
759 complete_quest(p_ptr->inside_quest);
764 p_ptr->inside_quest = g_ptr->special;
765 current_floor_ptr->dun_level = 0;
769 p_ptr->leaving = TRUE;
773 else if (have_flag(f_ptr->flags, FF_HIT_TRAP) && !(mpe_mode & MPE_STAYING))
775 disturb(FALSE, TRUE);
778 if (g_ptr->mimic || have_flag(f_ptr->flags, FF_SECRET))
780 msg_print(_("トラップだ!", "You found a trap!"));
783 disclose_grid(p_ptr->y, p_ptr->x);
787 hit_trap((mpe_mode & MPE_BREAK_TRAP) ? TRUE : FALSE);
789 if (!player_bold(ny, nx) || p_ptr->is_dead || p_ptr->leaving) return FALSE;
792 /* Warn when leaving trap detected region */
793 if (!(mpe_mode & MPE_STAYING) && (disturb_trap_detect || alert_trap_detect)
794 && p_ptr->dtrap && !(g_ptr->info & CAVE_IN_DETECT))
796 /* No duplicate warning */
797 p_ptr->dtrap = FALSE;
799 /* You are just on the edge */
800 if (!(g_ptr->info & CAVE_UNSAFE))
802 if (alert_trap_detect)
804 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
807 if (disturb_trap_detect) disturb(FALSE, TRUE);
811 return player_bold(ny, nx) && !p_ptr->is_dead && !p_ptr->leaving;
815 * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す
817 * @return トラップが自動的に無効ならばTRUEを返す
819 bool trap_can_be_ignored(FEAT_IDX feat)
821 feature_type *f_ptr = &f_info[feat];
823 if (!have_flag(f_ptr->flags, FF_TRAP)) return TRUE;
825 switch (f_ptr->subtype)
829 case TRAP_SPIKED_PIT:
830 case TRAP_POISON_PIT:
831 if (p_ptr->levitation) return TRUE;
834 if (p_ptr->anti_tele) return TRUE;
837 if (p_ptr->immune_fire) return TRUE;
840 if (p_ptr->immune_acid) return TRUE;
843 if (p_ptr->resist_blind) return TRUE;
846 if (p_ptr->resist_conf) return TRUE;
849 if (p_ptr->resist_pois) return TRUE;
852 if (p_ptr->free_act) return TRUE;
861 * Determine if a "boundary" grid is "floor mimic"
863 #define boundary_floor(C, F, MF) \
864 ((C)->mimic && permanent_wall(F) && \
865 (have_flag((MF)->flags, FF_MOVE) || have_flag((MF)->flags, FF_CAN_FLY)) && \
866 have_flag((MF)->flags, FF_PROJECT) && \
867 !have_flag((MF)->flags, FF_OPEN))
871 * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す /
872 * Move player in the given direction, with the given "pickup" flag.
874 * @param do_pickup 罠解除を試みながらの移動ならばTRUE
875 * @param break_trap トラップ粉砕処理を行うならばTRUE
876 * @return 実際に移動が行われたならばTRUEを返す。
878 * This routine should (probably) always induce energy expenditure.\n
880 * Note that moving will *always* take a current_world_ptr->game_turn, and will *always* hit\n
881 * any monster which might be in the destination grid. Previously,\n
882 * moving into walls was "free" and did NOT hit invisible monsters.\n
884 void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
886 /* Find the result of moving */
887 POSITION y = p_ptr->y + ddy[dir];
888 POSITION x = p_ptr->x + ddx[dir];
890 /* Examine the destination */
891 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
893 feature_type *f_ptr = &f_info[g_ptr->feat];
897 monster_type *riding_m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
898 monster_race *riding_r_ptr = &r_info[p_ptr->riding ? riding_m_ptr->r_idx : 0];
900 GAME_TEXT m_name[MAX_NLEN];
902 bool p_can_enter = player_can_enter(g_ptr->feat, CEM_P_CAN_ENTER_PATTERN);
903 bool p_can_kill_walls = FALSE;
904 bool stormbringer = FALSE;
906 bool oktomove = TRUE;
907 bool do_past = FALSE;
910 if (!current_floor_ptr->dun_level && !p_ptr->wild_mode &&
911 ((x == 0) || (x == MAX_WID - 1) ||
912 (y == 0) || (y == MAX_HGT - 1)))
914 /* Can the player enter the grid? */
915 if (g_ptr->mimic && player_can_enter(g_ptr->mimic, 0))
917 /* Hack: move to new area */
918 if ((y == 0) && (x == 0))
920 p_ptr->wilderness_y--;
921 p_ptr->wilderness_x--;
922 p_ptr->oldpy = current_floor_ptr->height - 2;
923 p_ptr->oldpx = current_floor_ptr->width - 2;
924 p_ptr->ambush_flag = FALSE;
927 else if ((y == 0) && (x == MAX_WID - 1))
929 p_ptr->wilderness_y--;
930 p_ptr->wilderness_x++;
931 p_ptr->oldpy = current_floor_ptr->height - 2;
933 p_ptr->ambush_flag = FALSE;
936 else if ((y == MAX_HGT - 1) && (x == 0))
938 p_ptr->wilderness_y++;
939 p_ptr->wilderness_x--;
941 p_ptr->oldpx = current_floor_ptr->width - 2;
942 p_ptr->ambush_flag = FALSE;
945 else if ((y == MAX_HGT - 1) && (x == MAX_WID - 1))
947 p_ptr->wilderness_y++;
948 p_ptr->wilderness_x++;
951 p_ptr->ambush_flag = FALSE;
956 p_ptr->wilderness_y--;
957 p_ptr->oldpy = current_floor_ptr->height - 2;
959 p_ptr->ambush_flag = FALSE;
962 else if (y == MAX_HGT - 1)
964 p_ptr->wilderness_y++;
967 p_ptr->ambush_flag = FALSE;
972 p_ptr->wilderness_x--;
973 p_ptr->oldpx = current_floor_ptr->width - 2;
975 p_ptr->ambush_flag = FALSE;
978 else if (x == MAX_WID - 1)
980 p_ptr->wilderness_x++;
983 p_ptr->ambush_flag = FALSE;
986 p_ptr->leaving = TRUE;
987 take_turn(p_ptr, 100);
992 /* "Blocked" message appears later */
993 /* oktomove = FALSE; */
997 m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
999 if (inventory[INVEN_RARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
1000 if (inventory[INVEN_LARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
1002 /* Player can not walk through "walls"... */
1003 /* unless in Shadow Form */
1004 p_can_kill_walls = p_ptr->kill_wall && have_flag(f_ptr->flags, FF_HURT_DISI) &&
1005 (!p_can_enter || !have_flag(f_ptr->flags, FF_LOS)) &&
1006 !have_flag(f_ptr->flags, FF_PERMANENT);
1008 /* Hack -- attack monsters */
1009 if (g_ptr->m_idx && (m_ptr->ml || p_can_enter || p_can_kill_walls))
1011 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1013 /* Attack -- only if we can see it OR it is not in a wall */
1014 if (!is_hostile(m_ptr) &&
1015 !(p_ptr->confused || p_ptr->image || !m_ptr->ml || p_ptr->stun ||
1016 ((p_ptr->muta2 & MUT2_BERS_RAGE) && p_ptr->shero)) &&
1017 pattern_seq(p_ptr->y, p_ptr->x, y, x) && (p_can_enter || p_can_kill_walls))
1019 /* Disturb the monster */
1020 (void)set_monster_csleep(g_ptr->m_idx, 0);
1022 /* Extract monster name (or "it") */
1023 monster_desc(m_name, m_ptr, 0);
1027 /* Auto-Recall if possible and visible */
1028 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
1030 /* Track a new monster */
1031 health_track(g_ptr->m_idx);
1035 if ((stormbringer && (randint1(1000) > 666)) || (p_ptr->pclass == CLASS_BERSERKER))
1040 else if (monster_can_cross_terrain(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].feat, r_ptr, 0))
1046 msg_format(_("%^sが邪魔だ!", "%^s is in your way!"), m_name);
1051 /* now continue on to 'movement' */
1060 if (oktomove && p_ptr->riding)
1062 if (riding_r_ptr->flags1 & RF1_NEVER_MOVE)
1064 msg_print(_("動けない!", "Can't move!"));
1067 disturb(FALSE, TRUE);
1069 else if (MON_MONFEAR(riding_m_ptr))
1071 GAME_TEXT steed_name[MAX_NLEN];
1072 monster_desc(steed_name, riding_m_ptr, 0);
1073 msg_format(_("%sが恐怖していて制御できない。", "%^s is too scared to control."), steed_name);
1075 disturb(FALSE, TRUE);
1077 else if (p_ptr->riding_ryoute)
1080 disturb(FALSE, TRUE);
1082 else if (have_flag(f_ptr->flags, FF_CAN_FLY) && (riding_r_ptr->flags7 & RF7_CAN_FLY))
1086 else if (have_flag(f_ptr->flags, FF_CAN_SWIM) && (riding_r_ptr->flags7 & RF7_CAN_SWIM))
1090 else if (have_flag(f_ptr->flags, FF_WATER) &&
1091 !(riding_r_ptr->flags7 & RF7_AQUATIC) &&
1092 (have_flag(f_ptr->flags, FF_DEEP) || (riding_r_ptr->flags2 & RF2_AURA_FIRE)))
1094 msg_format(_("%sの上に行けない。", "Can't swim."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1097 disturb(FALSE, TRUE);
1099 else if (!have_flag(f_ptr->flags, FF_WATER) && (riding_r_ptr->flags7 & RF7_AQUATIC))
1101 msg_format(_("%sから上がれない。", "Can't land."), f_name + f_info[get_feat_mimic(¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x])].name);
1104 disturb(FALSE, TRUE);
1106 else if (have_flag(f_ptr->flags, FF_LAVA) && !(riding_r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
1108 msg_format(_("%sの上に行けない。", "Too hot to go through."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1111 disturb(FALSE, TRUE);
1114 if (oktomove && MON_STUNNED(riding_m_ptr) && one_in_(2))
1116 GAME_TEXT steed_name[MAX_NLEN];
1117 monster_desc(steed_name, riding_m_ptr, 0);
1118 msg_format(_("%sが朦朧としていてうまく動けない!", "You cannot control stunned %s!"), steed_name);
1120 disturb(FALSE, TRUE);
1128 else if (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation)
1130 msg_format(_("空を飛ばないと%sの上には行けない。", "You need to fly to go through the %s."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1137 * Player can move through trees and
1138 * has effective -10 speed
1139 * Rangers can move without penality
1141 else if (have_flag(f_ptr->flags, FF_TREE) && !p_can_kill_walls)
1143 if ((p_ptr->pclass != CLASS_RANGER) && !p_ptr->levitation && (!p_ptr->riding || !(riding_r_ptr->flags8 & RF8_WILD_WOOD))) p_ptr->energy_use *= 2;
1147 /* Disarm a visible trap */
1148 else if ((do_pickup != easy_disarm) && have_flag(f_ptr->flags, FF_DISARM) && !g_ptr->mimic)
1150 if (!trap_can_be_ignored(g_ptr->feat))
1152 (void)do_cmd_disarm_aux(y, x, dir);
1158 /* Player can not walk through "walls" unless in wraith form...*/
1159 else if (!p_can_enter && !p_can_kill_walls)
1161 /* Feature code (applying "mimic" field) */
1162 FEAT_IDX feat = get_feat_mimic(g_ptr);
1163 feature_type *mimic_f_ptr = &f_info[feat];
1164 concptr name = f_name + mimic_f_ptr->name;
1168 /* Notice things in the dark */
1169 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
1171 /* Boundary floor mimic */
1172 if (boundary_floor(g_ptr, f_ptr, mimic_f_ptr))
1174 msg_print(_("それ以上先には進めないようだ。", "You feel you cannot go any more."));
1177 /* Wall (or secret door) */
1181 msg_format("%sが行く手をはばんでいるようだ。", name);
1183 msg_format("You feel %s %s blocking your way.",
1184 is_a_vowel(name[0]) ? "an" : "a", name);
1187 g_ptr->info |= (CAVE_MARK);
1195 /* Boundary floor mimic */
1196 if (boundary_floor(g_ptr, f_ptr, mimic_f_ptr))
1198 msg_print(_("それ以上先には進めない。", "You cannot go any more."));
1199 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
1203 /* Wall (or secret door) */
1207 if (easy_open && is_closed_door(feat) && easy_open_door(y, x)) return;
1210 msg_format("%sが行く手をはばんでいる。", name);
1212 msg_format("There is %s %s blocking your way.",
1213 is_a_vowel(name[0]) ? "an" : "a", name);
1217 * Well, it makes sense that you lose time bumping into
1218 * a wall _if_ you are confused, stunned or blind; but
1219 * typing mistakes should not cost you a current_world_ptr->game_turn...
1221 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
1226 disturb(FALSE, TRUE);
1228 if (!boundary_floor(g_ptr, f_ptr, mimic_f_ptr)) sound(SOUND_HITWALL);
1231 /* Normal movement */
1232 if (oktomove && !pattern_seq(p_ptr->y, p_ptr->x, y, x))
1234 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
1239 /* To avoid a loop with running */
1240 disturb(FALSE, TRUE);
1245 /* Normal movement */
1248 u32b mpe_mode = MPE_ENERGY_USE;
1252 if (!process_warning(x, y))
1254 p_ptr->energy_use = 25;
1261 msg_format(_("%sを押し退けた。", "You push past %s."), m_name);
1264 /* Change oldpx and oldpy to place the player well when going back to big mode */
1265 if (p_ptr->wild_mode)
1267 if (ddy[dir] > 0) p_ptr->oldpy = 1;
1268 if (ddy[dir] < 0) p_ptr->oldpy = MAX_HGT - 2;
1269 if (ddy[dir] == 0) p_ptr->oldpy = MAX_HGT / 2;
1270 if (ddx[dir] > 0) p_ptr->oldpx = 1;
1271 if (ddx[dir] < 0) p_ptr->oldpx = MAX_WID - 2;
1272 if (ddx[dir] == 0) p_ptr->oldpx = MAX_WID / 2;
1275 if (p_can_kill_walls)
1277 cave_alter_feat(y, x, FF_HURT_DISI);
1279 /* Update some things -- similar to GF_KILL_WALL */
1280 p_ptr->update |= (PU_FLOW);
1283 /* sound(SOUND_WALK); */
1285 if (do_pickup != always_pickup) mpe_mode |= MPE_DO_PICKUP;
1286 if (break_trap) mpe_mode |= MPE_BREAK_TRAP;
1288 (void)move_player_effect(y, x, mpe_mode);
1293 static bool ignore_avoid_run;
1296 * @brief ダッシュ移動処理中、移動先のマスが既知の壁かどうかを判定する /
1297 * Hack -- Check for a "known wall" (see below)
1298 * @param dir 想定する移動方向ID
1301 * @return 移動先が既知の壁ならばTRUE
1303 static bool see_wall(DIRECTION dir, POSITION y, POSITION x)
1307 /* Get the new location */
1311 /* Illegal grids are not known walls */
1312 if (!in_bounds2(y, x)) return (FALSE);
1315 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1317 /* Must be known to the player */
1318 if (g_ptr->info & (CAVE_MARK))
1320 /* Feature code (applying "mimic" field) */
1321 s16b feat = get_feat_mimic(g_ptr);
1322 feature_type *f_ptr = &f_info[feat];
1324 /* Wall grids are known walls */
1325 if (!player_can_enter(feat, 0)) return !have_flag(f_ptr->flags, FF_DOOR);
1327 /* Don't run on a tree unless explicitly requested */
1328 if (have_flag(f_ptr->flags, FF_AVOID_RUN) && !ignore_avoid_run)
1331 /* Don't run in a wall */
1332 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
1333 return !have_flag(f_ptr->flags, FF_DOOR);
1341 * @brief ダッシュ移動処理中、移動先のマスか未知の地形かどうかを判定する /
1342 * Hack -- Check for an "unknown corner" (see below)
1343 * @param dir 想定する移動方向ID
1346 * @return 移動先が未知の地形ならばTRUE
1348 static bool see_nothing(DIRECTION dir, POSITION y, POSITION x)
1350 /* Get the new location */
1354 /* Illegal grids are unknown */
1355 if (!in_bounds2(y, x)) return (TRUE);
1357 /* Memorized grids are always known */
1358 if (current_floor_ptr->grid_array[y][x].info & (CAVE_MARK)) return (FALSE);
1360 /* Viewable door/wall grids are known */
1361 if (player_can_see_bold(y, x)) return (FALSE);
1369 * Hack -- allow quick "cycling" through the legal directions
1371 static byte cycle[] = { 1, 2, 3, 6, 9, 8, 7, 4, 1, 2, 3, 6, 9, 8, 7, 4, 1 };
1374 * Hack -- map each direction into the "middle" of the "cycle[]" array
1376 static byte chome[] = { 0, 8, 9, 10, 7, 0, 11, 6, 5, 4 };
1379 * The direction we are running
1381 static DIRECTION find_current;
1384 * The direction we came from
1386 static DIRECTION find_prevdir;
1389 * We are looking for open area
1391 static bool find_openarea;
1394 * We are looking for a break
1396 static bool find_breakright;
1397 static bool find_breakleft;
1400 * @brief ダッシュ処理の導入 /
1401 * Initialize the running algorithm for a new direction.
1404 * Diagonal Corridor -- allow diaginal entry into corridors.\n
1406 * Blunt Corridor -- If there is a wall two spaces ahead and\n
1407 * we seem to be in a corridor, then force a current_world_ptr->game_turn into the side\n
1408 * corridor, must be moving straight into a corridor here. ???\n
1410 * Diagonal Corridor Blunt Corridor (?)\n
1415 static void run_init(DIRECTION dir)
1417 int row, col, deepleft, deepright;
1418 int i, shortleft, shortright;
1420 /* Save the direction */
1423 /* Assume running straight */
1426 /* Assume looking for open area */
1427 find_openarea = TRUE;
1429 /* Assume not looking for breaks */
1430 find_breakright = find_breakleft = FALSE;
1432 /* Assume no nearby walls */
1433 deepleft = deepright = FALSE;
1434 shortright = shortleft = FALSE;
1436 p_ptr->run_py = p_ptr->y;
1437 p_ptr->run_px = p_ptr->x;
1439 /* Find the destination grid */
1440 row = p_ptr->y + ddy[dir];
1441 col = p_ptr->x + ddx[dir];
1443 ignore_avoid_run = cave_have_flag_bold(row, col, FF_AVOID_RUN);
1445 /* Extract cycle index */
1448 /* Check for walls */
1449 if (see_wall(cycle[i+1], p_ptr->y, p_ptr->x))
1451 find_breakleft = TRUE;
1454 else if (see_wall(cycle[i+1], row, col))
1456 find_breakleft = TRUE;
1460 /* Check for walls */
1461 if (see_wall(cycle[i-1], p_ptr->y, p_ptr->x))
1463 find_breakright = TRUE;
1466 else if (see_wall(cycle[i-1], row, col))
1468 find_breakright = TRUE;
1472 /* Looking for a break */
1473 if (find_breakleft && find_breakright)
1475 /* Not looking for open area */
1476 find_openarea = FALSE;
1478 /* Hack -- allow angled corridor entry */
1481 if (deepleft && !deepright)
1483 find_prevdir = cycle[i - 1];
1485 else if (deepright && !deepleft)
1487 find_prevdir = cycle[i + 1];
1491 /* Hack -- allow blunt corridor entry */
1492 else if (see_wall(cycle[i], row, col))
1494 if (shortleft && !shortright)
1496 find_prevdir = cycle[i - 2];
1498 else if (shortright && !shortleft)
1500 find_prevdir = cycle[i + 2];
1508 * @brief ダッシュ移動が継続できるかどうかの判定 /
1509 * Update the current "run" path
1511 * ダッシュ移動が継続できるならばTRUEを返す。
1512 * Return TRUE if the running should be stopped
1514 static bool run_test(void)
1516 DIRECTION prev_dir, new_dir, check_dir = 0;
1519 int option = 0, option2 = 0;
1522 feature_type *f_ptr;
1524 /* Where we came from */
1525 prev_dir = find_prevdir;
1528 /* Range of newly adjacent grids */
1529 max = (prev_dir & 0x01) + 1;
1531 /* break run when leaving trap detected region */
1532 if ((disturb_trap_detect || alert_trap_detect)
1533 && p_ptr->dtrap && !(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_IN_DETECT))
1535 /* No duplicate warning */
1536 p_ptr->dtrap = FALSE;
1538 /* You are just on the edge */
1539 if (!(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_UNSAFE))
1541 if (alert_trap_detect)
1543 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
1546 if (disturb_trap_detect)
1554 /* Look at every newly adjacent square. */
1555 for (i = -max; i <= max; i++)
1557 OBJECT_IDX this_o_idx, next_o_idx = 0;
1560 new_dir = cycle[chome[prev_dir] + i];
1563 row = p_ptr->y + ddy[new_dir];
1564 col = p_ptr->x + ddx[new_dir];
1567 g_ptr = ¤t_floor_ptr->grid_array[row][col];
1569 /* Feature code (applying "mimic" field) */
1570 feat = get_feat_mimic(g_ptr);
1571 f_ptr = &f_info[feat];
1573 /* Visible monsters abort running */
1576 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
1578 /* Visible monster */
1579 if (m_ptr->ml) return (TRUE);
1582 /* Visible objects abort running */
1583 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1586 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1587 next_o_idx = o_ptr->next_o_idx;
1589 /* Visible object */
1590 if (o_ptr->marked & OM_FOUND) return (TRUE);
1593 /* Assume unknown */
1596 /* Check memorized grids */
1597 if (g_ptr->info & (CAVE_MARK))
1599 bool notice = have_flag(f_ptr->flags, FF_NOTICE);
1601 if (notice && have_flag(f_ptr->flags, FF_MOVE))
1604 if (find_ignore_doors && have_flag(f_ptr->flags, FF_DOOR) && have_flag(f_ptr->flags, FF_CLOSE))
1606 /* Option -- ignore */
1611 else if (find_ignore_stairs && have_flag(f_ptr->flags, FF_STAIRS))
1613 /* Option -- ignore */
1618 else if (have_flag(f_ptr->flags, FF_LAVA) && (p_ptr->immune_fire || IS_INVULN()))
1625 else if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP) &&
1626 (p_ptr->levitation || p_ptr->can_swim || (p_ptr->total_weight <= weight_limit())))
1633 /* Interesting feature */
1634 if (notice) return (TRUE);
1636 /* The grid is "visible" */
1640 /* Analyze unknown grids and floors considering mimic */
1641 if (inv || !see_wall(0, row, col))
1643 /* Looking for open area */
1649 /* The first new direction. */
1655 /* Three new directions. Stop running. */
1661 /* Two non-adjacent new directions. Stop running. */
1662 else if (option != cycle[chome[prev_dir] + i - 1])
1667 /* Two new (adjacent) directions (case 1) */
1668 else if (new_dir & 0x01)
1670 check_dir = cycle[chome[prev_dir] + i - 2];
1674 /* Two new (adjacent) directions (case 2) */
1677 check_dir = cycle[chome[prev_dir] + i + 1];
1683 /* Obstacle, while looking for open area */
1690 /* Break to the right */
1691 find_breakright = TRUE;
1696 /* Break to the left */
1697 find_breakleft = TRUE;
1703 /* Looking for open area */
1706 /* Hack -- look again */
1707 for (i = -max; i < 0; i++)
1709 /* Unknown grid or non-wall */
1710 if (!see_wall(cycle[chome[prev_dir] + i], p_ptr->y, p_ptr->x))
1712 /* Looking to break right */
1713 if (find_breakright)
1722 /* Looking to break left */
1730 /* Hack -- look again */
1731 for (i = max; i > 0; i--)
1733 /* Unknown grid or non-wall */
1734 if (!see_wall(cycle[chome[prev_dir] + i], p_ptr->y, p_ptr->x))
1736 /* Looking to break left */
1746 /* Looking to break right */
1747 if (find_breakright)
1755 /* Not looking for open area */
1767 /* Primary option */
1768 find_current = option;
1770 /* No other options */
1771 find_prevdir = option;
1774 /* Two options, examining corners */
1777 /* Primary option */
1778 find_current = option;
1780 /* Hack -- allow curving */
1781 find_prevdir = option2;
1784 /* Two options, pick one */
1787 /* Get next location */
1788 row = p_ptr->y + ddy[option];
1789 col = p_ptr->x + ddx[option];
1791 /* Don't see that it is closed off. */
1792 /* This could be a potential corner or an intersection. */
1793 if (!see_wall(option, row, col) ||
1794 !see_wall(check_dir, row, col))
1796 /* Can not see anything ahead and in the direction we */
1797 /* are turning, assume that it is a potential corner. */
1798 if (see_nothing(option, row, col) &&
1799 see_nothing(option2, row, col))
1801 find_current = option;
1802 find_prevdir = option2;
1805 /* STOP: we are next to an intersection or a room */
1812 /* This corner is seen to be enclosed; we cut the corner. */
1815 find_current = option2;
1816 find_prevdir = option2;
1819 /* This corner is seen to be enclosed, and we */
1820 /* deliberately go the long way. */
1823 find_current = option;
1824 find_prevdir = option2;
1829 /* About to hit a known wall, stop */
1830 if (see_wall(find_current, p_ptr->y, p_ptr->x))
1842 * @brief 継続的なダッシュ処理 /
1843 * Take one step along the current "run" path
1844 * @param dir 移動を試みる方向ID
1847 void run_step(DIRECTION dir)
1852 /* Ignore AVOID_RUN on a first step */
1853 ignore_avoid_run = TRUE;
1855 /* Hack -- do not start silly run */
1856 if (see_wall(dir, p_ptr->y, p_ptr->x))
1858 sound(SOUND_HITWALL);
1860 msg_print(_("その方向には走れません。", "You cannot run in that direction."));
1862 disturb(FALSE, FALSE);
1876 disturb(FALSE, FALSE);
1882 /* Decrease the run counter */
1883 if (--running <= 0) return;
1886 take_turn(p_ptr, 100);
1888 /* Move the player, using the "pickup" flag */
1889 move_player(find_current, FALSE, FALSE);
1891 if (player_bold(p_ptr->run_py, p_ptr->run_px))
1895 disturb(FALSE, FALSE);
1903 * @brief トラベル機能の判定処理 /
1904 * Test for traveling
1905 * @param prev_dir 前回移動を行った元の方角ID
1908 static DIRECTION travel_test(DIRECTION prev_dir)
1910 DIRECTION new_dir = 0;
1912 const grid_type *g_ptr;
1915 /* Cannot travel when blind */
1916 if (p_ptr->blind || no_lite())
1918 msg_print(_("目が見えない!", "You cannot see!"));
1922 /* break run when leaving trap detected region */
1923 if ((disturb_trap_detect || alert_trap_detect)
1924 && p_ptr->dtrap && !(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_IN_DETECT))
1926 /* No duplicate warning */
1927 p_ptr->dtrap = FALSE;
1929 /* You are just on the edge */
1930 if (!(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_UNSAFE))
1932 if (alert_trap_detect)
1934 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
1937 if (disturb_trap_detect)
1945 /* Range of newly adjacent grids */
1946 max = (prev_dir & 0x01) + 1;
1948 /* Look at every newly adjacent square. */
1949 for (i = -max; i <= max; i++)
1952 DIRECTION dir = cycle[chome[prev_dir] + i];
1955 POSITION row = p_ptr->y + ddy[dir];
1956 POSITION col = p_ptr->x + ddx[dir];
1959 g_ptr = ¤t_floor_ptr->grid_array[row][col];
1961 /* Visible monsters abort running */
1964 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
1966 /* Visible monster */
1967 if (m_ptr->ml) return (0);
1972 /* Travel cost of current grid */
1973 cost = travel.cost[p_ptr->y][p_ptr->x];
1975 /* Determine travel direction */
1976 for (i = 0; i < 8; ++ i) {
1977 int dir_cost = travel.cost[p_ptr->y+ddy_ddd[i]][p_ptr->x+ddx_ddd[i]];
1979 if (dir_cost < cost)
1986 if (!new_dir) return (0);
1988 /* Access newly move grid */
1989 g_ptr = ¤t_floor_ptr->grid_array[p_ptr->y+ddy[new_dir]][p_ptr->x+ddx[new_dir]];
1991 /* Close door abort traveling */
1992 if (!easy_open && is_closed_door(g_ptr->feat)) return (0);
1994 /* Visible and unignorable trap abort tarveling */
1995 if (!g_ptr->mimic && !trap_can_be_ignored(g_ptr->feat)) return (0);
2003 * @brief トラベル機能の実装 /
2007 void travel_step(void)
2009 /* Get travel direction */
2010 travel.dir = travel_test(travel.dir);
2014 if (travel.run == 255)
2016 msg_print(_("道筋が見つかりません!", "No route is found!"));
2017 travel.y = travel.x = 0;
2019 disturb(FALSE, TRUE);
2023 take_turn(p_ptr, 100);
2025 move_player(travel.dir, always_pickup, FALSE);
2027 if ((p_ptr->y == travel.y) && (p_ptr->x == travel.x))
2030 travel.y = travel.x = 0;
2032 else if (travel.run > 0)
2036 Term_xtra(TERM_XTRA_DELAY, delay_factor);
2043 * Hack: travel command
2045 #define TRAVEL_UNABLE 9999
2047 static int flow_head = 0;
2048 static int flow_tail = 0;
2049 static POSITION temp2_x[MAX_SHORT];
2050 static POSITION temp2_y[MAX_SHORT];
2053 * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information
2056 void forget_travel_flow(void)
2059 /* Check the entire dungeon / Forget the old data */
2060 for (y = 0; y < current_floor_ptr->height; y++)
2062 for (x = 0; x < current_floor_ptr->width; x++)
2065 travel.cost[y][x] = MAX_SHORT;
2068 travel.y = travel.x = 0;
2072 * @brief トラベル処理中に地形に応じた移動コスト基準を返す
2077 static int travel_flow_cost(POSITION y, POSITION x)
2079 feature_type *f_ptr = &f_info[current_floor_ptr->grid_array[y][x].feat];
2082 /* Avoid obstacles (ex. trees) */
2083 if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
2086 if (have_flag(f_ptr->flags, FF_WATER))
2088 if (have_flag(f_ptr->flags, FF_DEEP) && !p_ptr->levitation) cost += 5;
2092 if (have_flag(f_ptr->flags, FF_LAVA))
2095 if (!p_ptr->resist_fire) lava *= 2;
2096 if (!p_ptr->levitation) lava *= 2;
2097 if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
2102 /* Detected traps and doors */
2103 if (current_floor_ptr->grid_array[y][x].info & (CAVE_MARK))
2105 if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
2106 if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
2113 * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
2117 * @param wall プレイヤーが壁の中にいるならばTRUE
2120 static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
2122 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2123 feature_type *f_ptr = &f_info[g_ptr->feat];
2124 int old_head = flow_head;
2126 int base_cost = (n % TRAVEL_UNABLE);
2127 int from_wall = (n / TRAVEL_UNABLE);
2130 /* Ignore out of bounds */
2131 if (!in_bounds(y, x)) return;
2133 /* Ignore unknown grid except in wilderness */
2134 if (current_floor_ptr->dun_level > 0 && !(g_ptr->info & CAVE_KNOWN)) return;
2136 /* Ignore "walls" and "rubble" (include "secret doors") */
2137 if (have_flag(f_ptr->flags, FF_WALL) ||
2138 have_flag(f_ptr->flags, FF_CAN_DIG) ||
2139 (have_flag(f_ptr->flags, FF_DOOR) && current_floor_ptr->grid_array[y][x].mimic) ||
2140 (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
2142 if (!wall || !from_wall) return;
2143 add_cost += TRAVEL_UNABLE;
2147 add_cost = travel_flow_cost(y, x);
2150 cost = base_cost + add_cost;
2152 /* Ignore lower cost entries */
2153 if (travel.cost[y][x] <= cost) return;
2155 /* Save the flow cost */
2156 travel.cost[y][x] = cost;
2158 /* Enqueue that entry */
2159 temp2_y[flow_head] = y;
2160 temp2_x[flow_head] = x;
2162 /* Advance the queue */
2163 if (++flow_head == MAX_SHORT) flow_head = 0;
2165 /* Hack -- notice overflow by forgetting new entry */
2166 if (flow_head == flow_tail) flow_head = old_head;
2172 * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
2173 * @param ty 目標地点のY座標
2174 * @param tx 目標地点のX座標
2177 static void travel_flow(POSITION ty, POSITION tx)
2182 feature_type *f_ptr = &f_info[current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].feat];
2184 /* Reset the "queue" */
2185 flow_head = flow_tail = 0;
2187 /* is player in the wall? */
2188 if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
2190 /* Start at the target grid */
2191 travel_flow_aux(ty, tx, 0, wall);
2193 /* Now process the queue */
2194 while (flow_head != flow_tail)
2196 /* Extract the next entry */
2197 y = temp2_y[flow_tail];
2198 x = temp2_x[flow_tail];
2200 /* Forget that entry */
2201 if (++flow_tail == MAX_SHORT) flow_tail = 0;
2203 /* Ignore too far entries */
2204 //if (distance(ty, tx, y, x) > 100) continue;
2206 /* Add the "children" */
2207 for (d = 0; d < 8; d++)
2209 /* Add that child if "legal" */
2210 travel_flow_aux(y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
2214 /* Forget the flow info */
2215 flow_head = flow_tail = 0;
2219 * @brief トラベル処理のメインルーチン
2222 void do_cmd_travel(void)
2226 POSITION dx, dy, sx, sy;
2227 feature_type *f_ptr;
2229 if (travel.x != 0 && travel.y != 0 &&
2230 get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
2235 else if (!tgt_pt(&x, &y)) return;
2237 if ((x == p_ptr->x) && (y == p_ptr->y))
2239 msg_print(_("すでにそこにいます!", "You are already there!!"));
2243 f_ptr = &f_info[current_floor_ptr->grid_array[y][x].feat];
2245 if ((current_floor_ptr->grid_array[y][x].info & CAVE_MARK) &&
2246 (have_flag(f_ptr->flags, FF_WALL) ||
2247 have_flag(f_ptr->flags, FF_CAN_DIG) ||
2248 (have_flag(f_ptr->flags, FF_DOOR) && current_floor_ptr->grid_array[y][x].mimic)))
2250 msg_print(_("そこには行くことができません!", "You cannot travel there!"));
2254 forget_travel_flow();
2260 /* Travel till 255 steps */
2264 /* Decides first direction */
2265 dx = abs(p_ptr->x - x);
2266 dy = abs(p_ptr->y - y);
2267 sx = ((x == p_ptr->x) || (dx < dy)) ? 0 : ((x > p_ptr->x) ? 1 : -1);
2268 sy = ((y == p_ptr->y) || (dy < dx)) ? 0 : ((y > p_ptr->y) ? 1 : -1);
2270 for (i = 1; i <= 9; i++)
2272 if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
2278 * Something has happened to disturb the player.
2279 * The first arg indicates a major disturbance, which affects search.
2280 * The second arg is currently unused, but could induce output flush.
2281 * All disturbance cancels repeated commands, resting, and running.
2283 void disturb(bool stop_search, bool stop_travel)
2287 stop_travel = stop_travel;
2290 /* Cancel auto-commands */
2291 /* command_new = 0; */
2293 /* Cancel repeated commands */
2299 /* Redraw the state (later) */
2300 p_ptr->redraw |= (PR_STATE);
2303 /* Cancel Resting */
2304 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
2307 set_action(ACTION_NONE);
2310 /* Cancel running */
2316 /* Check for new panel if appropriate */
2317 if (center_player && !center_running) verify_panel();
2319 /* Calculate torch radius */
2320 p_ptr->update |= (PU_TORCH);
2322 /* Update monster flow */
2323 p_ptr->update |= (PU_FLOW);
2332 /* Check for new panel if appropriate */
2333 if (center_player && !center_running) verify_panel();
2335 /* Calculate torch radius */
2336 p_ptr->update |= (PU_TORCH);
2340 /* Flush the input if requested */
2341 if (flush_disturb) flush();