OSDN Git Service

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