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