OSDN Git Service

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