OSDN Git Service

[Refactor] #40413 Separated sound-of-music.c/h from util.c/h
[hengband/hengband.git] / src / player / player-move.c
1 /*!
2  *  @brief プレイヤーのコマンド処理1 / Movement commands (part 1)
3  *  @date 2014/01/02
4  *  @author
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6  *
7  * This software may be copied and distributed for educational, research,
8  * and not for profit purposes provided that this copyright and statement
9  * are included in all such copies.  Other copyrights may also apply.
10  * @note
11  * <pre>
12  * The running algorithm:                       -CJS-
13  *
14  * In the diagrams below, the player has just arrived in the
15  * grid marked as '@', and he has just come from a grid marked
16  * as 'o', and he is about to enter the grid marked as 'x'.
17  *
18  * Of course, if the "requested" move was impossible, then you
19  * will of course be blocked, and will stop.
20  *
21  * Overview: You keep moving until something interesting happens.
22  * If you are in an enclosed space, you follow corners. This is
23  * the usual corridor scheme. If you are in an open space, you go
24  * straight, but stop before entering enclosed space. This is
25  * analogous to reaching doorways. If you have enclosed space on
26  * one side only (that is, running along side a wall) stop if
27  * your wall opens out, or your open space closes in. Either case
28  * corresponds to a doorway.
29  *
30  * What happens depends on what you can really SEE. (i.e. if you
31  * have no light, then running along a dark corridor is JUST like
32  * running in a dark room.) The algorithm works equally well in
33  * corridors, rooms, mine tailings, earthquake rubble, etc, etc.
34  *
35  * These conditions are kept in static memory:
36  * find_openarea         You are in the open on at least one
37  * side.
38  * find_breakleft        You have a wall on the left, and will
39  * stop if it opens
40  * find_breakright       You have a wall on the right, and will
41  * stop if it opens
42  *
43  * To initialize these conditions, we examine the grids adjacent
44  * to the grid marked 'x', two on each side (marked 'L' and 'R').
45  * If either one of the two grids on a given side is seen to be
46  * closed, then that side is considered to be closed. If both
47  * sides are closed, then it is an enclosed (corridor) run.
48  *
49  * LL           L
50  * @@x          LxR
51  * RR          @@R
52  *
53  * Looking at more than just the immediate squares is
54  * significant. Consider the following case. A run along the
55  * corridor will stop just before entering the center point,
56  * because a choice is clearly established. Running in any of
57  * three available directions will be defined as a corridor run.
58  * Note that a minor hack is inserted to make the angled corridor
59  * entry (with one side blocked near and the other side blocked
60  * further away from the runner) work correctly. The runner moves
61  * diagonally, but then saves the previous direction as being
62  * straight into the gap. Otherwise, the tail end of the other
63  * entry would be perceived as an alternative on the next move.
64  *
65  * \#.\#
66  * \#\#.\#\#
67  * \.\@x..
68  * \#\#.\#\#
69  * \#.\#
70  *
71  * Likewise, a run along a wall, and then into a doorway (two
72  * runs) will work correctly. A single run rightwards from \@ will
73  * stop at 1. Another run right and down will enter the corridor
74  * and make the corner, stopping at the 2.
75  *
76  * \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
77  * o@@x       1
78  * \#\#\#\#\#\#\#\#\#\#\# \#\#\#\#\#\#
79  * \#2          \#
80  * \#\#\#\#\#\#\#\#\#\#\#\#\#
81  *
82  * After any move, the function area_affect is called to
83  * determine the new surroundings, and the direction of
84  * subsequent moves. It examines the current player location
85  * (at which the runner has just arrived) and the previous
86  * direction (from which the runner is considered to have come).
87  *
88  * Moving one square in some direction places you adjacent to
89  * three or five new squares (for straight and diagonal moves
90  * respectively) to which you were not previously adjacent,
91  * marked as '!' in the diagrams below.
92  *
93  *   ...!              ...
94  *   .o@@!  (normal)    .o.!  (diagonal)
95  *   ...!  (east)      ..@@!  (south east)
96  *                      !!!
97  *
98  * You STOP if any of the new squares are interesting in any way:
99  * for example, if they contain visible monsters or treasure.
100  *
101  * You STOP if any of the newly adjacent squares seem to be open,
102  * and you are also looking for a break on that side. (that is,
103  * find_openarea AND find_break).
104  *
105  * You STOP if any of the newly adjacent squares do NOT seem to be
106  * open and you are in an open area, and that side was previously
107  * entirely open.
108  *
109  * Corners: If you are not in the open (i.e. you are in a corridor)
110  * and there is only one way to go in the new squares, then turn in
111  * that direction. If there are more than two new ways to go, STOP.
112  * If there are two ways to go, and those ways are separated by a
113  * square which does not seem to be open, then STOP.
114  *
115  * Otherwise, we have a potential corner. There are two new open
116  * squares, which are also adjacent. One of the new squares is
117  * diagonally located, the other is straight on (as in the diagram).
118  * We consider two more squares further out (marked below as ?).
119  *
120  * We assign "option" to the straight-on grid, and "option2" to the
121  * diagonal grid, and "check_dir" to the grid marked 's'.
122  *
123  * \#\#s
124  * @@x?
125  * \#.?
126  *
127  * If they are both seen to be closed, then it is seen that no benefit
128  * is gained from moving straight. It is a known corner.  To cut the
129  * corner, go diagonally, otherwise go straight, but pretend you
130  * stepped diagonally into that next location for a full view next
131  * time. Conversely, if one of the ? squares is not seen to be closed,
132  * then there is a potential choice. We check to see whether it is a
133  * potential corner or an intersection/room entrance.  If the square
134  * two spaces straight ahead, and the space marked with 's' are both
135  * unknown space, then it is a potential corner and enter if
136  * find_examine is set, otherwise must stop because it is not a
137  * corner. (find_examine option is removed and always is TRUE.)
138  * </pre>
139  */
140
141 #include "player/player-move.h"
142 #include "art-definition/art-bow-types.h"
143 #include "art-definition/art-sword-types.h"
144 #include "autopick/autopick.h"
145 #include "cmd-action/cmd-attack.h"
146 #include "cmd/cmd-basic.h"
147 #include "core/special-internal-keys.h"
148 #include "core/stuff-handler.h"
149 #include "dungeon/dungeon.h"
150 #include "dungeon/quest.h"
151 #include "effect/effect-characteristics.h"
152 #include "floor/floor-object.h"
153 #include "game-option/auto-destruction-options.h"
154 #include "game-option/disturbance-options.h"
155 #include "game-option/input-options.h"
156 #include "game-option/map-screen-options.h"
157 #include "game-option/play-record-options.h"
158 #include "game-option/special-options.h"
159 #include "game-option/text-display-options.h"
160 #include "grid/feature.h"
161 #include "grid/grid.h"
162 #include "grid/trap.h"
163 #include "inventory/inventory-object.h"
164 #include "inventory/player-inventory.h"
165 #include "io/targeting.h"
166 #include "main/sound-definitions-table.h"
167 #include "main/sound-of-music.h"
168 #include "monster-race/race-flags-resistance.h"
169 #include "monster-race/race-flags1.h"
170 #include "monster-race/race-flags2.h"
171 #include "monster-race/race-flags7.h"
172 #include "monster-race/race-flags8.h"
173 #include "monster/monster-describer.h"
174 #include "monster/monster-info.h"
175 #include "monster/monster-status.h"
176 #include "monster/monster-update.h"
177 #include "mspell/monster-spell.h"
178 #include "object-enchant/special-object-flags.h"
179 #include "object/object-flavor.h"
180 #include "object/object-hook.h"
181 #include "object/object-mark-types.h"
182 #include "object/object-info.h"
183 #include "object/warning.h"
184 #include "perception/object-perception.h"
185 #include "player/player-class.h"
186 #include "player/player-effects.h"
187 #include "player/player-personalities-types.h"
188 #include "player/player-race-types.h"
189 #include "player/player-status.h"
190 #include "realm/realm-song-numbers.h"
191 #include "spell-kind/spells-floor.h"
192 #include "spell/process-effect.h"
193 #include "spell/spell-types.h"
194 #include "spell/spells3.h"
195 #include "view/display-main-window.h"
196 #include "world/world.h"
197
198 travel_type travel;
199
200 /*!
201  * @brief 地形やその上のアイテムの隠された要素を全て明かす /
202  * Search for hidden things
203  * @param creature_ptr プレーヤーへの参照ポインタ
204  * @param y 対象となるマスのY座標
205  * @param x 対象となるマスのX座標
206  * @return なし
207  */
208 static void discover_hidden_things(player_type *creature_ptr, POSITION y, POSITION x)
209 {
210         grid_type *g_ptr;
211         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
212         g_ptr = &floor_ptr->grid_array[y][x];
213
214         if (g_ptr->mimic && is_trap(creature_ptr, g_ptr->feat))
215         {
216                 disclose_grid(creature_ptr, y, x);
217                 msg_print(_("トラップを発見した。", "You have found a trap."));
218                 disturb(creature_ptr, FALSE, TRUE);
219         }
220
221         if (is_hidden_door(creature_ptr, g_ptr))
222         {
223                 msg_print(_("隠しドアを発見した。", "You have found a secret door."));
224                 disclose_grid(creature_ptr, y, x);
225                 disturb(creature_ptr, FALSE, FALSE);
226         }
227
228         /* Scan all objects in the grid */
229         OBJECT_IDX next_o_idx = 0;
230         for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
231         {
232                 object_type *o_ptr;
233                 o_ptr = &floor_ptr->o_list[this_o_idx];
234                 next_o_idx = o_ptr->next_o_idx;
235                 if (o_ptr->tval != TV_CHEST) continue;
236                 if (!chest_traps[o_ptr->pval]) continue;
237                 if (!object_is_known(o_ptr))
238                 {
239                         msg_print(_("箱に仕掛けられたトラップを発見した!", "You have discovered a trap on the chest!"));
240                         object_known(o_ptr);
241                         disturb(creature_ptr, FALSE, FALSE);
242                 }
243         }
244 }
245
246
247 /*!
248  * @brief プレイヤーの探索処理判定
249  * @param creature_ptr プレーヤーへの参照ポインタ
250  * @return なし
251  */
252 void search(player_type *creature_ptr)
253 {
254         /* Start with base search ability */
255         PERCENTAGE chance = creature_ptr->skill_srh;
256
257         /* Penalize various conditions */
258         if (creature_ptr->blind || no_lite(creature_ptr)) chance = chance / 10;
259         if (creature_ptr->confused || creature_ptr->image) chance = chance / 10;
260
261         /* Search the nearby grids, which are always in bounds */
262         for (DIRECTION i = 0; i < 9; ++ i)
263         {
264                 /* Sometimes, notice things */
265                 if (randint0(100) < chance)
266                 {
267                         discover_hidden_things(creature_ptr, creature_ptr->y + ddy_ddd[i], creature_ptr->x + ddx_ddd[i]);
268                 }
269         }
270 }
271
272
273 /*!
274  * @brief プレイヤーがオブジェクトを拾った際のメッセージ表示処理 /
275  * Helper routine for py_pickup() and py_pickup_floor().
276  * @param creature_ptr プレーヤーへの参照ポインタ
277  * @param o_idx 取得したオブジェクトの参照ID
278  * @return なし
279  * @details
280  * アイテムを拾った際に「2つのケーキを持っている」\n
281  * "You have two cakes." とアイテムを拾った後の合計のみの表示がオリジナル\n
282  * だが、違和感が\n
283  * あるという指摘をうけたので、「~を拾った、~を持っている」という表示\n
284  * にかえてある。そのための配列。\n
285  * Add the given dungeon object to the character's inventory.\n
286  * Delete the object afterwards.\n
287  */
288 void py_pickup_aux(player_type *owner_ptr, OBJECT_IDX o_idx)
289 {
290 #ifdef JP
291         GAME_TEXT o_name[MAX_NLEN];
292         GAME_TEXT old_name[MAX_NLEN];
293         char kazu_str[80];
294         int hirottakazu;
295 #else
296         GAME_TEXT o_name[MAX_NLEN];
297 #endif
298
299         object_type *o_ptr;
300         o_ptr = &owner_ptr->current_floor_ptr->o_list[o_idx];
301
302 #ifdef JP
303         object_desc(owner_ptr, old_name, o_ptr, OD_NAME_ONLY);
304         object_desc_kosuu(kazu_str, o_ptr);
305         hirottakazu = o_ptr->number;
306 #endif
307
308         /* Carry the object */
309         INVENTORY_IDX slot = store_item_to_inventory(owner_ptr, o_ptr);
310
311         /* Get the object again */
312         o_ptr = &owner_ptr->inventory_list[slot];
313
314         delete_object_idx(owner_ptr, o_idx);
315
316         if (owner_ptr->pseikaku == PERSONALITY_MUNCHKIN)
317         {
318                 bool old_known = identify_item(owner_ptr, o_ptr);
319
320                 /* Auto-inscription/destroy */
321                 autopick_alter_item(owner_ptr, slot, (bool)(destroy_identify && !old_known));
322
323                 /* If it is destroyed, don't pick it up */
324                 if (o_ptr->marked & OM_AUTODESTROY) return;
325         }
326
327         object_desc(owner_ptr, o_name, o_ptr, 0);
328
329 #ifdef JP
330         if ((o_ptr->name1 == ART_CRIMSON) && (owner_ptr->pseikaku == PERSONALITY_COMBAT))
331         {
332                 msg_format("こうして、%sは『クリムゾン』を手に入れた。", owner_ptr->name);
333                 msg_print("しかし今、『混沌のサーペント』の放ったモンスターが、");
334                 msg_format("%sに襲いかかる...", owner_ptr->name);
335         }
336         else
337         {
338                 if (plain_pickup)
339                 {
340                         msg_format("%s(%c)を持っている。",o_name, index_to_label(slot));
341                 }
342                 else
343                 {
344                         if (o_ptr->number > hirottakazu) {
345                             msg_format("%s拾って、%s(%c)を持っている。",
346                                kazu_str, o_name, index_to_label(slot));
347                         } else {
348                                 msg_format("%s(%c)を拾った。", o_name, index_to_label(slot));
349                         }
350                 }
351         }
352
353         strcpy(record_o_name, old_name);
354 #else
355         msg_format("You have %s (%c).", o_name, index_to_label(slot));
356         strcpy(record_o_name, o_name);
357 #endif
358         record_turn = current_world_ptr->game_turn;
359         check_find_art_quest_completion(owner_ptr, o_ptr);
360 }
361
362
363 /*!
364  * @brief プレイヤーがオブジェクト上に乗った際の表示処理
365  * @param creature_ptr プレーヤーへの参照ポインタ
366  * @param pickup 自動拾い処理を行うならばTRUEとする
367  * @return なし
368  * @details
369  * Player "wants" to pick up an object or gold.
370  * Note that we ONLY handle things that can be picked up.
371  * See "move_player(creature_ptr, )" for handling of other things.
372  */
373 void carry(player_type *creature_ptr, bool pickup)
374 {
375         /* Recenter the map around the player */
376         verify_panel(creature_ptr);
377
378         creature_ptr->update |= (PU_MONSTERS);
379         creature_ptr->redraw |= (PR_MAP);
380         creature_ptr->window |= (PW_OVERHEAD);
381         handle_stuff(creature_ptr);
382
383         /* Automatically pickup/destroy/inscribe items */
384         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
385         autopick_pickup_items(creature_ptr, g_ptr);
386
387         if (easy_floor)
388         {
389                 py_pickup_floor(creature_ptr, pickup);
390                 return;
391         }
392
393         /* Scan the pile of objects */
394         OBJECT_IDX next_o_idx = 0;
395         for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
396         {
397                 object_type *o_ptr;
398                 o_ptr = &creature_ptr->current_floor_ptr->o_list[this_o_idx];
399                 GAME_TEXT o_name[MAX_NLEN];
400                 object_desc(creature_ptr, o_name, o_ptr, 0);
401                 next_o_idx = o_ptr->next_o_idx;
402
403                 disturb(creature_ptr, FALSE, FALSE);
404
405                 if (o_ptr->tval == TV_GOLD)
406                 {
407                         int value = (long)o_ptr->pval;
408                         delete_object_idx(creature_ptr, this_o_idx);
409                         msg_format(_(" $%ld の価値がある%sを見つけた。", "You collect %ld gold pieces worth of %s."),
410                            (long)value, o_name);
411
412                         sound(SOUND_SELL);
413
414                         creature_ptr->au += value;
415                         creature_ptr->redraw |= (PR_GOLD);
416                         creature_ptr->window |= (PW_PLAYER);
417                         continue;
418                 }
419
420                 /* Hack - some objects were handled in autopick_pickup_items(). */
421                 if (o_ptr->marked & OM_NOMSG)
422                 {
423                         o_ptr->marked &= ~OM_NOMSG;
424                         continue;
425                 }
426                 
427                 if (!pickup)
428                 {
429                         msg_format(_("%sがある。", "You see %s."), o_name);
430                         continue;
431                 }
432                 
433                 if (!check_store_item_to_inventory(o_ptr))
434                 {
435                         msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
436                         continue;
437                 }
438
439                 int is_pickup_successful = TRUE;
440                 if (carry_query_flag)
441                 {
442                         char out_val[MAX_NLEN + 20];
443                         sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
444                         is_pickup_successful = get_check(out_val);
445                 }
446
447                 if (is_pickup_successful)
448                 {
449                         py_pickup_aux(creature_ptr, this_o_idx);
450                 }
451         }
452 }
453
454
455 /*!
456  * @brief パターンによる移動制限処理
457  * @param creature_ptr プレーヤーへの参照ポインタ
458  * @param c_y プレイヤーの移動元Y座標
459  * @param c_x プレイヤーの移動元X座標
460  * @param n_y プレイヤーの移動先Y座標
461  * @param n_x プレイヤーの移動先X座標
462  * @return 移動処理が可能である場合(可能な場合に選択した場合)TRUEを返す。
463  */
464 bool pattern_seq(player_type *creature_ptr, POSITION c_y, POSITION c_x, POSITION n_y, POSITION n_x)
465 {
466         feature_type *cur_f_ptr = &f_info[creature_ptr->current_floor_ptr->grid_array[c_y][c_x].feat];
467         feature_type *new_f_ptr = &f_info[creature_ptr->current_floor_ptr->grid_array[n_y][n_x].feat];
468         bool is_pattern_tile_cur = have_flag(cur_f_ptr->flags, FF_PATTERN);
469         bool is_pattern_tile_new = have_flag(new_f_ptr->flags, FF_PATTERN);
470
471         if (!is_pattern_tile_cur && !is_pattern_tile_new) return TRUE;
472
473         int pattern_type_cur = is_pattern_tile_cur ? cur_f_ptr->subtype : NOT_PATTERN_TILE;
474         int pattern_type_new = is_pattern_tile_new ? new_f_ptr->subtype : NOT_PATTERN_TILE;
475
476         if (pattern_type_new == PATTERN_TILE_START)
477         {
478                 if (!is_pattern_tile_cur && !creature_ptr->confused && !creature_ptr->stun && !creature_ptr->image)
479                 {
480                         if (get_check(_("パターンの上を歩き始めると、全てを歩かなければなりません。いいですか?", 
481                                                         "If you start walking the Pattern, you must walk the whole way. Ok? ")))
482                                 return TRUE;
483                         else
484                                 return FALSE;
485                 }
486                 else
487                         return TRUE;
488         }
489         
490         if ((pattern_type_new == PATTERN_TILE_OLD) ||
491                  (pattern_type_new == PATTERN_TILE_END) ||
492                  (pattern_type_new == PATTERN_TILE_WRECKED))
493         {
494                 if (is_pattern_tile_cur)
495                 {
496                         return TRUE;
497                 }
498                 else
499                 {
500                         msg_print(_("パターンの上を歩くにはスタート地点から歩き始めなくてはなりません。",
501                                                 "You must start walking the Pattern from the startpoint."));
502
503                         return FALSE;
504                 }
505         }
506         
507         if ((pattern_type_new == PATTERN_TILE_TELEPORT) ||
508                  (pattern_type_cur == PATTERN_TILE_TELEPORT))
509         {
510                 return TRUE;
511         }
512         
513         if (pattern_type_cur == PATTERN_TILE_START)
514         {
515                 if (is_pattern_tile_new)
516                         return TRUE;
517                 else
518                 {
519                         msg_print(_("パターンの上は正しい順序で歩かねばなりません。", "You must walk the Pattern in correct order."));
520                         return FALSE;
521                 }
522         }
523         
524         if ((pattern_type_cur == PATTERN_TILE_OLD) ||
525                  (pattern_type_cur == PATTERN_TILE_END) ||
526                  (pattern_type_cur == PATTERN_TILE_WRECKED))
527         {
528                 if (!is_pattern_tile_new)
529                 {
530                         msg_print(_("パターンを踏み外してはいけません。", "You may not step off from the Pattern."));
531                         return FALSE;
532                 }
533                 else
534                 {
535                         return TRUE;
536                 }
537         }
538         
539         if (!is_pattern_tile_cur)
540         {
541                 msg_print(_("パターンの上を歩くにはスタート地点から歩き始めなくてはなりません。",
542                         "You must start walking the Pattern from the startpoint."));
543
544                 return FALSE;
545         }
546         
547         byte ok_move = PATTERN_TILE_START;
548         switch (pattern_type_cur)
549         {
550         case PATTERN_TILE_1:
551                 ok_move = PATTERN_TILE_2;
552                 break;
553         case PATTERN_TILE_2:
554                 ok_move = PATTERN_TILE_3;
555                 break;
556         case PATTERN_TILE_3:
557                 ok_move = PATTERN_TILE_4;
558                 break;
559         case PATTERN_TILE_4:
560                 ok_move = PATTERN_TILE_1;
561                 break;
562         default:
563                 if (current_world_ptr->wizard)
564                         msg_format(_("おかしなパターン歩行、%d。", "Funny Pattern walking, %d."), pattern_type_cur);
565                 return TRUE;
566         }
567
568         if ((pattern_type_new == ok_move) || (pattern_type_new == pattern_type_cur)) return TRUE;
569         
570         if (!is_pattern_tile_new)
571                 msg_print(_("パターンを踏み外してはいけません。", "You may not step off from the Pattern."));
572         else
573                 msg_print(_("パターンの上は正しい順序で歩かねばなりません。", "You must walk the Pattern in correct order."));
574
575         return FALSE;
576 }
577
578
579 /*!
580  * @brief 移動に伴うプレイヤーのステータス変化処理
581  * @param creature_ptr プレーヤーへの参照ポインタ
582  * @param ny 移動先Y座標
583  * @param nx 移動先X座標
584  * @param mpe_mode 移動オプションフラグ
585  * @return プレイヤーが死亡やフロア離脱を行わず、実際に移動が可能ならばTRUEを返す。
586  */
587 bool move_player_effect(player_type *creature_ptr, POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
588 {
589         POSITION oy = creature_ptr->y;
590         POSITION ox = creature_ptr->x;
591         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
592         grid_type *g_ptr = &floor_ptr->grid_array[ny][nx];
593         grid_type *oc_ptr = &floor_ptr->grid_array[oy][ox];
594         feature_type *f_ptr = &f_info[g_ptr->feat];
595         feature_type *of_ptr = &f_info[oc_ptr->feat];
596
597         if (!(mpe_mode & MPE_STAYING))
598         {
599                 MONSTER_IDX om_idx = oc_ptr->m_idx;
600                 MONSTER_IDX nm_idx = g_ptr->m_idx;
601
602                 creature_ptr->y = ny;
603                 creature_ptr->x = nx;
604
605                 /* Hack -- For moving monster or riding player's moving */
606                 if (!(mpe_mode & MPE_DONT_SWAP_MON))
607                 {
608                         /* Swap two monsters */
609                         g_ptr->m_idx = om_idx;
610                         oc_ptr->m_idx = nm_idx;
611
612                         if (om_idx > 0) /* Monster on old spot (or creature_ptr->riding) */
613                         {
614                                 monster_type *om_ptr = &floor_ptr->m_list[om_idx];
615                                 om_ptr->fy = ny;
616                                 om_ptr->fx = nx;
617                                 update_monster(creature_ptr, om_idx, TRUE);
618                         }
619
620                         if (nm_idx > 0) /* Monster on new spot */
621                         {
622                                 monster_type *nm_ptr = &floor_ptr->m_list[nm_idx];
623                                 nm_ptr->fy = oy;
624                                 nm_ptr->fx = ox;
625                                 update_monster(creature_ptr, nm_idx, TRUE);
626                         }
627                 }
628
629                 lite_spot(creature_ptr, oy, ox);
630                 lite_spot(creature_ptr, ny, nx);
631
632                 /* Check for new panel (redraw map) */
633                 verify_panel(creature_ptr);
634
635                 if (mpe_mode & MPE_FORGET_FLOW)
636                 {
637                         forget_flow(floor_ptr);
638
639                         creature_ptr->update |= (PU_UN_VIEW);
640                         creature_ptr->redraw |= (PR_MAP);
641                 }
642
643                 creature_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_DISTANCE);
644                 creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
645
646                 /* Remove "unsafe" flag */
647                 if ((!creature_ptr->blind && !no_lite(creature_ptr)) || !is_trap(creature_ptr, g_ptr->feat)) g_ptr->info &= ~(CAVE_UNSAFE);
648
649                 /* For get everything when requested hehe I'm *NASTY* */
650                 if (floor_ptr->dun_level && (d_info[creature_ptr->dungeon_idx].flags1 & DF1_FORGET)) wiz_dark(creature_ptr);
651                 if (mpe_mode & MPE_HANDLE_STUFF) handle_stuff(creature_ptr);
652
653                 if (creature_ptr->pclass == CLASS_NINJA)
654                 {
655                         if (g_ptr->info & (CAVE_GLOW)) set_superstealth(creature_ptr, FALSE);
656                         else if (creature_ptr->cur_lite <= 0) set_superstealth(creature_ptr, TRUE);
657                 }
658
659                 if ((creature_ptr->action == ACTION_HAYAGAKE) &&
660                     (!have_flag(f_ptr->flags, FF_PROJECT) ||
661                      (!creature_ptr->levitation && have_flag(f_ptr->flags, FF_DEEP))))
662                 {
663                         msg_print(_("ここでは素早く動けない。", "You cannot run in here."));
664                         set_action(creature_ptr, ACTION_NONE);
665                 }
666                 if (creature_ptr->prace == RACE_MERFOLK)
667                 {
668                         if(have_flag(f_ptr->flags, FF_WATER) ^ have_flag(of_ptr->flags, FF_WATER))
669                         {
670                                 creature_ptr->update |= PU_BONUS;
671                                 update_creature(creature_ptr);
672                         }
673                 }
674         }
675
676         if (mpe_mode & MPE_ENERGY_USE)
677         {
678                 if (music_singing(creature_ptr, MUSIC_WALL))
679                 {
680                         (void)project(creature_ptr, 0, 0, creature_ptr->y, creature_ptr->x, (60 + creature_ptr->lev), GF_DISINTEGRATE,
681                                 PROJECT_KILL | PROJECT_ITEM, -1);
682
683                         if (!player_bold(creature_ptr, ny, nx) || creature_ptr->is_dead || creature_ptr->leaving) return FALSE;
684                 }
685
686                 /* Spontaneous Searching */
687                 if ((creature_ptr->skill_fos >= 50) || (0 == randint0(50 - creature_ptr->skill_fos)))
688                 {
689                         search(creature_ptr);
690                 }
691
692                 /* Continuous Searching */
693                 if (creature_ptr->action == ACTION_SEARCH)
694                 {
695                         search(creature_ptr);
696                 }
697         }
698
699         /* Handle "objects" */
700         if (!(mpe_mode & MPE_DONT_PICKUP))
701         {
702                 carry(creature_ptr, (mpe_mode & MPE_DO_PICKUP) ? TRUE : FALSE);
703         }
704
705         /* Handle "store doors" */
706         if (have_flag(f_ptr->flags, FF_STORE))
707         {
708                 disturb(creature_ptr, FALSE, TRUE);
709
710                 free_turn(creature_ptr);
711                 /* Hack -- Enter store */
712                 command_new = SPECIAL_KEY_STORE;
713         }
714
715         /* Handle "building doors" -KMW- */
716         else if (have_flag(f_ptr->flags, FF_BLDG))
717         {
718                 disturb(creature_ptr, FALSE, TRUE);
719
720                 free_turn(creature_ptr);
721                 /* Hack -- Enter building */
722                 command_new = SPECIAL_KEY_BUILDING;
723         }
724
725         /* Handle quest areas -KMW- */
726         else if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
727         {
728                 disturb(creature_ptr, FALSE, TRUE);
729
730                 free_turn(creature_ptr);
731                 /* Hack -- Enter quest level */
732                 command_new = SPECIAL_KEY_QUEST;
733         }
734
735         else if (have_flag(f_ptr->flags, FF_QUEST_EXIT))
736         {
737                 if (quest[floor_ptr->inside_quest].type == QUEST_TYPE_FIND_EXIT)
738                 {
739                         complete_quest(creature_ptr, floor_ptr->inside_quest);
740                 }
741
742                 leave_quest_check(creature_ptr);
743
744                 floor_ptr->inside_quest = g_ptr->special;
745                 floor_ptr->dun_level = 0;
746                 creature_ptr->oldpx = 0;
747                 creature_ptr->oldpy = 0;
748
749                 creature_ptr->leaving = TRUE;
750         }
751
752         /* Set off a trap */
753         else if (have_flag(f_ptr->flags, FF_HIT_TRAP) && !(mpe_mode & MPE_STAYING))
754         {
755                 disturb(creature_ptr, FALSE, TRUE);
756
757                 /* Hidden trap */
758                 if (g_ptr->mimic || have_flag(f_ptr->flags, FF_SECRET))
759                 {
760                         msg_print(_("トラップだ!", "You found a trap!"));
761
762                         /* Pick a trap */
763                         disclose_grid(creature_ptr, creature_ptr->y, creature_ptr->x);
764                 }
765
766                 /* Hit the trap */
767                 hit_trap(creature_ptr, (mpe_mode & MPE_BREAK_TRAP) ? TRUE : FALSE);
768
769                 if (!player_bold(creature_ptr, ny, nx) || creature_ptr->is_dead || creature_ptr->leaving) return FALSE;
770         }
771
772         /* Warn when leaving trap detected region */
773         if (!(mpe_mode & MPE_STAYING) && (disturb_trap_detect || alert_trap_detect)
774             && creature_ptr->dtrap && !(g_ptr->info & CAVE_IN_DETECT))
775         {
776                 /* No duplicate warning */
777                 creature_ptr->dtrap = FALSE;
778
779                 /* You are just on the edge */
780                 if (!(g_ptr->info & CAVE_UNSAFE))
781                 {
782                         if (alert_trap_detect)
783                         {
784                                 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
785                         }
786
787                         if (disturb_trap_detect) disturb(creature_ptr, FALSE, TRUE);
788                 }
789         }
790
791         return player_bold(creature_ptr, ny, nx) && !creature_ptr->is_dead && !creature_ptr->leaving;
792 }
793
794
795 /*!
796  * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す
797  * @param creature_ptr プレーヤーへの参照ポインタ
798  * @param feat 地形ID
799  * @return トラップが自動的に無効ならばTRUEを返す
800  */
801 bool trap_can_be_ignored(player_type *creature_ptr, FEAT_IDX feat)
802 {
803         feature_type *f_ptr = &f_info[feat];
804
805         if (!have_flag(f_ptr->flags, FF_TRAP)) return TRUE;
806
807         switch (f_ptr->subtype)
808         {
809         case TRAP_TRAPDOOR:
810         case TRAP_PIT:
811         case TRAP_SPIKED_PIT:
812         case TRAP_POISON_PIT:
813                 if (creature_ptr->levitation) return TRUE;
814                 break;
815         case TRAP_TELEPORT:
816                 if (creature_ptr->anti_tele) return TRUE;
817                 break;
818         case TRAP_FIRE:
819                 if (creature_ptr->immune_fire) return TRUE;
820                 break;
821         case TRAP_ACID:
822                 if (creature_ptr->immune_acid) return TRUE;
823                 break;
824         case TRAP_BLIND:
825                 if (creature_ptr->resist_blind) return TRUE;
826                 break;
827         case TRAP_CONFUSE:
828                 if (creature_ptr->resist_conf) return TRUE;
829                 break;
830         case TRAP_POISON:
831                 if (creature_ptr->resist_pois) return TRUE;
832                 break;
833         case TRAP_SLEEP:
834                 if (creature_ptr->free_act) return TRUE;
835                 break;
836         }
837
838         return FALSE;
839 }
840
841
842 /*
843  * todo 負論理なので反転させたい
844  * Determine if a "boundary" grid is "floor mimic"
845  * @param grid_type *g_ptr
846  * @param feature_type *f_ptr
847  * @param feature_type  *mimic_f_ptr
848  * @return 移動不能であればTRUE
849  */
850 bool boundary_floor(grid_type *g_ptr, feature_type *f_ptr, feature_type *mimic_f_ptr)
851 {
852         bool is_boundary_floor = g_ptr->mimic > 0;
853         is_boundary_floor &= permanent_wall(f_ptr);
854         is_boundary_floor &= have_flag((mimic_f_ptr)->flags, FF_MOVE) || have_flag((mimic_f_ptr)->flags, FF_CAN_FLY);
855         is_boundary_floor &= have_flag((mimic_f_ptr)->flags, FF_PROJECT);
856         is_boundary_floor &= !have_flag((mimic_f_ptr)->flags, FF_OPEN);
857         return is_boundary_floor;
858 }
859
860
861 /*!
862  * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す /
863  * Move player in the given direction, with the given "pickup" flag.
864  * @param creature_ptr プレーヤーへの参照ポインタ
865  * @param dir 移動方向ID
866  * @param do_pickup 罠解除を試みながらの移動ならばTRUE
867  * @param break_trap トラップ粉砕処理を行うならばTRUE
868  * @return 実際に移動が行われたならばTRUEを返す。
869  * @note
870  * This routine should (probably) always induce energy expenditure.\n
871  * @details
872  * Note that moving will *always* take a turn, and will *always* hit\n
873  * any monster which might be in the destination grid.  Previously,\n
874  * moving into walls was "free" and did NOT hit invisible monsters.\n
875  */
876 void move_player(player_type *creature_ptr, DIRECTION dir, bool do_pickup, bool break_trap)
877 {
878         POSITION y = creature_ptr->y + ddy[dir];
879         POSITION x = creature_ptr->x + ddx[dir];
880
881         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
882         grid_type *g_ptr = &floor_ptr->grid_array[y][x];
883         bool p_can_enter = player_can_enter(creature_ptr, g_ptr->feat, CEM_P_CAN_ENTER_PATTERN);
884         bool stormbringer = FALSE;
885
886         /* Exit the area */
887         if (!floor_ptr->dun_level && !creature_ptr->wild_mode &&
888                 ((x == 0) || (x == MAX_WID - 1) ||
889                  (y == 0) || (y == MAX_HGT - 1)))
890         {
891                 /* Can the player enter the grid? */
892                 if (g_ptr->mimic && player_can_enter(creature_ptr, g_ptr->mimic, 0))
893                 {
894                         /* Hack: move to new area */
895                         if ((y == 0) && (x == 0))
896                         {
897                                 creature_ptr->wilderness_y--;
898                                 creature_ptr->wilderness_x--;
899                                 creature_ptr->oldpy = floor_ptr->height - 2;
900                                 creature_ptr->oldpx = floor_ptr->width - 2;
901                                 creature_ptr->ambush_flag = FALSE;
902                         }
903
904                         else if ((y == 0) && (x == MAX_WID - 1))
905                         {
906                                 creature_ptr->wilderness_y--;
907                                 creature_ptr->wilderness_x++;
908                                 creature_ptr->oldpy = floor_ptr->height - 2;
909                                 creature_ptr->oldpx = 1;
910                                 creature_ptr->ambush_flag = FALSE;
911                         }
912
913                         else if ((y == MAX_HGT - 1) && (x == 0))
914                         {
915                                 creature_ptr->wilderness_y++;
916                                 creature_ptr->wilderness_x--;
917                                 creature_ptr->oldpy = 1;
918                                 creature_ptr->oldpx = floor_ptr->width - 2;
919                                 creature_ptr->ambush_flag = FALSE;
920                         }
921
922                         else if ((y == MAX_HGT - 1) && (x == MAX_WID - 1))
923                         {
924                                 creature_ptr->wilderness_y++;
925                                 creature_ptr->wilderness_x++;
926                                 creature_ptr->oldpy = 1;
927                                 creature_ptr->oldpx = 1;
928                                 creature_ptr->ambush_flag = FALSE;
929                         }
930
931                         else if (y == 0)
932                         {
933                                 creature_ptr->wilderness_y--;
934                                 creature_ptr->oldpy = floor_ptr->height - 2;
935                                 creature_ptr->oldpx = x;
936                                 creature_ptr->ambush_flag = FALSE;
937                         }
938
939                         else if (y == MAX_HGT - 1)
940                         {
941                                 creature_ptr->wilderness_y++;
942                                 creature_ptr->oldpy = 1;
943                                 creature_ptr->oldpx = x;
944                                 creature_ptr->ambush_flag = FALSE;
945                         }
946
947                         else if (x == 0)
948                         {
949                                 creature_ptr->wilderness_x--;
950                                 creature_ptr->oldpx = floor_ptr->width - 2;
951                                 creature_ptr->oldpy = y;
952                                 creature_ptr->ambush_flag = FALSE;
953                         }
954
955                         else if (x == MAX_WID - 1)
956                         {
957                                 creature_ptr->wilderness_x++;
958                                 creature_ptr->oldpx = 1;
959                                 creature_ptr->oldpy = y;
960                                 creature_ptr->ambush_flag = FALSE;
961                         }
962
963                         creature_ptr->leaving = TRUE;
964                         take_turn(creature_ptr, 100);
965
966                         return;
967                 }
968
969                 /* "Blocked" message appears later */
970                 /* oktomove = FALSE; */
971                 p_can_enter = FALSE;
972         }
973
974         monster_type *m_ptr;
975         m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
976
977         if (creature_ptr->inventory_list[INVEN_RARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
978         if (creature_ptr->inventory_list[INVEN_LARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
979
980         /* Player can not walk through "walls"... */
981         /* unless in Shadow Form */
982         feature_type *f_ptr = &f_info[g_ptr->feat];
983         bool p_can_kill_walls = creature_ptr->kill_wall && have_flag(f_ptr->flags, FF_HURT_DISI) &&
984                 (!p_can_enter || !have_flag(f_ptr->flags, FF_LOS)) &&
985                 !have_flag(f_ptr->flags, FF_PERMANENT);
986
987         /* Hack -- attack monsters */
988         GAME_TEXT m_name[MAX_NLEN];
989         bool can_move = TRUE;
990         bool do_past = FALSE;
991         if (g_ptr->m_idx && (m_ptr->ml || p_can_enter || p_can_kill_walls))
992         {
993                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
994
995                 /* Attack -- only if we can see it OR it is not in a wall */
996                 if (!is_hostile(m_ptr) &&
997                     !(creature_ptr->confused || creature_ptr->image || !m_ptr->ml || creature_ptr->stun ||
998                     ((creature_ptr->muta2 & MUT2_BERS_RAGE) && creature_ptr->shero)) &&
999                     pattern_seq(creature_ptr, creature_ptr->y, creature_ptr->x, y, x) && (p_can_enter || p_can_kill_walls))
1000                 {
1001                         /* Disturb the monster */
1002                         (void)set_monster_csleep(creature_ptr, g_ptr->m_idx, 0);
1003
1004                         monster_desc(creature_ptr, m_name, m_ptr, 0);
1005
1006                         if (m_ptr->ml)
1007                         {
1008                                 /* Auto-Recall if possible and visible */
1009                                 if (!creature_ptr->image) monster_race_track(creature_ptr, m_ptr->ap_r_idx);
1010                                 health_track(creature_ptr, g_ptr->m_idx);
1011                         }
1012
1013                         /* displace? */
1014                         if ((stormbringer && (randint1(1000) > 666)) || (creature_ptr->pclass == CLASS_BERSERKER))
1015                         {
1016                                 do_cmd_attack(creature_ptr, y, x, 0);
1017                                 can_move = FALSE;
1018                         }
1019                         else if (monster_can_cross_terrain(creature_ptr, floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].feat, r_ptr, 0))
1020                         {
1021                                 do_past = TRUE;
1022                         }
1023                         else
1024                         {
1025                                 msg_format(_("%^sが邪魔だ!", "%^s is in your way!"), m_name);
1026                                 free_turn(creature_ptr);
1027                                 can_move = FALSE;
1028                         }
1029
1030                         /* now continue on to 'movement' */
1031                 }
1032                 else
1033                 {
1034                         do_cmd_attack(creature_ptr, y, x, 0);
1035                         can_move = FALSE;
1036                 }
1037         }
1038
1039         monster_type *riding_m_ptr = &floor_ptr->m_list[creature_ptr->riding];
1040         monster_race *riding_r_ptr = &r_info[creature_ptr->riding ? riding_m_ptr->r_idx : 0];
1041         if (can_move && creature_ptr->riding)
1042         {
1043                 if (riding_r_ptr->flags1 & RF1_NEVER_MOVE)
1044                 {
1045                         msg_print(_("動けない!", "Can't move!"));
1046                         free_turn(creature_ptr);
1047                         can_move = FALSE;
1048                         disturb(creature_ptr, FALSE, TRUE);
1049                 }
1050                 else if (monster_fear_remaining(riding_m_ptr))
1051                 {
1052                         GAME_TEXT steed_name[MAX_NLEN];
1053                         monster_desc(creature_ptr, steed_name, riding_m_ptr, 0);
1054                         msg_format(_("%sが恐怖していて制御できない。", "%^s is too scared to control."), steed_name);
1055                         can_move = FALSE;
1056                         disturb(creature_ptr, FALSE, TRUE);
1057                 }
1058                 else if (creature_ptr->riding_ryoute)
1059                 {
1060                         can_move = FALSE;
1061                         disturb(creature_ptr, FALSE, TRUE);
1062                 }
1063                 else if (have_flag(f_ptr->flags, FF_CAN_FLY) && (riding_r_ptr->flags7 & RF7_CAN_FLY))
1064                 {
1065                         /* Allow moving */
1066                 }
1067                 else if (have_flag(f_ptr->flags, FF_CAN_SWIM) && (riding_r_ptr->flags7 & RF7_CAN_SWIM))
1068                 {
1069                         /* Allow moving */
1070                 }
1071                 else if (have_flag(f_ptr->flags, FF_WATER) &&
1072                         !(riding_r_ptr->flags7 & RF7_AQUATIC) &&
1073                         (have_flag(f_ptr->flags, FF_DEEP) || (riding_r_ptr->flags2 & RF2_AURA_FIRE)))
1074                 {
1075                         msg_format(_("%sの上に行けない。", "Can't swim."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1076                         free_turn(creature_ptr);
1077                         can_move = FALSE;
1078                         disturb(creature_ptr, FALSE, TRUE);
1079                 }
1080                 else if (!have_flag(f_ptr->flags, FF_WATER) && (riding_r_ptr->flags7 & RF7_AQUATIC))
1081                 {
1082                         msg_format(_("%sから上がれない。", "Can't land."), f_name + f_info[get_feat_mimic(&floor_ptr->grid_array[creature_ptr->y][creature_ptr->x])].name);
1083                         free_turn(creature_ptr);
1084                         can_move = FALSE;
1085                         disturb(creature_ptr, FALSE, TRUE);
1086                 }
1087                 else if (have_flag(f_ptr->flags, FF_LAVA) && !(riding_r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
1088                 {
1089                         msg_format(_("%sの上に行けない。", "Too hot to go through."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1090                         free_turn(creature_ptr);
1091                         can_move = FALSE;
1092                         disturb(creature_ptr, FALSE, TRUE);
1093                 }
1094
1095                 if (can_move && monster_stunned_remaining(riding_m_ptr) && one_in_(2))
1096                 {
1097                         GAME_TEXT steed_name[MAX_NLEN];
1098                         monster_desc(creature_ptr, steed_name, riding_m_ptr, 0);
1099                         msg_format(_("%sが朦朧としていてうまく動けない!", "You cannot control stunned %s!"), steed_name);
1100                         can_move = FALSE;
1101                         disturb(creature_ptr, FALSE, TRUE);
1102                 }
1103         }
1104
1105         if (!can_move)
1106         {
1107         }
1108
1109         else if (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !creature_ptr->levitation)
1110         {
1111                 msg_format(_("空を飛ばないと%sの上には行けない。", "You need to fly to go through the %s."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1112                 free_turn(creature_ptr);
1113                 creature_ptr->running = 0;
1114                 can_move = FALSE;
1115         }
1116
1117         /*
1118          * Player can move through trees and
1119          * has effective -10 speed
1120          * Rangers can move without penality
1121          */
1122         else if (have_flag(f_ptr->flags, FF_TREE) && !p_can_kill_walls)
1123         {
1124                 if ((creature_ptr->pclass != CLASS_RANGER) && !creature_ptr->levitation && (!creature_ptr->riding || !(riding_r_ptr->flags8 & RF8_WILD_WOOD))) creature_ptr->energy_use *= 2;
1125         }
1126
1127         /* Disarm a visible trap */
1128         else if ((do_pickup != easy_disarm) && have_flag(f_ptr->flags, FF_DISARM) && !g_ptr->mimic)
1129         {
1130                 if (!trap_can_be_ignored(creature_ptr, g_ptr->feat))
1131                 {
1132                         (void)exe_disarm(creature_ptr, y, x, dir);
1133                         return;
1134                 }
1135         }
1136
1137         /* Player can not walk through "walls" unless in wraith form...*/
1138         else if (!p_can_enter && !p_can_kill_walls)
1139         {
1140                 /* Feature code (applying "mimic" field) */
1141                 FEAT_IDX feat = get_feat_mimic(g_ptr);
1142                 feature_type *mimic_f_ptr = &f_info[feat];
1143                 concptr name = f_name + mimic_f_ptr->name;
1144
1145                 can_move = FALSE;
1146
1147                 /* Notice things in the dark */
1148                 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(creature_ptr, y, x))
1149                 {
1150                         /* Boundary floor mimic */
1151                         if (boundary_floor(g_ptr, f_ptr, mimic_f_ptr))
1152                         {
1153                                 msg_print(_("それ以上先には進めないようだ。", "You feel you cannot go any more."));
1154                         }
1155
1156                         /* Wall (or secret door) */
1157                         else
1158                         {
1159 #ifdef JP
1160                                 msg_format("%sが行く手をはばんでいるようだ。", name);
1161 #else
1162                                 msg_format("You feel %s %s blocking your way.",
1163                                         is_a_vowel(name[0]) ? "an" : "a", name);
1164 #endif
1165
1166                                 g_ptr->info |= (CAVE_MARK);
1167                                 lite_spot(creature_ptr, y, x);
1168                         }
1169                 }
1170
1171                 /* Notice things */
1172                 else
1173                 {
1174                         /* Boundary floor mimic */
1175                         if (boundary_floor(g_ptr, f_ptr, mimic_f_ptr))
1176                         {
1177                                 msg_print(_("それ以上先には進めない。", "You cannot go any more."));
1178                                 if (!(creature_ptr->confused || creature_ptr->stun || creature_ptr->image))
1179                                         free_turn(creature_ptr);
1180                         }
1181
1182                         /* Wall (or secret door) */
1183                         else
1184                         {
1185                                 /* Closed doors */
1186                                 if (easy_open && is_closed_door(creature_ptr, feat) && easy_open_door(creature_ptr, y, x)) return;
1187
1188 #ifdef JP
1189                                 msg_format("%sが行く手をはばんでいる。", name);
1190 #else
1191                                 msg_format("There is %s %s blocking your way.",
1192                                         is_a_vowel(name[0]) ? "an" : "a", name);
1193 #endif
1194
1195                                 /*
1196                                  * Well, it makes sense that you lose time bumping into
1197                                  * a wall _if_ you are confused, stunned or blind; but
1198                                  * typing mistakes should not cost you a turn...
1199                                  */
1200                                 if (!(creature_ptr->confused || creature_ptr->stun || creature_ptr->image))
1201                                         free_turn(creature_ptr);
1202                         }
1203                 }
1204
1205                 disturb(creature_ptr, FALSE, TRUE);
1206
1207                 if (!boundary_floor(g_ptr, f_ptr, mimic_f_ptr)) sound(SOUND_HITWALL);
1208         }
1209
1210         /* Normal movement */
1211         if (can_move && !pattern_seq(creature_ptr, creature_ptr->y, creature_ptr->x, y, x))
1212         {
1213                 if (!(creature_ptr->confused || creature_ptr->stun || creature_ptr->image))
1214                 {
1215                         free_turn(creature_ptr);
1216                 }
1217
1218                 /* To avoid a loop with running */
1219                 disturb(creature_ptr, FALSE, TRUE);
1220
1221                 can_move = FALSE;
1222         }
1223
1224         if (!can_move) return;
1225
1226         if (creature_ptr->warning)
1227         {
1228                 if (!process_warning(creature_ptr, x, y))
1229                 {
1230                         creature_ptr->energy_use = 25;
1231                         return;
1232                 }
1233         }
1234
1235         if (do_past)
1236         {
1237                 msg_format(_("%sを押し退けた。", "You push past %s."), m_name);
1238         }
1239
1240         /* Change oldpx and oldpy to place the player well when going back to big mode */
1241         if (creature_ptr->wild_mode)
1242         {
1243                 if (ddy[dir] > 0)  creature_ptr->oldpy = 1;
1244                 if (ddy[dir] < 0)  creature_ptr->oldpy = MAX_HGT - 2;
1245                 if (ddy[dir] == 0) creature_ptr->oldpy = MAX_HGT / 2;
1246                 if (ddx[dir] > 0)  creature_ptr->oldpx = 1;
1247                 if (ddx[dir] < 0)  creature_ptr->oldpx = MAX_WID - 2;
1248                 if (ddx[dir] == 0) creature_ptr->oldpx = MAX_WID / 2;
1249         }
1250
1251         if (p_can_kill_walls)
1252         {
1253                 cave_alter_feat(creature_ptr, y, x, FF_HURT_DISI);
1254
1255                 /* Update some things -- similar to GF_KILL_WALL */
1256                 creature_ptr->update |= (PU_FLOW);
1257         }
1258
1259         u32b mpe_mode = MPE_ENERGY_USE;
1260         if (do_pickup != always_pickup) mpe_mode |= MPE_DO_PICKUP;
1261         if (break_trap) mpe_mode |= MPE_BREAK_TRAP;
1262
1263         (void)move_player_effect(creature_ptr, y, x, mpe_mode);
1264 }
1265
1266
1267 static bool ignore_avoid_run;
1268
1269 /*!
1270  * @brief ダッシュ移動処理中、移動先のマスが既知の壁かどうかを判定する /
1271  * Hack -- Check for a "known wall" (see below)
1272  * @param creature_ptr  プレーヤーへの参照ポインタ
1273  * @param dir 想定する移動方向ID
1274  * @param y 移動元のY座標
1275  * @param x 移動元のX座標
1276  * @return 移動先が既知の壁ならばTRUE
1277  */
1278 static bool see_wall(player_type *creature_ptr, DIRECTION dir, POSITION y, POSITION x)
1279 {
1280         /* Get the new location */
1281         y += ddy[dir];
1282         x += ddx[dir];
1283
1284         /* Illegal grids are not known walls */
1285         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1286         if (!in_bounds2(floor_ptr, y, x)) return FALSE;
1287
1288         grid_type *g_ptr;
1289         g_ptr = &floor_ptr->grid_array[y][x];
1290
1291         /* Must be known to the player */
1292         if (!(g_ptr->info & CAVE_MARK)) return FALSE;
1293
1294         /* Feature code (applying "mimic" field) */
1295         s16b feat = get_feat_mimic(g_ptr);
1296         feature_type *f_ptr = &f_info[feat];
1297
1298         /* Wall grids are known walls */
1299         if (!player_can_enter(creature_ptr, feat, 0))
1300                 return !have_flag(f_ptr->flags, FF_DOOR);
1301
1302         /* Don't run on a tree unless explicitly requested */
1303         if (have_flag(f_ptr->flags, FF_AVOID_RUN) && !ignore_avoid_run)
1304                 return TRUE;
1305
1306         /* Don't run in a wall */
1307         if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
1308                 return !have_flag(f_ptr->flags, FF_DOOR);
1309
1310         return FALSE;
1311 }
1312
1313
1314 /*!
1315  * @brief ダッシュ移動処理中、移動先のマスか未知の地形かどうかを判定する /
1316  * Hack -- Check for an "unknown corner" (see below)
1317  * @param creature_ptr  プレーヤーへの参照ポインタ
1318  * @param dir 想定する移動方向ID
1319  * @param y 移動元のY座標
1320  * @param x 移動元のX座標
1321  * @return 移動先が未知の地形ならばTRUE
1322  */
1323 static bool see_nothing(player_type *creature_ptr, DIRECTION dir, POSITION y, POSITION x)
1324 {
1325         /* Get the new location */
1326         y += ddy[dir];
1327         x += ddx[dir];
1328
1329         /* Illegal grids are unknown */
1330         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1331         if (!in_bounds2(floor_ptr, y, x)) return TRUE;
1332
1333         /* Memorized grids are always known */
1334         if (floor_ptr->grid_array[y][x].info & (CAVE_MARK)) return FALSE;
1335
1336         /* Viewable door/wall grids are known */
1337         if (player_can_see_bold(creature_ptr, y, x)) return FALSE;
1338
1339         /* Default */
1340         return TRUE;
1341 }
1342
1343
1344 /*
1345  * Hack -- allow quick "cycling" through the legal directions
1346  */
1347 static byte cycle[] = { 1, 2, 3, 6, 9, 8, 7, 4, 1, 2, 3, 6, 9, 8, 7, 4, 1 };
1348
1349 /*
1350  * Hack -- map each direction into the "middle" of the "cycle[]" array
1351  */
1352 static byte chome[] = { 0, 8, 9, 10, 7, 0, 11, 6, 5, 4 };
1353
1354 /*
1355  * The direction we are running
1356  */
1357 static DIRECTION find_current;
1358
1359 /*
1360  * The direction we came from
1361  */
1362 static DIRECTION find_prevdir;
1363
1364 /*
1365  * We are looking for open area
1366  */
1367 static bool find_openarea;
1368
1369 /*
1370  * We are looking for a break
1371  */
1372 static bool find_breakright;
1373 static bool find_breakleft;
1374
1375 /*!
1376  * @brief ダッシュ処理の導入 /
1377  * Initialize the running algorithm for a new direction.
1378  * @param creature_ptr  プレーヤーへの参照ポインタ
1379  * @param dir 導入の移動先
1380  * @details
1381  * Diagonal Corridor -- allow diaginal entry into corridors.\n
1382  *\n
1383  * Blunt Corridor -- If there is a wall two spaces ahead and\n
1384  * we seem to be in a corridor, then force a turn into the side\n
1385  * corridor, must be moving straight into a corridor here. ???\n
1386  *\n
1387  * Diagonal Corridor    Blunt Corridor (?)\n
1388  *       \# \#                  \#\n
1389  *       \#x\#                  \@x\#\n
1390  *       \@\@p.                  p\n
1391  */
1392 static void run_init(player_type *creature_ptr, DIRECTION dir)
1393 {
1394         /* Save the direction */
1395         find_current = dir;
1396
1397         /* Assume running straight */
1398         find_prevdir = dir;
1399
1400         /* Assume looking for open area */
1401         find_openarea = TRUE;
1402
1403         /* Assume not looking for breaks */
1404         find_breakright = find_breakleft = FALSE;
1405
1406         /* Assume no nearby walls */
1407         bool deepleft = FALSE;
1408         bool deepright = FALSE;
1409         bool shortright = FALSE;
1410         bool shortleft = FALSE;
1411
1412         creature_ptr->run_py = creature_ptr->y;
1413         creature_ptr->run_px = creature_ptr->x;
1414
1415         /* Find the destination grid */
1416         int row = creature_ptr->y + ddy[dir];
1417         int col = creature_ptr->x + ddx[dir];
1418
1419         ignore_avoid_run = cave_have_flag_bold(creature_ptr->current_floor_ptr, row, col, FF_AVOID_RUN);
1420
1421         /* Extract cycle index */
1422         int i = chome[dir];
1423
1424         /* Check for walls */
1425         if (see_wall(creature_ptr, cycle[i+1], creature_ptr->y, creature_ptr->x))
1426         {
1427                 find_breakleft = TRUE;
1428                 shortleft = TRUE;
1429         }
1430         else if (see_wall(creature_ptr, cycle[i+1], row, col))
1431         {
1432                 find_breakleft = TRUE;
1433                 deepleft = TRUE;
1434         }
1435
1436         /* Check for walls */
1437         if (see_wall(creature_ptr, cycle[i-1], creature_ptr->y, creature_ptr->x))
1438         {
1439                 find_breakright = TRUE;
1440                 shortright = TRUE;
1441         }
1442         else if (see_wall(creature_ptr, cycle[i-1], row, col))
1443         {
1444                 find_breakright = TRUE;
1445                 deepright = TRUE;
1446         }
1447
1448         /* Looking for a break */
1449         if (!find_breakleft || !find_breakright) return;
1450
1451         /* Not looking for open area */
1452         find_openarea = FALSE;
1453
1454         /* Hack -- allow angled corridor entry */
1455         if (dir & 0x01)
1456         {
1457                 if (deepleft && !deepright)
1458                 {
1459                         find_prevdir = cycle[i - 1];
1460                 }
1461                 else if (deepright && !deepleft)
1462                 {
1463                         find_prevdir = cycle[i + 1];
1464                 }
1465
1466                 return;
1467         }
1468
1469         /* Hack -- allow blunt corridor entry */
1470         if (!see_wall(creature_ptr, cycle[i], row, col)) return;
1471
1472         if (shortleft && !shortright)
1473         {
1474                 find_prevdir = cycle[i - 2];
1475         }
1476         else if (shortright && !shortleft)
1477         {
1478                 find_prevdir = cycle[i + 2];
1479         }
1480 }
1481
1482
1483 /*!
1484  * @brief ダッシュ移動が継続できるかどうかの判定 /
1485  * Update the current "run" path
1486  * @param creature_ptr  プレーヤーへの参照ポインタ
1487  * @return 立ち止まるべき条件が満たされたらTRUE
1488  * ダッシュ移動が継続できるならばTRUEを返す。
1489  * Return TRUE if the running should be stopped
1490  */
1491 static bool run_test(player_type *creature_ptr)
1492 {
1493         DIRECTION prev_dir = find_prevdir;
1494
1495         /* Range of newly adjacent grids */
1496         int max = (prev_dir & 0x01) + 1;
1497
1498         /* break run when leaving trap detected region */
1499         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1500         if ((disturb_trap_detect || alert_trap_detect)
1501             && creature_ptr->dtrap && !(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_IN_DETECT))
1502         {
1503                 /* No duplicate warning */
1504                 creature_ptr->dtrap = FALSE;
1505
1506                 /* You are just on the edge */
1507                 if (!(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_UNSAFE))
1508                 {
1509                         if (alert_trap_detect)
1510                         {
1511                                 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
1512                         }
1513
1514                         if (disturb_trap_detect)
1515                         {
1516                                 /* Break Run */
1517                                 return TRUE;
1518                         }
1519                 }
1520         }
1521
1522         /* Look at every newly adjacent square. */
1523         DIRECTION check_dir = 0;
1524         int option = 0, option2 = 0;
1525         for (int i = -max; i <= max; i++)
1526         {
1527                 OBJECT_IDX this_o_idx, next_o_idx = 0;
1528
1529                 /* New direction */
1530                 DIRECTION new_dir = cycle[chome[prev_dir] + i];
1531
1532                 /* New location */
1533                 int row = creature_ptr->y + ddy[new_dir];
1534                 int col = creature_ptr->x + ddx[new_dir];
1535
1536                 grid_type *g_ptr;
1537                 g_ptr = &floor_ptr->grid_array[row][col];
1538
1539                 /* Feature code (applying "mimic" field) */
1540                 FEAT_IDX feat = get_feat_mimic(g_ptr);
1541                 feature_type *f_ptr;
1542                 f_ptr = &f_info[feat];
1543
1544                 /* Visible monsters abort running */
1545                 if (g_ptr->m_idx)
1546                 {
1547                         monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
1548
1549                         /* Visible monster */
1550                         if (m_ptr->ml) return TRUE;
1551                 }
1552
1553                 /* Visible objects abort running */
1554                 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1555                 {
1556                         object_type *o_ptr;
1557                         o_ptr = &floor_ptr->o_list[this_o_idx];
1558                         next_o_idx = o_ptr->next_o_idx;
1559
1560                         /* Visible object */
1561                         if (o_ptr->marked & OM_FOUND) return TRUE;
1562                 }
1563
1564                 /* Assume unknown */
1565                 bool inv = TRUE;
1566
1567                 /* Check memorized grids */
1568                 if (g_ptr->info & (CAVE_MARK))
1569                 {
1570                         bool notice = have_flag(f_ptr->flags, FF_NOTICE);
1571
1572                         if (notice && have_flag(f_ptr->flags, FF_MOVE))
1573                         {
1574                                 /* Open doors */
1575                                 if (find_ignore_doors && have_flag(f_ptr->flags, FF_DOOR) && have_flag(f_ptr->flags, FF_CLOSE))
1576                                 {
1577                                         /* Option -- ignore */
1578                                         notice = FALSE;
1579                                 }
1580
1581                                 /* Stairs */
1582                                 else if (find_ignore_stairs && have_flag(f_ptr->flags, FF_STAIRS))
1583                                 {
1584                                         /* Option -- ignore */
1585                                         notice = FALSE;
1586                                 }
1587
1588                                 /* Lava */
1589                                 else if (have_flag(f_ptr->flags, FF_LAVA) && (creature_ptr->immune_fire || IS_INVULN(creature_ptr)))
1590                                 {
1591                                         /* Ignore */
1592                                         notice = FALSE;
1593                                 }
1594
1595                                 /* Deep water */
1596                                 else if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP) &&
1597                                          (creature_ptr->levitation || creature_ptr->can_swim || (creature_ptr->total_weight <= weight_limit(creature_ptr))))
1598                                 {
1599                                         /* Ignore */
1600                                         notice = FALSE;
1601                                 }
1602                         }
1603
1604                         /* Interesting feature */
1605                         if (notice) return TRUE;
1606
1607                         /* The grid is "visible" */
1608                         inv = FALSE;
1609                 }
1610
1611                 /* Analyze unknown grids and floors considering mimic */
1612                 if (!inv && see_wall(creature_ptr, 0, row, col))
1613                 {
1614                         if (find_openarea)
1615                         {
1616                                 if (i < 0)
1617                                 {
1618                                         /* Break to the right */
1619                                         find_breakright = TRUE;
1620                                 }
1621
1622                                 else if (i > 0)
1623                                 {
1624                                         /* Break to the left */
1625                                         find_breakleft = TRUE;
1626                                 }
1627                         }
1628
1629                         continue;
1630                 }
1631
1632                 /* Looking for open area */
1633                 if (find_openarea) continue;
1634
1635                 /* The first new direction. */
1636                 if (!option)
1637                 {
1638                         option = new_dir;
1639                         continue;
1640                 }
1641
1642                 /* Three new directions. Stop running. */
1643                 if (option2)
1644                 {
1645                         return TRUE;
1646                 }
1647
1648                 /* Two non-adjacent new directions.  Stop running. */
1649                 if (option != cycle[chome[prev_dir] + i - 1])
1650                 {
1651                         return TRUE;
1652                 }
1653
1654                 /* Two new (adjacent) directions (case 1) */
1655                 if (new_dir & 0x01)
1656                 {
1657                         check_dir = cycle[chome[prev_dir] + i - 2];
1658                         option2 = new_dir;
1659                         continue;
1660                 }
1661
1662                 /* Two new (adjacent) directions (case 2) */
1663                 check_dir = cycle[chome[prev_dir] + i + 1];
1664                 option2 = option;
1665                 option = new_dir;
1666         }
1667
1668         /* Looking for open area */
1669         if (find_openarea)
1670         {
1671                 /* Hack -- look again */
1672                 for (int i = -max; i < 0; i++)
1673                 {
1674                         /* Unknown grid or non-wall */
1675                         if (!see_wall(creature_ptr, cycle[chome[prev_dir] + i], creature_ptr->y, creature_ptr->x))
1676                         {
1677                                 /* Looking to break right */
1678                                 if (find_breakright)
1679                                 {
1680                                         return TRUE;
1681                                 }
1682                         }
1683
1684                         /* Obstacle */
1685                         else
1686                         {
1687                                 /* Looking to break left */
1688                                 if (find_breakleft)
1689                                 {
1690                                         return TRUE;
1691                                 }
1692                         }
1693                 }
1694
1695                 /* Hack -- look again */
1696                 for (int i = max; i > 0; i--)
1697                 {
1698                         /* Unknown grid or non-wall */
1699                         if (!see_wall(creature_ptr, cycle[chome[prev_dir] + i], creature_ptr->y, creature_ptr->x))
1700                         {
1701                                 /* Looking to break left */
1702                                 if (find_breakleft)
1703                                 {
1704                                         return TRUE;
1705                                 }
1706                         }
1707
1708                         /* Obstacle */
1709                         else
1710                         {
1711                                 /* Looking to break right */
1712                                 if (find_breakright)
1713                                 {
1714                                         return TRUE;
1715                                 }
1716                         }
1717                 }
1718
1719                 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
1720         }
1721
1722         /* No options */
1723         if (!option)
1724         {
1725                 return TRUE;
1726         }
1727
1728         /* One option */
1729         if (!option2)
1730         {
1731                 find_current = option;
1732                 find_prevdir = option;
1733                 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
1734         }
1735
1736         /* Two options, examining corners */
1737         else if (!find_cut)
1738         {
1739                 find_current = option;
1740                 find_prevdir = option2;
1741                 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
1742         }
1743
1744         /* Two options, pick one */
1745         /* Get next location */
1746         int row = creature_ptr->y + ddy[option];
1747         int col = creature_ptr->x + ddx[option];
1748
1749         /* Don't see that it is closed off. */
1750         /* This could be a potential corner or an intersection. */
1751         if (!see_wall(creature_ptr, option, row, col) ||
1752                 !see_wall(creature_ptr, check_dir, row, col))
1753         {
1754                 /* Can not see anything ahead and in the direction we */
1755                 /* are turning, assume that it is a potential corner. */
1756                 if (see_nothing(creature_ptr, option, row, col) &&
1757                         see_nothing(creature_ptr, option2, row, col))
1758                 {
1759                         find_current = option;
1760                         find_prevdir = option2;
1761                         return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
1762                 }
1763
1764                 /* STOP: we are next to an intersection or a room */
1765                 return TRUE;
1766         }
1767
1768         /* This corner is seen to be enclosed; we cut the corner. */
1769         if (find_cut)
1770         {
1771                 find_current = option2;
1772                 find_prevdir = option2;
1773                 return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
1774         }
1775
1776         /* This corner is seen to be enclosed, and we */
1777         /* deliberately go the long way. */
1778         find_current = option;
1779         find_prevdir = option2;
1780         return see_wall(creature_ptr, find_current, creature_ptr->y, creature_ptr->x);
1781 }
1782
1783
1784 /*!
1785  * @brief 継続的なダッシュ処理 /
1786  * Take one step along the current "run" path
1787  * @param creature_ptr  プレーヤーへの参照ポインタ
1788  * @param dir 移動を試みる方向ID
1789  * @return なし
1790  */
1791 void run_step(player_type *creature_ptr, DIRECTION dir)
1792 {
1793         /* Start running */
1794         if (dir)
1795         {
1796                 /* Ignore AVOID_RUN on a first step */
1797                 ignore_avoid_run = TRUE;
1798
1799                 /* Hack -- do not start silly run */
1800                 if (see_wall(creature_ptr, dir, creature_ptr->y, creature_ptr->x))
1801                 {
1802                         sound(SOUND_HITWALL);
1803
1804                         msg_print(_("その方向には走れません。", "You cannot run in that direction."));
1805
1806                         disturb(creature_ptr, FALSE, FALSE);
1807
1808                         return;
1809                 }
1810
1811                 run_init(creature_ptr, dir);
1812         }
1813
1814         /* Keep running */
1815         else
1816         {
1817                 /* Update run */
1818                 if (run_test(creature_ptr))
1819                 {
1820                         disturb(creature_ptr, FALSE, FALSE);
1821
1822                         return;
1823                 }
1824         }
1825
1826         /* Decrease the run counter */
1827         if (--creature_ptr->running <= 0) return;
1828
1829         /* Take time */
1830         take_turn(creature_ptr, 100);
1831
1832         /* Move the player, using the "pickup" flag */
1833         move_player(creature_ptr, find_current, FALSE, FALSE);
1834
1835         if (player_bold(creature_ptr, creature_ptr->run_py, creature_ptr->run_px))
1836         {
1837                 creature_ptr->run_py = 0;
1838                 creature_ptr->run_px = 0;
1839                 disturb(creature_ptr, FALSE, FALSE);
1840         }
1841 }
1842
1843
1844 /*!
1845  * @brief トラベル機能の判定処理 /
1846  * Test for traveling
1847  * @param creature_ptr  プレーヤーへの参照ポインタ
1848  * @param prev_dir 前回移動を行った元の方角ID
1849  * @return 次の方向
1850  */
1851 static DIRECTION travel_test(player_type *creature_ptr, DIRECTION prev_dir)
1852 {
1853         /* Cannot travel when blind */
1854         if (creature_ptr->blind || no_lite(creature_ptr))
1855         {
1856                 msg_print(_("目が見えない!", "You cannot see!"));
1857                 return 0;
1858         }
1859
1860         /* break run when leaving trap detected region */
1861         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1862         if ((disturb_trap_detect || alert_trap_detect)
1863             && creature_ptr->dtrap && !(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_IN_DETECT))
1864         {
1865                 /* No duplicate warning */
1866                 creature_ptr->dtrap = FALSE;
1867
1868                 /* You are just on the edge */
1869                 if (!(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_UNSAFE))
1870                 {
1871                         if (alert_trap_detect)
1872                         {
1873                                 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
1874                         }
1875
1876                         if (disturb_trap_detect)
1877                         {
1878                                 /* Break Run */
1879                                 return 0;
1880                         }
1881                 }
1882         }
1883
1884         /* Range of newly adjacent grids */
1885         int max = (prev_dir & 0x01) + 1;
1886
1887         /* Look at every newly adjacent square. */
1888         const grid_type *g_ptr;
1889         for (int i = -max; i <= max; i++)
1890         {
1891                 /* New direction */
1892                 DIRECTION dir = cycle[chome[prev_dir] + i];
1893
1894                 /* New location */
1895                 POSITION row = creature_ptr->y + ddy[dir];
1896                 POSITION col = creature_ptr->x + ddx[dir];
1897
1898                 g_ptr = &floor_ptr->grid_array[row][col];
1899
1900                 /* Visible monsters abort running */
1901                 if (g_ptr->m_idx)
1902                 {
1903                         monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
1904
1905                         /* Visible monster */
1906                         if (m_ptr->ml) return 0;
1907                 }
1908
1909         }
1910
1911         /* Travel cost of current grid */
1912         int cost = travel.cost[creature_ptr->y][creature_ptr->x];
1913
1914         /* Determine travel direction */
1915         DIRECTION new_dir = 0;
1916         for (int i = 0; i < 8; ++ i)
1917         {
1918                 int dir_cost = travel.cost[creature_ptr->y+ddy_ddd[i]][creature_ptr->x+ddx_ddd[i]];
1919
1920                 if (dir_cost < cost)
1921                 {
1922                         new_dir = ddd[i];
1923                         cost = dir_cost;
1924                 }
1925         }
1926
1927         if (!new_dir) return 0;
1928
1929         /* Access newly move grid */
1930         g_ptr = &floor_ptr->grid_array[creature_ptr->y+ddy[new_dir]][creature_ptr->x+ddx[new_dir]];
1931
1932         /* Close door abort traveling */
1933         if (!easy_open && is_closed_door(creature_ptr, g_ptr->feat)) return 0;
1934
1935         /* Visible and unignorable trap abort tarveling */
1936         if (!g_ptr->mimic && !trap_can_be_ignored(creature_ptr, g_ptr->feat)) return 0;
1937
1938         /* Move new grid */
1939         return new_dir;
1940 }
1941
1942
1943 /*!
1944  * @brief トラベル機能の実装 /
1945  * Travel command
1946  * @param creature_ptr  プレーヤーへの参照ポインタ
1947  * @return なし
1948  */
1949 void travel_step(player_type *creature_ptr)
1950 {
1951         /* Get travel direction */
1952         travel.dir = travel_test(creature_ptr, travel.dir);
1953
1954         if (!travel.dir)
1955         {
1956                 if (travel.run == 255)
1957                 {
1958                         msg_print(_("道筋が見つかりません!", "No route is found!"));
1959                         travel.y = travel.x = 0;
1960                 }
1961
1962                 disturb(creature_ptr, FALSE, TRUE);
1963                 return;
1964         }
1965
1966         take_turn(creature_ptr, 100);
1967
1968         move_player(creature_ptr, travel.dir, always_pickup, FALSE);
1969
1970         if ((creature_ptr->y == travel.y) && (creature_ptr->x == travel.x))
1971         {
1972                 travel.run = 0;
1973                 travel.y = travel.x = 0;
1974         }
1975         else if (travel.run > 0)
1976         {
1977                 travel.run--;
1978         }
1979
1980         /* Travel Delay */
1981         Term_xtra(TERM_XTRA_DELAY, delay_factor);
1982 }
1983
1984
1985 #define TRAVEL_UNABLE 9999
1986
1987 static int flow_head = 0;
1988 static int flow_tail = 0;
1989 static POSITION temp2_x[MAX_SHORT];
1990 static POSITION temp2_y[MAX_SHORT];
1991
1992 /*!
1993  * @brief トラベル処理の記憶配列を初期化する Hack: forget the "flow" information
1994  * @param creature_ptr  プレーヤーへの参照ポインタ
1995  * @return なし
1996  */
1997 void forget_travel_flow(floor_type *floor_ptr)
1998 {
1999         /* Check the entire dungeon / Forget the old data */
2000         for (POSITION y = 0; y < floor_ptr->height; y++)
2001         {
2002                 for (POSITION x = 0; x < floor_ptr->width; x++)
2003                 {
2004                         travel.cost[y][x] = MAX_SHORT;
2005                 }
2006         }
2007
2008         travel.y = travel.x = 0;
2009 }
2010
2011
2012 /*!
2013  * @brief トラベル処理中に地形に応じた移動コスト基準を返す
2014  * @param creature_ptr  プレーヤーへの参照ポインタ
2015  * @param y 該当地点のY座標
2016  * @param x 該当地点のX座標
2017  * @return コスト値
2018  */
2019 static int travel_flow_cost(player_type *creature_ptr, POSITION y, POSITION x)
2020 {
2021         /* Avoid obstacles (ex. trees) */
2022         int cost = 1;
2023         feature_type *f_ptr = &f_info[creature_ptr->current_floor_ptr->grid_array[y][x].feat];
2024         if (have_flag(f_ptr->flags, FF_AVOID_RUN)) cost += 1;
2025
2026         /* Water */
2027         if (have_flag(f_ptr->flags, FF_WATER))
2028         {
2029                 if (have_flag(f_ptr->flags, FF_DEEP) && !creature_ptr->levitation) cost += 5;
2030         }
2031
2032         /* Lava */
2033         if (have_flag(f_ptr->flags, FF_LAVA))
2034         {
2035                 int lava = 2;
2036                 if (!creature_ptr->resist_fire) lava *= 2;
2037                 if (!creature_ptr->levitation) lava *= 2;
2038                 if (have_flag(f_ptr->flags, FF_DEEP)) lava *= 2;
2039
2040                 cost += lava;
2041         }
2042
2043         /* Detected traps and doors */
2044         if (creature_ptr->current_floor_ptr->grid_array[y][x].info & (CAVE_MARK))
2045         {
2046                 if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
2047                 if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
2048         }
2049
2050         return cost;
2051 }
2052
2053
2054 /*!
2055  * @brief トラベル処理の到達地点までの行程を得る処理のサブルーチン
2056  * @param creature_ptr  プレーヤーへの参照ポインタ
2057  * @param y 目標地点のY座標
2058  * @param x 目標地点のX座標
2059  * @param n 現在のコスト
2060  * @param wall プレイヤーが壁の中にいるならばTRUE
2061  * @return なし
2062  */
2063 static void travel_flow_aux(player_type *creature_ptr, POSITION y, POSITION x, int n, bool wall)
2064 {
2065         /* Ignore out of bounds */
2066         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2067         grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2068         feature_type *f_ptr = &f_info[g_ptr->feat];
2069         if (!in_bounds(floor_ptr, y, x)) return;
2070
2071         /* Ignore unknown grid except in wilderness */
2072         if (floor_ptr->dun_level > 0 && !(g_ptr->info & CAVE_KNOWN)) return;
2073
2074         /* Ignore "walls" and "rubble" (include "secret doors") */
2075         int add_cost = 1;
2076         int from_wall = (n / TRAVEL_UNABLE);
2077         if (have_flag(f_ptr->flags, FF_WALL) ||
2078                 have_flag(f_ptr->flags, FF_CAN_DIG) ||
2079                 (have_flag(f_ptr->flags, FF_DOOR) && floor_ptr->grid_array[y][x].mimic) ||
2080                 (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !creature_ptr->levitation))
2081         {
2082                 if (!wall || !from_wall) return;
2083                 add_cost += TRAVEL_UNABLE;
2084         }
2085         else
2086         {
2087                 add_cost = travel_flow_cost(creature_ptr, y, x);
2088         }
2089
2090         int base_cost = (n % TRAVEL_UNABLE);
2091         int cost = base_cost + add_cost;
2092
2093         /* Ignore lower cost entries */
2094         if (travel.cost[y][x] <= cost) return;
2095
2096         /* Save the flow cost */
2097         travel.cost[y][x] = cost;
2098
2099         /* Enqueue that entry */
2100         int old_head = flow_head;
2101         temp2_y[flow_head] = y;
2102         temp2_x[flow_head] = x;
2103
2104         /* Advance the queue */
2105         if (++flow_head == MAX_SHORT) flow_head = 0;
2106
2107         /* Hack -- notice overflow by forgetting new entry */
2108         if (flow_head == flow_tail) flow_head = old_head;
2109 }
2110
2111
2112 /*!
2113  * @brief トラベル処理の到達地点までの行程を得る処理のメインルーチン
2114  * @param creature_ptr  プレーヤーへの参照ポインタ
2115  * @param ty 目標地点のY座標
2116  * @param tx 目標地点のX座標
2117  * @return なし
2118  */
2119 static void travel_flow(player_type *creature_ptr, POSITION ty, POSITION tx)
2120 {
2121         flow_head = flow_tail = 0;
2122
2123         /* is player in the wall? */
2124         bool wall = FALSE;
2125         feature_type *f_ptr = &f_info[creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].feat];
2126         if (!have_flag(f_ptr->flags, FF_MOVE)) wall = TRUE;
2127
2128         /* Start at the target grid */
2129         travel_flow_aux(creature_ptr, ty, tx, 0, wall);
2130
2131         /* Now process the queue */
2132         POSITION x, y;
2133         while (flow_head != flow_tail)
2134         {
2135                 /* Extract the next entry */
2136                 y = temp2_y[flow_tail];
2137                 x = temp2_x[flow_tail];
2138
2139                 /* Forget that entry */
2140                 if (++flow_tail == MAX_SHORT) flow_tail = 0;
2141
2142                 /* Add the "children" */
2143                 for (DIRECTION d = 0; d < 8; d++)
2144                 {
2145                         /* Add that child if "legal" */
2146                         travel_flow_aux(creature_ptr, y + ddy_ddd[d], x + ddx_ddd[d], travel.cost[y][x], wall);
2147                 }
2148         }
2149
2150         flow_head = flow_tail = 0;
2151 }
2152
2153
2154 /*!
2155  * @brief トラベル処理のメインルーチン
2156  * @return なし
2157  */
2158 void do_cmd_travel(player_type *creature_ptr)
2159 {
2160         POSITION x, y;
2161         if (travel.x != 0 && travel.y != 0 &&
2162                 get_check(_("トラベルを継続しますか?", "Do you continue to travel?")))
2163         {
2164                 y = travel.y;
2165                 x = travel.x;
2166         }
2167         else if (!tgt_pt(creature_ptr, &x, &y)) return;
2168
2169         if ((x == creature_ptr->x) && (y == creature_ptr->y))
2170         {
2171                 msg_print(_("すでにそこにいます!", "You are already there!!"));
2172                 return;
2173         }
2174
2175         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2176         feature_type *f_ptr;
2177         f_ptr = &f_info[floor_ptr->grid_array[y][x].feat];
2178
2179         if ((floor_ptr->grid_array[y][x].info & CAVE_MARK) &&
2180                 (have_flag(f_ptr->flags, FF_WALL) ||
2181                         have_flag(f_ptr->flags, FF_CAN_DIG) ||
2182                         (have_flag(f_ptr->flags, FF_DOOR) && floor_ptr->grid_array[y][x].mimic)))
2183         {
2184                 msg_print(_("そこには行くことができません!", "You cannot travel there!"));
2185                 return;
2186         }
2187
2188         forget_travel_flow(creature_ptr->current_floor_ptr);
2189         travel_flow(creature_ptr, y, x);
2190
2191         travel.x = x;
2192         travel.y = y;
2193
2194         /* Travel till 255 steps */
2195         travel.run = 255;
2196         travel.dir = 0;
2197
2198         /* Decides first direction */
2199         POSITION dx = abs(creature_ptr->x - x);
2200         POSITION dy = abs(creature_ptr->y - y);
2201         POSITION sx = ((x == creature_ptr->x) || (dx < dy)) ? 0 : ((x > creature_ptr->x) ? 1 : -1);
2202         POSITION sy = ((y == creature_ptr->y) || (dy < dx)) ? 0 : ((y > creature_ptr->y) ? 1 : -1);
2203
2204         for (int i = 1; i <= 9; i++)
2205         {
2206                 if ((sx == ddx[i]) && (sy == ddy[i])) travel.dir = i;
2207         }
2208 }
2209
2210
2211 /*
2212  * Something has happened to disturb the player.
2213  * The first arg indicates a major disturbance, which affects search.
2214  * The second arg is currently unused, but could induce output flush.
2215  * All disturbance cancels repeated commands, resting, and running.
2216  */
2217 void disturb(player_type *creature_ptr, bool stop_search, bool stop_travel)
2218 {
2219         /* Cancel repeated commands */
2220         if (command_rep)
2221         {
2222                 /* Cancel */
2223                 command_rep = 0;
2224
2225                 /* Redraw the state (later) */
2226                 creature_ptr->redraw |= (PR_STATE);
2227         }
2228
2229         /* Cancel Resting */
2230         if ((creature_ptr->action == ACTION_REST) || (creature_ptr->action == ACTION_FISH) || (stop_search && (creature_ptr->action == ACTION_SEARCH)))
2231         {
2232                 /* Cancel */
2233                 set_action(creature_ptr, ACTION_NONE);
2234         }
2235
2236         /* Cancel running */
2237         if (creature_ptr->running)
2238         {
2239                 /* Cancel */
2240                 creature_ptr->running = 0;
2241
2242                 /* Check for new panel if appropriate */
2243                 if (center_player && !center_running) verify_panel(creature_ptr);
2244
2245                 /* Calculate torch radius */
2246                 creature_ptr->update |= (PU_TORCH);
2247
2248                 /* Update monster flow */
2249                 creature_ptr->update |= (PU_FLOW);
2250         }
2251
2252         if (stop_travel)
2253         {
2254                 /* Cancel */
2255                 travel.run = 0;
2256
2257                 /* Check for new panel if appropriate */
2258                 if (center_player && !center_running) verify_panel(creature_ptr);
2259
2260                 /* Calculate torch radius */
2261                 creature_ptr->update |= (PU_TORCH);
2262         }
2263
2264         if (flush_disturb) flush();
2265 }