OSDN Git Service

[Refactor] #37353 inside_arena を player_type から floor_type へ移動. / Move inside_arena...
[hengband/hengband.git] / src / monster2.c
index 0bc5a70..11a0ef4 100644 (file)
@@ -12,7 +12,9 @@
 
 #include "angband.h"
 #include "util.h"
+#include "core.h"
 
+#include "cmd-dump.h"
 #include "cmd-pet.h"
 #include "dungeon.h"
 #include "floor.h"
 #include "quest.h"
 #include "grid.h"
 #include "player-move.h"
+#include "player-status.h"
+#include "player-race.h"
+#include "player-class.h"
+#include "player-personality.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"
+#include "creature.h"
+#include "targeting.h"
+#include "realm-song.h"
+#include "melee.h"
 
 #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
 #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
 
+MONSTER_IDX hack_m_idx = 0;    /* Hack -- see "process_monsters()" */
+MONSTER_IDX hack_m_idx_ii = 0;
 
 /*!
  * @brief モンスターの目標地点をセットする / Set the target of counter attack
@@ -101,7 +114,7 @@ MONRACE_IDX real_r_idx(monster_type *m_ptr)
 void delete_monster_idx(MONSTER_IDX i)
 {
        POSITION x, y;
-       monster_type *m_ptr = &current_floor_ptr->m_list[i];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
        OBJECT_IDX this_o_idx, next_o_idx = 0;
 
@@ -112,7 +125,7 @@ void delete_monster_idx(MONSTER_IDX i)
        real_r_ptr(m_ptr)->cur_num--;
 
        /* Hack -- count the number of "reproducers" */
-       if (r_ptr->flags2 & (RF2_MULTIPLY)) current_floor_ptr->num_repro--;
+       if (r_ptr->flags2 & (RF2_MULTIPLY)) p_ptr->current_floor_ptr->num_repro--;
 
        if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(i, 0);
        if (MON_FAST(m_ptr)) (void)set_monster_fast(i, 0);
@@ -128,17 +141,17 @@ void delete_monster_idx(MONSTER_IDX i)
        /* Hack -- remove tracked monster */
        if (i == p_ptr->health_who) health_track(0);
 
-       if (pet_t_m_idx == i ) pet_t_m_idx = 0;
-       if (riding_t_m_idx == i) riding_t_m_idx = 0;
+       if (p_ptr->pet_t_m_idx == i ) p_ptr->pet_t_m_idx = 0;
+       if (p_ptr->riding_t_m_idx == i) p_ptr->riding_t_m_idx = 0;
        if (p_ptr->riding == i) p_ptr->riding = 0;
 
        /* Monster is gone */
-       current_floor_ptr->grid_array[y][x].m_idx = 0;
+       p_ptr->current_floor_ptr->grid_array[y][x].m_idx = 0;
 
        for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
-               o_ptr = &current_floor_ptr->o_list[this_o_idx];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                next_o_idx = o_ptr->next_o_idx;
 
                /*
@@ -152,7 +165,7 @@ void delete_monster_idx(MONSTER_IDX i)
        (void)WIPE(m_ptr, monster_type);
 
        /* Count monsters */
-       m_cnt--;
+       p_ptr->current_floor_ptr->m_cnt--;
 
        lite_spot(y, x);
        if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
@@ -171,10 +184,10 @@ void delete_monster_idx(MONSTER_IDX i)
 void delete_monster(POSITION y, POSITION x)
 {
        grid_type *g_ptr;
-       if (!in_bounds(y, x)) return;
+       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
 
        /* Check the grid */
-       g_ptr = &current_floor_ptr->grid_array[y][x];
+       g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
        /* Delete the monster (if any) */
        if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
@@ -199,22 +212,22 @@ static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
        if (i1 == i2) return;
 
        /* Old monster */
-       m_ptr = &current_floor_ptr->m_list[i1];
+       m_ptr = &p_ptr->current_floor_ptr->m_list[i1];
 
        y = m_ptr->fy;
        x = m_ptr->fx;
 
        /* Cave grid */
-       g_ptr = &current_floor_ptr->grid_array[y][x];
+       g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
-       /* Update the current_floor_ptr->grid_array */
+       /* Update the p_ptr->current_floor_ptr->grid_array */
        g_ptr->m_idx = i2;
 
        /* Repair objects being carried by monster */
        for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
-               o_ptr = &current_floor_ptr->o_list[this_o_idx];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                next_o_idx = o_ptr->next_o_idx;
 
                /* Reset monster pointer */
@@ -225,8 +238,8 @@ static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
        if (target_who == i1) target_who = i2;
 
        /* Hack -- Update the target */
-       if (pet_t_m_idx == i1) pet_t_m_idx = i2;
-       if (riding_t_m_idx == i1) riding_t_m_idx = i2;
+       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;
 
        /* Hack -- Update the riding */
        if (p_ptr->riding == i1) p_ptr->riding = i2;
@@ -237,9 +250,9 @@ 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 < p_ptr->current_floor_ptr->m_max; i++)
                {
-                       monster_type *m2_ptr = &current_floor_ptr->m_list[i];
+                       monster_type *m2_ptr = &p_ptr->current_floor_ptr->m_list[i];
 
                        if (m2_ptr->parent_m_idx == i1)
                                m2_ptr->parent_m_idx = i2;
@@ -247,15 +260,15 @@ static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
        }
 
        /* Structure copy */
-       (void)COPY(&current_floor_ptr->m_list[i2], &current_floor_ptr->m_list[i1], monster_type);
+       (void)COPY(&p_ptr->current_floor_ptr->m_list[i2], &p_ptr->current_floor_ptr->m_list[i1], monster_type);
 
        /* Wipe the hole */
