OSDN Git Service

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