OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengband/hengband.git] / src / mspells2.c
index 9109ac0..ddbc4fa 100644 (file)
@@ -1,6 +1,6 @@
-/*!
+/*!
  * @file mspells2.c
- * @brief ¥â¥ó¥¹¥¿¡¼ËâË¡¤Î¼ÂÁõ(ÂÐ¥â¥ó¥¹¥¿¡¼½èÍý) / Monster spells (attack monster)
+ * @brief モンスター魔法の実装(対モンスター処理) / Monster spells (attack monster)
  * @date 2014/01/17
  * @author
  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
 #include "angband.h"
 
 /*!
- * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨ÂÐ¥â¥ó¥¹¥¿¡¼¤Ë¥Ó¡¼¥à¤òÅö¤Æ¤ë¤³¤È²Äǽ¤«¤òȽÄꤹ¤ë /
+ * @brief モンスターが敵対モンスターにビームを当てること可能かを判定する /
  * Determine if a beam spell will hit the target.
- * @param y1 »ÏÅÀ¤ÎYºÂɸ
- * @param x1 »ÏÅÀ¤ÎXºÂɸ
- * @param y2 ÌÜɸ¤ÎYºÂɸ
- * @param x2 ÌÜɸ¤ÎXºÂɸ
- * @param m_ptr »ÈÍѤ¹¤ë¥â¥ó¥¹¥¿¡¼¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
- * @return ¥Ó¡¼¥à¤¬Åþã²Äǽ¤Ê¤é¤ÐTRUE¤òÊÖ¤¹
+ * @param y1 始点のY座標
+ * @param x1 始点のX座標
+ * @param y2 目標のY座標
+ * @param x2 目標のX座標
+ * @param m_ptr ä½¿ç\94¨ã\81\99ã\82\8bã\83¢ã\83³ã\82¹ã\82¿ã\83¼ã\81®æ§\8bé\80 ä½\93å\8f\82ç\85§ã\83\9dã\82¤ã\83³ã\82¿
+ * @return ビームが到達可能ならばTRUEを返す
  */
 static bool direct_beam(int y1, int x1, int y2, int x2, monster_type *m_ptr)
 {
@@ -62,39 +62,39 @@ static bool direct_beam(int y1, int x1, int y2, int x2, monster_type *m_ptr)
 }
 
 /*!
- * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨ÂÐ¥â¥ó¥¹¥¿¡¼¤ËľÀܥ֥쥹¤òÅö¤Æ¤ë¤³¤È¤¬²Äǽ¤«¤òȽÄꤹ¤ë /
+ * @brief モンスターが敵対モンスターに直接ブレスを当てることが可能かを判定する /
  * Determine if a breath will hit the target.
- * @param y1 »ÏÅÀ¤ÎYºÂɸ
- * @param x1 »ÏÅÀ¤ÎXºÂɸ
- * @param y2 ÌÜɸ¤ÎYºÂɸ
- * @param x2 ÌÜɸ¤ÎXºÂɸ
- * @param rad È¾·Â
- * @param typ ¸ú²Ì°À­ID
- * @param is_friend TRUE¤Ê¤é¤Ð¡¢¥×¥ì¥¤¥ä¡¼¤ò´¬¤­¹þ¤à»þ¤Ë¥Ö¥ì¥¹¤ÎȽÄê¤òFALSE¤Ë¤¹¤ë¡£
- * @return ¥Ö¥ì¥¹¤òľÀÜÅö¤Æ¤é¤ì¤ë¤Ê¤é¤ÐTRUE¤òÊÖ¤¹
+ * @param y1 始点のY座標
+ * @param x1 始点のX座標
+ * @param y2 目標のY座標
+ * @param x2 目標のX座標
+ * @param rad 半径
+ * @param typ 効果属性ID
+ * @param is_friend TRUEならば、プレイヤーを巻き込む時にブレスの判定をFALSEにする。
+ * @return ブレスを直接当てられるならばTRUEを返す
  */
