OSDN Git Service

#37287 (2.2.0.40) cmd1.c内のC4457警告に対応。 / Deal C4457 warning in cmd1.c.
[hengband/hengband.git] / src / monster2.c
index e330b57..ded6882 100644 (file)
 
 #include "angband.h"
 
-#define HORDE_NOGOOD 0x01
-#define HORDE_NOEVIL 0x02
+#define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
+#define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
 
+
+/*!
+ * @var horror_desc
+ * @brief ELDRITCH HORROR効果時のモンスターの形容メッセージ(通常時)
+ */
 cptr horror_desc[MAX_SAN_HORROR] =
 {
 #ifdef JP
@@ -69,6 +74,10 @@ cptr horror_desc[MAX_SAN_HORROR] =
 
 };
 
+/*!
+ * @var funny_desc
+ * @brief ELDRITCH HORROR効果時のモンスターの形容メッセージ(幻覚状態時)
+ */
 cptr funny_desc[MAX_SAN_FUNNY] =
 {
 #ifdef JP
@@ -129,6 +138,10 @@ cptr funny_desc[MAX_SAN_FUNNY] =
 
 };
 
+/*!
+ * @var funny_comments
+ * @brief ELDRITCH HORROR効果時の幻覚時間延長を示す錯乱表現
+ */
 cptr funny_comments[MAX_SAN_COMMENT] =
 {
 #ifdef JP
@@ -630,21 +643,28 @@ s16b m_pop(void)
 
 
 
-/*
- * Hack -- the "type" of the current "summon specific"
+/*!
+ * @var summon_specific_type
+ * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
+ * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
  */
 static int summon_specific_type = 0;
 
 
-/*
- * Hack -- the index of the summoning monster
+/*!
+ * @var summon_specific_who
+ * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
+ * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
  */
 static int summon_specific_who = -1;
 
-
+/*!
+ * @var summon_unique_okay
+ * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
+ * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
+ */
 static bool summon_unique_okay = FALSE;
 
-
 /*!
  * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
  * @return 召喚条件が一致するならtrue
@@ -741,35 +761,29 @@ static bool summon_specific_aux(int r_idx)
                        break;
                }
 
-               case SUMMON_BIZARRE1:
+               case SUMMON_MOLD:
                {
                        okay = (r_ptr->d_char == 'm');
                        break;
                }
-               case SUMMON_BIZARRE2:
+               case SUMMON_BAT:
                {
                        okay = (r_ptr->d_char == 'b');
                        break;
                }
-               case SUMMON_BIZARRE3:
+               case SUMMON_QUYLTHULG:
                {
                        okay = (r_ptr->d_char == 'Q');
                        break;
                }
 
-               case SUMMON_BIZARRE4:
-               {
-                       okay = (r_ptr->d_char == 'v');
-                       break;
-               }
-
-               case SUMMON_BIZARRE5:
+               case SUMMON_COIN_MIMIC:
                {
                        okay = (r_ptr->d_char == '$');
                        break;
                }
 
-               case SUMMON_BIZARRE6:
+               case SUMMON_MIMIC:
                {
                        okay = ((r_ptr->d_char == '!') ||
                                 (r_ptr->d_char == '?') ||
@@ -820,7 +834,7 @@ static bool summon_specific_aux(int r_idx)
                               !(r_ptr->flags3 & (RF3_UNDEAD)) &&
                               !(r_ptr->flags3 & (RF3_DEMON)) &&
                               !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
-                              !(r_ptr->flags4 || r_ptr->flags5 || r_ptr->flags6));
+                              !(r_ptr->flags4 || r_ptr->a_ability_flags1 || r_ptr->a_ability_flags2));
                        break;
                }
 
@@ -952,7 +966,11 @@ static bool summon_specific_aux(int r_idx)
        return (bool)(okay ? TRUE : FALSE);
 }
 
-
+/*!
+ * @var chameleon_change_m_idx
+ * @brief カメレオンの変身先モンスターIDを受け渡すためのグローバル変数
+ * @todo 変数渡しの問題などもあるができればchameleon_change_m_idxのグローバル変数を除去し、関数引き渡しに移行すること
+ */
 static int chameleon_change_m_idx = 0;
 
 
@@ -976,16 +994,16 @@ static bool restrict_monster_to_dungeon(int r_idx)
                if (r_idx != MON_CHAMELEON &&
                    r_ptr->freq_spell && 
                    !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
-                   !(r_ptr->flags5 & RF5_NOMAGIC_MASK) &&
-                   !(r_ptr->flags6 & RF6_NOMAGIC_MASK))
+                   !(r_ptr->a_ability_flags1 & RF5_NOMAGIC_MASK) &&
+                   !(r_ptr->a_ability_flags2 & RF6_NOMAGIC_MASK))
                        return FALSE;
        }
        if (d_ptr->flags1 & DF1_NO_MELEE)
        {
                if (r_idx == MON_CHAMELEON) return TRUE;
                if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
-                   !(r_ptr->flags5 & (RF5_BOLT_MASK | RF5_BEAM_MASK | RF5_BALL_MASK | RF5_CAUSE_1 | RF5_CAUSE_2 | RF5_CAUSE_3 | RF5_CAUSE_4 | RF5_MIND_BLAST | RF5_BRAIN_SMASH)) &&
-                   !(r_ptr->flags6 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
+                   !(r_ptr->a_ability_flags1 & (RF5_BOLT_MASK | RF5_BEAM_MASK | RF5_BALL_MASK | RF5_CAUSE_1 | RF5_CAUSE_2 | RF5_CAUSE_3 | RF5_CAUSE_4 | RF5_MIND_BLAST | RF5_BRAIN_SMASH)) &&
+                   !(r_ptr->a_ability_flags2 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
                        return FALSE;
        }
        if (d_ptr->flags1 & DF1_BEGINNER)
@@ -1020,14 +1038,14 @@ static bool restrict_monster_to_dungeon(int r_idx)
                        if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
                                return FALSE;
                }
-               if (d_ptr->mflags5)
+               if (d_ptr->m_a_ability_flags1)
                {
-                       if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
+                       if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
                                return FALSE;
                }
-               if (d_ptr->mflags6)
+               if (d_ptr->m_a_ability_flags2)
                {
-                       if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
+                       if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
                                return FALSE;
                }
                if (d_ptr->mflags7)
@@ -1076,14 +1094,14 @@ static bool restrict_monster_to_dungeon(int r_idx)
                        if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
                                return TRUE;
                }
