OSDN Git Service

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