OSDN Git Service

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