OSDN Git Service

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