OSDN Git Service

[Refactor] #38997 o_pop()、drop_near()、inven_drop() にplayer_type *引数を追加 (コールチェーンが長いのでそ...
[hengband/hengband.git] / src / floor-generate.c
index ee37df3..3b4989a 100644 (file)
@@ -144,17 +144,17 @@ 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(POSITION y, POSITION x)
+static int next_to_walls(floor_type* floor_ptr, POSITION y, POSITION x)
 {
        int k = 0;
 
-       if (in_bounds(p_ptr->current_floor_ptr, y + 1, x) && is_extra_bold(y + 1, x)) k++;
-       if (in_bounds(p_ptr->current_floor_ptr, y - 1, x) && is_extra_bold(y - 1, x)) k++;
-       if (in_bounds(p_ptr->current_floor_ptr, y, x + 1) && is_extra_bold(y, x + 1)) k++;
-       if (in_bounds(p_ptr->current_floor_ptr, y, x - 1) && is_extra_bold(y, x - 1)) k++;
+       if (in_bounds(floor_ptr, y + 1, x) && is_extra_bold(floor_ptr, y + 1, x)) k++;
+       if (in_bounds(floor_ptr, y - 1, x) && is_extra_bold(floor_ptr, y - 1, x)) k++;
+       if (in_bounds(floor_ptr, y, x + 1) && is_extra_bold(floor_ptr, y, x + 1)) k++;
+       if (in_bounds(floor_ptr, y, x - 1) && is_extra_bold(floor_ptr, y, x - 1)) k++;
 
        return (k);
 }
@@ -166,9 +166,9 @@ static int next_to_walls(POSITION y, POSITION x)
  * @param walls 最低減隣接させたい外壁の数
  * @return 階段を生成して問題がないならばTRUEを返す。
  */
-static bool alloc_stairs_aux(POSITION y, POSITION x, int walls)
+static bool alloc_stairs_aux(floor_type *floor_ptr, POSITION y, POSITION x, int walls)
 {
-       grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
+       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
 
        /* Require "naked" floor grid */
        if (!is_floor_grid(g_ptr)) return FALSE;
@@ -176,7 +176,7 @@ static bool alloc_stairs_aux(POSITION y, POSITION x, int walls)
        if (g_ptr->o_idx || g_ptr->m_idx) return FALSE;
 
        /* Require a certain number of adjacent walls */
-       if (next_to_walls(y, x) < walls) return FALSE;
+       if (next_to_walls(floor_ptr, y, x) < walls) return FALSE;
 
        return TRUE;
 }
@@ -189,7 +189,7 @@ static bool alloc_stairs_aux(POSITION y, POSITION x, int walls)
  * @param walls 最低減隣接させたい外壁の数
  * @return 規定数通りに生成に成功したらTRUEを返す。
  */
