OSDN Git Service

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