OSDN Git Service

[Refactor] #38997 build_maze_vault() に floor_type * 引数を追加. / Add floor_type * argumen...
[hengband/hengband.git] / src / rooms.c
index 37b7330..a9a4ace 100644 (file)
  */
 
 #include "angband.h"
-#include "generate.h"
+#include "util.h"
+
+#include "feature.h"
+#include "floor.h"
+#include "floor-generate.h"
+#include "dungeon.h"
 #include "grid.h"
 #include "rooms.h"
 
@@ -51,6 +56,8 @@
 
 #include "trap.h"
 
+#include "monster.h"
+
 
 /*!
  * 各部屋タイプの生成比定義
  * appear above their minimum depth.  Tiny levels will not have space\n
  * for all the rooms you ask for.\n
  */
+
+#if 1
+
 static room_info_type room_info_normal[ROOM_T_MAX] =
 {
        /* Depth */
        /*  0  10  20  30  40  50  60  70  80  90 100  min limit */
-
        {{999,900,800,700,600,500,400,300,200,100,  0},  0}, /*NORMAL   */
        {{  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100},  1}, /*OVERLAP  */
        {{  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100},  3}, /*CROSS    */
@@ -89,9 +98,37 @@ static room_info_type room_info_normal[ROOM_T_MAX] =
        {{  0,  0,  1,  1,  1,  2,  3,  4,  5,  6,  8}, 20}, /*TRAP     */
        {{  0,  0,  0,  0,  1,  1,  1,  2,  2,  2,  2}, 40}, /*GLASS    */
        {{  1,  1,  1,  1,  1,  1,  1,  2,  2,  3,  3},  1}, /*ARCADE   */
-       {{ 20, 40, 60, 80,100,100,100,100,100,100,100},  1}, /*FIX   */
+       {{  1,  8, 16, 24, 32, 40, 48, 56, 64, 72, 80},  1}, /*FIX      */
+};
+
+#endif
+
+#if 0
+static room_info_type room_info_normal[ROOM_T_MAX] =
+{
+/*デバッグ用配列*/
+{ {999, 900, 800, 700, 600, 500, 400, 300, 200, 100, 0}, 0}, /*NORMAL   */
+{ {  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,  0},  1 }, /*OVERLAP  */
+{ {  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,  0},  3 }, /*CROSS    */
+{ {  1, 10, 20, 30, 40, 50, 60, 70, 80, 90,  0},  3 }, /*INNER_F  */
+{ {  0,  1,  1,  1,  2,  3,  5,  6,  8, 10,  0}, 10 }, /*NEST     */
+{ {  0,  1,  1,  2,  3,  4,  6,  8, 10, 13,  0}, 10 }, /*PIT      */
+{ {  0,  1,  1,  1,  2,  2,  3,  5,  6,  8,  0}, 10 }, /*LESSER_V */
+{ {  0,  0,  1,  1,  1,  2,  2,  2,  3,  3,  0}, 20 }, /*GREATER_V*/
+{ {  0,100,200,300,400,500,600,700,800,900,  0}, 10 }, /*FRACAVE  */
+{ {  0,  1,  1,  1,  1,  1,  1,  1,  1,  2,  0}, 10 }, /*RANDOM_V */
+{ {  0,  4,  8, 12, 16, 20, 24, 28, 32, 36,  0},  3 }, /*OVAL     */
+{ {  1,  6, 12, 18, 24, 30, 36, 42, 48, 54,  0}, 10 }, /*CRYPT    */
+{ {  0,  0,  1,  1,  1,  2,  3,  4,  5,  6,  0}, 20 }, /*TRAP_PIT */
+{ {  0,  0,  1,  1,  1,  2,  3,  4,  5,  6,  0}, 20 }, /*TRAP     */
+{ {  0,  0,  0,  0,  1,  1,  1,  2,  2,  2,  0}, 40 }, /*GLASS    */
+{ {  1,  1,  1,  1,  1,  1,  1,  2,  2,  3,  0},  1 }, /*ARCADE   */
+{ { 20, 40, 60, 80,100,100,100,100,100,100,100},  1 }, /*FIX      */
 };
 
+#endif
+
+
 
 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
 static byte room_build_order[ROOM_T_MAX] = {
@@ -105,17 +142,18 @@ static byte room_build_order[ROOM_T_MAX] = {
        ROOM_T_TRAP,
        ROOM_T_GLASS,
        ROOM_T_INNER_FEAT,
+       ROOM_T_FIXED,
        ROOM_T_OVAL,
        ROOM_T_CRYPT,
        ROOM_T_OVERLAP,
        ROOM_T_CROSS,
        ROOM_T_FRACAVE,
-       ROOM_T_FIXED,
        ROOM_T_NORMAL,
 };
 
 /*!
  * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
+ * @param floor_ptr 配置するフロアの参照ポインタ
  * @param y0 配置したい中心のY座標
  * @param x0 配置したい中心のX座標
  * @details
@@ -125,42 +163,42 @@ static byte room_build_order[ROOM_T_MAX] = {
  * Note - this should be used only on allocated regions
  * within another room.
  */
-void build_small_room(POSITION x0, POSITION y0)
+void build_small_room(floor_type *floor_ptr, POSITION x0, POSITION y0)
 {
        POSITION x, y;
 
        for (y = y0 - 1; y <= y0 + 1; y++)
        {
-               place_inner_bold(y, x0 - 1);
-               place_inner_bold(y, x0 + 1);
+               place_inner_bold(floor_ptr, y, x0 - 1);
+               place_inner_bold(floor_ptr, y, x0 + 1);
        }
 
        for (x = x0 - 1; x <= x0 + 1; x++)
        {
-               place_inner_bold(y0 - 1, x);
-               place_inner_bold(y0 + 1, x);
+               place_inner_bold(floor_ptr, y0 - 1, x);
+               place_inner_bold(floor_ptr, y0 + 1, x);
        }
 
        /* Place a secret door on one side */
        switch (randint0(4))
        {
-               case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
-               case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
-               case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
-               case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
+               case 0: place_secret_door(floor_ptr, y0, x0 - 1, DOOR_DEFAULT); break;
+               case 1: place_secret_door(floor_ptr, y0, x0 + 1, DOOR_DEFAULT); break;
+               case 2: place_secret_door(floor_ptr, y0 - 1, x0, DOOR_DEFAULT); break;
+               case 3: place_secret_door(floor_ptr, y0 + 1, x0, DOOR_DEFAULT); break;
        }
 
        /* Clear mimic type */
-       cave[y0][x0].mimic = 0;
+       floor_ptr->grid_array[y0][x0].mimic = 0;
 
        /* Add inner open space */
-       place_floor_bold(y0, x0);
+       place_floor_bold(floor_ptr, y0, x0);
 }
 
 /*!
  * @brief
  * 指定範囲に通路が通っていることを確認した上で床で埋める
- * This function tunnels around a room if it will cut off part of a cave system.
+ * This function tunnels around a room if it will cut off part of a p_ptr->current_floor_ptr->grid_array system.
  * @param x1 範囲の左端
  * @param y1 範囲の上端
  * @param x2 範囲の右端
@@ -172,9 +210,6 @@ static void check_room_boundary(POSITION x1, POSITION y1, POSITION x2, POSITION
        int count;
        POSITION x, y;
        bool old_is_floor, new_is_floor;
-
-
-       /* Initialize */
        count = 0;
 
        old_is_floor = get_is_floor(x1 - 1, y1);
@@ -254,9 +289,9 @@ static void check_room_boundary(POSITION x1, POSITION y1, POSITION x2, POSITION
  * @param block_x 範囲の左端
  * @return なし
  */
-static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
+static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
 {
-       int by1, bx1, by2, bx2, by, bx;
+       POSITION by1, bx1, by2, bx2, by, bx;
 
        /* Itty-bitty rooms must shift about within their rectangle */
        if (blocks_wide < 3)
@@ -299,8 +334,8 @@ static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int bl
        }
 
        /* Extract blocks */
-       by1 = block_y + 0;
-       bx1 = block_x + 0;
+       by1 = block_y;
+       bx1 = block_x;
        by2 = block_y + blocks_high;
        bx2 = block_x + blocks_wide;
 
@@ -348,13 +383,12 @@ static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int bl
 bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
 {
        int candidates, pick;
-       int by, bx, by1, bx1, by2, bx2;
-       int block_y = 0, block_x = 0;
-
+       POSITION by, bx, by1, bx1, by2, bx2;
+       POSITION block_y = 0, block_x = 0;
 
        /* Find out how many blocks we need. */
-       int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
-       int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
+       POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
+       POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
 
        /* There are no way to allocate such huge space */
        if (dun->row_rooms < blocks_high) return FALSE;
@@ -383,7 +417,7 @@ bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
        }
 
        /* Normal dungeon */
-       if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
+       if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE))
        {
                /* Choose a random one */
                pick = randint1(candidates);
@@ -414,8 +448,8 @@ bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
        }
 
        /* Extract blocks */
