OSDN Git Service

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