OSDN Git Service

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