OSDN Git Service

ウィザードモードに職業を変える機能を追加(ただし、魔法領域の再設定などは行われず不完全であるので注意)
[hengband/hengband.git] / src / mspells1.c
index 2fb5df8..0048b65 100644 (file)
@@ -1,19 +1,17 @@
 /* File: mspells1.c */
 
-/* Purpose: Monster spells (attack player) */
-
 /*
- * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
+ * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
  *
- * This software may be copied and distributed for educational, research, and
- * not for profit purposes provided that this copyright and statement are
- * included in all such copies.
+ * This software may be copied and distributed for educational, research,
+ * and not for profit purposes provided that this copyright and statement
+ * are included in all such copies.  Other copyrights may also apply.
  */
 
-#include "angband.h"
+/* Purpose: Monster spells (attack player) */
 
+#include "angband.h"
 
-#ifdef DRS_SMART_OPTIONS
 
 /*
  * And now for Intelligent monster attacks (including spells).
@@ -56,7 +54,7 @@ static bool int_outof(monster_race *r_ptr, int prob)
        if (!(r_ptr->flags2 & RF2_SMART)) prob = prob / 2;
 
        /* Roll the dice */
-       return (rand_int(100) < prob);
+       return (randint0(100) < prob);
 }
 
 
@@ -88,7 +86,8 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
        if (smart_learn)
        {
                /* Hack -- Occasionally forget player status */
-               if (m_ptr->smart && (rand_int(100) < 1)) m_ptr->smart = 0L;
+               /* Only save SM_FRIENDLY, SM_PET or SM_CLONED */
+               if (m_ptr->smart && (randint0(100) < 1)) m_ptr->smart &= (SM_FRIENDLY | SM_PET | SM_CLONED);
 
                /* Use the memorized flags */
                smart = m_ptr->smart;
@@ -100,21 +99,21 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
        {
                /* Know basic info */
                if (p_ptr->resist_acid) smart |= (SM_RES_ACID);
-               if (p_ptr->oppose_acid) smart |= (SM_OPP_ACID);
+               if (IS_OPPOSE_ACID()) smart |= (SM_OPP_ACID);
                if (p_ptr->immune_acid) smart |= (SM_IMM_ACID);
                if (p_ptr->resist_elec) smart |= (SM_RES_ELEC);
-               if (p_ptr->oppose_elec) smart |= (SM_OPP_ELEC);
+               if (IS_OPPOSE_ELEC()) smart |= (SM_OPP_ELEC);
                if (p_ptr->immune_elec) smart |= (SM_IMM_ELEC);
                if (p_ptr->resist_fire) smart |= (SM_RES_FIRE);
-               if (p_ptr->oppose_fire) smart |= (SM_OPP_FIRE);
+               if (IS_OPPOSE_FIRE()) smart |= (SM_OPP_FIRE);
                if (p_ptr->immune_fire) smart |= (SM_IMM_FIRE);
                if (p_ptr->resist_cold) smart |= (SM_RES_COLD);
-               if (p_ptr->oppose_cold) smart |= (SM_OPP_COLD);
+               if (IS_OPPOSE_COLD()) smart |= (SM_OPP_COLD);
                if (p_ptr->immune_cold) smart |= (SM_IMM_COLD);
 
                /* Know poison info */
                if (p_ptr->resist_pois) smart |= (SM_RES_POIS);
-               if (p_ptr->oppose_pois) smart |= (SM_OPP_POIS);
+               if (IS_OPPOSE_POIS()) smart |= (SM_OPP_POIS);
 
                /* Know special resistances */
                if (p_ptr->resist_neth) smart |= (SM_RES_NETH);
@@ -142,9 +141,9 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & SM_IMM_ACID)
        {
-               if (int_outof(r_ptr, 200)) f4 &= ~(RF4_BR_ACID);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BA_ACID);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BO_ACID);
+               f4 &= ~(RF4_BR_ACID);
+               f5 &= ~(RF5_BA_ACID);
+               f5 &= ~(RF5_BO_ACID);
        }
        else if ((smart & (SM_OPP_ACID)) && (smart & (SM_RES_ACID)))
        {
@@ -162,9 +161,9 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & (SM_IMM_ELEC))
        {
-               if (int_outof(r_ptr, 200)) f4 &= ~(RF4_BR_ELEC);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BA_ELEC);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BO_ELEC);
+               f4 &= ~(RF4_BR_ELEC);
+               f5 &= ~(RF5_BA_ELEC);
+               f5 &= ~(RF5_BO_ELEC);
        }
        else if ((smart & (SM_OPP_ELEC)) && (smart & (SM_RES_ELEC)))
        {
@@ -182,9 +181,9 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & (SM_IMM_FIRE))
        {
-               if (int_outof(r_ptr, 200)) f4 &= ~(RF4_BR_FIRE);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BA_FIRE);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BO_FIRE);
+               f4 &= ~(RF4_BR_FIRE);
+               f5 &= ~(RF5_BA_FIRE);
+               f5 &= ~(RF5_BO_FIRE);
        }
        else if ((smart & (SM_OPP_FIRE)) && (smart & (SM_RES_FIRE)))
        {
@@ -202,10 +201,10 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & (SM_IMM_COLD))
        {
-               if (int_outof(r_ptr, 200)) f4 &= ~(RF4_BR_COLD);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BA_COLD);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BO_COLD);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BO_ICEE);
+               f4 &= ~(RF4_BR_COLD);
+               f5 &= ~(RF5_BA_COLD);
+               f5 &= ~(RF5_BO_COLD);
+               f5 &= ~(RF5_BO_ICEE);
        }
        else if ((smart & (SM_OPP_COLD)) && (smart & (SM_RES_COLD)))
        {
@@ -239,9 +238,18 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & (SM_RES_NETH))
        {
-               if (int_outof(r_ptr, 20)) f4 &= ~(RF4_BR_NETH);
-               if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_NETH);
-               if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BO_NETH);
+               if (prace_is_(RACE_SPECTRE))
+               {
+                       f4 &= ~(RF4_BR_NETH);
+                       f5 &= ~(RF5_BA_NETH);
+                       f5 &= ~(RF5_BO_NETH);
+               }
+               else
+               {
+                       if (int_outof(r_ptr, 20)) f4 &= ~(RF4_BR_NETH);
+                       if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_NETH);
+                       if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BO_NETH);
+               }
        }
 
        if (smart & (SM_RES_LITE))
@@ -252,18 +260,26 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & (SM_RES_DARK))
        {
-               if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_DARK);
-               if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_DARK);
+               if (prace_is_(RACE_VAMPIRE))
+               {
+                       f4 &= ~(RF4_BR_DARK);
+                       f5 &= ~(RF5_BA_DARK);
+               }
+               else
+               {
+                       if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_DARK);
+                       if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_DARK);
+               }
        }
 
        if (smart & (SM_RES_FEAR))
        {
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_SCARE);
+               f5 &= ~(RF5_SCARE);
        }
 
        if (smart & (SM_RES_CONF))
        {
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_CONF);
+               f5 &= ~(RF5_CONF);
                if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CONF);
        }
 
@@ -280,13 +296,13 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & (SM_RES_BLIND))
        {
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_BLIND);
+               f5 &= ~(RF5_BLIND);
        }
 
        if (smart & (SM_RES_NEXUS))
        {
                if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_NEXU);
-               if (int_outof(r_ptr, 200)) f6 &= ~(RF6_TELE_LEVEL);
+               f6 &= ~(RF6_TELE_LEVEL);
        }
 
        if (smart & (SM_RES_SOUND))
@@ -311,21 +327,18 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
                if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_PLAS);
                if (int_outof(r_ptr, 150)) f5 &= ~(RF5_BO_ICEE);
                if (int_outof(r_ptr, 150)) f5 &= ~(RF5_MISSILE);
-               if (int_outof(r_ptr, 150)) f4 &= ~(RF4_ARROW_1);
-               if (int_outof(r_ptr, 150)) f4 &= ~(RF4_ARROW_2);
-               if (int_outof(r_ptr, 150)) f4 &= ~(RF4_ARROW_3);
-               if (int_outof(r_ptr, 150)) f4 &= ~(RF4_ARROW_4);
+               if (int_outof(r_ptr, 150)) f4 &= ~(RF4_SHOOT);
        }
 
        if (smart & (SM_IMM_FREE))
        {
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_HOLD);
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_SLOW);
+               f5 &= ~(RF5_HOLD);
+               f5 &= ~(RF5_SLOW);
        }
 
        if (smart & (SM_IMM_MANA))
        {
-               if (int_outof(r_ptr, 200)) f5 &= ~(RF5_DRAIN_MANA);
+               f5 &= ~(RF5_DRAIN_MANA);
        }
 
        /* XXX XXX XXX No spells left? */
@@ -336,8 +349,6 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
        (*f6p) = f6;
 }
 
-#endif /* DRS_SMART_OPTIONS */
-
 
 /*
  * Determine if there is a space near the player in which
@@ -358,18 +369,11 @@ bool summon_possible(int y1, int x1)
                        /* Only check a circular area */
                        if (distance(y1, x1, y, x)>2) continue;
 
-#if 0
-                       /* Hack: no summon on glyph of warding */
-                       if (cave[y][x].feat == FEAT_GLYPH) continue;
-                       if (cave[y][x].feat == FEAT_MINOR_GLYPH) continue;
-#endif
-
                        /* ...nor on the Pattern */
-                       if ((cave[y][x].feat >= FEAT_PATTERN_START)
-                               && (cave[y][x].feat <= FEAT_PATTERN_XTRA2)) continue;
+                       if (pattern_tile(y, x)) continue;
 
-                       /* Require empty floor grid in line of sight */
-                       if ((cave_empty_bold(y, x) || (cave[y][x].feat == FEAT_TREES)) && los(y1, x1, y, x) && los(y, x, y1, x1)) return (TRUE);
+                       /* Require empty floor grid in line of projection */
+                       if (cave_empty_bold(y, x) && projectable(y1, x1, y, x) && projectable(y, x, y1, x1)) return (TRUE);
                }
        }
 
@@ -377,9 +381,11 @@ bool summon_possible(int y1, int x1)
 }
 
 
-static bool raise_possible(int y, int x)
+bool raise_possible(monster_type *m_ptr)
 {
        int xx, yy;
+       int y = m_ptr->fy;
+       int x = m_ptr->fx;
        s16b this_o_idx, next_o_idx = 0;
        cave_type *c_ptr;
 
@@ -389,6 +395,7 @@ static bool raise_possible(int y, int x)
                {
                        if (distance(y, x, yy, xx) > 5) continue;
                        if (!los(y, x, yy, xx)) continue;
+                       if (!projectable(y, x, yy, xx)) continue;
 
                        c_ptr = &cave[yy][xx];
                        /* Scan the pile of objects */
@@ -402,7 +409,9 @@ static bool raise_possible(int y, int x)
 
                                /* Known to be worthless? */
                                if (o_ptr->tval == TV_CORPSE)
-                                       return TRUE;
+                               {
+                                       if (!monster_has_hostile_align(m_ptr, 0, 0, &r_info[o_ptr->pval])) return TRUE;
+                               }
                        }
                }
        }
@@ -459,7 +468,7 @@ bool clean_shot(int y1, int x1, int y2, int x2, bool friend)
                        }
                }
                /* Pets may not shoot through the character - TNB */
-               if ((y == py) && (x == px))
+               if (player_bold(y, x))
                {
                        if (friend) return (FALSE);
                }
