OSDN Git Service

[Refactor] #39970 Moved dungeon*.c/h to dungeon/
[hengband/hengband.git] / src / floor-generate.c
index 1d6b635..c15105d 100644 (file)
 #include "angband.h"
 #include "util.h"
 #include "core.h"
-#include "bldg.h"
+#include "market/building.h"
 
-#include "cmd-dump.h"
+#include "io/write-diary.h"
+#include "cmd/cmd-dump.h"
 #include "grid.h"
+#include "market/arena-info-table.h"
 #include "rooms.h"
-#include "dungeon.h"
+#include "dungeon/dungeon.h"
 #include "floor.h"
 #include "floor-save.h"
 #include "floor-streams.h"
 #include "player-status.h"
 #include "wild.h"
 #include "monster-status.h"
-#include "dungeon-file.h"
+#include "dungeon/dungeon-file.h"
 #include "init.h"
 #include "feature.h"
-#include "spells.h"
+#include "spell/spells1.h"
 
-#include "world.h"
-#include "view-mainwindow.h"
+#include "world/world.h"
+#include "view/display-main-window.h"
 
 int dun_tun_rnd; 
 int dun_tun_chg;
@@ -144,7 +146,7 @@ dun_data *dun;
  * @param y 基準のy座標
  * @param x 基準のx座標
  * @return 隣接する外壁の数
- * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y, x)"
+ * @note Assumes "in_bounds()"
  * @details We count only granite walls and permanent walls.
  */
 static int next_to_walls(floor_type* floor_ptr, POSITION y, POSITION x)
@@ -161,18 +163,20 @@ static int next_to_walls(floor_type* floor_ptr, POSITION y, POSITION x)
 
 /*!
  * @brief alloc_stairs()の補助として指定の位置に階段を生成できるかの判定を行う / Helper function for alloc_stairs(). Is this a good location for stairs?
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y 基準のy座標
  * @param x 基準のx座標
  * @param walls 最低減隣接させたい外壁の数
  * @return 階段を生成して問題がないならばTRUEを返す。
  */
