OSDN Git Service

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