-static bool alloc_stairs(FEAT_IDX feat, int num, int walls)
+static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int walls)
 {
        int i;
        int shaft_num = 0;
@@ -199,17 +199,17 @@ static bool alloc_stairs(FEAT_IDX feat, int num, int walls)
        if (have_flag(f_ptr->flags, FF_LESS))
        {
                /* No up stairs in town or in ironman mode */
-               if (ironman_downward || !p_ptr->current_floor_ptr->dun_level) return TRUE;
+               if (ironman_downward || !floor_ptr->dun_level) return TRUE;
 
-               if (p_ptr->current_floor_ptr->dun_level > d_info[p_ptr->dungeon_idx].mindepth)
+               if (floor_ptr->dun_level > d_info[floor_ptr->dungeon_idx].mindepth)
                        shaft_num = (randint1(num+1))/2;
        }
        else if (have_flag(f_ptr->flags, FF_MORE))
        {
-               QUEST_IDX q_idx = quest_number(p_ptr->current_floor_ptr->dun_level);
+               QUEST_IDX q_idx = quest_number(floor_ptr->dun_level);
 
                /* No downstairs on quest levels */
-               if (p_ptr->current_floor_ptr->dun_level > 1 && q_idx)
+               if (floor_ptr->dun_level > 1 && q_idx)
                {
                        monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
 
@@ -219,9 +219,9 @@ static bool alloc_stairs(FEAT_IDX feat, int num, int walls)
                }
 
                /* No downstairs at the bottom */
-               if (p_ptr->current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) return TRUE;
+               if (floor_ptr->dun_level >= d_info[floor_ptr->dungeon_idx].maxdepth) return TRUE;
 
-               if ((p_ptr->current_floor_ptr->dun_level < d_info[p_ptr->dungeon_idx].maxdepth-1) && !quest_number(p_ptr->current_floor_ptr->dun_level+1))
+               if ((floor_ptr->dun_level < d_info[floor_ptr->dungeon_idx].maxdepth-1) && !quest_number(floor_ptr->dun_level+1))
                        shaft_num = (randint1(num)+1)/2;
        }
        else return FALSE;
@@ -238,11 +238,11 @@ static bool alloc_stairs(FEAT_IDX feat, int num, int walls)
                        int candidates = 0;
                        int pick;
 
-                       for (y = 1; y < p_ptr->current_floor_ptr->height - 1; y++)
+                       for (y = 1; y < floor_ptr->height - 1; y++)
                        {
-                               for (x = 1; x < p_ptr->current_floor_ptr->width - 1; x++)
+                               for (x = 1; x < floor_ptr->width - 1; x++)
                                {
-                                       if (alloc_stairs_aux(y, x, walls))
+                                       if (alloc_stairs_aux(floor_ptr, y, x, walls))
                                        {
                                                /* A valid space found */
                                                candidates++;
@@ -264,11 +264,11 @@ static bool alloc_stairs(FEAT_IDX feat, int num, int walls)
                        /* Choose a random one */
                        pick = randint1(candidates);
 
-                       for (y = 1; y < p_ptr->current_floor_ptr->height - 1; y++)
+                       for (y = 1; y < floor_ptr->height - 1; y++)
                        {
-                               for (x = 1; x < p_ptr->current_floor_ptr->width - 1; x++)
+                               for (x = 1; x < floor_ptr->width - 1; x++)
                                {
-                                       if (alloc_stairs_aux(y, x, walls))
+                                       if (alloc_stairs_aux(floor_ptr, y, x, walls))
                                        {
                                                pick--;
 
@@ -279,7 +279,7 @@ static bool alloc_stairs(FEAT_IDX feat, int num, int walls)
 
                                if (!pick) break;
                        }
-                       g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
+                       g_ptr = &floor_ptr->grid_array[y][x];
 
                        /* Clear possible garbage of hidden trap */
                        g_ptr->mimic = 0;
@@ -333,7 +333,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(y, x)) continue;
+                       if (player_bold(p_ptr, y, x)) continue;
 
                        /* Check for "room" */
                        room = (floor_ptr->grid_array[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
@@ -367,20 +367,20 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
 
                        case ALLOC_TYP_TRAP:
                        {
-                               place_trap(y, x);
+                               place_trap(floor_ptr, y, x);
                                floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
                                break;
                        }
 
                        case ALLOC_TYP_GOLD:
                        {
-                               place_gold(y, x);
+                               place_gold(floor_ptr, y, x);
                                break;
                        }
 
                        case ALLOC_TYP_OBJECT:
                        {
-                               place_object(y, x, 0L);
+                               place_object(floor_ptr, y, x, 0L);
                                break;
                        }
                }
@@ -392,9 +392,11 @@ 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 近隣への即出現を避けるためのプレイヤークリーチャー参照ポインタ
  * @return 成功したならばTRUEを返す
  */
-bool place_quest_monsters(void)
+bool place_quest_monsters(floor_type *floor_ptr, player_type *creature_ptr)
 {
        int i;
 
@@ -408,8 +410,8 @@ bool place_quest_monsters(void)
                if (quest[i].status != QUEST_STATUS_TAKEN ||
                    (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
                     quest[i].type != QUEST_TYPE_RANDOM) ||
-                   quest[i].level != p_ptr->current_floor_ptr->dun_level ||
-                   p_ptr->dungeon_idx != quest[i].dungeon ||
+                   quest[i].level != floor_ptr->dun_level ||
+                   creature_ptr->dungeon_idx != quest[i].dungeon ||
                    (quest[i].flags & QUEST_FLAG_PRESET))
                {
                        /* Ignore it */
@@ -442,15 +444,15 @@ bool place_quest_monsters(void)
                                        grid_type    *g_ptr;
                                        feature_type *f_ptr;
 
-                                       y = randint0(p_ptr->current_floor_ptr->height);
-                                       x = randint0(p_ptr->current_floor_ptr->width);
+                                       y = randint0(floor_ptr->height);
+                                       x = randint0(floor_ptr->width);
 
-                                       g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
+                                       g_ptr = &floor_ptr->grid_array[y][x];
                                        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 (distance(y, x, p_ptr->y, p_ptr->x) < 10) continue;
+                                       if (distance(y, x, creature_ptr->y, creature_ptr->x) < 10) continue;
                                        if (g_ptr->info & CAVE_ICKY) continue;
                                        else break;
                                }
@@ -493,7 +495,7 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
                dun->destroyed = TRUE;
 
                /* extra rubble around the place looks cool */
-               build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
+               build_lake(floor_ptr, one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
        }
 
        /* Make a lake some of the time */
@@ -545,7 +547,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(dun->laketype);
+                       build_lake(floor_ptr, dun->laketype);
                }
        }
 
@@ -558,7 +560,7 @@ 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();
+               build_cavern(floor_ptr);
        }
 #endif /* ALLOW_CAVERNS_AND_LAKES */
 
@@ -570,14 +572,18 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
 /*!
  * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
  * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
  */
-static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
+static bool cave_gen(player_type *player_ptr)
 {
        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;
        floor_ptr->mon_lite_n = 0;
        floor_ptr->redraw_n = 0;
@@ -592,7 +598,7 @@ static bool cave_gen(dungeon_type* dungeon_ptr, 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);
+       set_floor_and_wall(floor_ptr->dungeon_idx);
        get_mon_num_prep(get_monster_hook(), NULL);
 
        /* Randomize the dungeon creation values */
@@ -632,22 +638,22 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                {
                        for (x = 0; x < floor_ptr->width; x++)
                        {
-                               place_floor_bold(y, x);
+                               place_floor_bold(floor_ptr, y, x);
                        }
                }
 
                /* Special boundary walls -- Top and bottom */
                for (x = 0; x < floor_ptr->width; x++)
                {
-                       place_extra_bold(0, x);
-                       place_extra_bold(floor_ptr->height - 1, x);
+                       place_extra_bold(floor_ptr, 0, x);
+                       place_extra_bold(floor_ptr, floor_ptr->height - 1, x);
                }
 
                /* Special boundary walls -- Left and right */
                for (y = 1; y < (floor_ptr->height - 1); y++)
                {
-                       place_extra_bold(y, 0);
-                       place_extra_bold(y, floor_ptr->width - 1);
+                       place_extra_bold(floor_ptr, y, 0);
+                       place_extra_bold(floor_ptr, y, floor_ptr->width - 1);
                }
        }
        else
@@ -657,7 +663,7 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                {
                        for (x = 0; x < floor_ptr->width; x++)
                        {
-                               place_extra_bold(y, x);
+                               place_extra_bold(floor_ptr, y, x);
                        }
                }
        }
@@ -668,13 +674,13 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
        /* Build maze */
        if (dungeon_ptr->flags1 & DF1_MAZE)
        {
-               build_maze_vault(floor_ptr->width/2-1, floor_ptr->height/2-1, floor_ptr->width-4, floor_ptr->height-4, FALSE);
+               build_maze_vault(floor_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(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
+               if (!alloc_stairs(floor_ptr, feat_down_stair, rand_range(2, 3), 3)) return FALSE;
 
                /* Place 1 or 2 up stairs near some walls */
-               if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
+               if (!alloc_stairs(floor_ptr, feat_up_stair, 1, 3)) return FALSE;
        }
 
        /* Build some rooms */
@@ -683,9 +689,9 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                int tunnel_fail_count = 0;
 
                /*
-                * Build each type of room in current_world_ptr->game_turn until we cannot build any more.
+                * Build each type of room in turn until we cannot build any more.
                 */
-               if (!generate_rooms()) return FALSE;
+               if (!generate_rooms(floor_ptr)) return FALSE;
 
 
                /* Make a hole in the dungeon roof sometimes at level 1 */
@@ -693,12 +699,12 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                {
                        while (one_in_(DUN_MOS_DEN))
                        {
-                               place_trees(randint1(floor_ptr->width - 2), randint1(floor_ptr->height - 2));
+                               place_trees(floor_ptr, randint1(floor_ptr->width - 2), randint1(floor_ptr->height - 2));
                        }
                }
 
                /* Destroy the level if necessary */
-               if (dun->destroyed) destroy_level();
+               if (dun->destroyed) destroy_level(player_ptr);
 
                /* Hack -- Add some rivers */
                if (one_in_(3) && (randint1(floor_ptr->dun_level) > 5))
@@ -758,7 +764,7 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                                    ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
                                     !dun->laketype)
                                {
-                                       add_river(feat1, feat2);
+                                       add_river(floor_ptr, feat1, feat2);
                                }
                        }
                }
@@ -797,12 +803,12 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                        if (randint1(floor_ptr->dun_level) > dungeon_ptr->tunnel_percent)
                        {
                                /* make cavelike tunnel */
-                               (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
+                               (void)build_tunnel2(floor_ptr, dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
                        }
                        else
                        {
                                /* make normal tunnel */
-                               if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
+                               if (!build_tunnel(floor_ptr, dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
                        }
 
                        if (tunnel_fail_count >= 2) return FALSE;
@@ -845,7 +851,7 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                                if ((randint0(100) < dun_tun_pen) && !(dungeon_ptr->flags1 & DF1_NO_DOORS))
                                {
                                        /* Place a random door */
-                                       place_random_door(y, x, TRUE);
+                                       place_random_door(floor_ptr, y, x, TRUE);
                                }
                        }
 
@@ -862,17 +868,17 @@ static bool cave_gen(dungeon_type* dungeon_ptr, 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(floor_ptr, y, x - 1);
+                       try_door(floor_ptr, y, x + 1);
+                       try_door(floor_ptr, y - 1, x);
+                       try_door(floor_ptr, y + 1, x);
                }
 
                /* Place 3 or 4 down stairs near some walls */
-               if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
+               if (!alloc_stairs(floor_ptr, feat_down_stair, rand_range(3, 4), 3)) return FALSE;
 
                /* Place 1 or 2 up stairs near some walls */
-               if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
+               if (!alloc_stairs(floor_ptr, feat_up_stair, rand_range(1, 2), 3)) return FALSE;
        }
 
        if (!dun->laketype)
@@ -882,7 +888,7 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                        /* Hack -- Add some quartz streamers */
                        for (i = 0; i < DUN_STR_QUA; i++)
                        {
-                               build_streamer(dungeon_ptr->stream2, DUN_STR_QC);
+                               build_streamer(floor_ptr, dungeon_ptr->stream2, DUN_STR_QC);
                        }
                }
 
@@ -891,7 +897,7 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                        /* Hack -- Add some magma streamers */
                        for (i = 0; i < DUN_STR_MAG; i++)
                        {
-                               build_streamer(dungeon_ptr->stream1, DUN_STR_MC);
+                               build_streamer(floor_ptr, dungeon_ptr->stream1, DUN_STR_MC);
                        }
                }
        }
@@ -911,9 +917,9 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
        }
 
        /* Determine the character location */