@@ -475,7 +484,7 @@ bool clean_shot(int y1, int x1, int y2, int x2, bool friend)
  */
 static void bolt(int m_idx, int typ, int dam_hp, int monspell, bool learnable)
 {
-       int flg = PROJECT_STOP | PROJECT_KILL | PROJECT_PLAYER;
+       int flg = PROJECT_STOP | PROJECT_KILL | PROJECT_PLAYER | PROJECT_REFLECTABLE;
 
        /* Target the player with a bolt attack */
        (void)project(m_idx, 0, py, px, dam_hp, typ, flg, (learnable ? monspell : -1));
@@ -483,7 +492,7 @@ static void bolt(int m_idx, int typ, int dam_hp, int monspell, bool learnable)
 
 static void beam(int m_idx, int typ, int dam_hp, int monspell, bool learnable)
 {
-       int flg = PROJECT_BEAM | PROJECT_KILL | PROJECT_THRU | PROJECT_PLAYER | PROJECT_NO_REF;
+       int flg = PROJECT_BEAM | PROJECT_KILL | PROJECT_THRU | PROJECT_PLAYER;
 
        /* Target the player with a bolt attack */
        (void)project(m_idx, 0, py, px, dam_hp, typ, flg, (learnable ? monspell : -1));
@@ -508,31 +517,74 @@ static void breath(int y, int x, int m_idx, int typ, int dam_hp, int rad, bool b
        /* Handle breath attacks */
        if (breath) rad = 0 - rad;
 
-       if (typ == GF_ROCKET) flg |= PROJECT_STOP;
+       switch (typ)
+       {
+       case GF_ROCKET:
+               flg |= PROJECT_STOP;
+               break;
+       case GF_DRAIN_MANA:
+       case GF_MIND_BLAST:
+       case GF_BRAIN_SMASH:
+       case GF_CAUSE_1:
+       case GF_CAUSE_2:
+       case GF_CAUSE_3:
+       case GF_CAUSE_4:
+       case GF_HAND_DOOM:
+               flg |= (PROJECT_HIDE | PROJECT_AIMED);
+               break;
+       }
 
        /* Target the player with a ball attack */
        (void)project(m_idx, rad, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
 }
 
 
+u32b get_curse(int power, object_type *o_ptr)
+{
+       u32b new_curse;
+
+       while(1)
+       {
+               new_curse = (1 << (randint0(MAX_CURSE)+4));
+               if (power == 2)
+               {
+                       if (!(new_curse & TRC_HEAVY_MASK)) continue;
+               }
+               else if (power == 1)
+               {
+                       if (new_curse & TRC_SPECIAL_MASK) continue;
+               }
+               else if (power == 0)
+               {
+                       if (new_curse & TRC_HEAVY_MASK) continue;
+               }
+               if (new_curse == TRC_LOW_MELEE && !object_is_weapon(o_ptr)) continue;
+               if (new_curse == TRC_LOW_AC && !object_is_armour(o_ptr)) continue;
+               break;
+       }
+       return new_curse;
+}
+
 void curse_equipment(int chance, int heavy_chance)
 {
        bool        changed = FALSE;
-       u32b        o1, o2, o3;
-       object_type *o_ptr = &inventory[INVEN_RARM + rand_int(12)];
+       int         curse_power = 0;
+       u32b        new_curse;
+       u32b oflgs[TR_FLAG_SIZE];
+       object_type *o_ptr = &inventory[INVEN_RARM + randint0(12)];
+       char o_name[MAX_NLEN];
 
-       if (randint(100) > chance) return;
+       if (randint1(100) > chance) return;
 
        if (!o_ptr->k_idx) return;
 
-       object_flags(o_ptr, &o1, &o2, &o3);
+       object_flags(o_ptr, oflgs);
 
+       object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 
        /* Extra, biased saving throw for blessed items */
-       if ((o3 & TR3_BLESSED) && (randint(888) > chance))
+       if (have_flag(oflgs, TR_BLESSED) && (randint1(888) > chance))
        {
-               char o_name[MAX_NLEN];
-               object_desc(o_name, o_ptr, FALSE, 0);
 #ifdef JP
 msg_format("%s¤Ï¼ö¤¤¤òÄ·¤ÍÊÖ¤·¤¿¡ª", o_name,
 #else
@@ -544,33 +596,41 @@ msg_format("%s
                return;
        }
 
-       if ((randint(100) <= heavy_chance) &&
-               (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
+       if ((randint1(100) <= heavy_chance) &&
+           (object_is_artifact(o_ptr) || object_is_ego(o_ptr)))
        {
-               if (!(o3 & TR3_HEAVY_CURSE))
+               if (!(o_ptr->curse_flags & TRC_HEAVY_CURSE))
                        changed = TRUE;
-               o_ptr->art_flags3 |= TR3_HEAVY_CURSE;
-               o_ptr->art_flags3 |= TR3_CURSED;
-               o_ptr->ident |= IDENT_CURSED;
+               o_ptr->curse_flags |= TRC_HEAVY_CURSE;
+               o_ptr->curse_flags |= TRC_CURSED;
+               curse_power++;
        }
        else
        {
-               if (!(o_ptr->ident & IDENT_CURSED))
+               if (!object_is_cursed(o_ptr))
                        changed = TRUE;
-               o_ptr->art_flags3 |= TR3_CURSED;
-               o_ptr->ident |= IDENT_CURSED;
+               o_ptr->curse_flags |= TRC_CURSED;
+       }
+       if (heavy_chance >= 50) curse_power++;
+
+       new_curse = get_curse(curse_power, o_ptr);
+       if (!(o_ptr->curse_flags & new_curse))
+       {
+               changed = TRUE;
+               o_ptr->curse_flags |= new_curse;
        }
 
        if (changed)
        {
 #ifdef JP
-msg_print("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬¤¢¤Ê¤¿¤ò¤È¤ê¤Þ¤¤¤¿...");
+msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
 #else
-               msg_print("There is a malignant black aura surrounding you...");
+               msg_format("There is a malignant black aura surrounding %s...", o_name);
 #endif
 
                o_ptr->feeling = FEEL_NONE;
        }
+       p_ptr->update |= (PU_BONUS);
 }
 
 
@@ -774,13 +834,13 @@ static bool spell_dispel(byte spell)
 /*
  * Check should monster cast dispel spell.
  */
-static bool dispel_check(int m_idx)
+bool dispel_check(int m_idx)
 {
        monster_type *m_ptr = &m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
-       /* Invulnabilty */
-       if (p_ptr->invuln) return (TRUE);
+       /* Invulnabilty (including the song) */
+       if (IS_INVULN()) return (TRUE);
 
        /* Wraith form */
        if (p_ptr->wraith_form) return (TRUE);
@@ -800,17 +860,13 @@ static bool dispel_check(int m_idx)
        /* Berserk Strength */
        if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER)) return (TRUE);
 
-       /* Invulnability song */
-       if (music_singing(MUSIC_INVULN)) return (TRUE);
-
        /* Demon Lord */
        if (p_ptr->mimic_form == MIMIC_DEMON_LORD) return (TRUE);
 
        /* Elemental resistances */
        if (r_ptr->flags4 & RF4_BR_ACID)
        {
-               if (!p_ptr->immune_acid && p_ptr->oppose_acid) return (TRUE);
-
+               if (!p_ptr->immune_acid && (p_ptr->oppose_acid || music_singing(MUSIC_RESIST))) return (TRUE);
                if (p_ptr->special_defense & DEFENSE_ACID) return (TRUE);
        }
 
@@ -818,23 +874,20 @@ static bool dispel_check(int m_idx)
        {
                if (!((p_ptr->prace == RACE_DEMON) && p_ptr->lev > 44))
                {
-                       if(!p_ptr->immune_fire && p_ptr->oppose_fire) return (TRUE);
-
-                       if(p_ptr->special_defense & DEFENSE_FIRE) return(TRUE);
+                       if (!p_ptr->immune_fire && (p_ptr->oppose_fire || music_singing(MUSIC_RESIST))) return (TRUE);
+                       if (p_ptr->special_defense & DEFENSE_FIRE) return (TRUE);
                }
        }
 
        if (r_ptr->flags4 & RF4_BR_ELEC)
        {
-               if (!p_ptr->immune_elec && p_ptr->oppose_elec) return (TRUE);
-
+               if (!p_ptr->immune_elec && (p_ptr->oppose_elec || music_singing(MUSIC_RESIST))) return (TRUE);
                if (p_ptr->special_defense & DEFENSE_ELEC) return (TRUE);
        }
 
        if (r_ptr->flags4 & RF4_BR_COLD)
        {
-               if (!p_ptr->immune_cold && p_ptr->oppose_cold) return (TRUE);
-
+               if (!p_ptr->immune_cold && (p_ptr->oppose_cold || music_singing(MUSIC_RESIST))) return (TRUE);
                if (p_ptr->special_defense & DEFENSE_COLD) return (TRUE);
        }
 
@@ -842,18 +895,11 @@ static bool dispel_check(int m_idx)
        {
                if (!((p_ptr->pclass == CLASS_NINJA) && p_ptr->lev > 44))
                {
-                       if (p_ptr->oppose_pois) return (TRUE);
-
+                       if (p_ptr->oppose_pois || music_singing(MUSIC_RESIST)) return (TRUE);
                        if (p_ptr->special_defense & DEFENSE_POIS) return (TRUE);
                }
        }
 
-       /* Elemental resist music */
-       if (music_singing(MUSIC_RESIST))
-       {
-               if (r_ptr->flags4 & (RF4_BR_ACID | RF4_BR_FIRE | RF4_BR_ELEC | RF4_BR_COLD | RF4_BR_POIS)) return (TRUE);
-       }
-
        /* Ultimate resistance */
        if (p_ptr->ult_res) return (TRUE);
 
@@ -861,20 +907,16 @@ static bool dispel_check(int m_idx)
        if (p_ptr->tsuyoshi) return (TRUE);
 
        /* Elemental Brands */
-       if ((p_ptr->special_attack & ATTACK_ACID) && !(r_ptr->flags3 & RF3_IM_ACID)) return (TRUE);
-       if ((p_ptr->special_attack & ATTACK_FIRE) && !(r_ptr->flags3 & RF3_IM_FIRE)) return (TRUE);
-       if ((p_ptr->special_attack & ATTACK_ELEC) && !(r_ptr->flags3 & RF3_IM_ELEC)) return (TRUE);
-       if ((p_ptr->special_attack & ATTACK_COLD) && !(r_ptr->flags3 & RF3_IM_COLD)) return (TRUE);
-       if ((p_ptr->special_attack & ATTACK_POIS) && !(r_ptr->flags3 & RF3_IM_POIS)) return (TRUE);
+       if ((p_ptr->special_attack & ATTACK_ACID) && !(r_ptr->flagsr & RFR_EFF_IM_ACID_MASK)) return (TRUE);
+       if ((p_ptr->special_attack & ATTACK_FIRE) && !(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)) return (TRUE);
+       if ((p_ptr->special_attack & ATTACK_ELEC) && !(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK)) return (TRUE);
+       if ((p_ptr->special_attack & ATTACK_COLD) && !(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)) return (TRUE);
+       if ((p_ptr->special_attack & ATTACK_POIS) && !(r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)) return (TRUE);
 
        /* Speed */
        if (p_ptr->pspeed < 145)
        {
-               if (p_ptr->fast) return (TRUE);
-
-               if (music_singing(MUSIC_SPEED)) return (TRUE);
-
-               if (music_singing(MUSIC_SHERO)) return (TRUE);
+               if (IS_FAST()) return (TRUE);
        }
 
        /* Light speed */
@@ -882,7 +924,7 @@ static bool dispel_check(int m_idx)
 
        if (p_ptr->riding && (m_list[p_ptr->riding].mspeed < 135))
        {
-               if (m_list[p_ptr->riding].fast) return (TRUE);
+               if (MON_FAST(&m_list[p_ptr->riding])) return (TRUE);
        }
 
        /* No need to cast dispel spell */
@@ -914,7 +956,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
        byte summon[96], summon_num = 0;
        byte tactic[96], tactic_num = 0;
        byte annoy[96], annoy_num = 0;
-        byte invul[96], invul_num = 0;
+       byte invul[96], invul_num = 0;
        byte haste[96], haste_num = 0;
        byte world[96], world_num = 0;
        byte special[96], special_num = 0;
@@ -929,7 +971,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
        if (r_ptr->flags2 & (RF2_STUPID))
        {
                /* Pick at random */
-               return (spells[rand_int(num)]);
+               return (spells[randint0(num)]);
        }
 
        /* Categorize spells */
@@ -978,10 +1020,10 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
        /*** Try to pick an appropriate spell type ***/
 
        /* world */
-       if (world_num && (rand_int(100) < 15) && !world_monster)
+       if (world_num && (randint0(100) < 15) && !world_monster)
        {
                /* Choose haste spell */
-               return (world[rand_int(world_num)]);
+               return (world[randint0(world_num)]);
        }
 
        /* special */
@@ -996,52 +1038,58 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
                                break;
                        default: break;
                }
-               if (success) return (special[rand_int(special_num)]);
+               if (success) return (special[randint0(special_num)]);
        }
 
        /* Still hurt badly, couldn't flee, attempt to heal */
        if (m_ptr->hp < m_ptr->maxhp / 3 && one_in_(2))
        {
                /* Choose heal spell if possible */
-               if (heal_num) return (heal[rand_int(heal_num)]);
+               if (heal_num) return (heal[randint0(heal_num)]);
        }
 
        /* Hurt badly or afraid, attempt to flee */
-       if (((m_ptr->hp < m_ptr->maxhp / 3) || m_ptr->monfear) && one_in_(2))
+       if (((m_ptr->hp < m_ptr->maxhp / 3) || MON_MONFEAR(m_ptr)) && one_in_(2))
        {
                /* Choose escape spell if possible */
-               if (escape_num) return (escape[rand_int(escape_num)]);
+               if (escape_num) return (escape[randint0(escape_num)]);
        }
 
        /* special */
        if (special_num)
        {
                bool success = FALSE;
-               switch(m_ptr->r_idx)
+               switch (m_ptr->r_idx)
                {
                        case MON_OHMU:
-                               if (rand_int(100) < 50) success = TRUE;
+                       case MON_BANOR:
+                       case MON_LUPART:
                                break;
                        case MON_BANORLUPART:
-                               if (rand_int(100) < 70) success = TRUE;
+                               if (randint0(100) < 70) success = TRUE;
+                               break;
+                       case MON_ROLENTO:
+                               if (randint0(100) < 40) success = TRUE;
+                               break;
+                       default:
+                               if (randint0(100) < 50) success = TRUE;
                                break;
-                       default: break;
                }
-               if (success) return (special[rand_int(special_num)]);
+               if (success) return (special[randint0(special_num)]);
        }
 
        /* Player is close and we have attack spells, blink away */
-       if ((distance(py, px, m_ptr->fy, m_ptr->fx) < 4) && (attack_num || (r_ptr->flags6 & RF6_TRAPS)) && (rand_int(100) < 75) && !world_monster)
+       if ((distance(py, px, m_ptr->fy, m_ptr->fx) < 4) && (attack_num || (r_ptr->flags6 & RF6_TRAPS)) && (randint0(100) < 75) && !world_monster)
        {
                /* Choose tactical spell */
-               if (tactic_num) return (tactic[rand_int(tactic_num)]);
+               if (tactic_num) return (tactic[randint0(tactic_num)]);
        }
 
        /* Summon if possible (sometimes) */
-       if (summon_num && (rand_int(100) < 40))
+       if (summon_num && (randint0(100) < 40))
        {
                /* Choose summon spell */
-               return (summon[rand_int(summon_num)]);
+               return (summon[randint0(summon_num)]);
        }
 
        /* dispel */
@@ -1050,70 +1098,70 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
                /* Choose dispel spell if possible */
                if (dispel_check(m_idx))
                {
-                       return (dispel[rand_int(dispel_num)]);
+                       return (dispel[randint0(dispel_num)]);
                }
        }
 
        /* Raise-dead if possible (sometimes) */
-       if (raise_num && (rand_int(100) < 40) && raise_possible(m_ptr->fy, m_ptr->fx))
+       if (raise_num && (randint0(100) < 40))
        {
                /* Choose raise-dead spell */
-               return (raise[rand_int(raise_num)]);
+               return (raise[randint0(raise_num)]);
        }
 
        /* Attack spell (most of the time) */
-       if (p_ptr->invuln)
+       if (IS_INVULN())
        {
-               if (psy_spe_num && (rand_int(100) < 50))
+               if (psy_spe_num && (randint0(100) < 50))
                {
                        /* Choose attack spell */
-                       return (psy_spe[rand_int(psy_spe_num)]);
+                       return (psy_spe[randint0(psy_spe_num)]);
                }
-               else if (attack_num && (rand_int(100) < 40))
+               else if (attack_num && (randint0(100) < 40))
                {
                        /* Choose attack spell */
-                       return (attack[rand_int(attack_num)]);
+                       return (attack[randint0(attack_num)]);
                }
        }
-       else if (attack_num && (rand_int(100) < 85))
+       else if (attack_num && (randint0(100) < 85))
        {
                /* Choose attack spell */
-               return (attack[rand_int(attack_num)]);
+               return (attack[randint0(attack_num)]);
        }
 
        /* Try another tactical spell (sometimes) */
-       if (tactic_num && (rand_int(100) < 50) && !world_monster)
+       if (tactic_num && (randint0(100) < 50) && !world_monster)
        {
                /* Choose tactic spell */
-               return (tactic[rand_int(tactic_num)]);
+               return (tactic[randint0(tactic_num)]);
        }
 
        /* Cast globe of invulnerability if not already in effect */
-       if (invul_num && !(m_ptr->invulner) && (rand_int(100) < 50))
+       if (invul_num && !m_ptr->mtimed[MTIMED_INVULNER] && (randint0(100) < 50))
        {
                /* Choose Globe of Invulnerability */
-               return (invul[rand_int(invul_num)]);
+               return (invul[randint0(invul_num)]);
        }
 
        /* We're hurt (not badly), try to heal */
-       if ((m_ptr->hp < m_ptr->maxhp * 3 / 4) && (rand_int(100) < 25))
+       if ((m_ptr->hp < m_ptr->maxhp * 3 / 4) && (randint0(100) < 25))
        {
                /* Choose heal spell if possible */
-               if (heal_num) return (heal[rand_int(heal_num)]);
+               if (heal_num) return (heal[randint0(heal_num)]);
        }
 
        /* Haste self if we aren't already somewhat hasted (rarely) */
-       if (haste_num && (rand_int(100) < 20) && !(m_ptr->fast))
+       if (haste_num && (randint0(100) < 20) && !MON_FAST(m_ptr))
        {
                /* Choose haste spell */
-               return (haste[rand_int(haste_num)]);
+               return (haste[randint0(haste_num)]);
        }
 
        /* Annoy player (most of the time) */
-       if (annoy_num && (rand_int(100) < 80))
+       if (annoy_num && (randint0(100) < 80))
        {
                /* Choose annoyance spell */
-               return (annoy[rand_int(annoy_num)]);
+               return (annoy[randint0(annoy_num)]);
        }
 
        /* Choose no spell */
@@ -1122,6 +1170,76 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
 
 
 /*
+ * Return TRUE if a spell is inate spell.
+ */
+bool spell_is_inate(u16b spell)
+{
+       if (spell < 32 * 4) /* Set RF4 */
+       {
+               if ((1L << (spell - 32 * 3)) & RF4_NOMAGIC_MASK) return TRUE;
+       }
+       else if (spell < 32 * 5) /* Set RF5 */
+       {
+               if ((1L << (spell - 32 * 4)) & RF5_NOMAGIC_MASK) return TRUE;
+       }
+       else if (spell < 32 * 6) /* Set RF6 */
+       {
+               if ((1L << (spell - 32 * 5)) & RF6_NOMAGIC_MASK) return TRUE;
+       }
+
+       /* This spell is not "inate" */
+       return FALSE;
+}
+
+
+static bool adjacent_grid_check(monster_type *m_ptr, int *yp, int *xp,
+       int f_flag, bool (*path_check)(int, int, int, int))
+{
+       int i;
+       int tonari;
+       static int tonari_y[4][8] = {{-1, -1, -1,  0,  0,  1,  1,  1},
+                                            {-1, -1, -1,  0,  0,  1,  1,  1},
+                                            { 1,  1,  1,  0,  0, -1, -1, -1},
+                                            { 1,  1,  1,  0,  0, -1, -1, -1}};
+       static int tonari_x[4][8] = {{-1,  0,  1, -1,  1, -1,  0,  1},
+                                            { 1,  0, -1,  1, -1,  1,  0, -1},
+                                            {-1,  0,  1, -1,  1, -1,  0,  1},
+                                            { 1,  0, -1,  1, -1,  1,  0, -1}};
+
+       if (m_ptr->fy < py && m_ptr->fx < px) tonari = 0;
+       else if (m_ptr->fy < py) tonari = 1;
+       else if (m_ptr->fx < px) tonari = 2;
+       else tonari = 3;
+
+       for (i = 0; i < 8; i++)
+       {
+               int next_x = *xp + tonari_x[tonari][i];
+               int next_y = *yp + tonari_y[tonari][i];
+               cave_type *c_ptr;
+
+               /* Access the next grid */
+               c_ptr = &cave[next_y][next_x];
+
+               /* Skip this feature */
+               if (!cave_have_flag_grid(c_ptr, f_flag)) continue;
+
+               if (path_check(m_ptr->fy, m_ptr->fx, next_y, next_x))
+               {
+                       *yp = next_y;
+                       *xp = next_x;
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+#define DO_SPELL_NONE    0
+#define DO_SPELL_BR_LITE 1
+#define DO_SPELL_BR_DISI 2
+#define DO_SPELL_BA_LITE 3
+
+/*
  * Creatures can cast spells, shoot missiles, and breathe.
  *
  * Returns "TRUE" if a spell (or whatever) was (successfully) cast.
@@ -1177,17 +1295,19 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
  */
 bool make_attack_spell(int m_idx)
 {
-       int             k, chance, thrown_spell = 0, rlev, failrate;
+       int             k, thrown_spell = 0, rlev, failrate;
        byte            spell[96], num = 0;
        u32b            f4, f5, f6;
        monster_type    *m_ptr = &m_list[m_idx];
        monster_race    *r_ptr = &r_info[m_ptr->r_idx];
        char            m_name[80];
+#ifndef JP
        char            m_poss[80];
-       char            ddesc[80];
+#endif
        bool            no_inate = FALSE;
-       bool            do_disi = FALSE;
+       bool            do_spell = DO_SPELL_NONE;
        int             dam = 0;
+       u32b mode = 0L;
        int s_num_6 = (easy_band ? 2 : 6);
        int s_num_4 = (easy_band ? 1 : 4);
 
@@ -1195,6 +1315,10 @@ bool make_attack_spell(int m_idx)
        int x = px;
        int y = py;
 
+       /* Target location for lite breath */
+       int x_br_lite = 0;
+       int y_br_lite = 0;
+
        /* Summon count */
        int count = 0;
 
@@ -1207,17 +1331,20 @@ bool make_attack_spell(int m_idx)
        bool maneable = player_has_los_bold(m_ptr->fy, m_ptr->fx);
        bool learnable = (seen && maneable && !world_monster);
 
-       /* Assume "normal" target */
-       bool normal = TRUE;
+       /* Check "projectable" */
+       bool direct;
+
+       bool in_no_magic_dungeon = (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && dun_level
+               && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest));
 
-       /* Assume "projectable" */
-       bool direct = TRUE;
+       bool can_use_lite_area = FALSE;
+
+       bool can_remember;
 
        /* Cannot cast spells when confused */
-       if (m_ptr->confused)
+       if (MON_CONFUSED(m_ptr))
        {
-               m_ptr->target_y = 0;
-               m_ptr->target_x = 0;
+               reset_target(m_ptr);
                return (FALSE);
        }
 
@@ -1225,25 +1352,9 @@ bool make_attack_spell(int m_idx)
        if (m_ptr->mflag & MFLAG_NICE) return (FALSE);
        if (!is_hostile(m_ptr)) return (FALSE);
 
-       /* Hack -- Extract the spell probability */
-       chance = (r_ptr->freq_inate + r_ptr->freq_spell) / 2;
-
-       /* Not allowed to cast spells */
-       if (!chance) return (FALSE);
 
-
-       if (stupid_monsters)
-       {
-               /* Only do spells occasionally */
-               if (rand_int(100) >= chance) return (FALSE);
-       }
-       else
-       {
-               if (rand_int(100) >=  chance) return (FALSE);
-
-               /* Sometimes forbid inate attacks (breaths) */
-               if (rand_int(100) >= (chance * 2)) no_inate = TRUE;
-       }
+       /* Sometimes forbid inate attacks (breaths) */
+       if (randint0(100) >= (r_ptr->freq_spell * 2)) no_inate = TRUE;
 
        /* XXX XXX XXX Handle "track_target" option (?) */
 
@@ -1253,159 +1364,193 @@ bool make_attack_spell(int m_idx)
        f5 = r_ptr->flags5;
        f6 = r_ptr->flags6;
 
-       /* Hack -- require projectable player */
-       if (normal)
+       /*** require projectable player ***/
+
+       /* Check range */
+       if ((m_ptr->cdis > MAX_RANGE) && !m_ptr->target_y) return (FALSE);
+
+       /* Check path for lite breath */
+       if (f4 & RF4_BR_LITE)
        {
-               /* Check range */
-               if ((m_ptr->cdis > MAX_RANGE) && !m_ptr->target_y) return (FALSE);
+               y_br_lite = y;
+               x_br_lite = x;
 
-               /* Check path */
-               if (projectable(m_ptr->fy, m_ptr->fx, y, x))
+               if (los(m_ptr->fy, m_ptr->fx, y_br_lite, x_br_lite))
                {
-                       /* Breath disintegration to the glyph */
-                       if ((!cave_floor_bold(y,x)) && (r_ptr->flags4 & RF4_BR_DISI) && one_in_(2)) do_disi = TRUE;
+                       feature_type *f_ptr = &f_info[cave[y_br_lite][x_br_lite].feat];
+
+                       if (!have_flag(f_ptr->flags, FF_LOS))
+                       {
+                               if (have_flag(f_ptr->flags, FF_PROJECT) && one_in_(2)) f4 &= ~(RF4_BR_LITE);
+                       }
                }
 
                /* Check path to next grid */
-               else
+               else if (!adjacent_grid_check(m_ptr, &y_br_lite, &x_br_lite, FF_LOS, los)) f4 &= ~(RF4_BR_LITE);
+
+               /* Don't breath lite to the wall if impossible */
+               if (!(f4 & RF4_BR_LITE))
                {
-                       bool success = FALSE;
+                       y_br_lite = 0;
+                       x_br_lite = 0;
+               }
+       }
 
-                       if ((r_ptr->flags4 & RF4_BR_DISI) &&
-                           (m_ptr->cdis < MAX_RANGE/2) &&
-                           in_disintegration_range(m_ptr->fy, m_ptr->fx, y, x) &&
-                           (one_in_(10) || (projectable(y, x, m_ptr->fy, m_ptr->fx) && one_in_(2))))
-                       {
-                               do_disi = TRUE;
-                               success = TRUE;
-                       }
-                       else
-                       {
-                               int i;
-                               int tonari;
-                               int tonari_y[4][8] = {{-1,-1,-1,0,0,1,1,1},
-                                                     {-1,-1,-1,0,0,1,1,1},
-                                                     {1,1,1,0,0,-1,-1,-1},
-                                                     {1,1,1,0,0,-1,-1,-1}};
-                               int tonari_x[4][8] = {{-1,0,1,-1,1,-1,0,1},
-                                                     {1,0,-1,1,-1,1,0,-1},
-                                                     {-1,0,1,-1,1,-1,0,1},
-                                                     {1,0,-1,1,-1,1,0,-1}};
-
-                               if (m_ptr->fy < py && m_ptr->fx < px) tonari = 0;
-                               else if (m_ptr->fy < py) tonari = 1;
-                               else if (m_ptr->fx < px) tonari = 2;
-                               else tonari = 3;
-
-                               for (i = 0; i < 8; i++)
-                               {
-                                       int next_x = x + tonari_x[tonari][i];
-                                       int next_y = y + tonari_y[tonari][i];
-                                       cave_type *c_ptr;
+       /* Check path */
+       if (projectable(m_ptr->fy, m_ptr->fx, y, x))
+       {
+               feature_type *f_ptr = &f_info[cave[y][x].feat];
 
-                                       /* Access the next grid */
-                                       c_ptr = &cave[next_y][next_x];
+               if (!have_flag(f_ptr->flags, FF_PROJECT))
+               {
+                       /* Breath disintegration to the wall if possible */
+                       if ((f4 & RF4_BR_DISI) && have_flag(f_ptr->flags, FF_HURT_DISI) && one_in_(2)) do_spell = DO_SPELL_BR_DISI;
 
-                                       /* Skip door, rubble, wall */
-                                       if ((c_ptr->feat >= FEAT_DOOR_HEAD) && (c_ptr->feat <= FEAT_PERM_SOLID)) continue;
+                       /* Breath lite to the transparent wall if possible */
+                       else if ((f4 & RF4_BR_LITE) && have_flag(f_ptr->flags, FF_LOS) && one_in_(2)) do_spell = DO_SPELL_BR_LITE;
+               }
+       }
 
-                                       /* Skip tree */
-                                       if (c_ptr->feat == FEAT_TREES) continue;
+       /* Check path to next grid */
+       else
+       {
+               bool success = FALSE;
 
-                                       /* Skip mountain */
-                                       if (c_ptr->feat == FEAT_MOUNTAIN) continue;
+               if ((f4 & RF4_BR_DISI) && (m_ptr->cdis < MAX_RANGE/2) &&
+                   in_disintegration_range(m_ptr->fy, m_ptr->fx, y, x) &&
+                   (one_in_(10) || (projectable(y, x, m_ptr->fy, m_ptr->fx) && one_in_(2))))
+               {
+                       do_spell = DO_SPELL_BR_DISI;
+                       success = TRUE;
+               }
+               else if ((f4 & RF4_BR_LITE) && (m_ptr->cdis < MAX_RANGE/2) &&
+                   los(m_ptr->fy, m_ptr->fx, y, x) && one_in_(5))
+               {
+                       do_spell = DO_SPELL_BR_LITE;
+                       success = TRUE;
+               }
+               else if ((f5 & RF5_BA_LITE) && (m_ptr->cdis <= MAX_RANGE))
+               {
+                       int by = y, bx = x;
+                       get_project_point(m_ptr->fy, m_ptr->fx, &by, &bx, 0L);
+                       if ((distance(by, bx, y, x) <= 3) && los(by, bx, y, x) && one_in_(5))
+                       {
+                               do_spell = DO_SPELL_BA_LITE;
+                               success = TRUE;
+                       }
+               }
 
-                                       if (projectable(m_ptr->fy, m_ptr->fx, next_y, next_x))
-                                       {
-                                               y = next_y;
-                                               x = next_x;
-                                               success = TRUE;
-                                               break;
-                                       }
-                               }
+               if (!success) success = adjacent_grid_check(m_ptr, &y, &x, FF_PROJECT, projectable);
+
+               if (!success)
+               {
+                       if (m_ptr->target_y && m_ptr->target_x)
+                       {
+                               y = m_ptr->target_y;
+                               x = m_ptr->target_x;
+                               f4 &= (RF4_INDIRECT_MASK);
+                               f5 &= (RF5_INDIRECT_MASK);
+                               f6 &= (RF6_INDIRECT_MASK);
+                               success = TRUE;
                        }
 
-                       if (!success)
+                       if (y_br_lite && x_br_lite && (m_ptr->cdis < MAX_RANGE/2) && one_in_(5))
                        {
-                               if (m_ptr->target_y && m_ptr->target_x)
+                               if (!success)
                                {
-                                       y = m_ptr->target_y;
-                                       x = m_ptr->target_x;
-                                       f4 &= (RF4_INDIRECT_MASK);
-                                       f5 &= (RF5_INDIRECT_MASK);
-                                       f6 &= (RF6_INDIRECT_MASK);
+                                       y = y_br_lite;
+                                       x = x_br_lite;
+                                       do_spell = DO_SPELL_BR_LITE;
                                        success = TRUE;
                                }
+                               else f4 |= (RF4_BR_LITE);
                        }
-
-                       /* No spells */
-                       if (!success) return FALSE;
                }
+
+               /* No spells */
+               if (!success) return FALSE;
        }
 
-       m_ptr->target_y = 0;
-       m_ptr->target_x = 0;
+       reset_target(m_ptr);
 
        /* Extract the monster level */
        rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
 
-       if (!stupid_monsters)
+       /* Forbid inate attacks sometimes */
+       if (no_inate)
        {
-               /* Forbid inate attacks sometimes */
-               if (no_inate) f4 &= 0x500000FF;
+               f4 &= ~(RF4_NOMAGIC_MASK);
+               f5 &= ~(RF5_NOMAGIC_MASK);
+               f6 &= ~(RF6_NOMAGIC_MASK);
        }
 
-       if (!p_ptr->csp)
+       if (f6 & RF6_DARKNESS)
        {
-               f5 &= ~(RF5_DRAIN_MANA);
-       }
-       if ((p_ptr->pclass == CLASS_NINJA) && (r_ptr->flags3 & (RF3_UNDEAD | RF3_HURT_LITE)))
-       {
-               f6 &= ~(RF6_DARKNESS);
+               if ((p_ptr->pclass == CLASS_NINJA) &&
+                   !(r_ptr->flags3 & (RF3_UNDEAD | RF3_HURT_LITE)) &&
+                   !(r_ptr->flags7 & RF7_DARK_MASK))
+                       can_use_lite_area = TRUE;
+
+               if (!(r_ptr->flags2 & RF2_STUPID))
+               {
+                       if (d_info[dungeon_type].flags1 & DF1_DARKNESS) f6 &= ~(RF6_DARKNESS);
+                       else if ((p_ptr->pclass == CLASS_NINJA) && !can_use_lite_area) f6 &= ~(RF6_DARKNESS);
+               }
        }
 
-       if (dun_level && (!p_ptr->inside_quest || (p_ptr->inside_quest < MIN_RANDOM_QUEST)) && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC))
+       if (in_no_magic_dungeon && !(r_ptr->flags2 & RF2_STUPID))
        {
                f4 &= (RF4_NOMAGIC_MASK);
                f5 &= (RF5_NOMAGIC_MASK);
                f6 &= (RF6_NOMAGIC_MASK);
        }
 
-       /* Hack -- allow "desperate" spells */
-       if ((r_ptr->flags2 & (RF2_SMART)) &&
-               (m_ptr->hp < m_ptr->maxhp / 10) &&
-               (rand_int(100) < 50))
+       if (r_ptr->flags2 & RF2_SMART)
        {
-               /* Require intelligent spells */
-               f4 &= (RF4_INT_MASK);
-               f5 &= (RF5_INT_MASK);
-               f6 &= (RF6_INT_MASK);
+               /* Hack -- allow "desperate" spells */
+               if ((m_ptr->hp < m_ptr->maxhp / 10) &&
+                       (randint0(100) < 50))
+               {
+                       /* Require intelligent spells */
+                       f4 &= (RF4_INT_MASK);
+                       f5 &= (RF5_INT_MASK);
+                       f6 &= (RF6_INT_MASK);
+               }
 
-               /* No spells left */
-               if (!f4 && !f5 && !f6) return (FALSE);
+               /* Hack -- decline "teleport level" in some case */
+               if ((f6 & RF6_TELE_LEVEL) && TELE_LEVEL_IS_INEFF(0))
+               {
+                       f6 &= ~(RF6_TELE_LEVEL);
+               }
        }
 
+       /* No spells left */
+       if (!f4 && !f5 && !f6) return (FALSE);
+
        /* Remove the "ineffective" spells */
        remove_bad_spells(m_idx, &f4, &f5, &f6);
 
-       if (p_ptr->inside_arena)
+       if (p_ptr->inside_arena || p_ptr->inside_battle)
        {
                f4 &= ~(RF4_SUMMON_MASK);
                f5 &= ~(RF5_SUMMON_MASK);
-               f6 &= ~(RF6_SUMMON_MASK);
+               f6 &= ~(RF6_SUMMON_MASK | RF6_TELE_LEVEL);
+
+               if (m_ptr->r_idx == MON_ROLENTO) f6 &= ~(RF6_SPECIAL);
        }
 
        /* No spells left */
        if (!f4 && !f5 && !f6) return (FALSE);
 
-       if (!stupid_monsters)
+       if (!(r_ptr->flags2 & RF2_STUPID))
        {
+               if (!p_ptr->csp) f5 &= ~(RF5_DRAIN_MANA);
+
                /* Check for a clean bolt shot */
                if (((f4 & RF4_BOLT_MASK) ||
                     (f5 & RF5_BOLT_MASK) ||
                     (f6 & RF6_BOLT_MASK)) &&
-                    !(r_ptr->flags2 & RF2_STUPID) &&
-                    !clean_shot(m_ptr->fy, m_ptr->fx, py, px, FALSE))
+                   !clean_shot(m_ptr->fy, m_ptr->fx, py, px, FALSE))
                {
                        /* Remove spells that will only hurt friends */
                        f4 &= ~(RF4_BOLT_MASK);
@@ -1417,8 +1562,7 @@ bool make_attack_spell(int m_idx)
                if (((f4 & RF4_SUMMON_MASK) ||
                     (f5 & RF5_SUMMON_MASK) ||
                     (f6 & RF6_SUMMON_MASK)) &&
-                    !(r_ptr->flags2 & RF2_STUPID) &&
-                    !(summon_possible(y, x)))
+                   !(summon_possible(y, x)))
                {
                        /* Remove summoning spells */
                        f4 &= ~(RF4_SUMMON_MASK);
@@ -1426,6 +1570,22 @@ bool make_attack_spell(int m_idx)
                        f6 &= ~(RF6_SUMMON_MASK);
                }
 
+               /* Check for a possible raise dead */
+               if ((f6 & RF6_RAISE_DEAD) && !raise_possible(m_ptr))
+               {
+                       /* Remove raise dead spell */
+                       f6 &= ~(RF6_RAISE_DEAD);
+               }
+
+               /* Special moves restriction */
+               if (f6 & RF6_SPECIAL)
+               {
+                       if ((m_ptr->r_idx == MON_ROLENTO) && !summon_possible(y, x))
+                       {
+                               f6 &= ~(RF6_SPECIAL);
+                       }
+               }
+
                /* No spells left */
                if (!f4 && !f5 && !f6) return (FALSE);
        }
@@ -1452,7 +1612,7 @@ bool make_attack_spell(int m_idx)
        if (!num) return (FALSE);
 
        /* Stop if player is dead or gone */
-       if (!alive || death) return (FALSE);
+       if (!p_ptr->playing || p_ptr->is_dead) return (FALSE);
 
        /* Stop if player is leaving */
        if (p_ptr->leaving) return (FALSE);
@@ -1460,64 +1620,86 @@ bool make_attack_spell(int m_idx)
        /* Get the monster name (or "it") */
        monster_desc(m_name, m_ptr, 0x00);
 
+#ifndef JP
        /* Get the monster possessive ("his"/"her"/"its") */
-       monster_desc(m_poss, m_ptr, 0x22);
-
-       /* Hack -- Get the "died from" name */
-       monster_desc(ddesc, m_ptr, 0x88);
+       monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
+#endif
 
-       if (stupid_monsters)
-       {
-               /* Choose a spell to cast */
-               thrown_spell = spell[rand_int(num)];
-       }
-       else
+       switch (do_spell)
        {
-               int attempt = 10;
-               if (do_disi) thrown_spell = 96+31;
-               else
+       case DO_SPELL_NONE:
                {
-                       while(attempt--)
+                       int attempt = 10;
+                       while (attempt--)
                        {
                                thrown_spell = choose_attack_spell(m_idx, spell, num);
                                if (thrown_spell) break;
                        }
                }
+               break;
 
-               /* Abort if no spell was chosen */
-               if (!thrown_spell) return (FALSE);
+       case DO_SPELL_BR_LITE:
+               thrown_spell = 96+14; /* RF4_BR_LITE */
+               break;
 
-               /* Calculate spell failure rate */
-               failrate = 25 - (rlev + 3) / 4;
+       case DO_SPELL_BR_DISI:
+               thrown_spell = 96+31; /* RF4_BR_DISI */
+               break;
 
-               /* Hack -- Stupid monsters will never fail (for jellies and such) */
-               if (r_ptr->flags2 & RF2_STUPID) failrate = 0;
+       case DO_SPELL_BA_LITE:
+               thrown_spell = 128+20; /* RF5_BA_LITE */
+               break;
 
-               /* Check for spell failure (inate attacks never fail) */
-               if ((thrown_spell >= 128) && ((m_ptr->stunned && one_in_(2)) || (rand_int(100) < failrate)))
-               {
-                       disturb(1, 0);
-                       /* Message */
-                       if (thrown_spell != (160+7)) /* Not RF6_SPECIAL */
-                       {
+       default:
+               return FALSE; /* Paranoia */
+       }
+
+       /* Abort if no spell was chosen */
+       if (!thrown_spell) return (FALSE);
+
+       /* Calculate spell failure rate */
+       failrate = 25 - (rlev + 3) / 4;
+
+       /* Hack -- Stupid monsters will never fail (for jellies and such) */
+       if (r_ptr->flags2 & RF2_STUPID) failrate = 0;
+
+       /* Check for spell failure (inate attacks never fail) */
+       if (!spell_is_inate(thrown_spell)
+           && (in_no_magic_dungeon || (MON_STUNNED(m_ptr) && one_in_(2)) || (randint0(100) < failrate)))
+       {
+               disturb(1, 0);
+               /* Message */
 #ifdef JP
-msg_format("%^s¤Ï¼öʸ¤ò¾§¤¨¤è¤¦¤È¤·¤¿¤¬¼ºÇÔ¤·¤¿¡£", m_name);
+               msg_format("%^s¤Ï¼öʸ¤ò¾§¤¨¤è¤¦¤È¤·¤¿¤¬¼ºÇÔ¤·¤¿¡£", m_name);
 #else
-                               msg_format("%^s tries to cast a spell, but fails.", m_name);
+               msg_format("%^s tries to cast a spell, but fails.", m_name);
 #endif
-                       }
 
-                       return (TRUE);
-               }
+               return (TRUE);
+       }
+
+       /* Hex: Anti Magic Barrier */
+       if (!spell_is_inate(thrown_spell) && magic_barrier(m_idx))
+       {
+#ifdef JP
+               msg_format("È¿ËâË¡¥Ð¥ê¥¢¤¬%^s¤Î¼öʸ¤ò¤«¤­¾Ã¤·¤¿¡£", m_name);
+#else
+               msg_format("Anti magic barrier cancels the spell which %^s casts.");
+#endif
+               return (TRUE);
        }
 
+       /* Projectable? */
+       direct = player_bold(y, x);
+
+       can_remember = is_original_ap_and_seen(m_ptr);
+
        /* Cast the spell. */
        switch (thrown_spell)
        {
                /* RF4_SHRIEK */
                case 96+0:
                {
-                       if (!direct) break;
                        disturb(1, 0);
 #ifdef JP
 msg_format("%^s¤¬¤«¤ó¹â¤¤¶âÀÚ¤êÀ¼¤ò¤¢¤²¤¿¡£", m_name);
@@ -1539,7 +1721,7 @@ msg_format("%^s
                /* RF4_DISPEL */
                case 96+2:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
                        if (blind) msg_format("%^s¤¬²¿¤«¤òÎ϶¯¤¯¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -1548,89 +1730,8 @@ msg_format("%^s
                        if (blind) msg_format("%^s mumbles powerfully.", m_name);
                        else msg_format("%^s invokes a dispel magic.", m_name);
 #endif
-                       set_fast(0, TRUE);
-                       set_lightspeed(0, TRUE);
-                       set_slow(0, TRUE);
-                       set_shield(0, TRUE);
-                       set_blessed(0, TRUE);
-                       set_tsuyoshi(0, TRUE);
-                       set_hero(0, TRUE);
-                       set_shero(0, TRUE);
-                       set_protevil(0, TRUE);
-                       set_invuln(0, TRUE);
-                       set_wraith_form(0, TRUE);
-                       set_kabenuke(0, TRUE);
-                       set_tim_res_nether(0, TRUE);
-                       set_tim_res_time(0, TRUE);
-                       /* by henkma */
-                       set_tim_reflect(0,TRUE);
-                       set_multishadow(0,TRUE);
-                       set_dustrobe(0,TRUE);
-
-                       set_tim_invis(0, TRUE);
-                       set_tim_infra(0, TRUE);
-                       set_tim_esp(0, TRUE);
-                       set_tim_regen(0, TRUE);
-                       set_tim_stealth(0, TRUE);
-                       set_tim_ffall(0, TRUE);
-                       set_tim_sh_touki(0, TRUE);
-                       set_tim_sh_fire(0, TRUE);
-                       set_magicdef(0, TRUE);
-                       set_resist_magic(0, TRUE);
-                       set_oppose_acid(0, TRUE);
-                       set_oppose_elec(0, TRUE);
-                       set_oppose_fire(0, TRUE);
-                       set_oppose_cold(0, TRUE);
-                       set_oppose_pois(0, TRUE);
-                       set_ultimate_res(0, TRUE);
-                       set_mimic(0, 0, TRUE);
-                       set_ele_attack(0, 0);
-                       set_ele_immune(0, 0);
-                       /* Cancel glowing hands */
-                       if (p_ptr->special_attack & ATTACK_CONFUSE)
-                       {
-                               p_ptr->special_attack &= ~(ATTACK_CONFUSE);
-#ifdef JP
-                               msg_print("¼ê¤Îµ±¤­¤¬¤Ê¤¯¤Ê¤Ã¤¿¡£");
-#else
-                               msg_print("Your hands stop glowing.");
-#endif
-
-                       }
-                       if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0]))
-                       {
-                               p_ptr->magic_num1[1] = p_ptr->magic_num1[0];
-                               p_ptr->magic_num1[0] = 0;
-#ifdef JP
-                               msg_print("²Î¤¬ÅÓÀڤ줿¡£");
-#else
-                               msg_print("Your singing is interrupted.");
-#endif
-                               p_ptr->action = ACTION_NONE;
-
-                               /* Recalculate bonuses */
-                               p_ptr->update |= (PU_BONUS | PU_HP);
-
-                               /* Redraw map */
-                               p_ptr->redraw |= (PR_MAP | PR_STATUS | PR_STATE);
-
-                               /* Update monsters */
-                               p_ptr->update |= (PU_MONSTERS);
-
-                               /* Window stuff */
-                               p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
-
-                               p_ptr->energy -= 100;
-                       }
-                       if (p_ptr->riding)
-                       {
-                               m_list[p_ptr->riding].invulner = 0;
-                               m_list[p_ptr->riding].fast = 0;
-                               m_list[p_ptr->riding].slow = 0;
-                               p_ptr->update |= PU_BONUS;
-                               if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= PR_HEALTH;
-                               p_ptr->redraw |= (PR_UHEALTH);
-                       }
+                       dispel_player();
+                       if (p_ptr->riding) dispel_monster_status(p_ptr->riding);
 
 #ifdef JP
                        if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
@@ -1640,7 +1741,7 @@ msg_format("%^s
                        break;
                }
 
-               /* RF4_XXX4X4 */
+               /* RF4_ROCKET */
                case 96+3:
                {
                        disturb(1, 0);
@@ -1663,10 +1764,10 @@ else msg_format("%^s
                        break;
                }
 
-               /* RF4_ARROW_1 */
+               /* RF4_SHOOT */
                case 96+4:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬´ñ̯¤Ê²»¤òȯ¤·¤¿¡£", m_name);
@@ -1680,76 +1781,30 @@ else msg_format("%^s
                        else msg_format("%^s fires an arrow.", m_name);
 #endif
 
-                       dam = damroll(2, 5);
-                       bolt(m_idx, GF_ARROW, dam, MS_ARROW_1, learnable);
+                       dam = damroll(r_ptr->blow[0].d_dice, r_ptr->blow[0].d_side);
+                       bolt(m_idx, GF_ARROW, dam, MS_SHOOT, learnable);
                        update_smart_learn(m_idx, DRS_REFLECT);
                        break;
                }
 
-               /* RF4_ARROW_2 */
+               /* RF4_XXX2 */
                case 96+5:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       disturb(1, 0);
-#ifdef JP
-if (blind) msg_format("%^s¤¬´ñ̯¤Ê²»¤òȯ¤·¤¿¡£", m_name);
-#else
-                       if (blind) msg_format("%^s makes a strange noise.", m_name);
-#endif
-
-#ifdef JP
-else msg_format("%^s¤¬Ìð¤òÊü¤Ã¤¿¡£", m_name);
-#else
-                       else msg_format("%^s fires an arrow!", m_name);
-#endif
-
-                       dam = damroll(3, 6);
-                       bolt(m_idx, GF_ARROW, dam, MS_ARROW_2, learnable);
-                       update_smart_learn(m_idx, DRS_REFLECT);
+                       /* XXX XXX XXX */
                        break;
                }
 
-               /* RF4_ARROW_3 */
+               /* RF4_XXX3 */
                case 96+6:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       disturb(1, 0);
-#ifdef JP
-if (blind) msg_format("%^s¤¬´ñ̯¤Ê²»¤òȯ¤·¤¿¡£", m_name);
-#else
-                       if (blind) msg_format("%^s makes a strange noise.", m_name);
-#endif
-
-#ifdef JP
-                       else msg_format("%s¤¬¥Ü¥ë¥È¤ò·â¤Ã¤¿¡£", m_name);
-#else
-                       else msg_format("%^s fires a bolt.", m_name);
-#endif
-                       dam = damroll(5, 6);
-                       bolt(m_idx, GF_ARROW, dam, MS_ARROW_3, learnable);
-                       update_smart_learn(m_idx, DRS_REFLECT);
+                       /* XXX XXX XXX */
                        break;
                }
 
-               /* RF4_ARROW_4 */
+               /* RF4_XXX4 */
                case 96+7:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       disturb(1, 0);
-#ifdef JP
-if (blind) msg_format("%^s¤¬´ñ̯¤Ê²»¤òȯ¤·¤¿¡£", m_name);
-#else
-                       if (blind) msg_format("%^s makes a strange noise.", m_name);
-#endif
-
-#ifdef JP
-                       else msg_format("%s¤¬¥Ü¥ë¥È¤ò·â¤Ã¤¿¡£", m_name);
-#else
-                       else msg_format("%^s fires a bolt.", m_name);
-#endif
-                       dam = damroll(7, 6);
-                       bolt(m_idx, GF_ARROW, dam, MS_ARROW_4, learnable);
-                       update_smart_learn(m_idx, DRS_REFLECT);
+                       /* XXX XXX XXX */
                        break;
                }
 
@@ -1903,7 +1958,7 @@ else msg_format("%^s
 #endif
 
                        dam = ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6));
-                       breath(y, x, m_idx, GF_LITE, dam,0, TRUE, MS_BR_LITE, learnable);
+                       breath(y_br_lite, x_br_lite, m_idx, GF_LITE, dam,0, TRUE, MS_BR_LITE, learnable);
                        update_smart_learn(m_idx, DRS_LITE);
                        break;
                }
@@ -2304,7 +2359,7 @@ else msg_format("%^s
                        else msg_format("%^s casts an acid ball.", m_name);
 #endif
 
-                       dam = (randint(rlev * 3) + 15) * ((r_ptr->flags2 & RF2_POWERFUL) ? 2 : 1);
+                       dam = (randint1(rlev * 3) + 15) * ((r_ptr->flags2 & RF2_POWERFUL) ? 2 : 1);
                        breath(y, x, m_idx, GF_ACID, dam, 2, FALSE, MS_BALL_ACID, learnable);
                        update_smart_learn(m_idx, DRS_ACID);
                        break;
@@ -2326,7 +2381,7 @@ else msg_format("%^s
                        else msg_format("%^s casts a lightning ball.", m_name);
 #endif
 
-                       dam = (randint(rlev * 3 / 2) + 8) * ((r_ptr->flags2 & RF2_POWERFUL) ? 2 : 1);
+                       dam = (randint1(rlev * 3 / 2) + 8) * ((r_ptr->flags2 & RF2_POWERFUL) ? 2 : 1);
                        breath(y, x, m_idx, GF_ELEC, dam, 2, FALSE, MS_BALL_ELEC, learnable);
                        update_smart_learn(m_idx, DRS_ELEC);
                        break;
@@ -2366,7 +2421,7 @@ else msg_format("%^s
 #endif
                        }
 
-                       dam = (randint(rlev * 7 / 2) + 10) * ((r_ptr->flags2 & RF2_POWERFUL) ? 2 : 1);
+                       dam = (randint1(rlev * 7 / 2) + 10) * ((r_ptr->flags2 & RF2_POWERFUL) ? 2 : 1);
                        breath(y, x, m_idx, GF_FIRE, dam, 2, FALSE, MS_BALL_FIRE, learnable);
                        update_smart_learn(m_idx, DRS_FIRE);
                        break;
@@ -2388,7 +2443,7 @@ else msg_format("%^s
                        else msg_format("%^s casts a frost ball.", m_name);
 #endif
 
-                       dam = (randint(rlev * 3 / 2) + 10) * ((r_ptr->flags2 & RF2_POWERFUL) ? 2 : 1);
+                       dam = (randint1(rlev * 3 / 2) + 10) * ((r_ptr->flags2 & RF2_POWERFUL) ? 2 : 1);
                        breath(y, x, m_idx, GF_COLD, dam, 2, FALSE, MS_BALL_COLD, learnable);
                        update_smart_learn(m_idx, DRS_COLD);
                        break;
@@ -2460,7 +2515,7 @@ msg_print("
                        msg_print("You are engulfed in a whirlpool.");
 #endif
 
-                       dam = ((r_ptr->flags2 & RF2_POWERFUL) ? randint(rlev * 3) : randint(rlev * 2)) + 50;
+                       dam = ((r_ptr->flags2 & RF2_POWERFUL) ? randint1(rlev * 3) : randint1(rlev * 2)) + 50;
                        breath(y, x, m_idx, GF_WATER, dam, 4, FALSE, MS_BALL_WATER, learnable);
                        break;
                }
@@ -2511,84 +2566,24 @@ else msg_format("%^s
                /* RF5_DRAIN_MANA */
                case 128+9:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
-                       if (p_ptr->csp)
-                       {
-                               int r1;
 
-                               /* Basic message */
+                       dam = (randint1(rlev) / 2) + 1;
+                       breath(y, x, m_idx, GF_DRAIN_MANA, dam, 0, FALSE, MS_DRAIN_MANA, learnable);
+                       update_smart_learn(m_idx, DRS_MANA);
+                       break;
+               }
+
+               /* RF5_MIND_BLAST */
+               case 128+10:
+               {
+                       if (!direct) return (FALSE);
+                       disturb(1, 0);
+                       if (!seen)
+                       {
 #ifdef JP
-msg_format("%^s¤ËÀº¿À¥¨¥Í¥ë¥®¡¼¤òµÛ¤¤¼è¤é¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª", m_name);
-#else
-                               msg_format("%^s draws psychic energy from you!", m_name);
-#endif
-
-
-                               /* Attack power */
-                               r1 = (randint(rlev) / 2) + 1;
-
-                               /* Full drain */
-                               if (r1 >= p_ptr->csp)
-                               {
-                                       r1 = p_ptr->csp;
-                                       p_ptr->csp = 0;
-                                       p_ptr->csp_frac = 0;
-                               }
-
-                               /* Partial drain */
-                               else
-                               {
-                                       p_ptr->csp -= r1;
-                               }
-
-                               learn_spell(MS_DRAIN_MANA);
-
-                               /* Redraw mana */
-                               p_ptr->redraw |= (PR_MANA);
-
-                               /* Window stuff */
-                               p_ptr->window |= (PW_PLAYER);
-                               p_ptr->window |= (PW_SPELL);
-
-                               /* Heal the monster */
-                               if (m_ptr->hp < m_ptr->maxhp)
-                               {
-                                       /* Heal */
-                                       m_ptr->hp += (6 * r1);
-                                       if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
-
-                                       /* Redraw (later) if needed */
-                                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
-                                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
-
-                                       /* Special message */
-                                       if (seen)
-                                       {
-#ifdef JP
-msg_format("%^s¤Ïµ¤Ê¬¤¬Îɤµ¤½¤¦¤À¡£", m_name);
-#else
-                                               msg_format("%^s appears healthier.", m_name);
-#endif
-
-                                       }
-                               }
-                       }
-                       update_smart_learn(m_idx, DRS_MANA);
-                       break;
-               }
-
-               /* RF5_MIND_BLAST */
-               case 128+10:
-               {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
-                       disturb(1, 0);
-                       if (!seen)
-                       {
-#ifdef JP
-msg_print("²¿¤«¤¬¤¢¤Ê¤¿¤ÎÀº¿À¤ËÇ°¤òÊü¤Ã¤Æ¤¤¤ë¤è¤¦¤À¡£");
+msg_print("²¿¤«¤¬¤¢¤Ê¤¿¤ÎÀº¿À¤ËÇ°¤òÊü¤Ã¤Æ¤¤¤ë¤è¤¦¤À¡£");
 #else
                                msg_print("You feel something focusing on your mind.");
 #endif
@@ -2605,51 +2600,14 @@ msg_format("%^s
                        }
 
                        dam = damroll(7, 7);
-                       if (rand_int(100 + rlev/2) < (MAX(5, p_ptr->skill_sav)))
-                       {
-#ifdef JP
-msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
-#else
-                               msg_print("You resist the effects!");
-#endif
-                               learn_spell(MS_MIND_BLAST);
-                       }
-                       else
-                       {
-#ifdef JP
-msg_print("ÎîŪ¥¨¥Í¥ë¥®¡¼¤ÇÀº¿À¤¬¹¶·â¤µ¤ì¤¿¡£");
-#else
-                               msg_print("Your mind is blasted by psyonic energy.");
-#endif
-
-                               if (!p_ptr->resist_conf)
-                               {
-                                       (void)set_confused(p_ptr->confused + rand_int(4) + 4);
-                               }
-
-                               if (!p_ptr->resist_chaos && one_in_(3))
-                               {
-                                       (void)set_image(p_ptr->image + rand_int(250) + 150);
-                               }
-
-                               p_ptr->csp -= 50;
-                               if (p_ptr->csp < 0)
-                               {
-                                       p_ptr->csp = 0;
-                                       p_ptr->csp_frac = 0;
-                               }
-                               p_ptr->redraw |= PR_MANA;
-
-                               take_hit(DAMAGE_ATTACK, dam, ddesc, MS_MIND_BLAST);
-                       }
+                       breath(y, x, m_idx, GF_MIND_BLAST, dam, 0, FALSE, MS_MIND_BLAST, learnable);
                        break;
                }
 
                /* RF5_BRAIN_SMASH */
                case 128+11:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
                        if (!seen)
                        {
@@ -2671,64 +2629,14 @@ msg_format("%^s
                        }
 
                        dam = damroll(12, 12);
-                       if (rand_int(100 + rlev/2) < (MAX(5, p_ptr->skill_sav)))
-                       {
-#ifdef JP
-msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
-#else
-                               msg_print("You resist the effects!");
-#endif
-                               learn_spell(MS_BRAIN_SMASH);
-                       }
-                       else
-                       {
-#ifdef JP
-msg_print("ÎîŪ¥¨¥Í¥ë¥®¡¼¤ÇÀº¿À¤¬¹¶·â¤µ¤ì¤¿¡£");
-#else
-                               msg_print("Your mind is blasted by psionic energy.");
-#endif
-
-                               p_ptr->csp -= 100;
-                               if (p_ptr->csp < 0)
-                               {
-                                       p_ptr->csp = 0;
-                                       p_ptr->csp_frac = 0;
-                               }
-                               p_ptr->redraw |= PR_MANA;
-
-                               take_hit(DAMAGE_ATTACK, dam, ddesc, MS_BRAIN_SMASH);
-                               if (!p_ptr->resist_blind)
-                               {
-                                       (void)set_blind(p_ptr->blind + 8 + rand_int(8));
-                               }
-                               if (!p_ptr->resist_conf)
-                               {
-                                       (void)set_confused(p_ptr->confused + rand_int(4) + 4);
-                               }
-                               if (!p_ptr->free_act)
-                               {
-                                       (void)set_paralyzed(p_ptr->paralyzed + rand_int(4) + 4);
-                               }
-                               (void)set_slow(p_ptr->slow + rand_int(4) + 4, FALSE);
-
-                               while (rand_int(100 + rlev/2) > (MAX(5, p_ptr->skill_sav)))
-                                       (void)do_dec_stat(A_INT);
-                               while (rand_int(100 + rlev/2) > (MAX(5, p_ptr->skill_sav)))
-                                       (void)do_dec_stat(A_WIS);
-
-                               if (!p_ptr->resist_chaos)
-                               {
-                                       (void)set_image(p_ptr->image + rand_int(250) + 150);
-                               }
-                       }
+                       breath(y, x, m_idx, GF_BRAIN_SMASH, dam, 0, FALSE, MS_BRAIN_SMASH, learnable);
                        break;
                }
 
                /* RF5_CAUSE_1 */
                case 128+12:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -2743,28 +2651,14 @@ else msg_format("%^s
 #endif
 
                        dam = damroll(3, 8);
-                       if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
-                       {
-#ifdef JP
-msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
-#else
-                               msg_print("You resist the effects!");
-#endif
-                               learn_spell(MS_CAUSE_1);
-                       }
-                       else
-                       {
-                               curse_equipment(33, 0);
-                               take_hit(DAMAGE_ATTACK, dam, ddesc, MS_CAUSE_1);
-                       }
+                       breath(y, x, m_idx, GF_CAUSE_1, dam, 0, FALSE, MS_CAUSE_1, learnable);
                        break;
                }
 
                /* RF5_CAUSE_2 */
                case 128+13:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -2779,28 +2673,14 @@ else msg_format("%^s
 #endif
 
                        dam = damroll(8, 8);
-                       if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
-                       {
-#ifdef JP
-msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
-#else
-                               msg_print("You resist the effects!");
-#endif
-                               learn_spell(MS_CAUSE_2);
-                       }
-                       else
-                       {
-                               curse_equipment(50, 5);
-                               take_hit(DAMAGE_ATTACK, dam, ddesc, MS_CAUSE_2);
-                       }
+                       breath(y, x, m_idx, GF_CAUSE_2, dam, 0, FALSE, MS_CAUSE_2, learnable);
                        break;
                }
 
                /* RF5_CAUSE_3 */
                case 128+14:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤òÂçÀ¼¤Ç¶«¤ó¤À¡£", m_name);
@@ -2815,28 +2695,14 @@ else msg_format("%^s
 #endif
 
                        dam = damroll(10, 15);
-                       if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
-                       {
-#ifdef JP
-msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
-#else
-                               msg_print("You resist the effects!");
-#endif
-                               learn_spell(MS_CAUSE_3);
-                       }
-                       else
-                       {
-                               curse_equipment(80, 15);
-                               take_hit(DAMAGE_ATTACK, dam, ddesc, MS_CAUSE_3);
-                       }
+                       breath(y, x, m_idx, GF_CAUSE_3, dam, 0, FALSE, MS_CAUSE_3, learnable);
                        break;
                }
 
                /* RF5_CAUSE_4 */
                case 128+15:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬¡Ö¤ªÁ°¤Ï´û¤Ë»à¤ó¤Ç¤¤¤ë¡×¤È¶«¤ó¤À¡£", m_name);
@@ -2851,27 +2717,14 @@ else msg_format("%^s
 #endif
 
                        dam = damroll(15, 15);
-                       if ((rand_int(100 + rlev/2) < p_ptr->skill_sav) && !(m_ptr->r_idx == MON_KENSHIROU))
-                       {
-#ifdef JP
-msg_print("¤·¤«¤·È빦¤òÄ·¤ÍÊÖ¤·¤¿¡ª");
-#else
-                               msg_print("You resist the effects!");
-#endif
-                               learn_spell(MS_CAUSE_4);
-                       }
-                       else
-                       {
-                               take_hit(DAMAGE_ATTACK, dam, ddesc, MS_CAUSE_4);
-                               (void)set_cut(p_ptr->cut + damroll(10, 10));
-                       }
+                       breath(y, x, m_idx, GF_CAUSE_4, dam, 0, FALSE, MS_CAUSE_4, learnable);
                        break;
                }
 
                /* RF5_BO_ACID */
                case 128+16:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -2895,7 +2748,7 @@ else msg_format("%^s
                /* RF5_BO_ELEC */
                case 128+17:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -2919,7 +2772,7 @@ else msg_format("%^s
                /* RF5_BO_FIRE */
                case 128+18:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -2943,7 +2796,7 @@ else msg_format("%^s
                /* RF5_BO_COLD */
                case 128+19:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -2989,7 +2842,7 @@ else msg_format("%^s
                /* RF5_BO_NETH */
                case 128+21:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3013,7 +2866,7 @@ else msg_format("%^s
                /* RF5_BO_WATE */
                case 128+22:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3036,7 +2889,7 @@ else msg_format("%^s
                /* RF5_BO_MANA */
                case 128+23:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3050,7 +2903,7 @@ else msg_format("%^s
                        else msg_format("%^s casts a mana bolt.", m_name);
 #endif
 
-                       dam = randint(rlev * 7 / 2) + 50;
+                       dam = randint1(rlev * 7 / 2) + 50;
                        bolt(m_idx, GF_MANA, dam, MS_BOLT_MANA, learnable);
                        update_smart_learn(m_idx, DRS_REFLECT);
                        break;
@@ -3059,7 +2912,7 @@ else msg_format("%^s
                /* RF5_BO_PLAS */
                case 128+24:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3082,7 +2935,7 @@ else msg_format("%^s
                /* RF5_BO_ICEE */
                case 128+25:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3106,7 +2959,7 @@ else msg_format("%^s
                /* RF5_MISSILE */
                case 128+26:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3129,8 +2982,7 @@ else msg_format("%^s
                /* RF5_SCARE */
                case 128+27:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¯¤È¡¢¶²¤í¤·¤²¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£", m_name);
@@ -3153,7 +3005,7 @@ msg_print("
 #endif
 
                        }
-                       else if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
+                       else if (randint0(100 + rlev/2) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_print("¤·¤«¤·¶²Éݤ˿¯¤µ¤ì¤Ê¤«¤Ã¤¿¡£");
@@ -3164,7 +3016,7 @@ msg_print("
                        }
                        else
                        {
-                               (void)set_afraid(p_ptr->afraid + rand_int(4) + 4);
+                               (void)set_afraid(p_ptr->afraid + randint0(4) + 4);
                        }
                        learn_spell(MS_SCARE);
                        update_smart_learn(m_idx, DRS_FEAR);
@@ -3174,8 +3026,7 @@ msg_print("
                /* RF5_BLIND */
                case 128+28:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3198,7 +3049,7 @@ msg_print("
 #endif
 
                        }
-                       else if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
+                       else if (randint0(100 + rlev/2) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
@@ -3209,7 +3060,7 @@ msg_print("
                        }
                        else
                        {
-                               (void)set_blind(12 + rand_int(4));
+                               (void)set_blind(12 + randint0(4));
                        }
                        learn_spell(MS_BLIND);
                        update_smart_learn(m_idx, DRS_BLIND);
@@ -3219,8 +3070,7 @@ msg_print("
                /* RF5_CONF */
                case 128+29:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¯¤È¡¢Æ¬¤òǺ¤Þ¤¹²»¤¬¤·¤¿¡£", m_name);
@@ -3243,7 +3093,7 @@ msg_print("
 #endif
 
                        }
-                       else if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
+                       else if (randint0(100 + rlev/2) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_print("¤·¤«¤·¸¸³Ð¤Ë¤Ï¤À¤Þ¤µ¤ì¤Ê¤«¤Ã¤¿¡£");
@@ -3254,7 +3104,7 @@ msg_print("
                        }
                        else
                        {
-                               (void)set_confused(p_ptr->confused + rand_int(4) + 4);
+                               (void)set_confused(p_ptr->confused + randint0(4) + 4);
                        }
                        learn_spell(MS_CONF);
                        update_smart_learn(m_idx, DRS_CONF);
@@ -3264,8 +3114,7 @@ msg_print("
                /* RF5_SLOW */
                case 128+30:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 msg_format("%^s¤¬¤¢¤Ê¤¿¤Î¶ÚÎϤòµÛ¤¤¼è¤í¤¦¤È¤·¤¿¡ª", m_name);
@@ -3282,7 +3131,7 @@ msg_print("
 #endif
 
                        }
-                       else if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
+                       else if (randint0(100 + rlev/2) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
@@ -3293,7 +3142,7 @@ msg_print("
                        }
                        else
                        {
-                               (void)set_slow(p_ptr->slow + rand_int(4) + 4, FALSE);
+                               (void)set_slow(p_ptr->slow + randint0(4) + 4, FALSE);
                        }
                        learn_spell(MS_SLOW);
                        update_smart_learn(m_idx, DRS_FREE);
@@ -3303,8 +3152,7 @@ msg_print("
                /* RF5_HOLD */
                case 128+31:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3327,7 +3175,7 @@ msg_print("
 #endif
 
                        }
-                       else if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
+                       else if (randint0(100 + rlev/2) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_format("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
@@ -3338,7 +3186,7 @@ msg_format("
                        }
                        else
                        {
-                               (void)set_paralyzed(p_ptr->paralyzed + rand_int(4) + 4);
+                               (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
                        }
                        learn_spell(MS_SLEEP);
                        update_smart_learn(m_idx, DRS_FREE);
@@ -3361,7 +3209,7 @@ msg_format("%^s
                        else
                        {
 #ifdef JP
-msg_format("%^s¤¬¼«Ê¬¤ÎÂΤËÇ°¤òÁ÷¤Ã¤¿¡£", m_name, m_poss);
+msg_format("%^s¤¬¼«Ê¬¤ÎÂΤËÇ°¤òÁ÷¤Ã¤¿¡£", m_name);
 #else
                                msg_format("%^s concentrates on %s body.", m_name, m_poss);
 #endif
@@ -3369,54 +3217,29 @@ msg_format("%^s
                        }
 
                        /* Allow quick speed increases to base+10 */
-                       if (!m_ptr->fast)
+                       if (set_monster_fast(m_idx, MON_FAST(m_ptr) + 100))
                        {
 #ifdef JP
-msg_format("%^s¤ÎÆ°¤­¤¬Â®¤¯¤Ê¤Ã¤¿¡£", m_name);
+                               msg_format("%^s¤ÎÆ°¤­¤¬Â®¤¯¤Ê¤Ã¤¿¡£", m_name);
 #else
                                msg_format("%^s starts moving faster.", m_name);
 #endif
                        }
-                       m_ptr->fast = MIN(200, m_ptr->fast + 100);
-                       if (p_ptr->riding == m_idx) p_ptr->update |= PU_BONUS;
                        break;
                }
 
                /* RF6_HAND_DOOM */
                case 160+1:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
-msg_format("%^s¤¬ÇËÌǤμê¤òÊü¤Ã¤¿¡ª", m_name);
+msg_format("%^s¤¬<ÇËÌǤμê>¤òÊü¤Ã¤¿¡ª", m_name);
 #else
                        msg_format("%^s invokes the Hand of Doom!", m_name);
 #endif
-
-                       if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
-                       {
-#ifdef JP
-msg_format("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
-#else
-                               msg_format("You resist the effects!");
-#endif
-                               learn_spell(MS_HAND_DOOM);
-
-                       }
-                       else
-                       {
-                               int dummy = (((s32b) ((40 + randint(20)) * (p_ptr->chp))) / 100);
-#ifdef JP
-msg_print("¤¢¤Ê¤¿¤ÏÌ¿¤¬Çö¤Þ¤Ã¤Æ¤¤¤¯¤è¤¦¤Ë´¶¤¸¤¿¡ª");
-#else
-                               msg_print("Your feel your life fade away!");
-#endif
-
-                               take_hit(DAMAGE_ATTACK, dummy, m_name, MS_HAND_DOOM);
-                               curse_equipment(100, 20);
-
-                               if (p_ptr->chp < 1) p_ptr->chp = 1;
-                       }
+                       dam = (((s32b) ((40 + randint1(20)) * (p_ptr->chp))) / 100);
+                       breath(y, x, m_idx, GF_HAND_DOOM, dam, 0, FALSE, MS_HAND_DOOM, learnable);
                        break;
                }
 
@@ -3504,18 +3327,17 @@ msg_format("%^s
                        if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
 
                        /* Cancel fear */
-                       if (m_ptr->monfear)
+                       if (MON_MONFEAR(m_ptr))
                        {
                                /* Cancel fear */
-                               m_ptr->monfear = 0;
+                               (void)set_monster_monfear(m_idx, 0);
 
                                /* Message */
 #ifdef JP
-msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name, m_poss);
+                               msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
 #else
                                msg_format("%^s recovers %s courage.", m_name, m_poss);
 #endif
-
                        }
                        break;
                }
@@ -3545,11 +3367,7 @@ msg_format("%s
 
                        }
 
-                       if (!(m_ptr->invulner))
-                               m_ptr->invulner = randint(4) + 4;
-
-                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
-                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
+                       if (!MON_INVULNER(m_ptr)) (void)set_monster_invulner(m_idx, randint1(4) + 4, FALSE);
                        break;
                }
 
@@ -3557,69 +3375,47 @@ msg_format("%s
                case 160+4:
                {
                        disturb(1, 0);
+                       if (teleport_barrier(m_idx))
+                       {
 #ifdef JP
-msg_format("%^s¤¬½Ö»þ¤Ë¾Ã¤¨¤¿¡£", m_name);
+                               msg_format("ËâË¡¤Î¥Ð¥ê¥¢¤¬%^s¤Î¥Æ¥ì¥Ý¡¼¥È¤ò¼ÙË⤷¤¿¡£", m_name);
 #else
-                       msg_format("%^s blinks away.", m_name);
+                               msg_format("Magic barrier obstructs teleporting of %^s.", m_name);
 #endif
-
-                       teleport_away(m_idx, 10, FALSE);
-                       p_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
+                       }
+                       else
+                       {
+#ifdef JP
+                               msg_format("%^s¤¬½Ö»þ¤Ë¾Ã¤¨¤¿¡£", m_name);
+#else
+                               msg_format("%^s blinks away.", m_name);
+#endif
+                               teleport_away(m_idx, 10, 0L);
+                               p_ptr->update |= (PU_MONSTERS);
+                       }
                        break;
                }
 
                /* RF6_TPORT */
                case 160+5:
                {
-                       int i, oldfy, oldfx;
-                       u32b f1 = 0 , f2 = 0 , f3 = 0;
-                       object_type *o_ptr;
-
-                       oldfy = m_ptr->fy;
-                       oldfx = m_ptr->fx;
-
                        disturb(1, 0);
-#ifdef JP
-msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¤·¤¿¡£", m_name);
-#else
-                       msg_format("%^s teleports away.", m_name);
-#endif
-
-                       teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
-
-                       if (los(py, px, oldfy, oldfx) && !world_monster)
+                       if (teleport_barrier(m_idx))
                        {
-                               for (i=INVEN_RARM;i<INVEN_TOTAL;i++)
-                               {
-                                       o_ptr = &inventory[i];
-                                       if(!(o_ptr->ident & IDENT_CURSED))
-                                       {
-                                               object_flags(o_ptr, &f1, &f2, &f3);
-
-                                               if((f3 & TR3_TELEPORT) || (p_ptr->muta1 & MUT1_VTELEPORT) || (p_ptr->pclass == CLASS_IMITATOR))
-                                               {
 #ifdef JP
-                                                       if(get_check_strict("¤Ä¤¤¤Æ¤¤¤­¤Þ¤¹¤«¡©", 1))
+                               msg_format("ËâË¡¤Î¥Ð¥ê¥¢¤¬%^s¤Î¥Æ¥ì¥Ý¡¼¥È¤ò¼ÙË⤷¤¿¡£", m_name);
 #else
-                                                       if(get_check_strict("Do you follow it? ", 1))
+                               msg_format("Magic barrier obstructs teleporting of %^s.", m_name);
 #endif
-                                                       {
-                                                               if (randint(3) == 1)
-                                                               {
-                                                                       teleport_player(200);
+                       }
+                       else
+                       {
 #ifdef JP
-                                                                       msg_print("¼ºÇÔ¡ª");
+                               msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¤·¤¿¡£", m_name);
 #else
-                                                                       msg_print("Failed!");
+                               msg_format("%^s teleports away.", m_name);
 #endif
-                                                               }
-                                                               else teleport_player_to(m_ptr->fy, m_ptr->fx, TRUE);
-                                                               p_ptr->energy -= 100;
-                                                       }
-                                                       break;
-                                               }
-                                       }
-                               }
+                               teleport_away_followable(m_idx);
                        }
                        break;
                }
@@ -3632,7 +3428,7 @@ msg_format("%^s
                        if(m_ptr->r_idx == MON_DIO) who = 1;
                        else if(m_ptr->r_idx == MON_WONG) who = 3;
                        dam = who;
-                       if (!process_the_world(randint(2)+2, who, TRUE)) return (FALSE);
+                       if (!process_the_world(randint1(2)+2, who, TRUE)) return (FALSE);
                        break;
                }
 
@@ -3642,16 +3438,12 @@ msg_format("%^s
                        int k;
 
                        disturb(1, 0);
-                       switch(m_ptr->r_idx)
+                       switch (m_ptr->r_idx)
                        {
                        case MON_OHMU:
-                               if (p_ptr->inside_arena || p_ptr->inside_battle) return FALSE;
-                               for (k = 0; k < 6; k++)
-                               {
-                                       count += summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_BIZARRE1, TRUE, FALSE, FALSE, FALSE, FALSE);
-                               }
+                               /* Moved to process_monster(), like multiplication */
                                return FALSE;
-                               
+
                        case MON_BANORLUPART:
                                {
                                        int dummy_hp = (m_ptr->hp + 1) / 2;
@@ -3661,10 +3453,10 @@ msg_format("%^s
 
                                        if (p_ptr->inside_arena || p_ptr->inside_battle || !summon_possible(m_ptr->fy, m_ptr->fx)) return FALSE;
                                        delete_monster_idx(cave[m_ptr->fy][m_ptr->fx].m_idx);
-                                       summon_named_creature(dummy_y, dummy_x, MON_BANOR, FALSE, FALSE, is_friendly(m_ptr), FALSE);
+                                       summon_named_creature(0, dummy_y, dummy_x, MON_BANOR, mode);
                                        m_list[hack_m_idx_ii].hp = dummy_hp;
                                        m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
-                                       summon_named_creature(dummy_y, dummy_x, MON_LUPART, FALSE, FALSE, is_friendly(m_ptr), FALSE);
+                                       summon_named_creature(0, dummy_y, dummy_x, MON_LUPART, mode);
                                        m_list[hack_m_idx_ii].hp = dummy_hp;
                                        m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
 
@@ -3676,8 +3468,9 @@ msg_format("%^s
 
                                        break;
                                }
-                               case MON_BANOR:
-                               case MON_LUPART:
+
+                       case MON_BANOR:
+                       case MON_LUPART:
                                {
                                        int dummy_hp = 0;
                                        int dummy_maxhp = 0;
@@ -3699,7 +3492,7 @@ msg_format("%^s
                                                        delete_monster_idx(k);
                                                }
                                        }
-                                       summon_named_creature(dummy_y, dummy_x, MON_BANORLUPART, FALSE, FALSE, is_friendly(m_ptr), FALSE);
+                                       summon_named_creature(0, dummy_y, dummy_x, MON_BANORLUPART, mode);
                                        m_list[hack_m_idx_ii].hp = dummy_hp;
                                        m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
 
@@ -3711,7 +3504,105 @@ msg_format("%^s
 
                                        break;
                                }
-                               default: return FALSE;
+
+                       case MON_ROLENTO:
+#ifdef JP
+                               if (blind) msg_format("%^s¤¬²¿¤«ÂçÎ̤ËÅꤲ¤¿¡£", m_name);
+                               else msg_format("%^s¤Ï¼êÜØÃƤò¤Ð¤é¤Þ¤¤¤¿¡£", m_name);
+#else
+                               if (blind) msg_format("%^s spreads something.", m_name);
+                               else msg_format("%^s throws some hand grenades.", m_name);
+#endif
+
+                               {
+                                       int num = 1 + randint1(3);
+
+                                       for (k = 0; k < num; k++)
+                                       {
+                                               count += summon_named_creature(m_idx, y, x, MON_SHURYUUDAN, mode);
+                                       }
+                               }
+#ifdef JP
+                               if (blind && count) msg_print("¿¤¯¤Î¤â¤Î¤¬´Ö¶á¤Ë¤Ð¤é¤Þ¤«¤ì¤ë²»¤¬¤¹¤ë¡£");
+#else
+                               if (blind && count) msg_print("You hear many things are scattered nearby.");
+#endif
+                               break;
+
+                       default:
+                               if (r_ptr->d_char == 'B')
+                               {
+                                       disturb(1, 0);
+                                       if (one_in_(3) || !direct)
+                                       {
+#ifdef JP
+                                               msg_format("%^s¤ÏÆÍÁ³»ë³¦¤«¤é¾Ã¤¨¤¿!", m_name);
+#else
+                                               msg_format("%^s suddenly go out of your sight!", m_name);
+#endif
+                                               teleport_away(m_idx, 10, TELEPORT_NONMAGICAL);
+                                               p_ptr->update |= (PU_MONSTERS);
+                                       }
+                                       else
+                                       {
+                                               int get_damage = 0;
+                                               bool fear; /* dummy */
+
+#ifdef JP
+                                               msg_format("%^s¤¬¤¢¤Ê¤¿¤òÄϤó¤Ç¶õÃ椫¤éÅꤲÍî¤È¤·¤¿¡£", m_name);
+#else
+                                               msg_format("%^s holds you, and drops from the sky.", m_name);
+#endif
+                                               dam = damroll(4, 8);
+                                               teleport_player_to(m_ptr->fy, m_ptr->fx, TELEPORT_NONMAGICAL | TELEPORT_PASSIVE);
+
+                                               sound(SOUND_FALL);
+
+                                               if (p_ptr->levitation)
+                                               {
+#ifdef JP
+                                                       msg_print("¤¢¤Ê¤¿¤ÏÀŤ«¤ËÃåÃϤ·¤¿¡£");
+#else
+                                                       msg_print("You float gently down to the ground.");
+#endif
+                                               }
+                                               else
+                                               {
+#ifdef JP
+                                                       msg_print("¤¢¤Ê¤¿¤ÏÃÏÌ̤Ë᤭¤Ä¤±¤é¤ì¤¿¡£");
+#else
+                                                       msg_print("You crashed into the ground.");
+#endif
+                                                       dam += damroll(6, 8);
+                                               }
+
+                                               /* Mega hack -- this special action deals damage to the player. Therefore the code of "eyeeye" is necessary.
+                                                  -- henkma
+                                                */
+                                               get_damage = take_hit(DAMAGE_NOESCAPE, dam, m_name, -1);
+                                               if (p_ptr->tim_eyeeye && get_damage > 0 && !p_ptr->is_dead)
+                                               {
+#ifdef JP
+                                                       msg_format("¹¶·â¤¬%s¼«¿È¤ò½ý¤Ä¤±¤¿¡ª", m_name);
+#else
+                                                       char m_name_self[80];
+
+                                                       /* hisself */
+                                                       monster_desc(m_name_self, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE);
+
+                                                       msg_format("The attack of %s has wounded %s!", m_name, m_name_self);
+#endif
+                                                       project(0, 0, m_ptr->fy, m_ptr->fx, get_damage, GF_MISSILE, PROJECT_KILL, -1);
+                                                       set_tim_eyeeye(p_ptr->tim_eyeeye-5, TRUE);
+                                               }
+
+                                               if (p_ptr->riding) mon_take_hit_mon(p_ptr->riding, dam, &fear, extract_note_dies(real_r_ptr(&m_list[p_ptr->riding])), m_idx);
+                                       }
+                                       break;
+                               }
+
+                               /* Something is wrong */
+                               else return FALSE;
                        }
                        break;
                }
@@ -3719,8 +3610,7 @@ msg_format("%^s
                /* RF6_TELE_TO */
                case 160+8:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 msg_format("%^s¤¬¤¢¤Ê¤¿¤ò°ú¤­Ìᤷ¤¿¡£", m_name);
@@ -3728,7 +3618,7 @@ msg_format("%^s
                        msg_format("%^s commands you to return.", m_name);
 #endif
 
-                       teleport_player_to(m_ptr->fy, m_ptr->fx, TRUE);
+                       teleport_player_to(m_ptr->fy, m_ptr->fx, TELEPORT_PASSIVE);
                        learn_spell(MS_TELE_TO);
                        break;
                }
@@ -3736,8 +3626,7 @@ msg_format("%^s
                /* RF6_TELE_AWAY */
                case 160+9:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 msg_format("%^s¤Ë¥Æ¥ì¥Ý¡¼¥È¤µ¤»¤é¤ì¤¿¡£", m_name);
@@ -3748,15 +3637,14 @@ msg_format("%^s
 #endif
 
                        learn_spell(MS_TELE_AWAY);
-                       teleport_player(100);
+                       teleport_player_away(m_idx, 100);
                        break;
                }
 
                /* RF6_TELE_LEVEL */
                case 160+10:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«´ñ̯¤Ê¸ÀÍÕ¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3779,7 +3667,7 @@ msg_print("
 #endif
 
                        }
-                       else if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
+                       else if (randint0(100 + rlev/2) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
@@ -3790,7 +3678,7 @@ msg_print("
                        }
                        else
                        {
-                               teleport_player_level();
+                               teleport_level(0);
                        }
                        learn_spell(MS_TELE_LEVEL);
                        update_smart_learn(m_idx, DRS_NEXUS);
@@ -3800,7 +3688,7 @@ msg_print("
                /* RF6_PSY_SPEAR */
                case 160+11:
                {
-                       if (x!=px || y!=py) return (FALSE);
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -3814,7 +3702,7 @@ else msg_format("%^s
                        else msg_format("%^s throw a Psycho-Spear.", m_name);
 #endif
 
-                       dam = (r_ptr->flags2 & RF2_POWERFUL) ? (randint(rlev * 2) + 150) : (randint(rlev * 3 / 2) + 100);
+                       dam = (r_ptr->flags2 & RF2_POWERFUL) ? (randint1(rlev * 2) + 150) : (randint1(rlev * 3 / 2) + 100);
                        beam(m_idx, GF_PSY_SPEAR, dam, MS_PSY_SPEAR, learnable);
                        break;
                }
@@ -3822,36 +3710,34 @@ else msg_format("%^s
                /* RF6_DARKNESS */
                case 160+12:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
-if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
+                       if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
 #else
                        if (blind) msg_format("%^s mumbles.", m_name);
 #endif
 
 #ifdef JP
-else if (p_ptr->pclass == CLASS_NINJA) msg_format("%^s¤¬ÊÕ¤ê¤òÌÀ¤ë¤¯¾È¤é¤·¤¿¡£", m_name);
-else msg_format("%^s¤¬°Å°Ç¤ÎÃæ¤Ç¼ê¤ò¿¶¤Ã¤¿¡£", m_name);
+                       else if (can_use_lite_area) msg_format("%^s¤¬ÊÕ¤ê¤òÌÀ¤ë¤¯¾È¤é¤·¤¿¡£", m_name);
+                       else msg_format("%^s¤¬°Å°Ç¤ÎÃæ¤Ç¼ê¤ò¿¶¤Ã¤¿¡£", m_name);
 #else
-                       else if (p_ptr->pclass == CLASS_NINJA)
-                               msg_format("%^s cast a spell to light up.", m_name);
+                       else if (can_use_lite_area) msg_format("%^s cast a spell to light up.", m_name);
                        else msg_format("%^s gestures in shadow.", m_name);
 #endif
 
-                       learn_spell(MS_DARKNESS);
-                       if (p_ptr->pclass == CLASS_NINJA)
-                               (void)lite_area(0, 3);
+                       if (can_use_lite_area) (void)lite_area(0, 3);
                        else
+                       {
+                               learn_spell(MS_DARKNESS);
                                (void)unlite_area(0, 3);
+                       }
                        break;
                }
 
                /* RF6_TRAPS */
                case 160+13:
                {
-                       if (!direct) break;
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤Æ¼Ù°­¤ËÈù¾Ð¤ó¤À¡£", m_name);
@@ -3873,8 +3759,7 @@ else msg_format("%^s
                /* RF6_FORGET */
                case 160+14:
                {
-                       if (x!=px || y!=py) return (FALSE);
-                       if (!direct) break;
+                       if (!direct) return (FALSE);
                        disturb(1, 0);
 #ifdef JP
 msg_format("%^s¤¬¤¢¤Ê¤¿¤Îµ­²±¤ò¾Ãµî¤·¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
@@ -3883,7 +3768,7 @@ msg_format("%^s
 #endif
 
 
-                       if (rand_int(100 + rlev/2) < p_ptr->skill_sav)
+                       if (randint0(100 + rlev/2) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
@@ -3924,25 +3809,11 @@ else msg_format("%^s
                        break;
                }
 
-               /* RF6_SUMMON_KIN */
+               /* RF6_S_KIN */
                case 160+16:
                {
                        disturb(1, 0);
-                       if (m_ptr->r_idx == MON_ROLENTO)
-                       {
-#ifdef JP
-                               if (blind)
-                                       msg_format("%^s¤¬²¿¤«ÂçÎ̤ËÅꤲ¤¿¡£", m_name);
-                               else 
-                                       msg_format("%^s¤Ï¼êÜØÃƤò¤Ð¤é¤Þ¤¤¤¿¡£", m_name);
-#else
-                               if (blind)
-                                       msg_format("%^s spreads something.", m_name);
-                               else
-                                       msg_format("%^s throws some hand grenades.", m_name);
-#endif
-                       }
-                       else if (m_ptr->r_idx == MON_SERPENT)
+                       if (m_ptr->r_idx == MON_SERPENT || m_ptr->r_idx == MON_ZOMBI_SERPENT)
                        {
 #ifdef JP
                                if (blind)
@@ -3977,74 +3848,87 @@ else msg_format("%^s
 #endif
                        }
 
-                       if(m_ptr->r_idx == MON_ROLENTO)
+                       switch (m_ptr->r_idx)
                        {
-                               int num = 1 + randint(3);
-                               for (k = 0; k < num; k++)
+                       case MON_MENELDOR:
+                       case MON_GWAIHIR:
+                       case MON_THORONDOR:
                                {
-                                       count += summon_named_creature(y, x, MON_SHURYUUDAN, FALSE, FALSE, is_friendly(m_ptr), is_pet(m_ptr));
-                               }
-                       }
-                       else if(m_ptr->r_idx == MON_LOUSY)
-                       {
-                               int num = 2 + randint(3);
-                               for (k = 0; k < num; k++)
-                               {
-                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_LOUSE, TRUE, FALSE, FALSE, FALSE, FALSE);
-                               }
-                       }
-                       else if(m_ptr->r_idx == MON_BULLGATES)
-                       {
-                               int num = 2 + randint(3);
-                               for (k = 0; k < num; k++)
-                               {
-                                       count += summon_named_creature(y, x, 921, FALSE, FALSE, is_friendly(m_ptr), is_pet(m_ptr));
+                                       int num = 4 + randint1(3);
+                                       for (k = 0; k < num; k++)
+                                       {
+                                               count += summon_specific(m_idx, y, x, rlev, SUMMON_EAGLES, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
+                                       }
                                }
-                       }
-                       else if (m_ptr->r_idx == MON_CALDARM)
-                       {
-                               int num = randint(3);
-                               for (k = 0; k < num; k++)
+                               break;
+
+                       case MON_BULLGATES:
                                {
-                                       count += summon_named_creature(y, x, 930, FALSE, FALSE, is_friendly(m_ptr), is_pet(m_ptr));
+                                       int num = 2 + randint1(3);
+                                       for (k = 0; k < num; k++)
+                                       {
+                                               count += summon_named_creature(m_idx, y, x, MON_IE, mode);
+                                       }
                                }
-                       }
-                       else if (m_ptr->r_idx == MON_SERPENT)
-                       {
-                               int num = 2 + randint(3);
+                               break;
 
-                               if (r_info[MON_JORMUNGAND].cur_num < r_info[MON_JORMUNGAND].max_num && one_in_(6))
+                       case MON_SERPENT:
+                       case MON_ZOMBI_SERPENT:
                                {
+                                       int num = 2 + randint1(3);
+
+                                       if (r_info[MON_JORMUNGAND].cur_num < r_info[MON_JORMUNGAND].max_num && one_in_(6))
+                                       {
 #ifdef JP
-                                       msg_print("ÃÏÌ̤«¤é¿å¤¬¿á¤­½Ð¤·¤¿¡ª");
+                                               msg_print("ÃÏÌ̤«¤é¿å¤¬¿á¤­½Ð¤·¤¿¡ª");
 #else
-                                       msg_print("Water blew off from the ground!");
+                                               msg_print("Water blew off from the ground!");
 #endif
-                                       fire_ball_hide(GF_WATER_FLOW, 0, 3, 8);
+                                               fire_ball_hide(GF_WATER_FLOW, 0, 3, 8);
+                                       }
+
+                                       for (k = 0; k < num; k++)
+                                       {
+                                               count += summon_specific(m_idx, y, x, rlev, SUMMON_GUARDIANS, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
+                                       }
                                }
+                               break;
 
-                               for (k = 0; k < num; k++)
+                       case MON_CALDARM:
                                {
-                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_GUARDIANS, TRUE, FALSE, FALSE, TRUE, FALSE);
+                                       int num = randint1(3);
+                                       for (k = 0; k < num; k++)
+                                       {
+                                               count += summon_named_creature(m_idx, y, x, MON_LOCKE_CLONE, mode);
+                                       }
                                }
-                       }
-                       else
-                       {
+                               break;
+
+                       case MON_LOUSY:
+                               {
+                                       int num = 2 + randint1(3);
+                                       for (k = 0; k < num; k++)
+                                       {
+                                               count += summon_specific(m_idx, y, x, rlev, SUMMON_LOUSE, PM_ALLOW_GROUP);
+                                       }
+                               }
+                               break;
 
+                       default:
                                summon_kin_type = r_ptr->d_char; /* Big hack */
 
                                for (k = 0; k < 4; k++)
                                {
-                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_KIN, TRUE, FALSE, FALSE, FALSE, FALSE);
+                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_KIN, PM_ALLOW_GROUP);
                                }
+                               break;
                        }
 #ifdef JP
-if (blind && count) msg_print("¿¤¯¤Î¤â¤Î¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
+                       if (blind && count) msg_print("¿¤¯¤Î¤â¤Î¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
 #else
                        if (blind && count) msg_print("You hear many things appear nearby.");
 #endif
 
-
                        break;
                }
 
@@ -4092,7 +3976,7 @@ else msg_format("%^s
 
                        for (k = 0; k < 1; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, 0, TRUE, FALSE, FALSE, TRUE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
                        }
 #ifdef JP
 if (blind && count) msg_print("²¿¤«¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4121,7 +4005,7 @@ else msg_format("%^s
 
                        for (k = 0; k < s_num_6; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, 0, TRUE, FALSE, FALSE, TRUE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
                        }
 #ifdef JP
 if (blind && count) msg_print("¿¤¯¤Î¤â¤Î¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4150,7 +4034,7 @@ else msg_format("%^s
 
                        for (k = 0; k < s_num_6; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_ANT, TRUE, FALSE, FALSE, FALSE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_ANT, PM_ALLOW_GROUP);
                        }
 #ifdef JP
 if (blind && count) msg_print("¿¤¯¤Î¤â¤Î¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4179,7 +4063,7 @@ else msg_format("%^s
 
                        for (k = 0; k < s_num_6; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_SPIDER, TRUE, FALSE, FALSE, FALSE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_SPIDER, PM_ALLOW_GROUP);
                        }
 #ifdef JP
 if (blind && count) msg_print("¿¤¯¤Î¤â¤Î¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4208,7 +4092,7 @@ else msg_format("%^s
 
                        for (k = 0; k < s_num_4; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_HOUND, TRUE, FALSE, FALSE, FALSE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_HOUND, PM_ALLOW_GROUP);
                        }
 #ifdef JP
 if (blind && count) msg_print("¿¤¯¤Î¤â¤Î¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4237,7 +4121,7 @@ else msg_format("%^s
 
                        for (k = 0; k < s_num_4; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_HYDRA, TRUE, FALSE, FALSE, FALSE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_HYDRA, PM_ALLOW_GROUP);
                        }
 #ifdef JP
 if (blind && count) msg_print("¿¤¯¤Î¤â¤Î¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4273,7 +4157,7 @@ else msg_format("%^s
 
                        for (k = 0; k < num; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_ANGEL, TRUE, FALSE, FALSE, FALSE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_ANGEL, PM_ALLOW_GROUP);
                        }
 
                        if (count < 2)
@@ -4314,7 +4198,7 @@ else msg_format("%^s
 
                        for (k = 0; k < 1; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_DEMON, TRUE, FALSE, FALSE, FALSE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_DEMON, PM_ALLOW_GROUP);
                        }
 #ifdef JP
 if (blind && count) msg_print("²¿¤«¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4343,7 +4227,7 @@ else msg_format("%^s
 
                        for (k = 0; k < 1; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_UNDEAD, TRUE, FALSE, FALSE, FALSE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_UNDEAD, PM_ALLOW_GROUP);
                        }
 #ifdef JP
 if (blind && count) msg_print("²¿¤«¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4372,7 +4256,7 @@ else msg_format("%^s
 
                        for (k = 0; k < 1; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_DRAGON, TRUE, FALSE, FALSE, FALSE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_DRAGON, PM_ALLOW_GROUP);
                        }
 #ifdef JP
 if (blind && count) msg_print("²¿¤«¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬¤¹¤ë¡£");
@@ -4408,19 +4292,19 @@ else msg_format("%^s
 
                                for (k = 0; k < 30; k++)
                                {
-                                       if (!summon_possible(cy, cx) || !cave_floor_bold(cy, cx))
+                                       if (!summon_possible(cy, cx) || !cave_empty_bold(cy, cx))
                                        {
                                                int j;
                                                for (j = 100; j > 0; j--)
                                                {
                                                        scatter(&cy, &cx, y, x, 2, 0);
-                                                       if (cave_floor_bold(cy, cx)) break;
+                                                       if (cave_empty_bold(cy, cx)) break;
                                                }
                                                if (!j) break;
                                        }
-                                       if (!cave_floor_bold(cy, cx)) continue;
+                                       if (!cave_empty_bold(cy, cx)) continue;
 
-                                       if (summon_named_creature(cy, cx, MON_NAZGUL, FALSE, FALSE, is_friendly(m_ptr), is_pet(m_ptr)))
+                                       if (summon_named_creature(m_idx, cy, cx, MON_NAZGUL, mode))
                                        {
                                                y = cy;
                                                x = cx;
@@ -4441,7 +4325,7 @@ msg_format("
                                        }
                                }
 #ifdef JP
-msg_format("¡Ö%dɤ¤½¤í¤Ã¤Æ¡¢¥ê¥ó¥°¥ì¥ó¥¸¥ã¡¼¡ª¡×", count);
+msg_format("¡Ö%d¿Í¤½¤í¤Ã¤Æ¡¢¥ê¥ó¥°¥ì¥ó¥¸¥ã¡¼¡ª¡×", count);
 #else
 msg_format("They say 'The %d meets! We are the Ring-Ranger!'.", count);
 #endif
@@ -4463,7 +4347,7 @@ else msg_format("%^s
 
                                for (k = 0; k < s_num_6; k++)
                                {
-                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_UNDEAD, TRUE, FALSE, FALSE, TRUE, FALSE);
+                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_UNDEAD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
                                }
                        }
                        if (blind && count)
@@ -4496,7 +4380,7 @@ else msg_format("%^s
 
                        for (k = 0; k < s_num_4; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_DRAGON, TRUE, FALSE, FALSE, TRUE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_DRAGON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
                        }
                        if (blind && count)
                        {
@@ -4521,7 +4405,7 @@ if (blind) msg_format("%^s
 #endif
 
 #ifdef JP
-else msg_format("%^s¤¬¥¢¥ó¥Ð¡¼¤Î²¦¤ò¾¤´­¤·¤¿¡ª", m_name);
+else msg_format("%^s¤¬¥¢¥ó¥Ð¡¼¤Î²¦²¤ò¾¤´­¤·¤¿¡ª", m_name);
 #else
                        else msg_format("%^s magically summons Lords of Amber!", m_name);
 #endif
@@ -4530,7 +4414,7 @@ else msg_format("%^s
 
                        for (k = 0; k < s_num_4; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_AMBERITES, TRUE, FALSE, FALSE, TRUE, FALSE);
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_AMBERITES, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
                        }
                        if (blind && count)
                        {
@@ -4547,6 +4431,9 @@ msg_print("
                /* RF6_S_UNIQUE */
                case 160+31:
                {
+                       bool uniques_are_summoned = FALSE;
+                       int non_unique_type = SUMMON_HI_UNDEAD;
+
                        disturb(1, 0);
 #ifdef JP
 if (blind) msg_format("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", m_name);
@@ -4562,30 +4449,28 @@ else msg_format("%^s
 
                        for (k = 0; k < s_num_4; k++)
                        {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_UNIQUE, TRUE, FALSE, FALSE, TRUE, FALSE);
-                       }
-                       if (r_ptr->flags3 & RF3_GOOD)
-                       {
-                               for (k = count; k < s_num_4; k++)
-                               {
-                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_ANGEL, TRUE, FALSE, FALSE, TRUE, FALSE);
-                               }
+                               count += summon_specific(m_idx, y, x, rlev, SUMMON_UNIQUE, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
                        }
-                       else
+
+                       if (count) uniques_are_summoned = TRUE;
+
+                       if ((m_ptr->sub_align & (SUB_ALIGN_GOOD | SUB_ALIGN_EVIL)) == (SUB_ALIGN_GOOD | SUB_ALIGN_EVIL))
+                               non_unique_type = 0;
+                       else if (m_ptr->sub_align & SUB_ALIGN_GOOD)
+                               non_unique_type = SUMMON_ANGEL;
+
+                       for (k = count; k < s_num_4; k++)
                        {
-                               for (k = count; k < s_num_4; k++)
-                               {
-                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_UNDEAD, TRUE, FALSE, FALSE, TRUE, FALSE);
-                               }
+                               count += summon_specific(m_idx, y, x, rlev, non_unique_type, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
                        }
+
                        if (blind && count)
                        {
 #ifdef JP
-msg_print("¿¤¯¤ÎÎ϶¯¤¤¤â¤Î¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬Ê¹¤³¤¨¤ë¡£");
+                               msg_format("¿¤¯¤Î%s¤¬´Ö¶á¤Ë¸½¤ì¤¿²»¤¬Ê¹¤³¤¨¤ë¡£", uniques_are_summoned ? "Î϶¯¤¤¤â¤Î" : "¤â¤Î");
 #else
-                               msg_print("You hear many powerful things appear nearby.");
+                               msg_format("You hear many %s appear nearby.", uniques_are_summoned ? "powerful things" : "things");
 #endif
-
                        }
                        break;
                }
@@ -4598,35 +4483,35 @@ msg_print("¿
 
        if (seen && maneable && !world_monster && (p_ptr->pclass == CLASS_IMITATOR))
        {
-               if (thrown_spell != 167)
+               if (thrown_spell != 167) /* Not RF6_SPECIAL */
                {
-                       if (mane_num == MAX_MANE)
+                       if (p_ptr->mane_num == MAX_MANE)
                        {
                                int i;
-                               mane_num--;
-                               for (i = 0;i < mane_num;i++)
+                               p_ptr->mane_num--;
+                               for (i = 0;i < p_ptr->mane_num;i++)
                                {
-                                       mane_spell[i] = mane_spell[i+1];
-                                       mane_dam[i] = mane_dam[i+1];
+                                       p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
+                                       p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
                                }
                        }
-                       mane_spell[mane_num] = thrown_spell - 96;
-                       mane_dam[mane_num] = dam;
-                       mane_num++;
+                       p_ptr->mane_spell[p_ptr->mane_num] = thrown_spell - 96;
+                       p_ptr->mane_dam[p_ptr->mane_num] = dam;
+                       p_ptr->mane_num++;
                        new_mane = TRUE;
 
-                       p_ptr->redraw |= (PR_MANE);
+                       p_ptr->redraw |= (PR_IMITATION);
                }
        }
 
        /* Remember what the monster did to us */
-       if (seen)
+       if (can_remember)
        {
                /* Inate spell */
                if (thrown_spell < 32 * 4)
                {
                        r_ptr->r_flags4 |= (1L << (thrown_spell - 32 * 3));
-                       if (r_ptr->r_cast_inate < MAX_UCHAR) r_ptr->r_cast_inate++;
+                       if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
                }
 
                /* Bolt or Ball */
@@ -4646,9 +4531,9 @@ msg_print("¿
 
 
        /* Always take note of monsters that kill you */
-       if (death && (r_ptr->r_deaths < MAX_SHORT))
+       if (p_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !p_ptr->inside_arena)
        {
-               r_ptr->r_deaths++;
+               r_ptr->r_deaths++; /* Ignore appearance difference */
        }
 
        /* A spell was cast */