-               if (d_ptr->mflags5)
+               if (d_ptr->m_a_ability_flags1)
                {
-                       if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
+                       if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
                                return TRUE;
                }
-               if (d_ptr->mflags6)
+               if (d_ptr->m_a_ability_flags2)
                {
-                       if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
+                       if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
                                return TRUE;
                }
                if (d_ptr->mflags7)
@@ -1116,8 +1134,8 @@ static bool restrict_monster_to_dungeon(int r_idx)
                if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
                if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
                if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
-               if (r_ptr->flags5 & d_ptr->mflags5) return TRUE;
-               if (r_ptr->flags6 & d_ptr->mflags6) return TRUE;
+               if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return TRUE;
+               if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return TRUE;
                if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
                if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
                if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
@@ -1132,8 +1150,8 @@ static bool restrict_monster_to_dungeon(int r_idx)
                if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
                if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
                if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
-               if (r_ptr->flags5 & d_ptr->mflags5) return FALSE;
-               if (r_ptr->flags6 & d_ptr->mflags6) return FALSE;
+               if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return FALSE;
+               if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return FALSE;
                if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
                if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
                if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
@@ -1149,8 +1167,8 @@ static bool restrict_monster_to_dungeon(int r_idx)
 
 /*!
  * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
- * @param monnster_hook 制限関数1
- * @param monnster_hook2 制限関数2
+ * @param monster_hook 制限関数1
+ * @param monster_hook2 制限関数2
  * @return エラーコード
  */
 errr get_mon_num_prep(monster_hook_type monster_hook,
@@ -1288,12 +1306,12 @@ s16b get_mon_num(int level)
        alloc_entry             *table = alloc_race_table;
 
        int pls_kakuritu, pls_level;
-       int hoge = mysqrt(level*10000L);
+       int delay = mysqrt(level * 10000L) + 400L;
 
        if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
 
-       pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((dungeon_turn / (TURNS_PER_TICK * 2500L) - hoge / 10)));
-       pls_level    = MIN(NASTY_MON_PLUS_MAX, 3 + dungeon_turn / (TURNS_PER_TICK * 20000L) - hoge / 40 + MIN(5, level / 10)) ;
+       pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10)));
+       pls_level    = MIN(NASTY_MON_PLUS_MAX, 3 + dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10)) ;
 
        if (d_info[dungeon_type].flags1 & DF1_MAZE)
        {
@@ -1847,9 +1865,9 @@ int lore_do_probe(int r_idx)
                if (!(r_ptr->r_flags4 & (1L << i)) &&
                    (r_ptr->flags4 & (1L << i))) n++;
                if (!(r_ptr->r_flags5 & (1L << i)) &&
-                   (r_ptr->flags5 & (1L << i))) n++;
+                   (r_ptr->a_ability_flags1 & (1L << i))) n++;
                if (!(r_ptr->r_flags6 & (1L << i)) &&
-                   (r_ptr->flags6 & (1L << i))) n++;
+                   (r_ptr->a_ability_flags2 & (1L << i))) n++;
                if (!(r_ptr->r_flagsr & (1L << i)) &&
                    (r_ptr->flagsr & (1L << i))) n++;
 
