OSDN Git Service

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