-       by1 = block_y + 0;
-       bx1 = block_x + 0;
+       by1 = block_y;
+       bx1 = block_x;
        by2 = block_y + blocks_high;
        bx2 = block_x + blocks_wide;
 
@@ -445,7 +479,6 @@ bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
                }
        }
 
-
        /*
         * Hack- See if room will cut off a cavern.
         *
@@ -454,14 +487,11 @@ bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
         */
        check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
 
-
        /* Success. */
        return TRUE;
 }
 
 
-
-
 /*
  * Structure to hold all "fill" data
  */
@@ -471,10 +501,10 @@ typedef struct fill_data_type fill_data_type;
 struct fill_data_type
 {
        /* area size */
-       int xmin;
-       int ymin;
-       int xmax;
-       int ymax;
+       POSITION xmin;
+       POSITION ymin;
+       POSITION xmax;
+       POSITION ymax;
 
        /* cutoffs */
        int c1;
@@ -482,9 +512,9 @@ struct fill_data_type
        int c3;
 
        /* features to fill with */
-       int feat1;
-       int feat2;
-       int feat3;
+       FEAT_IDX feat1;
+       FEAT_IDX feat2;
+       FEAT_IDX feat3;
 
        int info1;
        int info2;
@@ -497,17 +527,17 @@ struct fill_data_type
 static fill_data_type fill_data;
 
 
-/* Store routine for the fractal cave generator */
+/* Store routine for the fractal floor generator */
 /* this routine probably should be an inline function or a macro. */
-static void store_height(int x, int y, int val)
+static void store_height(floor_type *floor_ptr, POSITION x, POSITION y, FEAT_IDX val)
 {
        /* if on boundary set val > cutoff so walls are not as square */
        if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
-            (x == fill_data.xmax) || (y == fill_data.ymax)) &&
-           (val <= fill_data.c1)) val = fill_data.c1 + 1;
+               (x == fill_data.xmax) || (y == fill_data.ymax)) &&
+               (val <= fill_data.c1)) val = fill_data.c1 + 1;
 
        /* store the value in height-map format */
-       cave[y][x].feat = (s16b)val;
+       floor_ptr->grid_array[y][x].feat = val;
 
        return;
 }
@@ -540,7 +570,7 @@ static void store_height(int x, int y, int val)
 *
 * How fractal caves are made:
 *
-* When the map is complete, a cut-off value is used to create a cave.
+* When the map is complete, a cut-off value is used to create a p_ptr->current_floor_ptr->grid_array.
 * Heights below this value are "floor", and heights above are "wall".
 * This also can be used to create lakes, by adding more height levels
 * representing shallow and deep water/ lava etc.
@@ -548,7 +578,7 @@ static void store_height(int x, int y, int val)
 * The grd variable affects the width of passages.
 * The roug variable affects the roughness of those passages
 *
-* The tricky part is making sure the created cave is connected.  This
+* The tricky part is making sure the created p_ptr->current_floor_ptr->grid_array is connected.  This
 * is done by 'filling' from the inside and only keeping the 'filled'
 * floor.  Walls bounding the 'filled' floor are also kept.  Everything
 * else is converted to the normal _extra_.
@@ -556,7 +586,7 @@ static void store_height(int x, int y, int val)
 
 
 /*
- *  Note that this uses the cave.feat array in a very hackish way
+ *  Note that this uses the p_ptr->current_floor_ptr->grid_array.feat array in a very hackish way
  *  the values are first set to zero, and then each array location
  *  is used as a "heightmap"
  *  The heightmap then needs to be converted back into the "feat" format.
@@ -564,9 +594,9 @@ static void store_height(int x, int y, int val)
  *  grd=level at which fractal turns on.  smaller gives more mazelike caves
  *  roug=roughness level.  16=normal.  higher values make things more convoluted
  *    small values are good for smooth walls.
- *  size=length of the side of the square cave system.
+ *  size=length of the side of the square p_ptr->current_floor_ptr->grid_array system.
  */