@@ -1865,8 +1883,8 @@ int lore_do_probe(int r_idx)
        r_ptr->r_flags2 = r_ptr->flags2;
        r_ptr->r_flags3 = r_ptr->flags3;
        r_ptr->r_flags4 = r_ptr->flags4;
-       r_ptr->r_flags5 = r_ptr->flags5;
-       r_ptr->r_flags6 = r_ptr->flags6;
+       r_ptr->r_flags5 = r_ptr->a_ability_flags1;
+       r_ptr->r_flags6 = r_ptr->a_ability_flags2;
        r_ptr->r_flagsr = r_ptr->flagsr;
 
        /* r_flags7 is actually unused */
@@ -1944,10 +1962,10 @@ void sanity_blast(monster_type *m_ptr, bool necro)
 
        if (p_ptr->inside_battle || !character_dungeon) return;
 
-       if (!necro)
+       if (!necro && m_ptr)
        {
-               char            m_name[80];
-               monster_race    *r_ptr = &r_info[m_ptr->ap_r_idx];
+               char m_name[80];
+               monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
 
                power = r_ptr->level / 2;
 
@@ -1969,8 +1987,6 @@ void sanity_blast(monster_type *m_ptr, bool necro)
                if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
                        return; /* oops */
 
-
-
                if (is_pet(m_ptr))
                        return; /* Pet eldritch horrors are safe most of the time */
 
@@ -1992,7 +2008,6 @@ void sanity_blast(monster_type *m_ptr, bool necro)
                                funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
 #endif
 
-
                        if (one_in_(3))
                        {
                                msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
@@ -2025,6 +2040,95 @@ void sanity_blast(monster_type *m_ptr, bool necro)
                        if (saving_throw(25 + p_ptr->lev)) return;
                }
        }
