OSDN Git Service

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