OSDN Git Service

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