-       (void)WIPE(&current_floor_ptr->m_list[i1], monster_type);
+       (void)WIPE(&p_ptr->current_floor_ptr->m_list[i1], monster_type);
 
        for (i = 0; i < MAX_MTIMED; i++)
        {
                int mproc_idx = get_mproc_idx(i1, i);
-               if (mproc_idx >= 0) current_floor_ptr->mproc_list[i][mproc_idx] = i2;
+               if (mproc_idx >= 0) p_ptr->current_floor_ptr->mproc_list[i][mproc_idx] = i2;
        }
 }
 
@@ -294,9 +307,9 @@ 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 < p_ptr->current_floor_ptr->m_max; i++)
                {
-                       monster_type *m_ptr = &current_floor_ptr->m_list[i];
+                       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i];
 
                        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
@@ -327,7 +340,7 @@ void compact_monsters(int size)
                        {
                                GAME_TEXT m_name[MAX_NLEN];
                                monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
-                               do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
+                               exe_write_diary(p_ptr, NIKKI_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
                        }
 
                        delete_monster_idx(i);
@@ -339,19 +352,19 @@ void compact_monsters(int size)
 
 
        /* Excise dead monsters (backwards!) */
-       for (i = m_max - 1; i >= 1; i--)
+       for (i = p_ptr->current_floor_ptr->m_max - 1; i >= 1; i--)
        {
                /* Get the i'th monster */
-               monster_type *m_ptr = &current_floor_ptr->m_list[i];
+               monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i];
 
                /* Skip real monsters */
                if (m_ptr->r_idx) continue;
 
                /* Move last monster into open hole */
-               compact_monsters_aux(m_max - 1, i);
+               compact_monsters_aux(p_ptr->current_floor_ptr->m_max - 1, i);
 
-               /* Compress "m_max" */
-               m_max--;
+               /* Compress "p_ptr->current_floor_ptr->m_max" */
+               p_ptr->current_floor_ptr->m_max--;
        }
 }
 
@@ -387,13 +400,13 @@ void wipe_m_list(void)
        }
 
        /* Delete all the monsters */
-       for (i = m_max - 1; i >= 1; i--)
+       for (i = p_ptr->current_floor_ptr->m_max - 1; i >= 1; i--)
        {
-               monster_type *m_ptr = &current_floor_ptr->m_list[i];
+               monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i];
                if (!monster_is_valid(m_ptr)) continue;
 
                /* Monster is gone */
-               current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx = 0;
+               p_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx = 0;
 
                (void)WIPE(m_ptr, monster_type);
 
@@ -408,22 +421,22 @@ 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 "p_ptr->current_floor_ptr->m_max" */
+       p_ptr->current_floor_ptr->m_max = 1;
 
-       /* Reset "m_cnt" */
-       m_cnt = 0;
+       /* Reset "p_ptr->current_floor_ptr->m_cnt" */
+       p_ptr->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;
+       /* Reset "p_ptr->current_floor_ptr->mproc_max[]" */
+       for (i = 0; i < MAX_MTIMED; i++) p_ptr->current_floor_ptr->mproc_max[i] = 0;
 
        /* Hack -- reset "reproducer" count */
-       current_floor_ptr->num_repro = 0;
+       p_ptr->current_floor_ptr->num_repro = 0;
 
        /* Hack -- no more target */
        target_who = 0;
-       pet_t_m_idx = 0;
-       riding_t_m_idx = 0;
+       p_ptr->pet_t_m_idx = 0;
+       p_ptr->riding_t_m_idx = 0;
 
        /* Hack -- no more tracking */
        health_track(0);
@@ -441,41 +454,39 @@ MONSTER_IDX m_pop(void)
        MONSTER_IDX i;
 
        /* Normal allocation */
-       if (m_max < current_floor_ptr->max_m_idx)
+       if (p_ptr->current_floor_ptr->m_max < current_world_ptr->max_m_idx)
        {
                /* Access the next hole */
-               i = m_max;
+               i = p_ptr->current_floor_ptr->m_max;
 
                /* Expand the array */
-               m_max++;
+               p_ptr->current_floor_ptr->m_max++;
 
                /* Count monsters */
-               m_cnt++;
+               p_ptr->current_floor_ptr->m_cnt++;
 
                /* Return the index */
                return (i);
        }
 
        /* Recycle dead monsters */
-       for (i = 1; i < m_max; i++)
+       for (i = 1; i < p_ptr->current_floor_ptr->m_max; i++)
        {
                monster_type *m_ptr;
-
-               /* Acquire monster */
-               m_ptr = &current_floor_ptr->m_list[i];
+               m_ptr = &p_ptr->current_floor_ptr->m_list[i];
 
                /* Skip live monsters */
                if (m_ptr->r_idx) continue;
 
                /* Count monsters */
-               m_cnt++;
+               p_ptr->current_floor_ptr->m_cnt++;
 
                /* Use this monster */
                return (i);
        }
 
        /* Warn the player (except during dungeon creation) */
