OSDN Git Service

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