OSDN Git Service

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