-       if (character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
+       if (current_world_ptr->character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
 
        /* Try not to crash */
        return (0);
@@ -511,7 +522,7 @@ static bool summon_unique_okay = FALSE;
  * @return 召喚条件が一致するならtrue
  * @details
  */
-static bool summon_specific_aux(MONRACE_IDX r_idx)
+static bool summon_specific_aux(MONRACE_IDX summoner_idx, MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
        int okay = FALSE;
@@ -649,6 +660,16 @@ static bool summon_specific_aux(MONRACE_IDX r_idx)
 
                case SUMMON_KIN:
                {
+                       SYMBOL_CODE summon_kin_type;
+                       if (summoner_idx)
+                       {
+                               summon_kin_type = r_info[summoner_idx].d_char;
+                       }
+                       else
+                       {
+                               summon_kin_type = get_summon_symbol_from_player(p_ptr);
+                       }
+
                        okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
                        break;
                }
@@ -817,9 +838,9 @@ static int chameleon_change_m_idx = 0;
  * @param r_idx チェックするモンスター種族ID
  * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
  */
-static bool restrict_monster_to_dungeon(MONRACE_IDX r_idx)
+static bool restrict_monster_to_dungeon(DUNGEON_IDX d_idx, MONRACE_IDX r_idx)
 {
-       dungeon_type *d_ptr = &d_info[p_ptr->dungeon_idx];
+       dungeon_type *d_ptr = &d_info[d_idx];
        monster_race *r_ptr = &r_info[r_idx];
        byte a;
 
@@ -846,7 +867,7 @@ static bool restrict_monster_to_dungeon(MONRACE_IDX r_idx)
        }
        if (d_ptr->flags1 & DF1_BEGINNER)
        {
-               if (r_ptr->level > current_floor_ptr->dun_level)
+               if (r_ptr->level > p_ptr->current_floor_ptr->dun_level)
                        return FALSE;
        }
 
@@ -1003,6 +1024,12 @@ static bool restrict_monster_to_dungeon(MONRACE_IDX r_idx)
        return TRUE;
 }
 
+/*
+ * Hack -- function hooks to restrict "get_mon_num_prep()" function
+ */
+monsterrace_hook_type get_mon_num_hook;
+monsterrace_hook_type get_mon_num2_hook;
+
 /*!
  * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
  * @param monster_hook 制限関数1
@@ -1036,7 +1063,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->inside_battle && !chameleon_change_m_idx &&
+               if (!p_ptr->phase_out && !chameleon_change_m_idx &&
                    summon_specific_type != SUMMON_GUARDIANS)
                {
                        /* Hack -- don't create questors */
@@ -1048,14 +1075,15 @@ errr get_mon_num_prep(monsterrace_hook_type monster_hook,
 
                        /* Depth Monsters never appear out of depth */
                        if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
-                           (r_ptr->level > current_floor_ptr->dun_level))
+                           (r_ptr->level > p_ptr->current_floor_ptr->dun_level))
                                continue;
                }
 
                /* Accept this monster */
                entry->prob2 = entry->prob1;
 
-               if (current_floor_ptr->dun_level && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest)) && !restrict_monster_to_dungeon(entry->index) && !p_ptr->inside_battle)
+               if (p_ptr->current_floor_ptr->dun_level && (!p_ptr->current_floor_ptr->inside_quest || is_fixed_quest_idx(p_ptr->current_floor_ptr->inside_quest)) &&
+                       !restrict_monster_to_dungeon(p_ptr->dungeon_idx, entry->index) && !p_ptr->phase_out)
                {
                        int hoge = entry->prob2 * d_info[p_ptr->dungeon_idx].special_div;
                        entry->prob2 = hoge / 64;
@@ -1117,7 +1145,7 @@ MONRACE_IDX get_mon_num(DEPTH level)
        }
 
        /* Boost the level */
