OSDN Git Service

ソースコードのUTF-8化。
[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
143 #include "angband.h"
144 #define MAX_VAMPIRIC_DRAIN 50 /*!< 吸血処理の最大回復HP */
145
146
147 /*!
148  * @brief プレイヤーからモンスターへの射撃命中判定 /
149  * Determine if the player "hits" a monster (normal combat).
150  * @param chance 基本命中値
151  * @param m_ptr モンスターの構造体参照ポインタ
152  * @param vis 目標を視界に捕らえているならばTRUEを指定
153  * @param o_name メッセージ表示時のモンスター名
154  * @return 命中と判定された場合TRUEを返す
155  * @note Always miss 5%, always hit 5%, otherwise random.
156  */
157 bool test_hit_fire(int chance, monster_type *m_ptr, int vis, char* o_name)
158 {
159         int k, ac;
160         monster_race *r_ptr = &r_info[m_ptr->r_idx];
161         
162         ac = r_ptr->ac;
163         if(m_ptr->r_idx == MON_GOEMON && !MON_CSLEEP(m_ptr)) ac *= 3;
164
165         /* Percentile dice */
166         k = randint0(100);
167         
168         /* Snipers with high-concentration reduce instant miss percentage.*/
169         k += p_ptr->concent;
170         
171         /* Hack -- Instant miss or hit */
172         if (k < 10) return (k < 5);
173
174         if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
175                 if (one_in_(20)) return (FALSE);
176
177         /* Never hit */
178         if (chance <= 0) return (FALSE);
179
180         /* Invisible monsters are harder to hit */
181         if (!vis) chance = (chance + 1) / 2;
182
183         /* Power competes against armor */
184         if (randint0(chance) < (ac * 3 / 4))
185         {
186                 if(m_ptr->r_idx == MON_GOEMON && !MON_CSLEEP(m_ptr))
187                 {
188                         char m_name[80];
189                         
190                         /* Extract monster name */
191                         monster_desc(m_name, m_ptr, 0);
192                         msg_format(_("%sは%sを斬り捨てた!", "%s cuts down %s!"), m_name, o_name);
193                 }
194                 return (FALSE);
195         }
196
197         /* Assume hit */
198         return (TRUE);
199 }
200
201
202
203 /*!
204  * @brief プレイヤーからモンスターへの打撃命中判定 /
205  * Determine if the player "hits" a monster (normal combat).
206  * @param chance 基本命中値
207  * @param ac モンスターのAC
208  * @param vis 目標を視界に捕らえているならばTRUEを指定
209  * @return 命中と判定された場合TRUEを返す
210  * @note Always miss 5%, always hit 5%, otherwise random.
211  */
212 bool test_hit_norm(int chance, int ac, int vis)
213 {
214         int k;
215
216         /* Percentile dice */
217         k = randint0(100);
218
219         /* Hack -- Instant miss or hit */
220         if (k < 10) return (k < 5);
221
222         if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
223                 if (one_in_(20)) return (FALSE);
224
225         /* Wimpy attack never hits */
226         if (chance <= 0) return (FALSE);
227
228         /* Penalize invisible targets */
229         if (!vis) chance = (chance + 1) / 2;
230
231         /* Power must defeat armor */
232         if (randint0(chance) < (ac * 3 / 4)) return (FALSE);
233
234         /* Assume hit */
235         return (TRUE);
236 }
237
238
239
240 /*!
241  * @brief プレイヤーからモンスターへの射撃クリティカル判定 /
242  * Critical hits (from objects thrown by player) Factor in item weight, total plusses, and player level.
243  * @param weight 矢弾の重量
244  * @param plus_ammo 矢弾の命中修正
245  * @param plus_bow 弓の命中修正
246  * @param dam 現在算出中のダメージ値
247  * @return クリティカル修正が入ったダメージ値
248  */
249 s16b critical_shot(int weight, int plus_ammo, int plus_bow, int dam)
250 {
251         int i, k;
252         object_type *j_ptr =  &inventory[INVEN_BOW];
253         
254         /* Extract "shot" power */
255         i = p_ptr->to_h_b + plus_ammo;
256         
257         if (p_ptr->tval_ammo == TV_BOLT)
258                 i = (p_ptr->skill_thb + (p_ptr->weapon_exp[0][j_ptr->sval] / 400 + i) * BTH_PLUS_ADJ);
259         else
260                 i = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200 + i) * BTH_PLUS_ADJ);
261
262         
263         /* Snipers can shot more critically with crossbows */
264         if (p_ptr->concent) i += ((i * p_ptr->concent) / 5);
265         if ((p_ptr->pclass == CLASS_SNIPER) && (p_ptr->tval_ammo == TV_BOLT)) i *= 2;
266         
267         /* Good bow makes more critical */
268         i += plus_bow * 8 * (p_ptr->concent ? p_ptr->concent + 5 : 5);
269         
270         /* Critical hit */
271         if (randint1(10000) <= i)
272         {
273                 k = weight * randint1(500);
274
275                 if (k < 900)
276                 {
277 #ifdef JP
278                         msg_print("手ごたえがあった!");
279 #else
280                         msg_print("It was a good hit!");
281 #endif
282
283                         dam += (dam / 2);
284                 }
285                 else if (k < 1350)
286                 {
287 #ifdef JP
288                         msg_print("かなりの手ごたえがあった!");
289 #else
290                         msg_print("It was a great hit!");
291 #endif
292
293                         dam *= 2;
294                 }
295                 else
296                 {
297 #ifdef JP
298                         msg_print("会心の一撃だ!");
299 #else
300                         msg_print("It was a superb hit!");
301 #endif
302
303                         dam *= 3;
304                 }
305         }
306
307         return (dam);
308 }
309
310
311
312 /*!
313  * @brief プレイヤーからモンスターへの打撃クリティカル判定 /
314  * Critical hits (by player) Factor in weapon weight, total plusses, player melee bonus
315  * @param weight 矢弾の重量
316  * @param plus 武器の命中修正
317  * @param dam 現在算出中のダメージ値
318  * @param meichuu 打撃の基本命中力
319  * @param mode オプションフラグ
320  * @return クリティカル修正が入ったダメージ値
321  */
322 s16b critical_norm(int weight, int plus, int dam, s16b meichuu, int mode)
323 {
324         int i, k;
325         
326         /* Extract "blow" power */
327         i = (weight + (meichuu * 3 + plus * 5) + p_ptr->skill_thn);
328
329         /* Chance */
330         if ((randint1((p_ptr->pclass == CLASS_NINJA) ? 4444 : 5000) <= i) || (mode == HISSATSU_MAJIN) || (mode == HISSATSU_3DAN))
331         {
332                 k = weight + randint1(650);
333                 if ((mode == HISSATSU_MAJIN) || (mode == HISSATSU_3DAN)) k+= randint1(650);
334
335                 if (k < 400)
336                 {
337 #ifdef JP
338                         msg_print("手ごたえがあった!");
339 #else
340                         msg_print("It was a good hit!");
341 #endif
342
343                         dam = 2 * dam + 5;
344                 }
345                 else if (k < 700)
346                 {
347 #ifdef JP
348                         msg_print("かなりの手ごたえがあった!");
349 #else
350                         msg_print("It was a great hit!");
351 #endif
352
353                         dam = 2 * dam + 10;
354                 }
355                 else if (k < 900)
356                 {
357 #ifdef JP
358                         msg_print("会心の一撃だ!");
359 #else
360                         msg_print("It was a superb hit!");
361 #endif
362
363                         dam = 3 * dam + 15;
364                 }
365                 else if (k < 1300)
366                 {
367 #ifdef JP
368                         msg_print("最高の会心の一撃だ!");
369 #else
370                         msg_print("It was a *GREAT* hit!");
371 #endif
372
373                         dam = 3 * dam + 20;
374                 }
375                 else
376                 {
377 #ifdef JP
378                         msg_print("比類なき最高の会心の一撃だ!");
379 #else
380                         msg_print("It was a *SUPERB* hit!");
381 #endif
382
383                         dam = ((7 * dam) / 2) + 25;
384                 }
385         }
386
387         return (dam);
388 }
389
390
391
392 /*!
393  * @brief プレイヤー攻撃の種族スレイング倍率計算
394  * @param mult 算出前の基本倍率(/10倍)
395  * @param flgs スレイフラグ配列
396  * @param m_ptr 目標モンスターの構造体参照ポインタ
397  * @return スレイング加味後の倍率(/10倍)
398  */
399 static int mult_slaying(int mult, const u32b* flgs, const monster_type* m_ptr)
400 {
401         static const struct slay_table_t {
402                 int slay_flag;
403                 u32b affect_race_flag;
404                 int slay_mult;
405                 size_t flag_offset;
406                 size_t r_flag_offset;
407         } slay_table[] = {
408 #define OFFSET(X) offsetof(monster_race, X)
409                 {TR_SLAY_ANIMAL, RF3_ANIMAL, 25, OFFSET(flags3), OFFSET(r_flags3)},
410                 {TR_KILL_ANIMAL, RF3_ANIMAL, 40, OFFSET(flags3), OFFSET(r_flags3)},
411                 {TR_SLAY_EVIL,   RF3_EVIL,   20, OFFSET(flags3), OFFSET(r_flags3)},
412                 {TR_KILL_EVIL,   RF3_EVIL,   35, OFFSET(flags3), OFFSET(r_flags3)},
413                 {TR_SLAY_GOOD,   RF3_GOOD,   20, OFFSET(flags3), OFFSET(r_flags3)},
414                 {TR_KILL_GOOD,   RF3_GOOD,   35, OFFSET(flags3), OFFSET(r_flags3)},
415                 {TR_SLAY_HUMAN,  RF2_HUMAN,  25, OFFSET(flags2), OFFSET(r_flags2)},
416                 {TR_KILL_HUMAN,  RF2_HUMAN,  40, OFFSET(flags2), OFFSET(r_flags2)},
417                 {TR_SLAY_UNDEAD, RF3_UNDEAD, 30, OFFSET(flags3), OFFSET(r_flags3)},
418                 {TR_KILL_UNDEAD, RF3_UNDEAD, 50, OFFSET(flags3), OFFSET(r_flags3)},
419                 {TR_SLAY_DEMON,  RF3_DEMON,  30, OFFSET(flags3), OFFSET(r_flags3)},
420                 {TR_KILL_DEMON,  RF3_DEMON,  50, OFFSET(flags3), OFFSET(r_flags3)},
421                 {TR_SLAY_ORC,    RF3_ORC,    30, OFFSET(flags3), OFFSET(r_flags3)},
422                 {TR_KILL_ORC,    RF3_ORC,    50, OFFSET(flags3), OFFSET(r_flags3)},
423                 {TR_SLAY_TROLL,  RF3_TROLL,  30, OFFSET(flags3), OFFSET(r_flags3)},
424                 {TR_KILL_TROLL,  RF3_TROLL,  50, OFFSET(flags3), OFFSET(r_flags3)},
425                 {TR_SLAY_GIANT,  RF3_GIANT,  30, OFFSET(flags3), OFFSET(r_flags3)},
426                 {TR_KILL_GIANT,  RF3_GIANT,  50, OFFSET(flags3), OFFSET(r_flags3)},
427                 {TR_SLAY_DRAGON, RF3_DRAGON, 30, OFFSET(flags3), OFFSET(r_flags3)},
428                 {TR_KILL_DRAGON, RF3_DRAGON, 50, OFFSET(flags3), OFFSET(r_flags3)},
429 #undef OFFSET
430         };
431         int i;
432         monster_race* r_ptr = &r_info[m_ptr->r_idx];
433
434         for (i = 0; i < sizeof(slay_table) / sizeof(slay_table[0]); ++ i)
435         {
436                 const struct slay_table_t* p = &slay_table[i];
437
438                 if ((have_flag(flgs, p->slay_flag)) &&
439                     (atoffset(u32b, r_ptr, p->flag_offset) & p->affect_race_flag))
440                 {
441                         if (is_original_ap_and_seen(m_ptr))
442                         {
443                                 atoffset(u32b, r_ptr, p->r_flag_offset) |= p->affect_race_flag;
444                         }
445
446                         mult = MAX(mult, p->slay_mult);
447                 }
448         }
449
450         return mult;
451 }
452
453 /*!
454  * @brief プレイヤー攻撃の属性スレイング倍率計算
455  * @param mult 算出前の基本倍率(/10倍)
456  * @param flgs スレイフラグ配列
457  * @param m_ptr 目標モンスターの構造体参照ポインタ
458  * @return スレイング加味後の倍率(/10倍)
459  */
460 static int mult_brand(int mult, const u32b* flgs, const monster_type* m_ptr)
461 {
462         static const struct brand_table_t {
463                 int brand_flag;
464                 u32b resist_mask;
465                 u32b hurt_flag;
466         } brand_table[] = {
467                 {TR_BRAND_ACID, RFR_EFF_IM_ACID_MASK, 0U           },
468                 {TR_BRAND_ELEC, RFR_EFF_IM_ELEC_MASK, 0U           },
469                 {TR_BRAND_FIRE, RFR_EFF_IM_FIRE_MASK, RF3_HURT_FIRE},
470                 {TR_BRAND_COLD, RFR_EFF_IM_COLD_MASK, RF3_HURT_COLD},
471                 {TR_BRAND_POIS, RFR_EFF_IM_POIS_MASK, 0U           },
472         };
473         int i;
474         monster_race* r_ptr = &r_info[m_ptr->r_idx];
475
476         for (i = 0; i < sizeof(brand_table) / sizeof(brand_table[0]); ++ i)
477         {
478                 const struct brand_table_t* p = &brand_table[i];
479
480                 if (have_flag(flgs, p->brand_flag))
481                 {
482                         /* Notice immunity */
483                         if (r_ptr->flagsr & p->resist_mask)
484                         {
485                                 if (is_original_ap_and_seen(m_ptr))
486                                 {
487                                         r_ptr->r_flagsr |= (r_ptr->flagsr & p->resist_mask);
488                                 }
489                         }
490
491                         /* Otherwise, take the damage */
492                         else if (r_ptr->flags3 & p->hurt_flag)
493                         {
494                                 if (is_original_ap_and_seen(m_ptr))
495                                 {
496                                         r_ptr->r_flags3 |= p->hurt_flag;
497                                 }
498
499                                 mult = MAX(mult, 50);
500                         }
501                         else
502                         {
503                                 mult = MAX(mult, 25);
504                         }
505                 }
506         }
507
508         return mult;
509 }
510
511 /*!
512  * @brief ダメージにスレイ要素を加える総合処理ルーチン /
513  * Extract the "total damage" from a given object hitting a given monster.
514  * @param o_ptr 使用武器オブジェクトの構造体参照ポインタ
515  * @param tdam 現在算出途中のダメージ値
516  * @param m_ptr 目標モンスターの構造体参照ポインタ
517  * @param mode 剣術のID
518  * @param thrown 射撃処理ならばTRUEを指定する
519  * @return 総合的なスレイを加味したダメージ値
520  * @note
521  * Note that "flasks of oil" do NOT do fire damage, although they\n
522  * certainly could be made to do so.  XXX XXX\n
523  *\n
524  * Note that most brands and slays are x3, except Slay Animal (x2),\n
525  * Slay Evil (x2), and Kill dragon (x5).\n
526  */
527 s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, int mode, bool thrown)
528 {
529         int mult = 10;
530
531         u32b flgs[TR_FLAG_SIZE];
532
533         /* Extract the flags */
534         object_flags(o_ptr, flgs);
535         torch_flags(o_ptr, flgs); /* torches has secret flags */
536
537         if (!thrown)
538         {
539                 /* Magical Swords */
540                 if (p_ptr->special_attack & (ATTACK_ACID)) add_flag(flgs, TR_BRAND_ACID);
541                 if (p_ptr->special_attack & (ATTACK_COLD)) add_flag(flgs, TR_BRAND_COLD);
542                 if (p_ptr->special_attack & (ATTACK_ELEC)) add_flag(flgs, TR_BRAND_ELEC);
543                 if (p_ptr->special_attack & (ATTACK_FIRE)) add_flag(flgs, TR_BRAND_FIRE);
544                 if (p_ptr->special_attack & (ATTACK_POIS)) add_flag(flgs, TR_BRAND_POIS);
545         }
546
547         /* Hex - Slay Good (Runesword) */
548         if (hex_spelling(HEX_RUNESWORD)) add_flag(flgs, TR_SLAY_GOOD);
549
550         /* Some "weapons" and "ammo" do extra damage */
551         switch (o_ptr->tval)
552         {
553                 case TV_SHOT:
554                 case TV_ARROW:
555                 case TV_BOLT:
556                 case TV_HAFTED:
557                 case TV_POLEARM:
558                 case TV_SWORD:
559                 case TV_DIGGING:
560                 case TV_LITE:
561                 {
562                         /* Slaying */
563                         mult = mult_slaying(mult, flgs, m_ptr);
564
565                         /* Elemental Brand */
566                         mult = mult_brand(mult, flgs, m_ptr);
567
568                         /* Hissatsu */
569                         if (p_ptr->pclass == CLASS_SAMURAI)
570                         {
571                                 mult = mult_hissatsu(mult, flgs, m_ptr, mode);
572                         }
573
574                         /* Force Weapon */
575                         if ((p_ptr->pclass != CLASS_SAMURAI) && (have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (o_ptr->dd * o_ptr->ds / 5)))
576                         {
577                                 p_ptr->csp -= (1+(o_ptr->dd * o_ptr->ds / 5));
578                                 p_ptr->redraw |= (PR_MANA);
579                                 mult = mult * 3 / 2 + 20;
580                         }
581
582                         /* Hack -- The Nothung cause special damage to Fafner */
583                         if ((o_ptr->name1 == ART_NOTHUNG) && (m_ptr->r_idx == MON_FAFNER))
584                                 mult = 150;
585                         break;
586                 }
587         }
588         if (mult > 150) mult = 150;
589
590         /* Return the total damage */
591         return (tdam * mult / 10);
592 }
593
594
595 /*!
596  * @brief 地形やその上のアイテムの隠された要素を明かす /
597  * Search for hidden things
598  * @param y 対象となるマスのY座標
599  * @param x 対象となるマスのX座標
600  * @return なし
601  */
602 static void discover_hidden_things(int y, int x)
603 {
604         s16b this_o_idx, next_o_idx = 0;
605
606         cave_type *c_ptr;
607
608         /* Access the grid */
609         c_ptr = &cave[y][x];
610
611         /* Invisible trap */
612         if (c_ptr->mimic && is_trap(c_ptr->feat))
613         {
614                 /* Pick a trap */
615                 disclose_grid(y, x);
616
617                 /* Message */
618                 msg_print(_("トラップを発見した。", "You have found a trap."));
619
620                 /* Disturb */
621                 disturb(0, 1);
622         }
623
624         /* Secret door */
625         if (is_hidden_door(c_ptr))
626         {
627                 /* Message */
628                 msg_print(_("隠しドアを発見した。", "You have found a secret door."));
629
630                 /* Disclose */
631                 disclose_grid(y, x);
632
633                 /* Disturb */
634                 disturb(0, 0);
635         }
636
637         /* Scan all objects in the grid */
638         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
639         {
640                 object_type *o_ptr;
641
642                 /* Acquire object */
643                 o_ptr = &o_list[this_o_idx];
644
645                 /* Acquire next object */
646                 next_o_idx = o_ptr->next_o_idx;
647
648                 /* Skip non-chests */
649                 if (o_ptr->tval != TV_CHEST) continue;
650
651                 /* Skip non-trapped chests */
652                 if (!chest_traps[o_ptr->pval]) continue;
653
654                 /* Identify once */
655                 if (!object_is_known(o_ptr))
656                 {
657                         /* Message */
658                         msg_print(_("箱に仕掛けられたトラップを発見した!", "You have discovered a trap on the chest!"));
659
660                         /* Know the trap */
661                         object_known(o_ptr);
662
663                         /* Notice it */
664                         disturb(0, 0);
665                 }
666         }
667 }
668
669 /*!
670  * @brief プレイヤーの探索処理判定
671  * @return なし
672  */
673 void search(void)
674 {
675         int i, chance;
676
677         /* Start with base search ability */
678         chance = p_ptr->skill_srh;
679
680         /* Penalize various conditions */
681         if (p_ptr->blind || no_lite()) chance = chance / 10;
682         if (p_ptr->confused || p_ptr->image) chance = chance / 10;
683
684         /* Search the nearby grids, which are always in bounds */
685         for (i = 0; i < 9; ++ i)
686         {
687                 /* Sometimes, notice things */
688                 if (randint0(100) < chance)
689                 {
690                         discover_hidden_things(py + ddy_ddd[i], px + ddx_ddd[i]);
691                 }
692         }
693 }
694
695
696 /*!
697  * @brief プレイヤーがオブジェクトを拾った際のメッセージ表示処理 /
698  * Helper routine for py_pickup() and py_pickup_floor().
699  * @param o_idx 取得したオブジェクトの参照ID
700  * @return なし
701  * @details
702  * アイテムを拾った際に「2つのケーキを持っている」\n
703  * "You have two cakes." とアイテムを拾った後の合計のみの表示がオリジナル\n
704  * だが、違和感が\n
705  * あるという指摘をうけたので、「~を拾った、~を持っている」という表示\n
706  * にかえてある。そのための配列。\n
707  * Add the given dungeon object to the character's inventory.\n
708  * Delete the object afterwards.\n
709  */
710 void py_pickup_aux(int o_idx)
711 {
712         int slot;
713
714 #ifdef JP
715         char o_name[MAX_NLEN];
716         char old_name[MAX_NLEN];
717         char kazu_str[80];
718         int hirottakazu;
719 #else
720         char o_name[MAX_NLEN];
721 #endif
722
723         object_type *o_ptr;
724
725         o_ptr = &o_list[o_idx];
726
727 #ifdef JP
728         /* Describe the object */
729         object_desc(old_name, o_ptr, OD_NAME_ONLY);
730         object_desc_kosuu(kazu_str, o_ptr);
731         hirottakazu = o_ptr->number;
732 #endif
733         /* Carry the object */
734         slot = inven_carry(o_ptr);
735
736         /* Get the object again */
737         o_ptr = &inventory[slot];
738
739         /* Delete the object */
740         delete_object_idx(o_idx);
741
742         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
743         {
744                 bool old_known = identify_item(o_ptr);
745
746                 /* Auto-inscription/destroy */
747                 autopick_alter_item(slot, (bool)(destroy_identify && !old_known));
748
749                 /* If it is destroyed, don't pick it up */
750                 if (o_ptr->marked & OM_AUTODESTROY) return;
751         }
752
753         /* Describe the object */
754         object_desc(o_name, o_ptr, 0);
755
756         /* Message */
757 #ifdef JP
758         if ((o_ptr->name1 == ART_CRIMSON) && (p_ptr->pseikaku == SEIKAKU_COMBAT))
759         {
760                 msg_format("こうして、%sは『クリムゾン』を手に入れた。", player_name);
761                 msg_print("しかし今、『混沌のサーペント』の放ったモンスターが、");
762                 msg_format("%sに襲いかかる...", player_name);
763         }
764         else
765         {
766                 if (plain_pickup)
767                 {
768                         msg_format("%s(%c)を持っている。",o_name, index_to_label(slot));
769                 }
770                 else
771                 {
772                         if (o_ptr->number > hirottakazu) {
773                             msg_format("%s拾って、%s(%c)を持っている。",
774                                kazu_str, o_name, index_to_label(slot));
775                         } else {
776                                 msg_format("%s(%c)を拾った。", o_name, index_to_label(slot));
777                         }
778                 }
779         }
780         strcpy(record_o_name, old_name);
781 #else
782         msg_format("You have %s (%c).", o_name, index_to_label(slot));
783         strcpy(record_o_name, o_name);
784 #endif
785         record_turn = turn;
786
787
788         check_find_art_quest_completion(o_ptr);
789 }
790
791
792 /*!
793  * @brief プレイヤーがオブジェクト上に乗った際の表示処理
794  * @param pickup 自動拾い処理を行うならばTRUEとする
795  * @return なし
796  * @details
797  * Player "wants" to pick up an object or gold.
798  * Note that we ONLY handle things that can be picked up.
799  * See "move_player()" for handling of other things.
800  */
801 void carry(bool pickup)
802 {
803         cave_type *c_ptr = &cave[py][px];
804
805         s16b this_o_idx, next_o_idx = 0;
806
807         char    o_name[MAX_NLEN];
808
809         /* Recenter the map around the player */
810         verify_panel();
811
812         /* Update stuff */
813         p_ptr->update |= (PU_MONSTERS);
814
815         /* Redraw map */
816         p_ptr->redraw |= (PR_MAP);
817
818         /* Window stuff */
819         p_ptr->window |= (PW_OVERHEAD);
820
821         /* Handle stuff */
822         handle_stuff();
823
824         /* Automatically pickup/destroy/inscribe items */
825         autopick_pickup_items(c_ptr);
826
827
828 #ifdef ALLOW_EASY_FLOOR
829
830         if (easy_floor)
831         {
832                 py_pickup_floor(pickup);
833                 return;
834         }
835
836 #endif /* ALLOW_EASY_FLOOR */
837
838         /* Scan the pile of objects */
839         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
840         {
841                 object_type *o_ptr;
842
843                 /* Acquire object */
844                 o_ptr = &o_list[this_o_idx];
845
846 #ifdef ALLOW_EASY_SENSE /* TNB */
847
848                 /* Option: Make item sensing easy */
849                 if (easy_sense)
850                 {
851                         /* Sense the object */
852                         (void)sense_object(o_ptr);
853                 }
854
855 #endif /* ALLOW_EASY_SENSE -- TNB */
856
857                 /* Describe the object */
858                 object_desc(o_name, o_ptr, 0);
859
860                 /* Acquire next object */
861                 next_o_idx = o_ptr->next_o_idx;
862
863                 /* Hack -- disturb */
864                 disturb(0, 0);
865
866                 /* Pick up gold */
867                 if (o_ptr->tval == TV_GOLD)
868                 {
869                         int value = (long)o_ptr->pval;
870
871                         /* Delete the gold */
872                         delete_object_idx(this_o_idx);
873
874                         /* Message */
875 #ifdef JP
876                 msg_format(" $%ld の価値がある%sを見つけた。",
877                            (long)value, o_name);
878 #else
879                         msg_format("You collect %ld gold pieces worth of %s.",
880                                    (long)value, o_name);
881 #endif
882
883
884                         sound(SOUND_SELL);
885
886                         /* Collect the gold */
887                         p_ptr->au += value;
888
889                         /* Redraw gold */
890                         p_ptr->redraw |= (PR_GOLD);
891
892                         /* Window stuff */
893                         p_ptr->window |= (PW_PLAYER);
894                 }
895
896                 /* Pick up objects */
897                 else
898                 {
899                         /* Hack - some objects were handled in autopick_pickup_items(). */
900                         if (o_ptr->marked & OM_NOMSG)
901                         {
902                                 /* Clear the flag. */
903                                 o_ptr->marked &= ~OM_NOMSG;
904                         }
905                         /* Describe the object */
906                         else if (!pickup)
907                         {
908 #ifdef JP
909                                 msg_format("%sがある。", o_name);
910 #else
911                                 msg_format("You see %s.", o_name);
912 #endif
913
914                         }
915
916                         /* Note that the pack is too full */
917                         else if (!inven_carry_okay(o_ptr))
918                         {
919 #ifdef JP
920                                 msg_format("ザックには%sを入れる隙間がない。", o_name);
921 #else
922                                 msg_format("You have no room for %s.", o_name);
923 #endif
924
925                         }
926
927                         /* Pick up the item (if requested and allowed) */
928                         else
929                         {
930                                 int okay = TRUE;
931
932                                 /* Hack -- query every item */
933                                 if (carry_query_flag)
934                                 {
935                                         char out_val[MAX_NLEN+20];
936 #ifdef JP
937                                         sprintf(out_val, "%sを拾いますか? ", o_name);
938 #else
939                                         sprintf(out_val, "Pick up %s? ", o_name);
940 #endif
941
942                                         okay = get_check(out_val);
943                                 }
944
945                                 /* Attempt to pick up an object. */
946                                 if (okay)
947                                 {
948                                         /* Pick up the object */
949                                         py_pickup_aux(this_o_idx);
950                                 }
951                         }
952                 }
953         }
954 }
955
956
957 /*!
958  * @brief プレイヤーへのトラップ命中判定 /
959  * Determine if a trap affects the player.
960  * @param power 基本回避難度
961  * @return トラップが命中した場合TRUEを返す。
962  * @details
963  * Always miss 5% of the time, Always hit 5% of the time.
964  * Otherwise, match trap power against player armor.
965  */
966 static int check_hit(int power)
967 {
968         int k, ac;
969
970         /* Percentile dice */
971         k = randint0(100);
972
973         /* Hack -- 5% hit, 5% miss */
974         if (k < 10) return (k < 5);
975
976         if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
977                 if (one_in_(20)) return (TRUE);
978
979         /* Paranoia -- No power */
980         if (power <= 0) return (FALSE);
981
982         /* Total armor */
983         ac = p_ptr->ac + p_ptr->to_a;
984
985         /* Power competes against Armor */
986         if (randint1(power) > ((ac * 3) / 4)) return (TRUE);
987
988         /* Assume miss */
989         return (FALSE);
990 }
991
992
993 /*!
994  * @brief 落とし穴系トラップの判定とプレイヤーの被害処理
995  * @param trap_feat_type トラップの種別ID
996  * @return なし
997  */
998 static void hit_trap_pit(int trap_feat_type)
999 {
1000         int dam;
1001         cptr trap_name = "";
1002         cptr spike_name = "";
1003
1004         switch (trap_feat_type)
1005         {
1006         case TRAP_PIT:
1007                 trap_name = _("落とし穴", "a pit trap");
1008                 break;
1009         case TRAP_SPIKED_PIT:
1010                 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
1011                 spike_name = _("スパイク", "spikes");
1012                 break;
1013         case TRAP_POISON_PIT:
1014                 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
1015                 spike_name = _("毒を塗られたスパイク", "poisonous spikes");
1016                 break;
1017         default:
1018                 return;
1019         }
1020
1021         if (p_ptr->levitation)
1022         {
1023                 msg_format(_("%sを飛び越えた。", "You fly over %s."), trap_name);
1024                 return;
1025         }
1026
1027         msg_format(_("%sに落ちてしまった!", "You have fallen into %s!"), trap_name);
1028
1029         /* Base damage */
1030         dam = damroll(2, 6);
1031
1032         /* Extra spike damage */
1033         if ((trap_feat_type == TRAP_SPIKED_PIT || trap_feat_type == TRAP_POISON_PIT) &&
1034             one_in_(2))
1035         {
1036                 msg_format(_("%sが刺さった!", "You are impaled on %s!"), spike_name);
1037
1038                 dam = dam * 2;
1039                 (void)set_cut(p_ptr->cut + randint1(dam));
1040
1041                 if (trap_feat_type == TRAP_POISON_PIT) {
1042                         if (p_ptr->resist_pois || IS_OPPOSE_POIS())
1043                         {
1044                                 msg_print(_("しかし毒の影響はなかった!", "The poison does not affect you!"));
1045                         }
1046                         else
1047                         {
1048                                 dam = dam * 2;
1049                                 (void)set_poisoned(p_ptr->poisoned + randint1(dam));
1050                         }
1051                 }
1052         }
1053
1054         /* Take the damage */
1055         take_hit(DAMAGE_NOESCAPE, dam, trap_name, -1);
1056 }
1057
1058 /*!
1059  * @brief ダーツ系トラップ(通常ダメージ)の判定とプレイヤーの被害処理
1060  * @return ダーツが命中した場合TRUEを返す
1061  */
1062 static bool hit_trap_dart(void)
1063 {
1064         bool hit = FALSE;
1065
1066         if (check_hit(125))
1067         {
1068                 msg_print(_("小さなダーツが飛んできて刺さった!", "A small dart hits you!"));
1069
1070                 take_hit(DAMAGE_ATTACK, damroll(1, 4), _("ダーツの罠", "a dart trap"), -1);
1071
1072                 if (!CHECK_MULTISHADOW()) hit = TRUE;
1073         }
1074         else
1075         {
1076                 msg_print(_("小さなダーツが飛んできた!が、運良く当たらなかった。", "A small dart barely misses you."));
1077         }
1078
1079         return hit;
1080 }
1081
1082 /*!
1083  * @brief ダーツ系トラップ(通常ダメージ+能力値減少)の判定とプレイヤーの被害処理
1084  * @param stat 低下する能力値ID
1085  * @return なし
1086  */
1087 static void hit_trap_lose_stat(int stat)
1088 {
1089         if (hit_trap_dart())
1090         {
1091                 do_dec_stat(stat);
1092         }
1093 }
1094
1095 /*!
1096  * @brief ダーツ系トラップ(通常ダメージ+減速)の判定とプレイヤーの被害処理
1097  * @return なし
1098  */
1099 static void hit_trap_slow(void)
1100 {
1101         if (hit_trap_dart())
1102         {
1103                 set_slow(p_ptr->slow + randint0(20) + 20, FALSE);
1104         }
1105 }
1106
1107 /*!
1108  * @brief ダーツ系トラップ(通常ダメージ+状態異常)の判定とプレイヤーの被害処理
1109  * @param trap_message メッセージの補完文字列
1110  * @param resist 状態異常に抵抗する判定が出たならTRUE
1111  * @param set_status 状態異常を指定する関数ポインタ
1112  * @param turn 状態異常の追加ターン量
1113  * @return なし
1114  */
1115 static void hit_trap_set_abnormal_status(cptr trap_message, bool resist, bool (*set_status)(int turn), int turn)
1116 {
1117         msg_print(trap_message);
1118
1119         if (!resist)
1120         {
1121                 set_status(turn);
1122         }
1123 }
1124
1125 /*!
1126  * @brief プレイヤーへのトラップ作動処理メインルーチン /
1127  * Handle player hitting a real trap
1128  * @param break_trap 作動後のトラップ破壊が確定しているならばTRUE
1129  * @return なし
1130  */
1131 static void hit_trap(bool break_trap)
1132 {
1133         int i, num, dam;
1134         int x = px, y = py;
1135
1136         /* Get the cave grid */
1137         cave_type *c_ptr = &cave[y][x];
1138         feature_type *f_ptr = &f_info[c_ptr->feat];
1139         int trap_feat_type = have_flag(f_ptr->flags, FF_TRAP) ? f_ptr->subtype : NOT_TRAP;
1140
1141 #ifdef JP
1142         cptr name = "トラップ";
1143 #else
1144         cptr name = "a trap";
1145 #endif
1146
1147         /* Disturb the player */
1148         disturb(0, 1);
1149
1150         cave_alter_feat(y, x, FF_HIT_TRAP);
1151
1152         /* Analyze XXX XXX XXX */
1153         switch (trap_feat_type)
1154         {
1155                 case TRAP_TRAPDOOR:
1156                 {
1157                         if (p_ptr->levitation)
1158                         {
1159 #ifdef JP
1160                                 msg_print("落とし戸を飛び越えた。");
1161 #else
1162                                 msg_print("You fly over a trap door.");
1163 #endif
1164
1165                         }
1166                         else
1167                         {
1168 #ifdef JP
1169                                 msg_print("落とし戸に落ちた!");
1170                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1171                                         msg_print("くっそ~!");
1172 #else
1173                                 msg_print("You have fallen through a trap door!");
1174 #endif
1175
1176                                 sound(SOUND_FALL);
1177                                 dam = damroll(2, 8);
1178 #ifdef JP
1179                                 name = "落とし戸";
1180 #else
1181                                 name = "a trap door";
1182 #endif
1183
1184                                 take_hit(DAMAGE_NOESCAPE, dam, name, -1);
1185
1186                                 /* Still alive and autosave enabled */
1187                                 if (autosave_l && (p_ptr->chp >= 0))
1188                                         do_cmd_save_game(TRUE);
1189
1190 #ifdef JP
1191                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "落とし戸に落ちた");
1192 #else
1193                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "You have fallen through a trap door!");
1194 #endif
1195                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
1196
1197                                 /* Leaving */
1198                                 p_ptr->leaving = TRUE;
1199                         }
1200                         break;
1201                 }
1202
1203                 case TRAP_PIT:
1204                 case TRAP_SPIKED_PIT:
1205                 case TRAP_POISON_PIT:
1206                 {
1207                         hit_trap_pit(trap_feat_type);
1208                         break;
1209                 }
1210
1211                 case TRAP_TY_CURSE:
1212                 {
1213 #ifdef JP
1214                         msg_print("何かがピカッと光った!");
1215 #else
1216                         msg_print("There is a flash of shimmering light!");
1217 #endif
1218
1219                         num = 2 + randint1(3);
1220                         for (i = 0; i < num; i++)
1221                         {
1222                                 (void)summon_specific(0, y, x, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
1223                         }
1224
1225                         if (dun_level > randint1(100)) /* No nasty effect for low levels */
1226                         {
1227                                 bool stop_ty = FALSE;
1228                                 int count = 0;
1229
1230                                 do
1231                                 {
1232                                         stop_ty = activate_ty_curse(stop_ty, &count);
1233                                 }
1234                                 while (one_in_(6));
1235                         }
1236                         break;
1237                 }
1238
1239                 case TRAP_TELEPORT:
1240                 {
1241 #ifdef JP
1242                         msg_print("テレポート・トラップにひっかかった!");
1243 #else
1244                         msg_print("You hit a teleport trap!");
1245 #endif
1246
1247                         teleport_player(100, TELEPORT_PASSIVE);
1248                         break;
1249                 }
1250
1251                 case TRAP_FIRE:
1252                 {
1253 #ifdef JP
1254                         msg_print("炎に包まれた!");
1255 #else
1256                         msg_print("You are enveloped in flames!");
1257 #endif
1258
1259                         dam = damroll(4, 6);
1260 #ifdef JP
1261                         (void)fire_dam(dam, "炎のトラップ", -1, FALSE);
1262 #else
1263                         (void)fire_dam(dam, "a fire trap", -1, FALSE);
1264 #endif
1265
1266                         break;
1267                 }
1268
1269                 case TRAP_ACID:
1270                 {
1271 #ifdef JP
1272                         msg_print("酸が吹きかけられた!");
1273 #else
1274                         msg_print("You are splashed with acid!");
1275 #endif
1276
1277                         dam = damroll(4, 6);
1278 #ifdef JP
1279                         (void)acid_dam(dam, "酸のトラップ", -1, FALSE);
1280 #else
1281                         (void)acid_dam(dam, "an acid trap", -1, FALSE);
1282 #endif
1283
1284                         break;
1285                 }
1286
1287                 case TRAP_SLOW:
1288                 {
1289                         hit_trap_slow();
1290                         break;
1291                 }
1292
1293                 case TRAP_LOSE_STR:
1294                 {
1295                         hit_trap_lose_stat(A_STR);
1296                         break;
1297                 }
1298
1299                 case TRAP_LOSE_DEX:
1300                 {
1301                         hit_trap_lose_stat(A_DEX);
1302                         break;
1303                 }
1304
1305                 case TRAP_LOSE_CON:
1306                 {
1307                         hit_trap_lose_stat(A_CON);
1308                         break;
1309                 }
1310
1311                 case TRAP_BLIND:
1312                 {
1313                         hit_trap_set_abnormal_status(
1314                                 _("黒いガスに包み込まれた!", "A black gas surrounds you!"),
1315                                 p_ptr->resist_blind,
1316                                 set_blind, p_ptr->blind + randint0(50) + 25);
1317                         break;
1318                 }
1319
1320                 case TRAP_CONFUSE:
1321                 {
1322                         hit_trap_set_abnormal_status(
1323                                 _("きらめくガスに包み込まれた!", "A gas of scintillating colors surrounds you!"),
1324                                 p_ptr->resist_conf,
1325                                 set_confused, p_ptr->confused + randint0(20) + 10);
1326                         break;
1327                 }
1328
1329                 case TRAP_POISON:
1330                 {
1331                         hit_trap_set_abnormal_status(
1332                                 _("刺激的な緑色のガスに包み込まれた!", "A pungent green gas surrounds you!"),
1333                                 p_ptr->resist_pois || IS_OPPOSE_POIS(),
1334                                 set_poisoned, p_ptr->poisoned + randint0(20) + 10);
1335                         break;
1336                 }
1337
1338                 case TRAP_SLEEP:
1339                 {
1340 #ifdef JP
1341                         msg_print("奇妙な白い霧に包まれた!");
1342 #else
1343                         msg_print("A strange white mist surrounds you!");
1344 #endif
1345
1346                         if (!p_ptr->free_act)
1347                         {
1348 #ifdef JP
1349 msg_print("あなたは眠りに就いた。");
1350 #else
1351                                 msg_print("You fall asleep.");
1352 #endif
1353
1354
1355                                 if (ironman_nightmare)
1356                                 {
1357 #ifdef JP
1358 msg_print("身の毛もよだつ光景が頭に浮かんだ。");
1359 #else
1360                                         msg_print("A horrible vision enters your mind.");
1361 #endif
1362
1363
1364                                         /* Pick a nightmare */
1365                                         get_mon_num_prep(get_nightmare, NULL);
1366
1367                                         /* Have some nightmares */
1368                                         have_nightmare(get_mon_num(MAX_DEPTH));
1369
1370                                         /* Remove the monster restriction */
1371                                         get_mon_num_prep(NULL, NULL);
1372                                 }
1373                                 (void)set_paralyzed(p_ptr->paralyzed + randint0(10) + 5);
1374                         }
1375                         break;
1376                 }
1377
1378                 case TRAP_TRAPS:
1379                 {
1380 #ifdef JP
1381 msg_print("まばゆい閃光が走った!");
1382 #else
1383                         msg_print("There is a bright flash of light!");
1384 #endif
1385
1386                         /* Make some new traps */
1387                         project(0, 1, y, x, 0, GF_MAKE_TRAP, PROJECT_HIDE | PROJECT_JUMP | PROJECT_GRID, -1);
1388
1389                         break;
1390                 }
1391
1392                 case TRAP_ALARM:
1393                 {
1394 #ifdef JP
1395                         msg_print("けたたましい音が鳴り響いた!");
1396 #else
1397                         msg_print("An alarm sounds!");
1398 #endif
1399
1400                         aggravate_monsters(0);
1401
1402                         break;
1403                 }
1404
1405                 case TRAP_OPEN:
1406                 {
1407 #ifdef JP
1408                         msg_print("大音響と共にまわりの壁が崩れた!");
1409 #else
1410                         msg_print("Suddenly, surrounding walls are opened!");
1411 #endif
1412                         (void)project(0, 3, y, x, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
1413                         (void)project(0, 3, y, x - 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
1414                         (void)project(0, 3, y, x + 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
1415                         aggravate_monsters(0);
1416
1417                         break;
1418                 }
1419
1420                 case TRAP_ARMAGEDDON:
1421                 {
1422                         static int levs[10] = {0, 0, 20, 10, 5, 3, 2, 1, 1, 1};
1423                         int evil_idx = 0, good_idx = 0;
1424
1425                         int lev;
1426 #ifdef JP
1427                         msg_print("突然天界の戦争に巻き込まれた!");
1428 #else
1429                         msg_print("Suddenly, you are surrounded by immotal beings!");
1430 #endif
1431
1432                         /* Summon Demons and Angels */
1433                         for (lev = dun_level; lev >= 20; lev -= 1 + lev/16)
1434                         {
1435                                 num = levs[MIN(lev/10, 9)];
1436                                 for (i = 0; i < num; i++)
1437                                 {
1438                                         int x1 = rand_spread(x, 7);
1439                                         int y1 = rand_spread(y, 5);
1440
1441                                         /* Skip illegal grids */
1442                                         if (!in_bounds(y1, x1)) continue;
1443
1444                                         /* Require line of projection */
1445                                         if (!projectable(py, px, y1, x1)) continue;
1446
1447                                         if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET)))
1448                                                 evil_idx = hack_m_idx_ii;
1449
1450                                         if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET)))
1451                                         {
1452                                                 good_idx = hack_m_idx_ii;
1453                                         }
1454
1455                                         /* Let them fight each other */
1456                                         if (evil_idx && good_idx)
1457                                         {
1458                                                 monster_type *evil_ptr = &m_list[evil_idx];
1459                                                 monster_type *good_ptr = &m_list[good_idx];
1460                                                 evil_ptr->target_y = good_ptr->fy;
1461                                                 evil_ptr->target_x = good_ptr->fx;
1462                                                 good_ptr->target_y = evil_ptr->fy;
1463                                                 good_ptr->target_x = evil_ptr->fx;
1464                                         }
1465                                 }
1466                         }
1467                         break;
1468                 }
1469
1470                 case TRAP_PIRANHA:
1471                 {
1472 #ifdef JP
1473                         msg_print("突然壁から水が溢れ出した!ピラニアがいる!");
1474 #else
1475                         msg_print("Suddenly, the room is filled with water with piranhas!");
1476 #endif
1477
1478                         /* Water fills room */
1479                         fire_ball_hide(GF_WATER_FLOW, 0, 1, 10);
1480
1481                         /* Summon Piranhas */
1482                         num = 1 + dun_level/20;
1483                         for (i = 0; i < num; i++)
1484                         {
1485                                 (void)summon_specific(0, y, x, dun_level, SUMMON_PIRANHAS, (PM_ALLOW_GROUP | PM_NO_PET));
1486                         }
1487                         break;
1488                 }
1489         }
1490
1491         if (break_trap && is_trap(c_ptr->feat))
1492         {
1493                 cave_alter_feat(y, x, FF_DISARM);
1494 #ifdef JP
1495                 msg_print("トラップを粉砕した。");
1496 #else
1497                 msg_print("You destroyed the trap.");
1498 #endif
1499         }
1500 }
1501
1502
1503 /*!
1504  * @brief 敵オーラによるプレイヤーのダメージ処理(補助)
1505  * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
1506  * @param immune ダメージを回避できる免疫フラグ
1507  * @param flags_offset オーラフラグ配列の参照オフセット
1508  * @param r_flags_offset モンスターの耐性配列の参照オフセット
1509  * @param aura_flag オーラフラグ配列
1510  * @param dam_func ダメージ処理を行う関数の参照ポインタ
1511  * @param message オーラダメージを受けた際のメッセージ
1512  * @return なし
1513  */
1514 static void touch_zap_player_aux(monster_type *m_ptr, bool immune, int flags_offset, int r_flags_offset, u32b aura_flag,
1515                                  int (*dam_func)(int dam, cptr kb_str, int monspell, bool aura), cptr message)
1516 {
1517         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1518
1519         if ((atoffset(u32b, r_ptr, flags_offset) & aura_flag) && !immune)
1520         {
1521                 char mon_name[80];
1522                 int aura_damage = damroll(1 + (r_ptr->level / 26), 1 + (r_ptr->level / 17));
1523
1524                 /* Hack -- Get the "died from" name */
1525                 monster_desc(mon_name, m_ptr, MD_IGNORE_HALLU | MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
1526
1527                 msg_print(message);
1528
1529                 dam_func(aura_damage, mon_name, -1, TRUE);
1530
1531                 if (is_original_ap_and_seen(m_ptr))
1532                 {
1533                         atoffset(u32b, r_ptr, r_flags_offset) |= aura_flag;
1534                 }
1535
1536                 handle_stuff();
1537         }
1538 }
1539
1540 /*!
1541  * @brief 敵オーラによるプレイヤーのダメージ処理(メイン)
1542  * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
1543  * @return なし
1544  */
1545 static void touch_zap_player(monster_type *m_ptr)
1546 {
1547         touch_zap_player_aux(m_ptr, p_ptr->immune_fire, offsetof(monster_race, flags2), offsetof(monster_race, r_flags2), RF2_AURA_FIRE,
1548                              fire_dam, _("突然とても熱くなった!", "You are suddenly very hot!"));
1549         touch_zap_player_aux(m_ptr, p_ptr->immune_cold, offsetof(monster_race, flags3), offsetof(monster_race, r_flags3), RF3_AURA_COLD,
1550                              cold_dam, _("突然とても寒くなった!", "You are suddenly very cold!"));
1551         touch_zap_player_aux(m_ptr, p_ptr->immune_elec, offsetof(monster_race, flags2), offsetof(monster_race, r_flags2), RF2_AURA_ELEC,
1552                              elec_dam, _("電撃をくらった!", "You get zapped!"));
1553 }
1554
1555
1556 /*!
1557  * @brief プレイヤーの変異要素による打撃処理
1558  * @param m_idx 攻撃目標となったモンスターの参照ID
1559  * @param attack 変異要素による攻撃要素の種類
1560  * @param fear 攻撃を受けたモンスターが恐慌状態に陥ったかを返す参照ポインタ
1561  * @param mdeath 攻撃を受けたモンスターが死亡したかを返す参照ポインタ
1562  * @return なし
1563  */
1564 static void natural_attack(s16b m_idx, int attack, bool *fear, bool *mdeath)
1565 {
1566         int             k, bonus, chance;
1567         int             n_weight = 0;
1568         monster_type    *m_ptr = &m_list[m_idx];
1569         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1570         char            m_name[80];
1571
1572         int             dss, ddd;
1573
1574         cptr            atk_desc;
1575
1576         switch (attack)
1577         {
1578                 case MUT2_SCOR_TAIL:
1579                         dss = 3;
1580                         ddd = 7;
1581                         n_weight = 5;
1582 #ifdef JP
1583                         atk_desc = "尻尾";
1584 #else
1585                         atk_desc = "tail";
1586 #endif
1587
1588                         break;
1589                 case MUT2_HORNS:
1590                         dss = 2;
1591                         ddd = 6;
1592                         n_weight = 15;
1593 #ifdef JP
1594                         atk_desc = "角";
1595 #else
1596                         atk_desc = "horns";
1597 #endif
1598
1599                         break;
1600                 case MUT2_BEAK:
1601                         dss = 2;
1602                         ddd = 4;
1603                         n_weight = 5;
1604 #ifdef JP
1605                         atk_desc = "クチバシ";
1606 #else
1607                         atk_desc = "beak";
1608 #endif
1609
1610                         break;
1611                 case MUT2_TRUNK:
1612                         dss = 1;
1613                         ddd = 4;
1614                         n_weight = 35;
1615 #ifdef JP
1616                         atk_desc = "象の鼻";
1617 #else
1618                         atk_desc = "trunk";
1619 #endif
1620
1621                         break;
1622                 case MUT2_TENTACLES:
1623                         dss = 2;
1624                         ddd = 5;
1625                         n_weight = 5;
1626 #ifdef JP
1627                         atk_desc = "触手";
1628 #else
1629                         atk_desc = "tentacles";
1630 #endif
1631
1632                         break;
1633                 default:
1634                         dss = ddd = n_weight = 1;
1635 #ifdef JP
1636                         atk_desc = "未定義の部位";
1637 #else
1638                         atk_desc = "undefined body part";
1639 #endif
1640
1641         }
1642
1643         /* Extract monster name (or "it") */
1644         monster_desc(m_name, m_ptr, 0);
1645
1646
1647         /* Calculate the "attack quality" */
1648         bonus = p_ptr->to_h_m;
1649         bonus += (p_ptr->lev * 6 / 5);
1650         chance = (p_ptr->skill_thn + (bonus * BTH_PLUS_ADJ));
1651
1652         /* Test for hit */
1653         if ((!(r_ptr->flags2 & RF2_QUANTUM) || !randint0(2)) && test_hit_norm(chance, r_ptr->ac, m_ptr->ml))
1654         {
1655                 /* Sound */
1656                 sound(SOUND_HIT);
1657
1658 #ifdef JP
1659                 msg_format("%sを%sで攻撃した。", m_name, atk_desc);
1660 #else
1661                 msg_format("You hit %s with your %s.", m_name, atk_desc);
1662 #endif
1663
1664
1665                 k = damroll(ddd, dss);
1666                 k = critical_norm(n_weight, bonus, k, (s16b)bonus, 0);
1667
1668                 /* Apply the player damage bonuses */
1669                 k += p_ptr->to_d_m;
1670
1671                 /* No negative damage */
1672                 if (k < 0) k = 0;
1673
1674                 /* Modify the damage */
1675                 k = mon_damage_mod(m_ptr, k, FALSE);
1676
1677                 /* Complex message */
1678                 if (p_ptr->wizard)
1679                 {
1680 #ifdef JP
1681                                 msg_format("%d/%d のダメージを与えた。", k, m_ptr->hp);
1682 #else
1683                         msg_format("You do %d (out of %d) damage.", k, m_ptr->hp);
1684 #endif
1685
1686                 }
1687
1688                 /* Anger the monster */
1689                 if (k > 0) anger_monster(m_ptr);
1690
1691                 /* Damage, check for fear and mdeath */
1692                 switch (attack)
1693                 {
1694                         case MUT2_SCOR_TAIL:
1695                                 project(0, 0, m_ptr->fy, m_ptr->fx, k, GF_POIS, PROJECT_KILL, -1);
1696                                 *mdeath = (m_ptr->r_idx == 0);
1697                                 break;
1698                         case MUT2_HORNS:
1699                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1700                                 break;
1701                         case MUT2_BEAK:
1702                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1703                                 break;
1704                         case MUT2_TRUNK:
1705                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1706                                 break;
1707                         case MUT2_TENTACLES:
1708                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1709                                 break;
1710                         default:
1711                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1712                 }
1713
1714                 touch_zap_player(m_ptr);
1715         }
1716         /* Player misses */
1717         else
1718         {
1719                 /* Sound */
1720                 sound(SOUND_MISS);
1721
1722                 /* Message */
1723 #ifdef JP
1724                         msg_format("ミス! %sにかわされた。", m_name);
1725 #else
1726                 msg_format("You miss %s.", m_name);
1727 #endif
1728
1729         }
1730 }
1731
1732
1733 /*!
1734  * @brief プレイヤーの打撃処理サブルーチン /
1735  * Player attacks a (poor, defenseless) creature        -RAK-
1736  * @param y 攻撃目標のY座標
1737  * @param x 攻撃目標のX座標
1738  * @param fear 攻撃を受けたモンスターが恐慌状態に陥ったかを返す参照ポインタ
1739  * @param mdeath 攻撃を受けたモンスターが死亡したかを返す参照ポインタ
1740  * @param hand 攻撃を行うための武器を持つ手
1741  * @param mode 発動中の剣術ID
1742  * @return なし
1743  * @details
1744  * If no "weapon" is available, then "punch" the monster one time.
1745  */
1746 static void py_attack_aux(int y, int x, bool *fear, bool *mdeath, s16b hand, int mode)
1747 {
1748         int             num = 0, k, bonus, chance, vir;
1749
1750         cave_type       *c_ptr = &cave[y][x];
1751
1752         monster_type    *m_ptr = &m_list[c_ptr->m_idx];
1753         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1754
1755         /* Access the weapon */
1756         object_type     *o_ptr = &inventory[INVEN_RARM + hand];
1757
1758         char            m_name[80];
1759
1760         bool            success_hit = FALSE;
1761         bool            backstab = FALSE;
1762         bool            vorpal_cut = FALSE;
1763         int             chaos_effect = 0;
1764         bool            stab_fleeing = FALSE;
1765         bool            fuiuchi = FALSE;
1766         bool            monk_attack = FALSE;
1767         bool            do_quake = FALSE;
1768         bool            weak = FALSE;
1769         bool            drain_msg = TRUE;
1770         int             drain_result = 0, drain_heal = 0;
1771         bool            can_drain = FALSE;
1772         int             num_blow;
1773         int             drain_left = MAX_VAMPIRIC_DRAIN;
1774         u32b flgs[TR_FLAG_SIZE]; /* A massive hack -- life-draining weapons */
1775         bool            is_human = (r_ptr->d_char == 'p');
1776         bool            is_lowlevel = (r_ptr->level < (p_ptr->lev - 15));
1777         bool            zantetsu_mukou, e_j_mukou;
1778
1779         switch (p_ptr->pclass)
1780         {
1781         case CLASS_ROGUE:
1782         case CLASS_NINJA:
1783                 if (buki_motteruka(INVEN_RARM + hand) && !p_ptr->icky_wield[hand])
1784                 {
1785                         int tmp = p_ptr->lev * 6 + (p_ptr->skill_stl + 10) * 4;
1786                         if (p_ptr->monlite && (mode != HISSATSU_NYUSIN)) tmp /= 3;
1787                         if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1788                         if (r_ptr->level > (p_ptr->lev * p_ptr->lev / 20 + 10)) tmp /= 3;
1789                         if (MON_CSLEEP(m_ptr) && m_ptr->ml)
1790                         {
1791                                 /* Can't backstab creatures that we can't see, right? */
1792                                 backstab = TRUE;
1793                         }
1794                         else if ((p_ptr->special_defense & NINJA_S_STEALTH) && (randint0(tmp) > (r_ptr->level+20)) && m_ptr->ml && !(r_ptr->flagsr & RFR_RES_ALL))
1795                         {
1796                                 fuiuchi = TRUE;
1797                         }
1798                         else if (MON_MONFEAR(m_ptr) && m_ptr->ml)
1799                         {
1800                                 stab_fleeing = TRUE;
1801                         }
1802                 }
1803                 break;
1804
1805         case CLASS_MONK:
1806         case CLASS_FORCETRAINER:
1807         case CLASS_BERSERKER:
1808                 if ((empty_hands(TRUE) & EMPTY_HAND_RARM) && !p_ptr->riding) monk_attack = TRUE;
1809                 break;
1810         }
1811
1812         if (!o_ptr->k_idx) /* Empty hand */
1813         {
1814                 if ((r_ptr->level + 10) > p_ptr->lev)
1815                 {
1816                         if (p_ptr->skill_exp[GINOU_SUDE] < s_info[p_ptr->pclass].s_max[GINOU_SUDE])
1817                         {
1818                                 if (p_ptr->skill_exp[GINOU_SUDE] < WEAPON_EXP_BEGINNER)
1819                                         p_ptr->skill_exp[GINOU_SUDE] += 40;
1820                                 else if ((p_ptr->skill_exp[GINOU_SUDE] < WEAPON_EXP_SKILLED))
1821                                         p_ptr->skill_exp[GINOU_SUDE] += 5;
1822                                 else if ((p_ptr->skill_exp[GINOU_SUDE] < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19))
1823                                         p_ptr->skill_exp[GINOU_SUDE] += 1;
1824                                 else if ((p_ptr->lev > 34))
1825                                         if (one_in_(3)) p_ptr->skill_exp[GINOU_SUDE] += 1;
1826                                 p_ptr->update |= (PU_BONUS);
1827                         }
1828                 }
1829         }
1830         else if (object_is_melee_weapon(o_ptr))
1831         {
1832                 if ((r_ptr->level + 10) > p_ptr->lev)
1833                 {
1834                         int tval = inventory[INVEN_RARM+hand].tval - TV_WEAPON_BEGIN;
1835                         int sval = inventory[INVEN_RARM+hand].sval;
1836                         int now_exp = p_ptr->weapon_exp[tval][sval];
1837                         if (now_exp < s_info[p_ptr->pclass].w_max[tval][sval])
1838                         {
1839                                 int amount = 0;
1840                                 if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
1841                                 else if (now_exp < WEAPON_EXP_SKILLED) amount = 10;
1842                                 else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 1;
1843                                 else if ((p_ptr->lev > 34) && one_in_(2)) amount = 1;
1844                                 p_ptr->weapon_exp[tval][sval] += amount;
1845                                 p_ptr->update |= (PU_BONUS);
1846                         }
1847                 }
1848         }
1849
1850         /* Disturb the monster */
1851         (void)set_monster_csleep(c_ptr->m_idx, 0);
1852
1853         /* Extract monster name (or "it") */
1854         monster_desc(m_name, m_ptr, 0);
1855
1856         /* Calculate the "attack quality" */
1857         bonus = p_ptr->to_h[hand] + o_ptr->to_h;
1858         chance = (p_ptr->skill_thn + (bonus * BTH_PLUS_ADJ));
1859         if (mode == HISSATSU_IAI) chance += 60;
1860         if (p_ptr->special_defense & KATA_KOUKIJIN) chance += 150;
1861
1862         if (p_ptr->sutemi) chance = MAX(chance * 3 / 2, chance + 60);
1863
1864         vir = virtue_number(V_VALOUR);
1865         if (vir)
1866         {
1867                 chance += (p_ptr->virtues[vir - 1]/10);
1868         }
1869
1870         zantetsu_mukou = ((o_ptr->name1 == ART_ZANTETSU) && (r_ptr->d_char == 'j'));
1871         e_j_mukou = ((o_ptr->name1 == ART_EXCALIBUR_J) && (r_ptr->d_char == 'S'));
1872
1873         if ((mode == HISSATSU_KYUSHO) || (mode == HISSATSU_MINEUCHI) || (mode == HISSATSU_3DAN) || (mode == HISSATSU_IAI)) num_blow = 1;
1874         else if (mode == HISSATSU_COLD) num_blow = p_ptr->num_blow[hand]+2;
1875         else num_blow = p_ptr->num_blow[hand];
1876
1877         /* Hack -- DOKUBARI always hit once */
1878         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) num_blow = 1;
1879
1880         /* Attack once for each legal blow */
1881         while ((num++ < num_blow) && !p_ptr->is_dead)
1882         {
1883                 if (((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) || (mode == HISSATSU_KYUSHO))
1884                 {
1885                         int n = 1;
1886
1887                         if (p_ptr->migite && p_ptr->hidarite)
1888                         {
1889                                 n *= 2;
1890                         }
1891                         if (mode == HISSATSU_3DAN)
1892                         {
1893                                 n *= 2;
1894                         }
1895
1896                         success_hit = one_in_(n);
1897                 }
1898                 else if ((p_ptr->pclass == CLASS_NINJA) && ((backstab || fuiuchi) && !(r_ptr->flagsr & RFR_RES_ALL))) success_hit = TRUE;
1899                 else success_hit = test_hit_norm(chance, r_ptr->ac, m_ptr->ml);
1900
1901                 if (mode == HISSATSU_MAJIN)
1902                 {
1903                         if (one_in_(2))
1904                                 success_hit = FALSE;
1905                 }
1906
1907                 /* Test for hit */
1908                 if (success_hit)
1909                 {
1910                         int vorpal_chance = ((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD)) ? 2 : 4;
1911
1912                         /* Sound */
1913                         sound(SOUND_HIT);
1914
1915                         /* Message */
1916 #ifdef JP
1917                         if (backstab) msg_format("あなたは冷酷にも眠っている無力な%sを突き刺した!", m_name);
1918                         else if (fuiuchi) msg_format("不意を突いて%sに強烈な一撃を喰らわせた!", m_name);
1919                         else if (stab_fleeing) msg_format("逃げる%sを背中から突き刺した!", m_name);
1920                         else if (!monk_attack) msg_format("%sを攻撃した。", m_name);
1921 #else
1922                         if (backstab) msg_format("You cruelly stab the helpless, sleeping %s!", m_name);
1923                         else if (fuiuchi) msg_format("You make surprise attack, and hit %s with a powerful blow!", m_name);
1924                         else if (stab_fleeing) msg_format("You backstab the fleeing %s!",  m_name);
1925                         else if (!monk_attack) msg_format("You hit %s.", m_name);
1926 #endif
1927
1928                         /* Hack -- bare hands do one damage */
1929                         k = 1;
1930
1931                         object_flags(o_ptr, flgs);
1932
1933                         /* Select a chaotic effect (50% chance) */
1934                         if ((have_flag(flgs, TR_CHAOTIC)) && one_in_(2))
1935                         {
1936                                 if (one_in_(10))
1937                                 chg_virtue(V_CHANCE, 1);
1938
1939                                 if (randint1(5) < 3)
1940                                 {
1941                                         /* Vampiric (20%) */
1942                                         chaos_effect = 1;
1943                                 }
1944                                 else if (one_in_(250))
1945                                 {
1946                                         /* Quake (0.12%) */
1947                                         chaos_effect = 2;
1948                                 }
1949                                 else if (!one_in_(10))
1950                                 {
1951                                         /* Confusion (26.892%) */
1952                                         chaos_effect = 3;
1953                                 }
1954                                 else if (one_in_(2))
1955                                 {
1956                                         /* Teleport away (1.494%) */
1957                                         chaos_effect = 4;
1958                                 }
1959                                 else
1960                                 {
1961                                         /* Polymorph (1.494%) */
1962                                         chaos_effect = 5;
1963                                 }
1964                         }
1965
1966                         /* Vampiric drain */
1967                         if ((have_flag(flgs, TR_VAMPIRIC)) || (chaos_effect == 1) || (mode == HISSATSU_DRAIN) || hex_spelling(HEX_VAMP_BLADE))
1968                         {
1969                                 /* Only drain "living" monsters */
1970                                 if (monster_living(r_ptr))
1971                                         can_drain = TRUE;
1972                                 else
1973                                         can_drain = FALSE;
1974                         }
1975
1976                         if ((have_flag(flgs, TR_VORPAL) || hex_spelling(HEX_RUNESWORD)) && (randint1(vorpal_chance*3/2) == 1) && !zantetsu_mukou)
1977                                 vorpal_cut = TRUE;
1978                         else vorpal_cut = FALSE;
1979
1980                         if (monk_attack)
1981                         {
1982                                 int special_effect = 0, stun_effect = 0, times = 0, max_times;
1983                                 int min_level = 1;
1984                                 const martial_arts *ma_ptr = &ma_blows[0], *old_ptr = &ma_blows[0];
1985                                 int resist_stun = 0;
1986                                 int weight = 8;
1987
1988                                 if (r_ptr->flags1 & RF1_UNIQUE) resist_stun += 88;
1989                                 if (r_ptr->flags3 & RF3_NO_STUN) resist_stun += 66;
1990                                 if (r_ptr->flags3 & RF3_NO_CONF) resist_stun += 33;
1991                                 if (r_ptr->flags3 & RF3_NO_SLEEP) resist_stun += 33;
1992                                 if ((r_ptr->flags3 & RF3_UNDEAD) || (r_ptr->flags3 & RF3_NONLIVING))
1993                                         resist_stun += 66;
1994
1995                                 if (p_ptr->special_defense & KAMAE_BYAKKO)
1996                                         max_times = (p_ptr->lev < 3 ? 1 : p_ptr->lev / 3);
1997                                 else if (p_ptr->special_defense & KAMAE_SUZAKU)
1998                                         max_times = 1;
1999                                 else if (p_ptr->special_defense & KAMAE_GENBU)
2000                                         max_times = 1;
2001                                 else
2002                                         max_times = (p_ptr->lev < 7 ? 1 : p_ptr->lev / 7);
2003                                 /* Attempt 'times' */
2004                                 for (times = 0; times < max_times; times++)
2005                                 {
2006                                         do
2007                                         {
2008                                                 ma_ptr = &ma_blows[randint0(MAX_MA)];
2009                                                 if ((p_ptr->pclass == CLASS_FORCETRAINER) && (ma_ptr->min_level > 1)) min_level = ma_ptr->min_level + 3;
2010                                                 else min_level = ma_ptr->min_level;
2011                                         }
2012                                         while ((min_level > p_ptr->lev) ||
2013                                                (randint1(p_ptr->lev) < ma_ptr->chance));
2014
2015                                         /* keep the highest level attack available we found */
2016                                         if ((ma_ptr->min_level > old_ptr->min_level) &&
2017                                             !p_ptr->stun && !p_ptr->confused)
2018                                         {
2019                                                 old_ptr = ma_ptr;
2020
2021                                                 if (p_ptr->wizard && cheat_xtra)
2022                                                 {
2023 #ifdef JP
2024                                                         msg_print("攻撃を再選択しました。");
2025 #else
2026                                                         msg_print("Attack re-selected.");
2027 #endif
2028                                                 }
2029                                         }
2030                                         else
2031                                         {
2032                                                 ma_ptr = old_ptr;
2033                                         }
2034                                 }
2035
2036                                 if (p_ptr->pclass == CLASS_FORCETRAINER) min_level = MAX(1, ma_ptr->min_level - 3);
2037                                 else min_level = ma_ptr->min_level;
2038                                 k = damroll(ma_ptr->dd + p_ptr->to_dd[hand], ma_ptr->ds + p_ptr->to_ds[hand]);
2039                                 if (p_ptr->special_attack & ATTACK_SUIKEN) k *= 2;
2040
2041                                 if (ma_ptr->effect == MA_KNEE)
2042                                 {
2043                                         if (r_ptr->flags1 & RF1_MALE)
2044                                         {
2045 #ifdef JP
2046                                                 msg_format("%sに金的膝蹴りをくらわした!", m_name);
2047 #else
2048                                                 msg_format("You hit %s in the groin with your knee!", m_name);
2049 #endif
2050
2051                                                 sound(SOUND_PAIN);
2052                                                 special_effect = MA_KNEE;
2053                                         }
2054                                         else
2055                                                 msg_format(ma_ptr->desc, m_name);
2056                                 }
2057
2058                                 else if (ma_ptr->effect == MA_SLOW)
2059                                 {
2060                                         if (!((r_ptr->flags1 & RF1_NEVER_MOVE) ||
2061                                             my_strchr("~#{}.UjmeEv$,DdsbBFIJQSXclnw!=?", r_ptr->d_char)))
2062                                         {
2063 #ifdef JP
2064                                                 msg_format("%sの足首に関節蹴りをくらわした!", m_name);
2065 #else
2066                                                 msg_format("You kick %s in the ankle.", m_name);
2067 #endif
2068
2069                                                 special_effect = MA_SLOW;
2070                                         }
2071                                         else msg_format(ma_ptr->desc, m_name);
2072                                 }
2073                                 else
2074                                 {
2075                                         if (ma_ptr->effect)
2076                                         {
2077                                                 stun_effect = (ma_ptr->effect / 2) + randint1(ma_ptr->effect / 2);
2078                                         }
2079
2080                                         msg_format(ma_ptr->desc, m_name);
2081                                 }
2082
2083                                 if (p_ptr->special_defense & KAMAE_SUZAKU) weight = 4;
2084                                 if ((p_ptr->pclass == CLASS_FORCETRAINER) && (p_ptr->magic_num1[0]))
2085                                 {
2086                                         weight += (p_ptr->magic_num1[0]/30);
2087                                         if (weight > 20) weight = 20;
2088                                 }
2089
2090                                 k = critical_norm(p_ptr->lev * weight, min_level, k, p_ptr->to_h[0], 0);
2091
2092                                 if ((special_effect == MA_KNEE) && ((k + p_ptr->to_d[hand]) < m_ptr->hp))
2093                                 {
2094 #ifdef JP
2095                                         msg_format("%^sは苦痛にうめいている!", m_name);
2096 #else
2097                                         msg_format("%^s moans in agony!", m_name);
2098 #endif
2099
2100                                         stun_effect = 7 + randint1(13);
2101                                         resist_stun /= 3;
2102                                 }
2103
2104                                 else if ((special_effect == MA_SLOW) && ((k + p_ptr->to_d[hand]) < m_ptr->hp))
2105                                 {
2106                                         if (!(r_ptr->flags1 & RF1_UNIQUE) &&
2107                                             (randint1(p_ptr->lev) > r_ptr->level) &&
2108                                             m_ptr->mspeed > 60)
2109                                         {
2110 #ifdef JP
2111                                                 msg_format("%^sは足をひきずり始めた。", m_name);
2112 #else
2113                                                 msg_format("%^s starts limping slower.", m_name);
2114 #endif
2115
2116                                                 m_ptr->mspeed -= 10;
2117                                         }
2118                                 }
2119
2120                                 if (stun_effect && ((k + p_ptr->to_d[hand]) < m_ptr->hp))
2121                                 {
2122                                         if (p_ptr->lev > randint1(r_ptr->level + resist_stun + 10))
2123                                         {
2124                                                 if (set_monster_stunned(c_ptr->m_idx, stun_effect + MON_STUNNED(m_ptr)))
2125                                                 {
2126 #ifdef JP
2127                                                         msg_format("%^sはフラフラになった。", m_name);
2128 #else
2129                                                         msg_format("%^s is stunned.", m_name);
2130 #endif
2131                                                 }
2132                                                 else
2133                                                 {
2134 #ifdef JP
2135                                                         msg_format("%^sはさらにフラフラになった。", m_name);
2136 #else
2137                                                         msg_format("%^s is more stunned.", m_name);
2138 #endif
2139                                                 }
2140                                         }
2141                                 }
2142                         }
2143
2144                         /* Handle normal weapon */
2145                         else if (o_ptr->k_idx)
2146                         {
2147                                 k = damroll(o_ptr->dd + p_ptr->to_dd[hand], o_ptr->ds + p_ptr->to_ds[hand]);
2148                                 k = tot_dam_aux(o_ptr, k, m_ptr, mode, FALSE);
2149
2150                                 if (backstab)
2151                                 {
2152                                         k *= (3 + (p_ptr->lev / 20));
2153                                 }
2154                                 else if (fuiuchi)
2155                                 {
2156                                         k = k*(5+(p_ptr->lev*2/25))/2;
2157                                 }
2158                                 else if (stab_fleeing)
2159                                 {
2160                                         k = (3 * k) / 2;
2161                                 }
2162
2163                                 if ((p_ptr->impact[hand] && ((k > 50) || one_in_(7))) ||
2164                                          (chaos_effect == 2) || (mode == HISSATSU_QUAKE))
2165                                 {
2166                                         do_quake = TRUE;
2167                                 }
2168
2169                                 if ((!(o_ptr->tval == TV_SWORD) || !(o_ptr->sval == SV_DOKUBARI)) && !(mode == HISSATSU_KYUSHO))
2170                                         k = critical_norm(o_ptr->weight, o_ptr->to_h, k, p_ptr->to_h[hand], mode);
2171
2172                                 drain_result = k;
2173
2174                                 if (vorpal_cut)
2175                                 {
2176                                         int mult = 2;
2177
2178                                         if ((o_ptr->name1 == ART_CHAINSWORD) && !one_in_(2))
2179                                         {
2180                                                 char chainsword_noise[1024];
2181 #ifdef JP
2182                                                 if (!get_rnd_line("chainswd_j.txt", 0, chainsword_noise))
2183 #else
2184                                                 if (!get_rnd_line("chainswd.txt", 0, chainsword_noise))
2185 #endif
2186                                                 {
2187                                                         msg_print(chainsword_noise);
2188                                                 }
2189                                         }
2190
2191                                         if (o_ptr->name1 == ART_VORPAL_BLADE)
2192                                         {
2193 #ifdef JP
2194                                                 msg_print("目にも止まらぬヴォーパルブレード、手錬の早業!");
2195 #else
2196                                                 msg_print("Your Vorpal Blade goes snicker-snack!");
2197 #endif
2198                                         }
2199                                         else
2200                                         {
2201 #ifdef JP
2202                                                 msg_format("%sをグッサリ切り裂いた!", m_name);
2203 #else
2204                                                 msg_format("Your weapon cuts deep into %s!", m_name);
2205 #endif
2206                                         }
2207
2208                                         /* Try to increase the damage */
2209                                         while (one_in_(vorpal_chance))
2210                                         {
2211                                                 mult++;
2212                                         }
2213
2214                                         k *= mult;
2215
2216                                         /* Ouch! */
2217                                         if (((r_ptr->flagsr & RFR_RES_ALL) ? k/100 : k) > m_ptr->hp)
2218                                         {
2219 #ifdef JP
2220                                                 msg_format("%sを真っ二つにした!", m_name);
2221 #else
2222                                                 msg_format("You cut %s in half!", m_name);
2223 #endif
2224                                         }
2225                                         else
2226                                         {
2227                                                 switch (mult)
2228                                                 {
2229 #ifdef JP
2230                                                 case 2: msg_format("%sを斬った!", m_name); break;
2231                                                 case 3: msg_format("%sをぶった斬った!", m_name); break;
2232                                                 case 4: msg_format("%sをメッタ斬りにした!", m_name); break;
2233                                                 case 5: msg_format("%sをメッタメタに斬った!", m_name); break;
2234                                                 case 6: msg_format("%sを刺身にした!", m_name); break;
2235                                                 case 7: msg_format("%sを斬って斬って斬りまくった!", m_name); break;
2236                                                 default: msg_format("%sを細切れにした!", m_name); break;
2237 #else
2238                                                 case 2: msg_format("You gouge %s!", m_name); break;
2239                                                 case 3: msg_format("You maim %s!", m_name); break;
2240                                                 case 4: msg_format("You carve %s!", m_name); break;
2241                                                 case 5: msg_format("You cleave %s!", m_name); break;
2242                                                 case 6: msg_format("You smite %s!", m_name); break;
2243                                                 case 7: msg_format("You eviscerate %s!", m_name); break;
2244                                                 default: msg_format("You shred %s!", m_name); break;
2245 #endif
2246                                                 }
2247                                         }
2248                                         drain_result = drain_result * 3 / 2;
2249                                 }
2250
2251                                 k += o_ptr->to_d;
2252                                 drain_result += o_ptr->to_d;
2253                         }
2254
2255                         /* Apply the player damage bonuses */
2256                         k += p_ptr->to_d[hand];
2257                         drain_result += p_ptr->to_d[hand];
2258
2259                         if ((mode == HISSATSU_SUTEMI) || (mode == HISSATSU_3DAN)) k *= 2;
2260                         if ((mode == HISSATSU_SEKIRYUKA) && !monster_living(r_ptr)) k = 0;
2261                         if ((mode == HISSATSU_SEKIRYUKA) && !p_ptr->cut) k /= 2;
2262
2263                         /* No negative damage */
2264                         if (k < 0) k = 0;
2265
2266                         if ((mode == HISSATSU_ZANMA) && !(!monster_living(r_ptr) && (r_ptr->flags3 & RF3_EVIL)))
2267                         {
2268                                 k = 0;
2269                         }
2270
2271                         if (zantetsu_mukou)
2272                         {
2273 #ifdef JP
2274                                 msg_print("こんな軟らかいものは切れん!");
2275 #else
2276                                 msg_print("You cannot cut such a elastic thing!");
2277 #endif
2278                                 k = 0;
2279                         }
2280
2281                         if (e_j_mukou)
2282                         {
2283 #ifdef JP
2284                                 msg_print("蜘蛛は苦手だ!");
2285 #else
2286                                 msg_print("Spiders are difficult for you to deal with!");
2287 #endif
2288                                 k /= 2;
2289                         }
2290
2291                         if (mode == HISSATSU_MINEUCHI)
2292                         {
2293                                 int tmp = (10 + randint1(15) + p_ptr->lev / 5);
2294
2295                                 k = 0;
2296                                 anger_monster(m_ptr);
2297
2298                                 if (!(r_ptr->flags3 & (RF3_NO_STUN)))
2299                                 {
2300                                         /* Get stunned */
2301                                         if (MON_STUNNED(m_ptr))
2302                                         {
2303 #ifdef JP
2304                                                 msg_format("%sはひどくもうろうとした。", m_name);
2305 #else
2306                                                 msg_format("%s is more dazed.", m_name);
2307 #endif
2308
2309                                                 tmp /= 2;
2310                                         }
2311                                         else
2312                                         {
2313 #ifdef JP
2314                                                 msg_format("%s はもうろうとした。", m_name);
2315 #else
2316                                                 msg_format("%s is dazed.", m_name);
2317 #endif
2318                                         }
2319
2320                                         /* Apply stun */
2321                                         (void)set_monster_stunned(c_ptr->m_idx, MON_STUNNED(m_ptr) + tmp);
2322                                 }
2323                                 else
2324                                 {
2325 #ifdef JP
2326                                         msg_format("%s には効果がなかった。", m_name);
2327 #else
2328                                         msg_format("%s is not effected.", m_name);
2329 #endif
2330                                 }
2331                         }
2332
2333                         /* Modify the damage */
2334                         k = mon_damage_mod(m_ptr, k, (bool)(((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE)) || ((p_ptr->pclass == CLASS_BERSERKER) && one_in_(2))));
2335                         if (((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) || (mode == HISSATSU_KYUSHO))
2336                         {
2337                                 if ((randint1(randint1(r_ptr->level/7)+5) == 1) && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
2338                                 {
2339                                         k = m_ptr->hp + 1;
2340 #ifdef JP
2341                                         msg_format("%sの急所を突き刺した!", m_name);
2342 #else
2343                                         msg_format("You hit %s on a fatal spot!", m_name);
2344 #endif
2345                                 }
2346                                 else k = 1;
2347                         }
2348                         else if ((p_ptr->pclass == CLASS_NINJA) && buki_motteruka(INVEN_RARM + hand) && !p_ptr->icky_wield[hand] && ((p_ptr->cur_lite <= 0) || one_in_(7)))
2349                         {
2350                                 int maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2351                                 if (one_in_(backstab ? 13 : (stab_fleeing || fuiuchi) ? 15 : 27))
2352                                 {
2353                                         k *= 5;
2354                                         drain_result *= 2;
2355 #ifdef JP
2356                                         msg_format("刃が%sに深々と突き刺さった!", m_name);
2357 #else
2358                                         msg_format("You critically injured %s!", m_name);
2359 #endif
2360                                 }
2361                                 else if (((m_ptr->hp < maxhp/2) && one_in_((p_ptr->num_blow[0]+p_ptr->num_blow[1]+1)*10)) || ((one_in_(666) || ((backstab || fuiuchi) && one_in_(11))) && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2)))
2362                                 {
2363                                         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE2) || (m_ptr->hp >= maxhp/2))
2364                                         {
2365                                                 k = MAX(k*5, m_ptr->hp/2);
2366                                                 drain_result *= 2;
2367 #ifdef JP
2368                                                 msg_format("%sに致命傷を負わせた!", m_name);
2369 #else
2370                                                 msg_format("You fatally injured %s!", m_name);
2371 #endif
2372                                         }
2373                                         else
2374                                         {
2375                                                 k = m_ptr->hp + 1;
2376 #ifdef JP
2377                                                 msg_format("刃が%sの急所を貫いた!", m_name);
2378 #else
2379                                                 msg_format("You hit %s on a fatal spot!", m_name);
2380 #endif
2381                                         }
2382                                 }
2383                         }
2384
2385                         /* Complex message */
2386                         if (p_ptr->wizard || cheat_xtra)
2387                         {
2388 #ifdef JP
2389                                 msg_format("%d/%d のダメージを与えた。", k, m_ptr->hp);
2390 #else
2391                                 msg_format("You do %d (out of %d) damage.", k, m_ptr->hp);
2392 #endif
2393                         }
2394
2395                         if (k <= 0) can_drain = FALSE;
2396
2397                         if (drain_result > m_ptr->hp)
2398                                 drain_result = m_ptr->hp;
2399
2400                         /* Damage, check for fear and death */
2401                         if (mon_take_hit(c_ptr->m_idx, k, fear, NULL))
2402                         {
2403                                 *mdeath = TRUE;
2404                                 if ((p_ptr->pclass == CLASS_BERSERKER) && energy_use)
2405                                 {
2406                                         if (p_ptr->migite && p_ptr->hidarite)
2407                                         {
2408                                                 if (hand) energy_use = energy_use*3/5+energy_use*num*2/(p_ptr->num_blow[hand]*5);
2409                                                 else energy_use = energy_use*num*3/(p_ptr->num_blow[hand]*5);
2410                                         }
2411                                         else
2412                                         {
2413                                                 energy_use = energy_use*num/p_ptr->num_blow[hand];
2414                                         }
2415                                 }
2416                                 if ((o_ptr->name1 == ART_ZANTETSU) && is_lowlevel)
2417 #ifdef JP
2418                                         msg_print("またつまらぬものを斬ってしまった...");
2419 #else
2420                                         msg_print("Sigh... Another trifling thing I've cut....");
2421 #endif
2422                                 break;
2423                         }
2424
2425                         /* Anger the monster */
2426                         if (k > 0) anger_monster(m_ptr);
2427
2428                         touch_zap_player(m_ptr);
2429
2430                         /* Are we draining it?  A little note: If the monster is
2431                         dead, the drain does not work... */
2432
2433                         if (can_drain && (drain_result > 0))
2434                         {
2435                                 if (o_ptr->name1 == ART_MURAMASA)
2436                                 {
2437                                         if (is_human)
2438                                         {
2439                                                 int to_h = o_ptr->to_h;
2440                                                 int to_d = o_ptr->to_d;
2441                                                 int i, flag;
2442
2443                                                 flag = 1;
2444                                                 for (i = 0; i < to_h + 3; i++) if (one_in_(4)) flag = 0;
2445                                                 if (flag) to_h++;
2446
2447                                                 flag = 1;
2448                                                 for (i = 0; i < to_d + 3; i++) if (one_in_(4)) flag = 0;
2449                                                 if (flag) to_d++;
2450
2451                                                 if (o_ptr->to_h != to_h || o_ptr->to_d != to_d)
2452                                                 {
2453 #ifdef JP
2454                                                         msg_print("妖刀は血を吸って強くなった!");
2455 #else
2456                                                         msg_print("Muramasa sucked blood, and became more powerful!");
2457 #endif
2458                                                         o_ptr->to_h = to_h;
2459                                                         o_ptr->to_d = to_d;
2460                                                 }
2461                                         }
2462                                 }
2463                                 else
2464                                 {
2465                                         if (drain_result > 5) /* Did we really hurt it? */
2466                                         {
2467                                                 drain_heal = damroll(2, drain_result / 6);
2468
2469                                                 /* Hex */
2470                                                 if (hex_spelling(HEX_VAMP_BLADE)) drain_heal *= 2;
2471
2472                                                 if (cheat_xtra)
2473                                                 {
2474 #ifdef JP
2475                                                         msg_format("Draining left: %d", drain_left);
2476 #else
2477                                                         msg_format("Draining left: %d", drain_left);
2478 #endif
2479
2480                                                 }
2481
2482                                                 if (drain_left)
2483                                                 {
2484                                                         if (drain_heal < drain_left)
2485                                                         {
2486                                                                 drain_left -= drain_heal;
2487                                                         }
2488                                                         else
2489                                                         {
2490                                                                 drain_heal = drain_left;
2491                                                                 drain_left = 0;
2492                                                         }
2493
2494                                                         if (drain_msg)
2495                                                         {
2496 #ifdef JP
2497                                                                 msg_format("刃が%sから生命力を吸い取った!", m_name);
2498 #else
2499                                                                 msg_format("Your weapon drains life from %s!", m_name);
2500 #endif
2501
2502                                                                 drain_msg = FALSE;
2503                                                         }
2504
2505                                                         drain_heal = (drain_heal * mutant_regenerate_mod) / 100;
2506
2507                                                         hp_player(drain_heal);
2508                                                         /* We get to keep some of it! */
2509                                                 }
2510                                         }
2511                                 }
2512                                 m_ptr->maxhp -= (k+7)/8;
2513                                 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
2514                                 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2515                                 weak = TRUE;
2516                         }
2517                         can_drain = FALSE;
2518                         drain_result = 0;
2519
2520                         /* Confusion attack */
2521                         if ((p_ptr->special_attack & ATTACK_CONFUSE) || (chaos_effect == 3) || (mode == HISSATSU_CONF) || hex_spelling(HEX_CONFUSION))
2522                         {
2523                                 /* Cancel glowing hands */
2524                                 if (p_ptr->special_attack & ATTACK_CONFUSE)
2525                                 {
2526                                         p_ptr->special_attack &= ~(ATTACK_CONFUSE);
2527 #ifdef JP
2528                                         msg_print("手の輝きがなくなった。");
2529 #else
2530                                         msg_print("Your hands stop glowing.");
2531 #endif
2532                                         p_ptr->redraw |= (PR_STATUS);
2533
2534                                 }
2535
2536                                 /* Confuse the monster */
2537                                 if (r_ptr->flags3 & RF3_NO_CONF)
2538                                 {
2539                                         if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags3 |= RF3_NO_CONF;
2540
2541 #ifdef JP
2542                                         msg_format("%^sには効果がなかった。", m_name);
2543 #else
2544                                         msg_format("%^s is unaffected.", m_name);
2545 #endif
2546
2547                                 }
2548                                 else if (randint0(100) < r_ptr->level)
2549                                 {
2550 #ifdef JP
2551                                         msg_format("%^sには効果がなかった。", m_name);
2552 #else
2553                                         msg_format("%^s is unaffected.", m_name);
2554 #endif
2555
2556                                 }
2557                                 else
2558                                 {
2559 #ifdef JP
2560                                         msg_format("%^sは混乱したようだ。", m_name);
2561 #else
2562                                         msg_format("%^s appears confused.", m_name);
2563 #endif
2564
2565                                         (void)set_monster_confused(c_ptr->m_idx, MON_CONFUSED(m_ptr) + 10 + randint0(p_ptr->lev) / 5);
2566                                 }
2567                         }
2568
2569                         else if (chaos_effect == 4)
2570                         {
2571                                 bool resists_tele = FALSE;
2572
2573                                 if (r_ptr->flagsr & RFR_RES_TELE)
2574                                 {
2575                                         if (r_ptr->flags1 & RF1_UNIQUE)
2576                                         {
2577                                                 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= RFR_RES_TELE;
2578 #ifdef JP
2579                                                 msg_format("%^sには効果がなかった。", m_name);
2580 #else
2581                                                 msg_format("%^s is unaffected!", m_name);
2582 #endif
2583
2584                                                 resists_tele = TRUE;
2585                                         }
2586                                         else if (r_ptr->level > randint1(100))
2587                                         {
2588                                                 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= RFR_RES_TELE;
2589 #ifdef JP
2590                                                 msg_format("%^sは抵抗力を持っている!", m_name);
2591 #else
2592                                                 msg_format("%^s resists!", m_name);
2593 #endif
2594
2595                                                 resists_tele = TRUE;
2596                                         }
2597                                 }
2598
2599                                 if (!resists_tele)
2600                                 {
2601 #ifdef JP
2602                                         msg_format("%^sは消えた!", m_name);
2603 #else
2604                                         msg_format("%^s disappears!", m_name);
2605 #endif
2606
2607                                         teleport_away(c_ptr->m_idx, 50, TELEPORT_PASSIVE);
2608                                         num = num_blow + 1; /* Can't hit it anymore! */
2609                                         *mdeath = TRUE;
2610                                 }
2611                         }
2612
2613                         else if ((chaos_effect == 5) && (randint1(90) > r_ptr->level))
2614                         {
2615                                 if (!(r_ptr->flags1 & (RF1_UNIQUE | RF1_QUESTOR)) &&
2616                                     !(r_ptr->flagsr & RFR_EFF_RES_CHAO_MASK))
2617                                 {
2618                                         if (polymorph_monster(y, x))
2619                                         {
2620 #ifdef JP
2621                                                 msg_format("%^sは変化した!", m_name);
2622 #else
2623                                                 msg_format("%^s changes!", m_name);
2624 #endif
2625
2626                                                 *fear = FALSE;
2627                                                 weak = FALSE;
2628                                         }
2629                                         else
2630                                         {
2631 #ifdef JP
2632                                                 msg_format("%^sには効果がなかった。", m_name);
2633 #else
2634                                                 msg_format("%^s is unaffected.", m_name);
2635 #endif
2636                                         }
2637
2638                                         /* Hack -- Get new monster */
2639                                         m_ptr = &m_list[c_ptr->m_idx];
2640
2641                                         /* Oops, we need a different name... */
2642                                         monster_desc(m_name, m_ptr, 0);
2643
2644                                         /* Hack -- Get new race */
2645                                         r_ptr = &r_info[m_ptr->r_idx];
2646                                 }
2647                         }
2648                         else if (o_ptr->name1 == ART_G_HAMMER)
2649                         {
2650                                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2651
2652                                 if (m_ptr->hold_o_idx)
2653                                 {
2654                                         object_type *q_ptr = &o_list[m_ptr->hold_o_idx];
2655                                         char o_name[MAX_NLEN];
2656
2657                                         object_desc(o_name, q_ptr, OD_NAME_ONLY);
2658                                         q_ptr->held_m_idx = 0;
2659                                         q_ptr->marked = OM_TOUCHED;
2660                                         m_ptr->hold_o_idx = q_ptr->next_o_idx;
2661                                         q_ptr->next_o_idx = 0;
2662 #ifdef JP
2663                                         msg_format("%sを奪った。", o_name);
2664 #else
2665                                         msg_format("You snatched %s.", o_name);
2666 #endif
2667                                         inven_carry(q_ptr);
2668                                 }
2669                         }
2670                 }
2671
2672                 /* Player misses */
2673                 else
2674                 {
2675                         backstab = FALSE; /* Clumsy! */
2676                         fuiuchi = FALSE; /* Clumsy! */
2677
2678                         if ((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE) && one_in_(3))
2679                         {
2680                                 u32b flgs[TR_FLAG_SIZE];
2681
2682                                 /* Sound */
2683                                 sound(SOUND_HIT);
2684
2685                                 /* Message */
2686 #ifdef JP
2687                                 msg_format("ミス! %sにかわされた。", m_name);
2688 #else
2689                                 msg_format("You miss %s.", m_name);
2690 #endif
2691                                 /* Message */
2692 #ifdef JP
2693                                 msg_print("振り回した大鎌が自分自身に返ってきた!");
2694 #else
2695                                 msg_print("Your scythe returns to you!");
2696 #endif
2697
2698                                 /* Extract the flags */
2699                                 object_flags(o_ptr, flgs);
2700
2701                                 k = damroll(o_ptr->dd + p_ptr->to_dd[hand], o_ptr->ds + p_ptr->to_ds[hand]);
2702                                 {
2703                                         int mult;
2704                                         switch (p_ptr->mimic_form)
2705                                         {
2706                                         case MIMIC_NONE:
2707                                                 switch (p_ptr->prace)
2708                                                 {
2709                                                         case RACE_YEEK:
2710                                                         case RACE_KLACKON:
2711                                                         case RACE_HUMAN:
2712                                                         case RACE_AMBERITE:
2713                                                         case RACE_DUNADAN:
2714                                                         case RACE_BARBARIAN:
2715                                                         case RACE_BEASTMAN:
2716                                                                 mult = 25;break;
2717                                                         case RACE_HALF_ORC:
2718                                                         case RACE_HALF_TROLL:
2719                                                         case RACE_HALF_OGRE:
2720                                                         case RACE_HALF_GIANT:
2721                                                         case RACE_HALF_TITAN:
2722                                                         case RACE_CYCLOPS:
2723                                                         case RACE_IMP:
2724                                                         case RACE_SKELETON:
2725                                                         case RACE_ZOMBIE:
2726                                                         case RACE_VAMPIRE:
2727                                                         case RACE_SPECTRE:
2728                                                         case RACE_DEMON:
2729                                                         case RACE_DRACONIAN:
2730                                                                 mult = 30;break;
2731                                                         default:
2732                                                                 mult = 10;break;
2733                                                 }
2734                                                 break;
2735                                         case MIMIC_DEMON:
2736                                         case MIMIC_DEMON_LORD:
2737                                         case MIMIC_VAMPIRE:
2738                                                 mult = 30;break;
2739                                         default:
2740                                                 mult = 10;break;
2741                                         }
2742
2743                                         if (p_ptr->align < 0 && mult < 20)
2744                                                 mult = 20;
2745                                         if (!(p_ptr->resist_acid || IS_OPPOSE_ACID() || p_ptr->immune_acid) && (mult < 25))
2746                                                 mult = 25;
2747                                         if (!(p_ptr->resist_elec || IS_OPPOSE_ELEC() || p_ptr->immune_elec) && (mult < 25))
2748                                                 mult = 25;
2749                                         if (!(p_ptr->resist_fire || IS_OPPOSE_FIRE() || p_ptr->immune_fire) && (mult < 25))
2750                                                 mult = 25;
2751                                         if (!(p_ptr->resist_cold || IS_OPPOSE_COLD() || p_ptr->immune_cold) && (mult < 25))
2752                                                 mult = 25;
2753                                         if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()) && (mult < 25))
2754                                                 mult = 25;
2755
2756                                         if ((p_ptr->pclass != CLASS_SAMURAI) && (have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
2757                                         {
2758                                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
2759                                                 p_ptr->redraw |= (PR_MANA);
2760                                                 mult = mult * 3 / 2 + 20;
2761                                         }
2762                                         k *= mult;
2763                                         k /= 10;
2764                                 }
2765
2766                                 k = critical_norm(o_ptr->weight, o_ptr->to_h, k, p_ptr->to_h[hand], mode);
2767                                 if (one_in_(6))
2768                                 {
2769                                         int mult = 2;
2770 #ifdef JP
2771                                         msg_format("グッサリ切り裂かれた!");
2772 #else
2773                                         msg_format("Your weapon cuts deep into yourself!");
2774 #endif
2775                                         /* Try to increase the damage */
2776                                         while (one_in_(4))
2777                                         {
2778                                                 mult++;
2779                                         }
2780
2781                                         k *= mult;
2782                                 }
2783                                 k += (p_ptr->to_d[hand] + o_ptr->to_d);
2784
2785                                 if (k < 0) k = 0;
2786
2787 #ifdef JP
2788                                 take_hit(DAMAGE_FORCE, k, "死の大鎌", -1);
2789 #else
2790                                 take_hit(DAMAGE_FORCE, k, "Death scythe", -1);
2791 #endif
2792
2793                                 redraw_stuff();
2794                         }
2795                         else
2796                         {
2797                                 /* Sound */
2798                                 sound(SOUND_MISS);
2799
2800                                 /* Message */
2801 #ifdef JP
2802                                 msg_format("ミス! %sにかわされた。", m_name);
2803 #else
2804                                 msg_format("You miss %s.", m_name);
2805 #endif
2806                         }
2807                 }
2808                 backstab = FALSE;
2809                 fuiuchi = FALSE;
2810         }
2811
2812
2813         if (weak && !(*mdeath))
2814         {
2815 #ifdef JP
2816                 msg_format("%sは弱くなったようだ。", m_name);
2817 #else
2818                 msg_format("%^s seems weakened.", m_name);
2819 #endif
2820         }
2821         if (drain_left != MAX_VAMPIRIC_DRAIN)
2822         {
2823                 if (one_in_(4))
2824                 {
2825                         chg_virtue(V_UNLIFE, 1);
2826                 }
2827         }
2828         /* Mega-Hack -- apply earthquake brand */
2829         if (do_quake)
2830         {
2831                 earthquake(py, px, 10);
2832                 if (!cave[y][x].m_idx) *mdeath = TRUE;
2833         }
2834 }
2835
2836 /*!
2837  * @brief プレイヤーの打撃処理メインルーチン
2838  * @param y 攻撃目標のY座標
2839  * @param x 攻撃目標のX座標
2840  * @param mode 発動中の剣術ID
2841  * @return 実際に攻撃処理が行われた場合TRUEを返す。
2842  * @details
2843  * If no "weapon" is available, then "punch" the monster one time.
2844  */
2845 bool py_attack(int y, int x, int mode)
2846 {
2847         bool            fear = FALSE;
2848         bool            mdeath = FALSE;
2849         bool            stormbringer = FALSE;
2850
2851         cave_type       *c_ptr = &cave[y][x];
2852         monster_type    *m_ptr = &m_list[c_ptr->m_idx];
2853         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
2854         char            m_name[80];
2855
2856         /* Disturb the player */
2857         disturb(0, 1);
2858
2859         energy_use = 100;
2860
2861         if (!p_ptr->migite && !p_ptr->hidarite &&
2862             !(p_ptr->muta2 & (MUT2_HORNS | MUT2_BEAK | MUT2_SCOR_TAIL | MUT2_TRUNK | MUT2_TENTACLES)))
2863         {
2864 #ifdef JP
2865                 msg_format("%s攻撃できない。", (empty_hands(FALSE) == EMPTY_HAND_NONE) ? "両手がふさがって" : "");
2866 #else
2867                 msg_print("You cannot do attacking.");
2868 #endif
2869                 return FALSE;
2870         }
2871
2872         /* Extract monster name (or "it") */
2873         monster_desc(m_name, m_ptr, 0);
2874
2875         if (m_ptr->ml)
2876         {
2877                 /* Auto-Recall if possible and visible */
2878                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
2879
2880                 /* Track a new monster */
2881                 health_track(c_ptr->m_idx);
2882         }
2883
2884         if ((r_ptr->flags1 & RF1_FEMALE) &&
2885             !(p_ptr->stun || p_ptr->confused || p_ptr->image || !m_ptr->ml))
2886         {
2887                 if ((inventory[INVEN_RARM].name1 == ART_ZANTETSU) || (inventory[INVEN_LARM].name1 == ART_ZANTETSU))
2888                 {
2889 #ifdef JP
2890                         msg_print("拙者、おなごは斬れぬ!");
2891 #else
2892                         msg_print("I can not attack women!");
2893 #endif
2894                         return FALSE;
2895                 }
2896         }
2897
2898         if (d_info[dungeon_type].flags1 & DF1_NO_MELEE)
2899         {
2900 #ifdef JP
2901                 msg_print("なぜか攻撃することができない。");
2902 #else
2903                 msg_print("Something prevent you from attacking.");
2904 #endif
2905                 return FALSE;
2906         }
2907
2908         /* Stop if friendly */
2909         if (!is_hostile(m_ptr) &&
2910             !(p_ptr->stun || p_ptr->confused || p_ptr->image ||
2911             p_ptr->shero || !m_ptr->ml))
2912         {
2913                 if (inventory[INVEN_RARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
2914                 if (inventory[INVEN_LARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
2915                 if (stormbringer)
2916                 {
2917 #ifdef JP
2918                         msg_format("黒い刃は強欲に%sを攻撃した!", m_name);
2919 #else
2920                         msg_format("Your black blade greedily attacks %s!", m_name);
2921 #endif
2922                         chg_virtue(V_INDIVIDUALISM, 1);
2923                         chg_virtue(V_HONOUR, -1);
2924                         chg_virtue(V_JUSTICE, -1);
2925                         chg_virtue(V_COMPASSION, -1);
2926                 }
2927                 else if (p_ptr->pclass != CLASS_BERSERKER)
2928                 {
2929 #ifdef JP
2930                         if (get_check("本当に攻撃しますか?"))
2931 #else
2932                         if (get_check("Really hit it? "))
2933 #endif
2934                         {
2935                                 chg_virtue(V_INDIVIDUALISM, 1);
2936                                 chg_virtue(V_HONOUR, -1);
2937                                 chg_virtue(V_JUSTICE, -1);
2938                                 chg_virtue(V_COMPASSION, -1);
2939                         }
2940                         else
2941                         {
2942 #ifdef JP
2943                                 msg_format("%sを攻撃するのを止めた。", m_name);
2944 #else
2945                                 msg_format("You stop to avoid hitting %s.", m_name);
2946 #endif
2947                                 return FALSE;
2948                         }
2949                 }
2950         }
2951
2952
2953         /* Handle player fear */
2954         if (p_ptr->afraid)
2955         {
2956                 /* Message */
2957                 if (m_ptr->ml)
2958 #ifdef JP
2959                         msg_format("恐くて%sを攻撃できない!", m_name);
2960 #else
2961                         msg_format("You are too afraid to attack %s!", m_name);
2962 #endif
2963
2964                 else
2965 #ifdef JP
2966                         msg_format ("そっちには何か恐いものがいる!");
2967 #else
2968                         msg_format ("There is something scary in your way!");
2969 #endif
2970
2971                 /* Disturb the monster */
2972                 (void)set_monster_csleep(c_ptr->m_idx, 0);
2973
2974                 /* Done */
2975                 return FALSE;
2976         }
2977
2978         if (MON_CSLEEP(m_ptr)) /* It is not honorable etc to attack helpless victims */
2979         {
2980                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
2981                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
2982         }
2983
2984         if (p_ptr->migite && p_ptr->hidarite)
2985         {
2986                 if ((p_ptr->skill_exp[GINOU_NITOURYU] < s_info[p_ptr->pclass].s_max[GINOU_NITOURYU]) && ((p_ptr->skill_exp[GINOU_NITOURYU] - 1000) / 200 < r_ptr->level))
2987                 {
2988                         if (p_ptr->skill_exp[GINOU_NITOURYU] < WEAPON_EXP_BEGINNER)
2989                                 p_ptr->skill_exp[GINOU_NITOURYU] += 80;
2990                         else if(p_ptr->skill_exp[GINOU_NITOURYU] < WEAPON_EXP_SKILLED)
2991                                 p_ptr->skill_exp[GINOU_NITOURYU] += 4;
2992                         else if(p_ptr->skill_exp[GINOU_NITOURYU] < WEAPON_EXP_EXPERT)
2993                                 p_ptr->skill_exp[GINOU_NITOURYU] += 1;
2994                         else if(p_ptr->skill_exp[GINOU_NITOURYU] < WEAPON_EXP_MASTER)
2995                                 if (one_in_(3)) p_ptr->skill_exp[GINOU_NITOURYU] += 1;
2996                         p_ptr->update |= (PU_BONUS);
2997                 }
2998         }
2999
3000         /* Gain riding experience */
3001         if (p_ptr->riding)
3002         {
3003                 int cur = p_ptr->skill_exp[GINOU_RIDING];
3004                 int max = s_info[p_ptr->pclass].s_max[GINOU_RIDING];
3005
3006                 if (cur < max)
3007                 {
3008                         int ridinglevel = r_info[m_list[p_ptr->riding].r_idx].level;
3009                         int targetlevel = r_ptr->level;
3010                         int inc = 0;
3011
3012                         if ((cur / 200 - 5) < targetlevel)
3013                                 inc += 1;
3014
3015                         /* Extra experience */
3016                         if ((cur / 100) < ridinglevel)
3017                         {
3018                                 if ((cur / 100 + 15) < ridinglevel)
3019                                         inc += 1 + (ridinglevel - (cur / 100 + 15));
3020                                 else
3021                                         inc += 1;
3022                         }
3023
3024                         p_ptr->skill_exp[GINOU_RIDING] = MIN(max, cur + inc);
3025
3026                         p_ptr->update |= (PU_BONUS);
3027                 }
3028         }
3029
3030         riding_t_m_idx = c_ptr->m_idx;
3031         if (p_ptr->migite) py_attack_aux(y, x, &fear, &mdeath, 0, mode);
3032         if (p_ptr->hidarite && !mdeath) py_attack_aux(y, x, &fear, &mdeath, 1, mode);
3033
3034         /* Mutations which yield extra 'natural' attacks */
3035         if (!mdeath)
3036         {
3037                 if ((p_ptr->muta2 & MUT2_HORNS) && !mdeath)
3038                         natural_attack(c_ptr->m_idx, MUT2_HORNS, &fear, &mdeath);
3039                 if ((p_ptr->muta2 & MUT2_BEAK) && !mdeath)
3040                         natural_attack(c_ptr->m_idx, MUT2_BEAK, &fear, &mdeath);
3041                 if ((p_ptr->muta2 & MUT2_SCOR_TAIL) && !mdeath)
3042                         natural_attack(c_ptr->m_idx, MUT2_SCOR_TAIL, &fear, &mdeath);
3043                 if ((p_ptr->muta2 & MUT2_TRUNK) && !mdeath)
3044                         natural_attack(c_ptr->m_idx, MUT2_TRUNK, &fear, &mdeath);
3045                 if ((p_ptr->muta2 & MUT2_TENTACLES) && !mdeath)
3046                         natural_attack(c_ptr->m_idx, MUT2_TENTACLES, &fear, &mdeath);
3047         }
3048
3049         /* Hack -- delay fear messages */
3050         if (fear && m_ptr->ml && !mdeath)
3051         {
3052                 /* Sound */
3053                 sound(SOUND_FLEE);
3054
3055                 /* Message */
3056 #ifdef JP
3057                 msg_format("%^sは恐怖して逃げ出した!", m_name);
3058 #else
3059                 msg_format("%^s flees in terror!", m_name);
3060 #endif
3061
3062         }
3063
3064         if ((p_ptr->special_defense & KATA_IAI) && ((mode != HISSATSU_IAI) || mdeath))
3065         {
3066                 set_action(ACTION_NONE);
3067         }
3068
3069         return mdeath;
3070 }
3071
3072
3073 /*!
3074  * @brief パターンによる移動制限処理
3075  * @param c_y プレイヤーの移動元Y座標
3076  * @param c_x プレイヤーの移動元X座標
3077  * @param n_y プレイヤーの移動先Y座標
3078  * @param n_x プレイヤーの移動先X座標
3079  * @return 移動処理が可能である場合(可能な場合に選択した場合)TRUEを返す。
3080  */
3081 bool pattern_seq(int c_y, int c_x, int n_y, int n_x)
3082 {
3083         feature_type *cur_f_ptr = &f_info[cave[c_y][c_x].feat];
3084         feature_type *new_f_ptr = &f_info[cave[n_y][n_x].feat];
3085         bool is_pattern_tile_cur = have_flag(cur_f_ptr->flags, FF_PATTERN);
3086         bool is_pattern_tile_new = have_flag(new_f_ptr->flags, FF_PATTERN);
3087         int pattern_type_cur, pattern_type_new;
3088
3089         if (!is_pattern_tile_cur && !is_pattern_tile_new) return TRUE;
3090
3091         pattern_type_cur = is_pattern_tile_cur ? cur_f_ptr->subtype : NOT_PATTERN_TILE;
3092         pattern_type_new = is_pattern_tile_new ? new_f_ptr->subtype : NOT_PATTERN_TILE;
3093
3094         if (pattern_type_new == PATTERN_TILE_START)
3095         {
3096                 if (!is_pattern_tile_cur && !p_ptr->confused && !p_ptr->stun && !p_ptr->image)
3097                 {
3098 #ifdef JP
3099                         if (get_check("パターンの上を歩き始めると、全てを歩かなければなりません。いいですか?"))
3100 #else
3101                         if (get_check("If you start walking the Pattern, you must walk the whole way. Ok? "))
3102 #endif
3103                                 return TRUE;
3104                         else
3105                                 return FALSE;
3106                 }
3107                 else
3108                         return TRUE;
3109         }
3110         else if ((pattern_type_new == PATTERN_TILE_OLD) ||
3111                  (pattern_type_new == PATTERN_TILE_END) ||
3112                  (pattern_type_new == PATTERN_TILE_WRECKED))
3113         {
3114                 if (is_pattern_tile_cur)
3115                 {
3116                         return TRUE;
3117                 }
3118                 else
3119                 {
3120 #ifdef JP
3121                         msg_print("パターンの上を歩くにはスタート地点から歩き始めなくてはなりません。");
3122 #else
3123                         msg_print("You must start walking the Pattern from the startpoint.");
3124 #endif
3125
3126                         return FALSE;
3127                 }
3128         }
3129         else if ((pattern_type_new == PATTERN_TILE_TELEPORT) ||
3130                  (pattern_type_cur == PATTERN_TILE_TELEPORT))
3131         {
3132                 return TRUE;
3133         }
3134         else if (pattern_type_cur == PATTERN_TILE_START)
3135         {
3136                 if (is_pattern_tile_new)
3137                         return TRUE;
3138                 else
3139                 {
3140 #ifdef JP
3141                         msg_print("パターンの上は正しい順序で歩かねばなりません。");
3142 #else
3143                         msg_print("You must walk the Pattern in correct order.");
3144 #endif
3145
3146                         return FALSE;
3147                 }
3148         }
3149         else if ((pattern_type_cur == PATTERN_TILE_OLD) ||
3150                  (pattern_type_cur == PATTERN_TILE_END) ||
3151                  (pattern_type_cur == PATTERN_TILE_WRECKED))
3152         {
3153                 if (!is_pattern_tile_new)
3154                 {
3155 #ifdef JP
3156                         msg_print("パターンを踏み外してはいけません。");
3157 #else
3158                         msg_print("You may not step off from the Pattern.");
3159 #endif
3160
3161                         return FALSE;
3162                 }
3163                 else
3164                 {
3165                         return TRUE;
3166                 }
3167         }
3168         else
3169         {
3170                 if (!is_pattern_tile_cur)
3171                 {
3172 #ifdef JP
3173                         msg_print("パターンの上を歩くにはスタート地点から歩き始めなくてはなりません。");
3174 #else
3175                         msg_print("You must start walking the Pattern from the startpoint.");
3176 #endif
3177
3178                         return FALSE;
3179                 }
3180                 else
3181                 {
3182                         byte ok_move = PATTERN_TILE_START;
3183                         switch (pattern_type_cur)
3184                         {
3185                                 case PATTERN_TILE_1:
3186                                         ok_move = PATTERN_TILE_2;
3187                                         break;
3188                                 case PATTERN_TILE_2:
3189                                         ok_move = PATTERN_TILE_3;
3190                                         break;
3191                                 case PATTERN_TILE_3:
3192                                         ok_move = PATTERN_TILE_4;
3193                                         break;
3194                                 case PATTERN_TILE_4:
3195                                         ok_move = PATTERN_TILE_1;
3196                                         break;
3197                                 default:
3198                                         if (p_ptr->wizard)
3199 #ifdef JP
3200                                                 msg_format("おかしなパターン歩行、%d。", pattern_type_cur);
3201 #else
3202                                                 msg_format("Funny Pattern walking, %d.", pattern_type_cur);
3203 #endif
3204
3205                                         return TRUE; /* Goof-up */
3206                         }
3207
3208                         if ((pattern_type_new == ok_move) ||
3209                             (pattern_type_new == pattern_type_cur))
3210                                 return TRUE;
3211                         else
3212                         {
3213                                 if (!is_pattern_tile_new)
3214 #ifdef JP
3215                                         msg_print("パターンを踏み外してはいけません。");
3216 #else
3217                                         msg_print("You may not step off from the Pattern.");
3218 #endif
3219                                 else
3220 #ifdef JP
3221                                         msg_print("パターンの上は正しい順序で歩かねばなりません。");
3222 #else
3223                                         msg_print("You must walk the Pattern in correct order.");
3224 #endif
3225
3226                                 return FALSE;
3227                         }
3228                 }
3229         }
3230 }
3231
3232
3233 /*!
3234  * @brief プレイヤーが地形踏破可能かを返す
3235  * @param feature 判定したい地形ID
3236  * @param mode 移動に関するオプションフラグ
3237  * @return 移動可能ならばTRUEを返す
3238  */
3239 bool player_can_enter(s16b feature, u16b mode)
3240 {
3241         feature_type *f_ptr = &f_info[feature];
3242
3243         if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
3244
3245         /* Pattern */
3246         if (have_flag(f_ptr->flags, FF_PATTERN))
3247         {
3248                 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
3249         }
3250
3251         /* "CAN" flags */
3252         if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
3253         if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
3254         if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
3255
3256         if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;
3257
3258         return TRUE;
3259 }
3260
3261
3262 /*!
3263  * @brief 移動に伴うプレイヤーのステータス変化処理
3264  * @param ny 移動先Y座標
3265  * @param nx 移動先X座標
3266  * @param mpe_mode 移動オプションフラグ
3267  * @return プレイヤーが死亡やフロア離脱を行わず、実際に移動が可能ならばTRUEを返す。
3268  */
3269 bool move_player_effect(int ny, int nx, u32b mpe_mode)
3270 {
3271         cave_type *c_ptr = &cave[ny][nx];
3272         feature_type *f_ptr = &f_info[c_ptr->feat];
3273
3274         if (!(mpe_mode & MPE_STAYING))
3275         {
3276                 int oy = py;
3277                 int ox = px;
3278                 cave_type *oc_ptr = &cave[oy][ox];
3279                 int om_idx = oc_ptr->m_idx;
3280                 int nm_idx = c_ptr->m_idx;
3281
3282                 /* Move the player */
3283                 py = ny;
3284                 px = nx;
3285
3286                 /* Hack -- For moving monster or riding player's moving */
3287                 if (!(mpe_mode & MPE_DONT_SWAP_MON))
3288                 {
3289                         /* Swap two monsters */
3290                         c_ptr->m_idx = om_idx;
3291                         oc_ptr->m_idx = nm_idx;
3292
3293                         if (om_idx > 0) /* Monster on old spot (or p_ptr->riding) */
3294                         {
3295                                 monster_type *om_ptr = &m_list[om_idx];
3296                                 om_ptr->fy = ny;
3297                                 om_ptr->fx = nx;
3298                                 update_mon(om_idx, TRUE);
3299                         }
3300
3301                         if (nm_idx > 0) /* Monster on new spot */
3302                         {
3303                                 monster_type *nm_ptr = &m_list[nm_idx];
3304                                 nm_ptr->fy = oy;
3305                                 nm_ptr->fx = ox;
3306                                 update_mon(nm_idx, TRUE);
3307                         }
3308                 }
3309
3310                 /* Redraw old spot */
3311                 lite_spot(oy, ox);
3312
3313                 /* Redraw new spot */
3314                 lite_spot(ny, nx);
3315
3316                 /* Check for new panel (redraw map) */
3317                 verify_panel();
3318
3319                 if (mpe_mode & MPE_FORGET_FLOW)
3320                 {
3321                         forget_flow();
3322
3323                         /* Mega-Hack -- Forget the view */
3324                         p_ptr->update |= (PU_UN_VIEW);
3325
3326                         /* Redraw map */
3327                         p_ptr->redraw |= (PR_MAP);
3328                 }
3329
3330                 /* Update stuff */
3331                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_DISTANCE);
3332
3333                 /* Window stuff */
3334                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3335
3336                 /* Remove "unsafe" flag */
3337                 if ((!p_ptr->blind && !no_lite()) || !is_trap(c_ptr->feat)) c_ptr->info &= ~(CAVE_UNSAFE);
3338
3339                 /* For get everything when requested hehe I'm *NASTY* */
3340                 if (dun_level && (d_info[dungeon_type].flags1 & DF1_FORGET)) wiz_dark();
3341
3342                 /* Handle stuff */
3343                 if (mpe_mode & MPE_HANDLE_STUFF) handle_stuff();
3344
3345                 if (p_ptr->pclass == CLASS_NINJA)
3346                 {
3347                         if (c_ptr->info & (CAVE_GLOW)) set_superstealth(FALSE);
3348                         else if (p_ptr->cur_lite <= 0) set_superstealth(TRUE);
3349                 }
3350
3351                 if ((p_ptr->action == ACTION_HAYAGAKE) &&
3352                     (!have_flag(f_ptr->flags, FF_PROJECT) ||
3353                      (!p_ptr->levitation && have_flag(f_ptr->flags, FF_DEEP))))
3354                 {
3355 #ifdef JP
3356                         msg_print("ここでは素早く動けない。");
3357 #else
3358                         msg_print("You cannot run in here.");
3359 #endif
3360                         set_action(ACTION_NONE);
3361                 }
3362         }
3363
3364         if (mpe_mode & MPE_ENERGY_USE)
3365         {
3366                 if (music_singing(MUSIC_WALL))
3367                 {
3368                         (void)project(0, 0, py, px, (60 + p_ptr->lev), GF_DISINTEGRATE,
3369                                 PROJECT_KILL | PROJECT_ITEM, -1);
3370
3371                         if (!player_bold(ny, nx) || p_ptr->is_dead || p_ptr->leaving) return FALSE;
3372                 }
3373
3374                 /* Spontaneous Searching */
3375                 if ((p_ptr->skill_fos >= 50) || (0 == randint0(50 - p_ptr->skill_fos)))
3376                 {
3377                         search();
3378                 }
3379
3380                 /* Continuous Searching */
3381                 if (p_ptr->action == ACTION_SEARCH)
3382                 {
3383                         search();
3384                 }
3385         }
3386
3387         /* Handle "objects" */
3388         if (!(mpe_mode & MPE_DONT_PICKUP))
3389         {
3390                 carry((mpe_mode & MPE_DO_PICKUP) ? TRUE : FALSE);
3391         }
3392
3393         /* Handle "store doors" */
3394         if (have_flag(f_ptr->flags, FF_STORE))
3395         {
3396                 /* Disturb */
3397                 disturb(0, 1);
3398
3399                 energy_use = 0;
3400                 /* Hack -- Enter store */
3401                 command_new = SPECIAL_KEY_STORE;
3402         }
3403
3404         /* Handle "building doors" -KMW- */
3405         else if (have_flag(f_ptr->flags, FF_BLDG))
3406         {
3407                 /* Disturb */
3408                 disturb(0, 1);
3409
3410                 energy_use = 0;
3411                 /* Hack -- Enter building */
3412                 command_new = SPECIAL_KEY_BUILDING;
3413         }
3414
3415         /* Handle quest areas -KMW- */
3416         else if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
3417         {
3418                 /* Disturb */
3419                 disturb(0, 1);
3420
3421                 energy_use = 0;
3422                 /* Hack -- Enter quest level */
3423                 command_new = SPECIAL_KEY_QUEST;
3424         }
3425
3426         else if (have_flag(f_ptr->flags, FF_QUEST_EXIT))
3427         {
3428                 if (quest[p_ptr->inside_quest].type == QUEST_TYPE_FIND_EXIT)
3429                 {
3430                         complete_quest(p_ptr->inside_quest);
3431                 }
3432
3433                 leave_quest_check();
3434
3435                 p_ptr->inside_quest = c_ptr->special;
3436                 dun_level = 0;
3437                 p_ptr->oldpx = 0;
3438                 p_ptr->oldpy = 0;
3439
3440                 p_ptr->leaving = TRUE;
3441         }
3442
3443         /* Set off a trap */
3444         else if (have_flag(f_ptr->flags, FF_HIT_TRAP) && !(mpe_mode & MPE_STAYING))
3445         {
3446                 /* Disturb */
3447                 disturb(0, 1);
3448
3449                 /* Hidden trap */
3450                 if (c_ptr->mimic || have_flag(f_ptr->flags, FF_SECRET))
3451                 {
3452                         /* Message */
3453 #ifdef JP
3454                         msg_print("トラップだ!");
3455 #else
3456                         msg_print("You found a trap!");
3457 #endif
3458
3459                         /* Pick a trap */
3460                         disclose_grid(py, px);
3461                 }
3462
3463                 /* Hit the trap */
3464                 hit_trap((mpe_mode & MPE_BREAK_TRAP) ? TRUE : FALSE);
3465
3466                 if (!player_bold(ny, nx) || p_ptr->is_dead || p_ptr->leaving) return FALSE;
3467         }
3468
3469         /* Warn when leaving trap detected region */
3470         if (!(mpe_mode & MPE_STAYING) && (disturb_trap_detect || alert_trap_detect)
3471             && p_ptr->dtrap && !(c_ptr->info & CAVE_IN_DETECT))
3472         {
3473                 /* No duplicate warning */
3474                 p_ptr->dtrap = FALSE;
3475
3476                 /* You are just on the edge */
3477                 if (!(c_ptr->info & CAVE_UNSAFE))
3478                 {
3479                         if (alert_trap_detect)
3480                         {
3481 #ifdef JP
3482                                 msg_print("* 注意:この先はトラップの感知範囲外です! *");
3483 #else
3484                                 msg_print("*Leaving trap detect region!*");
3485 #endif
3486                         }
3487
3488                         if (disturb_trap_detect) disturb(0, 1);
3489                 }
3490         }
3491
3492         return player_bold(ny, nx) && !p_ptr->is_dead && !p_ptr->leaving;
3493 }
3494
3495 /*!
3496  * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す
3497  * @param feat 地形ID
3498  * @return トラップが自動的に無効ならばTRUEを返す
3499  */
3500 bool trap_can_be_ignored(int feat)
3501 {
3502         feature_type *f_ptr = &f_info[feat];
3503
3504         if (!have_flag(f_ptr->flags, FF_TRAP)) return TRUE;
3505
3506         switch (f_ptr->subtype)
3507         {
3508         case TRAP_TRAPDOOR:
3509         case TRAP_PIT:
3510         case TRAP_SPIKED_PIT:
3511         case TRAP_POISON_PIT:
3512                 if (p_ptr->levitation) return TRUE;
3513                 break;
3514         case TRAP_TELEPORT:
3515                 if (p_ptr->anti_tele) return TRUE;
3516                 break;
3517         case TRAP_FIRE:
3518                 if (p_ptr->immune_fire) return TRUE;
3519                 break;
3520         case TRAP_ACID:
3521                 if (p_ptr->immune_acid) return TRUE;
3522                 break;
3523         case TRAP_BLIND:
3524                 if (p_ptr->resist_blind) return TRUE;
3525                 break;
3526         case TRAP_CONFUSE:
3527                 if (p_ptr->resist_conf) return TRUE;
3528                 break;
3529         case TRAP_POISON:
3530                 if (p_ptr->resist_pois) return TRUE;
3531                 break;
3532         case TRAP_SLEEP:
3533                 if (p_ptr->free_act) return TRUE;
3534                 break;
3535         }
3536
3537         return FALSE;
3538 }
3539
3540
3541 /*
3542  * Determine if a "boundary" grid is "floor mimic"
3543  */
3544 #define boundary_floor(C, F, MF) \
3545         ((C)->mimic && permanent_wall(F) && \
3546          (have_flag((MF)->flags, FF_MOVE) || have_flag((MF)->flags, FF_CAN_FLY)) && \
3547          have_flag((MF)->flags, FF_PROJECT) && \
3548          !have_flag((MF)->flags, FF_OPEN))
3549
3550
3551 /*!
3552  * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す /
3553  * Move player in the given direction, with the given "pickup" flag.
3554  * @param dir 移動方向ID
3555  * @param do_pickup 罠解除を試みながらの移動ならばTRUE
3556  * @param break_trap トラップ粉砕処理を行うならばTRUE
3557  * @return 実際に移動が行われたならばTRUEを返す。
3558  * @note
3559  * This routine should (probably) always induce energy expenditure.\n
3560  * @details
3561  * Note that moving will *always* take a turn, and will *always* hit\n
3562  * any monster which might be in the destination grid.  Previously,\n
3563  * moving into walls was "free" and did NOT hit invisible monsters.\n
3564  */
3565 void move_player(int dir, bool do_pickup, bool break_trap)
3566 {
3567         /* Find the result of moving */
3568         int y = py + ddy[dir];
3569         int x = px + ddx[dir];
3570
3571         /* Examine the destination */
3572         cave_type *c_ptr = &cave[y][x];
3573
3574         feature_type *f_ptr = &f_info[c_ptr->feat];
3575
3576         monster_type *m_ptr;
3577
3578         monster_type *riding_m_ptr = &m_list[p_ptr->riding];
3579         monster_race *riding_r_ptr = &r_info[p_ptr->riding ? riding_m_ptr->r_idx : 0]; /* Paranoia */
3580
3581         char m_name[80];
3582
3583         bool p_can_enter = player_can_enter(c_ptr->feat, CEM_P_CAN_ENTER_PATTERN);
3584         bool p_can_kill_walls = FALSE;
3585         bool stormbringer = FALSE;
3586
3587         bool oktomove = TRUE;
3588         bool do_past = FALSE;
3589
3590         /* Exit the area */
3591         if (!dun_level && !p_ptr->wild_mode &&
3592                 ((x == 0) || (x == MAX_WID - 1) ||
3593                  (y == 0) || (y == MAX_HGT - 1)))
3594         {
3595                 /* Can the player enter the grid? */
3596                 if (c_ptr->mimic && player_can_enter(c_ptr->mimic, 0))
3597                 {
3598                         /* Hack: move to new area */
3599                         if ((y == 0) && (x == 0))
3600                         {
3601                                 p_ptr->wilderness_y--;
3602                                 p_ptr->wilderness_x--;
3603                                 p_ptr->oldpy = cur_hgt - 2;
3604                                 p_ptr->oldpx = cur_wid - 2;
3605                                 ambush_flag = FALSE;
3606                         }
3607
3608                         else if ((y == 0) && (x == MAX_WID - 1))
3609                         {
3610                                 p_ptr->wilderness_y--;
3611                                 p_ptr->wilderness_x++;
3612                                 p_ptr->oldpy = cur_hgt - 2;
3613                                 p_ptr->oldpx = 1;
3614                                 ambush_flag = FALSE;
3615                         }
3616
3617                         else if ((y == MAX_HGT - 1) && (x == 0))
3618                         {
3619                                 p_ptr->wilderness_y++;
3620                                 p_ptr->wilderness_x--;
3621                                 p_ptr->oldpy = 1;
3622                                 p_ptr->oldpx = cur_wid - 2;
3623                                 ambush_flag = FALSE;
3624                         }
3625
3626                         else if ((y == MAX_HGT - 1) && (x == MAX_WID - 1))
3627                         {
3628                                 p_ptr->wilderness_y++;
3629                                 p_ptr->wilderness_x++;
3630                                 p_ptr->oldpy = 1;
3631                                 p_ptr->oldpx = 1;
3632                                 ambush_flag = FALSE;
3633                         }
3634
3635                         else if (y == 0)
3636                         {
3637                                 p_ptr->wilderness_y--;
3638                                 p_ptr->oldpy = cur_hgt - 2;
3639                                 p_ptr->oldpx = x;
3640                                 ambush_flag = FALSE;
3641                         }
3642
3643                         else if (y == MAX_HGT - 1)
3644                         {
3645                                 p_ptr->wilderness_y++;
3646                                 p_ptr->oldpy = 1;
3647                                 p_ptr->oldpx = x;
3648                                 ambush_flag = FALSE;
3649                         }
3650
3651                         else if (x == 0)
3652                         {
3653                                 p_ptr->wilderness_x--;
3654                                 p_ptr->oldpx = cur_wid - 2;
3655                                 p_ptr->oldpy = y;
3656                                 ambush_flag = FALSE;
3657                         }
3658
3659                         else if (x == MAX_WID - 1)
3660                         {
3661                                 p_ptr->wilderness_x++;
3662                                 p_ptr->oldpx = 1;
3663                                 p_ptr->oldpy = y;
3664                                 ambush_flag = FALSE;
3665                         }
3666
3667                         p_ptr->leaving = TRUE;
3668                         energy_use = 100;
3669
3670                         return;
3671                 }
3672
3673                 /* "Blocked" message appears later */
3674                 /* oktomove = FALSE; */
3675                 p_can_enter = FALSE;
3676         }
3677
3678         /* Get the monster */
3679         m_ptr = &m_list[c_ptr->m_idx];
3680
3681
3682         if (inventory[INVEN_RARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
3683         if (inventory[INVEN_LARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
3684
3685         /* Player can not walk through "walls"... */
3686         /* unless in Shadow Form */
3687         p_can_kill_walls = p_ptr->kill_wall && have_flag(f_ptr->flags, FF_HURT_DISI) &&
3688                 (!p_can_enter || !have_flag(f_ptr->flags, FF_LOS)) &&
3689                 !have_flag(f_ptr->flags, FF_PERMANENT);
3690
3691         /* Hack -- attack monsters */
3692         if (c_ptr->m_idx && (m_ptr->ml || p_can_enter || p_can_kill_walls))
3693         {
3694                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3695
3696                 /* Attack -- only if we can see it OR it is not in a wall */
3697                 if (!is_hostile(m_ptr) &&
3698                     !(p_ptr->confused || p_ptr->image || !m_ptr->ml || p_ptr->stun ||
3699                     ((p_ptr->muta2 & MUT2_BERS_RAGE) && p_ptr->shero)) &&
3700                     pattern_seq(py, px, y, x) && (p_can_enter || p_can_kill_walls))
3701                 {
3702                         /* Disturb the monster */
3703                         (void)set_monster_csleep(c_ptr->m_idx, 0);
3704
3705                         /* Extract monster name (or "it") */
3706                         monster_desc(m_name, m_ptr, 0);
3707
3708                         if (m_ptr->ml)
3709                         {
3710                                 /* Auto-Recall if possible and visible */
3711                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3712
3713                                 /* Track a new monster */
3714                                 health_track(c_ptr->m_idx);
3715                         }
3716
3717                         /* displace? */
3718                         if ((stormbringer && (randint1(1000) > 666)) || (p_ptr->pclass == CLASS_BERSERKER))
3719                         {
3720                                 py_attack(y, x, 0);
3721                                 oktomove = FALSE;
3722                         }
3723                         else if (monster_can_cross_terrain(cave[py][px].feat, r_ptr, 0))
3724                         {
3725                                 do_past = TRUE;
3726                         }
3727                         else
3728                         {
3729 #ifdef JP
3730                                 msg_format("%^sが邪魔だ!", m_name);
3731 #else
3732                                 msg_format("%^s is in your way!", m_name);
3733 #endif
3734
3735                                 energy_use = 0;
3736                                 oktomove = FALSE;
3737                         }
3738
3739                         /* now continue on to 'movement' */
3740                 }
3741                 else
3742                 {
3743                         py_attack(y, x, 0);
3744                         oktomove = FALSE;
3745                 }
3746         }
3747
3748         if (oktomove && p_ptr->riding)
3749         {
3750                 if (riding_r_ptr->flags1 & RF1_NEVER_MOVE)
3751                 {
3752 #ifdef JP
3753                         msg_print("動けない!");
3754 #else
3755                         msg_print("Can't move!");
3756 #endif
3757                         energy_use = 0;
3758                         oktomove = FALSE;
3759                         disturb(0, 1);
3760                 }
3761                 else if (MON_MONFEAR(riding_m_ptr))
3762                 {
3763                         char m_name[80];
3764
3765                         /* Acquire the monster name */
3766                         monster_desc(m_name, riding_m_ptr, 0);
3767
3768                         /* Dump a message */
3769 #ifdef JP
3770                         msg_format("%sが恐怖していて制御できない。", m_name);
3771 #else
3772                         msg_format("%^s is too scared to control.", m_name);
3773 #endif
3774                         oktomove = FALSE;
3775                         disturb(0, 1);
3776                 }
3777                 else if (p_ptr->riding_ryoute)
3778                 {
3779                         oktomove = FALSE;
3780                         disturb(0, 1);
3781                 }
3782                 else if (have_flag(f_ptr->flags, FF_CAN_FLY) && (riding_r_ptr->flags7 & RF7_CAN_FLY))
3783                 {
3784                         /* Allow moving */
3785                 }
3786                 else if (have_flag(f_ptr->flags, FF_CAN_SWIM) && (riding_r_ptr->flags7 & RF7_CAN_SWIM))
3787                 {
3788                         /* Allow moving */
3789                 }
3790                 else if (have_flag(f_ptr->flags, FF_WATER) &&
3791                         !(riding_r_ptr->flags7 & RF7_AQUATIC) &&
3792                         (have_flag(f_ptr->flags, FF_DEEP) || (riding_r_ptr->flags2 & RF2_AURA_FIRE)))
3793                 {
3794 #ifdef JP
3795                         msg_format("%sの上に行けない。", f_name + f_info[get_feat_mimic(c_ptr)].name);
3796 #else
3797                         msg_print("Can't swim.");
3798 #endif
3799                         energy_use = 0;
3800                         oktomove = FALSE;
3801                         disturb(0, 1);
3802                 }
3803                 else if (!have_flag(f_ptr->flags, FF_WATER) && (riding_r_ptr->flags7 & RF7_AQUATIC))
3804                 {
3805 #ifdef JP
3806                         msg_format("%sから上がれない。", f_name + f_info[get_feat_mimic(&cave[py][px])].name);
3807 #else
3808                         msg_print("Can't land.");
3809 #endif
3810                         energy_use = 0;
3811                         oktomove = FALSE;
3812                         disturb(0, 1);
3813                 }
3814                 else if (have_flag(f_ptr->flags, FF_LAVA) && !(riding_r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
3815                 {
3816 #ifdef JP
3817                         msg_format("%sの上に行けない。", f_name + f_info[get_feat_mimic(c_ptr)].name);
3818 #else
3819                         msg_print("Too hot to go through.");
3820 #endif
3821                         energy_use = 0;
3822                         oktomove = FALSE;
3823                         disturb(0, 1);
3824                 }
3825
3826                 if (oktomove && MON_STUNNED(riding_m_ptr) && one_in_(2))
3827                 {
3828                         char m_name[80];
3829                         monster_desc(m_name, riding_m_ptr, 0);
3830 #ifdef JP
3831                         msg_format("%sが朦朧としていてうまく動けない!",m_name);
3832 #else
3833                         msg_format("You cannot control stunned %s!",m_name);
3834 #endif
3835                         oktomove = FALSE;
3836                         disturb(0, 1);
3837                 }
3838         }
3839
3840         if (!oktomove)
3841         {
3842         }
3843
3844         else if (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation)
3845         {
3846 #ifdef JP
3847                 msg_format("空を飛ばないと%sの上には行けない。", f_name + f_info[get_feat_mimic(c_ptr)].name);
3848 #else
3849                 msg_format("You need to fly to go through the %s.", f_name + f_info[get_feat_mimic(c_ptr)].name);
3850 #endif
3851
3852                 energy_use = 0;
3853                 running = 0;
3854                 oktomove = FALSE;
3855         }
3856
3857         /*
3858          * Player can move through trees and
3859          * has effective -10 speed
3860          * Rangers can move without penality
3861          */
3862         else if (have_flag(f_ptr->flags, FF_TREE) && !p_can_kill_walls)
3863         {
3864                 if ((p_ptr->pclass != CLASS_RANGER) && !p_ptr->levitation && (!p_ptr->riding || !(riding_r_ptr->flags8 & RF8_WILD_WOOD))) energy_use *= 2;
3865         }
3866
3867 #ifdef ALLOW_EASY_DISARM /* TNB */
3868
3869         /* Disarm a visible trap */
3870         else if ((do_pickup != easy_disarm) && have_flag(f_ptr->flags, FF_DISARM) && !c_ptr->mimic)
3871         {
3872                 if (!trap_can_be_ignored(c_ptr->feat))
3873                 {
3874                         (void)do_cmd_disarm_aux(y, x, dir);
3875                         return;
3876                 }
3877         }
3878
3879 #endif /* ALLOW_EASY_DISARM -- TNB */
3880
3881         /* Player can not walk through "walls" unless in wraith form...*/
3882         else if (!p_can_enter && !p_can_kill_walls)
3883         {
3884                 /* Feature code (applying "mimic" field) */
3885                 s16b feat = get_feat_mimic(c_ptr);
3886                 feature_type *mimic_f_ptr = &f_info[feat];
3887                 cptr name = f_name + mimic_f_ptr->name;
3888
3889                 oktomove = FALSE;
3890
3891                 /* Notice things in the dark */
3892                 if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
3893                 {
3894                         /* Boundary floor mimic */
3895                         if (boundary_floor(c_ptr, f_ptr, mimic_f_ptr))
3896                         {
3897 #ifdef JP
3898                                 msg_print("それ以上先には進めないようだ。");
3899 #else
3900                                 msg_print("You feel you cannot go any more.");
3901 #endif
3902                         }
3903
3904                         /* Wall (or secret door) */
3905                         else
3906                         {
3907 #ifdef JP
3908                                 msg_format("%sが行く手をはばんでいるようだ。", name);
3909 #else
3910                                 msg_format("You feel %s %s blocking your way.",
3911                                         is_a_vowel(name[0]) ? "an" : "a", name);
3912 #endif
3913
3914                                 c_ptr->info |= (CAVE_MARK);
3915                                 lite_spot(y, x);
3916                         }
3917                 }
3918
3919                 /* Notice things */
3920                 else
3921                 {
3922                         /* Boundary floor mimic */
3923                         if (boundary_floor(c_ptr, f_ptr, mimic_f_ptr))
3924                         {
3925 #ifdef JP
3926                                 msg_print("それ以上先には進めない。");
3927 #else
3928                                 msg_print("You cannot go any more.");
3929 #endif
3930
3931                                 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
3932                                         energy_use = 0;
3933                         }
3934
3935                         /* Wall (or secret door) */
3936                         else
3937                         {
3938 #ifdef ALLOW_EASY_OPEN
3939                                 /* Closed doors */
3940                                 if (easy_open && is_closed_door(feat) && easy_open_door(y, x)) return;
3941 #endif /* ALLOW_EASY_OPEN */
3942
3943 #ifdef JP
3944                                 msg_format("%sが行く手をはばんでいる。", name);
3945 #else
3946                                 msg_format("There is %s %s blocking your way.",
3947                                         is_a_vowel(name[0]) ? "an" : "a", name);
3948 #endif
3949
3950                                 /*
3951                                  * Well, it makes sense that you lose time bumping into
3952                                  * a wall _if_ you are confused, stunned or blind; but
3953                                  * typing mistakes should not cost you a turn...
3954                                  */
3955                                 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
3956                                         energy_use = 0;
3957                         }
3958                 }
3959
3960                 /* Disturb the player */
3961                 disturb(0, 1);
3962
3963                 /* Sound */
3964                 if (!boundary_floor(c_ptr, f_ptr, mimic_f_ptr)) sound(SOUND_HITWALL);
3965         }
3966
3967         /* Normal movement */
3968         if (oktomove && !pattern_seq(py, px, y, x))
3969         {
3970                 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
3971                 {
3972                         energy_use = 0;
3973                 }
3974
3975                 /* To avoid a loop with running */
3976                 disturb(0, 1);
3977
3978                 oktomove = FALSE;
3979         }
3980
3981         /* Normal movement */
3982         if (oktomove)
3983         {
3984                 u32b mpe_mode = MPE_ENERGY_USE;
3985
3986                 if (p_ptr->warning)
3987                 {
3988                         if (!process_warning(x, y))
3989                         {
3990                                 energy_use = 25;
3991                                 return;
3992                         }
3993                 }
3994
3995                 if (do_past)
3996                 {
3997 #ifdef JP
3998                         msg_format("%sを押し退けた。", m_name);
3999 #else
4000                         msg_format("You push past %s.", m_name);
4001 #endif
4002                 }
4003
4004                 /* Change oldpx and oldpy to place the player well when going back to big mode */
4005                 if (p_ptr->wild_mode)
4006                 {
4007                         if (ddy[dir] > 0)  p_ptr->oldpy = 1;
4008                         if (ddy[dir] < 0)  p_ptr->oldpy = MAX_HGT - 2;
4009                         if (ddy[dir] == 0) p_ptr->oldpy = MAX_HGT / 2;
4010                         if (ddx[dir] > 0)  p_ptr->oldpx = 1;
4011                         if (ddx[dir] < 0)  p_ptr->oldpx = MAX_WID - 2;
4012                         if (ddx[dir] == 0) p_ptr->oldpx = MAX_WID / 2;
4013                 }
4014
4015                 if (p_can_kill_walls)
4016                 {
4017                         cave_alter_feat(y, x, FF_HURT_DISI);
4018
4019                         /* Update some things -- similar to GF_KILL_WALL */
4020                         p_ptr->update |= (PU_FLOW);
4021                 }
4022
4023                 /* Sound */
4024                 /* sound(SOUND_WALK); */
4025
4026 #ifdef ALLOW_EASY_DISARM /* TNB */
4027
4028                 if (do_pickup != always_pickup) mpe_mode |= MPE_DO_PICKUP;
4029
4030 #else /* ALLOW_EASY_DISARM -- TNB */
4031
4032                 if (do_pickup) mpe_mode |= MPE_DO_PICKUP;
4033
4034 #endif /* ALLOW_EASY_DISARM -- TNB */
4035
4036                 if (break_trap) mpe_mode |= MPE_BREAK_TRAP;
4037
4038                 /* Move the player */
4039                 (void)move_player_effect(y, x, mpe_mode);
4040         }
4041 }
4042
4043
4044 static bool ignore_avoid_run;
4045
4046 /*!
4047  * @brief ダッシュ移動処理中、移動先のマスが既知の壁かどうかを判定する /
4048  * Hack -- Check for a "known wall" (see below)
4049  * @param dir 想定する移動方向ID
4050  * @param y 移動元のY座標
4051  * @param x 移動元のX座標
4052  * @return 移動先が既知の壁ならばTRUE
4053  */
4054 static int see_wall(int dir, int y, int x)
4055 {
4056         cave_type   *c_ptr;
4057
4058         /* Get the new location */
4059         y += ddy[dir];
4060         x += ddx[dir];
4061
4062         /* Illegal grids are not known walls */
4063         if (!in_bounds2(y, x)) return (FALSE);
4064
4065         /* Access grid */
4066         c_ptr = &cave[y][x];
4067
4068         /* Must be known to the player */
4069         if (c_ptr->info & (CAVE_MARK))
4070         {
4071                 /* Feature code (applying "mimic" field) */
4072                 s16b         feat = get_feat_mimic(c_ptr);
4073                 feature_type *f_ptr = &f_info[feat];
4074
4075                 /* Wall grids are known walls */
4076                 if (!player_can_enter(feat, 0)) return !have_flag(f_ptr->flags, FF_DOOR);
4077
4078                 /* Don't run on a tree unless explicitly requested */
4079                 if (have_flag(f_ptr->flags, FF_AVOID_RUN) && !ignore_avoid_run)
4080                         return TRUE;
4081
4082                 /* Don't run in a wall */
4083                 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
4084                         return !have_flag(f_ptr->flags, FF_DOOR);
4085         }
4086
4087         return FALSE;
4088 }
4089
4090
4091 /*!
4092  * @brief ダッシュ移動処理中、移動先のマスか未知の地形かどうかを判定する /
4093  * Hack -- Check for an "unknown corner" (see below)
4094  * @param dir 想定する移動方向ID
4095  * @param y 移動元のY座標
4096  * @param x 移動元のX座標
4097  * @return 移動先が未知の地形ならばTRUE
4098  */
4099 static int see_nothing(int dir, int y, int x)
4100 {
4101         /* Get the new location */
4102         y += ddy[dir];
4103         x += ddx[dir];
4104
4105         /* Illegal grids are unknown */
4106         if (!in_bounds2(y, x)) return (TRUE);
4107
4108         /* Memorized grids are always known */
4109         if (cave[y][x].info & (CAVE_MARK)) return (FALSE);
4110
4111         /* Viewable door/wall grids are known */
4112         if (player_can_see_bold(y, x)) return (FALSE);
4113
4114         /* Default */
4115         return (TRUE);
4116 }
4117
4118
4119
4120
4121
4122
4123 /*
4124  * Hack -- allow quick "cycling" through the legal directions
4125  */
4126 static byte cycle[] =
4127 { 1, 2, 3, 6, 9, 8, 7, 4, 1, 2, 3, 6, 9, 8, 7, 4, 1 };
4128
4129 /*
4130  * Hack -- map each direction into the "middle" of the "cycle[]" array
4131  */
4132 static byte chome[] =
4133 { 0, 8, 9, 10, 7, 0, 11, 6, 5, 4 };
4134
4135 /*
4136  * The direction we are running
4137  */
4138 static byte find_current;
4139
4140 /*
4141  * The direction we came from
4142  */
4143 static byte find_prevdir;
4144
4145 /*
4146  * We are looking for open area
4147  */
4148 static bool find_openarea;
4149
4150 /*
4151  * We are looking for a break
4152  */
4153 static bool find_breakright;
4154 static bool find_breakleft;
4155
4156
4157
4158 /*!
4159  * @brief ダッシュ処理の導入 /
4160  * Initialize the running algorithm for a new direction.
4161  * @param dir 導入の移動先
4162  * @details
4163  * Diagonal Corridor -- allow diaginal entry into corridors.\n
4164  *\n
4165  * Blunt Corridor -- If there is a wall two spaces ahead and\n
4166  * we seem to be in a corridor, then force a turn into the side\n
4167  * corridor, must be moving straight into a corridor here. ???\n
4168  *\n
4169  * Diagonal Corridor    Blunt Corridor (?)\n
4170  *       \# \#                  \#\n
4171  *       \#x\#                  \@x\#\n
4172  *       \@\@p.                  p\n
4173  */
4174 static void run_init(int dir)
4175 {
4176         int             row, col, deepleft, deepright;
4177         int             i, shortleft, shortright;
4178
4179
4180         /* Save the direction */
4181         find_current = dir;
4182
4183         /* Assume running straight */
4184         find_prevdir = dir;
4185
4186         /* Assume looking for open area */
4187         find_openarea = TRUE;
4188
4189         /* Assume not looking for breaks */
4190         find_breakright = find_breakleft = FALSE;
4191
4192         /* Assume no nearby walls */
4193         deepleft = deepright = FALSE;
4194         shortright = shortleft = FALSE;
4195
4196         p_ptr->run_py = py;
4197         p_ptr->run_px = px;
4198
4199         /* Find the destination grid */
4200         row = py + ddy[dir];
4201         col = px + ddx[dir];
4202
4203         ignore_avoid_run = cave_have_flag_bold(row, col, FF_AVOID_RUN);
4204
4205         /* Extract cycle index */
4206         i = chome[dir];
4207
4208         /* Check for walls */
4209         if (see_wall(cycle[i+1], py, px))
4210         {
4211                 find_breakleft = TRUE;
4212                 shortleft = TRUE;
4213         }
4214         else if (see_wall(cycle[i+1], row, col))
4215         {
4216                 find_breakleft = TRUE;
4217                 deepleft = TRUE;
4218         }
4219
4220         /* Check for walls */
4221         if (see_wall(cycle[i-1], py, px))
4222         {
4223                 find_breakright = TRUE;
4224                 shortright = TRUE;
4225         }
4226         else if (see_wall(cycle[i-1], row, col))
4227         {
4228                 find_breakright = TRUE;
4229                 deepright = TRUE;
4230         }
4231
4232         /* Looking for a break */
4233         if (find_breakleft && find_breakright)
4234         {
4235                 /* Not looking for open area */
4236                 find_openarea = FALSE;
4237
4238                 /* Hack -- allow angled corridor entry */
4239                 if (dir & 0x01)
4240                 {
4241                         if (deepleft && !deepright)
4242                         {
4243                                 find_prevdir = cycle[i - 1];
4244                         }
4245                         else if (deepright && !deepleft)
4246                         {
4247                                 find_prevdir = cycle[i + 1];
4248                         }
4249                 }
4250
4251                 /* Hack -- allow blunt corridor entry */
4252                 else if (see_wall(cycle[i], row, col))
4253                 {
4254                         if (shortleft && !shortright)
4255                         {
4256                                 find_prevdir = cycle[i - 2];
4257                         }
4258                         else if (shortright && !shortleft)
4259                         {
4260                                 find_prevdir = cycle[i + 2];
4261                         }
4262                 }
4263         }
4264 }
4265
4266
4267 /*!
4268  * @brief ダッシュ移動が継続できるかどうかの判定 /
4269  * Update the current "run" path
4270  * @return
4271  * ダッシュ移動が継続できるならばTRUEを返す。
4272  * Return TRUE if the running should be stopped
4273  */
4274 static bool run_test(void)
4275 {
4276         int         prev_dir, new_dir, check_dir = 0;
4277         int         row, col;
4278         int         i, max, inv;
4279         int         option = 0, option2 = 0;
4280         cave_type   *c_ptr;
4281         s16b        feat;
4282         feature_type *f_ptr;
4283
4284         /* Where we came from */
4285         prev_dir = find_prevdir;
4286
4287
4288         /* Range of newly adjacent grids */
4289         max = (prev_dir & 0x01) + 1;
4290
4291         /* break run when leaving trap detected region */
4292         if ((disturb_trap_detect || alert_trap_detect)
4293             && p_ptr->dtrap && !(cave[py][px].info & CAVE_IN_DETECT))
4294         {
4295                 /* No duplicate warning */
4296                 p_ptr->dtrap = FALSE;
4297
4298                 /* You are just on the edge */
4299                 if (!(cave[py][px].info & CAVE_UNSAFE))
4300                 {
4301                         if (alert_trap_detect)
4302                         {
4303 #ifdef JP
4304                                 msg_print("* 注意:この先はトラップの感知範囲外です! *");
4305 #else
4306                                 msg_print("*Leaving trap detect region!*");
4307 #endif
4308                         }
4309
4310                         if (disturb_trap_detect)
4311                         {
4312                                 /* Break Run */
4313                                 return(TRUE);
4314                         }
4315                 }
4316         }
4317
4318         /* Look at every newly adjacent square. */
4319         for (i = -max; i <= max; i++)
4320         {
4321                 s16b this_o_idx, next_o_idx = 0;
4322
4323                 /* New direction */
4324                 new_dir = cycle[chome[prev_dir] + i];
4325
4326                 /* New location */
4327                 row = py + ddy[new_dir];
4328                 col = px + ddx[new_dir];
4329
4330                 /* Access grid */
4331                 c_ptr = &cave[row][col];
4332
4333                 /* Feature code (applying "mimic" field) */
4334                 feat = get_feat_mimic(c_ptr);
4335                 f_ptr = &f_info[feat];
4336
4337                 /* Visible monsters abort running */
4338                 if (c_ptr->m_idx)
4339                 {
4340                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4341
4342                         /* Visible monster */
4343                         if (m_ptr->ml) return (TRUE);
4344                 }
4345
4346                 /* Visible objects abort running */
4347                 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
4348                 {
4349                         object_type *o_ptr;
4350
4351                         /* Acquire object */
4352                         o_ptr = &o_list[this_o_idx];
4353
4354                         /* Acquire next object */
4355                         next_o_idx = o_ptr->next_o_idx;
4356
4357                         /* Visible object */
4358                         if (o_ptr->marked & OM_FOUND) return (TRUE);
4359                 }
4360
4361                 /* Assume unknown */
4362                 inv = TRUE;
4363
4364                 /* Check memorized grids */
4365                 if (c_ptr->info & (CAVE_MARK))
4366                 {
4367                         bool notice = have_flag(f_ptr->flags, FF_NOTICE);
4368
4369                         if (notice && have_flag(f_ptr->flags, FF_MOVE))
4370                         {
4371                                 /* Open doors */
4372                                 if (find_ignore_doors && have_flag(f_ptr->flags, FF_DOOR) && have_flag(f_ptr->flags, FF_CLOSE))
4373                                 {
4374                                         /* Option -- ignore */
4375                                         notice = FALSE;
4376                                 }
4377
4378                                 /* Stairs */
4379                                 else if (find_ignore_stairs && have_flag(f_ptr->flags, FF_STAIRS))
4380                                 {
4381                                         /* Option -- ignore */
4382                                         notice = FALSE;
4383                                 }
4384
4385                                 /* Lava */
4386                                 else if (have_flag(f_ptr->flags, FF_LAVA) && (p_ptr->immune_fire || IS_INVULN()))
4387                                 {
4388                                         /* Ignore */
4389                                         notice = FALSE;
4390                                 }
4391
4392                                 /* Deep water */
4393                                 else if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP) &&
4394                                          (p_ptr->levitation || p_ptr->can_swim || (p_ptr->total_weight <= weight_limit())))
4395                                 {
4396                                         /* Ignore */
4397                                         notice = FALSE;
4398                                 }
4399                         }
4400
4401                         /* Interesting feature */
4402                         if (notice) return (TRUE);
4403
4404                         /* The grid is "visible" */
4405                         inv = FALSE;
4406                 }
4407
4408                 /* Analyze unknown grids and floors considering mimic */
4409                 if (inv || !see_wall(0, row, col))
4410                 {
4411                         /* Looking for open area */
4412                         if (find_openarea)
4413                         {
4414                                 /* Nothing */
4415                         }
4416
4417                         /* The first new direction. */
4418                         else if (!option)
4419                         {
4420                                 option = new_dir;
4421                         }
4422
4423                         /* Three new directions. Stop running. */
4424                         else if (option2)
4425                         {
4426                                 return (TRUE);
4427                         }
4428
4429                         /* Two non-adjacent new directions.  Stop running. */
4430                         else if (option != cycle[chome[prev_dir] + i - 1])
4431                         {
4432                                 return (TRUE);
4433                         }
4434
4435                         /* Two new (adjacent) directions (case 1) */
4436                         else if (new_dir & 0x01)
4437                         {
4438                                 check_dir = cycle[chome[prev_dir] + i - 2];
4439                                 option2 = new_dir;
4440                         }
4441
4442                         /* Two new (adjacent) directions (case 2) */
4443                         else
4444                         {
4445                                 check_dir = cycle[chome[prev_dir] + i + 1];
4446                                 option2 = option;
4447                                 option = new_dir;
4448                         }
4449                 }
4450
4451                 /* Obstacle, while looking for open area */
4452                 else
4453                 {
4454                         if (find_openarea)
4455                         {
4456                                 if (i < 0)
4457                                 {
4458                                         /* Break to the right */
4459                                         find_breakright = TRUE;
4460                                 }
4461
4462                                 else if (i > 0)
4463                                 {
4464                                         /* Break to the left */
4465                                         find_breakleft = TRUE;
4466                                 }
4467                         }
4468                 }
4469         }
4470
4471         /* Looking for open area */
4472         if (find_openarea)
4473         {
4474                 /* Hack -- look again */
4475                 for (i = -max; i < 0; i++)
4476                 {
4477                         /* Unknown grid or non-wall */
4478                         if (!see_wall(cycle[chome[prev_dir] + i], py, px))
4479                         {
4480                                 /* Looking to break right */
4481                                 if (find_breakright)
4482                                 {
4483                                         return (TRUE);
4484                                 }
4485                         }
4486
4487                         /* Obstacle */
4488                         else
4489                         {
4490                                 /* Looking to break left */
4491                                 if (find_breakleft)
4492                                 {
4493                                         return (TRUE);
4494                                 }
4495                         }
4496                 }
4497
4498                 /* Hack -- look again */
4499                 for (i = max; i > 0; i--)
4500                 {
4501                         /* Unknown grid or non-wall */
4502                         if (!see_wall(cycle[chome[prev_dir] + i], py, px))
4503                         {
4504                                 /* Looking to break left */
4505                                 if (find_breakleft)
4506                                 {
4507                                         return (TRUE);
4508                                 }
4509                         }
4510
4511                         /* Obstacle */
4512                         else
4513                         {
4514                                 /* Looking to break right */
4515                                 if (find_breakright)
4516                                 {
4517                                         return (TRUE);
4518                                 }
4519                         }
4520                 }
4521         }
4522
4523         /* Not looking for open area */
4524         else
4525         {
4526                 /* No options */
4527                 if (!option)
4528                 {
4529                         return (TRUE);
4530                 }
4531
4532                 /* One option */
4533                 else if (!option2)
4534                 {
4535                         /* Primary option */
4536                         find_current = option;
4537
4538                         /* No other options */
4539                         find_prevdir = option;
4540                 }
4541
4542                 /* Two options, examining corners */
4543                 else if (!find_cut)
4544                 {
4545                         /* Primary option */
4546                         find_current = option;
4547
4548                         /* Hack -- allow curving */
4549                         find_prevdir = option2;
4550                 }
4551
4552                 /* Two options, pick one */
4553                 else
4554                 {
4555                         /* Get next location */
4556                         row = py + ddy[option];
4557                         col = px + ddx[option];
4558
4559                         /* Don't see that it is closed off. */
4560                         /* This could be a potential corner or an intersection. */
4561                         if (!see_wall(option, row, col) ||
4562                             !see_wall(check_dir, row, col))
4563                         {
4564                                 /* Can not see anything ahead and in the direction we */
4565                                 /* are turning, assume that it is a potential corner. */
4566                                 if (see_nothing(option, row, col) &&
4567                                     see_nothing(option2, row, col))
4568                                 {
4569                                         find_current = option;
4570                                         find_prevdir = option2;
4571                                 }
4572
4573                                 /* STOP: we are next to an intersection or a room */
4574                                 else
4575                                 {
4576                                         return (TRUE);
4577                                 }
4578                         }
4579
4580                         /* This corner is seen to be enclosed; we cut the corner. */
4581                         else if (find_cut)
4582                         {
4583                                 find_current = option2;
4584                                 find_prevdir = option2;
4585                         }
4586
4587                         /* This corner is seen to be enclosed, and we */
4588                         /* deliberately go the long way. */
4589                         else
4590                         {
4591                                 find_current = option;
4592                                 find_prevdir = option2;
4593                         }
4594                 }
4595         }
4596
4597         /* About to hit a known wall, stop */
4598         if (see_wall(find_current, py, px))
4599         {
4600                 return (TRUE);
4601         }
4602
4603         /* Failure */
4604         return (FALSE);
4605 }
4606
4607
4608
4609 /*!
4610  * @brief 継続的なダッシュ処理 /
4611  * Take one step along the current "run" path
4612  * @param dir 移動を試みる方向ID
4613  * @return なし
4614  */
4615 void run_step(int dir)
4616 {
4617         /* Start running */
4618         if (dir)
4619         {
4620                 /* Ignore AVOID_RUN on a first step */
4621                 ignore_avoid_run = TRUE;
4622
4623                 /* Hack -- do not start silly run */
4624                 if (see_wall(dir, py, px))
4625                 {
4626                         /* Message */
4627 #ifdef JP
4628                         msg_print("その方向には走れません。");
4629 #else
4630                         msg_print("You cannot run in that direction.");
4631 #endif
4632
4633                         /* Disturb */
4634                         disturb(0, 0);
4635
4636                         /* Done */
4637                         return;
4638                 }
4639
4640                 /* Initialize */
4641                 run_init(dir);
4642         }
4643
4644         /* Keep running */
4645         else
4646         {
4647                 /* Update run */
4648                 if (run_test())
4649                 {
4650                         /* Disturb */
4651                         disturb(0, 0);
4652
4653                         /* Done */
4654                         return;
4655                 }
4656         }
4657
4658         /* Decrease the run counter */
4659         if (--running <= 0) return;
4660
4661         /* Take time */
4662         energy_use = 100;
4663
4664         /* Move the player, using the "pickup" flag */
4665 #ifdef ALLOW_EASY_DISARM /* TNB */
4666
4667         move_player(find_current, FALSE, FALSE);
4668
4669 #else /* ALLOW_EASY_DISARM -- TNB */
4670
4671         move_player(find_current, always_pickup, FALSE);
4672
4673 #endif /* ALLOW_EASY_DISARM -- TNB */
4674
4675         if (player_bold(p_ptr->run_py, p_ptr->run_px))
4676         {
4677                 p_ptr->run_py = 0;
4678                 p_ptr->run_px = 0;
4679                 disturb(0, 0);
4680         }
4681 }
4682
4683
4684 #ifdef TRAVEL
4685
4686 /*!
4687  * @brief トラベル機能の判定処理 /
4688  * Test for traveling
4689  * @param prev_dir 前回移動を行った元の方角ID
4690  * @return なし
4691  */
4692 static int travel_test(int prev_dir)
4693 {
4694         int new_dir = 0;
4695         int i, max;
4696         const cave_type *c_ptr;
4697         int cost;
4698
4699         /* Cannot travel when blind */
4700         if (p_ptr->blind || no_lite())
4701         {
4702                 msg_print(_("目が見えない!", "You cannot see!"));
4703                 return (0);
4704         }
4705
4706         /* break run when leaving trap detected region */
4707         if ((disturb_trap_detect || alert_trap_detect)
4708             && p_ptr->dtrap && !(cave[py][px].info & CAVE_IN_DETECT))
4709         {
4710                 /* No duplicate warning */
4711                 p_ptr->dtrap = FALSE;
4712
4713                 /* You are just on the edge */
4714                 if (!(cave[py][px].info & CAVE_UNSAFE))
4715                 {
4716                         if (alert_trap_detect)
4717                         {
4718 #ifdef JP
4719                                 msg_print("* 注意:この先はトラップの感知範囲外です! *");
4720 #else
4721                                 msg_print("*Leaving trap detect region!*");
4722 #endif
4723                         }
4724
4725                         if (disturb_trap_detect)
4726                         {
4727                                 /* Break Run */
4728                                 return (0);
4729                         }
4730                 }
4731         }
4732
4733         /* Range of newly adjacent grids */
4734         max = (prev_dir & 0x01) + 1;
4735
4736         /* Look at every newly adjacent square. */
4737         for (i = -max; i <= max; i++)
4738         {
4739                 /* New direction */
4740                 int dir = cycle[chome[prev_dir] + i];
4741
4742                 /* New location */
4743                 int row = py + ddy[dir];
4744                 int col = px + ddx[dir];
4745
4746                 /* Access grid */
4747                 c_ptr = &cave[row][col];
4748
4749                 /* Visible monsters abort running */
4750                 if (c_ptr->m_idx)
4751                 {
4752                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4753
4754                         /* Visible monster */
4755                         if (m_ptr->ml) return (0);
4756                 }
4757
4758         }
4759
4760         /* Travel cost of current grid */
4761         cost = travel.cost[py][px];
4762
4763         /* Determine travel direction */
4764         for (i = 0; i < 8; ++ i) {
4765                 int dir_cost = travel.cost[py+ddy_ddd[i]][px+ddx_ddd[i]];
4766
4767                 if (dir_cost < cost)
4768                 {
4769                         new_dir = ddd[i];
4770                         cost = dir_cost;
4771                 }
4772         }
4773
4774         if (!new_dir) return (0);
4775
4776         /* Access newly move grid */
4777         c_ptr = &cave[py+ddy[new_dir]][px+ddx[new_dir]];
4778
4779         /* Close door abort traveling */
4780         if (!easy_open && is_closed_door(c_ptr->feat)) return (0);
4781
4782         /* Visible and unignorable trap abort tarveling */
4783         if (!c_ptr->mimic && !trap_can_be_ignored(c_ptr->feat)) return (0);
4784
4785         /* Move new grid */
4786         return (new_dir);
4787 }
4788
4789
4790 /*!
4791  * @brief トラベル機能の実装 /
4792  * Travel command
4793  * @return なし
4794  */
4795 void travel_step(void)
4796 {
4797         /* Get travel direction */
4798         travel.dir = travel_test(travel.dir);
4799
4800         /* disturb */
4801         if (!travel.dir)
4802         {
4803                 if (travel.run == 255)
4804                 {
4805 #ifdef JP
4806                         msg_print("道筋が見つかりません!");
4807 #else
4808                         msg_print("No route is found!");
4809 #endif
4810                         travel.y = travel.x = 0;
4811                 }
4812                 disturb(0, 1);
4813                 return;
4814         }
4815
4816         energy_use = 100;
4817
4818         move_player(travel.dir, always_pickup, FALSE);
4819
4820         if ((py == travel.y) && (px == travel.x))
4821         {
4822                 travel.run = 0;
4823                 travel.y = travel.x = 0;
4824         }
4825         else if (travel.run > 0)
4826                 travel.run--;
4827
4828         /* Travel Delay */
4829         Term_xtra(TERM_XTRA_DELAY, delay_factor);
4830 }
4831 #endif