OSDN Git Service

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