-       if (!new_player_spot()) return FALSE;
+       if (!new_player_spot(p_ptr)) return FALSE;
 
-       if (!place_quest_monsters()) return FALSE;
+       if (!place_quest_monsters(floor_ptr, p_ptr)) return FALSE;
 
        /* Basic "amount" */
        k = (floor_ptr->dun_level / 3);
@@ -972,15 +978,17 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
        /* Put the Guardian */
        if (!alloc_guardian(TRUE)) 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);
+       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);
                }
        }
 
@@ -991,10 +999,10 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
  * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
  * @return なし
  */
-static void build_arena(floor_type *floor_ptr)
+static void build_arena(floor_type *floor_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;
@@ -1006,49 +1014,48 @@ static void build_arena(floor_type *floor_ptr)
        for (i = y_height; i <= y_height + 5; i++)
                for (j = x_left; j <= x_right; j++)
                {
-                       place_extra_perm_bold(i, j);
+                       place_extra_perm_bold(floor_ptr, i, j);
                        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(i, j);
+                       place_extra_perm_bold(floor_ptr, i, j);
                        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(i, j);
+                       place_extra_perm_bold(floor_ptr, i, j);
                        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(i, j);
+                       place_extra_perm_bold(floor_ptr, i, j);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
-       place_extra_perm_bold(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(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(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(y_depth-6, x_right-18);
-       floor_ptr->grid_array[y_depth-6][x_right-18].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);
 
-       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)
+static void generate_challenge_arena(floor_type *floor_ptr, player_type *challanger_ptr)
 {
        POSITION y, x;
        POSITION qy = 0;
@@ -1064,7 +1071,7 @@ static void generate_challenge_arena(floor_type *floor_ptr)
                for (x = 0; x < MAX_WID; x++)
                {
                        /* Create "solid" perma-wall */
-                       place_solid_perm_bold(y, x);
+                       place_solid_perm_bold(floor_ptr, y, x);
 
                        /* Illuminate and memorize the walls */
                        floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
@@ -1081,12 +1088,13 @@ static void generate_challenge_arena(floor_type *floor_ptr)
                }
        }
 
-       build_arena(floor_ptr);
+       build_arena(floor_ptr, &y, &x);
+       player_place(challanger_ptr, y, x);
 
-       if(!place_monster_aux(0, p_ptr->y + 5, p_ptr->x, arena_info[p_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET)))
+       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)))
        {
-               p_ptr->exit_bldg = TRUE;
-               p_ptr->arena_number++;
+               challanger_ptr->exit_bldg = TRUE;
+               challanger_ptr->arena_number++;
                msg_print(_("相手は欠場した。あなたの不戦勝だ。", "The enemy is unable appear. You won by default."));
        }
 