-void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
+void generate_hmap(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
 {
        POSITION xhsize, yhsize, xsize, ysize, maxsize;
 
@@ -575,12 +605,12 @@ void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int g
         * this gives 8 binary places of fractional part + 8 places of normal part
         */
 
-       u16b xstep, xhstep, ystep, yhstep;
-       u16b xstep2, xhstep2, ystep2, yhstep2;
-       u16b i, j, ii, jj, diagsize, xxsize, yysize;
+       POSITION xstep, xhstep, ystep, yhstep;
+       POSITION xstep2, xhstep2, ystep2, yhstep2;
+       POSITION i, j, ii, jj, diagsize, xxsize, yysize;
        
        /* Cache for speed */
-       u16b xm, xp, ym, yp;
+       POSITION xm, xp, ym, yp;
 
        /* redefine size so can change the value if out of range */
        xsize = xsiz;
@@ -625,20 +655,20 @@ void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int g
                for (j = 0; j <= ysize; j++)
                {
                        /* -1 is a flag for "not done yet" */
-                       cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
-                       /* Clear icky flag because may be redoing the cave */
-                       cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
+                       floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
+                       /* Clear icky flag because may be redoing the floor_ptr->grid_array */
+                       floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
                }
        }
 
        /* Boundaries are walls */
-       cave[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
-       cave[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
-       cave[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
-       cave[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
+       floor_ptr->grid_array[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
+       floor_ptr->grid_array[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
+       floor_ptr->grid_array[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
+       floor_ptr->grid_array[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
 
        /* Set the middle square to be an open area. */
-       cave[y0][x0].feat = 0;
+       floor_ptr->grid_array[y0][x0].feat = 0;
 
        /* Initialize the step sizes */
        xstep = xhstep = xsize * 256;
@@ -675,19 +705,19 @@ void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int g
                                jj = j / 256 + fill_data.ymin;
 
                                /* Test square */
-                               if (cave[jj][ii].feat == -1)
+                               if (floor_ptr->grid_array[jj][ii].feat == -1)
                                {
                                        if (xhstep2 > grd)
                                        {
                                                /* If greater than 'grid' level then is random */
-                                               store_height(ii, jj, randint1(maxsize));
+                                               store_height(floor_ptr, ii, jj, randint1(maxsize));
                                        }
                                        else
                                        {
                                                /* Average of left and right points +random bit */
-                                               store_height(ii, jj,
-                                                       (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
-                                                        + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
+                                               store_height(floor_ptr, ii, jj,
+                                                       (floor_ptr->grid_array[jj][fill_data.xmin + (i - xhstep) / 256].feat
+                                                        + floor_ptr->grid_array[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
                                                         + (randint1(xstep2) - xhstep2) * roug / 16);
                                        }
                                }
@@ -705,19 +735,19 @@ void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int g
                                jj = j / 256 + fill_data.ymin;
 
                                /* Test square */
-                               if (cave[jj][ii].feat == -1)
+                               if (floor_ptr->grid_array[jj][ii].feat == -1)
                                {
                                        if (xhstep2 > grd)
                                        {
                                                /* If greater than 'grid' level then is random */
-                                               store_height(ii, jj, randint1(maxsize));
+                                               store_height(floor_ptr, ii, jj, randint1(maxsize));
                                        }
                                        else
                                        {
                                                /* Average of up and down points +random bit */
-                                               store_height(ii, jj,
-                                                       (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
-                                                       + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
+                                               store_height(floor_ptr, ii, jj,
+                                                       (floor_ptr->grid_array[fill_data.ymin + (j - yhstep) / 256][ii].feat
+                                                       + floor_ptr->grid_array[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
                                                        + (randint1(ystep2) - yhstep2) * roug / 16);
                                        }
                                }
@@ -734,12 +764,12 @@ void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int g
                                jj = j / 256 + fill_data.ymin;
 
                                /* Test square */
-                               if (cave[jj][ii].feat == -1)
+                               if (floor_ptr->grid_array[jj][ii].feat == -1)
                                {
                                        if (xhstep2 > grd)
                                        {
                                                /* If greater than 'grid' level then is random */
-                                               store_height(ii, jj, randint1(maxsize));
+                                               store_height(floor_ptr, ii, jj, randint1(maxsize));
                                        }
                                        else
                                        {
@@ -753,9 +783,9 @@ void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int g
                                                 * Average over all four corners + scale by diagsize to
                                                 * reduce the effect of the square grid on the shape of the fractal
                                                 */
-                                               store_height(ii, jj,
-                                                       (cave[ym][xm].feat + cave[yp][xm].feat
-                                                       + cave[ym][xp].feat + cave[yp][xp].feat) / 4
+                                               store_height(floor_ptr, ii, jj,
+                                                       (floor_ptr->grid_array[ym][xm].feat + floor_ptr->grid_array[yp][xm].feat
+                                                       + floor_ptr->grid_array[ym][xp].feat + floor_ptr->grid_array[yp][xp].feat) / 4
                                                        + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
                                        }
                                }
@@ -765,13 +795,13 @@ void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int g
 }
 
 
-static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int feat2, int feat3, int info1, int info2, int info3)
+static bool hack_isnt_wall(floor_type *floor_ptr, POSITION y, POSITION x, int c1, int c2, int c3, FEAT_IDX feat1, FEAT_IDX feat2, FEAT_IDX feat3, BIT_FLAGS info1, BIT_FLAGS info2, BIT_FLAGS info3)
 {
        /*
         * function used to convert from height-map back to the
-        *  normal angband cave format
+        *  normal angband floor_ptr->grid_array format
         */
-       if (cave[y][x].info & CAVE_ICKY)
+       if (floor_ptr->grid_array[y][x].info & CAVE_ICKY)
        {
                /* already done */
                return FALSE;
@@ -779,56 +809,56 @@ static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int
        else
        {
                /* Show that have looked at this square */
-               cave[y][x].info|= (CAVE_ICKY);
+               floor_ptr->grid_array[y][x].info|= (CAVE_ICKY);
 
                /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
-               if (cave[y][x].feat <= c1)
+               if (floor_ptr->grid_array[y][x].feat <= c1)
                {
                        /* 25% of the time use the other tile : it looks better this way */
                        if (randint1(100) < 75)
                        {
-                               cave[y][x].feat = (s16b)feat1;
-                               cave[y][x].info &= ~(CAVE_MASK);
-                               cave[y][x].info |= info1;
+                               floor_ptr->grid_array[y][x].feat = feat1;
+                               floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                               floor_ptr->grid_array[y][x].info |= info1;
                                return TRUE;
                        }
                        else
                        {
-                               cave[y][x].feat = (s16b)feat2;
-                               cave[y][x].info &= ~(CAVE_MASK);
-                               cave[y][x].info |= info2;
+                               floor_ptr->grid_array[y][x].feat = feat2;
+                               floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                               floor_ptr->grid_array[y][x].info |= info2;
                                return TRUE;
                        }
                }
-               else if (cave[y][x].feat <= c2)
+               else if (floor_ptr->grid_array[y][x].feat <= c2)
                {
                        /* 25% of the time use the other tile : it looks better this way */
                        if (randint1(100) < 75)
                        {
-                               cave[y][x].feat = (s16b)feat2;
-                               cave[y][x].info &= ~(CAVE_MASK);
-                               cave[y][x].info |= info2;
+                               floor_ptr->grid_array[y][x].feat = feat2;
+                               floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                               floor_ptr->grid_array[y][x].info |= info2;
                                return TRUE;
                        }
                        else
                        {
-                               cave[y][x].feat = (s16b)feat1;
-                               cave[y][x].info &= ~(CAVE_MASK);
-                               cave[y][x].info |= info1;
+                               floor_ptr->grid_array[y][x].feat = feat1;
+                               floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                               floor_ptr->grid_array[y][x].info |= info1;
                                return TRUE;
                        }
                }
-               else if (cave[y][x].feat <= c3)
+               else if (floor_ptr->grid_array[y][x].feat <= c3)
                {
-                       cave[y][x].feat = (s16b)feat3;
-                       cave[y][x].info &= ~(CAVE_MASK);
-                       cave[y][x].info |= info3;
+                       floor_ptr->grid_array[y][x].feat = feat3;
+                       floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                       floor_ptr->grid_array[y][x].info |= info3;
                        return TRUE;
                }
                /* if greater than cutoff then is a wall */
                else
                {
-                       place_outer_bold(y, x);
+                       place_outer_bold(floor_ptr, y, x);
                        return FALSE;
                }
        }
@@ -839,12 +869,12 @@ static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int
 
 /*
  * Quick and nasty fill routine used to find the connected region
- * of floor in the middle of the cave
+ * of floor in the middle of the grids
  */
-static void cave_fill(POSITION y, POSITION x)
+static void cave_fill(floor_type *floor_ptr, POSITION y, POSITION x)
 {
        int i, j, d;
-       int ty, tx;
+       POSITION ty, tx;
 
        int flow_tail = 1;
        int flow_head = 0;
@@ -853,16 +883,15 @@ static void cave_fill(POSITION y, POSITION x)
        /*** Start Grid ***/
 
        /* Enqueue that entry */
-       temp_y[0] = y;
-       temp_x[0] = x;
-
+       tmp_pos.y[0] = y;
+       tmp_pos.x[0] = x;
 
        /* Now process the queue */
        while (flow_head != flow_tail)
        {
                /* Extract the next entry */
-               ty = temp_y[flow_head];
-               tx = temp_x[flow_head];
+               ty = tmp_pos.y[flow_head];
+               tx = tmp_pos.x[flow_head];
 
                /* Forget that entry */
                if (++flow_head == TEMP_MAX) flow_head = 0;
@@ -876,11 +905,11 @@ static void cave_fill(POSITION y, POSITION x)
                        j = ty + ddy_ddd[d];
                        i = tx + ddx_ddd[d];
 
-                       /* Paranoia Don't leave the cave */
-                       if (!in_bounds(j, i))
+                       /* Paranoia Don't leave the floor_ptr->grid_array */
+                       if (!in_bounds(floor_ptr, j, i))
                        {
                                /* affect boundary */
-                               cave[j][i].info |= CAVE_ICKY;
+                               floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
 /*                             return; */
                        }
 
@@ -889,14 +918,14 @@ static void cave_fill(POSITION y, POSITION x)
                                && (j > fill_data.ymin) && (j < fill_data.ymax))
                        {
                                /* If not a wall or floor done before */
-                               if (hack_isnt_wall(j, i,
+                               if (hack_isnt_wall(floor_ptr, j, i,
                                        fill_data.c1, fill_data.c2, fill_data.c3,
                                        fill_data.feat1, fill_data.feat2, fill_data.feat3,
                                        fill_data.info1, fill_data.info2, fill_data.info3))
                                {
                                        /* Enqueue that entry */
-                                       temp_y[flow_tail] = (byte_hack)j;
-                                       temp_x[flow_tail] = (byte_hack)i;
+                                       tmp_pos.y[flow_tail] = (byte_hack)j;
+                                       tmp_pos.x[flow_tail] = (byte_hack)i;
 
                                        /* Advance the queue */
                                        if (++flow_tail == TEMP_MAX) flow_tail = 0;
@@ -908,7 +937,7 @@ static void cave_fill(POSITION y, POSITION x)
                                        }
                                        else
                                        {
-                                               /* keep tally of size of cave system */
+                                               /* keep tally of size of floor_ptr->grid_array system */
                                                (fill_data.amount)++;
                                        }
                                }
@@ -916,14 +945,14 @@ static void cave_fill(POSITION y, POSITION x)
                        else
                        {
                                /* affect boundary */
-                               cave[j][i].info |= CAVE_ICKY;
+                               floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
                        }
                }
        }
 }
 
 
-bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
+bool generate_fracave(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
 {
        POSITION x, y, xhsize, yhsize;
        int i;
@@ -934,7 +963,7 @@ bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize,
 
 
        /*
-        * select region connected to center of cave system
+        * select region connected to center of floor_ptr->grid_array system
         * this gets rid of alot of isolated one-sqaures that
         * can make teleport traps instadeaths...
         */
@@ -945,9 +974,9 @@ bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize,
        fill_data.c3 = 0;
 
        /* features to fill with */
-       fill_data.feat1 = floor_type[randint0(100)];
-       fill_data.feat2 = floor_type[randint0(100)];
-       fill_data.feat3 = floor_type[randint0(100)];
+       fill_data.feat1 = feat_ground_type[randint0(100)];
+       fill_data.feat2 = feat_ground_type[randint0(100)];
+       fill_data.feat3 = feat_ground_type[randint0(100)];
 
        fill_data.info1 = CAVE_FLOOR;
        fill_data.info2 = CAVE_FLOOR;
@@ -956,7 +985,7 @@ bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize,
        /* number of filled squares */
        fill_data.amount = 0;
 
-       cave_fill((byte)y0, (byte)x0);
+       cave_fill(floor_ptr, (byte)y0, (byte)x0);
 
        /* if tally too small, try again */
        if (fill_data.amount < 10)
@@ -966,8 +995,8 @@ bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize,
                {
                        for (y = 0; y <= ysize; ++y)
                        {
-                               place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
-                               cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
+                               place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
+                               floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
                        }
                }
                return FALSE;
@@ -981,75 +1010,75 @@ bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize,
        for (i = 0; i <= xsize; ++i)
        {
                /* top boundary */
-               if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
+               if ((floor_ptr->grid_array[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
                {
                        /* Next to a 'filled' region? - set to be room walls */
-                       place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
-                       if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
-                       cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
-                       place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
+                       place_outer_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
+                       if (light) floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
+                       floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
+                       place_outer_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
                }
                else
                {
                        /* set to be normal granite */
-                       place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
+                       place_extra_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
                }
 
                /* bottom boundary */
-               if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
+               if ((floor_ptr->grid_array[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
                {
                        /* Next to a 'filled' region? - set to be room walls */
-                       place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
-                       if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
-                       cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
-                       place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
+                       place_outer_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
+                       if (light) floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
+                       floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
+                       place_outer_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
                }
                else
                {
                        /* set to be normal granite */
-                       place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
+                       place_extra_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
                }
 
                /* clear the icky flag-don't need it any more */
-               cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
-               cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
+               floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
+               floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
        }
 
        /* Do the left and right boundaries minus the corners (done above) */
        for (i = 1; i < ysize; ++i)
        {
                /* left boundary */
-               if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
+               if ((floor_ptr->grid_array[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
                {
                        /* room boundary */
-                       place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
-                       if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
-                       cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
-                       place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
+                       place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
+                       if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
+                       floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
+                       place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
                }
                else
                {
                        /* outside room */
-                       place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
+                       place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
                }
                /* right boundary */
-               if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
+               if ((floor_ptr->grid_array[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
                {
                        /* room boundary */
-                       place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
-                       if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
-                       cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
-                       place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
+                       place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
+                       if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
+                       floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
+                       place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
                }
                else
                {
                        /* outside room */
-                       place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
+                       place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
                }
 
                /* clear icky flag -done with it */
-               cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
-               cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
+               floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
+               floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
        }
 
 
@@ -1058,44 +1087,44 @@ bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize,
        {
                for (y = 1; y < ysize; ++y)
                {
-                       if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
-                           (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
+                       if (is_floor_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
+                           (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
                        {
                                /* Clear the icky flag in the filled region */
-                               cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
+                               floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
 
                                /* Set appropriate flags */
-                               if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
-                               if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
+                               if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
+                               if (room) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
                        }
-                       else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
-                                (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
+                       else if (is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
+                                (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
                        {
                                /* Walls */
-                               cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
-                               if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
+                               floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
+                               if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
                                if (room)
                                {
-                                       cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
+                                       floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
                                }
                                else
                                {
 
-                                       place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
-                                       cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
+                                       place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
+                                       floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
                                }
                        }
                        else
                        {
                                /* Clear the unconnected regions */
-                               place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
-                               cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
+                               place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
+                               floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
                        }
                }
        }
 
        /*
-        * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
+        * There is a slight problem when tunnels pierce the caves:
         * Extra doors appear inside the system.  (Its not very noticeable though.)
         * This can be removed by "filling" from the outside in.  This allows a separation
         * from _outer_ with _inner_.  (Internal walls are  _outer_ instead.)
@@ -1112,17 +1141,18 @@ bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize,
 /*
  * Builds a cave system in the center of the dungeon.
  */
-void build_cavern(void)
+void build_cavern(floor_type *floor_ptr)
 {
-       int grd, roug, cutoff, xsize, ysize, x0, y0;
+       int grd, roug, cutoff;
+       POSITION xsize, ysize, x0, y0;
        bool done, light;
 
        light = done = FALSE;
-       if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
+       if ((floor_ptr->dun_level <= randint1(50)) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) light = TRUE;
 
        /* Make a cave the size of the dungeon */
-       xsize = cur_wid - 1;
-       ysize = cur_hgt - 1;
+       xsize = floor_ptr->width - 1;
+       ysize = floor_ptr->height - 1;
        x0 = xsize / 2;
        y0 = ysize / 2;
 
@@ -1142,17 +1172,18 @@ void build_cavern(void)
                cutoff = xsize / 2;
 
                 /* make it */
-               generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
+               generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
 
                /* Convert to normal format+ clean up */
-               done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
+               done = generate_fracave(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
        }
 }
 
-bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
+bool generate_lake(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int c1, int c2, int c3, int type)
 {
-       int x, y, i, xhsize, yhsize;
-       int feat1, feat2, feat3;
+       POSITION x, y, xhsize, yhsize;
+       int i;
+       FEAT_IDX feat1, feat2, feat3;
 
        /* offsets to middle from corner */
        xhsize = xsize / 2;
@@ -1164,21 +1195,21 @@ bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3,
        case LAKE_T_LAVA: /* Lava */
                feat1 = feat_deep_lava;
                feat2 = feat_shallow_lava;
-               feat3 = floor_type[randint0(100)];
+               feat3 = feat_ground_type[randint0(100)];
                break;
        case LAKE_T_WATER: /* Water */
                feat1 = feat_deep_water;
                feat2 = feat_shallow_water;
-               feat3 = floor_type[randint0(100)];
+               feat3 = feat_ground_type[randint0(100)];
                break;
-       case LAKE_T_CAVE: /* Collapsed cave */
-               feat1 = floor_type[randint0(100)];
-               feat2 = floor_type[randint0(100)];
+       case LAKE_T_CAVE: /* Collapsed floor_ptr->grid_array */
+               feat1 = feat_ground_type[randint0(100)];
+               feat2 = feat_ground_type[randint0(100)];
                feat3 = feat_rubble;
                break;
        case LAKE_T_EARTH_VAULT: /* Earth vault */
                feat1 = feat_rubble;
-               feat2 = floor_type[randint0(100)];
+               feat2 = feat_ground_type[randint0(100)];
                feat3 = feat_rubble;
                break;
        case LAKE_T_AIR_VAULT: /* Air vault */
@@ -1196,13 +1227,11 @@ bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3,
                feat2 = feat_deep_lava;
                feat3 = feat_shallow_lava;
                break;
-
-       /* Paranoia */
        default: return FALSE;
        }
 
        /*
-        * select region connected to center of cave system
+        * select region connected to center of floor_ptr->grid_array system
         * this gets rid of alot of isolated one-sqaures that
         * can make teleport traps instadeaths...
         */
@@ -1224,10 +1253,10 @@ bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3,
        /* number of filled squares */
        fill_data.amount = 0;
 
-       /* select region connected to center of cave system
+       /* select region connected to center of floor_ptr->grid_array system
        * this gets rid of alot of isolated one-sqaures that
        * can make teleport traps instadeaths... */
-       cave_fill((byte)y0, (byte)x0);
+       cave_fill(floor_ptr, (byte)y0, (byte)x0);
 
        /* if tally too small, try again */
        if (fill_data.amount < 10)
@@ -1237,8 +1266,8 @@ bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3,
                {
                        for (y = 0; y <= ysize; ++y)
                        {
-                               place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
-                               cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
+                               place_floor_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
+                               floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
                        }
                }
                return FALSE;
@@ -1247,24 +1276,24 @@ bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3,
        /* Do boundarys- set to normal granite */
        for (i = 0; i <= xsize; ++i)
        {
-               place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
-               place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
+               place_extra_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
+               place_extra_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
 
                /* clear the icky flag-don't need it any more */
-               cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
-               cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
+               floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
+               floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
        }
 
        /* Do the left and right boundaries minus the corners (done above) */
 
        for (i = 1; i < ysize; ++i)
        {
-               place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
-               place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
+               place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
+               place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
 
                /* clear icky flag -done with it */
-               cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
-               cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
+               floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
+               floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
        }
 
 
@@ -1274,17 +1303,17 @@ bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3,
                for (y = 1; y < ysize; ++y)
                {
                        /* Fill unconnected regions with granite */
-                       if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
-                               is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
-                               place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
+                       if ((!(floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
+                               is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize))
+                               place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
 
                        /* turn off icky flag (no longer needed.) */
-                       cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
+                       floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
 
                        /* Light lava */
                        if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
                        {
-                               if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
+                               if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
                        }
                }
        }
@@ -1294,9 +1323,9 @@ bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3,
 
 
 /*
- * makes a lake/collapsed cave system in the center of the dungeon
+ * makes a lake/collapsed p_ptr->current_floor_ptr->grid_array system in the center of the dungeon
  */
-void build_lake(int type)
+void build_lake(floor_type *floor_ptr, int type)
 {
        int grd, roug, xsize, ysize, x0, y0;
        bool done = FALSE;
@@ -1310,8 +1339,8 @@ void build_lake(int type)
        }
 
        /* Make the size of the dungeon */
-       xsize = cur_wid - 1;
-       ysize = cur_hgt - 1;
+       xsize = floor_ptr->width - 1;
+       ysize = floor_ptr->height - 1;
        x0 = xsize / 2;
        y0 = ysize / 2;
 
@@ -1338,10 +1367,10 @@ void build_lake(int type)
                c2 = (c1 + c3) / 2;
 
                /* make it */
-               generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
+               generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
 
                /* Convert to normal format+ clean up */
-               done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
+               done = generate_lake(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
        }
 }
 #endif /* ALLOW_CAVERNS_AND_LAKES */
@@ -1351,9 +1380,9 @@ void build_lake(int type)
 /*
  * Routine that fills the empty areas of a room with treasure and monsters.
  */
-void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
+void fill_treasure(floor_type *floor_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
 {
-       int x, y, cx, cy, size;
+       POSITION x, y, cx, cy, size;
        s32b value;
 
        /* center of room:*/
@@ -1375,36 +1404,35 @@ void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
                        if ((randint1(100) - difficulty * 3) > 50) value = 20;
 
                         /* if floor, shallow water and lava */
-                       if (is_floor_bold(y, x) ||
+                       if (is_floor_bold(p_ptr->current_floor_ptr, y, x) ||
                            (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
                        {
                                /* The smaller 'value' is, the better the stuff */
                                if (value < 0)
                                {
                                        /* Meanest monster + treasure */
-                                       monster_level = base_level + 40;
+                                       floor_ptr->monster_level = floor_ptr->base_level + 40;
                                        place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                       monster_level = base_level;
-                                       object_level = base_level + 20;
+                                       floor_ptr->monster_level = floor_ptr->base_level;
+                                       floor_ptr->object_level = floor_ptr->base_level + 20;
                                        place_object(y, x, AM_GOOD);
-                                       object_level = base_level;
+                                       floor_ptr->object_level = floor_ptr->base_level;
                                }
                                else if (value < 5)
                                {
                                        /* Mean monster +treasure */
-                                       monster_level = base_level + 20;
+                                       floor_ptr->monster_level = floor_ptr->base_level + 20;
                                        place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                       monster_level = base_level;
-                                       object_level = base_level + 10;
+                                       floor_ptr->monster_level = floor_ptr->base_level;
+                                       floor_ptr->object_level = floor_ptr->base_level + 10;
                                        place_object(y, x, AM_GOOD);
-                                       object_level = base_level;
+                                       floor_ptr->object_level = floor_ptr->base_level;
                                }
                                else if (value < 10)
                                {
-                                       /* Monster */
-                                       monster_level = base_level + 9;
+                                       floor_ptr->monster_level = floor_ptr->base_level + 9;
                                        place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                       monster_level = base_level;
+                                       floor_ptr->monster_level = floor_ptr->base_level;
                                }
                                else if (value < 17)
                                {
@@ -1426,37 +1454,37 @@ void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
                                        }
                                        else
                                        {
-                                               place_trap(y, x);
+                                               place_trap(floor_ptr, y, x);
                                        }
                                }
                                else if (value < 30)
                                {
                                        /* Monster and trap */
-                                       monster_level = base_level + 5;
+                                       floor_ptr->monster_level = floor_ptr->base_level + 5;
                                        place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                       monster_level = base_level;
-                                       place_trap(y, x);
+                                       floor_ptr->monster_level = floor_ptr->base_level;
+                                       place_trap(floor_ptr, y, x);
                                }
                                else if (value < 40)
                                {
                                        /* Monster or object */
                                        if (randint0(100) < 50)
                                        {
-                                               monster_level = base_level + 3;
+                                               floor_ptr->monster_level = floor_ptr->base_level + 3;
                                                place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                               monster_level = base_level;
+                                               floor_ptr->monster_level = floor_ptr->base_level;
                                        }
                                        if (randint0(100) < 50)
                                        {
-                                               object_level = base_level + 7;
+                                               floor_ptr->object_level = floor_ptr->base_level + 7;
                                                place_object(y, x, 0L);
-                                               object_level = base_level;
+                                               floor_ptr->object_level = floor_ptr->base_level;
                                        }
                                }
                                else if (value < 50)
                                {
                                        /* Trap */
-                                       place_trap(y, x);
+                                       place_trap(floor_ptr, y, x);
                                }
                                else
                                {
@@ -1469,7 +1497,7 @@ void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
                                        }
                                        else if (randint0(100) < 50)
                                        {
-                                               place_trap(y, x);
+                                               place_trap(floor_ptr, y, x);
                                        }
                                        else if (randint0(100) < 50)
                                        {
@@ -1490,14 +1518,14 @@ void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
  * The area inside the walls is not touched:
  * only granite is removed- normal walls stay
  */
-void build_room(int x1, int x2, int y1, int y2)
+void build_room(floor_type *floor_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2)
 {
-       int x, y, i, xsize, ysize, temp;
+       POSITION x, y, xsize, ysize;
+       int i, temp;
 
        /* Check if rectangle has no width */
        if ((x1 == x2) || (y1 == y2)) return;
 
-       /* initialize */
        if (x1 > x2)
        {
                /* Swap boundaries if in wrong order */
@@ -1522,19 +1550,19 @@ void build_room(int x1, int x2, int y1, int y2)
        /* Top and bottom boundaries */
        for (i = 0; i <= xsize; i++)
        {
-               place_outer_noperm_bold(y1, x1 + i);
-               cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
-               place_outer_noperm_bold(y2, x1 + i);
-               cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
+               place_outer_noperm_bold(floor_ptr, y1, x1 + i);
+               floor_ptr->grid_array[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
+               place_outer_noperm_bold(floor_ptr, y2, x1 + i);
+               floor_ptr->grid_array[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
        }
 
        /* Left and right boundaries */
        for (i = 1; i < ysize; i++)
        {
-               place_outer_noperm_bold(y1 + i, x1);
-               cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
-               place_outer_noperm_bold(y1 + i, x2);
-               cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
+               place_outer_noperm_bold(floor_ptr, y1 + i, x1);
+               floor_ptr->grid_array[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
+               place_outer_noperm_bold(floor_ptr, y1 + i, x2);
+               floor_ptr->grid_array[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
        }
 
        /* Middle */
@@ -1542,16 +1570,16 @@ void build_room(int x1, int x2, int y1, int y2)
        {
                for (y = 1; y < ysize; y++)
                {
-                       if (is_extra_bold(y1+y, x1+x))
+                       if (is_extra_bold(floor_ptr, y1+y, x1+x))
                        {
                                /* clear the untouched region */
-                               place_floor_bold(y1 + y, x1 + x);
-                               cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
+                               place_floor_bold(floor_ptr, y1 + y, x1 + x);
+                               floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
                        }
                        else
                        {
                                /* make it a room- but don't touch */
-                               cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
+                               floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
                        }
                }
        }
@@ -1577,7 +1605,7 @@ void build_room(int x1, int x2, int y1, int y2)
  * is the randint0(3) below; it governs the relative density of
  * twists and turns in the labyrinth: smaller number, more twists.
  */
-void r_visit(int y1, int x1, int y2, int x2, int node, int dir, int *visited)
+void r_visit(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
 {
        int i, j, m, n, temp, x, y, adj[4];
 
@@ -1589,7 +1617,7 @@ void r_visit(int y1, int x1, int y2, int x2, int node, int dir, int *visited)
        visited[node] = 1;
        x = 2 * (node % m) + x1;
        y = 2 * (node / m) + y1;
-       place_floor_bold(y, x);
+       place_floor_bold(floor_ptr, y, x);
 
        /* setup order of adjacent node visits */
        if (one_in_(3))
@@ -1629,50 +1657,50 @@ void r_visit(int y1, int x1, int y2, int x2, int node, int dir, int *visited)
                                /* (0,+) - check for bottom boundary */
                                if ((node / m < n - 1) && (visited[node + m] == 0))
                                {
-                                       place_floor_bold(y + 1, x);
-                                       r_visit(y1, x1, y2, x2, node + m, dir, visited);
+                                       place_floor_bold(floor_ptr, y + 1, x);
+                                       r_visit(floor_ptr, y1, x1, y2, x2, node + m, dir, visited);
                                }
                                break;
                        case 1:
                                /* (0,-) - check for top boundary */
                                if ((node / m > 0) && (visited[node - m] == 0))
                                {
-                                       place_floor_bold(y - 1, x);
-                                       r_visit(y1, x1, y2, x2, node - m, dir, visited);
+                                       place_floor_bold(floor_ptr, y - 1, x);
+                                       r_visit(floor_ptr, y1, x1, y2, x2, node - m, dir, visited);
                                }
                                break;
                        case 2:
                                /* (+,0) - check for right boundary */
                                if ((node % m < m - 1) && (visited[node + 1] == 0))
                                {
-                                       place_floor_bold(y, x + 1);
-                                       r_visit(y1, x1, y2, x2, node + 1, dir, visited);
+                                       place_floor_bold(floor_ptr, y, x + 1);
+                                       r_visit(floor_ptr, y1, x1, y2, x2, node + 1, dir, visited);
                                }
                                break;
                        case 3:
                                /* (-,0) - check for left boundary */
                                if ((node % m > 0) && (visited[node - 1] == 0))
                                {
-                                       place_floor_bold(y, x - 1);
-                                       r_visit(y1, x1, y2, x2, node - 1, dir, visited);
+                                       place_floor_bold(floor_ptr, y, x - 1);
+                                       r_visit(floor_ptr, y1, x1, y2, x2, node - 1, dir, visited);
                                }
                } /* end switch */
        }
 }
 
 
-void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
+void build_maze_vault(floor_type *floor_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
 {
        POSITION y, x, dy, dx;
        POSITION y1, x1, y2, x2;
        int m, n, num_vertices, *visited;
        bool light;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
 
        /* Choose lite or dark */
-       light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
+       light = ((floor_ptr->dun_level <= randint1(25)) && is_vault && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS));
 
        /* Pick a random room size - randomized by calling routine */
        dy = ysize / 2 - 1;
@@ -1688,22 +1716,22 @@ void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize,
        {
                for (x = x1 - 1; x <= x2 + 1; x++)
                {
-                       c_ptr = &cave[y][x];
-                       c_ptr->info |= CAVE_ROOM;
-                       if (is_vault) c_ptr->info |= CAVE_ICKY;
+                       g_ptr = &floor_ptr->grid_array[y][x];
+                       g_ptr->info |= CAVE_ROOM;
+                       if (is_vault) g_ptr->info |= CAVE_ICKY;
                        if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
                        {
-                               place_outer_grid(c_ptr);
+                               place_outer_grid(g_ptr);
                        }
                        else if (!is_vault)
                        {
-                               place_extra_grid(c_ptr);
+                               place_extra_grid(g_ptr);
                        }
                        else
                        {
-                               place_inner_grid(c_ptr);
+                               place_inner_grid(g_ptr);
                        }
-                       if (light) c_ptr->info |= (CAVE_GLOW);
+                       if (light) g_ptr->info |= (CAVE_GLOW);
                }
        }
 
@@ -1716,10 +1744,10 @@ void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize,
        C_MAKE(visited, num_vertices, int);
 
        /* traverse the graph to create a spaning tree, pick a random root */
-       r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
+       r_visit(floor_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited);
 
        /* Fill with monsters and treasure, low difficulty */
-       if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
+       if (is_vault) fill_treasure(floor_ptr, x1, x2, y1, y2, randint1(5));
 
        C_KILL(visited, num_vertices, int);
 }
@@ -1732,10 +1760,10 @@ void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize,
  * The power variable is a measure of how well defended a region is.
  * This alters the possible choices.
  */
-void build_recursive_room(int x1, int y1, int x2, int y2, int power)
+void build_recursive_room(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
 {
-       int xsize, ysize;
-       int x, y;
+       POSITION xsize, ysize;
+       POSITION x, y;
        int choice;
 
        /* Temp variables */
@@ -1781,15 +1809,15 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
                        /* top and bottom */
                        for (x = x1; x <= x2; x++)
                        {
-                               place_outer_bold(y1, x);
-                               place_outer_bold(y2, x);
+                               place_outer_bold(floor_ptr, y1, x);
+                               place_outer_bold(floor_ptr, y2, x);
                        }
 
                        /* left and right */
                        for (y = y1 + 1; y < y2; y++)
                        {
-                               place_outer_bold(y, x1);
-                               place_outer_bold(y, x2);
+                               place_outer_bold(floor_ptr, y, x1);
+                               place_outer_bold(floor_ptr, y, x2);
                        }
 
                        /* Make a couple of entrances */
@@ -1797,15 +1825,15 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
                        {
                                /* left and right */
                                y = randint1(ysize) + y1;
-                               place_floor_bold(y, x1);
-                               place_floor_bold(y, x2);
+                               place_floor_bold(floor_ptr, y, x1);
+                               place_floor_bold(floor_ptr, y, x2);
                        }
                        else
                        {
                                /* top and bottom */
                                x = randint1(xsize) + x1;
-                               place_floor_bold(y1, x);
-                               place_floor_bold(y2, x);
+                               place_floor_bold(floor_ptr, y1, x);
+                               place_floor_bold(floor_ptr, y2, x);
                        }
 
                        /* Select size of keep */
@@ -1817,12 +1845,12 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
                        /* Do outside areas */
 
                        /* Above and below keep */
-                       build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
-                       build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
+                       build_recursive_room(floor_ptr, x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
+                       build_recursive_room(floor_ptr, x1 + 1, t2, x2 - 1, y2, power + 1);
 
                        /* Left and right of keep */
-                       build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
-                       build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
+                       build_recursive_room(floor_ptr, x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
+                       build_recursive_room(floor_ptr, t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
 
                        /* Make the keep itself: */
                        x1 = t3;
@@ -1844,7 +1872,7 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
                                {
                                        for (x = x1; x < x2; x++)
                                        {
-                                               place_inner_bold(y, x);
+                                               place_inner_bold(floor_ptr, y, x);
                                        }
                                }
 
@@ -1856,15 +1884,15 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
                        /* top and bottom */
                        for (x = x1 + 1; x <= x2 - 1; x++)
                        {
-                               place_inner_bold(y1 + 1, x);
-                               place_inner_bold(y2 - 1, x);
+                               place_inner_bold(floor_ptr, y1 + 1, x);
+                               place_inner_bold(floor_ptr, y2 - 1, x);
                        }
 
                        /* left and right */
                        for (y = y1 + 1; y <= y2 - 1; y++)
                        {
-                               place_inner_bold(y, x1 + 1);
-                               place_inner_bold(y, x2 - 1);
+                               place_inner_bold(floor_ptr, y, x1 + 1);
+                               place_inner_bold(floor_ptr, y, x2 - 1);
                        }
 
                        /* Make a door */
@@ -1873,16 +1901,16 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
                        if (one_in_(2))
                        {
                                /* left */
-                               place_floor_bold(y, x1 + 1);
+                               place_floor_bold(floor_ptr, y, x1 + 1);
                        }
                        else
                        {
                                /* right */
-                               place_floor_bold(y, x2 - 1);
+                               place_floor_bold(floor_ptr, y, x2 - 1);
                        }
 
                        /* Build the room */
-                       build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
+                       build_recursive_room(floor_ptr, x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
                        break;
                }
                case 2:
@@ -1895,15 +1923,15 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
                                {
                                        for (x = x1; x < x2; x++)
                                        {
-                                               place_inner_bold(y, x);
+                                               place_inner_bold(floor_ptr, y, x);
                                        }
                                }
                                return;
                        }
 
                        t1 = randint1(xsize - 2) + x1 + 1;
-                       build_recursive_room(x1, y1, t1, y2, power - 2);
-                       build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
+                       build_recursive_room(floor_ptr, x1, y1, t1, y2, power - 2);
+                       build_recursive_room(floor_ptr, t1 + 1, y1, x2, y2, power - 2);
                        break;
                }
                case 3:
@@ -1916,15 +1944,15 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
                                {
                                        for (x = x1; x < x2; x++)
                                        {
-                                               place_inner_bold(y, x);
+                                               place_inner_bold(floor_ptr, y, x);
                                        }
                                }
                                return;
                        }
 
                        t1 = randint1(ysize - 2) + y1 + 1;
-                       build_recursive_room(x1, y1, x2, t1, power - 2);
-                       build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
+                       build_recursive_room(floor_ptr, x1, y1, x2, t1, power - 2);
+                       build_recursive_room(floor_ptr, x1, t1 + 1, x2, y2, power - 2);
                        break;
                }
        }
@@ -1936,26 +1964,26 @@ void build_recursive_room(int x1, int y1, int x2, int y2, int power)
  * Note: no range checking is done so must be inside dungeon
  * This routine also stomps on doors
  */
-void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
+void add_outer_wall(POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
 {
-       cave_type *c_ptr;
+       grid_type *g_ptr;
        feature_type *f_ptr;
        int i, j;
 
-       if (!in_bounds(y, x)) return;
+       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
 
-       c_ptr = &cave[y][x];
+       g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
        /* hack- check to see if square has been visited before
        * if so, then exit (use room flag to do this) */
-       if (c_ptr->info & CAVE_ROOM) return;
+       if (g_ptr->info & CAVE_ROOM) return;
 
        /* set room flag */
-       c_ptr->info |= CAVE_ROOM;
+       g_ptr->info |= CAVE_ROOM;
 
-       f_ptr = &f_info[c_ptr->feat];
+       f_ptr = &f_info[g_ptr->feat];
 
-       if (is_floor_bold(y, x))
+       if (is_floor_bold(p_ptr->current_floor_ptr, y, x))
        {
                for (i = -1; i <= 1; i++)
                {
@@ -1965,21 +1993,21 @@ void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
                                         (y + j >= y1) && (y + j <= y2))
                                {
                                        add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
-                                       if (light) c_ptr->info |= CAVE_GLOW;
+                                       if (light) g_ptr->info |= CAVE_GLOW;
                                }
                        }
                }
        }
-       else if (is_extra_bold(y, x))
+       else if (is_extra_bold(p_ptr->current_floor_ptr, y, x))
        {
                /* Set bounding walls */
-               place_outer_bold(y, x);
-               if (light) c_ptr->info |= CAVE_GLOW;
+               place_outer_bold(p_ptr->current_floor_ptr, y, x);
+               if (light) g_ptr->info |= CAVE_GLOW;
        }
        else if (permanent_wall(f_ptr))
        {
                /* Set bounding walls */
-               if (light) c_ptr->info |= CAVE_GLOW;
+               if (light) g_ptr->info |= CAVE_GLOW;
        }
 }
 
@@ -1988,9 +2016,9 @@ void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
  * Hacked distance formula - gives the 'wrong' answer.
  * Used to build crypts
  */
-int dist2(int x1, int y1, int x2, int y2, int h1, int h2, int h3, int h4)
+POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
 {
-       int dx, dy;
+       POSITION dx, dy;
        dx = abs(x2 - x1);
        dy = abs(y2 - y1);
 
@@ -2013,35 +2041,35 @@ int dist2(int x1, int y1, int x2, int y2, int h1, int h2, int h3, int h4)
 
 
 /* Create a new floor room with optional light */
-void generate_room_floor(int y1, int x1, int y2, int x2, int light)
+void generate_room_floor(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
 {
-       int y, x;
+       POSITION y, x;
        
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        for (y = y1; y <= y2; y++)
        {
                for (x = x1; x <= x2; x++)
                {
                        /* Point to grid */
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-                       c_ptr->info |= (CAVE_ROOM);
-                       if (light) c_ptr->info |= (CAVE_GLOW);
+                       g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
+                       place_floor_grid(g_ptr);
+                       g_ptr->info |= (CAVE_ROOM);
+                       if (light) g_ptr->info |= (CAVE_GLOW);
                }
        }
 }
 
-void generate_fill_perm_bold(int y1, int x1, int y2, int x2)
+void generate_fill_perm_bold(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
 {
-       int y, x;
+       POSITION y, x;
 
        for (y = y1; y <= y2; y++)
        {
                for (x = x1; x <= x2; x++)
                {
                        /* Point to grid */
-                       place_inner_perm_bold(y, x);
+                       place_inner_perm_bold(p_ptr->current_floor_ptr ,y, x);
                }
        }
 }
@@ -2053,32 +2081,30 @@ void generate_fill_perm_bold(int y1, int x1, int y2, int x2)
  * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
  * @return 部屋の精製に成功した場合 TRUE を返す。
  */
-static bool room_build(int typ)
+static bool room_build(floor_type *floor_ptr, EFFECT_ID typ)
 {
        /* Build a room */
        switch (typ)
        {
        /* Build an appropriate room */
-       case ROOM_T_NORMAL:        return build_type1();
-       case ROOM_T_OVERLAP:       return build_type2();
-       case ROOM_T_CROSS:         return build_type3();
-       case ROOM_T_INNER_FEAT:    return build_type4();
-       case ROOM_T_NEST:          return build_type5();
-       case ROOM_T_PIT:           return build_type6();
-       case ROOM_T_LESSER_VAULT:  return build_type7();
-       case ROOM_T_GREATER_VAULT: return build_type8();
-       case ROOM_T_FRACAVE:       return build_type9();
-       case ROOM_T_RANDOM_VAULT:  return build_type10();
-       case ROOM_T_OVAL:          return build_type11();
-       case ROOM_T_CRYPT:         return build_type12();
-       case ROOM_T_TRAP_PIT:      return build_type13();
-       case ROOM_T_TRAP:          return build_type14();
-       case ROOM_T_GLASS:         return build_type15();
-       case ROOM_T_ARCADE:        return build_type16();
-       case ROOM_T_FIXED:         return build_type17();
-       }
-
-       /* Paranoia */
+       case ROOM_T_NORMAL:        return build_type1(floor_ptr);
+       case ROOM_T_OVERLAP:       return build_type2(floor_ptr);
+       case ROOM_T_CROSS:         return build_type3(floor_ptr);
+       case ROOM_T_INNER_FEAT:    return build_type4(floor_ptr);
+       case ROOM_T_NEST:          return build_type5(floor_ptr);
+       case ROOM_T_PIT:           return build_type6(floor_ptr);
+       case ROOM_T_LESSER_VAULT:  return build_type7(floor_ptr);
+       case ROOM_T_GREATER_VAULT: return build_type8(floor_ptr);
+       case ROOM_T_FRACAVE:       return build_type9(floor_ptr);
+       case ROOM_T_RANDOM_VAULT:  return build_type10(floor_ptr);
+       case ROOM_T_OVAL:          return build_type11(floor_ptr);
+       case ROOM_T_CRYPT:         return build_type12(floor_ptr);
+       case ROOM_T_TRAP_PIT:      return build_type13(floor_ptr);
+       case ROOM_T_TRAP:          return build_type14(floor_ptr);
+       case ROOM_T_GLASS:         return build_type15(floor_ptr);
+       case ROOM_T_ARCADE:        return build_type16(floor_ptr);
+       case ROOM_T_FIXED:         return build_type17(floor_ptr);
+       }
        return FALSE;
 }
 
@@ -2093,7 +2119,7 @@ static bool room_build(int typ)
  * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon.  Build bigger rooms at first. [from SAngband (originally from OAngband)]
  * @return 部屋生成に成功した場合 TRUE を返す。
  */
-bool generate_rooms(void)
+bool generate_rooms(floor_type *floor_ptr)
 {
        int i;
        bool remain;
@@ -2101,8 +2127,8 @@ bool generate_rooms(void)
        int total_prob;
        int prob_list[ROOM_T_MAX];
        int rooms_built = 0;
-       int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
-       int level_index = MIN(10, div_round(dun_level, 10));
+       int area_size = 100 * (floor_ptr->height*floor_ptr->width) / (MAX_HGT*MAX_WID);
+       int level_index = MIN(10, div_round(floor_ptr->dun_level, 10));
 
        /* Number of each type of room on this level */
        s16b room_num[ROOM_T_MAX];
@@ -2110,7 +2136,7 @@ bool generate_rooms(void)
        /* Limit number of rooms */
        int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
 
-       /* Assume normal cave */
+       /* Assume normal floor_ptr->grid_array */
        room_info_type *room_info_ptr = room_info_normal;
 
        /*
@@ -2119,7 +2145,7 @@ bool generate_rooms(void)
        for (i = 0; i < ROOM_T_MAX; i++)
        {
                /* No rooms allowed above their minimum depth. */
-               if (dun_level < room_info_ptr[i].min_level)
+               if (floor_ptr->dun_level < room_info_ptr[i].min_level)
                {
                        prob_list[i] = 0;
                }
@@ -2133,8 +2159,10 @@ bool generate_rooms(void)
         * XXX -- Various dungeon types and options.
         */
 
-       /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、かつ「常に通常でない部屋を生成する」フラグがONならば、GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
-       if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
+       /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、
+        * かつ「常に通常でない部屋を生成する」フラグがONならば、
+        * GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
+       if (ironman_rooms && !((d_info[p_ptr->dungeon_idx].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
        {
                for (i = 0; i < ROOM_T_MAX; i++)
                {
@@ -2144,23 +2172,29 @@ bool generate_rooms(void)
        }
 
        /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
-       else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
+       else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_VAULT)
        {
                prob_list[ROOM_T_LESSER_VAULT] = 0;
                prob_list[ROOM_T_GREATER_VAULT] = 0;
                prob_list[ROOM_T_RANDOM_VAULT] = 0;
        }
 
+       /*! @details ダンジョンにBEGINNERフラグがあるならば、FIXED_ROOMを除外 / Forbidden vaults */
+       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
+       {
+               prob_list[ROOM_T_FIXED] = 0;
+       }
+
        /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
-       if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
+       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)
        {
                MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
                MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
                MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
        }
 
-       /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc cave etc.) */
-       else if (d_info[dungeon_type].flags1 & DF1_CAVE)
+       /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc floor_ptr->grid_array etc.) */
+       else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CAVE)
        {
                MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
        }
@@ -2172,13 +2206,13 @@ bool generate_rooms(void)
        }
 
        /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
-       if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
+       if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_ROOM))
        {
                prob_list[ROOM_T_GLASS] = 0;
        }
 
        /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
-       if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
+       if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_ARCADE))
        {
                prob_list[ROOM_T_ARCADE] = 0;
        }
@@ -2208,8 +2242,6 @@ bool generate_rooms(void)
                        if (rand < prob_list[room_type]) break;
                        else rand -= prob_list[room_type];
                }
-
-               /* Paranoia */
                if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
 
                /* Increase the number of rooms of that type we should build. */
@@ -2258,7 +2290,7 @@ bool generate_rooms(void)
                        room_num[room_type]--;
 
                        /* Build the room. */
-                       if (room_build(room_type))
+                       if (room_build(floor_ptr, room_type))
                        {
                                /* Increase the room built count. */
                                rooms_built++;