OSDN Git Service

[Refactor] #37353 cmd4.c を cmd-dump.c に改名して関数整理.
[hengband/hengband.git] / src / monster2.c
index 37854d3..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 "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なモンスターの生成を禁止する? */
@@ -144,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))
@@ -229,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];
 
@@ -286,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];
 
@@ -331,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];
@@ -340,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--;
        }
 }
 
@@ -379,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;
@@ -400,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;
@@ -433,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;
 
@@ -460,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);
@@ -2179,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;
@@ -4018,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 */
@@ -4033,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