@@ -1096,7 +1104,7 @@ static void generate_challenge_arena(floor_type *floor_ptr)
  * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
  * @return なし
  */
-static void build_battle(floor_type *floor_ptr)
+static void build_battle(floor_type *floor_ptr, POSITION *y, POSITION *x)
 {
        POSITION yval, y_height, y_depth, xval, x_left, x_right;
        register int i, j;
@@ -1111,35 +1119,35 @@ static void build_battle(floor_type *floor_ptr)
        for (i = y_height; i <= y_height + 5; i++)
                for (j = x_left; j <= x_right; j++)
                {
-                       place_extra_perm_bold(i, j);
+                       place_extra_perm_bold(floor_ptr, i, j);
                        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(i, j);
+                       place_extra_perm_bold(floor_ptr, i, j);
                        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(i, j);
+                       place_extra_perm_bold(floor_ptr, i, j);
                        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(i, j);
+                       place_extra_perm_bold(floor_ptr, i, j);
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
-       place_extra_perm_bold(y_height+6, x_left+18);
+       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(y_depth-4, x_left+18);
+       place_extra_perm_bold(floor_ptr, y_depth-4, x_left+18);
        floor_ptr->grid_array[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(y_height+6, x_right-18);
+       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(y_depth-4, x_right-18);
+       place_extra_perm_bold(floor_ptr, y_depth-4, x_right-18);
        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++)
@@ -1152,14 +1160,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)
+static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature_ptr)
 {
        POSITION y, x;
        MONSTER_IDX i;
@@ -1172,7 +1182,7 @@ static void generate_gambling_arena(floor_type *floor_ptr)
                for (x = 0; x < MAX_WID; x++)
                {
                        /* Create "solid" perma-wall */
-                       place_solid_perm_bold(y, x);
+                       place_solid_perm_bold(floor_ptr, y, x);
 
                        /* Illuminate and memorize the walls */
                        floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
@@ -1189,12 +1199,14 @@ static void generate_gambling_arena(floor_type *floor_ptr)
                }
        }
 
