OSDN Git Service

[Refactor] #37353 cmd4.c を cmd-dump.c に改名して関数整理.
[hengband/hengband.git] / src / monster2.c
index 10dc955..40213be 100644 (file)
  */
 
 #include "angband.h"
+#include "util.h"
+
+#include "cmd-dump.h"
 #include "cmd-pet.h"
+#include "dungeon.h"
+#include "floor.h"
+#include "object-flavor.h"
 #include "monsterrace-hook.h"
 #include "monster-status.h"
-#include "projection.h"
 #include "monster.h"
+#include "spells.h"
 #include "spells-summon.h"
 #include "quest.h"
 #include "grid.h"
 #include "wild.h"
 #include "warning.h"
 #include "player-status.h"
+#include "monster-spell.h"
+#include "files.h"
+#include "view-mainwindow.h"
+#include "world.h"
+#include "monsterrace.h"
 
 #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
 #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
 
 
 /*!
- * @var horror_desc
- * @brief ELDRITCH HORROR効果時のモンスターの形容メッセージ(通常時)
- */
-concptr horror_desc[MAX_SAN_HORROR] =
-{
-#ifdef JP
-       "忌まわしい",
-       "底知れぬ",
-       "ぞっとする",
-       "破滅的な",
-       "冒涜的な",
-
-       "いやな",
-       "恐ろしい",
-       "不潔な",
-       "容赦のない",
-       "おぞましい",
-
-       "地獄の",
-       "身の毛もよだつ",
-       "地獄の",
-       "忌まわしい",
-       "悪夢のような",
-
-       "嫌悪を感じる",
-       "罰当たりな",
-       "恐い",
-       "不浄な",
-       "言うもおぞましい",
-#else
-       "abominable",
-       "abysmal",
-       "appalling",
-       "baleful",
-       "blasphemous",
-
-       "disgusting",
-       "dreadful",
-       "filthy",
-       "grisly",
-       "hideous",
-
-       "hellish",
-       "horrible",
-       "infernal",
-       "loathsome",
-       "nightmarish",
-
-       "repulsive",
-       "sacrilegious",
-       "terrible",
-       "unclean",
-       "unspeakable",
-#endif
-
-};
-
-/*!
- * @var funny_desc
- * @brief ELDRITCH HORROR効果時のモンスターの形容メッセージ(幻覚状態時)
- */
-concptr funny_desc[MAX_SAN_FUNNY] =
-{
-#ifdef JP
-       "間抜けな",
-       "滑稽な",
-       "ばからしい",
-       "無味乾燥な",
-       "馬鹿げた",
-
-       "笑える",
-       "ばかばかしい",
-       "ぶっとんだ",
-       "いかした",
-       "ポストモダンな",
-
-       "ファンタスティックな",
-       "ダダイズム的な",
-       "キュビズム的な",
-       "宇宙的な",
-       "卓越した",
-
-       "理解不能な",
-       "ものすごい",
-       "驚くべき",
-       "信じられない",
-       "カオティックな",
-
-       "野性的な",
-       "非常識な",
-#else
-       "silly",
-       "hilarious",
-       "absurd",
-       "insipid",
-       "ridiculous",
-
-       "laughable",
-       "ludicrous",
-       "far-out",
-       "groovy",
-       "postmodern",
-
-       "fantastic",
-       "dadaistic",
-       "cubistic",
-       "cosmic",
-       "awesome",
-
-       "incomprehensible",
-       "fabulous",
-       "amazing",
-       "incredible",
-       "chaotic",
-
-       "wild",
-       "preposterous",
-#endif
-
-};
-
-/*!
- * @var funny_comments
- * @brief ELDRITCH HORROR効果時の幻覚時間延長を示す錯乱表現
- */
-concptr funny_comments[MAX_SAN_COMMENT] =
-{
-#ifdef JP
-  /* nuke me */
-       "最高だぜ!",
-       "うひょー!",
-       "いかすぜ!",
-       "すんばらしい!",
-       "ぶっとびー!"
-#else
-       "Wow, cosmic, man!",
-       "Rad!",
-       "Groovy!",
-       "Cool!",
-       "Far out!"
-#endif
-
-};
-
-
-/*!
  * @brief モンスターの目標地点をセットする / Set the target of counter attack
  * @param m_ptr モンスターの参照ポインタ
  * @param y 目標y座標
@@ -287,19 +152,16 @@ void delete_monster_idx(MONSTER_IDX i)
                delete_object_idx(this_o_idx);
        }
 
-       if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, FALSE);
-
        (void)WIPE(m_ptr, monster_type);
 
        /* Count monsters */