-static bool breath_direct(int y1, int x1, int y2, int x2, int rad, int typ, bool is_friend)
+static bool breath_direct(POSITION y1, POSITION x1, POSITION y2, POSITION x2, POSITION rad, EFFECT_ID typ, bool is_friend)
 {
        /* Must be the same as projectable() */
 
        int i;
 
        /* Initial grid */
-       int y = y1;
-       int x = x1;
+       POSITION y = y1;
+       POSITION x = x1;
 
        int grid_n = 0;
        u16b grid_g[512];
 
        int grids = 0;
-       byte gx[1024], gy[1024];
-       byte gm[32];
-       int gm_rad = rad;
+       POSITION gx[1024], gy[1024];
+       POSITION gm[32];
+       POSITION gm_rad = rad;
 
        bool hit2 = FALSE;
        bool hityou = FALSE;
 
-       int flg;
+       BIT_FLAGS flg;
 
        switch (typ)
        {
@@ -147,17 +147,17 @@ static bool breath_direct(int y1, int x1, int y2, int x2, int rad, int typ, bool
                if (flg & PROJECT_DISI)
                {
                        if (in_disintegration_range(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
-                       if (in_disintegration_range(y1, x1, py, px) && (distance(y1, x1, py, px) <= rad)) hityou = TRUE;
+                       if (in_disintegration_range(y1, x1, p_ptr->y, p_ptr->x) && (distance(y1, x1, p_ptr->y, p_ptr->x) <= rad)) hityou = TRUE;
                }
                else if (flg & PROJECT_LOS)
                {
                        if (los(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
-                       if (los(y1, x1, py, px) && (distance(y1, x1, py, px) <= rad)) hityou = TRUE;
+                       if (los(y1, x1, p_ptr->y, p_ptr->x) && (distance(y1, x1, p_ptr->y, p_ptr->x) <= rad)) hityou = TRUE;
                }
                else
                {
                        if (projectable(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
-                       if (projectable(y1, x1, py, px) && (distance(y1, x1, py, px) <= rad)) hityou = TRUE;
+                       if (projectable(y1, x1, p_ptr->y, p_ptr->x) && (distance(y1, x1, p_ptr->y, p_ptr->x) <= rad)) hityou = TRUE;
                }
        }
        else
@@ -182,16 +182,16 @@ static bool breath_direct(int y1, int x1, int y2, int x2, int rad, int typ, bool
 }
 
 /*!
- * @brief ¥â¥ó¥¹¥¿¡¼¤¬ÆüìǽÎϤÎÌÜɸÃÏÅÀ¤ò·è¤á¤ë½èÍý /
+ * @brief モンスターが特殊能力の目標地点を決める処理 /
  * Get the actual center point of ball spells (rad > 1) (originally from TOband)
- * @param sy »ÏÅÀ¤ÎYºÂɸ
- * @param sx »ÏÅÀ¤ÎXºÂɸ
- * @param ty ÌÜɸYºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
- * @param tx ÌÜɸXºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
- * @param flg È½Äê¤Î¥Õ¥é¥°ÇÛÎó
- * @return ¤Ê¤·
+ * @param sy 始点のY座標
+ * @param sx 始点のX座標
+ * @param ty ç\9b®æ¨\99Y座æ¨\99ã\82\92è¿\94ã\81\99å\8f\82ç\85§ã\83\9dã\82¤ã\83³ã\82¿
+ * @param tx ç\9b®æ¨\99X座æ¨\99ã\82\92è¿\94ã\81\99å\8f\82ç\85§ã\83\9dã\82¤ã\83³ã\82¿
+ * @param flg 判定のフラグ配列
+ * @return なし
  */
-void get_project_point(int sy, int sx, int *ty, int *tx, int flg)
+void get_project_point(POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT_FLAGS flg)
 {
        u16b path_g[128];
        int  path_n, i;
@@ -216,13 +216,13 @@ void get_project_point(int sy, int sx, int *ty, int *tx, int flg)
 }
 
 /*!
- * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨¥â¥ó¥¹¥¿¡¼¤ËËâÎϾõî¤ò»È¤¦¤«¤É¤¦¤«¤òÊÖ¤¹ /
+ * @brief モンスターが敵モンスターに魔力消去を使うかどうかを返す /
  * Check should monster cast dispel spell at other monster.
- * @param m_idx ½Ñ¼Ô¤Î¥â¥ó¥¹¥¿¡¼ID
- * @param t_idx ÌÜɸ¤Î¥â¥ó¥¹¥¿¡¼ID
- * @return ËâÎϾõî¤ò»È¤¦¤Ù¤­¤Ê¤é¤ÐTRUE¤òÊѤ¨¤¹¡£
+ * @param m_idx è¡\93è\80\85ã\81®ã\83¢ã\83³ã\82¹ã\82¿ã\83¼ID
+ * @param t_idx ç\9b®æ¨\99ã\81®ã\83¢ã\83³ã\82¹ã\82¿ã\83¼ID
+ * @return 魔力消去を使うべきならばTRUEを変えす。
  */
-static bool dispel_check_monster(int m_idx, int t_idx)
+static bool dispel_check_monster(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
 {
        monster_type *t_ptr = &m_list[t_idx];
 
@@ -246,26 +246,22 @@ static bool dispel_check_monster(int m_idx, int t_idx)
 }
 
 /*!
- * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨¥â¥ó¥¹¥¿¡¼¤ËÆüìǽÎϤò»È¤¦½èÍý¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
+ * @brief モンスターが敵モンスターに特殊能力を使う処理のメインルーチン /
  * Monster tries to 'cast a spell' (or breath, etc) at another monster.
- * @param m_idx ½Ñ¼Ô¤Î¥â¥ó¥¹¥¿¡¼ID
- * @return ¼ÂºÝ¤ËÆüìǽÎϤò»È¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
+ * @param m_idx è¡\93è\80\85ã\81®ã\83¢ã\83³ã\82¹ã\82¿ã\83¼ID
+ * @return 実際に特殊能力を使った場合TRUEを返す
  * @details
  * The player is only disturbed if able to be affected by the spell.
  */
-bool monst_spell_monst(int m_idx)
+bool monst_spell_monst(MONSTER_IDX m_idx)
 {
-       int y = 0, x = 0;
-       int i, k, t_idx = 0;
-       int thrown_spell, count = 0;
-       int rlev;
-       int dam = 0;
+       POSITION y = 0, x = 0;
+       int i, k;
+       MONSTER_IDX target_idx = 0;
+       int thrown_spell;
+       HIT_POINT dam = 0;
        int start;
        int plus = 1;
-       u32b u_mode = 0L;
-       int s_num_6 = (easy_band ? 2 : 6);
-       int s_num_4 = (easy_band ? 1 : 4);
-       int rad = 0; //For elemental balls
 
        byte spell[96], num = 0;
 
@@ -280,70 +276,54 @@ bool monst_spell_monst(int m_idx)
        monster_type *t_ptr = NULL;
 
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
-       monster_race *tr_ptr = NULL;
 
        u32b f4, f5, f6;
 
-       bool wake_up = FALSE;
-       bool fear = FALSE;
-
-       bool blind = (p_ptr->blind ? TRUE : FALSE);
-
        bool see_m = is_seen(m_ptr);
        bool maneable = player_has_los_bold(m_ptr->fy, m_ptr->fx);
-       bool see_t;
-       bool see_either;
-       bool known;
-
        bool pet = is_pet(m_ptr);
 
        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));
 
        bool can_use_lite_area = FALSE;
-
        bool can_remember;
 
-       bool resists_tele = FALSE;
-
-       /* Prepare flags for summoning */
-       if (!pet) u_mode |= PM_ALLOW_UNIQUE;
-
        /* Cannot cast spells when confused */
        if (MON_CONFUSED(m_ptr)) return (FALSE);
 
        /* Extract the racial spell flags */
        f4 = r_ptr->flags4;
-       f5 = r_ptr->flags5;
-       f6 = r_ptr->flags6;
+       f5 = r_ptr->a_ability_flags1;
+       f6 = r_ptr->a_ability_flags2;
 
        /* Target is given for pet? */
        if (pet_t_m_idx && pet)
        {
-               t_idx = pet_t_m_idx;
-               t_ptr = &m_list[t_idx];
+               target_idx = pet_t_m_idx;
+               t_ptr = &m_list[target_idx];
 
                /* Cancel if not projectable (for now) */
-               if ((m_idx == t_idx) || !projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
+               if ((m_idx == target_idx) || !projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
                {
-                       t_idx = 0;
+                       target_idx = 0;
                }
        }
 
        /* Is there counter attack target? */
-       if (!t_idx && m_ptr->target_y)
+       if (!target_idx && m_ptr->target_y)
        {
-               t_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
+               target_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
 
-               if (t_idx)
+               if (target_idx)
                {
-                       t_ptr = &m_list[t_idx];
+                       t_ptr = &m_list[target_idx];
 
                        /* Cancel if neither enemy nor a given target */
-                       if ((m_idx == t_idx) ||
-                           ((t_idx != pet_t_m_idx) && !are_enemies(m_ptr, t_ptr)))
+                       if ((m_idx == target_idx) ||
+                           ((target_idx != pet_t_m_idx) && !are_enemies(m_ptr, t_ptr)))
                        {
-                               t_idx = 0;
+                               target_idx = 0;
                        }
 
                        /* Allow only summoning etc.. if not projectable */
@@ -357,7 +337,7 @@ bool monst_spell_monst(int m_idx)
        }
 
        /* Look for enemies normally */
-       if (!t_idx)
+       if (!target_idx)
        {
                bool success = FALSE;
 
@@ -371,17 +351,17 @@ bool monst_spell_monst(int m_idx)
                /* Scan thru all monsters */
                for (i = start; ((i < start + m_max) && (i > start - m_max)); i += plus)
                {
-                       int dummy = (i % m_max);
+                       MONSTER_IDX dummy = (i % m_max);
                        if (!dummy) continue;
 
-                       t_idx = dummy;
-                       t_ptr = &m_list[t_idx];
+                       target_idx = dummy;
+                       t_ptr = &m_list[target_idx];
 
                        /* Skip dead monsters */
                        if (!t_ptr->r_idx) continue;
 
                        /* Monster must be 'an enemy' */
-                       if ((m_idx == t_idx) || !are_enemies(m_ptr, t_ptr)) continue;
+                       if ((m_idx == target_idx) || !are_enemies(m_ptr, t_ptr)) continue;
 
                        /* Monster must be projectable */
                        if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
@@ -399,14 +379,10 @@ bool monst_spell_monst(int m_idx)
        /* OK -- we've got a target */
        y = t_ptr->fy;
        x = t_ptr->fx;
-       tr_ptr = &r_info[t_ptr->r_idx];
 
        /* Forget old counter attack target */
        reset_target(m_ptr);
 
-       /* Extract the monster level */
-       rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
-
        /* Remove unimplemented spells */
        f6 &= ~(RF6_WORLD | RF6_TRAPS | RF6_FORGET);
 
@@ -498,14 +474,14 @@ bool monst_spell_monst(int m_idx)
                            (f5 & RF5_BALL_MASK) ||
                            (f6 & RF6_BALL_MASK))
                        {
-                               int real_y = y;
-                               int real_x = x;
+                               POSITION real_y = y;
+                               POSITION real_x = x;
 
                                get_project_point(m_ptr->fy, m_ptr->fx, &real_y, &real_x, 0L);
 
-                               if (projectable(real_y, real_x, py, px))
+                               if (projectable(real_y, real_x, p_ptr->y, p_ptr->x))
                                {
-                                       int dist = distance(real_y, real_x, py, px);
+                                       int dist = distance(real_y, real_x, p_ptr->y, p_ptr->x);
 
                                        if (dist <= 2)
                                        {
@@ -522,24 +498,22 @@ bool monst_spell_monst(int m_idx)
                                }
                                else if (f5 & RF5_BA_LITE)
                                {
-                                       if ((distance(real_y, real_x, py, px) <= 4) && los(real_y, real_x, py, px))
+                                       if ((distance(real_y, real_x, p_ptr->y, p_ptr->x) <= 4) && los(real_y, real_x, p_ptr->y, p_ptr->x))
                                                f5 &= ~(RF5_BA_LITE);
                                }
                        }
 
                        if (f4 & RF4_ROCKET)
                        {
-                               int real_y = y;
-                               int real_x = x;
+                               POSITION real_y = y;
+                               POSITION real_x = x;
 
                                get_project_point(m_ptr->fy, m_ptr->fx, &real_y, &real_x, PROJECT_STOP);
-                               if (projectable(real_y, real_x, py, px) && (distance(real_y, real_x, py, px) <= 2))
+                               if (projectable(real_y, real_x, p_ptr->y, p_ptr->x) && (distance(real_y, real_x, p_ptr->y, p_ptr->x) <= 2))
                                        f4 &= ~(RF4_ROCKET);
                        }
 
-                       if (((f4 & RF4_BEAM_MASK) ||
-                            (f5 & RF5_BEAM_MASK) ||
-                            (f6 & RF6_BEAM_MASK)) &&
+                       if (((f4 & RF4_BEAM_MASK) || (f5 & RF5_BEAM_MASK) || (f6 & RF6_BEAM_MASK)) &&
                            !direct_beam(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, m_ptr))
                        {
                                f4 &= ~(RF4_BEAM_MASK);
@@ -547,12 +521,10 @@ bool monst_spell_monst(int m_idx)
                                f6 &= ~(RF6_BEAM_MASK);
                        }
 
-                       if ((f4 & RF4_BREATH_MASK) ||
-                           (f5 & RF5_BREATH_MASK) ||
-                           (f6 & RF6_BREATH_MASK))
+                       if ((f4 & RF4_BREATH_MASK) || (f5 & RF5_BREATH_MASK) || (f6 & RF6_BREATH_MASK))
                        {
                                /* Expected breath radius */
-                               int rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2;
+                               POSITION rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2;
 
                                if (!breath_direct(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, 0, TRUE))
                                {
@@ -618,7 +590,7 @@ bool monst_spell_monst(int m_idx)
                }
 
                /* Dispel magic */
-               if ((f4 & RF4_DISPEL) && !dispel_check_monster(m_idx, t_idx))
+               if ((f4 & RF4_DISPEL) && !dispel_check_monster(m_idx, target_idx))
                {
                        /* Remove dispel spell */
                        f4 &= ~(RF4_DISPEL);
@@ -654,7 +626,7 @@ bool monst_spell_monst(int m_idx)
                }
 
                /* Hack -- decline "teleport level" in some case */
-               if ((f6 & RF6_TELE_LEVEL) && TELE_LEVEL_IS_INEFF((t_idx == p_ptr->riding) ? 0 : t_idx))
+               if ((f6 & RF6_TELE_LEVEL) && TELE_LEVEL_IS_INEFF((target_idx == p_ptr->riding) ? 0 : target_idx))
                {
                        f6 &= ~(RF6_TELE_LEVEL);
                }
@@ -666,19 +638,19 @@ bool monst_spell_monst(int m_idx)
        /* Extract the "inate" spells */
        for (k = 0; k < 32; k++)
        {
-               if (f4 & (1L << k)) spell[num++] = k + 32 * 3;
+               if (f4 & (1L << k)) spell[num++] = k + RF4_SPELL_START;
        }
 
        /* Extract the "normal" spells */
        for (k = 0; k < 32; k++)
        {
-               if (f5 & (1L << k)) spell[num++] = k + 32 * 4;
+        if (f5 & (1L << k)) spell[num++] = k + RF5_SPELL_START;
        }
 
        /* Extract the "bizarre" spells */
        for (k = 0; k < 32; k++)
        {
-               if (f6 & (1L << k)) spell[num++] = k + 32 * 5;
+        if (f6 & (1L << k)) spell[num++] = k + RF6_SPELL_START;
        }
 
        /* No spells left */
@@ -704,20 +676,13 @@ bool monst_spell_monst(int m_idx)
        /* Choose a spell to cast */
        thrown_spell = spell[randint0(num)];
 
-       see_t = is_seen(t_ptr);
-       see_either = (see_m || see_t);
-
-       /* Can the player be aware of this attack? */
-       known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
-
-       if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 1);
+       if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(TRUE, TRUE);
 
        /* 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))))
        {
-               disturb(1, 1);
-               /* Message */
-               if (see_m) msg_format(_("%^s¤Ï¼öʸ¤ò¾§¤¨¤è¤¦¤È¤·¤¿¤¬¼ºÇÔ¤·¤¿¡£", 
+               disturb(TRUE, TRUE);
+               if (see_m) msg_format(_("%^sは呪文を唱えようとしたが失敗した。", 
                                            "%^s tries to cast a spell, but fails."), m_name);
 
                return (TRUE);
@@ -726,693 +691,15 @@ bool monst_spell_monst(int m_idx)
        /* Hex: Anti Magic Barrier */
        if (!spell_is_inate(thrown_spell) && magic_barrier(m_idx))
        {
-               if (see_m) msg_format(_("È¿ËâË¡¥Ð¥ê¥¢¤¬%^s¤Î¼öʸ¤ò¤«¤­¾Ã¤·¤¿¡£", 
+               if (see_m) msg_format(_("反魔法バリアが%^sの呪文をかき消した。", 
                                            "Anti magic barrier cancels the spell which %^s casts."), m_name);
                return (TRUE);
        }
 
        can_remember = is_original_ap_and_seen(m_ptr);
 
-    dam = monspell_to_monster(thrown_spell, y, x, m_idx, t_idx);
-    if (dam < 0)return FALSE;
-
-       switch (thrown_spell)
-    {
-
-       /* RF6_PSY_SPEAR */
-       case 160+11:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               msg_format(_("%^s¤¬%s¤Ë¸þ¤«¤Ã¤Æ¸÷¤Î·õ¤òÊü¤Ã¤¿¡£", "%^s throw a Psycho-spear at %s."), m_name, t_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               dam = (r_ptr->flags2 & RF2_POWERFUL) ? (randint1(rlev * 2) + 180) : (randint1(rlev * 3 / 2) + 120);
-               beam(m_idx, y, x, GF_PSY_SPEAR, dam, MS_PSY_SPEAR, MONSTER_TO_MONSTER);
-               break;
-
-       /* RF6_DARKNESS */
-       case 160+12:
-               if (known)
-               {
-                       if (see_m)
-                       {
-                               if (can_use_lite_area)
-                               {
-                                       msg_format(_("%^s¤¬ÊÕ¤ê¤òÌÀ¤ë¤¯¾È¤é¤·¤¿¡£", "%^s cast a spell to light up."), m_name);
-                               }
-                               else
-                               {
-                                       msg_format(_("%^s¤¬°Å°Ç¤ÎÃæ¤Ç¼ê¤ò¿¶¤Ã¤¿¡£", "%^s gestures in shadow."), m_name);
-                               }
-
-                               if (see_t)
-                               {
-                                       if (can_use_lite_area)
-                                       {
-                                               msg_format(_("%^s¤ÏÇò¤¤¸÷¤ËÊñ¤Þ¤ì¤¿¡£", "%^s is surrounded by a white light."), t_name);
-                                       }
-                                       else
-                                       {
-                                               msg_format(_("%^s¤Ï°Å°Ç¤ËÊñ¤Þ¤ì¤¿¡£", "%^s is surrounded by darkness."), t_name);
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               if (can_use_lite_area)
-               {
-                       (void)project(m_idx, 3, y, x, 0, GF_LITE_WEAK, PROJECT_GRID | PROJECT_KILL, -1);
-                       lite_room(y, x);
-               }
-               else
-               {
-                       (void)project(m_idx, 3, y, x, 0, GF_DARK_WEAK, PROJECT_GRID | PROJECT_KILL, MS_DARKNESS);
-                       unlite_room(y, x);
-               }
-
-               break;
-
-       /* RF6_TRAPS */
-       case 160+13:
-#if 0
-               if (known)
-               {
-                       if (see_m)
-                       {
-                               msg_format(_("%^s¤¬¼öʸ¤ò¾§¤¨¤Æ¼Ù°­¤ËÈù¾Ð¤ó¤À¡£", "%^s casts a spell and cackles evilly."), m_name);
-                       }
-                       else
-                       {
-                               msg_format(_("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", "%^s mumbles."), m_name);
-                       }
-               }
-
-               trap_creation(y, x);
-
-               break;
-#else
-               /* Not implemented */
-               return FALSE;
-#endif
-
-       /* RF6_FORGET */
-       case 160+14:
-               /* Not implemented */
-               return FALSE;
-
-       /* RF6_RAISE_DEAD */
-       case 160+15:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-                               if (blind)
-                               {
-                                       msg_format(_("%^s¤¬²¿¤«¤ò¤Ä¤Ö¤ä¤¤¤¿¡£", "%^s mumbles."), m_name);
-                               }
-                               else
-                               {
-                                       msg_format(_("%^s¤¬»à¼ÔÉü³è¤Î¼öʸ¤ò¾§¤¨¤¿¡£", "%^s casts a spell to revive corpses."), m_name);
-                               }
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-               animate_dead(m_idx, m_ptr->fy, m_ptr->fx);
-               break;
-
-       /* RF6_S_KIN */
-       case 160+16:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               if (m_ptr->r_idx == MON_SERPENT || m_ptr->r_idx == MON_ZOMBI_SERPENT)
-                               {
-                                       msg_format(_("%^s¤¬¥À¥ó¥¸¥ç¥ó¤Î¼ç¤ò¾¤´­¤·¤¿¡£", "%^s magically summons guardians of dungeons."), m_name);
-                               }
-                               else
-                               {
-                                       _(msg_format("%s¤¬ËâË¡¤Ç%s¤ò¾¤´­¤·¤¿¡£", m_name, ((r_ptr->flags1 & RF1_UNIQUE) ? "¼ê²¼" : "Ãç´Ö")),   
-                                         msg_format("%^s magically summons %s %s.", m_name, m_poss, ((r_ptr->flags1 & RF1_UNIQUE) ? "minions" : "kin")));
-                               }
-
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               switch (m_ptr->r_idx)
-               {
-               case MON_MENELDOR:
-               case MON_GWAIHIR:
-               case MON_THORONDOR:
-                       {
-                               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));
-                               }
-                       }
-                       break;
-
-               case MON_BULLGATES:
-                       {
-                               int num = 2 + randint1(3);
-                               for (k = 0; k < num; k++)
-                               {
-                                       count += summon_named_creature(m_idx, y, x, MON_IE, 0);
-                               }
-                       }
-                       break;
-
-               case MON_SERPENT:
-               case MON_ZOMBI_SERPENT:
-                       if (r_info[MON_JORMUNGAND].cur_num < r_info[MON_JORMUNGAND].max_num && one_in_(6))
-                       {
-                               if (known && see_t)
-                               {
-                                       msg_print(_("ÃÏÌ̤«¤é¿å¤¬¿á¤­½Ð¤·¤¿¡ª", "Water blew off from the ground!"));
-                               }
-                               project(t_idx, 8, y, x, 3, GF_WATER_FLOW, PROJECT_GRID | PROJECT_HIDE, -1);
-                       }
-
-                       {
-                               int num = 2 + randint1(3);
-                               for (k = 0; k < num; k++)
-                               {
-                                       count += summon_specific(m_idx, y, x, rlev, SUMMON_GUARDIANS, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
-                               }
-                       }
-                       break;
-
-               case MON_CALDARM:
-                       {
-                               int num = randint1(3);
-                               for (k = 0; k < num; k++)
-                               {
-                                       count += summon_named_creature(m_idx, y, x, MON_LOCKE_CLONE, 0);
-                               }
-                       }
-                       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;
-
-                       for (k = 0; k < 4; k++)
-                       {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_KIN, (PM_ALLOW_GROUP));
-                       }
-                       break;
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_CYBER */
-       case 160+17:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬¥µ¥¤¥Ð¡¼¥Ç¡¼¥â¥ó¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons Cyberdemons!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               if (is_friendly(m_ptr))
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_CYBER, (PM_ALLOW_GROUP));
-               }
-               else
-               {
-                       count += summon_cyber(m_idx, y, x);
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_MONSTER */
-       case 160+18:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤ÇÃç´Ö¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons help!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               count += summon_specific(m_idx, y, x, rlev, 0, (u_mode));
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_MONSTERS */
-       case 160+19:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤Ç¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons monsters!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_6; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, 0, (PM_ALLOW_GROUP | u_mode));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_ANT */
-       case 160+20:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤Ç¥¢¥ê¤ò¾¤´­¤·¤¿¡£", "%^s magically summons ants."), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_6; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_ANT, (PM_ALLOW_GROUP));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_SPIDER */
-       case 160+21:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤Ç¥¯¥â¤ò¾¤´­¤·¤¿¡£", "%^s magically summons spiders."), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_6; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_SPIDER, (PM_ALLOW_GROUP));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_HOUND */
-       case 160+22:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤Ç¥Ï¥¦¥ó¥É¤ò¾¤´­¤·¤¿¡£", "%^s magically summons hounds."), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_4; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_HOUND, (PM_ALLOW_GROUP));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_HYDRA */
-       case 160+23:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤Ç¥Ò¥É¥é¤ò¾¤´­¤·¤¿¡£", "%^s magically summons hydras."), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_4; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_HYDRA, (PM_ALLOW_GROUP));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_ANGEL */
-       case 160+24:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤ÇÅ·»È¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons an angel!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               {
-                       int num = 1;
-
-                       if ((r_ptr->flags1 & RF1_UNIQUE) && !easy_band)
-                       {
-                               num += r_ptr->level/40;
-                       }
-
-                       for (k = 0; k < num; k++)
-                       {
-                               count += summon_specific(m_idx, y, x, rlev, SUMMON_ANGEL, (PM_ALLOW_GROUP));
-                       }
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_DEMON */
-       case 160+25:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤Çº®Æ٤εÜÄ¤é¥Ç¡¼¥â¥ó¤ò¾¤´­¤·¤¿¡ª", 
-                                                "%^s magically summons a demon from the Courts of Chaos!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < 1; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_DEMON, (PM_ALLOW_GROUP));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_UNDEAD */
-       case 160+26:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%s¤¬ËâË¡¤Ç¥¢¥ó¥Ç¥Ã¥É¤ò¾¤´­¤·¤¿¡£", "%^s magically summons undead."), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < 1; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_UNDEAD, (PM_ALLOW_GROUP));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_DRAGON */
-       case 160+27:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤Ç¥É¥é¥´¥ó¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons a dragon!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < 1; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_DRAGON, (PM_ALLOW_GROUP));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_HI_UNDEAD */
-       case 160+28:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%s¤¬ËâË¡¤Ç¥¢¥ó¥Ç¥Ã¥É¤ò¾¤´­¤·¤¿¡£", "%^s magically summons undead."), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_6; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_UNDEAD, (PM_ALLOW_GROUP | u_mode));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_HI_DRAGON */
-       case 160+29:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤Ç¸ÅÂå¥É¥é¥´¥ó¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons ancient dragons!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_4; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_HI_DRAGON, (PM_ALLOW_GROUP | u_mode));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_AMBERITES */
-       case 160+30:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬¥¢¥ó¥Ð¡¼¤Î²¦Â²¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons Lords of Amber!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_4; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_AMBERITES, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-
-       /* RF6_S_UNIQUE */
-       case 160+31:
-               if (known)
-               {
-                       if (see_either)
-                       {
-                               disturb(1, 1);
-
-                               msg_format(_("%^s¤¬ËâË¡¤ÇÆÃÊ̤ʶ¯Å¨¤ò¾¤´­¤·¤¿¡ª", "%^s magically summons special opponents!"), m_name);
-                       }
-                       else
-                       {
-                               mon_fight = TRUE;
-                       }
-               }
-
-               for (k = 0; k < s_num_4; k++)
-               {
-                       count += summon_specific(m_idx, y, x, rlev, SUMMON_UNIQUE, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
-               }
-
-               {
-                       int non_unique_type = SUMMON_HI_UNDEAD;
-
-                       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++)
-                       {
-                               count += summon_specific(m_idx, y, x, rlev, non_unique_type, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
-                       }
-               }
-
-               if (known && !see_t && count)
-               {
-                       mon_fight = TRUE;
-               }
-
-               break;
-       }
-
-       if (wake_up) (void)set_monster_csleep(t_idx, 0);
-
-       if (fear && see_t)
-       {
-               msg_format(_("%^s¤Ï¶²Éݤ·¤Æƨ¤²½Ð¤·¤¿¡ª", "%^s flees in terror!"), t_name);
-       }
+       dam = monspell_to_monster(thrown_spell, y, x, m_idx, target_idx);
+       if (dam < 0) return FALSE;
 
        if (m_ptr->ml && maneable && !world_monster && !p_ptr->blind && (p_ptr->pclass == CLASS_IMITATOR))
        {
@@ -1427,7 +714,7 @@ bool monst_spell_monst(int m_idx)
                                        p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
                                }
                        }
-                       p_ptr->mane_spell[p_ptr->mane_num] = thrown_spell - 96;
+                       p_ptr->mane_spell[p_ptr->mane_num] = thrown_spell - RF4_SPELL_START;
                        p_ptr->mane_dam[p_ptr->mane_num] = dam;
                        p_ptr->mane_num++;
                        new_mane = TRUE;
@@ -1440,23 +727,23 @@ bool monst_spell_monst(int m_idx)
        if (can_remember)
        {
                /* Inate spell */
-               if (thrown_spell < 32*4)
+        if (thrown_spell < RF4_SPELL_START + RF4_SPELL_SIZE)
                {
-                       r_ptr->r_flags4 |= (1L << (thrown_spell - 32*3));
+            r_ptr->r_flags4 |= (1L << (thrown_spell - RF4_SPELL_START));
                        if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
                }
 
                /* Bolt or Ball */
-               else if (thrown_spell < 32*5)
+        else if (thrown_spell < RF5_SPELL_START + RF5_SPELL_SIZE)
                {
-                       r_ptr->r_flags5 |= (1L << (thrown_spell - 32*4));
+            r_ptr->r_flags5 |= (1L << (thrown_spell - RF5_SPELL_START));
                        if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
                }
 
                /* Special spell */
-               else if (thrown_spell < 32*6)
+        else if (thrown_spell < RF6_SPELL_START + RF6_SPELL_SIZE)
                {
-                       r_ptr->r_flags6 |= (1L << (thrown_spell - 32*5));
+            r_ptr->r_flags6 |= (1L << (thrown_spell - RF6_SPELL_START));
                        if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
                }
        }