-       build_battle(floor_ptr);
+       build_battle(floor_ptr, &y, &x);
+
+       player_place(creature_ptr, y, x);
 
        for(i = 0; i < 4; i++)
        {
-               place_monster_aux(0, p_ptr->y + 8 + (i/2)*4, p_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[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
+               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));
+               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++)
        {
@@ -1203,73 +1215,83 @@ static void generate_gambling_arena(floor_type *floor_ptr)
                if (!monster_is_valid(m_ptr)) continue;
 
                m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
-               update_monster(i, FALSE);
+               update_monster(p_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_solid_perm_bold(floor_ptr, y, x);
                }
        }
 
        /* Set the quest level */
-       floor_ptr->base_level = quest[p_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->inside_quest, NULL);
+       if (record_stair) exe_write_diary(p_ptr, NIKKI_TO_QUEST, floor_ptr->inside_quest, NULL);
        get_mon_num_prep(get_monster_hook(), 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 ||
            (one_in_(SMALL_LEVEL) && small_levels) ||
-            (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER) ||
-           (d_info[p_ptr->dungeon_idx].flags1 & DF1_SMALLEST)) &&
-           !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BIG))
+            (d_info[d_idx].flags1 & DF1_BEGINNER) ||
+           (d_info[d_idx].flags1 & DF1_SMALLEST)) &&
+           !(d_info[d_idx].flags1 & DF1_BIG))
        {
-               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_SMALLEST)
+               int level_height, level_width;
+               if (d_info[d_idx].flags1 & DF1_SMALLEST)
                {
                        level_height = 1;
                        level_width = 1;
                }
-               else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
+               else if (d_info[d_idx].flags1 & DF1_BEGINNER)
                {
                        level_height = 2;
                        level_width = 2;
                }
                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_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;
@@ -1294,17 +1316,18 @@ static bool level_gen(floor_type *floor_ptr, concptr *why)
                panel_col_min = floor_ptr->width;
        }
 