+       else if(!necro)
+       {
+               monster_race *r_ptr;
+               char m_name[80];
+               cptr desc;
+
+               get_mon_num_prep(get_nightmare, NULL);
+
+               r_ptr = &r_info[get_mon_num(MAX_DEPTH)];
+               power = r_ptr->level + 10;
+               desc = r_name + r_ptr->name;
+
+               get_mon_num_prep(NULL, NULL);
+
+               /* Describe it */
+#ifndef JP
+               if (!(r_ptr->flags1 & RF1_UNIQUE))
+                       sprintf(m_name, "%s %s", (is_a_vowel(desc[0]) ? "an" : "a"), desc);
+               else
+#endif
+               sprintf(m_name, "%s", desc);
+
+               if (!(r_ptr->flags1 & RF1_UNIQUE))
+               {
+                       if (r_ptr->flags1 & RF1_FRIENDS) power /= 2;
+               }
+               else power *= 2;
+
+               if (saving_throw(p_ptr->skill_sav * 100 / power))
+               {
+                       msg_format(_("夢の中で%sに追いかけられた。", "%^s chases you through your dreams."), m_name);
+                       /* Safe */
+                       return;
+               }
+
+               if (p_ptr->image)
+               {
+                       /* Something silly happens... */
+                       msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
+                                               funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
+
+                       if (one_in_(3))
+                       {
+                               msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
+                               p_ptr->image = p_ptr->image + randint1(r_ptr->level);
+                       }
+
+                       /* Never mind; we can't see it clearly enough */
+                       return;
+               }
+
+               /* Something frightening happens... */
+               msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
+                                 horror_desc[randint0(MAX_SAN_HORROR)], desc);
+
+               r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
+
+               if (!p_ptr->mimic_form)
+               {
+                       switch (p_ptr->prace)
+                       {
+                       /* Demons may make a saving throw */
+                       case RACE_IMP:
+                       case RACE_DEMON:
+                               if (saving_throw(20 + p_ptr->lev)) return;
+                               break;
+                       /* Undead may make a saving throw */
+                       case RACE_SKELETON:
+                       case RACE_ZOMBIE:
+                       case RACE_SPECTRE:
+                       case RACE_VAMPIRE:
+                               if (saving_throw(10 + p_ptr->lev)) return;
+                               break;
+                       }
+               }
+               else
+               {
+                       /* Demons may make a saving throw */
+                       if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)
+                       {
+                               if (saving_throw(20 + p_ptr->lev)) return;
+                       }
+                       /* Undead may make a saving throw */
+                       else if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD)
+                       {
+                               if (saving_throw(10 + p_ptr->lev)) return;
+                       }
+               }
+       }
        else
        {
                msg_print(_("ネクロノミコンを読んで正気を失った!", "Your sanity is shaken by reading the Necronomicon!"));
@@ -2181,7 +2285,7 @@ void sanity_blast(monster_type *m_ptr, bool necro)
  * @param m_idx 更新するモンスター情報のID
  * @param full プレイヤーとの距離更新を行うならばtrue
  * @return なし
- * @detail 
+ * @details
  * This involves extracting the distance to the player (if requested),
  * and then checking for visibility (natural, infravision, see-invis,
  * telepathy), updating the monster visibility flag, redrawing (or
@@ -2274,8 +2378,8 @@ void update_mon(int m_idx, bool full)
        if (full)
        {
                /* Distance components */
-               int dy = (py > fy) ? (py - fy) : (fy - py);
-               int dx = (px > fx) ? (px - fx) : (fx - px);
+               int dy = (p_ptr->y > fy) ? (p_ptr->y - fy) : (fy - p_ptr->y);
+               int dx = (p_ptr->x > fx) ? (p_ptr->x - fx) : (fx - p_ptr->x);
 
                /* Approximate distance */
                d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
@@ -2554,7 +2658,7 @@ void update_mon(int m_idx, bool full)
                        }
 
                        /* Disturb on appearance */
-                       if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, py, px) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
+                       if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)))
                        {
                                if (disturb_pets || is_hostile(m_ptr))
                                        disturb(1, 1);
@@ -2886,7 +2990,7 @@ static int initial_r_appearance(int r_idx)
 
 
 /*!
- * @brief モンスターの個体加速を設定する / Get initial monster spee\d
+ * @brief モンスターの個体加速を設定する / Get initial monster speed
  * @param r_ptr モンスター種族の参照ポインタ
  * @return 加速値
  */
@@ -2938,11 +3042,8 @@ static bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
 {
        /* Access the location */
        cave_type               *c_ptr = &cave[y][x];
-
        monster_type    *m_ptr;
-
        monster_race    *r_ptr = &r_info[r_idx];
-
        cptr            name = (r_name + r_ptr->name);
 
        int cmi;
@@ -3344,7 +3445,7 @@ static bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
 
 
 
-#define MON_SCAT_MAXD 10
+#define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
 
 /*!
  * @brief モンスター1体を目標地点に可能ながり近い位置に生成する / improved version of scatter() for place monster
@@ -3426,11 +3527,7 @@ static bool mon_scatter(int r_idx, int *yp, int *xp, int y, int x, int max_dist)
        return TRUE;
 }
 
-
-/*
- * Maximum size of a group of monsters
- */
-#define GROUP_MAX      32
+#define GROUP_MAX 32 /*!< place_monster_group() 関数によるモンスターのGROUP生成時の配置最大数 / Maximum size of a group of monsters */
 
 /*!
  * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
@@ -3522,11 +3619,18 @@ static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
        return (TRUE);
 }
 
-
-/*
- * Hack -- help pick an escort type
+/*!
+ * @var place_monster_idx
+ * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
+ * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
  */
 static int place_monster_idx = 0;
+
+/*!
+ * @var place_monster_m_idx
+ * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
+ * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
+ */
 static int place_monster_m_idx = 0;
 
 /*!
@@ -3534,7 +3638,7 @@ static int place_monster_m_idx = 0;
  * @param r_idx チェックするモンスター種族のID
  * @return 護衛にできるならばtrue
  */
-static bool place_monster_okay(int r_idx)
+static bool place_monster_can_escort(int r_idx)
 {
        monster_race *r_ptr = &r_info[place_monster_idx];
        monster_type *m_ptr = &m_list[place_monster_m_idx];
@@ -3650,7 +3754,7 @@ bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
                        if (!cave_empty_bold2(ny, nx)) continue;
 
                        /* Prepare allocation table */
-                       get_mon_num_prep(place_monster_okay, get_monster_hook2(ny, nx));
+                       get_mon_num_prep(place_monster_can_escort, get_monster_hook2(ny, nx));
 
                        /* Pick a random race */
                        z = get_mon_num(r_ptr->level);
@@ -3847,7 +3951,7 @@ bool alloc_monster(int dis, u32b mode)
                }
 
                /* Accept far away grids */
-               if (distance(y, x, py, px) > dis) break;
+               if (distance(y, x, p_ptr->y, p_ptr->x) > dis) break;
        }
 
        if (!attempts_left)
@@ -4532,8 +4636,8 @@ bool player_place(int y, int x)
        if (cave[y][x].m_idx != 0) return FALSE;
 
        /* Save player location */
-       py = y;
-       px = x;
+       p_ptr->y = y;
+       p_ptr->x = x;
 
        /* Success */
        return TRUE;