OSDN Git Service

#37287 #37353 (2.2.0.89) ACTION_IDX 型を定義し、型の置換を継続中。 / Define ACTION_IDX, ongoing...
[hengband/hengband.git] / src / cmd1.c
1 /*!
2  *  @file cmd1.c
3  *  @brief プレイヤーのコマンド処理1 / Movement commands (part 1)
4  *  @date 2014/01/02
5  *  @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  * @note
12  * <pre>
13  * The running algorithm:                       -CJS-
14  *
15  * In the diagrams below, the player has just arrived in the
16  * grid marked as '@', and he has just come from a grid marked
17  * as 'o', and he is about to enter the grid marked as 'x'.
18  *
19  * Of course, if the "requested" move was impossible, then you
20  * will of course be blocked, and will stop.
21  *
22  * Overview: You keep moving until something interesting happens.
23  * If you are in an enclosed space, you follow corners. This is
24  * the usual corridor scheme. If you are in an open space, you go
25  * straight, but stop before entering enclosed space. This is
26  * analogous to reaching doorways. If you have enclosed space on
27  * one side only (that is, running along side a wall) stop if
28  * your wall opens out, or your open space closes in. Either case
29  * corresponds to a doorway.
30  *
31  * What happens depends on what you can really SEE. (i.e. if you
32  * have no light, then running along a dark corridor is JUST like
33  * running in a dark room.) The algorithm works equally well in
34  * corridors, rooms, mine tailings, earthquake rubble, etc, etc.
35  *
36  * These conditions are kept in static memory:
37  * find_openarea         You are in the open on at least one
38  * side.
39  * find_breakleft        You have a wall on the left, and will
40  * stop if it opens
41  * find_breakright       You have a wall on the right, and will
42  * stop if it opens
43  *
44  * To initialize these conditions, we examine the grids adjacent
45  * to the grid marked 'x', two on each side (marked 'L' and 'R').
46  * If either one of the two grids on a given side is seen to be
47  * closed, then that side is considered to be closed. If both
48  * sides are closed, then it is an enclosed (corridor) run.
49  *
50  * LL           L
51  * @@x          LxR
52  * RR          @@R
53  *
54  * Looking at more than just the immediate squares is
55  * significant. Consider the following case. A run along the
56  * corridor will stop just before entering the center point,
57  * because a choice is clearly established. Running in any of
58  * three available directions will be defined as a corridor run.
59  * Note that a minor hack is inserted to make the angled corridor
60  * entry (with one side blocked near and the other side blocked
61  * further away from the runner) work correctly. The runner moves
62  * diagonally, but then saves the previous direction as being
63  * straight into the gap. Otherwise, the tail end of the other
64  * entry would be perceived as an alternative on the next move.
65  *
66  * \#.\#
67  * \#\#.\#\#
68  * \.\@x..
69  * \#\#.\#\#
70  * \#.\#
71  *
72  * Likewise, a run along a wall, and then into a doorway (two
73  * runs) will work correctly. A single run rightwards from \@ will
74  * stop at 1. Another run right and down will enter the corridor
75  * and make the corner, stopping at the 2.
76  *
77  * \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
78  * o@@x       1
79  * \#\#\#\#\#\#\#\#\#\#\# \#\#\#\#\#\#
80  * \#2          \#
81  * \#\#\#\#\#\#\#\#\#\#\#\#\#
82  *
83  * After any move, the function area_affect is called to
84  * determine the new surroundings, and the direction of
85  * subsequent moves. It examines the current player location
86  * (at which the runner has just arrived) and the previous
87  * direction (from which the runner is considered to have come).
88  *
89  * Moving one square in some direction places you adjacent to
90  * three or five new squares (for straight and diagonal moves
91  * respectively) to which you were not previously adjacent,
92  * marked as '!' in the diagrams below.
93  *
94  *   ...!              ...
95  *   .o@@!  (normal)    .o.!  (diagonal)
96  *   ...!  (east)      ..@@!  (south east)
97  *                      !!!
98  *
99  * You STOP if any of the new squares are interesting in any way:
100  * for example, if they contain visible monsters or treasure.
101  *
102  * You STOP if any of the newly adjacent squares seem to be open,
103  * and you are also looking for a break on that side. (that is,
104  * find_openarea AND find_break).
105  *
106  * You STOP if any of the newly adjacent squares do NOT seem to be
107  * open and you are in an open area, and that side was previously
108  * entirely open.
109  *
110  * Corners: If you are not in the open (i.e. you are in a corridor)
111  * and there is only one way to go in the new squares, then turn in
112  * that direction. If there are more than two new ways to go, STOP.
113  * If there are two ways to go, and those ways are separated by a
114  * square which does not seem to be open, then STOP.
115  *
116  * Otherwise, we have a potential corner. There are two new open
117  * squares, which are also adjacent. One of the new squares is
118  * diagonally located, the other is straight on (as in the diagram).
119  * We consider two more squares further out (marked below as ?).
120  *
121  * We assign "option" to the straight-on grid, and "option2" to the
122  * diagonal grid, and "check_dir" to the grid marked 's'.
123  *
124  * \#\#s
125  * @@x?
126  * \#.?
127  *
128  * If they are both seen to be closed, then it is seen that no benefit
129  * is gained from moving straight. It is a known corner.  To cut the
130  * corner, go diagonally, otherwise go straight, but pretend you
131  * stepped diagonally into that next location for a full view next
132  * time. Conversely, if one of the ? squares is not seen to be closed,
133  * then there is a potential choice. We check to see whether it is a
134  * potential corner or an intersection/room entrance.  If the square
135  * two spaces straight ahead, and the space marked with 's' are both
136  * unknown space, then it is a potential corner and enter if
137  * find_examine is set, otherwise must stop because it is not a
138  * corner. (find_examine option is removed and always is TRUE.)
139  * </pre>
140  */
141
142
143 #include "angband.h"
144 #define MAX_VAMPIRIC_DRAIN 50 /*!< 吸血処理の最大回復HP */
145
146
147 /*!
148  * @brief プレイヤーからモンスターへの射撃命中判定 /
149  * Determine if the player "hits" a monster (normal combat).
150  * @param chance 基本命中値
151  * @param m_ptr モンスターの構造体参照ポインタ
152  * @param vis 目標を視界に捕らえているならばTRUEを指定
153  * @param o_name メッセージ表示時のモンスター名
154  * @return 命中と判定された場合TRUEを返す
155  * @note Always miss 5%, always hit 5%, otherwise random.
156  */
157 bool test_hit_fire(int chance, monster_type *m_ptr, int vis, char* o_name)
158 {
159         int k, ac;
160         monster_race *r_ptr = &r_info[m_ptr->r_idx];
161
162         /* 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(int y, int x)
571 {
572         s16b this_o_idx, next_o_idx = 0;
573
574         cave_type *c_ptr;
575
576         /* Access the grid */
577         c_ptr = &cave[y][x];
578
579         /* Invisible trap */
580         if (c_ptr->mimic && is_trap(c_ptr->feat))
581         {
582                 /* Pick a trap */
583                 disclose_grid(y, x);
584
585                 /* Message */
586                 msg_print(_("トラップを発見した。", "You have found a trap."));
587
588                 /* Disturb */
589                 disturb(0, 1);
590         }
591
592         /* Secret door */
593         if (is_hidden_door(c_ptr))
594         {
595                 /* Message */
596                 msg_print(_("隠しドアを発見した。", "You have found a secret door."));
597
598                 /* Disclose */
599                 disclose_grid(y, x);
600
601                 /* Disturb */
602                 disturb(0, 0);
603         }
604
605         /* Scan all objects in the grid */
606         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
607         {
608                 object_type *o_ptr;
609
610                 /* Acquire object */
611                 o_ptr = &o_list[this_o_idx];
612
613                 /* Acquire next object */
614                 next_o_idx = o_ptr->next_o_idx;
615
616                 /* Skip non-chests */
617                 if (o_ptr->tval != TV_CHEST) continue;
618
619                 /* Skip non-trapped chests */
620                 if (!chest_traps[o_ptr->pval]) continue;
621
622                 /* Identify once */
623                 if (!object_is_known(o_ptr))
624                 {
625                         /* Message */
626                         msg_print(_("箱に仕掛けられたトラップを発見した!", "You have discovered a trap on the chest!"));
627
628                         /* Know the trap */
629                         object_known(o_ptr);
630
631                         /* Notice it */
632                         disturb(0, 0);
633                 }
634         }
635 }
636
637 /*!
638  * @brief プレイヤーの探索処理判定
639  * @return なし
640  */
641 void search(void)
642 {
643         int i, 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  * @brief プレイヤーへのトラップ命中判定 /
912  * Determine if a trap affects the player.
913  * @param power 基本回避難度
914  * @return トラップが命中した場合TRUEを返す。
915  * @details
916  * Always miss 5% of the time, Always hit 5% of the time.
917  * Otherwise, match trap power against player armor.
918  */
919 static int check_hit(int power)
920 {
921         int k, ac;
922
923         /* Percentile dice */
924         k = randint0(100);
925
926         /* Hack -- 5% hit, 5% miss */
927         if (k < 10) return (k < 5);
928
929         if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
930                 if (one_in_(20)) return (TRUE);
931
932         /* Paranoia -- No power */
933         if (power <= 0) return (FALSE);
934
935         /* Total armor */
936         ac = p_ptr->ac + p_ptr->to_a;
937
938         /* Power competes against Armor */
939         if (randint1(power) > ((ac * 3) / 4)) return (TRUE);
940
941         /* Assume miss */
942         return (FALSE);
943 }
944
945
946 /*!
947  * @brief 落とし穴系トラップの判定とプレイヤーの被害処理
948  * @param trap_feat_type トラップの種別ID
949  * @return なし
950  */
951 static void hit_trap_pit(int trap_feat_type)
952 {
953         HIT_POINT dam;
954         cptr trap_name = "";
955         cptr spike_name = "";
956
957         switch (trap_feat_type)
958         {
959         case TRAP_PIT:
960                 trap_name = _("落とし穴", "a pit trap");
961                 break;
962         case TRAP_SPIKED_PIT:
963                 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
964                 spike_name = _("スパイク", "spikes");
965                 break;
966         case TRAP_POISON_PIT:
967                 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
968                 spike_name = _("毒を塗られたスパイク", "poisonous spikes");
969                 break;
970         default:
971                 return;
972         }
973
974         if (p_ptr->levitation)
975         {
976                 msg_format(_("%sを飛び越えた。", "You fly over %s."), trap_name);
977                 return;
978         }
979
980         msg_format(_("%sに落ちてしまった!", "You have fallen into %s!"), trap_name);
981
982         /* Base damage */
983         dam = damroll(2, 6);
984
985         /* Extra spike damage */
986         if ((trap_feat_type == TRAP_SPIKED_PIT || trap_feat_type == TRAP_POISON_PIT) &&
987             one_in_(2))
988         {
989                 msg_format(_("%sが刺さった!", "You are impaled on %s!"), spike_name);
990
991                 dam = dam * 2;
992                 (void)set_cut(p_ptr->cut + randint1(dam));
993
994                 if (trap_feat_type == TRAP_POISON_PIT) {
995                         if (p_ptr->resist_pois || IS_OPPOSE_POIS())
996                         {
997                                 msg_print(_("しかし毒の影響はなかった!", "The poison does not affect you!"));
998                         }
999                         else
1000                         {
1001                                 dam = dam * 2;
1002                                 (void)set_poisoned(p_ptr->poisoned + randint1(dam));
1003                         }
1004                 }
1005         }
1006
1007         /* Take the damage */
1008         take_hit(DAMAGE_NOESCAPE, dam, trap_name, -1);
1009 }
1010
1011 /*!
1012  * @brief ダーツ系トラップ(通常ダメージ)の判定とプレイヤーの被害処理
1013  * @return ダーツが命中した場合TRUEを返す
1014  */
1015 static bool hit_trap_dart(void)
1016 {
1017         bool hit = FALSE;
1018
1019         if (check_hit(125))
1020         {
1021                 msg_print(_("小さなダーツが飛んできて刺さった!", "A small dart hits you!"));
1022
1023                 take_hit(DAMAGE_ATTACK, damroll(1, 4), _("ダーツの罠", "a dart trap"), -1);
1024
1025                 if (!CHECK_MULTISHADOW()) hit = TRUE;
1026         }
1027         else
1028         {
1029                 msg_print(_("小さなダーツが飛んできた!が、運良く当たらなかった。", "A small dart barely misses you."));
1030         }
1031
1032         return hit;
1033 }
1034
1035 /*!
1036  * @brief ダーツ系トラップ(通常ダメージ+能力値減少)の判定とプレイヤーの被害処理
1037  * @param stat 低下する能力値ID
1038  * @return なし
1039  */
1040 static void hit_trap_lose_stat(int stat)
1041 {
1042         if (hit_trap_dart())
1043         {
1044                 do_dec_stat(stat);
1045         }
1046 }
1047
1048 /*!
1049  * @brief ダーツ系トラップ(通常ダメージ+減速)の判定とプレイヤーの被害処理
1050  * @return なし
1051  */
1052 static void hit_trap_slow(void)
1053 {
1054         if (hit_trap_dart())
1055         {
1056                 set_slow(p_ptr->slow + randint0(20) + 20, FALSE);
1057         }
1058 }
1059
1060 /*!
1061  * @brief ダーツ系トラップ(通常ダメージ+状態異常)の判定とプレイヤーの被害処理
1062  * @param trap_message メッセージの補完文字列
1063  * @param resist 状態異常に抵抗する判定が出たならTRUE
1064  * @param set_status 状態異常を指定する関数ポインタ
1065  * @param turn 状態異常の追加ターン量
1066  * @return なし
1067  */
1068 static void hit_trap_set_abnormal_status(cptr trap_message, bool resist, bool (*set_status)(IDX), IDX turn_aux)
1069 {
1070         msg_print(trap_message);
1071
1072         if (!resist)
1073         {
1074                 set_status(turn_aux);
1075         }
1076 }
1077
1078 /*!
1079  * @brief プレイヤーへのトラップ作動処理メインルーチン /
1080  * Handle player hitting a real trap
1081  * @param break_trap 作動後のトラップ破壊が確定しているならばTRUE
1082  * @return なし
1083  */
1084 static void hit_trap(bool break_trap)
1085 {
1086         int i, num, dam;
1087         int x = p_ptr->x, y = p_ptr->y;
1088
1089         /* Get the cave grid */
1090         cave_type *c_ptr = &cave[y][x];
1091         feature_type *f_ptr = &f_info[c_ptr->feat];
1092         int trap_feat_type = have_flag(f_ptr->flags, FF_TRAP) ? f_ptr->subtype : NOT_TRAP;
1093         cptr name = _("トラップ", "a trap");
1094
1095         /* Disturb the player */
1096         disturb(0, 1);
1097
1098         cave_alter_feat(y, x, FF_HIT_TRAP);
1099
1100         /* Analyze XXX XXX XXX */
1101         switch (trap_feat_type)
1102         {
1103                 case TRAP_TRAPDOOR:
1104                 {
1105                         if (p_ptr->levitation)
1106                         {
1107                                 msg_print(_("落とし戸を飛び越えた。", "You fly over a trap door."));
1108                         }
1109                         else
1110                         {
1111                                 msg_print(_("落とし戸に落ちた!", "You have fallen through a trap door!"));
1112                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1113                                         msg_print(_("くっそ~!", ""));
1114
1115                                 sound(SOUND_FALL);
1116                                 dam = damroll(2, 8);
1117                                 name = _("落とし戸", "a trap door");
1118
1119                                 take_hit(DAMAGE_NOESCAPE, dam, name, -1);
1120
1121                                 /* Still alive and autosave enabled */
1122                                 if (autosave_l && (p_ptr->chp >= 0))
1123                                         do_cmd_save_game(TRUE);
1124
1125                                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("落とし戸に落ちた", "You have fallen through a trap door!"));
1126                                 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
1127
1128                                 /* Leaving */
1129                                 p_ptr->leaving = TRUE;
1130                         }
1131                         break;
1132                 }
1133
1134                 case TRAP_PIT:
1135                 case TRAP_SPIKED_PIT:
1136                 case TRAP_POISON_PIT:
1137                 {
1138                         hit_trap_pit(trap_feat_type);
1139                         break;
1140                 }
1141
1142                 case TRAP_TY_CURSE:
1143                 {
1144                         msg_print(_("何かがピカッと光った!", "There is a flash of shimmering light!"));
1145                         num = 2 + randint1(3);
1146                         for (i = 0; i < num; i++)
1147                         {
1148                                 (void)summon_specific(0, y, x, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
1149                         }
1150
1151                         if (dun_level > randint1(100)) /* No nasty effect for low levels */
1152                         {
1153                                 bool stop_ty = FALSE;
1154                                 int count = 0;
1155
1156                                 do
1157                                 {
1158                                         stop_ty = activate_ty_curse(stop_ty, &count);
1159                                 }
1160                                 while (one_in_(6));
1161                         }
1162                         break;
1163                 }
1164
1165                 case TRAP_TELEPORT:
1166                 {
1167                         msg_print(_("テレポート・トラップにひっかかった!", "You hit a teleport trap!"));
1168                         teleport_player(100, TELEPORT_PASSIVE);
1169                         break;
1170                 }
1171
1172                 case TRAP_FIRE:
1173                 {
1174                         msg_print(_("炎に包まれた!", "You are enveloped in flames!"));
1175                         dam = damroll(4, 6);
1176                         (void)fire_dam(dam, _("炎のトラップ", "a fire trap"), -1, FALSE);
1177                         break;
1178                 }
1179
1180                 case TRAP_ACID:
1181                 {
1182                         msg_print(_("酸が吹きかけられた!", "You are splashed with acid!"));
1183                         dam = damroll(4, 6);
1184                         (void)acid_dam(dam, _("酸のトラップ", "an acid trap"), -1, FALSE);
1185                         break;
1186                 }
1187
1188                 case TRAP_SLOW:
1189                 {
1190                         hit_trap_slow();
1191                         break;
1192                 }
1193
1194                 case TRAP_LOSE_STR:
1195                 {
1196                         hit_trap_lose_stat(A_STR);
1197                         break;
1198                 }
1199
1200                 case TRAP_LOSE_DEX:
1201                 {
1202                         hit_trap_lose_stat(A_DEX);
1203                         break;
1204                 }
1205
1206                 case TRAP_LOSE_CON:
1207                 {
1208                         hit_trap_lose_stat(A_CON);
1209                         break;
1210                 }
1211
1212                 case TRAP_BLIND:
1213                 {
1214                         hit_trap_set_abnormal_status(
1215                                 _("黒いガスに包み込まれた!", "A black gas surrounds you!"),
1216                                 p_ptr->resist_blind,
1217                                 set_blind, p_ptr->blind + (TIME_EFFECT)randint0(50) + 25);
1218                         break;
1219                 }
1220
1221                 case TRAP_CONFUSE:
1222                 {
1223                         hit_trap_set_abnormal_status(
1224                                 _("きらめくガスに包み込まれた!", "A gas of scintillating colors surrounds you!"),
1225                                 p_ptr->resist_conf,
1226                                 set_confused, p_ptr->confused + (TIME_EFFECT)randint0(20) + 10);
1227                         break;
1228                 }
1229
1230                 case TRAP_POISON:
1231                 {
1232                         hit_trap_set_abnormal_status(
1233                                 _("刺激的な緑色のガスに包み込まれた!", "A pungent green gas surrounds you!"),
1234                                 p_ptr->resist_pois || IS_OPPOSE_POIS(),
1235                                 set_poisoned, p_ptr->poisoned + (TIME_EFFECT)randint0(20) + 10);
1236                         break;
1237                 }
1238
1239                 case TRAP_SLEEP:
1240                 {
1241                         msg_print(_("奇妙な白い霧に包まれた!", "A strange white mist surrounds you!"));
1242                         if (!p_ptr->free_act)
1243                         {
1244                                 msg_print(_("あなたは眠りに就いた。", "You fall asleep."));
1245
1246                                 if (ironman_nightmare)
1247                                 {
1248                                         msg_print(_("身の毛もよだつ光景が頭に浮かんだ。", "A horrible vision enters your mind."));
1249
1250                                         /* Have some nightmares */
1251                                         sanity_blast(NULL, FALSE);
1252
1253                                 }
1254                                 (void)set_paralyzed(p_ptr->paralyzed + randint0(10) + 5);
1255                         }
1256                         break;
1257                 }
1258
1259                 case TRAP_TRAPS:
1260                 {
1261                         msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
1262                         /* Make some new traps */
1263                         project(0, 1, y, x, 0, GF_MAKE_TRAP, PROJECT_HIDE | PROJECT_JUMP | PROJECT_GRID, -1);
1264
1265                         break;
1266                 }
1267
1268                 case TRAP_ALARM:
1269                 {
1270                         msg_print(_("けたたましい音が鳴り響いた!", "An alarm sounds!"));
1271
1272                         aggravate_monsters(0);
1273
1274                         break;
1275                 }
1276
1277                 case TRAP_OPEN:
1278                 {
1279                         msg_print(_("大音響と共にまわりの壁が崩れた!", "Suddenly, surrounding walls are opened!"));
1280                         (void)project(0, 3, y, x, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
1281                         (void)project(0, 3, y, x - 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
1282                         (void)project(0, 3, y, x + 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
1283                         aggravate_monsters(0);
1284
1285                         break;
1286                 }
1287
1288                 case TRAP_ARMAGEDDON:
1289                 {
1290                         static int levs[10] = {0, 0, 20, 10, 5, 3, 2, 1, 1, 1};
1291                         int evil_idx = 0, good_idx = 0;
1292
1293                         int lev;
1294                         msg_print(_("突然天界の戦争に巻き込まれた!", "Suddenly, you are surrounded by immotal beings!"));
1295
1296                         /* Summon Demons and Angels */
1297                         for (lev = dun_level; lev >= 20; lev -= 1 + lev/16)
1298                         {
1299                                 num = levs[MIN(lev/10, 9)];
1300                                 for (i = 0; i < num; i++)
1301                                 {
1302                                         int x1 = rand_spread(x, 7);
1303                                         int y1 = rand_spread(y, 5);
1304
1305                                         /* Skip illegal grids */
1306                                         if (!in_bounds(y1, x1)) continue;
1307
1308                                         /* Require line of projection */
1309                                         if (!projectable(p_ptr->y, p_ptr->x, y1, x1)) continue;
1310
1311                                         if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET)))
1312                                                 evil_idx = hack_m_idx_ii;
1313
1314                                         if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET)))
1315                                         {
1316                                                 good_idx = hack_m_idx_ii;
1317                                         }
1318
1319                                         /* Let them fight each other */
1320                                         if (evil_idx && good_idx)
1321                                         {
1322                                                 monster_type *evil_ptr = &m_list[evil_idx];
1323                                                 monster_type *good_ptr = &m_list[good_idx];
1324                                                 evil_ptr->target_y = good_ptr->fy;
1325                                                 evil_ptr->target_x = good_ptr->fx;
1326                                                 good_ptr->target_y = evil_ptr->fy;
1327                                                 good_ptr->target_x = evil_ptr->fx;
1328                                         }
1329                                 }
1330                         }
1331                         break;
1332                 }
1333
1334                 case TRAP_PIRANHA:
1335                 {
1336                         msg_print(_("突然壁から水が溢れ出した!ピラニアがいる!", "Suddenly, the room is filled with water with piranhas!"));
1337
1338                         /* Water fills room */
1339                         fire_ball_hide(GF_WATER_FLOW, 0, 1, 10);
1340
1341                         /* Summon Piranhas */
1342                         num = 1 + dun_level/20;
1343                         for (i = 0; i < num; i++)
1344                         {
1345                                 (void)summon_specific(0, y, x, dun_level, SUMMON_PIRANHAS, (PM_ALLOW_GROUP | PM_NO_PET));
1346                         }
1347                         break;
1348                 }
1349         }
1350
1351         if (break_trap && is_trap(c_ptr->feat))
1352         {
1353                 cave_alter_feat(y, x, FF_DISARM);
1354                 msg_print(_("トラップを粉砕した。", "You destroyed the trap."));
1355         }
1356 }
1357
1358
1359 /*!
1360  * @brief 敵オーラによるプレイヤーのダメージ処理(補助)
1361  * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
1362  * @param immune ダメージを回避できる免疫フラグ
1363  * @param flags_offset オーラフラグ配列の参照オフセット
1364  * @param r_flags_offset モンスターの耐性配列の参照オフセット
1365  * @param aura_flag オーラフラグ配列
1366  * @param dam_func ダメージ処理を行う関数の参照ポインタ
1367  * @param message オーラダメージを受けた際のメッセージ
1368  * @return なし
1369  */
1370 static void touch_zap_player_aux(monster_type *m_ptr, bool immune, int flags_offset, int r_flags_offset, u32b aura_flag,
1371                                  int (*dam_func)(HIT_POINT dam, cptr kb_str, int monspell, bool aura), cptr message)
1372 {
1373         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1374
1375         if ((atoffset(u32b, r_ptr, flags_offset) & aura_flag) && !immune)
1376         {
1377                 char mon_name[80];
1378                 int aura_damage = damroll(1 + (r_ptr->level / 26), 1 + (r_ptr->level / 17));
1379
1380                 /* Hack -- Get the "died from" name */
1381                 monster_desc(mon_name, m_ptr, MD_IGNORE_HALLU | MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
1382
1383                 msg_print(message);
1384
1385                 dam_func(aura_damage, mon_name, -1, TRUE);
1386
1387                 if (is_original_ap_and_seen(m_ptr))
1388                 {
1389                         atoffset(u32b, r_ptr, r_flags_offset) |= aura_flag;
1390                 }
1391
1392                 handle_stuff();
1393         }
1394 }
1395
1396 /*!
1397  * @brief 敵オーラによるプレイヤーのダメージ処理(メイン)
1398  * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
1399  * @return なし
1400  */
1401 static void touch_zap_player(monster_type *m_ptr)
1402 {
1403         touch_zap_player_aux(m_ptr, p_ptr->immune_fire, offsetof(monster_race, flags2), offsetof(monster_race, r_flags2), RF2_AURA_FIRE,
1404                              fire_dam, _("突然とても熱くなった!", "You are suddenly very hot!"));
1405         touch_zap_player_aux(m_ptr, p_ptr->immune_cold, offsetof(monster_race, flags3), offsetof(monster_race, r_flags3), RF3_AURA_COLD,
1406                              cold_dam, _("突然とても寒くなった!", "You are suddenly very cold!"));
1407         touch_zap_player_aux(m_ptr, p_ptr->immune_elec, offsetof(monster_race, flags2), offsetof(monster_race, r_flags2), RF2_AURA_ELEC,
1408                              elec_dam, _("電撃をくらった!", "You get zapped!"));
1409 }
1410
1411
1412 /*!
1413  * @brief プレイヤーの変異要素による打撃処理
1414  * @param m_idx 攻撃目標となったモンスターの参照ID
1415  * @param attack 変異要素による攻撃要素の種類
1416  * @param fear 攻撃を受けたモンスターが恐慌状態に陥ったかを返す参照ポインタ
1417  * @param mdeath 攻撃を受けたモンスターが死亡したかを返す参照ポインタ
1418  * @return なし
1419  */
1420 static void natural_attack(s16b m_idx, int attack, bool *fear, bool *mdeath)
1421 {
1422         HIT_POINT k;
1423         int bonus, chance;
1424         int             n_weight = 0;
1425         monster_type    *m_ptr = &m_list[m_idx];
1426         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1427         char            m_name[80];
1428
1429         int             dice_num, dice_side;
1430
1431         cptr            atk_desc;
1432
1433         switch (attack)
1434         {
1435                 case MUT2_SCOR_TAIL:
1436                         dice_num = 3;
1437                         dice_side = 7;
1438                         n_weight = 5;
1439                         atk_desc = _("尻尾", "tail");
1440
1441                         break;
1442                 case MUT2_HORNS:
1443                         dice_num = 2;
1444                         dice_side = 6;
1445                         n_weight = 15;
1446                         atk_desc = _("角", "horns");
1447
1448                         break;
1449                 case MUT2_BEAK:
1450                         dice_num = 2;
1451                         dice_side = 4;
1452                         n_weight = 5;
1453                         atk_desc = _("クチバシ", "beak");
1454
1455                         break;
1456                 case MUT2_TRUNK:
1457                         dice_num = 1;
1458                         dice_side = 4;
1459                         n_weight = 35;
1460                         atk_desc = _("象の鼻", "trunk");
1461
1462                         break;
1463                 case MUT2_TENTACLES:
1464                         dice_num = 2;
1465                         dice_side = 5;
1466                         n_weight = 5;
1467                         atk_desc = _("触手", "tentacles");
1468
1469                         break;
1470                 default:
1471                         dice_num = dice_side = n_weight = 1;
1472                         atk_desc = _("未定義の部位", "undefined body part");
1473
1474         }
1475
1476         /* Extract monster name (or "it") */
1477         monster_desc(m_name, m_ptr, 0);
1478
1479
1480         /* Calculate the "attack quality" */
1481         bonus = p_ptr->to_h_m;
1482         bonus += (p_ptr->lev * 6 / 5);
1483         chance = (p_ptr->skill_thn + (bonus * BTH_PLUS_ADJ));
1484
1485         /* Test for hit */
1486         if ((!(r_ptr->flags2 & RF2_QUANTUM) || !randint0(2)) && test_hit_norm(chance, r_ptr->ac, m_ptr->ml))
1487         {
1488                 /* Sound */
1489                 sound(SOUND_HIT);
1490                 msg_format(_("%sを%sで攻撃した。", "You hit %s with your %s."), m_name, atk_desc);
1491
1492                 k = damroll(dice_num, dice_side);
1493                 k = critical_norm(n_weight, bonus, k, (s16b)bonus, 0);
1494
1495                 /* Apply the player damage bonuses */
1496                 k += p_ptr->to_d_m;
1497
1498                 /* No negative damage */
1499                 if (k < 0) k = 0;
1500
1501                 /* Modify the damage */
1502                 k = mon_damage_mod(m_ptr, k, FALSE);
1503
1504                 /* Complex message */
1505                 msg_format_wizard(CHEAT_MONSTER,
1506                         _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
1507                         k, m_ptr->hp - k, m_ptr->maxhp, m_ptr->max_maxhp);
1508
1509                 /* Anger the monster */
1510                 if (k > 0) anger_monster(m_ptr);
1511
1512                 /* Damage, check for fear and mdeath */
1513                 switch (attack)
1514                 {
1515                         case MUT2_SCOR_TAIL:
1516                                 project(0, 0, m_ptr->fy, m_ptr->fx, k, GF_POIS, PROJECT_KILL, -1);
1517                                 *mdeath = (m_ptr->r_idx == 0);
1518                                 break;
1519                         case MUT2_HORNS:
1520                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1521                                 break;
1522                         case MUT2_BEAK:
1523                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1524                                 break;
1525                         case MUT2_TRUNK:
1526                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1527                                 break;
1528                         case MUT2_TENTACLES:
1529                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1530                                 break;
1531                         default:
1532                                 *mdeath = mon_take_hit(m_idx, k, fear, NULL);
1533                 }
1534
1535                 touch_zap_player(m_ptr);
1536         }
1537         /* Player misses */
1538         else
1539         {
1540                 /* Sound */
1541                 sound(SOUND_MISS);
1542
1543                 /* Message */
1544                 msg_format(_("ミス! %sにかわされた。", "You miss %s."), m_name);
1545         }
1546 }
1547
1548
1549 /*!
1550  * @brief プレイヤーの打撃処理サブルーチン /
1551  * Player attacks a (poor, defenseless) creature        -RAK-
1552  * @param y 攻撃目標のY座標
1553  * @param x 攻撃目標のX座標
1554  * @param fear 攻撃を受けたモンスターが恐慌状態に陥ったかを返す参照ポインタ
1555  * @param mdeath 攻撃を受けたモンスターが死亡したかを返す参照ポインタ
1556  * @param hand 攻撃を行うための武器を持つ手
1557  * @param mode 発動中の剣術ID
1558  * @return なし
1559  * @details
1560  * If no "weapon" is available, then "punch" the monster one time.
1561  */
1562 static void py_attack_aux(int y, int x, bool *fear, bool *mdeath, s16b hand, BIT_FLAGS mode)
1563 {
1564         int             num = 0, bonus, chance, vir;
1565         HIT_POINT k;
1566
1567         cave_type       *c_ptr = &cave[y][x];
1568
1569         monster_type    *m_ptr = &m_list[c_ptr->m_idx];
1570         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1571
1572         /* Access the weapon */
1573         object_type     *o_ptr = &inventory[INVEN_RARM + hand];
1574
1575         char            m_name[80];
1576
1577         bool            success_hit = FALSE;
1578         bool            backstab = FALSE;
1579         bool            vorpal_cut = FALSE;
1580         int             chaos_effect = 0;
1581         bool            stab_fleeing = FALSE;
1582         bool            fuiuchi = FALSE;
1583         bool            monk_attack = FALSE;
1584         bool            do_quake = FALSE;
1585         bool            weak = FALSE;
1586         bool            drain_msg = TRUE;
1587         int             drain_result = 0, drain_heal = 0;
1588         bool            can_drain = FALSE;
1589         int             num_blow;
1590         int             drain_left = MAX_VAMPIRIC_DRAIN;
1591         u32b flgs[TR_FLAG_SIZE]; /* A massive hack -- life-draining weapons */
1592         bool            is_human = (r_ptr->d_char == 'p');
1593         bool            is_lowlevel = (r_ptr->level < (p_ptr->lev - 15));
1594         bool            zantetsu_mukou, e_j_mukou;
1595
1596         switch (p_ptr->pclass)
1597         {
1598         case CLASS_ROGUE:
1599         case CLASS_NINJA:
1600                 if (buki_motteruka(INVEN_RARM + hand) && !p_ptr->icky_wield[hand])
1601                 {
1602                         int tmp = p_ptr->lev * 6 + (p_ptr->skill_stl + 10) * 4;
1603                         if (p_ptr->monlite && (mode != HISSATSU_NYUSIN)) tmp /= 3;
1604                         if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1605                         if (r_ptr->level > (p_ptr->lev * p_ptr->lev / 20 + 10)) tmp /= 3;
1606                         if (MON_CSLEEP(m_ptr) && m_ptr->ml)
1607                         {
1608                                 /* Can't backstab creatures that we can't see, right? */
1609                                 backstab = TRUE;
1610                         }
1611                         else if ((p_ptr->special_defense & NINJA_S_STEALTH) && (randint0(tmp) > (r_ptr->level+20)) && m_ptr->ml && !(r_ptr->flagsr & RFR_RES_ALL))
1612                         {
1613                                 fuiuchi = TRUE;
1614                         }
1615                         else if (MON_MONFEAR(m_ptr) && m_ptr->ml)
1616                         {
1617                                 stab_fleeing = TRUE;
1618                         }
1619                 }
1620                 break;
1621
1622         case CLASS_MONK:
1623         case CLASS_FORCETRAINER:
1624         case CLASS_BERSERKER:
1625                 if ((empty_hands(TRUE) & EMPTY_HAND_RARM) && !p_ptr->riding) monk_attack = TRUE;
1626                 break;
1627         }
1628
1629         if (!o_ptr->k_idx) /* Empty hand */
1630         {
1631                 if ((r_ptr->level + 10) > p_ptr->lev)
1632                 {
1633                         if (p_ptr->skill_exp[GINOU_SUDE] < s_info[p_ptr->pclass].s_max[GINOU_SUDE])
1634                         {
1635                                 if (p_ptr->skill_exp[GINOU_SUDE] < WEAPON_EXP_BEGINNER)
1636                                         p_ptr->skill_exp[GINOU_SUDE] += 40;
1637                                 else if ((p_ptr->skill_exp[GINOU_SUDE] < WEAPON_EXP_SKILLED))
1638                                         p_ptr->skill_exp[GINOU_SUDE] += 5;
1639                                 else if ((p_ptr->skill_exp[GINOU_SUDE] < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19))
1640                                         p_ptr->skill_exp[GINOU_SUDE] += 1;
1641                                 else if ((p_ptr->lev > 34))
1642                                         if (one_in_(3)) p_ptr->skill_exp[GINOU_SUDE] += 1;
1643                                 p_ptr->update |= (PU_BONUS);
1644                         }
1645                 }
1646         }
1647         else if (object_is_melee_weapon(o_ptr))
1648         {
1649                 if ((r_ptr->level + 10) > p_ptr->lev)
1650                 {
1651                         OBJECT_TYPE_VALUE tval = inventory[INVEN_RARM+hand].tval - TV_WEAPON_BEGIN;
1652                         OBJECT_SUBTYPE_VALUE sval = inventory[INVEN_RARM+hand].sval;
1653                         int now_exp = p_ptr->weapon_exp[tval][sval];
1654                         if (now_exp < s_info[p_ptr->pclass].w_max[tval][sval])
1655                         {
1656                                 SUB_EXP amount = 0;
1657                                 if (now_exp < WEAPON_EXP_BEGINNER) amount = 80;
1658                                 else if (now_exp < WEAPON_EXP_SKILLED) amount = 10;
1659                                 else if ((now_exp < WEAPON_EXP_EXPERT) && (p_ptr->lev > 19)) amount = 1;
1660                                 else if ((p_ptr->lev > 34) && one_in_(2)) amount = 1;
1661                                 p_ptr->weapon_exp[tval][sval] += amount;
1662                                 p_ptr->update |= (PU_BONUS);
1663                         }
1664                 }
1665         }
1666
1667         /* Disturb the monster */
1668         (void)set_monster_csleep(c_ptr->m_idx, 0);
1669
1670         /* Extract monster name (or "it") */
1671         monster_desc(m_name, m_ptr, 0);
1672
1673         /* Calculate the "attack quality" */
1674         bonus = p_ptr->to_h[hand] + o_ptr->to_h;
1675         chance = (p_ptr->skill_thn + (bonus * BTH_PLUS_ADJ));
1676         if (mode == HISSATSU_IAI) chance += 60;
1677         if (p_ptr->special_defense & KATA_KOUKIJIN) chance += 150;
1678
1679         if (p_ptr->sutemi) chance = MAX(chance * 3 / 2, chance + 60);
1680
1681         vir = virtue_number(V_VALOUR);
1682         if (vir)
1683         {
1684                 chance += (p_ptr->virtues[vir - 1]/10);
1685         }
1686
1687         zantetsu_mukou = ((o_ptr->name1 == ART_ZANTETSU) && (r_ptr->d_char == 'j'));
1688         e_j_mukou = ((o_ptr->name1 == ART_EXCALIBUR_J) && (r_ptr->d_char == 'S'));
1689
1690         if ((mode == HISSATSU_KYUSHO) || (mode == HISSATSU_MINEUCHI) || (mode == HISSATSU_3DAN) || (mode == HISSATSU_IAI)) num_blow = 1;
1691         else if (mode == HISSATSU_COLD) num_blow = p_ptr->num_blow[hand]+2;
1692         else num_blow = p_ptr->num_blow[hand];
1693
1694         /* Hack -- DOKUBARI always hit once */
1695         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) num_blow = 1;
1696
1697         /* Attack once for each legal blow */
1698         while ((num++ < num_blow) && !p_ptr->is_dead)
1699         {
1700                 if (((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) || (mode == HISSATSU_KYUSHO))
1701                 {
1702                         int n = 1;
1703
1704                         if (p_ptr->migite && p_ptr->hidarite)
1705                         {
1706                                 n *= 2;
1707                         }
1708                         if (mode == HISSATSU_3DAN)
1709                         {
1710                                 n *= 2;
1711                         }
1712
1713                         success_hit = one_in_(n);
1714                 }
1715                 else if ((p_ptr->pclass == CLASS_NINJA) && ((backstab || fuiuchi) && !(r_ptr->flagsr & RFR_RES_ALL))) success_hit = TRUE;
1716                 else success_hit = test_hit_norm(chance, r_ptr->ac, m_ptr->ml);
1717
1718                 if (mode == HISSATSU_MAJIN)
1719                 {
1720                         if (one_in_(2))
1721                                 success_hit = FALSE;
1722                 }
1723
1724                 /* Test for hit */
1725                 if (success_hit)
1726                 {
1727                         int vorpal_chance = ((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD)) ? 2 : 4;
1728
1729                         /* Sound */
1730                         sound(SOUND_HIT);
1731
1732                         /* Message */
1733 #ifdef JP
1734                         if (backstab) msg_format("あなたは冷酷にも眠っている無力な%sを突き刺した!", m_name);
1735                         else if (fuiuchi) msg_format("不意を突いて%sに強烈な一撃を喰らわせた!", m_name);
1736                         else if (stab_fleeing) msg_format("逃げる%sを背中から突き刺した!", m_name);
1737                         else if (!monk_attack) msg_format("%sを攻撃した。", m_name);
1738 #else
1739                         if (backstab) msg_format("You cruelly stab the helpless, sleeping %s!", m_name);
1740                         else if (fuiuchi) msg_format("You make surprise attack, and hit %s with a powerful blow!", m_name);
1741                         else if (stab_fleeing) msg_format("You backstab the fleeing %s!",  m_name);
1742                         else if (!monk_attack) msg_format("You hit %s.", m_name);
1743 #endif
1744
1745                         /* Hack -- bare hands do one damage */
1746                         k = 1;
1747
1748                         object_flags(o_ptr, flgs);
1749
1750                         /* Select a chaotic effect (50% chance) */
1751                         if ((have_flag(flgs, TR_CHAOTIC)) && one_in_(2))
1752                         {
1753                                 if (one_in_(10))
1754                                 chg_virtue(V_CHANCE, 1);
1755
1756                                 if (randint1(5) < 3)
1757                                 {
1758                                         /* Vampiric (20%) */
1759                                         chaos_effect = 1;
1760                                 }
1761                                 else if (one_in_(250))
1762                                 {
1763                                         /* Quake (0.12%) */
1764                                         chaos_effect = 2;
1765                                 }
1766                                 else if (!one_in_(10))
1767                                 {
1768                                         /* Confusion (26.892%) */
1769                                         chaos_effect = 3;
1770                                 }
1771                                 else if (one_in_(2))
1772                                 {
1773                                         /* Teleport away (1.494%) */
1774                                         chaos_effect = 4;
1775                                 }
1776                                 else
1777                                 {
1778                                         /* Polymorph (1.494%) */
1779                                         chaos_effect = 5;
1780                                 }
1781                         }
1782
1783                         /* Vampiric drain */
1784                         if ((have_flag(flgs, TR_VAMPIRIC)) || (chaos_effect == 1) || (mode == HISSATSU_DRAIN) || hex_spelling(HEX_VAMP_BLADE))
1785                         {
1786                                 /* Only drain "living" monsters */
1787                                 if (monster_living(r_ptr))
1788                                         can_drain = TRUE;
1789                                 else
1790                                         can_drain = FALSE;
1791                         }
1792
1793                         if ((have_flag(flgs, TR_VORPAL) || hex_spelling(HEX_RUNESWORD)) && (randint1(vorpal_chance*3/2) == 1) && !zantetsu_mukou)
1794                                 vorpal_cut = TRUE;
1795                         else vorpal_cut = FALSE;
1796
1797                         if (monk_attack)
1798                         {
1799                                 int special_effect = 0, stun_effect = 0, times = 0, max_times;
1800                                 int min_level = 1;
1801                                 const martial_arts *ma_ptr = &ma_blows[0], *old_ptr = &ma_blows[0];
1802                                 int resist_stun = 0;
1803                                 int weight = 8;
1804
1805                                 if (r_ptr->flags1 & RF1_UNIQUE) resist_stun += 88;
1806                                 if (r_ptr->flags3 & RF3_NO_STUN) resist_stun += 66;
1807                                 if (r_ptr->flags3 & RF3_NO_CONF) resist_stun += 33;
1808                                 if (r_ptr->flags3 & RF3_NO_SLEEP) resist_stun += 33;
1809                                 if ((r_ptr->flags3 & RF3_UNDEAD) || (r_ptr->flags3 & RF3_NONLIVING))
1810                                         resist_stun += 66;
1811
1812                                 if (p_ptr->special_defense & KAMAE_BYAKKO)
1813                                         max_times = (p_ptr->lev < 3 ? 1 : p_ptr->lev / 3);
1814                                 else if (p_ptr->special_defense & KAMAE_SUZAKU)
1815                                         max_times = 1;
1816                                 else if (p_ptr->special_defense & KAMAE_GENBU)
1817                                         max_times = 1;
1818                                 else
1819                                         max_times = (p_ptr->lev < 7 ? 1 : p_ptr->lev / 7);
1820                                 /* Attempt 'times' */
1821                                 for (times = 0; times < max_times; times++)
1822                                 {
1823                                         do
1824                                         {
1825                                                 ma_ptr = &ma_blows[randint0(MAX_MA)];
1826                                                 if ((p_ptr->pclass == CLASS_FORCETRAINER) && (ma_ptr->min_level > 1)) min_level = ma_ptr->min_level + 3;
1827                                                 else min_level = ma_ptr->min_level;
1828                                         }
1829                                         while ((min_level > p_ptr->lev) ||
1830                                                (randint1(p_ptr->lev) < ma_ptr->chance));
1831
1832                                         /* keep the highest level attack available we found */
1833                                         if ((ma_ptr->min_level > old_ptr->min_level) &&
1834                                             !p_ptr->stun && !p_ptr->confused)
1835                                         {
1836                                                 old_ptr = ma_ptr;
1837
1838                                                 if (p_ptr->wizard && cheat_xtra)
1839                                                 {
1840                                                         msg_print(_("攻撃を再選択しました。", "Attack re-selected."));
1841                                                 }
1842                                         }
1843                                         else
1844                                         {
1845                                                 ma_ptr = old_ptr;
1846                                         }
1847                                 }
1848
1849                                 if (p_ptr->pclass == CLASS_FORCETRAINER) min_level = MAX(1, ma_ptr->min_level - 3);
1850                                 else min_level = ma_ptr->min_level;
1851                                 k = damroll(ma_ptr->dd + p_ptr->to_dd[hand], ma_ptr->ds + p_ptr->to_ds[hand]);
1852                                 if (p_ptr->special_attack & ATTACK_SUIKEN) k *= 2;
1853
1854                                 if (ma_ptr->effect == MA_KNEE)
1855                                 {
1856                                         if (r_ptr->flags1 & RF1_MALE)
1857                                         {
1858                                                 msg_format(_("%sに金的膝蹴りをくらわした!", "You hit %s in the groin with your knee!"), m_name);
1859                                                 sound(SOUND_PAIN);
1860                                                 special_effect = MA_KNEE;
1861                                         }
1862                                         else
1863                                                 msg_format(ma_ptr->desc, m_name);
1864                                 }
1865
1866                                 else if (ma_ptr->effect == MA_SLOW)
1867                                 {
1868                                         if (!((r_ptr->flags1 & RF1_NEVER_MOVE) ||
1869                                             my_strchr("~#{}.UjmeEv$,DdsbBFIJQSXclnw!=?", r_ptr->d_char)))
1870                                         {
1871                                                 msg_format(_("%sの足首に関節蹴りをくらわした!", "You kick %s in the ankle."), m_name);
1872                                                 special_effect = MA_SLOW;
1873                                         }
1874                                         else msg_format(ma_ptr->desc, m_name);
1875                                 }
1876                                 else
1877                                 {
1878                                         if (ma_ptr->effect)
1879                                         {
1880                                                 stun_effect = (ma_ptr->effect / 2) + randint1(ma_ptr->effect / 2);
1881                                         }
1882
1883                                         msg_format(ma_ptr->desc, m_name);
1884                                 }
1885
1886                                 if (p_ptr->special_defense & KAMAE_SUZAKU) weight = 4;
1887                                 if ((p_ptr->pclass == CLASS_FORCETRAINER) && P_PTR_KI)
1888                                 {
1889                                         weight += (P_PTR_KI / 30);
1890                                         if (weight > 20) weight = 20;
1891                                 }
1892
1893                                 k = critical_norm(p_ptr->lev * weight, min_level, k, p_ptr->to_h[0], 0);
1894
1895                                 if ((special_effect == MA_KNEE) && ((k + p_ptr->to_d[hand]) < m_ptr->hp))
1896                                 {
1897                                         msg_format(_("%^sは苦痛にうめいている!", "%^s moans in agony!"), m_name);
1898                                         stun_effect = 7 + randint1(13);
1899                                         resist_stun /= 3;
1900                                 }
1901
1902                                 else if ((special_effect == MA_SLOW) && ((k + p_ptr->to_d[hand]) < m_ptr->hp))
1903                                 {
1904                                         if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1905                                             (randint1(p_ptr->lev) > r_ptr->level) &&
1906                                             m_ptr->mspeed > 60)
1907                                         {
1908                                                 msg_format(_("%^sは足をひきずり始めた。", "%^s starts limping slower."), m_name);
1909                                                 m_ptr->mspeed -= 10;
1910                                         }
1911                                 }
1912
1913                                 if (stun_effect && ((k + p_ptr->to_d[hand]) < m_ptr->hp))
1914                                 {
1915                                         if (p_ptr->lev > randint1(r_ptr->level + resist_stun + 10))
1916                                         {
1917                                                 if (set_monster_stunned(c_ptr->m_idx, stun_effect + MON_STUNNED(m_ptr)))
1918                                                 {
1919                                                         msg_format(_("%^sはフラフラになった。", "%^s is stunned."), m_name);
1920                                                 }
1921                                                 else
1922                                                 {
1923                                                         msg_format(_("%^sはさらにフラフラになった。", "%^s is more stunned."), m_name);
1924                                                 }
1925                                         }
1926                                 }
1927                         }
1928
1929                         /* Handle normal weapon */
1930                         else if (o_ptr->k_idx)
1931                         {
1932                                 k = damroll(o_ptr->dd + p_ptr->to_dd[hand], o_ptr->ds + p_ptr->to_ds[hand]);
1933                                 k = tot_dam_aux(o_ptr, k, m_ptr, mode, FALSE);
1934
1935                                 if (backstab)
1936                                 {
1937                                         k *= (3 + (p_ptr->lev / 20));
1938                                 }
1939                                 else if (fuiuchi)
1940                                 {
1941                                         k = k*(5+(p_ptr->lev*2/25))/2;
1942                                 }
1943                                 else if (stab_fleeing)
1944                                 {
1945                                         k = (3 * k) / 2;
1946                                 }
1947
1948                                 if ((p_ptr->impact[hand] && ((k > 50) || one_in_(7))) ||
1949                                          (chaos_effect == 2) || (mode == HISSATSU_QUAKE))
1950                                 {
1951                                         do_quake = TRUE;
1952                                 }
1953
1954                                 if ((!(o_ptr->tval == TV_SWORD) || !(o_ptr->sval == SV_DOKUBARI)) && !(mode == HISSATSU_KYUSHO))
1955                                         k = critical_norm(o_ptr->weight, o_ptr->to_h, k, p_ptr->to_h[hand], mode);
1956
1957                                 drain_result = k;
1958
1959                                 if (vorpal_cut)
1960                                 {
1961                                         int mult = 2;
1962
1963                                         if ((o_ptr->name1 == ART_CHAINSWORD) && !one_in_(2))
1964                                         {
1965                                                 char chainsword_noise[1024];
1966                                                 if (!get_rnd_line(_("chainswd_j.txt", "chainswd.txt"), 0, chainsword_noise))
1967                                                 {
1968                                                         msg_print(chainsword_noise);
1969                                                 }
1970                                         }
1971
1972                                         if (o_ptr->name1 == ART_VORPAL_BLADE)
1973                                         {
1974                                                 msg_print(_("目にも止まらぬヴォーパルブレード、手錬の早業!", "Your Vorpal Blade goes snicker-snack!"));
1975                                         }
1976                                         else
1977                                         {
1978                                                 msg_format(_("%sをグッサリ切り裂いた!", "Your weapon cuts deep into %s!"), m_name);
1979                                         }
1980
1981                                         /* Try to increase the damage */
1982                                         while (one_in_(vorpal_chance))
1983                                         {
1984                                                 mult++;
1985                                         }
1986
1987                                         k *= (HIT_POINT)mult;
1988
1989                                         /* Ouch! */
1990                                         if (((r_ptr->flagsr & RFR_RES_ALL) ? k/100 : k) > m_ptr->hp)
1991                                         {
1992                                                 msg_format(_("%sを真っ二つにした!", "You cut %s in half!"), m_name);
1993                                         }
1994                                         else
1995                                         {
1996                                                 switch (mult)
1997                                                 {
1998                                                 case 2: msg_format(_("%sを斬った!", "You gouge %s!"), m_name); break;
1999                                                 case 3: msg_format(_("%sをぶった斬った!", "You maim %s!"), m_name); break;
2000                                                 case 4: msg_format(_("%sをメッタ斬りにした!", "You carve %s!"), m_name); break;
2001                                                 case 5: msg_format(_("%sをメッタメタに斬った!", "You cleave %s!"), m_name); break;
2002                                                 case 6: msg_format(_("%sを刺身にした!", "You smite %s!"), m_name); break;
2003                                                 case 7: msg_format(_("%sを斬って斬って斬りまくった!", "You eviscerate %s!"), m_name); break;
2004                                                 default: msg_format(_("%sを細切れにした!", "You shred %s!"), m_name); break;
2005                                                 }
2006                                         }
2007                                         drain_result = drain_result * 3 / 2;
2008                                 }
2009
2010                                 k += o_ptr->to_d;
2011                                 drain_result += o_ptr->to_d;
2012                         }
2013
2014                         /* Apply the player damage bonuses */
2015                         k += p_ptr->to_d[hand];
2016                         drain_result += p_ptr->to_d[hand];
2017
2018                         if ((mode == HISSATSU_SUTEMI) || (mode == HISSATSU_3DAN)) k *= 2;
2019                         if ((mode == HISSATSU_SEKIRYUKA) && !monster_living(r_ptr)) k = 0;
2020                         if ((mode == HISSATSU_SEKIRYUKA) && !p_ptr->cut) k /= 2;
2021
2022                         /* No negative damage */
2023                         if (k < 0) k = 0;
2024
2025                         if ((mode == HISSATSU_ZANMA) && !(!monster_living(r_ptr) && (r_ptr->flags3 & RF3_EVIL)))
2026                         {
2027                                 k = 0;
2028                         }
2029
2030                         if (zantetsu_mukou)
2031                         {
2032                                 msg_print(_("こんな軟らかいものは切れん!", "You cannot cut such a elastic thing!"));
2033                                 k = 0;
2034                         }
2035
2036                         if (e_j_mukou)
2037                         {
2038                                 msg_print(_("蜘蛛は苦手だ!", "Spiders are difficult for you to deal with!"));
2039                                 k /= 2;
2040                         }
2041
2042                         if (mode == HISSATSU_MINEUCHI)
2043                         {
2044                                 int tmp = (10 + randint1(15) + p_ptr->lev / 5);
2045
2046                                 k = 0;
2047                                 anger_monster(m_ptr);
2048
2049                                 if (!(r_ptr->flags3 & (RF3_NO_STUN)))
2050                                 {
2051                                         /* Get stunned */
2052                                         if (MON_STUNNED(m_ptr))
2053                                         {
2054                                                 msg_format(_("%sはひどくもうろうとした。", "%s is more dazed."), m_name);
2055                                                 tmp /= 2;
2056                                         }
2057                                         else
2058                                         {
2059                                                 msg_format(_("%s はもうろうとした。", "%s is dazed."), m_name);
2060                                         }
2061
2062                                         /* Apply stun */
2063                                         (void)set_monster_stunned(c_ptr->m_idx, MON_STUNNED(m_ptr) + tmp);
2064                                 }
2065                                 else
2066                                 {
2067                                         msg_format(_("%s には効果がなかった。", "%s is not effected."), m_name);
2068                                 }
2069                         }
2070
2071                         /* Modify the damage */
2072                         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))));
2073                         if (((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) || (mode == HISSATSU_KYUSHO))
2074                         {
2075                                 if ((randint1(randint1(r_ptr->level/7)+5) == 1) && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2))
2076                                 {
2077                                         k = m_ptr->hp + 1;
2078                                         msg_format(_("%sの急所を突き刺した!", "You hit %s on a fatal spot!"), m_name);
2079                                 }
2080                                 else k = 1;
2081                         }
2082                         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)))
2083                         {
2084                                 int maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2085                                 if (one_in_(backstab ? 13 : (stab_fleeing || fuiuchi) ? 15 : 27))
2086                                 {
2087                                         k *= 5;
2088                                         drain_result *= 2;
2089                                         msg_format(_("刃が%sに深々と突き刺さった!", "You critically injured %s!"), m_name);
2090                                 }
2091                                 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)))
2092                                 {
2093                                         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE2) || (m_ptr->hp >= maxhp/2))
2094                                         {
2095                                                 k = MAX(k*5, m_ptr->hp/2);
2096                                                 drain_result *= 2;
2097                                                 msg_format(_("%sに致命傷を負わせた!", "You fatally injured %s!"), m_name);
2098                                         }
2099                                         else
2100                                         {
2101                                                 k = m_ptr->hp + 1;
2102                                                 msg_format(_("刃が%sの急所を貫いた!", "You hit %s on a fatal spot!"), m_name);
2103                                         }
2104                                 }
2105                         }
2106
2107                         msg_format_wizard(CHEAT_MONSTER,
2108                                 _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), k,
2109                                 m_ptr->hp - k, m_ptr->maxhp, m_ptr->max_maxhp);
2110
2111                         if (k <= 0) can_drain = FALSE;
2112
2113                         if (drain_result > m_ptr->hp)
2114                                 drain_result = m_ptr->hp;
2115
2116                         /* Damage, check for fear and death */
2117                         if (mon_take_hit(c_ptr->m_idx, k, fear, NULL))
2118                         {
2119                                 *mdeath = TRUE;
2120                                 if ((p_ptr->pclass == CLASS_BERSERKER) && p_ptr->energy_use)
2121                                 {
2122                                         if (p_ptr->migite && p_ptr->hidarite)
2123                                         {
2124                                                 if (hand) p_ptr->energy_use = p_ptr->energy_use*3/5+p_ptr->energy_use*num*2/(p_ptr->num_blow[hand]*5);
2125                                                 else p_ptr->energy_use = p_ptr->energy_use*num*3/(p_ptr->num_blow[hand]*5);
2126                                         }
2127                                         else
2128                                         {
2129                                                 p_ptr->energy_use = p_ptr->energy_use*num/p_ptr->num_blow[hand];
2130                                         }
2131                                 }
2132                                 if ((o_ptr->name1 == ART_ZANTETSU) && is_lowlevel)
2133                                         msg_print(_("またつまらぬものを斬ってしまった...", "Sigh... Another trifling thing I've cut...."));
2134                                 break;
2135                         }
2136
2137                         /* Anger the monster */
2138                         if (k > 0) anger_monster(m_ptr);
2139
2140                         touch_zap_player(m_ptr);
2141
2142                         /* Are we draining it?  A little note: If the monster is
2143                         dead, the drain does not work... */
2144
2145                         if (can_drain && (drain_result > 0))
2146                         {
2147                                 if (o_ptr->name1 == ART_MURAMASA)
2148                                 {
2149                                         if (is_human)
2150                                         {
2151                                                 HIT_PROB to_h = o_ptr->to_h;
2152                                                 HIT_POINT to_d = o_ptr->to_d;
2153                                                 int i, flag;
2154
2155                                                 flag = 1;
2156                                                 for (i = 0; i < to_h + 3; i++) if (one_in_(4)) flag = 0;
2157                                                 if (flag) to_h++;
2158
2159                                                 flag = 1;
2160                                                 for (i = 0; i < to_d + 3; i++) if (one_in_(4)) flag = 0;
2161                                                 if (flag) to_d++;
2162
2163                                                 if (o_ptr->to_h != to_h || o_ptr->to_d != to_d)
2164                                                 {
2165                                                         msg_print(_("妖刀は血を吸って強くなった!", "Muramasa sucked blood, and became more powerful!"));
2166                                                         o_ptr->to_h = to_h;
2167                                                         o_ptr->to_d = to_d;
2168                                                 }
2169                                         }
2170                                 }
2171                                 else
2172                                 {
2173                                         if (drain_result > 5) /* Did we really hurt it? */
2174                                         {
2175                                                 drain_heal = damroll(2, drain_result / 6);
2176
2177                                                 /* Hex */
2178                                                 if (hex_spelling(HEX_VAMP_BLADE)) drain_heal *= 2;
2179
2180                                                 if (cheat_xtra)
2181                                                 {
2182                                                         msg_format(_("Draining left: %d", "Draining left: %d"), drain_left);
2183                                                 }
2184
2185                                                 if (drain_left)
2186                                                 {
2187                                                         if (drain_heal < drain_left)
2188                                                         {
2189                                                                 drain_left -= drain_heal;
2190                                                         }
2191                                                         else
2192                                                         {
2193                                                                 drain_heal = drain_left;
2194                                                                 drain_left = 0;
2195                                                         }
2196
2197                                                         if (drain_msg)
2198                                                         {
2199                                                                 msg_format(_("刃が%sから生命力を吸い取った!", "Your weapon drains life from %s!"), m_name);
2200                                                                 drain_msg = FALSE;
2201                                                         }
2202
2203                                                         drain_heal = (drain_heal * mutant_regenerate_mod) / 100;
2204
2205                                                         hp_player(drain_heal);
2206                                                         /* We get to keep some of it! */
2207                                                 }
2208                                         }
2209                                 }
2210                                 m_ptr->maxhp -= (k+7)/8;
2211                                 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
2212                                 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2213                                 weak = TRUE;
2214                         }
2215                         can_drain = FALSE;
2216                         drain_result = 0;
2217
2218                         /* Confusion attack */
2219                         if ((p_ptr->special_attack & ATTACK_CONFUSE) || (chaos_effect == 3) || (mode == HISSATSU_CONF) || hex_spelling(HEX_CONFUSION))
2220                         {
2221                                 /* Cancel glowing hands */
2222                                 if (p_ptr->special_attack & ATTACK_CONFUSE)
2223                                 {
2224                                         p_ptr->special_attack &= ~(ATTACK_CONFUSE);
2225                                         msg_print(_("手の輝きがなくなった。", "Your hands stop glowing."));
2226                                         p_ptr->redraw |= (PR_STATUS);
2227
2228                                 }
2229
2230                                 /* Confuse the monster */
2231                                 if (r_ptr->flags3 & RF3_NO_CONF)
2232                                 {
2233                                         if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags3 |= RF3_NO_CONF;
2234                                         msg_format(_("%^sには効果がなかった。", "%^s is unaffected."), m_name);
2235
2236                                 }
2237                                 else if (randint0(100) < r_ptr->level)
2238                                 {
2239                                         msg_format(_("%^sには効果がなかった。", "%^s is unaffected."), m_name);
2240                                 }
2241                                 else
2242                                 {
2243                                         msg_format(_("%^sは混乱したようだ。", "%^s appears confused."), m_name);
2244                                         (void)set_monster_confused(c_ptr->m_idx, MON_CONFUSED(m_ptr) + 10 + randint0(p_ptr->lev) / 5);
2245                                 }
2246                         }
2247
2248                         else if (chaos_effect == 4)
2249                         {
2250                                 bool resists_tele = FALSE;
2251
2252                                 if (r_ptr->flagsr & RFR_RES_TELE)
2253                                 {
2254                                         if (r_ptr->flags1 & RF1_UNIQUE)
2255                                         {
2256                                                 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= RFR_RES_TELE;
2257                                                 msg_format(_("%^sには効果がなかった。", "%^s is unaffected!"), m_name);
2258                                                 resists_tele = TRUE;
2259                                         }
2260                                         else if (r_ptr->level > randint1(100))
2261                                         {
2262                                                 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= RFR_RES_TELE;
2263                                                 msg_format(_("%^sは抵抗力を持っている!", "%^s resists!"), m_name);
2264                                                 resists_tele = TRUE;
2265                                         }
2266                                 }
2267
2268                                 if (!resists_tele)
2269                                 {
2270                                         msg_format(_("%^sは消えた!", "%^s disappears!"), m_name);
2271                                         teleport_away(c_ptr->m_idx, 50, TELEPORT_PASSIVE);
2272                                         num = num_blow + 1; /* Can't hit it anymore! */
2273                                         *mdeath = TRUE;
2274                                 }
2275                         }
2276
2277                         else if ((chaos_effect == 5) && (randint1(90) > r_ptr->level))
2278                         {
2279                                 if (!(r_ptr->flags1 & (RF1_UNIQUE | RF1_QUESTOR)) &&
2280                                     !(r_ptr->flagsr & RFR_EFF_RES_CHAO_MASK))
2281                                 {
2282                                         if (polymorph_monster(y, x))
2283                                         {
2284                                                 msg_format(_("%^sは変化した!", "%^s changes!"), m_name);
2285                                                 *fear = FALSE;
2286                                                 weak = FALSE;
2287                                         }
2288                                         else
2289                                         {
2290                                                 msg_format(_("%^sには効果がなかった。", "%^s is unaffected."), m_name);
2291                                         }
2292
2293                                         /* Hack -- Get new monster */
2294                                         m_ptr = &m_list[c_ptr->m_idx];
2295
2296                                         /* Oops, we need a different name... */
2297                                         monster_desc(m_name, m_ptr, 0);
2298
2299                                         /* Hack -- Get new race */
2300                                         r_ptr = &r_info[m_ptr->r_idx];
2301                                 }
2302                         }
2303                         else if (o_ptr->name1 == ART_G_HAMMER)
2304                         {
2305                                 monster_type *target_ptr = &m_list[c_ptr->m_idx];
2306
2307                                 if (target_ptr->hold_o_idx)
2308                                 {
2309                                         object_type *q_ptr = &o_list[target_ptr->hold_o_idx];
2310                                         char o_name[MAX_NLEN];
2311
2312                                         object_desc(o_name, q_ptr, OD_NAME_ONLY);
2313                                         q_ptr->held_m_idx = 0;
2314                                         q_ptr->marked = OM_TOUCHED;
2315                                         target_ptr->hold_o_idx = q_ptr->next_o_idx;
2316                                         q_ptr->next_o_idx = 0;
2317                                         msg_format(_("%sを奪った。", "You snatched %s."), o_name);
2318                                         inven_carry(q_ptr);
2319                                 }
2320                         }
2321                 }
2322
2323                 /* Player misses */
2324                 else
2325                 {
2326                         backstab = FALSE; /* Clumsy! */
2327                         fuiuchi = FALSE; /* Clumsy! */
2328
2329                         if ((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE) && one_in_(3))
2330                         {
2331                                 u32b flgs_aux[TR_FLAG_SIZE];
2332
2333                                 /* Sound */
2334                                 sound(SOUND_HIT);
2335
2336                                 /* Message */
2337                                 msg_format(_("ミス! %sにかわされた。", "You miss %s."), m_name);
2338                                 /* Message */
2339                                 msg_print(_("振り回した大鎌が自分自身に返ってきた!", "Your scythe returns to you!"));
2340
2341                                 /* Extract the flags */
2342                                 object_flags(o_ptr, flgs_aux);
2343
2344                                 k = damroll(o_ptr->dd + p_ptr->to_dd[hand], o_ptr->ds + p_ptr->to_ds[hand]);
2345                                 {
2346                                         int mult;
2347                                         switch (p_ptr->mimic_form)
2348                                         {
2349                                         case MIMIC_NONE:
2350                                                 switch (p_ptr->prace)
2351                                                 {
2352                                                         case RACE_YEEK:
2353                                                         case RACE_KLACKON:
2354                                                         case RACE_HUMAN:
2355                                                         case RACE_AMBERITE:
2356                                                         case RACE_DUNADAN:
2357                                                         case RACE_BARBARIAN:
2358                                                         case RACE_BEASTMAN:
2359                                                                 mult = 25;break;
2360                                                         case RACE_HALF_ORC:
2361                                                         case RACE_HALF_TROLL:
2362                                                         case RACE_HALF_OGRE:
2363                                                         case RACE_HALF_GIANT:
2364                                                         case RACE_HALF_TITAN:
2365                                                         case RACE_CYCLOPS:
2366                                                         case RACE_IMP:
2367                                                         case RACE_SKELETON:
2368                                                         case RACE_ZOMBIE:
2369                                                         case RACE_VAMPIRE:
2370                                                         case RACE_SPECTRE:
2371                                                         case RACE_DEMON:
2372                                                         case RACE_DRACONIAN:
2373                                                                 mult = 30;break;
2374                                                         default:
2375                                                                 mult = 10;break;
2376                                                 }
2377                                                 break;
2378                                         case MIMIC_DEMON:
2379                                         case MIMIC_DEMON_LORD:
2380                                         case MIMIC_VAMPIRE:
2381                                                 mult = 30;break;
2382                                         default:
2383                                                 mult = 10;break;
2384                                         }
2385
2386                                         if (p_ptr->align < 0 && mult < 20)
2387                                                 mult = 20;
2388                                         if (!(p_ptr->resist_acid || IS_OPPOSE_ACID() || p_ptr->immune_acid) && (mult < 25))
2389                                                 mult = 25;
2390                                         if (!(p_ptr->resist_elec || IS_OPPOSE_ELEC() || p_ptr->immune_elec) && (mult < 25))
2391                                                 mult = 25;
2392                                         if (!(p_ptr->resist_fire || IS_OPPOSE_FIRE() || p_ptr->immune_fire) && (mult < 25))
2393                                                 mult = 25;
2394                                         if (!(p_ptr->resist_cold || IS_OPPOSE_COLD() || p_ptr->immune_cold) && (mult < 25))
2395                                                 mult = 25;
2396                                         if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()) && (mult < 25))
2397                                                 mult = 25;
2398
2399                                         if ((p_ptr->pclass != CLASS_SAMURAI) && (have_flag(flgs_aux, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
2400                                         {
2401                                                 p_ptr->csp -= (1+(p_ptr->msp / 30));
2402                                                 p_ptr->redraw |= (PR_MANA);
2403                                                 mult = mult * 3 / 2 + 20;
2404                                         }
2405                                         k *= (HIT_POINT)mult;
2406                                         k /= 10;
2407                                 }
2408
2409                                 k = critical_norm(o_ptr->weight, o_ptr->to_h, k, p_ptr->to_h[hand], mode);
2410                                 if (one_in_(6))
2411                                 {
2412                                         int mult = 2;
2413                                         msg_format(_("グッサリ切り裂かれた!", "Your weapon cuts deep into yourself!"));
2414                                         /* Try to increase the damage */
2415                                         while (one_in_(4))
2416                                         {
2417                                                 mult++;
2418                                         }
2419
2420                                         k *= (HIT_POINT)mult;
2421                                 }
2422                                 k += (p_ptr->to_d[hand] + o_ptr->to_d);
2423                                 if (k < 0) k = 0;
2424
2425                                 take_hit(DAMAGE_FORCE, k, _("死の大鎌", "Death scythe"), -1);
2426                                 redraw_stuff();
2427                         }
2428                         else
2429                         {
2430                                 /* Sound */
2431                                 sound(SOUND_MISS);
2432
2433                                 /* Message */
2434                                 msg_format(_("ミス! %sにかわされた。", "You miss %s."), m_name);
2435                         }
2436                 }
2437                 backstab = FALSE;
2438                 fuiuchi = FALSE;
2439         }
2440
2441
2442         if (weak && !(*mdeath))
2443         {
2444                 msg_format(_("%sは弱くなったようだ。", "%^s seems weakened."), m_name);
2445         }
2446         if (drain_left != MAX_VAMPIRIC_DRAIN)
2447         {
2448                 if (one_in_(4))
2449                 {
2450                         chg_virtue(V_UNLIFE, 1);
2451                 }
2452         }
2453         /* Mega-Hack -- apply earthquake brand */
2454         if (do_quake)
2455         {
2456                 earthquake(p_ptr->y, p_ptr->x, 10);
2457                 if (!cave[y][x].m_idx) *mdeath = TRUE;
2458         }
2459 }
2460
2461 /*!
2462  * @brief プレイヤーの打撃処理メインルーチン
2463  * @param y 攻撃目標のY座標
2464  * @param x 攻撃目標のX座標
2465  * @param mode 発動中の剣術ID
2466  * @return 実際に攻撃処理が行われた場合TRUEを返す。
2467  * @details
2468  * If no "weapon" is available, then "punch" the monster one time.
2469  */
2470 bool py_attack(int y, int x, BIT_FLAGS mode)
2471 {
2472         bool            fear = FALSE;
2473         bool            mdeath = FALSE;
2474         bool            stormbringer = FALSE;
2475
2476         cave_type       *c_ptr = &cave[y][x];
2477         monster_type    *m_ptr = &m_list[c_ptr->m_idx];
2478         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
2479         char            m_name[80];
2480
2481         /* Disturb the player */
2482         disturb(0, 1);
2483
2484         p_ptr->energy_use = 100;
2485
2486         if (!p_ptr->migite && !p_ptr->hidarite &&
2487             !(p_ptr->muta2 & (MUT2_HORNS | MUT2_BEAK | MUT2_SCOR_TAIL | MUT2_TRUNK | MUT2_TENTACLES)))
2488         {
2489                 msg_format(_("%s攻撃できない。", "You cannot do attacking."), 
2490                                         (empty_hands(FALSE) == EMPTY_HAND_NONE) ? _("両手がふさがって", "") : "");
2491                 return FALSE;
2492         }
2493
2494         /* Extract monster name (or "it") */
2495         monster_desc(m_name, m_ptr, 0);
2496
2497         if (m_ptr->ml)
2498         {
2499                 /* Auto-Recall if possible and visible */
2500                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
2501
2502                 /* Track a new monster */
2503                 health_track(c_ptr->m_idx);
2504         }
2505
2506         if ((r_ptr->flags1 & RF1_FEMALE) &&
2507             !(p_ptr->stun || p_ptr->confused || p_ptr->image || !m_ptr->ml))
2508         {
2509                 if ((inventory[INVEN_RARM].name1 == ART_ZANTETSU) || (inventory[INVEN_LARM].name1 == ART_ZANTETSU))
2510                 {
2511                         msg_print(_("拙者、おなごは斬れぬ!", "I can not attack women!"));
2512                         return FALSE;
2513                 }
2514         }
2515
2516         if (d_info[dungeon_type].flags1 & DF1_NO_MELEE)
2517         {
2518                 msg_print(_("なぜか攻撃することができない。", "Something prevent you from attacking."));
2519                 return FALSE;
2520         }
2521
2522         /* Stop if friendly */
2523         if (!is_hostile(m_ptr) &&
2524             !(p_ptr->stun || p_ptr->confused || p_ptr->image ||
2525             p_ptr->shero || !m_ptr->ml))
2526         {
2527                 if (inventory[INVEN_RARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
2528                 if (inventory[INVEN_LARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
2529                 if (stormbringer)
2530                 {
2531                         msg_format(_("黒い刃は強欲に%sを攻撃した!", "Your black blade greedily attacks %s!"), m_name);
2532                         chg_virtue(V_INDIVIDUALISM, 1);
2533                         chg_virtue(V_HONOUR, -1);
2534                         chg_virtue(V_JUSTICE, -1);
2535                         chg_virtue(V_COMPASSION, -1);
2536                 }
2537                 else if (p_ptr->pclass != CLASS_BERSERKER)
2538                 {
2539                         if (get_check(_("本当に攻撃しますか?", "Really hit it? ")))
2540                         {
2541                                 chg_virtue(V_INDIVIDUALISM, 1);
2542                                 chg_virtue(V_HONOUR, -1);
2543                                 chg_virtue(V_JUSTICE, -1);
2544                                 chg_virtue(V_COMPASSION, -1);
2545                         }
2546                         else
2547                         {
2548                                 msg_format(_("%sを攻撃するのを止めた。", "You stop to avoid hitting %s."), m_name);
2549                                 return FALSE;
2550                         }
2551                 }
2552         }
2553
2554
2555         /* Handle player fear */
2556         if (p_ptr->afraid)
2557         {
2558                 /* Message */
2559                 if (m_ptr->ml)
2560                         msg_format(_("恐くて%sを攻撃できない!", "You are too afraid to attack %s!"), m_name);
2561                 else
2562                         msg_format (_("そっちには何か恐いものがいる!", "There is something scary in your way!"));
2563
2564                 /* Disturb the monster */
2565                 (void)set_monster_csleep(c_ptr->m_idx, 0);
2566
2567                 /* Done */
2568                 return FALSE;
2569         }
2570
2571         if (MON_CSLEEP(m_ptr)) /* It is not honorable etc to attack helpless victims */
2572         {
2573                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_COMPASSION, -1);
2574                 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5)) chg_virtue(V_HONOUR, -1);
2575         }
2576
2577         if (p_ptr->migite && p_ptr->hidarite)
2578         {
2579                 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))
2580                 {
2581                         if (p_ptr->skill_exp[GINOU_NITOURYU] < WEAPON_EXP_BEGINNER)
2582                                 p_ptr->skill_exp[GINOU_NITOURYU] += 80;
2583                         else if(p_ptr->skill_exp[GINOU_NITOURYU] < WEAPON_EXP_SKILLED)
2584                                 p_ptr->skill_exp[GINOU_NITOURYU] += 4;
2585                         else if(p_ptr->skill_exp[GINOU_NITOURYU] < WEAPON_EXP_EXPERT)
2586                                 p_ptr->skill_exp[GINOU_NITOURYU] += 1;
2587                         else if(p_ptr->skill_exp[GINOU_NITOURYU] < WEAPON_EXP_MASTER)
2588                                 if (one_in_(3)) p_ptr->skill_exp[GINOU_NITOURYU] += 1;
2589                         p_ptr->update |= (PU_BONUS);
2590                 }
2591         }
2592
2593         /* Gain riding experience */
2594         if (p_ptr->riding)
2595         {
2596                 int cur = p_ptr->skill_exp[GINOU_RIDING];
2597                 int max = s_info[p_ptr->pclass].s_max[GINOU_RIDING];
2598
2599                 if (cur < max)
2600                 {
2601                         int ridinglevel = r_info[m_list[p_ptr->riding].r_idx].level;
2602                         int targetlevel = r_ptr->level;
2603                         int inc = 0;
2604
2605                         if ((cur / 200 - 5) < targetlevel)
2606                                 inc += 1;
2607
2608                         /* Extra experience */
2609                         if ((cur / 100) < ridinglevel)
2610                         {
2611                                 if ((cur / 100 + 15) < ridinglevel)
2612                                         inc += 1 + (ridinglevel - (cur / 100 + 15));
2613                                 else
2614                                         inc += 1;
2615                         }
2616
2617                         p_ptr->skill_exp[GINOU_RIDING] = MIN(max, cur + inc);
2618
2619                         p_ptr->update |= (PU_BONUS);
2620                 }
2621         }
2622
2623         riding_t_m_idx = c_ptr->m_idx;
2624         if (p_ptr->migite) py_attack_aux(y, x, &fear, &mdeath, 0, mode);
2625         if (p_ptr->hidarite && !mdeath) py_attack_aux(y, x, &fear, &mdeath, 1, mode);
2626
2627         /* Mutations which yield extra 'natural' attacks */
2628         if (!mdeath)
2629         {
2630                 if ((p_ptr->muta2 & MUT2_HORNS) && !mdeath)
2631                         natural_attack(c_ptr->m_idx, MUT2_HORNS, &fear, &mdeath);
2632                 if ((p_ptr->muta2 & MUT2_BEAK) && !mdeath)
2633                         natural_attack(c_ptr->m_idx, MUT2_BEAK, &fear, &mdeath);
2634                 if ((p_ptr->muta2 & MUT2_SCOR_TAIL) && !mdeath)
2635                         natural_attack(c_ptr->m_idx, MUT2_SCOR_TAIL, &fear, &mdeath);
2636                 if ((p_ptr->muta2 & MUT2_TRUNK) && !mdeath)
2637                         natural_attack(c_ptr->m_idx, MUT2_TRUNK, &fear, &mdeath);
2638                 if ((p_ptr->muta2 & MUT2_TENTACLES) && !mdeath)
2639                         natural_attack(c_ptr->m_idx, MUT2_TENTACLES, &fear, &mdeath);
2640         }
2641
2642         /* Hack -- delay fear messages */
2643         if (fear && m_ptr->ml && !mdeath)
2644         {
2645                 /* Sound */
2646                 sound(SOUND_FLEE);
2647
2648                 /* Message */
2649                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
2650         }
2651
2652         if ((p_ptr->special_defense & KATA_IAI) && ((mode != HISSATSU_IAI) || mdeath))
2653         {
2654                 set_action(ACTION_NONE);
2655         }
2656
2657         return mdeath;
2658 }
2659
2660
2661 /*!
2662  * @brief パターンによる移動制限処理
2663  * @param c_y プレイヤーの移動元Y座標
2664  * @param c_x プレイヤーの移動元X座標
2665  * @param n_y プレイヤーの移動先Y座標
2666  * @param n_x プレイヤーの移動先X座標
2667  * @return 移動処理が可能である場合(可能な場合に選択した場合)TRUEを返す。
2668  */
2669 bool pattern_seq(int c_y, int c_x, int n_y, int n_x)
2670 {
2671         feature_type *cur_f_ptr = &f_info[cave[c_y][c_x].feat];
2672         feature_type *new_f_ptr = &f_info[cave[n_y][n_x].feat];
2673         bool is_pattern_tile_cur = have_flag(cur_f_ptr->flags, FF_PATTERN);
2674         bool is_pattern_tile_new = have_flag(new_f_ptr->flags, FF_PATTERN);
2675         int pattern_type_cur, pattern_type_new;
2676
2677         if (!is_pattern_tile_cur && !is_pattern_tile_new) return TRUE;
2678
2679         pattern_type_cur = is_pattern_tile_cur ? cur_f_ptr->subtype : NOT_PATTERN_TILE;
2680         pattern_type_new = is_pattern_tile_new ? new_f_ptr->subtype : NOT_PATTERN_TILE;
2681
2682         if (pattern_type_new == PATTERN_TILE_START)
2683         {
2684                 if (!is_pattern_tile_cur && !p_ptr->confused && !p_ptr->stun && !p_ptr->image)
2685                 {
2686                         if (get_check(_("パターンの上を歩き始めると、全てを歩かなければなりません。いいですか?", 
2687                                                         "If you start walking the Pattern, you must walk the whole way. Ok? ")))
2688                                 return TRUE;
2689                         else
2690                                 return FALSE;
2691                 }
2692                 else
2693                         return TRUE;
2694         }
2695         else if ((pattern_type_new == PATTERN_TILE_OLD) ||
2696                  (pattern_type_new == PATTERN_TILE_END) ||
2697                  (pattern_type_new == PATTERN_TILE_WRECKED))
2698         {
2699                 if (is_pattern_tile_cur)
2700                 {
2701                         return TRUE;
2702                 }
2703                 else
2704                 {
2705                         msg_print(_("パターンの上を歩くにはスタート地点から歩き始めなくてはなりません。",
2706                                                 "You must start walking the Pattern from the startpoint."));
2707
2708                         return FALSE;
2709                 }
2710         }
2711         else if ((pattern_type_new == PATTERN_TILE_TELEPORT) ||
2712                  (pattern_type_cur == PATTERN_TILE_TELEPORT))
2713         {
2714                 return TRUE;
2715         }
2716         else if (pattern_type_cur == PATTERN_TILE_START)
2717         {
2718                 if (is_pattern_tile_new)
2719                         return TRUE;
2720                 else
2721                 {
2722                         msg_print(_("パターンの上は正しい順序で歩かねばなりません。", "You must walk the Pattern in correct order."));
2723                         return FALSE;
2724                 }
2725         }
2726         else if ((pattern_type_cur == PATTERN_TILE_OLD) ||
2727                  (pattern_type_cur == PATTERN_TILE_END) ||
2728                  (pattern_type_cur == PATTERN_TILE_WRECKED))
2729         {
2730                 if (!is_pattern_tile_new)
2731                 {
2732                         msg_print(_("パターンを踏み外してはいけません。", "You may not step off from the Pattern."));
2733                         return FALSE;
2734                 }
2735                 else
2736                 {
2737                         return TRUE;
2738                 }
2739         }
2740         else
2741         {
2742                 if (!is_pattern_tile_cur)
2743                 {
2744                         msg_print(_("パターンの上を歩くにはスタート地点から歩き始めなくてはなりません。",
2745                                                 "You must start walking the Pattern from the startpoint."));
2746
2747                         return FALSE;
2748                 }
2749                 else
2750                 {
2751                         byte ok_move = PATTERN_TILE_START;
2752                         switch (pattern_type_cur)
2753                         {
2754                                 case PATTERN_TILE_1:
2755                                         ok_move = PATTERN_TILE_2;
2756                                         break;
2757                                 case PATTERN_TILE_2:
2758                                         ok_move = PATTERN_TILE_3;
2759                                         break;
2760                                 case PATTERN_TILE_3:
2761                                         ok_move = PATTERN_TILE_4;
2762                                         break;
2763                                 case PATTERN_TILE_4:
2764                                         ok_move = PATTERN_TILE_1;
2765                                         break;
2766                                 default:
2767                                         if (p_ptr->wizard)
2768                                                 msg_format(_("おかしなパターン歩行、%d。", "Funny Pattern walking, %d."), pattern_type_cur);
2769
2770                                         return TRUE; /* Goof-up */
2771                         }
2772
2773                         if ((pattern_type_new == ok_move) ||
2774                             (pattern_type_new == pattern_type_cur))
2775                                 return TRUE;
2776                         else
2777                         {
2778                                 if (!is_pattern_tile_new)
2779                                         msg_print(_("パターンを踏み外してはいけません。", "You may not step off from the Pattern."));
2780                                 else
2781                                         msg_print(_("パターンの上は正しい順序で歩かねばなりません。", "You must walk the Pattern in correct order."));
2782
2783                                 return FALSE;
2784                         }
2785                 }
2786         }
2787 }
2788
2789
2790 /*!
2791  * @brief プレイヤーが地形踏破可能かを返す
2792  * @param feature 判定したい地形ID
2793  * @param mode 移動に関するオプションフラグ
2794  * @return 移動可能ならばTRUEを返す
2795  */
2796 bool player_can_enter(s16b feature, u16b mode)
2797 {
2798         feature_type *f_ptr = &f_info[feature];
2799
2800         if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
2801
2802         /* Pattern */
2803         if (have_flag(f_ptr->flags, FF_PATTERN))
2804         {
2805                 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
2806         }
2807
2808         /* "CAN" flags */
2809         if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
2810         if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
2811         if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
2812
2813         if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;
2814
2815         return TRUE;
2816 }
2817
2818
2819 /*!
2820  * @brief 移動に伴うプレイヤーのステータス変化処理
2821  * @param ny 移動先Y座標
2822  * @param nx 移動先X座標
2823  * @param mpe_mode 移動オプションフラグ
2824  * @return プレイヤーが死亡やフロア離脱を行わず、実際に移動が可能ならばTRUEを返す。
2825  */
2826 bool move_player_effect(POSITION ny, POSITION nx, u32b mpe_mode)
2827 {
2828         cave_type *c_ptr = &cave[ny][nx];
2829         feature_type *f_ptr = &f_info[c_ptr->feat];
2830
2831         if (!(mpe_mode & MPE_STAYING))
2832         {
2833                 POSITION oy = p_ptr->y;
2834                 POSITION ox = p_ptr->x;
2835                 cave_type *oc_ptr = &cave[oy][ox];
2836                 IDX om_idx = oc_ptr->m_idx;
2837                 IDX nm_idx = c_ptr->m_idx;
2838
2839                 /* Move the player */
2840                 p_ptr->y = ny;
2841                 p_ptr->x = nx;
2842
2843                 /* Hack -- For moving monster or riding player's moving */
2844                 if (!(mpe_mode & MPE_DONT_SWAP_MON))
2845                 {
2846                         /* Swap two monsters */
2847                         c_ptr->m_idx = om_idx;
2848                         oc_ptr->m_idx = nm_idx;
2849
2850                         if (om_idx > 0) /* Monster on old spot (or p_ptr->riding) */
2851                         {
2852                                 monster_type *om_ptr = &m_list[om_idx];
2853                                 om_ptr->fy = ny;
2854                                 om_ptr->fx = nx;
2855                                 update_mon(om_idx, TRUE);
2856                         }
2857
2858                         if (nm_idx > 0) /* Monster on new spot */
2859                         {
2860                                 monster_type *nm_ptr = &m_list[nm_idx];
2861                                 nm_ptr->fy = oy;
2862                                 nm_ptr->fx = ox;
2863                                 update_mon(nm_idx, TRUE);
2864                         }
2865                 }
2866
2867                 /* Redraw old spot */
2868                 lite_spot(oy, ox);
2869
2870                 /* Redraw new spot */
2871                 lite_spot(ny, nx);
2872
2873                 /* Check for new panel (redraw map) */
2874                 verify_panel();
2875
2876                 if (mpe_mode & MPE_FORGET_FLOW)
2877                 {
2878                         forget_flow();
2879
2880                         /* Mega-Hack -- Forget the view */
2881                         p_ptr->update |= (PU_UN_VIEW);
2882
2883                         /* Redraw map */
2884                         p_ptr->redraw |= (PR_MAP);
2885                 }
2886
2887                 /* Update stuff */
2888                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_DISTANCE);
2889
2890                 /* Window stuff */
2891                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2892
2893                 /* Remove "unsafe" flag */
2894                 if ((!p_ptr->blind && !no_lite()) || !is_trap(c_ptr->feat)) c_ptr->info &= ~(CAVE_UNSAFE);
2895
2896                 /* For get everything when requested hehe I'm *NASTY* */
2897                 if (dun_level && (d_info[dungeon_type].flags1 & DF1_FORGET)) wiz_dark();
2898
2899                 /* Handle stuff */
2900                 if (mpe_mode & MPE_HANDLE_STUFF) handle_stuff();
2901
2902                 if (p_ptr->pclass == CLASS_NINJA)
2903                 {
2904                         if (c_ptr->info & (CAVE_GLOW)) set_superstealth(FALSE);
2905                         else if (p_ptr->cur_lite <= 0) set_superstealth(TRUE);
2906                 }
2907
2908                 if ((p_ptr->action == ACTION_HAYAGAKE) &&
2909                     (!have_flag(f_ptr->flags, FF_PROJECT) ||
2910                      (!p_ptr->levitation && have_flag(f_ptr->flags, FF_DEEP))))
2911                 {
2912                         msg_print(_("ここでは素早く動けない。", "You cannot run in here."));
2913                         set_action(ACTION_NONE);
2914                 }
2915         }
2916
2917         if (mpe_mode & MPE_ENERGY_USE)
2918         {
2919                 if (music_singing(MUSIC_WALL))
2920                 {
2921                         (void)project(0, 0, p_ptr->y, p_ptr->x, (60 + p_ptr->lev), GF_DISINTEGRATE,
2922                                 PROJECT_KILL | PROJECT_ITEM, -1);
2923
2924                         if (!player_bold(ny, nx) || p_ptr->is_dead || p_ptr->leaving) return FALSE;
2925                 }
2926
2927                 /* Spontaneous Searching */
2928                 if ((p_ptr->skill_fos >= 50) || (0 == randint0(50 - p_ptr->skill_fos)))
2929                 {
2930                         search();
2931                 }
2932
2933                 /* Continuous Searching */
2934                 if (p_ptr->action == ACTION_SEARCH)
2935                 {
2936                         search();
2937                 }
2938         }
2939
2940         /* Handle "objects" */
2941         if (!(mpe_mode & MPE_DONT_PICKUP))
2942         {
2943                 carry((mpe_mode & MPE_DO_PICKUP) ? TRUE : FALSE);
2944         }
2945
2946         /* Handle "store doors" */
2947         if (have_flag(f_ptr->flags, FF_STORE))
2948         {
2949                 /* Disturb */
2950                 disturb(0, 1);
2951
2952                 p_ptr->energy_use = 0;
2953                 /* Hack -- Enter store */
2954                 command_new = SPECIAL_KEY_STORE;
2955         }
2956
2957         /* Handle "building doors" -KMW- */
2958         else if (have_flag(f_ptr->flags, FF_BLDG))
2959         {
2960                 /* Disturb */
2961                 disturb(0, 1);
2962
2963                 p_ptr->energy_use = 0;
2964                 /* Hack -- Enter building */
2965                 command_new = SPECIAL_KEY_BUILDING;
2966         }
2967
2968         /* Handle quest areas -KMW- */
2969         else if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
2970         {
2971                 /* Disturb */
2972                 disturb(0, 1);
2973
2974                 p_ptr->energy_use = 0;
2975                 /* Hack -- Enter quest level */
2976                 command_new = SPECIAL_KEY_QUEST;
2977         }
2978
2979         else if (have_flag(f_ptr->flags, FF_QUEST_EXIT))
2980         {
2981                 if (quest[p_ptr->inside_quest].type == QUEST_TYPE_FIND_EXIT)
2982                 {
2983                         complete_quest(p_ptr->inside_quest);
2984                 }
2985
2986                 leave_quest_check();
2987
2988                 p_ptr->inside_quest = c_ptr->special;
2989                 dun_level = 0;
2990                 p_ptr->oldpx = 0;
2991                 p_ptr->oldpy = 0;
2992
2993                 p_ptr->leaving = TRUE;
2994         }
2995
2996         /* Set off a trap */
2997         else if (have_flag(f_ptr->flags, FF_HIT_TRAP) && !(mpe_mode & MPE_STAYING))
2998         {
2999                 /* Disturb */
3000                 disturb(0, 1);
3001
3002                 /* Hidden trap */
3003                 if (c_ptr->mimic || have_flag(f_ptr->flags, FF_SECRET))
3004                 {
3005                         /* Message */
3006                         msg_print(_("トラップだ!", "You found a trap!"));
3007
3008                         /* Pick a trap */
3009                         disclose_grid(p_ptr->y, p_ptr->x);
3010                 }
3011
3012                 /* Hit the trap */
3013                 hit_trap((mpe_mode & MPE_BREAK_TRAP) ? TRUE : FALSE);
3014
3015                 if (!player_bold(ny, nx) || p_ptr->is_dead || p_ptr->leaving) return FALSE;
3016         }
3017
3018         /* Warn when leaving trap detected region */
3019         if (!(mpe_mode & MPE_STAYING) && (disturb_trap_detect || alert_trap_detect)
3020             && p_ptr->dtrap && !(c_ptr->info & CAVE_IN_DETECT))
3021         {
3022                 /* No duplicate warning */
3023                 p_ptr->dtrap = FALSE;
3024
3025                 /* You are just on the edge */
3026                 if (!(c_ptr->info & CAVE_UNSAFE))
3027                 {
3028                         if (alert_trap_detect)
3029                         {
3030                                 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
3031                         }
3032
3033                         if (disturb_trap_detect) disturb(0, 1);
3034                 }
3035         }
3036
3037         return player_bold(ny, nx) && !p_ptr->is_dead && !p_ptr->leaving;
3038 }
3039
3040 /*!
3041  * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す
3042  * @param feat 地形ID
3043  * @return トラップが自動的に無効ならばTRUEを返す
3044  */
3045 bool trap_can_be_ignored(int feat)
3046 {
3047         feature_type *f_ptr = &f_info[feat];
3048
3049         if (!have_flag(f_ptr->flags, FF_TRAP)) return TRUE;
3050
3051         switch (f_ptr->subtype)
3052         {
3053         case TRAP_TRAPDOOR:
3054         case TRAP_PIT:
3055         case TRAP_SPIKED_PIT:
3056         case TRAP_POISON_PIT:
3057                 if (p_ptr->levitation) return TRUE;
3058                 break;
3059         case TRAP_TELEPORT:
3060                 if (p_ptr->anti_tele) return TRUE;
3061                 break;
3062         case TRAP_FIRE:
3063                 if (p_ptr->immune_fire) return TRUE;
3064                 break;
3065         case TRAP_ACID:
3066                 if (p_ptr->immune_acid) return TRUE;
3067                 break;
3068         case TRAP_BLIND:
3069                 if (p_ptr->resist_blind) return TRUE;
3070                 break;
3071         case TRAP_CONFUSE:
3072                 if (p_ptr->resist_conf) return TRUE;
3073                 break;
3074         case TRAP_POISON:
3075                 if (p_ptr->resist_pois) return TRUE;
3076                 break;
3077         case TRAP_SLEEP:
3078                 if (p_ptr->free_act) return TRUE;
3079                 break;
3080         }
3081
3082         return FALSE;
3083 }
3084
3085
3086 /*
3087  * Determine if a "boundary" grid is "floor mimic"
3088  */
3089 #define boundary_floor(C, F, MF) \
3090         ((C)->mimic && permanent_wall(F) && \
3091          (have_flag((MF)->flags, FF_MOVE) || have_flag((MF)->flags, FF_CAN_FLY)) && \
3092          have_flag((MF)->flags, FF_PROJECT) && \
3093          !have_flag((MF)->flags, FF_OPEN))
3094
3095
3096 /*!
3097  * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す /
3098  * Move player in the given direction, with the given "pickup" flag.
3099  * @param dir 移動方向ID
3100  * @param do_pickup 罠解除を試みながらの移動ならばTRUE
3101  * @param break_trap トラップ粉砕処理を行うならばTRUE
3102  * @return 実際に移動が行われたならばTRUEを返す。
3103  * @note
3104  * This routine should (probably) always induce energy expenditure.\n
3105  * @details
3106  * Note that moving will *always* take a turn, and will *always* hit\n
3107  * any monster which might be in the destination grid.  Previously,\n
3108  * moving into walls was "free" and did NOT hit invisible monsters.\n
3109  */
3110 void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
3111 {
3112         /* Find the result of moving */
3113         POSITION y = p_ptr->y + ddy[dir];
3114         POSITION x = p_ptr->x + ddx[dir];
3115
3116         /* Examine the destination */
3117         cave_type *c_ptr = &cave[y][x];
3118
3119         feature_type *f_ptr = &f_info[c_ptr->feat];
3120
3121         monster_type *m_ptr;
3122
3123         monster_type *riding_m_ptr = &m_list[p_ptr->riding];
3124         monster_race *riding_r_ptr = &r_info[p_ptr->riding ? riding_m_ptr->r_idx : 0]; /* Paranoia */
3125
3126         char m_name[80];
3127
3128         bool p_can_enter = player_can_enter(c_ptr->feat, CEM_P_CAN_ENTER_PATTERN);
3129         bool p_can_kill_walls = FALSE;
3130         bool stormbringer = FALSE;
3131
3132         bool oktomove = TRUE;
3133         bool do_past = FALSE;
3134
3135         /* Exit the area */
3136         if (!dun_level && !p_ptr->wild_mode &&
3137                 ((x == 0) || (x == MAX_WID - 1) ||
3138                  (y == 0) || (y == MAX_HGT - 1)))
3139         {
3140                 /* Can the player enter the grid? */
3141                 if (c_ptr->mimic && player_can_enter(c_ptr->mimic, 0))
3142                 {
3143                         /* Hack: move to new area */
3144                         if ((y == 0) && (x == 0))
3145                         {
3146                                 p_ptr->wilderness_y--;
3147                                 p_ptr->wilderness_x--;
3148                                 p_ptr->oldpy = cur_hgt - 2;
3149                                 p_ptr->oldpx = cur_wid - 2;
3150                                 ambush_flag = FALSE;
3151                         }
3152
3153                         else if ((y == 0) && (x == MAX_WID - 1))
3154                         {
3155                                 p_ptr->wilderness_y--;
3156                                 p_ptr->wilderness_x++;
3157                                 p_ptr->oldpy = cur_hgt - 2;
3158                                 p_ptr->oldpx = 1;
3159                                 ambush_flag = FALSE;
3160                         }
3161
3162                         else if ((y == MAX_HGT - 1) && (x == 0))
3163                         {
3164                                 p_ptr->wilderness_y++;
3165                                 p_ptr->wilderness_x--;
3166                                 p_ptr->oldpy = 1;
3167                                 p_ptr->oldpx = cur_wid - 2;
3168                                 ambush_flag = FALSE;
3169                         }
3170
3171                         else if ((y == MAX_HGT - 1) && (x == MAX_WID - 1))
3172                         {
3173                                 p_ptr->wilderness_y++;
3174                                 p_ptr->wilderness_x++;
3175                                 p_ptr->oldpy = 1;
3176                                 p_ptr->oldpx = 1;
3177                                 ambush_flag = FALSE;
3178                         }
3179
3180                         else if (y == 0)
3181                         {
3182                                 p_ptr->wilderness_y--;
3183                                 p_ptr->oldpy = cur_hgt - 2;
3184                                 p_ptr->oldpx = x;
3185                                 ambush_flag = FALSE;
3186                         }
3187
3188                         else if (y == MAX_HGT - 1)
3189                         {
3190                                 p_ptr->wilderness_y++;
3191                                 p_ptr->oldpy = 1;
3192                                 p_ptr->oldpx = x;
3193                                 ambush_flag = FALSE;
3194                         }
3195
3196                         else if (x == 0)
3197                         {
3198                                 p_ptr->wilderness_x--;
3199                                 p_ptr->oldpx = cur_wid - 2;
3200                                 p_ptr->oldpy = y;
3201                                 ambush_flag = FALSE;
3202                         }
3203
3204                         else if (x == MAX_WID - 1)
3205                         {
3206                                 p_ptr->wilderness_x++;
3207                                 p_ptr->oldpx = 1;
3208                                 p_ptr->oldpy = y;
3209                                 ambush_flag = FALSE;
3210                         }
3211
3212                         p_ptr->leaving = TRUE;
3213                         p_ptr->energy_use = 100;
3214
3215                         return;
3216                 }
3217
3218                 /* "Blocked" message appears later */
3219                 /* oktomove = FALSE; */
3220                 p_can_enter = FALSE;
3221         }
3222
3223         /* Get the monster */
3224         m_ptr = &m_list[c_ptr->m_idx];
3225
3226
3227         if (inventory[INVEN_RARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
3228         if (inventory[INVEN_LARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
3229
3230         /* Player can not walk through "walls"... */
3231         /* unless in Shadow Form */
3232         p_can_kill_walls = p_ptr->kill_wall && have_flag(f_ptr->flags, FF_HURT_DISI) &&
3233                 (!p_can_enter || !have_flag(f_ptr->flags, FF_LOS)) &&
3234                 !have_flag(f_ptr->flags, FF_PERMANENT);
3235
3236         /* Hack -- attack monsters */
3237         if (c_ptr->m_idx && (m_ptr->ml || p_can_enter || p_can_kill_walls))
3238         {
3239                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3240
3241                 /* Attack -- only if we can see it OR it is not in a wall */
3242                 if (!is_hostile(m_ptr) &&
3243                     !(p_ptr->confused || p_ptr->image || !m_ptr->ml || p_ptr->stun ||
3244                     ((p_ptr->muta2 & MUT2_BERS_RAGE) && p_ptr->shero)) &&
3245                     pattern_seq(p_ptr->y, p_ptr->x, y, x) && (p_can_enter || p_can_kill_walls))
3246                 {
3247                         /* Disturb the monster */
3248                         (void)set_monster_csleep(c_ptr->m_idx, 0);
3249
3250                         /* Extract monster name (or "it") */
3251                         monster_desc(m_name, m_ptr, 0);
3252
3253                         if (m_ptr->ml)
3254                         {
3255                                 /* Auto-Recall if possible and visible */
3256                                 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
3257
3258                                 /* Track a new monster */
3259                                 health_track(c_ptr->m_idx);
3260                         }
3261
3262                         /* displace? */
3263                         if ((stormbringer && (randint1(1000) > 666)) || (p_ptr->pclass == CLASS_BERSERKER))
3264                         {
3265                                 py_attack(y, x, 0);
3266                                 oktomove = FALSE;
3267                         }
3268                         else if (monster_can_cross_terrain(cave[p_ptr->y][p_ptr->x].feat, r_ptr, 0))
3269                         {
3270                                 do_past = TRUE;
3271                         }
3272                         else
3273                         {
3274                                 msg_format(_("%^sが邪魔だ!", "%^s is in your way!"), m_name);
3275                                 p_ptr->energy_use = 0;
3276                                 oktomove = FALSE;
3277                         }
3278
3279                         /* now continue on to 'movement' */
3280                 }
3281                 else
3282                 {
3283                         py_attack(y, x, 0);
3284                         oktomove = FALSE;
3285                 }
3286         }
3287
3288         if (oktomove && p_ptr->riding)
3289         {
3290                 if (riding_r_ptr->flags1 & RF1_NEVER_MOVE)
3291                 {
3292                         msg_print(_("動けない!", "Can't move!"));
3293                         p_ptr->energy_use = 0;
3294                         oktomove = FALSE;
3295                         disturb(0, 1);
3296                 }
3297                 else if (MON_MONFEAR(riding_m_ptr))
3298                 {
3299                         char steed_name[80];
3300
3301                         /* Acquire the monster name */
3302                         monster_desc(steed_name, riding_m_ptr, 0);
3303
3304                         /* Dump a message */
3305                         msg_format(_("%sが恐怖していて制御できない。", "%^s is too scared to control."), steed_name);
3306                         oktomove = FALSE;
3307                         disturb(0, 1);
3308                 }
3309                 else if (p_ptr->riding_ryoute)
3310                 {
3311                         oktomove = FALSE;
3312                         disturb(0, 1);
3313                 }
3314                 else if (have_flag(f_ptr->flags, FF_CAN_FLY) && (riding_r_ptr->flags7 & RF7_CAN_FLY))
3315                 {
3316                         /* Allow moving */
3317                 }
3318                 else if (have_flag(f_ptr->flags, FF_CAN_SWIM) && (riding_r_ptr->flags7 & RF7_CAN_SWIM))
3319                 {
3320                         /* Allow moving */
3321                 }
3322                 else if (have_flag(f_ptr->flags, FF_WATER) &&
3323                         !(riding_r_ptr->flags7 & RF7_AQUATIC) &&
3324                         (have_flag(f_ptr->flags, FF_DEEP) || (riding_r_ptr->flags2 & RF2_AURA_FIRE)))
3325                 {
3326                         msg_format(_("%sの上に行けない。", "Can't swim."), f_name + f_info[get_feat_mimic(c_ptr)].name);
3327                         p_ptr->energy_use = 0;
3328                         oktomove = FALSE;
3329                         disturb(0, 1);
3330                 }
3331                 else if (!have_flag(f_ptr->flags, FF_WATER) && (riding_r_ptr->flags7 & RF7_AQUATIC))
3332                 {
3333                         msg_format(_("%sから上がれない。", "Can't land."), f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name);
3334                         p_ptr->energy_use = 0;
3335                         oktomove = FALSE;
3336                         disturb(0, 1);
3337                 }
3338                 else if (have_flag(f_ptr->flags, FF_LAVA) && !(riding_r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
3339                 {
3340                         msg_format(_("%sの上に行けない。", "Too hot to go through."), f_name + f_info[get_feat_mimic(c_ptr)].name);
3341                         p_ptr->energy_use = 0;
3342                         oktomove = FALSE;
3343                         disturb(0, 1);
3344                 }
3345
3346                 if (oktomove && MON_STUNNED(riding_m_ptr) && one_in_(2))
3347                 {
3348                         char steed_name[80];
3349                         monster_desc(steed_name, riding_m_ptr, 0);
3350                         msg_format(_("%sが朦朧としていてうまく動けない!", "You cannot control stunned %s!"), steed_name);
3351                         oktomove = FALSE;
3352                         disturb(0, 1);
3353                 }
3354         }
3355
3356         if (!oktomove)
3357         {
3358         }
3359
3360         else if (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation)
3361         {
3362                 msg_format(_("空を飛ばないと%sの上には行けない。", "You need to fly to go through the %s."), f_name + f_info[get_feat_mimic(c_ptr)].name);
3363                 p_ptr->energy_use = 0;
3364                 running = 0;
3365                 oktomove = FALSE;
3366         }
3367
3368         /*
3369          * Player can move through trees and
3370          * has effective -10 speed
3371          * Rangers can move without penality
3372          */
3373         else if (have_flag(f_ptr->flags, FF_TREE) && !p_can_kill_walls)
3374         {
3375                 if ((p_ptr->pclass != CLASS_RANGER) && !p_ptr->levitation && (!p_ptr->riding || !(riding_r_ptr->flags8 & RF8_WILD_WOOD))) p_ptr->energy_use *= 2;
3376         }
3377
3378 #ifdef ALLOW_EASY_DISARM /* TNB */
3379
3380         /* Disarm a visible trap */
3381         else if ((do_pickup != easy_disarm) && have_flag(f_ptr->flags, FF_DISARM) && !c_ptr->mimic)
3382         {
3383                 if (!trap_can_be_ignored(c_ptr->feat))
3384                 {
3385                         (void)do_cmd_disarm_aux(y, x, dir);
3386                         return;
3387                 }
3388         }
3389
3390 #endif /* ALLOW_EASY_DISARM -- TNB */
3391
3392         /* Player can not walk through "walls" unless in wraith form...*/
3393         else if (!p_can_enter && !p_can_kill_walls)
3394         {
3395                 /* Feature code (applying "mimic" field) */
3396                 s16b feat = get_feat_mimic(c_ptr);
3397                 feature_type *mimic_f_ptr = &f_info[feat];
3398                 cptr name = f_name + mimic_f_ptr->name;
3399
3400                 oktomove = FALSE;
3401
3402                 /* Notice things in the dark */
3403                 if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
3404                 {
3405                         /* Boundary floor mimic */
3406                         if (boundary_floor(c_ptr, f_ptr, mimic_f_ptr))
3407                         {
3408                                 msg_print(_("それ以上先には進めないようだ。", "You feel you cannot go any more."));
3409                         }
3410
3411                         /* Wall (or secret door) */
3412                         else
3413                         {
3414 #ifdef JP
3415                                 msg_format("%sが行く手をはばんでいるようだ。", name);
3416 #else
3417                                 msg_format("You feel %s %s blocking your way.",
3418                                         is_a_vowel(name[0]) ? "an" : "a", name);
3419 #endif
3420
3421                                 c_ptr->info |= (CAVE_MARK);
3422                                 lite_spot(y, x);
3423                         }
3424                 }
3425
3426                 /* Notice things */
3427                 else
3428                 {
3429                         /* Boundary floor mimic */
3430                         if (boundary_floor(c_ptr, f_ptr, mimic_f_ptr))
3431                         {
3432                                 msg_print(_("それ以上先には進めない。", "You cannot go any more."));
3433                                 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
3434                                         p_ptr->energy_use = 0;
3435                         }
3436
3437                         /* Wall (or secret door) */
3438                         else
3439                         {
3440 #ifdef ALLOW_EASY_OPEN
3441                                 /* Closed doors */
3442                                 if (easy_open && is_closed_door(feat) && easy_open_door(y, x)) return;
3443 #endif /* ALLOW_EASY_OPEN */
3444
3445 #ifdef JP
3446                                 msg_format("%sが行く手をはばんでいる。", name);
3447 #else
3448                                 msg_format("There is %s %s blocking your way.",
3449                                         is_a_vowel(name[0]) ? "an" : "a", name);
3450 #endif
3451
3452                                 /*
3453                                  * Well, it makes sense that you lose time bumping into
3454                                  * a wall _if_ you are confused, stunned or blind; but
3455                                  * typing mistakes should not cost you a turn...
3456                                  */
3457                                 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
3458                                         p_ptr->energy_use = 0;
3459                         }
3460                 }
3461
3462                 /* Disturb the player */
3463                 disturb(0, 1);
3464
3465                 /* Sound */
3466                 if (!boundary_floor(c_ptr, f_ptr, mimic_f_ptr)) sound(SOUND_HITWALL);
3467         }
3468
3469         /* Normal movement */
3470         if (oktomove && !pattern_seq(p_ptr->y, p_ptr->x, y, x))
3471         {
3472                 if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
3473                 {
3474                         p_ptr->energy_use = 0;
3475                 }
3476
3477                 /* To avoid a loop with running */
3478                 disturb(0, 1);
3479
3480                 oktomove = FALSE;
3481         }
3482
3483         /* Normal movement */
3484         if (oktomove)
3485         {
3486                 u32b mpe_mode = MPE_ENERGY_USE;
3487
3488                 if (p_ptr->warning)
3489                 {
3490                         if (!process_warning(x, y))
3491                         {
3492                                 p_ptr->energy_use = 25;
3493                                 return;
3494                         }
3495                 }
3496
3497                 if (do_past)
3498                 {
3499                         msg_format(_("%sを押し退けた。", "You push past %s."), m_name);
3500                 }
3501
3502                 /* Change oldpx and oldpy to place the player well when going back to big mode */
3503                 if (p_ptr->wild_mode)
3504                 {
3505                         if (ddy[dir] > 0)  p_ptr->oldpy = 1;
3506                         if (ddy[dir] < 0)  p_ptr->oldpy = MAX_HGT - 2;
3507                         if (ddy[dir] == 0) p_ptr->oldpy = MAX_HGT / 2;
3508                         if (ddx[dir] > 0)  p_ptr->oldpx = 1;
3509                         if (ddx[dir] < 0)  p_ptr->oldpx = MAX_WID - 2;
3510                         if (ddx[dir] == 0) p_ptr->oldpx = MAX_WID / 2;
3511                 }
3512
3513                 if (p_can_kill_walls)
3514                 {
3515                         cave_alter_feat(y, x, FF_HURT_DISI);
3516
3517                         /* Update some things -- similar to GF_KILL_WALL */
3518                         p_ptr->update |= (PU_FLOW);
3519                 }
3520
3521                 /* Sound */
3522                 /* sound(SOUND_WALK); */
3523
3524 #ifdef ALLOW_EASY_DISARM /* TNB */
3525
3526                 if (do_pickup != always_pickup) mpe_mode |= MPE_DO_PICKUP;
3527
3528 #else /* ALLOW_EASY_DISARM -- TNB */
3529
3530                 if (do_pickup) mpe_mode |= MPE_DO_PICKUP;
3531
3532 #endif /* ALLOW_EASY_DISARM -- TNB */
3533
3534                 if (break_trap) mpe_mode |= MPE_BREAK_TRAP;
3535
3536                 /* Move the player */
3537                 (void)move_player_effect(y, x, mpe_mode);
3538         }
3539 }
3540
3541
3542 static bool ignore_avoid_run;
3543
3544 /*!
3545  * @brief ダッシュ移動処理中、移動先のマスが既知の壁かどうかを判定する /
3546  * Hack -- Check for a "known wall" (see below)
3547  * @param dir 想定する移動方向ID
3548  * @param y 移動元のY座標
3549  * @param x 移動元のX座標
3550  * @return 移動先が既知の壁ならばTRUE
3551  */
3552 static int see_wall(int dir, int y, int x)
3553 {
3554         cave_type   *c_ptr;
3555
3556         /* Get the new location */
3557         y += ddy[dir];
3558         x += ddx[dir];
3559
3560         /* Illegal grids are not known walls */
3561         if (!in_bounds2(y, x)) return (FALSE);
3562
3563         /* Access grid */
3564         c_ptr = &cave[y][x];
3565
3566         /* Must be known to the player */
3567         if (c_ptr->info & (CAVE_MARK))
3568         {
3569                 /* Feature code (applying "mimic" field) */
3570                 s16b         feat = get_feat_mimic(c_ptr);
3571                 feature_type *f_ptr = &f_info[feat];
3572
3573                 /* Wall grids are known walls */
3574                 if (!player_can_enter(feat, 0)) return !have_flag(f_ptr->flags, FF_DOOR);
3575
3576                 /* Don't run on a tree unless explicitly requested */
3577                 if (have_flag(f_ptr->flags, FF_AVOID_RUN) && !ignore_avoid_run)
3578                         return TRUE;
3579
3580                 /* Don't run in a wall */
3581                 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
3582                         return !have_flag(f_ptr->flags, FF_DOOR);
3583         }
3584
3585         return FALSE;
3586 }
3587
3588
3589 /*!
3590  * @brief ダッシュ移動処理中、移動先のマスか未知の地形かどうかを判定する /
3591  * Hack -- Check for an "unknown corner" (see below)
3592  * @param dir 想定する移動方向ID
3593  * @param y 移動元のY座標
3594  * @param x 移動元のX座標
3595  * @return 移動先が未知の地形ならばTRUE
3596  */
3597 static int see_nothing(int dir, int y, int x)
3598 {
3599         /* Get the new location */
3600         y += ddy[dir];
3601         x += ddx[dir];
3602
3603         /* Illegal grids are unknown */
3604         if (!in_bounds2(y, x)) return (TRUE);
3605
3606         /* Memorized grids are always known */
3607         if (cave[y][x].info & (CAVE_MARK)) return (FALSE);
3608
3609         /* Viewable door/wall grids are known */
3610         if (player_can_see_bold(y, x)) return (FALSE);
3611
3612         /* Default */
3613         return (TRUE);
3614 }
3615
3616
3617
3618
3619
3620
3621 /*
3622  * Hack -- allow quick "cycling" through the legal directions
3623  */
3624 static byte cycle[] =
3625 { 1, 2, 3, 6, 9, 8, 7, 4, 1, 2, 3, 6, 9, 8, 7, 4, 1 };
3626
3627 /*
3628  * Hack -- map each direction into the "middle" of the "cycle[]" array
3629  */
3630 static byte chome[] =
3631 { 0, 8, 9, 10, 7, 0, 11, 6, 5, 4 };
3632
3633 /*
3634  * The direction we are running
3635  */
3636 static DIRECTION find_current;
3637
3638 /*
3639  * The direction we came from
3640  */
3641 static DIRECTION find_prevdir;
3642
3643 /*
3644  * We are looking for open area
3645  */
3646 static bool find_openarea;
3647
3648 /*
3649  * We are looking for a break
3650  */
3651 static bool find_breakright;
3652 static bool find_breakleft;
3653
3654
3655
3656 /*!
3657  * @brief ダッシュ処理の導入 /
3658  * Initialize the running algorithm for a new direction.
3659  * @param dir 導入の移動先
3660  * @details
3661  * Diagonal Corridor -- allow diaginal entry into corridors.\n
3662  *\n
3663  * Blunt Corridor -- If there is a wall two spaces ahead and\n
3664  * we seem to be in a corridor, then force a turn into the side\n
3665  * corridor, must be moving straight into a corridor here. ???\n
3666  *\n
3667  * Diagonal Corridor    Blunt Corridor (?)\n
3668  *       \# \#                  \#\n
3669  *       \#x\#                  \@x\#\n
3670  *       \@\@p.                  p\n
3671  */
3672 static void run_init(int dir)
3673 {
3674         int             row, col, deepleft, deepright;
3675         int             i, shortleft, shortright;
3676
3677
3678         /* Save the direction */
3679         find_current = dir;
3680
3681         /* Assume running straight */
3682         find_prevdir = dir;
3683
3684         /* Assume looking for open area */
3685         find_openarea = TRUE;
3686
3687         /* Assume not looking for breaks */
3688         find_breakright = find_breakleft = FALSE;
3689
3690         /* Assume no nearby walls */
3691         deepleft = deepright = FALSE;
3692         shortright = shortleft = FALSE;
3693
3694         p_ptr->run_py = p_ptr->y;
3695         p_ptr->run_px = p_ptr->x;
3696
3697         /* Find the destination grid */
3698         row = p_ptr->y + ddy[dir];
3699         col = p_ptr->x + ddx[dir];
3700
3701         ignore_avoid_run = cave_have_flag_bold(row, col, FF_AVOID_RUN);
3702
3703         /* Extract cycle index */
3704         i = chome[dir];
3705
3706         /* Check for walls */
3707         if (see_wall(cycle[i+1], p_ptr->y, p_ptr->x))
3708         {
3709                 find_breakleft = TRUE;
3710                 shortleft = TRUE;
3711         }
3712         else if (see_wall(cycle[i+1], row, col))
3713         {
3714                 find_breakleft = TRUE;
3715                 deepleft = TRUE;
3716         }
3717
3718         /* Check for walls */
3719         if (see_wall(cycle[i-1], p_ptr->y, p_ptr->x))
3720         {
3721                 find_breakright = TRUE;
3722                 shortright = TRUE;
3723         }
3724         else if (see_wall(cycle[i-1], row, col))
3725         {
3726                 find_breakright = TRUE;
3727                 deepright = TRUE;
3728         }
3729
3730         /* Looking for a break */
3731         if (find_breakleft && find_breakright)
3732         {
3733                 /* Not looking for open area */
3734                 find_openarea = FALSE;
3735
3736                 /* Hack -- allow angled corridor entry */
3737                 if (dir & 0x01)
3738                 {
3739                         if (deepleft && !deepright)
3740                         {
3741                                 find_prevdir = cycle[i - 1];
3742                         }
3743                         else if (deepright && !deepleft)
3744                         {
3745                                 find_prevdir = cycle[i + 1];
3746                         }
3747                 }
3748
3749                 /* Hack -- allow blunt corridor entry */
3750                 else if (see_wall(cycle[i], row, col))
3751                 {
3752                         if (shortleft && !shortright)
3753                         {
3754                                 find_prevdir = cycle[i - 2];
3755                         }
3756                         else if (shortright && !shortleft)
3757                         {
3758                                 find_prevdir = cycle[i + 2];
3759                         }
3760                 }
3761         }
3762 }
3763
3764
3765 /*!
3766  * @brief ダッシュ移動が継続できるかどうかの判定 /
3767  * Update the current "run" path
3768  * @return
3769  * ダッシュ移動が継続できるならばTRUEを返す。
3770  * Return TRUE if the running should be stopped
3771  */
3772 static bool run_test(void)
3773 {
3774         int         prev_dir, new_dir, check_dir = 0;
3775         int         row, col;
3776         int         i, max, inv;
3777         int         option = 0, option2 = 0;
3778         cave_type   *c_ptr;
3779         s16b        feat;
3780         feature_type *f_ptr;
3781
3782         /* Where we came from */
3783         prev_dir = find_prevdir;
3784
3785
3786         /* Range of newly adjacent grids */
3787         max = (prev_dir & 0x01) + 1;
3788
3789         /* break run when leaving trap detected region */
3790         if ((disturb_trap_detect || alert_trap_detect)
3791             && p_ptr->dtrap && !(cave[p_ptr->y][p_ptr->x].info & CAVE_IN_DETECT))
3792         {
3793                 /* No duplicate warning */
3794                 p_ptr->dtrap = FALSE;
3795
3796                 /* You are just on the edge */
3797                 if (!(cave[p_ptr->y][p_ptr->x].info & CAVE_UNSAFE))
3798                 {
3799                         if (alert_trap_detect)
3800                         {
3801                                 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
3802                         }
3803
3804                         if (disturb_trap_detect)
3805                         {
3806                                 /* Break Run */
3807                                 return(TRUE);
3808                         }
3809                 }
3810         }
3811
3812         /* Look at every newly adjacent square. */
3813         for (i = -max; i <= max; i++)
3814         {
3815                 s16b this_o_idx, next_o_idx = 0;
3816
3817                 /* New direction */
3818                 new_dir = cycle[chome[prev_dir] + i];
3819
3820                 /* New location */
3821                 row = p_ptr->y + ddy[new_dir];
3822                 col = p_ptr->x + ddx[new_dir];
3823
3824                 /* Access grid */
3825                 c_ptr = &cave[row][col];
3826
3827                 /* Feature code (applying "mimic" field) */
3828                 feat = get_feat_mimic(c_ptr);
3829                 f_ptr = &f_info[feat];
3830
3831                 /* Visible monsters abort running */
3832                 if (c_ptr->m_idx)
3833                 {
3834                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
3835
3836                         /* Visible monster */
3837                         if (m_ptr->ml) return (TRUE);
3838                 }
3839
3840                 /* Visible objects abort running */
3841                 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3842                 {
3843                         object_type *o_ptr;
3844
3845                         /* Acquire object */
3846                         o_ptr = &o_list[this_o_idx];
3847
3848                         /* Acquire next object */
3849                         next_o_idx = o_ptr->next_o_idx;
3850
3851                         /* Visible object */
3852                         if (o_ptr->marked & OM_FOUND) return (TRUE);
3853                 }
3854
3855                 /* Assume unknown */
3856                 inv = TRUE;
3857
3858                 /* Check memorized grids */
3859                 if (c_ptr->info & (CAVE_MARK))
3860                 {
3861                         bool notice = have_flag(f_ptr->flags, FF_NOTICE);
3862
3863                         if (notice && have_flag(f_ptr->flags, FF_MOVE))
3864                         {
3865                                 /* Open doors */
3866                                 if (find_ignore_doors && have_flag(f_ptr->flags, FF_DOOR) && have_flag(f_ptr->flags, FF_CLOSE))
3867                                 {
3868                                         /* Option -- ignore */
3869                                         notice = FALSE;
3870                                 }
3871
3872                                 /* Stairs */
3873                                 else if (find_ignore_stairs && have_flag(f_ptr->flags, FF_STAIRS))
3874                                 {
3875                                         /* Option -- ignore */
3876                                         notice = FALSE;
3877                                 }
3878
3879                                 /* Lava */
3880                                 else if (have_flag(f_ptr->flags, FF_LAVA) && (p_ptr->immune_fire || IS_INVULN()))
3881                                 {
3882                                         /* Ignore */
3883                                         notice = FALSE;
3884                                 }
3885
3886                                 /* Deep water */
3887                                 else if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP) &&
3888                                          (p_ptr->levitation || p_ptr->can_swim || (p_ptr->total_weight <= weight_limit())))
3889                                 {
3890                                         /* Ignore */
3891                                         notice = FALSE;
3892                                 }
3893                         }
3894
3895                         /* Interesting feature */
3896                         if (notice) return (TRUE);
3897
3898                         /* The grid is "visible" */
3899                         inv = FALSE;
3900                 }
3901
3902                 /* Analyze unknown grids and floors considering mimic */
3903                 if (inv || !see_wall(0, row, col))
3904                 {
3905                         /* Looking for open area */
3906                         if (find_openarea)
3907                         {
3908                                 /* Nothing */
3909                         }
3910
3911                         /* The first new direction. */
3912                         else if (!option)
3913                         {
3914                                 option = new_dir;
3915                         }
3916
3917                         /* Three new directions. Stop running. */
3918                         else if (option2)
3919                         {
3920                                 return (TRUE);
3921                         }
3922
3923                         /* Two non-adjacent new directions.  Stop running. */
3924                         else if (option != cycle[chome[prev_dir] + i - 1])
3925                         {
3926                                 return (TRUE);
3927                         }
3928
3929                         /* Two new (adjacent) directions (case 1) */
3930                         else if (new_dir & 0x01)
3931                         {
3932                                 check_dir = cycle[chome[prev_dir] + i - 2];
3933                                 option2 = new_dir;
3934                         }
3935
3936                         /* Two new (adjacent) directions (case 2) */
3937                         else
3938                         {
3939                                 check_dir = cycle[chome[prev_dir] + i + 1];
3940                                 option2 = option;
3941                                 option = new_dir;
3942                         }
3943                 }
3944
3945                 /* Obstacle, while looking for open area */
3946                 else
3947                 {
3948                         if (find_openarea)
3949                         {
3950                                 if (i < 0)
3951                                 {
3952                                         /* Break to the right */
3953                                         find_breakright = TRUE;
3954                                 }
3955
3956                                 else if (i > 0)
3957                                 {
3958                                         /* Break to the left */
3959                                         find_breakleft = TRUE;
3960                                 }
3961                         }
3962                 }
3963         }
3964
3965         /* Looking for open area */
3966         if (find_openarea)
3967         {
3968                 /* Hack -- look again */
3969                 for (i = -max; i < 0; i++)
3970                 {
3971                         /* Unknown grid or non-wall */
3972                         if (!see_wall(cycle[chome[prev_dir] + i], p_ptr->y, p_ptr->x))
3973                         {
3974                                 /* Looking to break right */
3975                                 if (find_breakright)
3976                                 {
3977                                         return (TRUE);
3978                                 }
3979                         }
3980
3981                         /* Obstacle */
3982                         else
3983                         {
3984                                 /* Looking to break left */
3985                                 if (find_breakleft)
3986                                 {
3987                                         return (TRUE);
3988                                 }
3989                         }
3990                 }
3991
3992                 /* Hack -- look again */
3993                 for (i = max; i > 0; i--)
3994                 {
3995                         /* Unknown grid or non-wall */
3996                         if (!see_wall(cycle[chome[prev_dir] + i], p_ptr->y, p_ptr->x))
3997                         {
3998                                 /* Looking to break left */
3999                                 if (find_breakleft)
4000                                 {
4001                                         return (TRUE);
4002                                 }
4003                         }
4004
4005                         /* Obstacle */
4006                         else
4007                         {
4008                                 /* Looking to break right */
4009                                 if (find_breakright)
4010                                 {
4011                                         return (TRUE);
4012                                 }
4013                         }
4014                 }
4015         }
4016
4017         /* Not looking for open area */
4018         else
4019         {
4020                 /* No options */
4021                 if (!option)
4022                 {
4023                         return (TRUE);
4024                 }
4025
4026                 /* One option */
4027                 else if (!option2)
4028                 {
4029                         /* Primary option */
4030                         find_current = option;
4031
4032                         /* No other options */
4033                         find_prevdir = option;
4034                 }
4035
4036                 /* Two options, examining corners */
4037                 else if (!find_cut)
4038                 {
4039                         /* Primary option */
4040                         find_current = option;
4041
4042                         /* Hack -- allow curving */
4043                         find_prevdir = option2;
4044                 }
4045
4046                 /* Two options, pick one */
4047                 else
4048                 {
4049                         /* Get next location */
4050                         row = p_ptr->y + ddy[option];
4051                         col = p_ptr->x + ddx[option];
4052
4053                         /* Don't see that it is closed off. */
4054                         /* This could be a potential corner or an intersection. */
4055                         if (!see_wall(option, row, col) ||
4056                             !see_wall(check_dir, row, col))
4057                         {
4058                                 /* Can not see anything ahead and in the direction we */
4059                                 /* are turning, assume that it is a potential corner. */
4060                                 if (see_nothing(option, row, col) &&
4061                                     see_nothing(option2, row, col))
4062                                 {
4063                                         find_current = option;
4064                                         find_prevdir = option2;
4065                                 }
4066
4067                                 /* STOP: we are next to an intersection or a room */
4068                                 else
4069                                 {
4070                                         return (TRUE);
4071                                 }
4072                         }
4073
4074                         /* This corner is seen to be enclosed; we cut the corner. */
4075                         else if (find_cut)
4076                         {
4077                                 find_current = option2;
4078                                 find_prevdir = option2;
4079                         }
4080
4081                         /* This corner is seen to be enclosed, and we */
4082                         /* deliberately go the long way. */
4083                         else
4084                         {
4085                                 find_current = option;
4086                                 find_prevdir = option2;
4087                         }
4088                 }
4089         }
4090
4091         /* About to hit a known wall, stop */
4092         if (see_wall(find_current, p_ptr->y, p_ptr->x))
4093         {
4094                 return (TRUE);
4095         }
4096
4097         /* Failure */
4098         return (FALSE);
4099 }
4100
4101
4102
4103 /*!
4104  * @brief 継続的なダッシュ処理 /
4105  * Take one step along the current "run" path
4106  * @param dir 移動を試みる方向ID
4107  * @return なし
4108  */
4109 void run_step(int dir)
4110 {
4111         /* Start running */
4112         if (dir)
4113         {
4114                 /* Ignore AVOID_RUN on a first step */
4115                 ignore_avoid_run = TRUE;
4116
4117                 /* Hack -- do not start silly run */
4118                 if (see_wall(dir, p_ptr->y, p_ptr->x))
4119                 {
4120                         /* Message */
4121                         msg_print(_("その方向には走れません。", "You cannot run in that direction."));
4122
4123                         /* Disturb */
4124                         disturb(0, 0);
4125
4126                         /* Done */
4127                         return;
4128                 }
4129
4130                 /* Initialize */
4131                 run_init(dir);
4132         }
4133
4134         /* Keep running */
4135         else
4136         {
4137                 /* Update run */
4138                 if (run_test())
4139                 {
4140                         /* Disturb */
4141                         disturb(0, 0);
4142
4143                         /* Done */
4144                         return;
4145                 }
4146         }
4147
4148         /* Decrease the run counter */
4149         if (--running <= 0) return;
4150
4151         /* Take time */
4152         p_ptr->energy_use = 100;
4153
4154         /* Move the player, using the "pickup" flag */
4155 #ifdef ALLOW_EASY_DISARM /* TNB */
4156
4157         move_player(find_current, FALSE, FALSE);
4158
4159 #else /* ALLOW_EASY_DISARM -- TNB */
4160
4161         move_player(find_current, always_pickup, FALSE);
4162
4163 #endif /* ALLOW_EASY_DISARM -- TNB */
4164
4165         if (player_bold(p_ptr->run_py, p_ptr->run_px))
4166         {
4167                 p_ptr->run_py = 0;
4168                 p_ptr->run_px = 0;
4169                 disturb(0, 0);
4170         }
4171 }
4172
4173
4174 #ifdef TRAVEL
4175
4176 /*!
4177  * @brief トラベル機能の判定処理 /
4178  * Test for traveling
4179  * @param prev_dir 前回移動を行った元の方角ID
4180  * @return なし
4181  */
4182 static int travel_test(int prev_dir)
4183 {
4184         int new_dir = 0;
4185         int i, max;
4186         const cave_type *c_ptr;
4187         int cost;
4188
4189         /* Cannot travel when blind */
4190         if (p_ptr->blind || no_lite())
4191         {
4192                 msg_print(_("目が見えない!", "You cannot see!"));
4193                 return (0);
4194         }
4195
4196         /* break run when leaving trap detected region */
4197         if ((disturb_trap_detect || alert_trap_detect)
4198             && p_ptr->dtrap && !(cave[p_ptr->y][p_ptr->x].info & CAVE_IN_DETECT))
4199         {
4200                 /* No duplicate warning */
4201                 p_ptr->dtrap = FALSE;
4202
4203                 /* You are just on the edge */
4204                 if (!(cave[p_ptr->y][p_ptr->x].info & CAVE_UNSAFE))
4205                 {
4206                         if (alert_trap_detect)
4207                         {
4208                                 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
4209                         }
4210
4211                         if (disturb_trap_detect)
4212                         {
4213                                 /* Break Run */
4214                                 return (0);
4215                         }
4216                 }
4217         }
4218
4219         /* Range of newly adjacent grids */
4220         max = (prev_dir & 0x01) + 1;
4221
4222         /* Look at every newly adjacent square. */
4223         for (i = -max; i <= max; i++)
4224         {
4225                 /* New direction */
4226                 int dir = cycle[chome[prev_dir] + i];
4227
4228                 /* New location */
4229                 int row = p_ptr->y + ddy[dir];
4230                 int col = p_ptr->x + ddx[dir];
4231
4232                 /* Access grid */
4233                 c_ptr = &cave[row][col];
4234
4235                 /* Visible monsters abort running */
4236                 if (c_ptr->m_idx)
4237                 {
4238                         monster_type *m_ptr = &m_list[c_ptr->m_idx];
4239
4240                         /* Visible monster */
4241                         if (m_ptr->ml) return (0);
4242                 }
4243
4244         }
4245
4246         /* Travel cost of current grid */
4247         cost = travel.cost[p_ptr->y][p_ptr->x];
4248
4249         /* Determine travel direction */
4250         for (i = 0; i < 8; ++ i) {
4251                 int dir_cost = travel.cost[p_ptr->y+ddy_ddd[i]][p_ptr->x+ddx_ddd[i]];
4252
4253                 if (dir_cost < cost)
4254                 {
4255                         new_dir = ddd[i];
4256                         cost = dir_cost;
4257                 }
4258         }
4259
4260         if (!new_dir) return (0);
4261
4262         /* Access newly move grid */
4263         c_ptr = &cave[p_ptr->y+ddy[new_dir]][p_ptr->x+ddx[new_dir]];
4264
4265         /* Close door abort traveling */
4266         if (!easy_open && is_closed_door(c_ptr->feat)) return (0);
4267
4268         /* Visible and unignorable trap abort tarveling */
4269         if (!c_ptr->mimic && !trap_can_be_ignored(c_ptr->feat)) return (0);
4270
4271         /* Move new grid */
4272         return (new_dir);
4273 }
4274
4275
4276 /*!
4277  * @brief トラベル機能の実装 /
4278  * Travel command
4279  * @return なし
4280  */
4281 void travel_step(void)
4282 {
4283         /* Get travel direction */
4284         travel.dir = travel_test(travel.dir);
4285
4286         /* disturb */
4287         if (!travel.dir)
4288         {
4289                 if (travel.run == 255)
4290                 {
4291                         msg_print(_("道筋が見つかりません!", "No route is found!"));
4292                         travel.y = travel.x = 0;
4293                 }
4294                 disturb(0, 1);
4295                 return;
4296         }
4297
4298         p_ptr->energy_use = 100;
4299
4300         move_player(travel.dir, always_pickup, FALSE);
4301
4302         if ((p_ptr->y == travel.y) && (p_ptr->x == travel.x))
4303         {
4304                 travel.run = 0;
4305                 travel.y = travel.x = 0;
4306         }
4307         else if (travel.run > 0)
4308                 travel.run--;
4309
4310         /* Travel Delay */
4311         Term_xtra(TERM_XTRA_DELAY, delay_factor);
4312 }
4313 #endif