-       /* Make a dungeon */
-       if (!cave_gen(&d_info[p_ptr->dungeon_idx], floor_ptr))
+       floor_ptr->dungeon_idx = d_idx;
+       if (!cave_gen(player_ptr))
        {
                *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)
@@ -1334,15 +1357,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;
@@ -1356,7 +1381,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 */
@@ -1377,9 +1402,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;
 
@@ -1393,15 +1415,17 @@ 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_random_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 */
-       set_floor_and_wall(p_ptr->dungeon_idx);
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       set_floor_and_wall(floor_ptr->dungeon_idx);
 
        /* Generate */
        for (num = 0; TRUE; num++)
@@ -1409,35 +1433,38 @@ void generate_random_floor(floor_type *floor_ptr)
                bool okay = TRUE;
                concptr why = NULL;
 
-               clear_cave(floor_ptr);
+               clear_cave(player_ptr);
+
+               /* Mega-Hack -- no player yet */
+               player_ptr->x = player_ptr->y = 0;
 
-               if (p_ptr->inside_arena)
+               if (floor_ptr->inside_arena)
                {
-                       generate_challenge_arena(floor_ptr);
+                       generate_challenge_arena(floor_ptr, player_ptr);
                }
 
-               else if (p_ptr->phase_out)
+               else if (player_ptr->phase_out)
                {
-                       generate_gambling_arena(floor_ptr);
+                       generate_gambling_arena(floor_ptr, player_ptr);
                }
 
-               else if (p_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();
-                       else wilderness_gen();
+                       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);
                }
 
 
@@ -1459,7 +1486,7 @@ void generate_random_floor(floor_type *floor_ptr)
 
                if (why) msg_format(_("生成やり直し(%s)", "Generation restarted (%s)"), why);
 
-               wipe_o_list();
+               wipe_o_list(floor_ptr);
                wipe_m_list();
        }
 
@@ -1467,7 +1494,7 @@ void generate_random_floor(floor_type *floor_ptr)
        glow_deep_lava_and_bldg(floor_ptr);
 
        /* Reset flag */
-       p_ptr->enter_dungeon = FALSE;
+       player_ptr->enter_dungeon = FALSE;
 
        wipe_generate_random_floor_flags(floor_ptr);
 }
@@ -1549,7 +1576,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(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
+bool build_tunnel(floor_type *floor_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2)
 {
        POSITION y, x;
        POSITION tmp_row, tmp_col;
@@ -1593,7 +1620,7 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
 
 
                /* Extremely Important -- do not leave the dungeon */
-               while (!in_bounds(p_ptr->current_floor_ptr, tmp_row, tmp_col))
+               while (!in_bounds(floor_ptr, tmp_row, tmp_col))
                {
                        /* Acquire the correct direction */
                        correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
@@ -1609,7 +1636,7 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
                        tmp_col = col1 + col_dir;
                }
 
-               g_ptr = &p_ptr->current_floor_ptr->grid_array[tmp_row][tmp_col];
+               g_ptr = &floor_ptr->grid_array[tmp_row][tmp_col];
 
                /* Avoid "solid" walls */
                if (is_solid_grid(g_ptr)) continue;
@@ -1622,8 +1649,8 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
                        x = tmp_col + col_dir;
 
                        /* Hack -- Avoid outer/solid walls */
-                       if (is_outer_bold(y, x)) continue;
-                       if (is_solid_bold(y, x)) continue;
+                       if (is_outer_bold(floor_ptr, y, x)) continue;
+                       if (is_solid_bold(floor_ptr, y, x)) continue;
 
                        /* Accept this location */
                        row1 = tmp_row;
@@ -1644,10 +1671,10 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
                                for (x = col1 - 1; x <= col1 + 1; x++)
                                {
                                        /* Convert adjacent "outer" walls as "solid" walls */
-                                       if (is_outer_bold(y, x))
+                                       if (is_outer_bold(floor_ptr, y, x))
                                        {
                                                /* Change the wall to a "solid" wall */
-                                               place_solid_noperm_bold(y, x);
+                                               place_solid_noperm_bold(floor_ptr, y, x);
                                        }
                                }
                        }
@@ -1743,20 +1770,20 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
 * routine.\n
 * @todo 特に詳細な処理の意味を調査すべし
 */
-static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
+static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool affectwall)
 {
        int i, j, dx, dy;
 
-       grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[*y][*x];
+       grid_type *g_ptr = &floor_ptr->grid_array[*y][*x];
 
-       if (!in_bounds(p_ptr->current_floor_ptr, *y, *x)) return TRUE;
+       if (!in_bounds(floor_ptr, *y, *x)) return TRUE;
 
        if (is_inner_grid(g_ptr))
        {
                return TRUE;
        }
 
-       if (is_extra_bold(*y, *x))
+       if (is_extra_bold(floor_ptr, *y, *x))
        {
                /* Save the tunnel location */
                if (dun->tunn_n < TUNN_MAX)
@@ -1770,7 +1797,7 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
                else return FALSE;
        }
 
-       if (is_floor_bold(*y, *x))
+       if (is_floor_bold(floor_ptr, *y, *x))
        {
                /* Don't do anything */
                return TRUE;
@@ -1793,18 +1820,18 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
                        for (i = *x - 1; i <= *x + 1; i++)
                        {
                                /* Convert adjacent "outer" walls as "solid" walls */
-                               if (is_outer_bold(j, i))
+                               if (is_outer_bold(floor_ptr, j, i))
                                {
                                        /* Change the wall to a "solid" wall */
-                                       place_solid_noperm_bold(j, i);
+                                       place_solid_noperm_bold(floor_ptr, j, i);
                                }
                        }
                }
 
                /* Clear mimic type */
-               p_ptr->current_floor_ptr->grid_array[*y][*x].mimic = 0;
+               floor_ptr->grid_array[*y][*x].mimic = 0;
 
-               place_floor_bold(*y, *x);
+               place_floor_bold(floor_ptr, *y, *x);
 
                return TRUE;
        }
