OSDN Git Service

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