-static bool alloc_stairs_aux(floor_type *floor_ptr, POSITION y, POSITION x, int walls)
+static bool alloc_stairs_aux(player_type *player_ptr, POSITION y, POSITION x, int walls)
 {
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        grid_type *g_ptr = &floor_ptr->grid_array[y][x];
 
        /* Require "naked" floor grid */
        if (!is_floor_grid(g_ptr)) return FALSE;
-       if (pattern_tile(y, x)) return FALSE;
+       if (pattern_tile(floor_ptr, y, x)) return FALSE;
        if (g_ptr->o_idx || g_ptr->m_idx) return FALSE;
 
        /* Require a certain number of adjacent walls */
@@ -184,18 +188,20 @@ static bool alloc_stairs_aux(floor_type *floor_ptr, POSITION y, POSITION x, int
 
 /*!
  * @brief 外壁に隣接させて階段を生成する / Places some staircases near walls
+ * @param owner_ptr プレーヤーへの参照ポインタ
  * @param feat 配置したい地形ID
  * @param num 配置したい階段の数
  * @param walls 最低減隣接させたい外壁の数
  * @return 規定数通りに生成に成功したらTRUEを返す。
  */
-static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int walls)
+static bool alloc_stairs(player_type *owner_ptr, FEAT_IDX feat, int num, int walls)
 {
        int i;
        int shaft_num = 0;
 
        feature_type *f_ptr = &f_info[feat];
 
+       floor_type *floor_ptr = owner_ptr->current_floor_ptr;
        if (have_flag(f_ptr->flags, FF_LESS))
        {
                /* No up stairs in town or in ironman mode */
@@ -206,7 +212,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
        }
        else if (have_flag(f_ptr->flags, FF_MORE))
        {
-               QUEST_IDX q_idx = quest_number(floor_ptr->dun_level);
+               QUEST_IDX q_idx = quest_number(owner_ptr, floor_ptr->dun_level);
 
                /* No downstairs on quest levels */
                if (floor_ptr->dun_level > 1 && q_idx)
@@ -221,7 +227,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
                /* No downstairs at the bottom */
                if (floor_ptr->dun_level >= d_info[floor_ptr->dungeon_idx].maxdepth) return TRUE;
 
-               if ((floor_ptr->dun_level < d_info[floor_ptr->dungeon_idx].maxdepth-1) && !quest_number(floor_ptr->dun_level+1))
+               if ((floor_ptr->dun_level < d_info[floor_ptr->dungeon_idx].maxdepth-1) && !quest_number(owner_ptr, floor_ptr->dun_level+1))
                        shaft_num = (randint1(num)+1)/2;
        }
        else return FALSE;
@@ -242,7 +248,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
                        {
                                for (x = 1; x < floor_ptr->width - 1; x++)
                                {
-                                       if (alloc_stairs_aux(floor_ptr, y, x, walls))
+                                       if (alloc_stairs_aux(owner_ptr, y, x, walls))
                                        {
                                                /* A valid space found */
                                                candidates++;
@@ -268,7 +274,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
                        {
                                for (x = 1; x < floor_ptr->width - 1; x++)
                                {
-                                       if (alloc_stairs_aux(floor_ptr, y, x, walls))
+                                       if (alloc_stairs_aux(owner_ptr, y, x, walls))
                                        {
                                                pick--;
 
@@ -285,7 +291,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
                        g_ptr->mimic = 0;
 
                        /* Clear previous contents, add stairs */
-                       g_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
+                       g_ptr->feat = (i < shaft_num) ? feat_state(owner_ptr, feat, FF_SHAFT) : feat;
 
                        /* No longer "FLOOR" */
                        g_ptr->info &= ~(CAVE_FLOOR);
@@ -304,7 +310,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
  * @param num 配置したい数
  * @return 規定数通りに生成に成功したらTRUEを返す。
  */
-static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
+static void alloc_object(player_type *owner_ptr, int set, EFFECT_ID typ, int num)
 {
        POSITION y = 0, x = 0;
        int k;
@@ -312,6 +318,7 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
        grid_type *g_ptr;
 
        /* A small level has few objects. */
+       floor_type *floor_ptr = owner_ptr->current_floor_ptr;
        num = num * floor_ptr->height * floor_ptr->width / (MAX_HGT*MAX_WID) +1;
 
        /* Place some objects */
@@ -333,7 +340,7 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
                        if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
 
                        /* Avoid player location */
-                       if (player_bold(p_ptr, y, x)) continue;
+                       if (player_bold(owner_ptr, y, x)) continue;
 
                        /* Check for "room" */
                        room = (floor_ptr->grid_array[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
@@ -367,20 +374,20 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
 
                        case ALLOC_TYP_TRAP:
                        {
-                               place_trap(floor_ptr, y, x);
+                               place_trap(owner_ptr, y, x);
                                floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
                                break;
                        }
 
                        case ALLOC_TYP_GOLD:
                        {
-                               place_gold(y, x);
+                               place_gold(owner_ptr, y, x);
                                break;
                        }
 
                        case ALLOC_TYP_OBJECT:
                        {
-                               place_object(y, x, 0L);
+                               place_object(owner_ptr, y, x, 0L);
                                break;
                        }
                }
@@ -392,15 +399,15 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
 
 /*!
  * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
- * @param floor_ptr 配置するフロアの参照ポインタ
- * @param subject_ptr 近隣への即出現を避けるためのプレイヤークリーチャー参照ポインタ
+ * @param creature_ptr プレーヤーへの参照ポインタ
  * @return 成功したならばTRUEを返す
  */
-bool place_quest_monsters(floor_type *floor_ptr, player_type *creature_ptr)
+bool place_quest_monsters(player_type *creature_ptr)
 {
        int i;
 
        /* Handle the quest monster placements */
+       floor_type *floor_ptr = creature_ptr->current_floor_ptr;
        for (i = 0; i < max_q_idx; i++)
        {
                monster_race *r_ptr;
@@ -451,7 +458,7 @@ bool place_quest_monsters(floor_type *floor_ptr, player_type *creature_ptr)
                                        f_ptr = &f_info[g_ptr->feat];
 
                                        if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
-                                       if (!monster_can_enter(y, x, r_ptr, 0)) continue;
+                                       if (!monster_can_enter(creature_ptr, y, x, r_ptr, 0)) continue;
                                        if (distance(y, x, creature_ptr->y, creature_ptr->x) < 10) continue;
                                        if (g_ptr->info & CAVE_ICKY) continue;
                                        else break;
@@ -461,7 +468,7 @@ bool place_quest_monsters(floor_type *floor_ptr, player_type *creature_ptr)
                                if (!l) return FALSE;
 
                                /* Try to place the monster */
-                               if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
+                               if (place_monster_aux(creature_ptr, 0, y, x, quest[i].r_idx, mode))
                                {
                                        /* Success */
                                        break;
@@ -486,16 +493,16 @@ bool place_quest_monsters(floor_type *floor_ptr, player_type *creature_ptr)
  * @details There were moved from cave_gen().
  * @return なし
  */
-static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_ptr)
+static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, player_type *owner_ptr)
 {
-#ifdef ALLOW_CAVERNS_AND_LAKES
+       floor_type *floor_ptr = owner_ptr->current_floor_ptr;
        /* Possible "destroyed" level */
        if ((floor_ptr->dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (dungeon_ptr->flags1 & DF1_DESTROY))
        {
                dun->destroyed = TRUE;
 
                /* extra rubble around the place looks cool */
-               build_lake(floor_ptr, one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
+               build_lake(owner_ptr, one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
        }
 
        /* Make a lake some of the time */
@@ -547,7 +554,7 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
                if (dun->laketype)
                {
                        msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
-                       build_lake(floor_ptr, dun->laketype);
+                       build_lake(owner_ptr, dun->laketype);
                }
        }
 
@@ -560,26 +567,28 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
                /* make a large fractal floor_ptr->grid_array in the middle of the dungeon */
 
                msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
-               build_cavern(floor_ptr);
+               build_cavern(owner_ptr);
        }
-#endif /* ALLOW_CAVERNS_AND_LAKES */
 
        /* Hack -- No destroyed "quest" levels */
-       if (quest_number(floor_ptr->dun_level)) dun->destroyed = FALSE;
+       if (quest_number(owner_ptr, floor_ptr->dun_level)) dun->destroyed = FALSE;
 }
 
 
 /*!
  * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
  * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param why エラー原因メッセージを返す
  * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
  */
-static bool cave_gen(floor_type *floor_ptr)
+static bool cave_gen(player_type *player_ptr, concptr *why)
 {
        int i, k;
        POSITION y, x;
        dun_data dun_body;
 
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        dungeon_type* dungeon_ptr = &d_info[floor_ptr->dungeon_idx];
 
        floor_ptr->lite_n = 0;
@@ -596,8 +605,8 @@ static bool cave_gen(floor_type *floor_ptr)
        dun->laketype = 0;
 
        /* Fill the arrays of floors and walls in the good proportions */
-       set_floor_and_wall(p_ptr->dungeon_idx);
-       get_mon_num_prep(get_monster_hook(), NULL);
+       set_floor_and_wall(floor_ptr->dungeon_idx);
+       get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), NULL);
 
        /* Randomize the dungeon creation values */
        dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
@@ -636,22 +645,22 @@ static bool cave_gen(floor_type *floor_ptr)
                {
                        for (x = 0; x < floor_ptr->width; x++)
                        {
-                               place_floor_bold(floor_ptr, y, x);
+                               place_bold(player_ptr, y, x, GB_FLOOR);
                        }
                }
 
                /* Special boundary walls -- Top and bottom */
                for (x = 0; x < floor_ptr->width; x++)
                {
-                       place_extra_bold(floor_ptr, 0, x);
-                       place_extra_bold(floor_ptr, floor_ptr->height - 1, x);
+                       place_bold(player_ptr, 0, x, GB_EXTRA);
+                       place_bold(player_ptr, floor_ptr->height - 1, x, GB_EXTRA);
                }
 
                /* Special boundary walls -- Left and right */
                for (y = 1; y < (floor_ptr->height - 1); y++)
                {
-                       place_extra_bold(floor_ptr, y, 0);
-                       place_extra_bold(floor_ptr, y, floor_ptr->width - 1);
+                       place_bold(player_ptr, y, 0, GB_EXTRA);
+                       place_bold(player_ptr, y, floor_ptr->width - 1, GB_EXTRA);
                }
        }
        else
@@ -661,24 +670,32 @@ static bool cave_gen(floor_type *floor_ptr)
                {
                        for (x = 0; x < floor_ptr->width; x++)
                        {
-                               place_extra_bold(floor_ptr, y, x);
+                               place_bold(player_ptr, y, x, GB_EXTRA);
                        }
                }
        }
 
        /* Generate various caverns and lakes */
-       gen_caverns_and_lakes(dungeon_ptr, floor_ptr);
+       gen_caverns_and_lakes(dungeon_ptr, player_ptr);
 
        /* Build maze */
        if (dungeon_ptr->flags1 & DF1_MAZE)
        {
-               build_maze_vault(floor_ptr, floor_ptr->width/2-1, floor_ptr->height/2-1, floor_ptr->width-4, floor_ptr->height-4, FALSE);
+               build_maze_vault(player_ptr, floor_ptr->width/2-1, floor_ptr->height/2-1, floor_ptr->width-4, floor_ptr->height-4, FALSE);
 
                /* Place 3 or 4 down stairs near some walls */
-               if (!alloc_stairs(floor_ptr, feat_down_stair, rand_range(2, 3), 3)) return FALSE;
+               if (!alloc_stairs(player_ptr, feat_down_stair, rand_range(2, 3), 3))
+               {
+                       *why = _("迷宮ダンジョンの下り階段生成に失敗", "Failed to alloc up stairs in maze dungeon.");
+                       return FALSE;
+               }
 
                /* Place 1 or 2 up stairs near some walls */
-               if (!alloc_stairs(floor_ptr, feat_up_stair, 1, 3)) return FALSE;
+               if (!alloc_stairs(player_ptr, feat_up_stair, 1, 3))
+               {
+                       *why = _("迷宮ダンジョンの上り階段生成に失敗", "Failed to alloc down stairs in maze dungeon.");
+                       return FALSE;
+               }
        }
 
        /* Build some rooms */
@@ -689,7 +706,11 @@ static bool cave_gen(floor_type *floor_ptr)
                /*
                 * Build each type of room in turn until we cannot build any more.
                 */
-               if (!generate_rooms(floor_ptr)) return FALSE;
+               if (!generate_rooms(player_ptr))
+               {
+                       *why = _("部屋群の生成に失敗", "Failed to generate rooms");
+                       return FALSE;
+               }
 
 
                /* Make a hole in the dungeon roof sometimes at level 1 */
@@ -697,74 +718,18 @@ static bool cave_gen(floor_type *floor_ptr)
                {
                        while (one_in_(DUN_MOS_DEN))
                        {
-                               place_trees(floor_ptr, randint1(floor_ptr->width - 2), randint1(floor_ptr->height - 2));
+                               place_trees(player_ptr, randint1(floor_ptr->width - 2), randint1(floor_ptr->height - 2));
                        }
                }
 
-               /* Destroy the level if necessary */
-               if (dun->destroyed) destroy_level();
-
-               /* Hack -- Add some rivers */
-               if (one_in_(3) && (randint1(floor_ptr->dun_level) > 5))
+               if (dun->destroyed)
                {
-                       FEAT_IDX feat1 = 0, feat2 = 0;
-
-                       /* Choose water mainly */
-                       if ((randint1(MAX_DEPTH * 2) - 1 > floor_ptr->dun_level) && (dungeon_ptr->flags1 & DF1_WATER_RIVER))
-                       {
-                               feat1 = feat_deep_water;
-                               feat2 = feat_shallow_water;
-                       }
-                       else /* others */
-                       {
-                               FEAT_IDX select_deep_feat[10];
-                               FEAT_IDX select_shallow_feat[10];
-                               int select_id_max = 0, selected;
-
-                               if (dungeon_ptr->flags1 & DF1_LAVA_RIVER)
-                               {
-                                       select_deep_feat[select_id_max] = feat_deep_lava;
-                                       select_shallow_feat[select_id_max] = feat_shallow_lava;
-                                       select_id_max++;
-                               }
-                               if (dungeon_ptr->flags1 & DF1_POISONOUS_RIVER)
-                               {
-                                       select_deep_feat[select_id_max] = feat_deep_poisonous_puddle;
-                                       select_shallow_feat[select_id_max] = feat_shallow_poisonous_puddle;
-                                       select_id_max++;
-                               }
-                               if (dungeon_ptr->flags1 & DF1_ACID_RIVER)
-                               {
-                                       select_deep_feat[select_id_max] = feat_deep_acid_puddle;
-                                       select_shallow_feat[select_id_max] = feat_shallow_acid_puddle;
-                                       select_id_max++;
-                               }
-
-                               if (select_id_max > 0)
-                               {
-                                       selected = randint0(select_id_max);
-                                       feat1 = select_deep_feat[selected];
-                                       feat2 = select_shallow_feat[selected];
-                               }
-                               else
-                               {
-                                       feat1 = feat_deep_water;
-                                       feat2 = feat_shallow_water;
-                               }
-                       }
-
-                       if (feat1)
-                       {
-                               feature_type *f_ptr = &f_info[feat1];
+                       destroy_level(player_ptr);
+               }
 
-                               /* Only add river if matches lake type or if have no lake at all */
-                               if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
-                                   ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
-                                    !dun->laketype)
-                               {
-                                       add_river(floor_ptr, feat1, feat2);
-                               }
-                       }
+               if (HAS_RIVER_FLAG(dungeon_ptr) && one_in_(3) && (randint1(floor_ptr->dun_level) > 5))
+               {
+                       add_river(floor_ptr);
                }
 
                /* Hack -- Scramble the room order */
@@ -801,15 +766,19 @@ static bool cave_gen(floor_type *floor_ptr)
                        if (randint1(floor_ptr->dun_level) > dungeon_ptr->tunnel_percent)
                        {
                                /* make cavelike tunnel */
-                               (void)build_tunnel2(floor_ptr, dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
+                               (void)build_tunnel2(player_ptr, dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
                        }
                        else
                        {
                                /* make normal tunnel */
-                               if (!build_tunnel(floor_ptr, dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
+                               if (!build_tunnel(player_ptr, dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
                        }
 
-                       if (tunnel_fail_count >= 2) return FALSE;
+                       if (tunnel_fail_count >= 2)
+                       {
+                               *why = _("トンネル接続に失敗", "Failed to generate tunnels");
+                               return FALSE;
+                       }
 
                        /* Turn the tunnel into corridor */
                        for (j = 0; j < dun->tunn_n; j++)
@@ -827,7 +796,7 @@ static bool cave_gen(floor_type *floor_ptr)
                                        /* Clear mimic type */
                                        g_ptr->mimic = 0;
 
-                                       place_floor_grid(g_ptr);
+                                       place_grid(player_ptr, g_ptr, GB_FLOOR);
                                }
                        }
 
@@ -843,13 +812,13 @@ static bool cave_gen(floor_type *floor_ptr)
                                g_ptr->mimic = 0;
 
                                /* Clear previous contents, add up floor */
-                               place_floor_grid(g_ptr);
+                               place_grid(player_ptr, g_ptr, GB_FLOOR);
 
                                /* Occasional doorway */
                                if ((randint0(100) < dun_tun_pen) && !(dungeon_ptr->flags1 & DF1_NO_DOORS))
                                {
                                        /* Place a random door */
-                                       place_random_door(floor_ptr, y, x, TRUE);
+                                       place_random_door(player_ptr, y, x, TRUE);
                                }
                        }
 
@@ -866,17 +835,25 @@ static bool cave_gen(floor_type *floor_ptr)
                        x = dun->door[i].x;
 
                        /* Try placing doors */
-                       try_door(y, x - 1);
-                       try_door(y, x + 1);
-                       try_door(y - 1, x);
-                       try_door(y + 1, x);
+                       try_door(player_ptr, y, x - 1);
+                       try_door(player_ptr, y, x + 1);
+                       try_door(player_ptr, y - 1, x);
+                       try_door(player_ptr, y + 1, x);
                }
 
                /* Place 3 or 4 down stairs near some walls */
-               if (!alloc_stairs(floor_ptr, feat_down_stair, rand_range(3, 4), 3)) return FALSE;
+               if (!alloc_stairs(player_ptr, feat_down_stair, rand_range(3, 4), 3))
+               {
+                       *why = _("下り階段生成に失敗", "Failed to generate down stairs.");
+                       return FALSE;
+               }
 
                /* Place 1 or 2 up stairs near some walls */
-               if (!alloc_stairs(floor_ptr, feat_up_stair, rand_range(1, 2), 3)) return FALSE;
+               if (!alloc_stairs(player_ptr, feat_up_stair, rand_range(1, 2), 3))
+               {
+                       *why = _("上り階段生成に失敗", "Failed to generate up stairs.");
+                       return FALSE;
+               }
        }
 
        if (!dun->laketype)
@@ -886,7 +863,7 @@ static bool cave_gen(floor_type *floor_ptr)
                        /* Hack -- Add some quartz streamers */
                        for (i = 0; i < DUN_STR_QUA; i++)
                        {
-                               build_streamer(floor_ptr, dungeon_ptr->stream2, DUN_STR_QC);
+                               build_streamer(player_ptr, dungeon_ptr->stream2, DUN_STR_QC);
                        }
                }
 
@@ -895,7 +872,7 @@ static bool cave_gen(floor_type *floor_ptr)
                        /* Hack -- Add some magma streamers */
                        for (i = 0; i < DUN_STR_MAG; i++)
                        {
-                               build_streamer(floor_ptr, dungeon_ptr->stream1, DUN_STR_MC);
+                               build_streamer(player_ptr, dungeon_ptr->stream1, DUN_STR_MC);
                        }
                }
        }
@@ -903,21 +880,29 @@ static bool cave_gen(floor_type *floor_ptr)
        /* Special boundary walls -- Top and bottom */
        for (x = 0; x < floor_ptr->width; x++)
        {
-               place_bound_perm_wall(&floor_ptr->grid_array[0][x]);
-               place_bound_perm_wall(&floor_ptr->grid_array[floor_ptr->height - 1][x]);
+               place_bound_perm_wall(player_ptr, &floor_ptr->grid_array[0][x]);
+               place_bound_perm_wall(player_ptr, &floor_ptr->grid_array[floor_ptr->height - 1][x]);
        }
 
        /* Special boundary walls -- Left and right */
        for (y = 1; y < (floor_ptr->height - 1); y++)
        {
-               place_bound_perm_wall(&floor_ptr->grid_array[y][0]);
-               place_bound_perm_wall(&floor_ptr->grid_array[y][floor_ptr->width - 1]);
+               place_bound_perm_wall(player_ptr, &floor_ptr->grid_array[y][0]);
+               place_bound_perm_wall(player_ptr, &floor_ptr->grid_array[y][floor_ptr->width - 1]);
        }
 
        /* Determine the character location */
-       if (!new_player_spot(p_ptr)) return FALSE;
+       if (!new_player_spot(player_ptr))
+       {
+               *why = _("プレイヤー配置に失敗", "Failed to place a player");
+               return FALSE;
+       }
 
-       if (!place_quest_monsters(floor_ptr, p_ptr)) return FALSE;
+       if (!place_quest_monsters(player_ptr))
+       {
+               *why = _("クエストモンスター配置に失敗", "Failed to place a quest monster");
+               return FALSE;
+       }
 
        /* Basic "amount" */
        k = (floor_ptr->dun_level / 3);
@@ -947,44 +932,50 @@ static bool cave_gen(floor_type *floor_ptr)
        /* Put some monsters in the dungeon */
        for (i = i + k; i > 0; i--)
        {
-               (void)alloc_monster(0, PM_ALLOW_SLEEP);
+               (void)alloc_monster(player_ptr, 0, PM_ALLOW_SLEEP);
        }
 
        /* Place some traps in the dungeon */
-       alloc_object(floor_ptr, ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
+       alloc_object(player_ptr, ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
 
        /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
-       if (!(dungeon_ptr->flags1 & DF1_NO_CAVE)) alloc_object(floor_ptr, ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
+       if (!(dungeon_ptr->flags1 & DF1_NO_CAVE)) alloc_object(player_ptr, ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
 
        /* Mega Hack -- No object at first level of deeper dungeon */
-       if (p_ptr->enter_dungeon && floor_ptr->dun_level > 1)
+       if (player_ptr->enter_dungeon && floor_ptr->dun_level > 1)
        {
                /* No stair scum! */
                floor_ptr->object_level = 1;
        }
 
        /* Put some objects in rooms */
-       alloc_object(floor_ptr, ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
+       alloc_object(player_ptr, ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
 
        /* Put some objects/gold in the dungeon */
-       alloc_object(floor_ptr, ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
-       alloc_object(floor_ptr, ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
+       alloc_object(player_ptr, ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
+       alloc_object(player_ptr, ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
 
        /* Set back to default */
        floor_ptr->object_level = floor_ptr->base_level;
 
        /* Put the Guardian */
-       if (!alloc_guardian(TRUE)) return FALSE;
+       if (!alloc_guardian(player_ptr, TRUE))
+       {
+               *why = _("ダンジョンの主配置に失敗", "Failed to place a dungeon guardian");
+               return FALSE;
+       }
 
-       if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > floor_ptr->dun_level)) && !(dungeon_ptr->flags1 & DF1_DARKNESS))
+       bool is_empty_or_dark = dun->empty_level;
+       is_empty_or_dark &= !one_in_(DARK_EMPTY) || (randint1(100) > floor_ptr->dun_level);
+       is_empty_or_dark &= (dungeon_ptr->flags1 & DF1_DARKNESS) == 0;
+       if (!is_empty_or_dark) return TRUE;
+
+       /* Lite the floor_ptr->grid_array */
+       for (y = 0; y < floor_ptr->height; y++)
        {
-               /* Lite the floor_ptr->grid_array */
-               for (y = 0; y < floor_ptr->height; y++)
+               for (x = 0; x < floor_ptr->width; x++)
                {
-                       for (x = 0; x < floor_ptr->width; x++)
-                       {
-                               floor_ptr->grid_array[y][x].info |= (CAVE_GLOW);
-                       }
+                       floor_ptr->grid_array[y][x].info |= (CAVE_GLOW);
                }
        }
 
@@ -993,12 +984,13 @@ static bool cave_gen(floor_type *floor_ptr)
 
 /*!
  * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
-static void build_arena(floor_type *floor_ptr)
+static void build_arena(player_type *player_ptr, POSITION *start_y, POSITION *start_x)
 {
        POSITION yval, y_height, y_depth, xval, x_left, x_right;
-       register int i, j;
+       POSITION i, j;
 
        yval = SCREEN_HGT / 2;
        xval = SCREEN_WID / 2;
@@ -1007,58 +999,59 @@ static void build_arena(floor_type *floor_ptr)
        x_left = xval - 32;
        x_right = xval + 32;
 
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        for (i = y_height; i <= y_height + 5; i++)
                for (j = x_left; j <= x_right; j++)
                {
-                       place_extra_perm_bold(floor_ptr, i, j);
+                       place_bold(player_ptr, i, j, GB_EXTRA_PERM);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (i = y_depth; i >= y_depth - 5; i--)
                for (j = x_left; j <= x_right; j++)
                {
-                       place_extra_perm_bold(floor_ptr, i, j);
+                       place_bold(player_ptr, i, j, GB_EXTRA_PERM);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_left; j <= x_left + 17; j++)
                for (i = y_height; i <= y_depth; i++)
                {
-                       place_extra_perm_bold(floor_ptr, i, j);
+                       place_bold(player_ptr, i, j, GB_EXTRA_PERM);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_right; j >= x_right - 17; j--)
                for (i = y_height; i <= y_depth; i++)
                {
-                       place_extra_perm_bold(floor_ptr, i, j);
+                       place_bold(player_ptr, i, j, GB_EXTRA_PERM);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
-       place_extra_perm_bold(floor_ptr, y_height+6, x_left+18);
-       floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_depth-6, x_left+18);
-       floor_ptr->grid_array[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_height+6, x_right-18);
-       floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_depth-6, x_right-18);
-       floor_ptr->grid_array[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
+       place_bold(player_ptr, y_height + 6, x_left + 18, GB_EXTRA_PERM);
+       floor_ptr->grid_array[y_height + 6][x_left + 18].info |= (CAVE_GLOW | CAVE_MARK);
+       place_bold(player_ptr, y_depth - 6, x_left + 18, GB_EXTRA_PERM);
+       floor_ptr->grid_array[y_depth - 6][x_left + 18].info |= (CAVE_GLOW | CAVE_MARK);
+       place_bold(player_ptr, y_height + 6, x_right - 18, GB_EXTRA_PERM);
+       floor_ptr->grid_array[y_height + 6][x_right - 18].info |= (CAVE_GLOW | CAVE_MARK);
+       place_bold(player_ptr, y_depth - 6, x_right - 18, GB_EXTRA_PERM);
+       floor_ptr->grid_array[y_depth - 6][x_right - 18].info |= (CAVE_GLOW | CAVE_MARK);
 
-       i = y_height + 5;
-       j = xval;
-       floor_ptr->grid_array[i][j].feat = f_tag_to_index("ARENA_GATE");
-       floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
-       player_place(p_ptr, i, j);
+       *start_y = y_height + 5;
+       *start_x = xval;
+       floor_ptr->grid_array[*start_y][*start_x].feat = f_tag_to_index("ARENA_GATE");
+       floor_ptr->grid_array[*start_y][*start_x].info |= (CAVE_GLOW | CAVE_MARK);
 }
 
 /*!
  * @brief 挑戦時闘技場への入場処理 / Town logic flow for generation of arena -KMW-
  * @return なし
  */
-static void generate_challenge_arena(floor_type *floor_ptr, player_type *challanger_ptr)
+static void generate_challenge_arena(player_type *challanger_ptr)
 {
        POSITION y, x;
        POSITION qy = 0;
        POSITION qx = 0;
 
        /* Smallest area */
+       floor_type *floor_ptr = challanger_ptr->current_floor_ptr;
        floor_ptr->height = SCREEN_HGT;
        floor_ptr->width = SCREEN_WID;
 
@@ -1068,7 +1061,7 @@ static void generate_challenge_arena(floor_type *floor_ptr, player_type *challan
                for (x = 0; x < MAX_WID; x++)
                {
                        /* Create "solid" perma-wall */
-                       place_solid_perm_bold(y, x);
+                       place_bold(challanger_ptr, y, x, GB_SOLID_PERM);
 
                        /* Illuminate and memorize the walls */
                        floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
@@ -1085,22 +1078,24 @@ static void generate_challenge_arena(floor_type *floor_ptr, player_type *challan
                }
        }
 
-       build_arena(floor_ptr);
+       build_arena(challanger_ptr, &y, &x);
+       player_place(challanger_ptr, y, x);
 
-       if(!place_monster_aux(0, challanger_ptr->y + 5, challanger_ptr->x, arena_info[challanger_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET)))
+       if(!place_monster_aux(challanger_ptr, 0, challanger_ptr->y + 5, challanger_ptr->x, arena_info[challanger_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET)))
        {
                challanger_ptr->exit_bldg = TRUE;
                challanger_ptr->arena_number++;
                msg_print(_("相手は欠場した。あなたの不戦勝だ。", "The enemy is unable appear. You won by default."));
        }
-
 }
 
+
 /*!
  * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
-static void build_battle(floor_type *floor_ptr)
+static void build_battle(player_type *player_ptr, POSITION *y, POSITION *x)
 {
        POSITION yval, y_height, y_depth, xval, x_left, x_right;
        register int i, j;
@@ -1112,38 +1107,39 @@ static void build_battle(floor_type *floor_ptr)
        x_left = xval - 32;
        x_right = xval + 32;
 
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        for (i = y_height; i <= y_height + 5; i++)
                for (j = x_left; j <= x_right; j++)
                {
-                       place_extra_perm_bold(floor_ptr, i, j);
+                       place_bold(player_ptr, i, j, GB_EXTRA_PERM);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (i = y_depth; i >= y_depth - 3; i--)
                for (j = x_left; j <= x_right; j++)
                {
-                       place_extra_perm_bold(floor_ptr, i, j);
+                       place_bold(player_ptr, i, j, GB_EXTRA_PERM);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_left; j <= x_left + 17; j++)
                for (i = y_height; i <= y_depth; i++)
                {
-                       place_extra_perm_bold(floor_ptr, i, j);
+                       place_bold(player_ptr, i, j, GB_EXTRA_PERM);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_right; j >= x_right - 17; j--)
                for (i = y_height; i <= y_depth; i++)
                {
-                       place_extra_perm_bold(floor_ptr, i, j);
+                       place_bold(player_ptr, i, j, GB_EXTRA_PERM);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
-       place_extra_perm_bold(floor_ptr, y_height+6, x_left+18);
+       place_bold(player_ptr, y_height+6, x_left+18, GB_EXTRA_PERM);
        floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_depth-4, x_left+18);
+       place_bold(player_ptr, y_depth-4, x_left+18, GB_EXTRA_PERM);
        floor_ptr->grid_array[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_height+6, x_right-18);
+       place_bold(player_ptr, y_height+6, x_right-18, GB_EXTRA_PERM);
        floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_depth-4, x_right-18);
+       place_bold(player_ptr, y_depth-4, x_right-18, GB_EXTRA_PERM);
        floor_ptr->grid_array[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
 
        for (i = y_height + 1; i <= y_height + 5; i++)
@@ -1156,14 +1152,16 @@ static void build_battle(floor_type *floor_ptr)
        j = xval;
        floor_ptr->grid_array[i][j].feat = f_tag_to_index("BUILDING_3");
        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
-       player_place(p_ptr, i, j);
+
+       *y = i;
+       *x = j;
 }
 
 /*!
  * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
  * @return なし
  */
-static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature_ptr)
+static void generate_gambling_arena(player_type *creature_ptr)
 {
        POSITION y, x;
        MONSTER_IDX i;
@@ -1171,12 +1169,13 @@ static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature
        POSITION qx = 0;
 
        /* Start with solid walls */
+       floor_type *floor_ptr = creature_ptr->current_floor_ptr;
        for (y = 0; y < MAX_HGT; y++)
        {
                for (x = 0; x < MAX_WID; x++)
                {
                        /* Create "solid" perma-wall */
-                       place_solid_perm_bold(y, x);
+                       place_bold(creature_ptr, y, x, GB_SOLID_PERM);
 
                        /* Illuminate and memorize the walls */
                        floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
@@ -1193,11 +1192,13 @@ static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature
                }
        }
 
-       build_battle(floor_ptr);
+       build_battle(creature_ptr, &y, &x);
+
+       player_place(creature_ptr, y, x);
 
        for(i = 0; i < 4; i++)
        {
-               place_monster_aux(0, creature_ptr->y + 8 + (i/2)*4, creature_ptr->x - 2 + (i%2)*4, battle_mon[i], (PM_NO_KAGE | PM_NO_PET));
+               place_monster_aux(creature_ptr, 0, creature_ptr->y + 8 + (i/2)*4, creature_ptr->x - 2 + (i%2)*4, battle_mon[i], (PM_NO_KAGE | PM_NO_PET));
                set_friendly(&floor_ptr->m_list[floor_ptr->grid_array[creature_ptr->y+8+(i/2)*4][creature_ptr->x-2+(i%2)*4].m_idx]);
        }
        for(i = 1; i < floor_ptr->m_max; i++)
@@ -1207,48 +1208,52 @@ static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature
                if (!monster_is_valid(m_ptr)) continue;
 
                m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
-               update_monster(p_ptr, i, FALSE);
+               update_monster(creature_ptr, i, FALSE);
        }
 }
 
 /*!
  * @brief 固定マップクエストのフロア生成 / Generate a quest level
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
-static void generate_fixed_floor(floor_type *floor_ptr)
+static void generate_fixed_floor(player_type *player_ptr)
 {
        POSITION x, y;
 
        /* Start with perm walls */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        for (y = 0; y < floor_ptr->height; y++)
        {
                for (x = 0; x < floor_ptr->width; x++)
                {
-                       place_solid_perm_bold(y, x);
+                       place_bold(player_ptr, y, x, GB_SOLID_PERM);
                }
        }
 
        /* Set the quest level */
-       floor_ptr->base_level = quest[p_ptr->current_floor_ptr->inside_quest].level;
+       floor_ptr->base_level = quest[floor_ptr->inside_quest].level;
        floor_ptr->dun_level = floor_ptr->base_level;
        floor_ptr->object_level = floor_ptr->base_level;
        floor_ptr->monster_level = floor_ptr->base_level;
 
-       if (record_stair) exe_write_diary(p_ptr, NIKKI_TO_QUEST, p_ptr->current_floor_ptr->inside_quest, NULL);
-       get_mon_num_prep(get_monster_hook(), NULL);
+       if (record_stair) exe_write_diary(player_ptr, DIARY_TO_QUEST, floor_ptr->inside_quest, NULL);
+       get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), NULL);
 
        init_flags = INIT_CREATE_DUNGEON;
 
-       process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
+       process_dungeon_file(player_ptr, "q_info.txt", 0, 0, MAX_HGT, MAX_WID);
 }
 
 /*!
  * @brief ダンジョン時のランダムフロア生成 / Make a real level
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param concptr
  * @return フロアの生成に成功したらTRUE
  */
-static bool level_gen(floor_type *floor_ptr, concptr *why)
+static bool level_gen(player_type *player_ptr, concptr *why)
 {
-       int level_height, level_width;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        DUNGEON_IDX d_idx = floor_ptr->dungeon_idx;
 
        if ((always_small_levels || ironman_small_levels ||
@@ -1257,6 +1262,7 @@ static bool level_gen(floor_type *floor_ptr, concptr *why)
            (d_info[d_idx].flags1 & DF1_SMALLEST)) &&
            !(d_info[d_idx].flags1 & DF1_BIG))
        {
+               int level_height, level_width;
                if (d_info[d_idx].flags1 & DF1_SMALLEST)
                {
                        level_height = 1;
@@ -1269,12 +1275,17 @@ static bool level_gen(floor_type *floor_ptr, concptr *why)
                }
                else
                {
-                       do
+                       level_height = randint1(MAX_HGT / SCREEN_HGT);
+                       level_width = randint1(MAX_WID / SCREEN_WID);
+                       bool is_first_level_area = TRUE;
+                       bool is_max_area = (level_height == MAX_HGT / SCREEN_HGT) && (level_width == MAX_WID / SCREEN_WID);
+                       while (is_first_level_area || is_max_area)
                        {
-                               level_height = randint1(MAX_HGT/SCREEN_HGT);
-                               level_width = randint1(MAX_WID/SCREEN_WID);
+                               level_height = randint1(MAX_HGT / SCREEN_HGT);
+                               level_width = randint1(MAX_WID / SCREEN_WID);
+                               is_first_level_area = FALSE;
+                               is_max_area = (level_height == MAX_HGT / SCREEN_HGT) && (level_width == MAX_WID / SCREEN_WID);
                        }
-                       while ((level_height == MAX_HGT/SCREEN_HGT) && (level_width == MAX_WID/SCREEN_WID));
                }
 
                floor_ptr->height = level_height * SCREEN_HGT;
@@ -1299,18 +1310,16 @@ static bool level_gen(floor_type *floor_ptr, concptr *why)
                panel_col_min = floor_ptr->width;
        }
 
-       /* Make a dungeon */
-       floor_ptr->dungeon_idx = d_idx;
-       if (!cave_gen(floor_ptr))
+       if (!cave_gen(player_ptr, why))
        {
-               *why = _("ダンジョン生成に失敗", "could not place player");
                return FALSE;
        }
+
        else return TRUE;
 }
 
 /*!
- * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after p_ptr->current_floor_ptr->grid_array generation
+ * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after grid_array generation
  * @return なし
  */
 void wipe_generate_random_floor_flags(floor_type *floor_ptr)
@@ -1340,15 +1349,17 @@ void wipe_generate_random_floor_flags(floor_type *floor_ptr)
 }
 
 /*!
- * @brief フロアの全情報を初期化する / Clear and empty the p_ptr->current_floor_ptr->grid_array
+ * @brief フロアの全情報を初期化する / Clear and empty floor.
+ * @parama player_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
-void clear_cave(floor_type *floor_ptr)
+void clear_cave(player_type *player_ptr)
 {
        POSITION x, y;
        int i;
 
        /* Very simplified version of wipe_o_list() */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        (void)C_WIPE(floor_ptr->o_list, floor_ptr->o_max, object_type);
        floor_ptr->o_max = 1;
        floor_ptr->o_cnt = 0;
@@ -1362,7 +1373,7 @@ void clear_cave(floor_type *floor_ptr)
        for (i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0;
 
        /* Pre-calc cur_num of pets in party_mon[] */
-       precalc_cur_num_of_pet();
+       precalc_cur_num_of_pet(player_ptr);
 
 
        /* Start with a blank floor_ptr->grid_array */
@@ -1383,9 +1394,6 @@ void clear_cave(floor_type *floor_ptr)
                }
        }
 
-       /* Mega-Hack -- no player yet */
-       p_ptr->x = p_ptr->y = 0;
-
        /* Set the base level */
        floor_ptr->base_level = floor_ptr->dun_level;
 
@@ -1399,14 +1407,16 @@ void clear_cave(floor_type *floor_ptr)
 
 /*!
  * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
+ * @parama player_ptr プレーヤーへの参照ポインタ
  * @return なし
  * @note Hack -- regenerate any "overflow" levels
  */
-void generate_floor(floor_type *floor_ptr)
+void generate_floor(player_type *player_ptr)
 {
        int num;
-
        /* Fill the arrays of floors and walls in the good proportions */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       floor_ptr->dungeon_idx = player_ptr->dungeon_idx;
        set_floor_and_wall(floor_ptr->dungeon_idx);
 
        /* Generate */
@@ -1415,35 +1425,38 @@ void generate_floor(floor_type *floor_ptr)
                bool okay = TRUE;
                concptr why = NULL;
 
-               clear_cave(floor_ptr);
+               clear_cave(player_ptr);
 
-               if (p_ptr->current_floor_ptr->inside_arena)
+               /* Mega-Hack -- no player yet */
+               player_ptr->x = player_ptr->y = 0;
+
+               if (floor_ptr->inside_arena)
                {
-                       generate_challenge_arena(floor_ptr, p_ptr);
+                       generate_challenge_arena(player_ptr);
                }
 
-               else if (p_ptr->phase_out)
+               else if (player_ptr->phase_out)
                {
-                       generate_gambling_arena(floor_ptr, p_ptr);
+                       generate_gambling_arena(player_ptr);
                }
 
-               else if (p_ptr->current_floor_ptr->inside_quest)
+               else if (floor_ptr->inside_quest)
                {
-                       generate_fixed_floor(floor_ptr);
+                       generate_fixed_floor(player_ptr);
                }
 
                /* Build the town */
                else if (!floor_ptr->dun_level)
                {
                        /* Make the wilderness */
-                       if (p_ptr->wild_mode) wilderness_gen_small(p_ptr, floor_ptr);
-                       else wilderness_gen(floor_ptr);
+                       if (player_ptr->wild_mode) wilderness_gen_small(player_ptr);
+                       else wilderness_gen(player_ptr);
                }
 
                /* Build a real level */
                else
                {
-                       okay = level_gen(floor_ptr, &why);
+                       okay = level_gen(player_ptr, &why);
                }
 
 
@@ -1466,14 +1479,14 @@ void generate_floor(floor_type *floor_ptr)
                if (why) msg_format(_("生成やり直し(%s)", "Generation restarted (%s)"), why);
 
                wipe_o_list(floor_ptr);
-               wipe_m_list();
+               wipe_monsters_list(player_ptr);
        }
 
-       /* Glow deep lava and building entrances */
-       glow_deep_lava_and_bldg(floor_ptr);
+       /* Glow deep lava and building entrances tempor */
+       glow_deep_lava_and_bldg(player_ptr);
 
        /* Reset flag */
-       p_ptr->enter_dungeon = FALSE;
+       player_ptr->enter_dungeon = FALSE;
 
        wipe_generate_random_floor_flags(floor_ptr);
 }
@@ -1522,6 +1535,7 @@ static void correct_dir(POSITION *rdir, POSITION *cdir, POSITION y1, POSITION x1
 
 /*!
 * @brief 部屋間のトンネルを生成する / Constructs a tunnel between two points
+* @param player_ptr プレーヤーへの参照ポインタ
 * @param row1 始点Y座標
 * @param col1 始点X座標
 * @param row2 終点Y座標
@@ -1555,7 +1569,7 @@ static void correct_dir(POSITION *rdir, POSITION *cdir, POSITION y1, POSITION x1
 *   outer -- outer room walls\n
 *   solid -- solid room walls\n
 */
-bool build_tunnel(floor_type *floor_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2)
+bool build_tunnel(player_type *player_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2)
 {
        POSITION y, x;
        POSITION tmp_row, tmp_col;
@@ -1575,6 +1589,7 @@ bool build_tunnel(floor_type *floor_ptr, POSITION row1, POSITION col1, POSITION
        correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
 
        /* Keep going until done (or bored) */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        while ((row1 != row2) || (col1 != col2))
        {
                /* Mega-Hack -- Paranoia -- prevent infinite loops */
@@ -1653,7 +1668,7 @@ bool build_tunnel(floor_type *floor_ptr, POSITION row1, POSITION col1, POSITION
                                        if (is_outer_bold(floor_ptr, y, x))
                                        {
                                                /* Change the wall to a "solid" wall */
-                                               place_solid_noperm_bold(y, x);
+                                               place_bold(player_ptr, y, x, GB_SOLID_NOPERM);
                                        }
                                }
                        }
@@ -1733,6 +1748,7 @@ bool build_tunnel(floor_type *floor_ptr, POSITION row1, POSITION col1, POSITION
 
 /*!
 * @brief トンネル生成のための基準点を指定する。
+* @param player_ptr プレーヤーへの参照ポインタ
 * @param x 基準点を指定するX座標の参照ポインタ、適時値が修正される。
 * @param y 基準点を指定するY座標の参照ポインタ、適時値が修正される。
 * @param affectwall (調査中)
@@ -1749,10 +1765,11 @@ bool build_tunnel(floor_type *floor_ptr, POSITION row1, POSITION col1, POSITION
 * routine.\n
 * @todo 特に詳細な処理の意味を調査すべし
 */
-static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool affectwall)
+static bool set_tunnel(player_type *player_ptr, POSITION *x, POSITION *y, bool affectwall)
 {
        int i, j, dx, dy;
 
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        grid_type *g_ptr = &floor_ptr->grid_array[*y][*x];
 
        if (!in_bounds(floor_ptr, *y, *x)) return TRUE;
@@ -1802,7 +1819,7 @@ static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool aff
                                if (is_outer_bold(floor_ptr, j, i))
                                {
                                        /* Change the wall to a "solid" wall */
-                                       place_solid_noperm_bold(j, i);
+                                       place_bold(player_ptr, j, i, GB_SOLID_NOPERM);
                                }
                        }
                }
@@ -1810,7 +1827,7 @@ static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool aff
                /* Clear mimic type */
                floor_ptr->grid_array[*y][*x].mimic = 0;
 
-               place_floor_bold(floor_ptr, *y, *x);
+               place_bold(player_ptr, *y, *x, GB_FLOOR);
 
                return TRUE;
        }
@@ -1842,7 +1859,7 @@ static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool aff
                if (i == 0)
                {
                        /* Failed for some reason: hack - ignore the solidness */
-                       place_outer_grid(g_ptr);
+                       place_grid(player_ptr, g_ptr, GB_OUTER);
                        dx = 0;
                        dy = 0;
                }
@@ -1860,6 +1877,7 @@ static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool aff
 
 /*!
 * @brief 外壁を削って「カタコンベ状」の通路を作成する / This routine creates the catacomb-like tunnels by removing extra rock.
+* @param player_ptr プレーヤーへの参照ポインタ
 * @param x 基準点のX座標
 * @param y 基準点のY座標
 * @return なし
@@ -1867,31 +1885,32 @@ static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool aff
 * Note that this routine is only called on "even" squares - so it gives
 * a natural checkerboard pattern.
 */
-static void create_cata_tunnel(floor_type *floor_ptr, POSITION x, POSITION y)
+static void create_cata_tunnel(player_type *player_ptr, POSITION x, POSITION y)
 {
        POSITION x1, y1;
 
        /* Build tunnel */
        x1 = x - 1;
        y1 = y;
-       set_tunnel(floor_ptr, &x1, &y1, FALSE);
+       set_tunnel(player_ptr, &x1, &y1, FALSE);
 
        x1 = x + 1;
        y1 = y;
-       set_tunnel(floor_ptr, &x1, &y1, FALSE);
+       set_tunnel(player_ptr, &x1, &y1, FALSE);
 
        x1 = x;
        y1 = y - 1;
-       set_tunnel(floor_ptr, &x1, &y1, FALSE);
+       set_tunnel(player_ptr, &x1, &y1, FALSE);
 
        x1 = x;
        y1 = y + 1;
-       set_tunnel(floor_ptr, &x1, &y1, FALSE);
+       set_tunnel(player_ptr, &x1, &y1, FALSE);
 }
 
 
 /*!
 * @brief トンネル生成処理(詳細調査中)/ This routine does the bulk of the work in creating the new types of tunnels.
+* @param player_ptr プレーヤーへの参照ポインタ
 * @return なし
 * @todo 詳細用調査
 * @details
@@ -1912,7 +1931,7 @@ static void create_cata_tunnel(floor_type *floor_ptr, POSITION x, POSITION y)
 * This, when used with longer line segments gives the "catacomb-like" tunnels seen near\n
 * the surface.\n
 */
-static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
+static void short_seg_hack(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
 {
        int i;
        POSITION x, y;
@@ -1932,7 +1951,7 @@ static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSI
                {
                        x = x1 + i * (x2 - x1) / length;
                        y = y1 + i * (y2 - y1) / length;
-                       if (!set_tunnel(floor_ptr, &x, &y, TRUE))
+                       if (!set_tunnel(player_ptr, &x, &y, TRUE))
                        {
                                if (count > 50)
                                {
@@ -1942,8 +1961,8 @@ static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSI
                                }
 
                                /* solid wall - so try to go around */
-                               short_seg_hack(floor_ptr, x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
-                               short_seg_hack(floor_ptr, x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
+                               short_seg_hack(player_ptr, x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
+                               short_seg_hack(player_ptr, x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
                        }
                }
        }
@@ -1955,15 +1974,15 @@ static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSI
                        {
                                x = i;
                                y = y1;
-                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
+                               if (!set_tunnel(player_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(floor_ptr, x, y, i - 1, y1, 1, count, fail);
-                                       short_seg_hack(floor_ptr, x, y, i + 1, y1, 1, count, fail);
+                                       short_seg_hack(player_ptr, x, y, i - 1, y1, 1, count, fail);
+                                       short_seg_hack(player_ptr, x, y, i + 1, y1, 1, count, fail);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(floor_ptr, i, y1);
+                                       create_cata_tunnel(player_ptr, i, y1);
                                }
                        }
                }
@@ -1973,15 +1992,15 @@ static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSI
                        {
                                x = i;
                                y = y1;
-                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
+                               if (!set_tunnel(player_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(floor_ptr, x, y, i - 1, y1, 1, count, fail);
-                                       short_seg_hack(floor_ptr, x, y, i + 1, y1, 1, count, fail);
+                                       short_seg_hack(player_ptr, x, y, i - 1, y1, 1, count, fail);
+                                       short_seg_hack(player_ptr, x, y, i + 1, y1, 1, count, fail);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(floor_ptr, i, y1);
+                                       create_cata_tunnel(player_ptr, i, y1);
                                }
                        }
 
@@ -1992,15 +2011,15 @@ static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSI
                        {
                                x = x2;
                                y = i;
-                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
+                               if (!set_tunnel(player_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(floor_ptr, x, y, x2, i - 1, 1, count, fail);
-                                       short_seg_hack(floor_ptr, x, y, x2, i + 1, 1, count, fail);
+                                       short_seg_hack(player_ptr, x, y, x2, i - 1, 1, count, fail);
+                                       short_seg_hack(player_ptr, x, y, x2, i + 1, 1, count, fail);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(floor_ptr, x2, i);
+                                       create_cata_tunnel(player_ptr, x2, i);
                                }
                        }
                }
@@ -2010,15 +2029,15 @@ static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSI
                        {
                                x = x2;
                                y = i;
-                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
+                               if (!set_tunnel(player_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(floor_ptr, x, y, x2, i - 1, 1, count, fail);
-                                       short_seg_hack(floor_ptr, x, y, x2, i + 1, 1, count, fail);
+                                       short_seg_hack(player_ptr, x, y, x2, i - 1, 1, count, fail);
+                                       short_seg_hack(player_ptr, x, y, x2, i + 1, 1, count, fail);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(floor_ptr, x2, i);
+                                       create_cata_tunnel(player_ptr, x2, i);
                                }
                        }
                }
@@ -2040,7 +2059,7 @@ static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSI
 * Note it is VERY important that the "stop if hit another passage" logic\n
 * stays as is.  Without this the dungeon turns into Swiss Cheese...\n
 */
-bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
+bool build_tunnel2(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
 {
        POSITION x3, y3, dx, dy;
        POSITION changex, changey;
@@ -2050,7 +2069,7 @@ bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2,
        grid_type *g_ptr;
 
        length = distance(x1, y1, x2, y2);
-
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (length > cutoff)
        {
                /*
@@ -2098,7 +2117,7 @@ bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2,
                        if (i == 0)
                        {
                                /* Failed for some reason: hack - ignore the solidness */
-                               place_outer_bold(floor_ptr, y3, x3);
+                               place_bold(player_ptr, y3, x3, GB_OUTER);
                                dx = 0;
                                dy = 0;
                        }
@@ -2109,12 +2128,12 @@ bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2,
 
                if (is_floor_grid(g_ptr))
                {
-                       if (build_tunnel2(floor_ptr, x1, y1, x3, y3, type, cutoff))
+                       if (build_tunnel2(player_ptr, x1, y1, x3, y3, type, cutoff))
                        {
                                if ((floor_ptr->grid_array[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
                                {
                                        /* do second half only if works + if have hit a room */
-                                       retval = build_tunnel2(floor_ptr, x3, y3, x2, y2, type, cutoff);
+                                       retval = build_tunnel2(player_ptr, x3, y3, x2, y2, type, cutoff);
                                }
                                else
                                {
@@ -2142,9 +2161,9 @@ bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2,
                else
                {
                        /* tunnel through walls */
-                       if (build_tunnel2(floor_ptr, x1, y1, x3, y3, type, cutoff))
+                       if (build_tunnel2(player_ptr, x1, y1, x3, y3, type, cutoff))
                        {
-                               retval = build_tunnel2(floor_ptr, x3, y3, x2, y2, type, cutoff);
+                               retval = build_tunnel2(player_ptr, x3, y3, x2, y2, type, cutoff);
                                firstsuccede = TRUE;
                        }
                        else
@@ -2157,7 +2176,7 @@ bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2,
                if (firstsuccede)
                {
                        /* only do this if the first half has worked */
-                       set_tunnel(floor_ptr, &x3, &y3, TRUE);
+                       set_tunnel(player_ptr, &x3, &y3, TRUE);
                }
                /* return value calculated above */
                return retval;
@@ -2166,7 +2185,7 @@ bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2,
        {
                /* Do a short segment */
                retval = TRUE;
-               short_seg_hack(floor_ptr, x1, y1, x2, y2, type, 0, &retval);
+               short_seg_hack(player_ptr, x1, y1, x2, y2, type, 0, &retval);
 
                /* Hack - ignore return value so avoid infinite loops */
                return TRUE;