@@ -1819,12 +1846,12 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
 
                dy = 0;
                dx = 0;
-               while ((i > 0) && is_solid_bold(*y + dy, *x + dx))
+               while ((i > 0) && is_solid_bold(floor_ptr, *y + dy, *x + dx))
                {
                        dy = randint0(3) - 1;
                        dx = randint0(3) - 1;
 
-                       if (!in_bounds(p_ptr->current_floor_ptr, *y + dy, *x + dx))
+                       if (!in_bounds(floor_ptr, *y + dy, *x + dx))
                        {
                                dx = 0;
                                dy = 0;
@@ -1861,26 +1888,26 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
 * Note that this routine is only called on "even" squares - so it gives
 * a natural checkerboard pattern.
 */
-static void create_cata_tunnel(POSITION x, POSITION y)
+static void create_cata_tunnel(floor_type *floor_ptr, POSITION x, POSITION y)
 {
        POSITION x1, y1;
 
        /* Build tunnel */
        x1 = x - 1;
        y1 = y;
-       set_tunnel(&x1, &y1, FALSE);
+       set_tunnel(floor_ptr, &x1, &y1, FALSE);
 
        x1 = x + 1;
        y1 = y;
-       set_tunnel(&x1, &y1, FALSE);
+       set_tunnel(floor_ptr, &x1, &y1, FALSE);
 
        x1 = x;
        y1 = y - 1;
-       set_tunnel(&x1, &y1, FALSE);
+       set_tunnel(floor_ptr, &x1, &y1, FALSE);
 
        x1 = x;
        y1 = y + 1;
-       set_tunnel(&x1, &y1, FALSE);
+       set_tunnel(floor_ptr, &x1, &y1, FALSE);
 }
 
 
@@ -1906,7 +1933,7 @@ static void create_cata_tunnel(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(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
+static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
 {
        int i;
        POSITION x, y;
@@ -1926,7 +1953,7 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                {
                        x = x1 + i * (x2 - x1) / length;
                        y = y1 + i * (y2 - y1) / length;
-                       if (!set_tunnel(&x, &y, TRUE))
+                       if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                        {
                                if (count > 50)
                                {
@@ -1936,8 +1963,8 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                                }
 
                                /* solid wall - so try to go around */
-                               short_seg_hack(x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
-                               short_seg_hack(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(floor_ptr, x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
                        }
                }
        }
@@ -1949,15 +1976,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                        {
                                x = i;
                                y = y1;
-                               if (!set_tunnel(&x, &y, TRUE))
+                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(x, y, i - 1, y1, 1, count, fail);
-                                       short_seg_hack(x, y, i + 1, y1, 1, count, fail);
+                                       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);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(i, y1);
+                                       create_cata_tunnel(floor_ptr, i, y1);
                                }
                        }
                }
@@ -1967,15 +1994,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                        {
                                x = i;
                                y = y1;
-                               if (!set_tunnel(&x, &y, TRUE))
+                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(x, y, i - 1, y1, 1, count, fail);
-                                       short_seg_hack(x, y, i + 1, y1, 1, count, fail);
+                                       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);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(i, y1);
+                                       create_cata_tunnel(floor_ptr, i, y1);
                                }
                        }
 
@@ -1986,15 +2013,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                        {
                                x = x2;
                                y = i;
-                               if (!set_tunnel(&x, &y, TRUE))
+                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(x, y, x2, i - 1, 1, count, fail);
-                                       short_seg_hack(x, y, x2, i + 1, 1, count, fail);
+                                       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);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(x2, i);
+                                       create_cata_tunnel(floor_ptr, x2, i);
                                }
                        }
                }
