OSDN Git Service

[Refactor] #38997 get_mon_num() にplayer_type * 引数追加 / Added player_type * argument...
[hengband/hengband.git] / src / monster2.c
index 2b46895..0791752 100644 (file)
@@ -49,6 +49,8 @@
 MONSTER_IDX hack_m_idx = 0;    /* Hack -- see "process_monsters()" */
 MONSTER_IDX hack_m_idx_ii = 0;
 
+bool is_friendly_idx(player_type *player_ptr, MONSTER_IDX m_idx);
+
 /*!
  * @brief モンスターの目標地点をセットする / Set the target of counter attack
  * @param m_ptr モンスターの参照ポインタ
@@ -178,11 +180,12 @@ void delete_monster_idx(MONSTER_IDX i)
 
 /*!
  * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param i1 配列移動元添字
  * @param i2 配列移動先添字
  * @return なし
  */
-static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
+static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTER_IDX i2)
 {
        POSITION y, x;
        int i;
@@ -194,7 +197,7 @@ static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
        if (i1 == i2) return;
 
        /* Old monster */
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        m_ptr = &floor_ptr->m_list[i1];
 
        y = m_ptr->fy;
@@ -220,14 +223,14 @@ static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
        if (target_who == i1) target_who = i2;
 
        /* Hack -- Update the target */
-       if (p_ptr->pet_t_m_idx == i1) p_ptr->pet_t_m_idx = i2;
-       if (p_ptr->riding_t_m_idx == i1) p_ptr->riding_t_m_idx = i2;
+       if (player_ptr->pet_t_m_idx == i1) player_ptr->pet_t_m_idx = i2;
+       if (player_ptr->riding_t_m_idx == i1) player_ptr->riding_t_m_idx = i2;
 
        /* Hack -- Update the riding */
-       if (p_ptr->riding == i1) p_ptr->riding = i2;
+       if (player_ptr->riding == i1) player_ptr->riding = i2;
 
        /* Hack -- Update the health bar */
-       if (p_ptr->health_who == i1) health_track(p_ptr, i2);
+       if (player_ptr->health_who == i1) health_track(player_ptr, i2);
 
        /* Hack -- Update parent index */
        if (is_pet(m_ptr))
@@ -257,6 +260,7 @@ static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
 
 /*!
  * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param size 圧縮後のモンスター件数目標
  * @return なし
  * @details
@@ -269,7 +273,7 @@ static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
  * After "compacting" (if needed), we "reorder" the monsters into a more
  * compact order, and we reset the allocation info, and the "live" array.
  */
-void compact_monsters(int size)
+void compact_monsters(player_type *player_ptr, int size)
 {
        MONSTER_IDX i;
        int num, cnt;
@@ -279,7 +283,7 @@ void compact_monsters(int size)
        if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
 
        /* Compact at least 'size' objects */
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        for (num = 0, cnt = 1; num < size; cnt++)
        {
                /* Get more vicious each iteration */
@@ -301,7 +305,7 @@ void compact_monsters(int size)
                        /* Hack -- High level monsters start out "immune" */
                        if (r_ptr->level > cur_lev) continue;
 
-                       if (i == p_ptr->riding) continue;
+                       if (i == player_ptr->riding) continue;
 
                        /* Ignore nearby monsters */
                        if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
@@ -322,7 +326,7 @@ void compact_monsters(int size)
                        {
                                GAME_TEXT m_name[MAX_NLEN];
                                monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
-                               exe_write_diary(p_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
+                               exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
                        }
 
                        delete_monster_idx(i);
@@ -343,7 +347,7 @@ void compact_monsters(int size)
                if (m_ptr->r_idx) continue;
 
                /* Move last monster into open hole */
-               compact_monsters_aux(floor_ptr->m_max - 1, i);
+               compact_monsters_aux(player_ptr, floor_ptr->m_max - 1, i);
 
                /* Compress "floor_ptr->m_max" */
                floor_ptr->m_max--;
@@ -352,13 +356,15 @@ void compact_monsters(int size)
 
 
 /*!
+ * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
  * @brief プレイヤーのフロア離脱に伴う全モンスター配列の消去 / Delete/Remove all the monsters when the player leaves the level
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return なし
  * @details
  * This is an efficient method of simulating multiple calls to the
  * "delete_monster()" function, with no visual effects.
  */
-void wipe_m_list(void)
+void wipe_monsters_list(player_type *player_ptr)
 {
        int i;
 
@@ -382,7 +388,7 @@ void wipe_m_list(void)
        }
 
        /* Delete all the monsters */
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        for (i = floor_ptr->m_max - 1; i >= 1; i--)
        {
                monster_type *m_ptr = &floor_ptr->m_list[i];
@@ -418,25 +424,26 @@ void wipe_m_list(void)
 
        /* Hack -- no more target */
        target_who = 0;
-       p_ptr->pet_t_m_idx = 0;
-       p_ptr->riding_t_m_idx = 0;
+       player_ptr->pet_t_m_idx = 0;
+       player_ptr->riding_t_m_idx = 0;
 
-       health_track(p_ptr, 0);
+       health_track(player_ptr, 0);
 }
 
 
 /*!
+ * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
  * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
  * @return 利用可能なモンスター配列の添字
  * @details
  * This routine should almost never fail, but it *can* happen.
  */
-MONSTER_IDX m_pop(void)
+MONSTER_IDX m_pop(player_type *player_ptr)
 {
        MONSTER_IDX i;
 
        /* Normal allocation */
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (floor_ptr->m_max < current_world_ptr->max_m_idx)
        {
                /* Access the next hole */
@@ -476,8 +483,6 @@ MONSTER_IDX m_pop(void)
 }
 
 
-
-
 /*!
  * @var summon_specific_type
  * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
@@ -493,6 +498,7 @@ static int summon_specific_type = 0;
  */
 static int summon_specific_who = -1;
 
+
 /*!
  * @var summon_unique_okay
  * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
@@ -500,12 +506,14 @@ static int summon_specific_who = -1;
  */
 static bool summon_unique_okay = FALSE;
 
+
 /*!
  * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return 召喚条件が一致するならtrue
  * @details
  */
-static bool summon_specific_aux(MONRACE_IDX summoner_idx, MONRACE_IDX r_idx)
+static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_idx, MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
        int okay = FALSE;
@@ -650,7 +658,7 @@ static bool summon_specific_aux(MONRACE_IDX summoner_idx, MONRACE_IDX r_idx)
                }
                else
                {
-                       summon_kin_type = get_summon_symbol_from_player(p_ptr);
+                       summon_kin_type = get_summon_symbol_from_player(player_ptr);
                }
 
                okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
@@ -817,12 +825,15 @@ static int chameleon_change_m_idx = 0;
 
 
 /*!
+ * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
  * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param r_idx チェックするモンスター種族ID
  * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
  */
-static bool restrict_monster_to_dungeon(DUNGEON_IDX d_idx, MONRACE_IDX r_idx)
+static bool restrict_monster_to_dungeon(player_type *player_ptr, MONRACE_IDX r_idx)
 {
+       DUNGEON_IDX d_idx = player_ptr->dungeon_idx;
        dungeon_type *d_ptr = &d_info[d_idx];
        monster_race *r_ptr = &r_info[r_idx];
        byte a;
@@ -851,7 +862,7 @@ static bool restrict_monster_to_dungeon(DUNGEON_IDX d_idx, MONRACE_IDX r_idx)
                        return FALSE;
        }
 
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (d_ptr->flags1 & DF1_BEGINNER)
        {
                if (r_ptr->level > floor_ptr->dun_level)
@@ -1019,12 +1030,12 @@ monsterrace_hook_type get_mon_num2_hook;
 
 /*!
  * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param monster_hook 制限関数1
  * @param monster_hook2 制限関数2
  * @return エラーコード
  */
-errr get_mon_num_prep(monsterrace_hook_type monster_hook,
-       monsterrace_hook_type monster_hook2)
+errr get_mon_num_prep(player_type *player_ptr, monsterrace_hook_type monster_hook, monsterrace_hook_type monster_hook2)
 {
        int i;
 
@@ -1035,7 +1046,7 @@ errr get_mon_num_prep(monsterrace_hook_type monster_hook,
        get_mon_num2_hook = monster_hook2;
 
        /* Scan the allocation table */
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        for (i = 0; i < alloc_race_size; i++)
        {
                monster_race *r_ptr;
@@ -1051,7 +1062,7 @@ errr get_mon_num_prep(monsterrace_hook_type monster_hook,
                        (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
                        continue;
 
-               if (!p_ptr->phase_out && !chameleon_change_m_idx &&
+               if (!player_ptr->phase_out && !chameleon_change_m_idx &&
                        summon_specific_type != SUMMON_GUARDIANS)
                {
                        /* Hack -- don't create questors */
@@ -1071,9 +1082,9 @@ errr get_mon_num_prep(monsterrace_hook_type monster_hook,
                entry->prob2 = entry->prob1;
 
                if (floor_ptr->dun_level && (!floor_ptr->inside_quest || is_fixed_quest_idx(floor_ptr->inside_quest)) &&
-                       !restrict_monster_to_dungeon(p_ptr->dungeon_idx, entry->index) && !p_ptr->phase_out)
+                       !restrict_monster_to_dungeon(player_ptr, entry->index) && !player_ptr->phase_out)
                {
-                       int hoge = entry->prob2 * d_info[p_ptr->dungeon_idx].special_div;
+                       int hoge = entry->prob2 * d_info[player_ptr->dungeon_idx].special_div;
                        entry->prob2 = hoge / 64;
                        if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
                }
@@ -1086,6 +1097,7 @@ errr get_mon_num_prep(monsterrace_hook_type monster_hook,
 
 /*!
  * @brief 生成モンスター種族を1種生成テーブルから選択する
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param level 生成階
  * @return 選択されたモンスター生成種族
  * @details
@@ -1110,7 +1122,7 @@ errr get_mon_num_prep(monsterrace_hook_type monster_hook,
  * Note that if no monsters are "appropriate", then this function will
  * fail, and return zero, but this should *almost* never happen.
  */
-MONRACE_IDX get_mon_num(DEPTH level)
+MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level)
 {
        int i, j, p;
        MONRACE_IDX r_idx;
@@ -1124,7 +1136,7 @@ MONRACE_IDX get_mon_num(DEPTH level)
        pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10)));
        pls_level = MIN(NASTY_MON_PLUS_MAX, 3 + current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10));
 
-       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_MAZE)
+       if (d_info[player_ptr->dungeon_idx].flags1 & DF1_MAZE)
        {
                pls_kakuritu = MIN(pls_kakuritu / 2, pls_kakuritu - 10);
                if (pls_kakuritu < 2) pls_kakuritu = 2;
@@ -1133,7 +1145,7 @@ MONRACE_IDX get_mon_num(DEPTH level)
        }
 
        /* Boost the level */
-       if (!p_ptr->phase_out && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
+       if (!player_ptr->phase_out && !(d_info[player_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
        {
                /* Nightmare mode allows more out-of depth monsters */
                if (ironman_nightmare && !randint0(pls_kakuritu))
@@ -1173,7 +1185,7 @@ MONRACE_IDX get_mon_num(DEPTH level)
                /* Access the actual race */
                r_ptr = &r_info[r_idx];
 
-               if (!p_ptr->phase_out && !chameleon_change_m_idx)
+               if (!player_ptr->phase_out && !chameleon_change_m_idx)
                {
                        /* Hack -- "unique" monsters must be "unique" */
                        if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
@@ -2287,15 +2299,16 @@ static bool monster_hook_chameleon(MONRACE_IDX r_idx)
 
 /*!
  * @brief モンスターの変身処理
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param m_idx 変身処理を受けるモンスター情報のID
  * @param born 生成時の初変身先指定ならばtrue
  * @param r_idx 旧モンスター種族のID
  * @return なし
  */
-void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
+void choose_new_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
 {
        int oldmaxhp;
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        monster_type *m_ptr = &floor_ptr->m_list[m_idx];
        monster_race *r_ptr;
        char old_m_name[MAX_NLEN];
@@ -2315,20 +2328,20 @@ void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
 
                chameleon_change_m_idx = m_idx;
                if (old_unique)
-                       get_mon_num_prep(monster_hook_chameleon_lord, NULL);
+                       get_mon_num_prep(player_ptr, monster_hook_chameleon_lord, NULL);
                else
-                       get_mon_num_prep(monster_hook_chameleon, NULL);
+                       get_mon_num_prep(player_ptr, monster_hook_chameleon, NULL);
 
                if (old_unique)
                        level = r_info[MON_CHAMELEON_K].level;
                else if (!floor_ptr->dun_level)
-                       level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
+                       level = wilderness[player_ptr->wilderness_y][player_ptr->wilderness_x].level;
                else
                        level = floor_ptr->dun_level;
 
-               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level += 2 + randint1(3);
+               if (d_info[player_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level += 2 + randint1(3);
 
-               r_idx = get_mon_num(level);
+               r_idx = get_mon_num(player_ptr, level);
                r_ptr = &r_info[r_idx];
 
                chameleon_change_m_idx = 0;
@@ -2337,12 +2350,12 @@ void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
 
        m_ptr->r_idx = r_idx;
        m_ptr->ap_r_idx = r_idx;
-       update_monster(p_ptr, m_idx, FALSE);
+       update_monster(player_ptr, m_idx, FALSE);
        lite_spot(m_ptr->fy, m_ptr->fx);
 
        if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
                (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
-               p_ptr->update |= (PU_MON_LITE);
+               player_ptr->update |= (PU_MON_LITE);
 
        if (born)
        {
@@ -2356,13 +2369,13 @@ void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
                return;
        }
 
-       if (m_idx == p_ptr->riding)
+       if (m_idx == player_ptr->riding)
        {
                GAME_TEXT m_name[MAX_NLEN];
                monster_desc(m_name, m_ptr, 0);
                msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
                if (!(r_ptr->flags7 & RF7_RIDING))
-                       if (rakuba(p_ptr, 0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
+                       if (rakuba(player_ptr, 0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
        }
 
        /* Extract the monster base speed */
@@ -2418,11 +2431,12 @@ static bool monster_hook_tanuki(MONRACE_IDX r_idx)
 
 
 /*!
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
  * @param r_idx モンスター種族ID
  * @return モンスター種族の表層ID
  */
-static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
+static MONRACE_IDX initial_r_appearance(player_type *player_ptr, MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
 {
        floor_type *floor_ptr = p_ptr->current_floor_ptr;
        int attempts = 1000;
@@ -2438,11 +2452,11 @@ static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx, BIT_FLAGS generate_mo
        if (!(r_info[r_idx].flags7 & RF7_TANUKI))
                return r_idx;
 
-       get_mon_num_prep(monster_hook_tanuki, NULL);
+       get_mon_num_prep(player_ptr, monster_hook_tanuki, NULL);
 
        while (--attempts)
        {
-               ap_r_idx = get_mon_num(floor_ptr->base_level + 10);
+               ap_r_idx = get_mon_num(player_ptr, floor_ptr->base_level + 10);
                if (r_info[ap_r_idx].level >= min) return ap_r_idx;
        }
 
@@ -2476,6 +2490,7 @@ SPEED get_mspeed(monster_race *r_ptr)
 
 /*!
  * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param who 召喚を行ったモンスターID
  * @param y 生成位置y座標
  * @param x 生成位置x座標
@@ -2499,9 +2514,9 @@ SPEED get_mspeed(monster_race *r_ptr)
  * This is the only function which may place a monster in the dungeon,
  * except for the savefile loading code.
  */
-static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
+static bool place_monster_one(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
 {
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        grid_type               *g_ptr = &floor_ptr->grid_array[y][x];
        monster_type    *m_ptr;
        monster_race    *r_ptr = &r_info[r_idx];
@@ -2510,7 +2525,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
        int cmi;
 
        /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
-       if (p_ptr->wild_mode) return FALSE;
+       if (player_ptr->wild_mode) return FALSE;
 
        if (!in_bounds(floor_ptr, y, x)) return FALSE;
        if (!r_idx) return FALSE;
@@ -2525,7 +2540,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
                if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
        }
 
-       if (!p_ptr->phase_out)
+       if (!player_ptr->phase_out)
        {
                /* Hack -- "unique" monsters must be "unique" */
                if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
@@ -2557,9 +2572,9 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
                }
        }
 
-       if (quest_number(p_ptr, floor_ptr->dun_level))
+       if (quest_number(player_ptr, floor_ptr->dun_level))
        {
-               int hoge = quest_number(p_ptr, floor_ptr->dun_level);
+               int hoge = quest_number(player_ptr, floor_ptr->dun_level);
                if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
                {
                        if (r_idx == quest[hoge].r_idx)
@@ -2606,7 +2621,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
        if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
 
        /* Make a new monster */
-       g_ptr->m_idx = m_pop();
+       g_ptr->m_idx = m_pop(player_ptr);
        hack_m_idx_ii = g_ptr->m_idx;
 
        /* Mega-Hack -- catch "failure" */
@@ -2618,7 +2633,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, mode);
+       m_ptr->ap_r_idx = initial_r_appearance(player_ptr, r_idx, mode);
 
        /* No flags */
        m_ptr->mflag = 0;
@@ -2674,7 +2689,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
 
        if (r_ptr->flags7 & RF7_CHAMELEON)
        {
-               choose_new_monster(g_ptr->m_idx, TRUE, 0);
+               choose_new_monster(player_ptr, g_ptr->m_idx, TRUE, 0);
                r_ptr = &r_info[m_ptr->r_idx];
                m_ptr->mflag2 |= MFLAG2_CHAMELEON;
 
@@ -2696,11 +2711,11 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
        /* Pet? */
        if (mode & PM_FORCE_PET)
        {
-               set_pet(m_ptr);
+               set_pet(player_ptr, m_ptr);
        }
        /* Friendly? */
        else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
-               (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
+               (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(player_ptr, who))
        {
                if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
        }
@@ -2712,7 +2727,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
        if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
        {
                int val = r_ptr->sleep;
-               (void)set_monster_csleep(p_ptr, g_ptr->m_idx, (val * 2) + randint1(val * 10));
+               (void)set_monster_csleep(player_ptr, g_ptr->m_idx, (val * 2) + randint1(val * 10));
        }
 
        /* Assign maximal hitpoints */
@@ -2748,7 +2763,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
        /* Extract the monster base speed */
        m_ptr->mspeed = get_mspeed(r_ptr);
 
-       if (mode & PM_HASTE) (void)set_monster_fast(p_ptr, g_ptr->m_idx, 100);
+       if (mode & PM_HASTE) (void)set_monster_fast(player_ptr, g_ptr->m_idx, 100);
 
        /* Give a random starting energy */
        if (!ironman_nightmare)
@@ -2780,10 +2795,10 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
 
 
        if (r_ptr->flags7 & RF7_SELF_LD_MASK)
-               p_ptr->update |= (PU_MON_LITE);
+               player_ptr->update |= (PU_MON_LITE);
        else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
-               p_ptr->update |= (PU_MON_LITE);
-       update_monster(p_ptr, g_ptr->m_idx, TRUE);
+               player_ptr->update |= (PU_MON_LITE);
+       update_monster(player_ptr, g_ptr->m_idx, TRUE);
 
 
        /* Count the monsters on the level */
@@ -2795,12 +2810,12 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
         */
        if (current_world_ptr->character_dungeon &&
                ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
-               real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
+               real_r_ptr(m_ptr)->floor_id = player_ptr->floor_id;
 
        /* Hack -- Count the number of "reproducers" */
        if (r_ptr->flags2 & RF2_MULTIPLY) floor_ptr->num_repro++;
 
-       if (p_ptr->warning && current_world_ptr->character_dungeon)
+       if (player_ptr->warning && current_world_ptr->character_dungeon)
        {
                if (r_ptr->flags1 & RF1_UNIQUE)
                {
@@ -2808,20 +2823,20 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
                        object_type *o_ptr;
                        GAME_TEXT o_name[MAX_NLEN];
 
-                       if (r_ptr->level > p_ptr->lev + 30)
+                       if (r_ptr->level > player_ptr->lev + 30)
                                color = _("黒く", "black");
-                       else if (r_ptr->level > p_ptr->lev + 15)
+                       else if (r_ptr->level > player_ptr->lev + 15)
                                color = _("紫色に", "purple");
-                       else if (r_ptr->level > p_ptr->lev + 5)
+                       else if (r_ptr->level > player_ptr->lev + 5)
                                color = _("ルビー色に", "deep red");
-                       else if (r_ptr->level > p_ptr->lev - 5)
+                       else if (r_ptr->level > player_ptr->lev - 5)
                                color = _("赤く", "red");
-                       else if (r_ptr->level > p_ptr->lev - 15)
+                       else if (r_ptr->level > player_ptr->lev - 15)
                                color = _("ピンク色に", "pink");
                        else
                                color = _("白く", "white");
 
-                       o_ptr = choose_warning_item(p_ptr);
+                       o_ptr = choose_warning_item(player_ptr);
                        if (o_ptr)
                        {
                                object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
@@ -2843,7 +2858,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
                        if (g_ptr->info & CAVE_MARK)
                        {
                                msg_print(_("ルーンが爆発した!", "The rune explodes!"));
-                               project(p_ptr, 0, 2, y, x, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
+                               project(player_ptr, 0, 2, y, x, 2 * (player_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
                        }
                }
                else
@@ -2960,7 +2975,7 @@ static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION
  * @param mode 生成オプション
  * @return 成功したらtrue
  */
-static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
+static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -2977,7 +2992,7 @@ static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE
        total = randint1(10);
 
        /* Hard monsters, small groups */
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (r_ptr->level > floor_ptr->dun_level)
        {
                extra = r_ptr->level - floor_ptr->dun_level;
@@ -3021,13 +3036,13 @@ static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE
                {
                        POSITION mx, my;
 
-                       scatter(p_ptr, &my, &mx, hy, hx, 4, 0);
+                       scatter(player_ptr, &my, &mx, hy, hx, 4, 0);
 
                        /* Walls and Monsters block flow */
                        if (!cave_empty_bold2(floor_ptr, my, mx)) continue;
 
                        /* Attempt to place another monster */
-                       if (place_monster_one(who, my, mx, r_idx, mode))
+                       if (place_monster_one(player_ptr, who, my, mx, r_idx, mode))
                        {
                                /* Add it to the "hack" set */
                                hack_y[hack_n] = my;
@@ -3100,6 +3115,7 @@ static bool place_monster_can_escort(MONRACE_IDX r_idx)
 
 /*!
  * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param who 召喚主のモンスター情報ID
  * @param y 生成地点y座標
  * @param x 生成地点x座標
@@ -3122,7 +3138,7 @@ static bool place_monster_can_escort(MONRACE_IDX r_idx)
  * Note the use of the new "monster allocation table" code to restrict
  * the "get_mon_num()" function to "legal" escort types.
  */
-bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
+bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
 {
        int             i, j, n;
        monster_race    *r_ptr = &r_info[r_idx];
@@ -3131,7 +3147,7 @@ bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_id
                mode |= PM_KAGE;
 
        /* Place one monster, or fail */
-       if (!place_monster_one(who, y, x, r_idx, mode)) return FALSE;
+       if (!place_monster_one(player_ptr, who, y, x, r_idx, mode)) return FALSE;
 
        /* Require the "group" flag */
        if (!(mode & PM_ALLOW_GROUP)) return TRUE;
@@ -3146,8 +3162,8 @@ bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_id
                for (j = 0; j < n; j++)
                {
                        POSITION nx, ny, d = 7;
-                       scatter(p_ptr, &ny, &nx, y, x, d, 0);
-                       (void)place_monster_one(place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
+                       scatter(player_ptr, &ny, &nx, y, x, d, 0);
+                       (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
                }
        }
 
@@ -3155,7 +3171,7 @@ bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_id
        if (r_ptr->flags1 & (RF1_FRIENDS))
        {
                /* Attempt to place a group */
-               (void)place_monster_group(who, y, x, r_idx, mode);
+               (void)place_monster_group(player_ptr, who, y, x, r_idx, mode);
        }
 
        /* Escorts for certain monsters */
@@ -3171,27 +3187,27 @@ bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_id
                        MONRACE_IDX z;
 
                        /* Pick a location */
-                       scatter(p_ptr, &ny, &nx, y, x, d, 0);
+                       scatter(player_ptr, &ny, &nx, y, x, d, 0);
 
                        /* Require empty grids */
-                       if (!cave_empty_bold2(p_ptr->current_floor_ptr, ny, nx)) continue;
-                       get_mon_num_prep(place_monster_can_escort, get_monster_hook2(ny, nx));
+                       if (!cave_empty_bold2(player_ptr->current_floor_ptr, ny, nx)) continue;
+                       get_mon_num_prep(player_ptr, place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx));
 
                        /* Pick a random race */
-                       z = get_mon_num(r_ptr->level);
+                       z = get_mon_num(player_ptr, r_ptr->level);
 
                        /* Handle failure */
                        if (!z) break;
 
                        /* Place a single escort */
-                       (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
+                       (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, z, mode);
 
                        /* Place a "group" of escorts if needed */
                        if ((r_info[z].flags1 & RF1_FRIENDS) ||
                                (r_ptr->flags1 & RF1_ESCORTS))
                        {
                                /* Place a group of monsters */
-                               (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
+                               (void)place_monster_group(player_ptr, place_monster_m_idx, ny, nx, z, mode);
                        }
                }
        }
@@ -3202,35 +3218,37 @@ bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_id
 
 /*!
  * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y 生成地点y座標
  * @param x 生成地点x座標
  * @param mode 生成オプション
  * @return 生成に成功したらtrue
  */
-bool place_monster(POSITION y, POSITION x, BIT_FLAGS mode)
+bool place_monster(player_type *player_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
 {
        MONRACE_IDX r_idx;
-       get_mon_num_prep(get_monster_hook(p_ptr), get_monster_hook2(y, x));
+       get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
 
        /* Pick a monster */
-       r_idx = get_mon_num(p_ptr->current_floor_ptr->monster_level);
+       r_idx = get_mon_num(player_ptr, player_ptr->current_floor_ptr->monster_level);
 
        /* Handle failure */
        if (!r_idx) return FALSE;
 
        /* Attempt to place the monster */
-       if (place_monster_aux(0, y, x, r_idx, mode)) return TRUE;
+       if (place_monster_aux(player_ptr, 0, y, x, r_idx, mode)) return TRUE;
 
        return FALSE;
 }
 
 /*!
  * @brief 指定地点に1種類のモンスター種族による群れを生成する
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y 生成地点y座標
  * @param x 生成地点x座標
  * @return 生成に成功したらtrue
  */
-bool alloc_horde(POSITION y, POSITION x)
+bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x)
 {
        monster_race *r_ptr = NULL;
        MONRACE_IDX r_idx = 0;
@@ -3238,13 +3256,13 @@ bool alloc_horde(POSITION y, POSITION x)
        int attempts = 1000;
        POSITION cy = y;
        POSITION cx = x;
-       get_mon_num_prep(get_monster_hook(p_ptr), get_monster_hook2(y, x));
+       get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
 
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        while (--attempts)
        {
                /* Pick a monster */
-               r_idx = get_mon_num(floor_ptr->monster_level);
+               r_idx = get_mon_num(player_ptr, floor_ptr->monster_level);
 
                /* Handle failure */
                if (!r_idx) return FALSE;
@@ -3263,7 +3281,7 @@ bool alloc_horde(POSITION y, POSITION x)
        while (--attempts)
        {
                /* Attempt to place the monster */
-               if (place_monster_aux(0, y, x, r_idx, 0L)) break;
+               if (place_monster_aux(player_ptr, 0, y, x, r_idx, 0L)) break;
        }
 
        if (attempts < 1) return FALSE;
@@ -3274,9 +3292,9 @@ bool alloc_horde(POSITION y, POSITION x)
 
        for (attempts = randint1(10) + 5; attempts; attempts--)
        {
-               scatter(p_ptr, &cy, &cx, y, x, 5, 0);
+               scatter(player_ptr, &cy, &cx, y, x, 5, 0);
 
-               (void)summon_specific(m_idx, cy, cx, floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
+               (void)summon_specific(player_ptr, m_idx, cy, cx, floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
 
                y = cy;
                x = cx;
@@ -3288,15 +3306,16 @@ bool alloc_horde(POSITION y, POSITION x)
 
 /*!
  * @brief ダンジョンの主生成を試みる / Put the Guardian
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param def_val 現在の主の生成状態
  * @return 生成に成功したらtrue
  */
-bool alloc_guardian(bool def_val)
+bool alloc_guardian(player_type *player_ptr, bool def_val)
 {
-       MONRACE_IDX guardian = d_info[p_ptr->dungeon_idx].final_guardian;
+       MONRACE_IDX guardian = d_info[player_ptr->dungeon_idx].final_guardian;
 
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
-       if (guardian && (d_info[p_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       if (guardian && (d_info[player_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
        {
                POSITION oy;
                POSITION ox;
@@ -3313,7 +3332,7 @@ bool alloc_guardian(bool def_val)
                        if (cave_empty_bold2(floor_ptr, oy, ox) && monster_can_cross_terrain(floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0))
                        {
                                /* Place the guardian */
-                               if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
+                               if (place_monster_aux(player_ptr, 0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
                        }
 
                        /* One less try count */
@@ -3337,16 +3356,16 @@ bool alloc_guardian(bool def_val)
  * Use "slp" to choose the initial "sleep" status
  * Use "floor_ptr->monster_level" for the monster level
  */
-bool alloc_monster(POSITION dis, BIT_FLAGS mode)
+bool alloc_monster(player_type *player_ptr, POSITION dis, BIT_FLAGS mode)
 {
        POSITION y = 0, x = 0;
        int attempts_left = 10000;
 
        /* Put the Guardian */
-       if (alloc_guardian(FALSE)) return TRUE;
+       if (alloc_guardian(player_ptr, FALSE)) return TRUE;
 
        /* Find a legal, distant, unoccupied, space */
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        while (attempts_left--)
        {
                /* Pick a location */
@@ -3364,7 +3383,7 @@ bool alloc_monster(POSITION dis, BIT_FLAGS mode)
                }
 
                /* Accept far away grids */
-               if (distance(y, x, p_ptr->y, p_ptr->x) > dis) break;
+               if (distance(y, x, player_ptr->y, player_ptr->x) > dis) break;
        }
 
        if (!attempts_left)
@@ -3380,7 +3399,7 @@ bool alloc_monster(POSITION dis, BIT_FLAGS mode)
 
        if (randint1(5000) <= floor_ptr->dun_level)
        {
-               if (alloc_horde(y, x))
+               if (alloc_horde(player_ptr, y, x))
                {
                        return TRUE;
                }
@@ -3388,7 +3407,7 @@ bool alloc_monster(POSITION dis, BIT_FLAGS mode)
        else
        {
                /* Attempt to place the monster, allow groups */
-               if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return TRUE;
+               if (place_monster(player_ptr, y, x, (mode | PM_ALLOW_GROUP))) return TRUE;
        }
 
        return FALSE;
@@ -3439,12 +3458,13 @@ static bool summon_specific_okay(MONRACE_IDX r_idx)
 
        if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE;
 
-       return (summon_specific_aux(m_ptr->r_idx, r_idx));
+       return (summon_specific_aux(p_ptr, m_ptr->r_idx, r_idx));
 }
 
 
 /*!
  * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param who 召喚主のモンスター情報ID
  * @param y1 目標地点y座標
  * @param x1 目標地点x座標
@@ -3474,12 +3494,12 @@ static bool summon_specific_okay(MONRACE_IDX r_idx)
  *
  * Note that this function may not succeed, though this is very rare.
  */
-bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode)
+bool summon_specific(player_type *player_ptr, MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode)
 {
        POSITION x, y;
        MONRACE_IDX r_idx;
 
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (floor_ptr->inside_arena) return FALSE;
 
        if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
@@ -3491,10 +3511,10 @@ bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int t
        summon_specific_type = type;
 
        summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
-       get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
+       get_mon_num_prep(player_ptr, summon_specific_okay, get_monster_hook2(player_ptr, y, x));
 
        /* Pick a monster, using the level calculation */
-       r_idx = get_mon_num((floor_ptr->dun_level + lev) / 2 + 5);
+       r_idx = get_mon_num(player_ptr, (floor_ptr->dun_level + lev) / 2 + 5);
 
        /* Handle failure */
        if (!r_idx)
@@ -3506,7 +3526,7 @@ bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int t
        if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
 
        /* Attempt to place the monster (awake, allow groups) */
-       if (!place_monster_aux(who, y, x, r_idx, mode))
+       if (!place_monster_aux(player_ptr, who, y, x, r_idx, mode))
        {
                summon_specific_type = 0;
                return FALSE;
@@ -3521,6 +3541,7 @@ bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int t
 
 /*!
  * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param who 召喚主のモンスター情報ID
  * @param oy 目標地点y座標
  * @param ox 目標地点x座標
@@ -3528,7 +3549,7 @@ bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int t
  * @param mode 生成オプション
  * @return 召喚できたらtrueを返す
  */
-bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
+bool summon_named_creature(player_type *player_ptr, MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
 {
        POSITION x, y;
        /* if (!r_idx) return; */
@@ -3536,17 +3557,18 @@ bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_ID
        /* Prevent illegal monsters */
        if (r_idx >= max_r_idx) return FALSE;
 
-       if (p_ptr->current_floor_ptr->inside_arena) return FALSE;
+       if (player_ptr->current_floor_ptr->inside_arena) return FALSE;
 
        if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
 
        /* Place it (allow groups) */
-       return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
+       return place_monster_aux(player_ptr, who, y, x, r_idx, (mode | PM_NO_KAGE));
 }
 
 
 /*!
  * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param m_idx 増殖するモンスター情報ID
  * @param clone クローン・モンスター処理ならばtrue
  * @param mode 生成オプション
@@ -3554,9 +3576,9 @@ bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_ID
  * @details
  * Note that "reproduction" REQUIRES empty space.
  */
-bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
+bool multiply_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
 {
-       floor_type *floor_ptr = p_ptr->current_floor_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        monster_type *m_ptr = &floor_ptr->m_list[m_idx];
        POSITION y, x;
 
@@ -3566,7 +3588,7 @@ bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
        if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
 
        /* Create a new monster (awake, no groups) */
-       if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
+       if (!place_monster_aux(player_ptr, m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
                return FALSE;
 
        /* Hack -- Transfer "clone" flag */
@@ -3580,7 +3602,6 @@ bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
 }
 
 
-
 /*!
  * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
  * @param m_idx モンスター情報ID
@@ -4086,3 +4107,9 @@ int get_monster_crowd_number(MONSTER_IDX m_idx)
 
        return count;
 }
+
+
+bool is_friendly_idx(player_type *player_ptr, MONSTER_IDX m_idx)
+{
+       return m_idx > 0 && is_friendly(&player_ptr->current_floor_ptr->m_list[(m_idx)]);
+}