OSDN Git Service

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