@@ -2004,15 +2031,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                        {
                                x = x2;
                                y = i;
-                               if (!set_tunnel(&x, &y, TRUE))
+                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(x, y, x2, i - 1, 1, count, fail);
-                                       short_seg_hack(x, y, x2, i + 1, 1, count, fail);
+                                       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);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(x2, i);
+                                       create_cata_tunnel(floor_ptr, x2, i);
                                }
                        }
                }
@@ -2034,7 +2061,7 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
 * 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(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
+bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
 {
        POSITION x3, y3, dx, dy;
        POSITION changex, changey;
@@ -2062,13 +2089,13 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
                y3 = y1 + dy + changey;
 
                /* See if in bounds - if not - do not perturb point */
-               if (!in_bounds(p_ptr->current_floor_ptr, y3, x3))
+               if (!in_bounds(floor_ptr, y3, x3))
                {
                        x3 = (x1 + x2) / 2;
                        y3 = (y1 + y2) / 2;
                }
                /* cache g_ptr */
-               g_ptr = &p_ptr->current_floor_ptr->grid_array[y3][x3];
+               g_ptr = &floor_ptr->grid_array[y3][x3];
                if (is_solid_grid(g_ptr))
                {
                        /* move midpoint a bit to avoid problem. */
@@ -2077,11 +2104,11 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
 
                        dy = 0;
                        dx = 0;
-                       while ((i > 0) && is_solid_bold(y3 + dy, x3 + dx))
+                       while ((i > 0) && is_solid_bold(floor_ptr, y3 + dy, x3 + dx))
                        {
                                dy = randint0(3) - 1;
                                dx = randint0(3) - 1;
-                               if (!in_bounds(p_ptr->current_floor_ptr, y3 + dy, x3 + dx))
+                               if (!in_bounds(floor_ptr, y3 + dy, x3 + dx))
                                {
                                        dx = 0;
                                        dy = 0;
@@ -2092,23 +2119,23 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
                        if (i == 0)
                        {
                                /* Failed for some reason: hack - ignore the solidness */
-                               place_outer_bold(y3, x3);
+                               place_outer_bold(floor_ptr, y3, x3);
                                dx = 0;
                                dy = 0;
                        }
                        y3 += dy;
                        x3 += dx;
-                       g_ptr = &p_ptr->current_floor_ptr->grid_array[y3][x3];
+                       g_ptr = &floor_ptr->grid_array[y3][x3];
                }
 
                if (is_floor_grid(g_ptr))
                {
-                       if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
+                       if (build_tunnel2(floor_ptr, x1, y1, x3, y3, type, cutoff))
                        {
-                               if ((p_ptr->current_floor_ptr->grid_array[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
+                               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(x3, y3, x2, y2, type, cutoff);
+                                       retval = build_tunnel2(floor_ptr, x3, y3, x2, y2, type, cutoff);
                                }
                                else
                                {
@@ -2136,9 +2163,9 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
                else
                {
                        /* tunnel through walls */
-                       if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
+                       if (build_tunnel2(floor_ptr, x1, y1, x3, y3, type, cutoff))
                        {
-                               retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
+                               retval = build_tunnel2(floor_ptr, x3, y3, x2, y2, type, cutoff);
                                firstsuccede = TRUE;
                        }
                        else
@@ -2151,7 +2178,7 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
                if (firstsuccede)
                {
                        /* only do this if the first half has worked */
-                       set_tunnel(&x3, &y3, TRUE);
+                       set_tunnel(floor_ptr, &x3, &y3, TRUE);
                }
                /* return value calculated above */
                return retval;
@@ -2160,7 +2187,7 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
        {
                /* Do a short segment */
                retval = TRUE;
-               short_seg_hack(x1, y1, x2, y2, type, 0, &retval);
+               short_seg_hack(floor_ptr, x1, y1, x2, y2, type, 0, &retval);
 
                /* Hack - ignore return value so avoid infinite loops */
                return TRUE;