OSDN Git Service

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