-       m_cnt--;
+       current_floor_ptr->m_cnt--;
 
-       /* Visual update */
        lite_spot(y, x);
-
-       /* Update some things */
        if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
+       {
                p_ptr->update |= (PU_MON_LITE);
+       }
 }
 
 
@@ -312,8 +174,6 @@ void delete_monster_idx(MONSTER_IDX i)
 void delete_monster(POSITION y, POSITION x)
 {
        grid_type *g_ptr;
-
-       /* Paranoia */
        if (!in_bounds(y, x)) return;
 
        /* Check the grid */
@@ -330,7 +190,7 @@ void delete_monster(POSITION y, POSITION x)
  * @param i2 配列移動先添字
  * @return なし
  */
-static void compact_monsters_aux(IDX i1, IDX i2)
+static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
 {
        POSITION y, x;
        int i;
@@ -380,7 +240,7 @@ static void compact_monsters_aux(IDX i1, IDX i2)
        /* Hack -- Update parent index */
        if (is_pet(m_ptr))
        {
-               for (i = 1; i < m_max; i++)
+               for (i = 1; i < current_floor_ptr->m_max; i++)
                {
                        monster_type *m2_ptr = &current_floor_ptr->m_list[i];
 
@@ -437,7 +297,7 @@ void compact_monsters(int size)
                cur_dis = 5 * (20 - cnt);
 
                /* Check all the monsters */
-               for (i = 1; i < m_max; i++)
+               for (i = 1; i < current_floor_ptr->m_max; i++)
                {
                        monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
@@ -482,7 +342,7 @@ void compact_monsters(int size)
 
 
        /* Excise dead monsters (backwards!) */
-       for (i = m_max - 1; i >= 1; i--)
+       for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
        {
                /* Get the i'th monster */
                monster_type *m_ptr = &current_floor_ptr->m_list[i];
@@ -491,10 +351,10 @@ void compact_monsters(int size)
                if (m_ptr->r_idx) continue;
 
                /* Move last monster into open hole */
-               compact_monsters_aux(m_max - 1, i);
+               compact_monsters_aux(current_floor_ptr->m_max - 1, i);
 
-               /* Compress "m_max" */
-               m_max--;
+               /* Compress "current_floor_ptr->m_max" */
+               current_floor_ptr->m_max--;
        }
 }
 
@@ -530,7 +390,7 @@ void wipe_m_list(void)
        }
 
        /* Delete all the monsters */
-       for (i = m_max - 1; i >= 1; i--)
+       for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
        {
                monster_type *m_ptr = &current_floor_ptr->m_list[i];
                if (!monster_is_valid(m_ptr)) continue;
@@ -551,11 +411,11 @@ void wipe_m_list(void)
        /* Hack -- Wipe the racial counter of all monster races */
        for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
 
-       /* Reset "m_max" */
-       m_max = 1;
+       /* Reset "current_floor_ptr->m_max" */
+       current_floor_ptr->m_max = 1;
 
-       /* Reset "m_cnt" */
-       m_cnt = 0;
+       /* Reset "current_floor_ptr->m_cnt" */
+       current_floor_ptr->m_cnt = 0;
 
        /* Reset "current_floor_ptr->mproc_max[]" */
        for (i = 0; i < MAX_MTIMED; i++) current_floor_ptr->mproc_max[i] = 0;
@@ -584,23 +444,23 @@ MONSTER_IDX m_pop(void)
        MONSTER_IDX i;
 
        /* Normal allocation */
-       if (m_max < current_floor_ptr->max_m_idx)
+       if (current_floor_ptr->m_max < current_floor_ptr->max_m_idx)
        {
                /* Access the next hole */
-               i = m_max;
+               i = current_floor_ptr->m_max;
 
                /* Expand the array */
-               m_max++;
+               current_floor_ptr->m_max++;
 
                /* Count monsters */
-               m_cnt++;
+               current_floor_ptr->m_cnt++;
 
                /* Return the index */
                return (i);
        }
 
        /* Recycle dead monsters */
-       for (i = 1; i < m_max; i++)
+       for (i = 1; i < current_floor_ptr->m_max; i++)
        {
                monster_type *m_ptr;
 
@@ -611,7 +471,7 @@ MONSTER_IDX m_pop(void)
                if (m_ptr->r_idx) continue;
 
                /* Count monsters */
-               m_cnt++;
+               current_floor_ptr->m_cnt++;
 
                /* Use this monster */
                return (i);
@@ -1729,6 +1589,16 @@ void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
        }
 }
 
+/*!
+* @brief モンスターIDを取り、モンスター名をm_nameに代入する /
+* @param m_idx モンスターID
+* @param m_name モンスター名を入力する配列
+*/
+void monster_name(MONSTER_IDX m_idx, char* m_name)
+{
+       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_desc(m_name, m_ptr, 0x00);
+}
 
 
 /*!
@@ -1950,8 +1820,6 @@ void update_monster(MONSTER_IDX m_idx, bool full)
        bool do_disturb = disturb_move;
 
        POSITION d;
-
-       /* Current location */
        POSITION fy = m_ptr->fy;
        POSITION fx = m_ptr->fx;
 
@@ -1999,11 +1867,9 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                d = m_ptr->cdis;
        }
 
-
        /* Detected */
        if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
 
-
        /* Nearby */
        if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
        {
@@ -2236,7 +2102,6 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                                        r_ptr->r_sights++;
                        }
 
-                       /* Eldritch Horror */
                        if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
                        {
                                sanity_blast(m_ptr, FALSE);
@@ -2325,7 +2190,7 @@ void update_monsters(bool full)
        MONSTER_IDX i;
 
        /* Update each (live) monster */
-       for (i = 1; i < m_max; i++)
+       for (i = 1; i < current_floor_ptr->m_max; i++)
        {
                monster_type *m_ptr = &current_floor_ptr->m_list[i];
                if (!monster_is_valid(m_ptr)) continue;
@@ -2374,6 +2239,7 @@ static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
  * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
  * @param r_idx モンスター種族ID
  * @return 対象にできるならtrueを返す
+ * @todo グローバル変数対策の上 monster_hook.cへ移す。
  */
 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
 {
@@ -2453,13 +2319,9 @@ void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
                r_ptr = &r_info[r_idx];
 
                chameleon_change_m_idx = 0;
-
-               /* Paranoia */
                if (!r_idx) return;
        }
 
-       if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, FALSE);
-
        m_ptr->r_idx = r_idx;
        m_ptr->ap_r_idx = r_idx;
        update_monster(m_idx, FALSE);
@@ -2469,8 +2331,6 @@ void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
            (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
                p_ptr->update |= (PU_MON_LITE);
 
-       if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, TRUE);
-
        if (born)
        {
                /* Sub-alignment of a chameleon */
@@ -2526,6 +2386,7 @@ void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
  * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
  * @param r_idx モンスター種族ID
  * @return 対象にできるならtrueを返す
+ * @todo グローバル変数対策の上 monster_hook.cへ移す。
  */
 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
 {
@@ -2548,13 +2409,13 @@ static bool monster_hook_tanuki(MONRACE_IDX r_idx)
  * @param r_idx モンスター種族ID
  * @return モンスター種族の表層ID
  */
-static IDX initial_r_appearance(MONRACE_IDX r_idx)
+static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
 {
        int attempts = 1000;
-       IDX ap_r_idx;
-       DEPTH min = MIN(current_floor_ptr->base_level-5, 50);
+       MONRACE_IDX ap_r_idx;
+       DEPTH min = MIN(current_floor_ptr->base_level - 5, 50);
 
-       if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN)
+       if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN && !(generate_mode & (PM_MULTIPLY | PM_KAGE)))
        {
                if (current_floor_ptr->base_level == 0 || one_in_(5)) return MON_ALIEN_JURAL;
        }
@@ -2579,10 +2440,10 @@ static IDX initial_r_appearance(MONRACE_IDX r_idx)
  * @param r_ptr モンスター種族の参照ポインタ
  * @return 加速値
  */
-byte get_mspeed(monster_race *r_ptr)
+SPEED get_mspeed(monster_race *r_ptr)
 {
        /* Extract the monster base speed */
-       int mspeed = r_ptr->speed;
+       SPEED mspeed = r_ptr->speed;
 
        /* Hack -- small racial variety */
        if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
@@ -2594,7 +2455,7 @@ byte get_mspeed(monster_race *r_ptr)
 
        if (mspeed > 199) mspeed = 199;
 
-       return (byte)mspeed;
+       return mspeed;
 }
 
 
@@ -2625,7 +2486,6 @@ byte get_mspeed(monster_race *r_ptr)
  */
 static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
 {
-       /* Access the location */
        grid_type               *g_ptr = &current_floor_ptr->grid_array[y][x];
        monster_type    *m_ptr;
        monster_race    *r_ptr = &r_info[r_idx];
@@ -2636,13 +2496,8 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
        /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
        if (p_ptr->wild_mode) return FALSE;
 
-       /* Verify location */
        if (!in_bounds(y, x)) return (FALSE);
-
-       /* Paranoia */
        if (!r_idx) return (FALSE);
-
-       /* Paranoia */
        if (!r_ptr->name) return (FALSE);
 
        if (!(mode & PM_IGNORE_TERRAIN))
@@ -2747,7 +2602,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
 
        /* Save the race */
        m_ptr->r_idx = r_idx;
-       m_ptr->ap_r_idx = initial_r_appearance(r_idx);
+       m_ptr->ap_r_idx = initial_r_appearance(r_idx, mode);
 
        /* No flags */
        m_ptr->mflag = 0;
@@ -3663,8 +3518,6 @@ bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int t
 bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
 {
        POSITION x, y;
-
-       /* Paranoia */
        /* if (!r_idx) return; */
 
        /* Prevent illegal monsters */
@@ -4176,7 +4029,6 @@ void monster_drop_carried_objects(monster_type *m_ptr)
                next_o_idx = o_ptr->next_o_idx;
                q_ptr = &forge;
 
-               /* Copy the object */
                object_copy(q_ptr, o_ptr);
 
                /* Forget monster */
@@ -4191,3 +4043,31 @@ void monster_drop_carried_objects(monster_type *m_ptr)
        /* Forget objects */
        m_ptr->hold_o_idx = 0;
 }
+
+/*!
+ * @brief 指定したモンスターに隣接しているモンスターの数を返す。
+ * / Count number of adjacent monsters
+ * @param m_idx 隣接数を調べたいモンスターのID
+ * @return 隣接しているモンスターの数
+ */
+int get_monster_crowd_number(MONSTER_IDX m_idx)
+{
+       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       POSITION my = m_ptr->fy;
+       POSITION mx = m_ptr->fx;
+       int i;
+       int count = 0;
+
+       for (i = 0; i < 7; i++)
+       {
+               int ay = my + ddy_ddd[i];
+               int ax = mx + ddx_ddd[i];
+
+               if (!in_bounds(ay, ax)) continue;
+
+               /* Count number of monsters */
+               if (current_floor_ptr->grid_array[ay][ax].m_idx > 0) count++;
+       }
+
+       return count;
+}
\ No newline at end of file