OSDN Git Service

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