OSDN Git Service

[Refactor] #37353 cmd4.c を cmd-dump.c に改名して関数整理.
[hengband/hengband.git] / src / monster2.c
index a7d7976..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 "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なモンスターの生成を禁止する? */
@@ -145,7 +155,7 @@ void delete_monster_idx(MONSTER_IDX i)
        (void)WIPE(m_ptr, monster_type);
 
        /* Count monsters */
-       m_cnt--;
+       current_floor_ptr->m_cnt--;
 
        lite_spot(y, x);
        if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
@@ -230,7 +240,7 @@ static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_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];
 
@@ -287,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];
 
@@ -332,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];
@@ -341,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--;
        }
 }
 
@@ -380,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;
@@ -401,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;
@@ -434,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;
 
@@ -461,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);
@@ -1810,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;
 
@@ -1859,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))
        {
@@ -2096,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);
@@ -2185,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;
@@ -2491,7 +2496,6 @@ 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);
        if (!r_idx) return (FALSE);
        if (!r_ptr->name) return (FALSE);
@@ -4025,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 */
@@ -4040,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