OSDN Git Service

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