-       if (!p_ptr->inside_battle && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
+       if (!p_ptr->phase_out && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
        {
                /* Nightmare mode allows more out-of depth monsters */
                if (ironman_nightmare && !randint0(pls_kakuritu))
@@ -1157,7 +1185,7 @@ MONRACE_IDX get_mon_num(DEPTH level)
                /* Access the actual race */
                r_ptr = &r_info[r_idx];
 
-               if (!p_ptr->inside_battle && !chameleon_change_m_idx)
+               if (!p_ptr->phase_out && !chameleon_change_m_idx)
                {
                        /* Hack -- "unique" monsters must be "unique" */
                        if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
@@ -1507,8 +1535,8 @@ void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
                        }
 
                        /* Inside monster arena, and it is not your mount */
-                       else if (p_ptr->inside_battle &&
-                                !(p_ptr->riding && (&current_floor_ptr->m_list[p_ptr->riding] == m_ptr)))
+                       else if (p_ptr->phase_out &&
+                                !(p_ptr->riding && (&p_ptr->current_floor_ptr->m_list[p_ptr->riding] == m_ptr)))
                        {
                                /* It is a fake unique monster */
                                (void)sprintf(desc, _("%sもどき", "fake %s"), name);
@@ -1553,7 +1581,7 @@ void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
                        strcat(desc,buf);
                }
 
-               if (p_ptr->riding && (&current_floor_ptr->m_list[p_ptr->riding] == m_ptr))
+               if (p_ptr->riding && (&p_ptr->current_floor_ptr->m_list[p_ptr->riding] == m_ptr))
                {
                        strcat(desc,_("(乗馬中)", "(riding)"));
                }
@@ -1593,7 +1621,7 @@ void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
 */
 void monster_name(MONSTER_IDX m_idx, char* m_name)
 {
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        monster_desc(m_name, m_ptr, 0x00);
 }
 
@@ -1724,7 +1752,7 @@ int lore_do_probe(MONRACE_IDX r_idx)
  */
 void lore_treasure(MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
 {
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
 
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
@@ -1809,9 +1837,9 @@ void lore_treasure(MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold
  * "disturb_near" (monster which is "easily" viewable moves in some
  * way).  Note that "moves" includes "appears" and "disappears".
  */
-void update_monster(MONSTER_IDX m_idx, bool full)
+void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full)
 {
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_type *m_ptr = &subject_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        bool do_disturb = disturb_move;
@@ -1827,14 +1855,14 @@ void update_monster(MONSTER_IDX m_idx, bool full)
        bool easy = FALSE;
 
        /* Non-Ninja player in the darkness */
-       bool in_darkness = (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
+       bool in_darkness = (d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !subject_ptr->see_nocto;
 
        /* Do disturb? */
        if (disturb_high)
        {
                monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
 
-               if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
+               if (ap_r_ptr->r_tkills && ap_r_ptr->level >= subject_ptr->lev)
                        do_disturb = TRUE;
        }
 
@@ -1842,8 +1870,8 @@ void update_monster(MONSTER_IDX m_idx, bool full)
        if (full)
        {
                /* Distance components */
-               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);
+               int dy = (subject_ptr->y > fy) ? (subject_ptr->y - fy) : (fy - subject_ptr->y);
+               int dx = (subject_ptr->x > fx) ? (subject_ptr->x - fx) : (fx - subject_ptr->x);
 
                /* Approximate distance */
                d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
@@ -1872,12 +1900,12 @@ void update_monster(MONSTER_IDX m_idx, bool full)
        {
                if (!in_darkness || (d <= MAX_SIGHT / 4))
                {
-                       if (p_ptr->special_defense & KATA_MUSOU)
+                       if (subject_ptr->special_defense & KATA_MUSOU)
                        {
                                /* Detectable */
                                flag = TRUE;
 
-                               if (is_original_ap(m_ptr) && !p_ptr->image)
+                               if (is_original_ap(m_ptr) && !subject_ptr->image)
                                {
                                        /* Hack -- Memorize mental flags */
                                        if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
@@ -1887,13 +1915,13 @@ void update_monster(MONSTER_IDX m_idx, bool full)
 
                        /* Basic telepathy */
                        /* Snipers get telepathy when they concentrate deeper */
-                       else if (p_ptr->telepathy)
+                       else if (subject_ptr->telepathy)
                        {
                                /* Empty mind, no telepathy */
                                if (r_ptr->flags2 & (RF2_EMPTY_MIND))
                                {
                                        /* Memorize flags */
-                                       if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
+                                       if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
                                }
 
                                /* Weird mind, occasional telepathy */
@@ -1905,7 +1933,7 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                                                /* Detectable */
                                                flag = TRUE;
 
-                                               if (is_original_ap(m_ptr) && !p_ptr->image)
+                                               if (is_original_ap(m_ptr) && !subject_ptr->image)
                                                {
                                                        /* Memorize flags */
                                                        r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
@@ -1923,7 +1951,7 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                                        /* Detectable */
                                        flag = TRUE;
 
-                                       if (is_original_ap(m_ptr) && !p_ptr->image)
+                                       if (is_original_ap(m_ptr) && !subject_ptr->image)
                                        {
                                                /* Hack -- Memorize mental flags */
                                                if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
@@ -1932,95 +1960,95 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                                }
                        }
 
-                       if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
+                       if ((subject_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
                        }
 
-                       if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
+                       if ((subject_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
                        }
 
-                       if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
+                       if ((subject_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
                        }
 
-                       if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
+                       if ((subject_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
                        }
 
-                       if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
+                       if ((subject_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
                        }
 
-                       if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
+                       if ((subject_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
                        }
 
-                       if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
+                       if ((subject_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
                        }
 
-                       if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
+                       if ((subject_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
                        }
 
-                       if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
+                       if ((subject_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
                        }
 
-                       if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
+                       if ((subject_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
                        }
 
-                       if ((p_ptr->esp_nonliving) &&
+                       if ((subject_ptr->esp_nonliving) &&
                            ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
                        }
 
-                       if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
+                       if ((subject_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
                        {
                                flag = TRUE;
-                               if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
+                               if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
                        }
                }
 
                /* Normal line of sight, and not blind */
-               if (player_has_los_bold(fy, fx) && !p_ptr->blind)
+               if (player_has_los_bold(subject_ptr, fy, fx) && !subject_ptr->blind)
                {
                        bool do_invisible = FALSE;
                        bool do_cold_blood = FALSE;
 
                        /* Snipers can see targets in darkness when they concentrate deeper */
-                       if (p_ptr->concent >= CONCENT_RADAR_THRESHOLD)
+                       if (subject_ptr->concent >= CONCENT_RADAR_THRESHOLD)
                        {
                                /* Easy to see */
                                easy = flag = TRUE;
                        }
 
                        /* Use "infravision" */
-                       if (d <= p_ptr->see_infra)
+                       if (d <= subject_ptr->see_infra)
                        {
                                /* Handle "cold blooded" monsters */
                                if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
@@ -2045,7 +2073,7 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                                        do_invisible = TRUE;
 
                                        /* See invisible */
-                                       if (p_ptr->see_inv)
+                                       if (subject_ptr->see_inv)
                                        {
                                                /* Easy to see */
                                                easy = flag = TRUE;
@@ -2063,7 +2091,7 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                        /* Visible */
                        if (flag)
                        {
-                               if (is_original_ap(m_ptr) && !p_ptr->image)
+                               if (is_original_ap(m_ptr) && !subject_ptr->image)
                                {
                                        /* Memorize flags */
                                        if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
@@ -2087,11 +2115,11 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                        lite_spot(fy, fx);
 
                        /* Update health bar as needed */
-                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
-                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
+                       if (subject_ptr->health_who == m_idx) subject_ptr->redraw |= (PR_HEALTH);
+                       if (subject_ptr->riding == m_idx) subject_ptr->redraw |= (PR_UHEALTH);
 
                        /* Hack -- Count "fresh" sightings */
-                       if (!p_ptr->image)
+                       if (!subject_ptr->image)
                        {
                                if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
                                        r_info[MON_KAGE].r_sights++;
@@ -2101,14 +2129,14 @@ void update_monster(MONSTER_IDX m_idx, bool full)
 
                        if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
                        {
-                               sanity_blast(m_ptr, FALSE);
+                               sanity_blast(subject_ptr, m_ptr, FALSE);
                        }
 
                        /* Disturb on appearance */
-                       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_near && (projectable(subject_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, subject_ptr->y, subject_ptr->x) && projectable(subject_ptr->current_floor_ptr, subject_ptr->y, subject_ptr->x, m_ptr->fy, m_ptr->fx)))
                        {
                                if (disturb_pets || is_hostile(m_ptr))
-                                       disturb(TRUE, TRUE);
+                                       disturb(subject_ptr, TRUE, TRUE);
                        }
                }
        }
@@ -2126,14 +2154,14 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                        lite_spot(fy, fx);
 
                        /* Update health bar as needed */
-                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
-                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
+                       if (subject_ptr->health_who == m_idx) subject_ptr->redraw |= (PR_HEALTH);
+                       if (subject_ptr->riding == m_idx) subject_ptr->redraw |= (PR_UHEALTH);
 
                        /* Disturb on disappearance */
                        if (do_disturb)
                        {
                                if (disturb_pets || is_hostile(m_ptr))
-                                       disturb(TRUE, TRUE);
+                                       disturb(subject_ptr, TRUE, TRUE);
                        }
                }
        }
@@ -2152,7 +2180,7 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                        if (do_disturb)
                        {
                                if (disturb_pets || is_hostile(m_ptr))
-                                       disturb(TRUE, TRUE);
+                                       disturb(subject_ptr, TRUE, TRUE);
                        }
                }
        }
@@ -2170,7 +2198,7 @@ void update_monster(MONSTER_IDX m_idx, bool full)
                        if (do_disturb)
                        {
                                if (disturb_pets || is_hostile(m_ptr))
-                                       disturb(TRUE, TRUE);
+                                       disturb(subject_ptr, TRUE, TRUE);
                        }
                }
        }
@@ -2187,11 +2215,11 @@ void update_monsters(bool full)
        MONSTER_IDX i;
 
        /* Update each (live) monster */
-       for (i = 1; i < m_max; i++)
+       for (i = 1; i < p_ptr->current_floor_ptr->m_max; i++)
        {
-               monster_type *m_ptr = &current_floor_ptr->m_list[i];
+               monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i];
                if (!monster_is_valid(m_ptr)) continue;
-               update_monster(i, full);
+               update_monster(p_ptr, i, full);
        }
 }
 
@@ -2204,7 +2232,7 @@ void update_monsters(bool full)
 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
-       monster_type *m_ptr = &current_floor_ptr->m_list[chameleon_change_m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[chameleon_change_m_idx];
        monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
 
        if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
@@ -2215,7 +2243,7 @@ static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
        if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
                return FALSE;
 
-       if (!monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
+       if (!monster_can_cross_terrain(p_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
 
        /* Not born */
        if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
@@ -2226,7 +2254,7 @@ static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
        /* Born now */
        else if (summon_specific_who > 0)
        {
-               if (monster_has_hostile_align(&current_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
+               if (monster_has_hostile_align(&p_ptr->current_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
        }
 
        return TRUE;
@@ -2241,7 +2269,7 @@ static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
-       monster_type *m_ptr = &current_floor_ptr->m_list[chameleon_change_m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[chameleon_change_m_idx];
        monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
 
        if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
@@ -2251,7 +2279,7 @@ static bool monster_hook_chameleon(MONRACE_IDX r_idx)
        if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
                return FALSE;
 
-       if (!monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
+       if (!monster_can_cross_terrain(p_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
 
        /* Not born */
        if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
@@ -2264,7 +2292,7 @@ static bool monster_hook_chameleon(MONRACE_IDX r_idx)
        /* Born now */
        else if (summon_specific_who > 0)
        {
-               if (monster_has_hostile_align(&current_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
+               if (monster_has_hostile_align(&p_ptr->current_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
        }
 
        return (*(get_monster_hook()))(r_idx);
@@ -2280,7 +2308,7 @@ static bool monster_hook_chameleon(MONRACE_IDX r_idx)
 void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
 {
        int oldmaxhp;
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr;
        char old_m_name[MAX_NLEN];
        bool old_unique = FALSE;
@@ -2305,10 +2333,10 @@ void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
 
                if (old_unique)
                        level = r_info[MON_CHAMELEON_K].level;
-               else if (!current_floor_ptr->dun_level)
+               else if (!p_ptr->current_floor_ptr->dun_level)
                        level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
                else
-                       level = current_floor_ptr->dun_level;
+                       level = p_ptr->current_floor_ptr->dun_level;
 
                if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
 
@@ -2321,7 +2349,7 @@ 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(m_idx, FALSE);
+       update_monster(p_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)) ||
@@ -2346,7 +2374,7 @@ void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
                monster_desc(m_name, m_ptr, 0);
                msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
                if (!(r_ptr->flags7 & RF7_RIDING))
-                       if (rakuba(0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
+                       if (rakuba(p_ptr, 0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
        }
 
        /* Extract the monster base speed */
@@ -2410,11 +2438,12 @@ static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx, BIT_FLAGS generate_mo
 {
        int attempts = 1000;
        MONRACE_IDX ap_r_idx;
-       DEPTH min = MIN(current_floor_ptr->base_level - 5, 50);
+       DEPTH min = MIN(p_ptr->current_floor_ptr->base_level - 5, 50);
 
        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;
+               if (p_ptr->current_floor_ptr->base_level == 0 ||
+                       (one_in_(5) && my_strchr("hkoptuyAHOPTUVY", r_info[r_idx].d_char))) return MON_ALIEN_JURAL;
        }
 
        if (!(r_info[r_idx].flags7 & RF7_TANUKI))
@@ -2424,7 +2453,7 @@ static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx, BIT_FLAGS generate_mo
 
        while (--attempts)
        {
-               ap_r_idx = get_mon_num(current_floor_ptr->base_level + 10);
+               ap_r_idx = get_mon_num(p_ptr->current_floor_ptr->base_level + 10);
                if (r_info[ap_r_idx].level >= min) return ap_r_idx;
        }
 
@@ -2443,7 +2472,7 @@ SPEED get_mspeed(monster_race *r_ptr)
        SPEED mspeed = r_ptr->speed;
 
        /* Hack -- small racial variety */
-       if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
+       if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->current_floor_ptr->inside_arena)
        {
                /* Allow some small variation per monster */
                int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
@@ -2483,7 +2512,7 @@ SPEED 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)
 {
-       grid_type               *g_ptr = &current_floor_ptr->grid_array[y][x];
+       grid_type               *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
        monster_type    *m_ptr;
        monster_race    *r_ptr = &r_info[r_idx];
        concptr         name = (r_name + r_ptr->name);
@@ -2493,7 +2522,7 @@ 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;
 
-       if (!in_bounds(y, x)) return (FALSE);
+       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return (FALSE);
        if (!r_idx) return (FALSE);
        if (!r_ptr->name) return (FALSE);
 
@@ -2506,7 +2535,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->inside_battle)
+       if (!p_ptr->phase_out)
        {
                /* Hack -- "unique" monsters must be "unique" */
                if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
@@ -2530,7 +2559,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
                }
 
                /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
-               if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (current_floor_ptr->dun_level < r_ptr->level) &&
+               if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (p_ptr->current_floor_ptr->dun_level < r_ptr->level) &&
                    (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
                {
                        /* Cannot create */
@@ -2538,9 +2567,9 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
                }
        }
 
-       if (quest_number(current_floor_ptr->dun_level))
+       if (quest_number(p_ptr->current_floor_ptr->dun_level))
        {
-               int hoge = quest_number(current_floor_ptr->dun_level);
+               int hoge = quest_number(p_ptr->current_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)
@@ -2549,10 +2578,10 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
                                number_mon = 0;
 
                                /* Count all quest monsters */
-                               for (i2 = 0; i2 < current_floor_ptr->width; ++i2)
-                                       for (j2 = 0; j2 < current_floor_ptr->height; j2++)
-                                               if (current_floor_ptr->grid_array[j2][i2].m_idx > 0)
-                                                       if (current_floor_ptr->m_list[current_floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
+                               for (i2 = 0; i2 < p_ptr->current_floor_ptr->width; ++i2)
+                                       for (j2 = 0; j2 < p_ptr->current_floor_ptr->height; j2++)
+                                               if (p_ptr->current_floor_ptr->grid_array[j2][i2].m_idx > 0)
+                                                       if (p_ptr->current_floor_ptr->m_list[p_ptr->current_floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
                                                                number_mon++;
                                if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
                                        return FALSE;
@@ -2595,7 +2624,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
 
 
        /* Get a new monster record */
-       m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
+       m_ptr = &p_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
 
        /* Save the race */
        m_ptr->r_idx = r_idx;
@@ -2606,17 +2635,17 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
        m_ptr->mflag2 = 0;
 
        /* Hack -- Appearance transfer */
-       if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&current_floor_ptr->m_list[who]))
+       if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&p_ptr->current_floor_ptr->m_list[who]))
        {
-               m_ptr->ap_r_idx = current_floor_ptr->m_list[who].ap_r_idx;
+               m_ptr->ap_r_idx = p_ptr->current_floor_ptr->m_list[who].ap_r_idx;
 
                /* Hack -- Shadower spawns Shadower */
-               if (current_floor_ptr->m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
+               if (p_ptr->current_floor_ptr->m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
        }
 
        /* Sub-alignment of a monster */
        if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
-               m_ptr->sub_align = current_floor_ptr->m_list[who].sub_align;
+               m_ptr->sub_align = p_ptr->current_floor_ptr->m_list[who].sub_align;
        else
        {
                m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
@@ -2627,6 +2656,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
        /* Place the monster at the location */
        m_ptr->fy = y;
        m_ptr->fx = x;
+       m_ptr->current_floor_ptr = p_ptr->current_floor_ptr;
 
 
        /* No "timed status" yet */
@@ -2643,7 +2673,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
 
 
        /* Your pet summons its pet. */
-       if (who > 0 && is_pet(&current_floor_ptr->m_list[who]))
+       if (who > 0 && is_pet(&p_ptr->current_floor_ptr->m_list[who]))
        {
                mode |= PM_FORCE_PET;
                m_ptr->parent_m_idx = who;
@@ -2764,7 +2794,7 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
                p_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(g_ptr->m_idx, TRUE);
+       update_monster(p_ptr, g_ptr->m_idx, TRUE);
 
 
        /* Count the monsters on the level */
@@ -2774,21 +2804,14 @@ static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_I
         * Memorize location of the unique monster in saved floors.
         * A unique monster move from old saved floor.
         */
-       if (character_dungeon &&
+       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;
 
        /* Hack -- Count the number of "reproducers" */
-       if (r_ptr->flags2 & RF2_MULTIPLY) current_floor_ptr->num_repro++;
-
-       /* Hack -- Notice new multi-hued monsters */
-       {
-               monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
-               if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
-                       shimmer_monsters = TRUE;
-       }
+       if (r_ptr->flags2 & RF2_MULTIPLY) p_ptr->current_floor_ptr->num_repro++;
 
-       if (p_ptr->warning && character_dungeon)
+       if (p_ptr->warning && current_world_ptr->character_dungeon)
        {
                if (r_ptr->flags1 & RF1_UNIQUE)
                {
@@ -2888,10 +2911,10 @@ static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION
                for (ny = y - max_dist; ny <= y + max_dist; ny++)
                {
                        /* Ignore annoying locations */
-                       if (!in_bounds(ny, nx)) continue;
+                       if (!in_bounds(p_ptr->current_floor_ptr, ny, nx)) continue;
 
                        /* Require "line of projection" */
-                       if (!projectable(y, x, ny, nx)) continue;
+                       if (!projectable(p_ptr->current_floor_ptr, y, x, ny, nx)) continue;
 
                        if (r_idx > 0)
                        {
@@ -2904,7 +2927,7 @@ static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION
                        else
                        {
                                /* Walls and Monsters block flow */
-                               if (!cave_empty_bold2(ny, nx)) continue;
+                               if (!cave_empty_bold2(p_ptr->current_floor_ptr, ny, nx)) continue;
 
                                /* ... nor on the Pattern */
                                if (pattern_tile(ny, nx)) continue;
@@ -2964,16 +2987,16 @@ static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE
        total = randint1(10);
 
        /* Hard monsters, small groups */
-       if (r_ptr->level > current_floor_ptr->dun_level)
+       if (r_ptr->level > p_ptr->current_floor_ptr->dun_level)
        {
-               extra = r_ptr->level - current_floor_ptr->dun_level;
+               extra = r_ptr->level - p_ptr->current_floor_ptr->dun_level;
                extra = 0 - randint1(extra);
        }
 
        /* Easy monsters, large groups */
-       else if (r_ptr->level < current_floor_ptr->dun_level)
+       else if (r_ptr->level < p_ptr->current_floor_ptr->dun_level)
        {
-               extra = current_floor_ptr->dun_level - r_ptr->level;
+               extra = p_ptr->current_floor_ptr->dun_level - r_ptr->level;
                extra = randint1(extra);
        }
 
@@ -3010,7 +3033,7 @@ static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE
                        scatter(&my, &mx, hy, hx, 4, 0);
 
                        /* Walls and Monsters block flow */
-                       if (!cave_empty_bold2(my, mx)) continue;
+                       if (!cave_empty_bold2(p_ptr->current_floor_ptr, my, mx)) continue;
 
                        /* Attempt to place another monster */
                        if (place_monster_one(who, my, mx, r_idx, mode))
@@ -3050,7 +3073,7 @@ static MONSTER_IDX place_monster_m_idx = 0;
 static bool place_monster_can_escort(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[place_monster_idx];
-       monster_type *m_ptr = &current_floor_ptr->m_list[place_monster_m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[place_monster_m_idx];
 
        monster_race *z_ptr = &r_info[r_idx];
 
@@ -3160,7 +3183,7 @@ bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_id
                        scatter(&ny, &nx, y, x, d, 0);
 
                        /* Require empty grids */
-                       if (!cave_empty_bold2(ny, nx)) continue;
+                       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));
 
                        /* Pick a random race */
@@ -3199,7 +3222,7 @@ bool place_monster(POSITION y, POSITION x, BIT_FLAGS mode)
        get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
 
        /* Pick a monster */
-       r_idx = get_mon_num(current_floor_ptr->monster_level);
+       r_idx = get_mon_num(p_ptr->current_floor_ptr->monster_level);
 
        /* Handle failure */
        if (!r_idx) return (FALSE);
@@ -3229,7 +3252,7 @@ bool alloc_horde(POSITION y, POSITION x)
        while (--attempts)
        {
                /* Pick a monster */
-               r_idx = get_mon_num(current_floor_ptr->monster_level);
+               r_idx = get_mon_num(p_ptr->current_floor_ptr->monster_level);
 
                /* Handle failure */
                if (!r_idx) return (FALSE);
@@ -3253,15 +3276,15 @@ bool alloc_horde(POSITION y, POSITION x)
 
        if (attempts < 1) return FALSE;
 
-       m_idx = current_floor_ptr->grid_array[y][x].m_idx;
+       m_idx = p_ptr->current_floor_ptr->grid_array[y][x].m_idx;
 
-       if (current_floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[current_floor_ptr->m_list[m_idx].r_idx];
+       if (p_ptr->current_floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[p_ptr->current_floor_ptr->m_list[m_idx].r_idx];
 
        for (attempts = randint1(10) + 5; attempts; attempts--)
        {
                scatter(&cy, &cx, y, x, 5, 0);
 
-               (void)summon_specific(m_idx, cy, cx, current_floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP, r_ptr->d_char);
+               (void)summon_specific(m_idx, cy, cx, p_ptr->current_floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
 
                y = cy;
                x = cx;
@@ -3280,7 +3303,7 @@ bool alloc_guardian(bool def_val)
 {
        MONRACE_IDX guardian = d_info[p_ptr->dungeon_idx].final_guardian;
 
-       if (guardian && (d_info[p_ptr->dungeon_idx].maxdepth == current_floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
+       if (guardian && (d_info[p_ptr->dungeon_idx].maxdepth == p_ptr->current_floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
        {
                POSITION oy;
                POSITION ox;
@@ -3290,11 +3313,11 @@ bool alloc_guardian(bool def_val)
                while (try_count)
                {
                        /* Get a random spot */
-                       oy = randint1(current_floor_ptr->height - 4) + 2;
-                       ox = randint1(current_floor_ptr->width - 4) + 2;
+                       oy = randint1(p_ptr->current_floor_ptr->height - 4) + 2;
+                       ox = randint1(p_ptr->current_floor_ptr->width - 4) + 2;
 
                        /* Is it a good spot ? */
-                       if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(current_floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0))
+                       if (cave_empty_bold2(p_ptr->current_floor_ptr, oy, ox) && monster_can_cross_terrain(p_ptr->current_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;
@@ -3319,7 +3342,7 @@ bool alloc_guardian(bool def_val)
  * @details
  * Place the monster at least "dis" distance from the player.
  * Use "slp" to choose the initial "sleep" status
- * Use "current_floor_ptr->monster_level" for the monster level
+ * Use "p_ptr->current_floor_ptr->monster_level" for the monster level
  */
 bool alloc_monster(POSITION dis, BIT_FLAGS mode)
 {
@@ -3333,17 +3356,17 @@ bool alloc_monster(POSITION dis, BIT_FLAGS mode)
        while (attempts_left--)
        {
                /* Pick a location */
-               y = randint0(current_floor_ptr->height);
-               x = randint0(current_floor_ptr->width);
+               y = randint0(p_ptr->current_floor_ptr->height);
+               x = randint0(p_ptr->current_floor_ptr->width);
 
                /* Require empty floor grid (was "naked") */
-               if (current_floor_ptr->dun_level)
+               if (p_ptr->current_floor_ptr->dun_level)
                {
-                       if (!cave_empty_bold2(y, x)) continue;
+                       if (!cave_empty_bold2(p_ptr->current_floor_ptr, y, x)) continue;
                }
                else
                {
-                       if (!cave_empty_bold(y, x)) continue;
+                       if (!cave_empty_bold(p_ptr->current_floor_ptr, y, x)) continue;
                }
 
                /* Accept far away grids */
@@ -3361,7 +3384,7 @@ bool alloc_monster(POSITION dis, BIT_FLAGS mode)
        }
 
 
-       if (randint1(5000) <= current_floor_ptr->dun_level)
+       if (randint1(5000) <= p_ptr->current_floor_ptr->dun_level)
        {
                if (alloc_horde(y, x))
                {
@@ -3386,6 +3409,7 @@ bool alloc_monster(POSITION dis, BIT_FLAGS mode)
 static bool summon_specific_okay(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[summon_specific_who];
 
        /* Hack - Only summon dungeon monsters */
        if (!mon_hook_dungeon(r_idx)) return (FALSE);
@@ -3393,7 +3417,6 @@ static bool summon_specific_okay(MONRACE_IDX r_idx)
        /* Hack -- identify the summoning monster */
        if (summon_specific_who > 0)
        {
-               monster_type *m_ptr = &current_floor_ptr->m_list[summon_specific_who];
 
                /* Do not summon enemies */
 
@@ -3422,7 +3445,7 @@ 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(r_idx));
+       return (summon_specific_aux(m_ptr->r_idx, r_idx));
 }
 
 
@@ -3457,12 +3480,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, SYMBOL_CODE symbol)
+bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode)
 {
        POSITION x, y;
        MONRACE_IDX r_idx;
 
-       if (p_ptr->inside_arena) return (FALSE);
+       if (p_ptr->current_floor_ptr->inside_arena) return (FALSE);
 
        if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
 
@@ -3472,13 +3495,11 @@ bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int t
        /* Save the "summon" type */
        summon_specific_type = type;
 
-       summon_kin_type = symbol;
-
        summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
        get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
 
        /* Pick a monster, using the level calculation */
-       r_idx = get_mon_num((current_floor_ptr->dun_level + lev) / 2 + 5);
+       r_idx = get_mon_num((p_ptr->current_floor_ptr->dun_level + lev) / 2 + 5);
 
        /* Handle failure */
        if (!r_idx)
@@ -3520,7 +3541,7 @@ 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->inside_arena) return FALSE;
+       if (p_ptr->current_floor_ptr->inside_arena) return FALSE;
 
        if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
 
@@ -3540,7 +3561,7 @@ bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_ID
  */
 bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
 {
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        POSITION y, x;
 
        if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
@@ -3555,8 +3576,8 @@ bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
        /* Hack -- Transfer "clone" flag */
        if (clone || (m_ptr->smart & SM_CLONED))
        {
-               current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
-               current_floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
+               p_ptr->current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
+               p_ptr->current_floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
        }
 
        return TRUE;
@@ -3578,7 +3599,7 @@ void message_pain(MONSTER_IDX m_idx, HIT_POINT dam)
        HIT_POINT tmp;
        PERCENTAGE percentage;
 
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        GAME_TEXT m_name[MAX_NLEN];
@@ -3902,7 +3923,7 @@ void message_pain(MONSTER_IDX m_idx, HIT_POINT dam)
  */
 void update_smart_learn(MONSTER_IDX m_idx, int what)
 {
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        /* Not allowed to learn */
@@ -4022,7 +4043,7 @@ void monster_drop_carried_objects(monster_type *m_ptr)
        /* Drop objects being carried */
        for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
-               o_ptr = &current_floor_ptr->o_list[this_o_idx];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                next_o_idx = o_ptr->next_o_idx;
                q_ptr = &forge;
 
@@ -4049,7 +4070,7 @@ void monster_drop_carried_objects(monster_type *m_ptr)
  */
 int get_monster_crowd_number(MONSTER_IDX m_idx)
 {
-       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        POSITION my = m_ptr->fy;
        POSITION mx = m_ptr->fx;
        int i;
@@ -4060,11 +4081,11 @@ int get_monster_crowd_number(MONSTER_IDX m_idx)
                int ay = my + ddy_ddd[i];
                int ax = mx + ddx_ddd[i];
 
-               if (!in_bounds(ay, ax)) continue;
+               if (!in_bounds(p_ptr->current_floor_ptr, ay, ax)) continue;
 
                /* Count number of monsters */
-               if (current_floor_ptr->grid_array[ay][ax].m_idx > 0) count++;
+               if (p_ptr->current_floor_ptr->grid_array[ay][ax].m_idx > 0) count++;
        }
 
        return count;
-}
\ No newline at end of file
+}