OSDN Git Service

Corrected spelling in English description of the hatchet of Elmi the Murderer.
[hengbandforosx/hengbandosx.git] / src / rooms.c
index d518bcf..bd5abfa 100644 (file)
 #include "rooms-trap.h"
 #include "rooms-vault.h"
 
+#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    */
@@ -87,8 +93,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   */
+       {{  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] = {
@@ -102,6 +137,7 @@ 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,
@@ -111,74 +147,6 @@ static byte room_build_order[ROOM_T_MAX] = {
 };
 
 /*!
- * @brief 鍵のかかったドアを配置する
- * @param y 配置したいフロアのY座標
- * @param x 配置したいフロアのX座標
- * @return なし
- */
-void place_locked_door(int y, int x)
-{
-       if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
-       {
-               place_floor_bold(y, x);
-       }
-       else
-       {
-               set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
-               cave[y][x].info &= ~(CAVE_FLOOR);
-               delete_monster(y, x);
-       }
-}
-
-/*!
- * @brief 隠しドアを配置する
- * @param y 配置したいフロアのY座標
- * @param x 配置したいフロアのX座標
- * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
- * @return なし
- */
-void place_secret_door(int y, int x, int type)
-{
-       if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
-       {
-               place_floor_bold(y, x);
-       }
-       else
-       {
-               cave_type *c_ptr = &cave[y][x];
-
-               if (type == DOOR_DEFAULT)
-               {
-                       type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
-                               one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
-                               ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
-               }
-
-               /* Create secret door */
-               place_closed_door(y, x, type);
-
-               if (type != DOOR_CURTAIN)
-               {
-                       /* Hide by inner wall because this is used in rooms only */
-                       c_ptr->mimic = feat_wall_inner;
-
-                       /* Floor type terrain cannot hide a door */
-                       if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
-                       {
-                               if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
-                               {
-                                       c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
-                               }
-                               c_ptr->mimic = 0;
-                       }
-               }
-
-               c_ptr->info &= ~(CAVE_FLOOR);
-               delete_monster(y, x);
-       }
-}
-
-/*!
  * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
  * @param y0 配置したい中心のY座標
  * @param x0 配置したい中心のX座標
@@ -189,9 +157,9 @@ void place_secret_door(int y, int x, int type)
  * Note - this should be used only on allocated regions
  * within another room.
  */
-void build_small_room(int x0, int y0)
+void build_small_room(POSITION x0, POSITION y0)
 {
-       int x, y;
+       POSITION x, y;
 
        for (y = y0 - 1; y <= y0 + 1; y++)
        {
@@ -215,7 +183,7 @@ void build_small_room(int x0, int y0)
        }
 
        /* Clear mimic type */
-       cave[y0][x0].mimic = 0;
+       current_floor_ptr->grid_array[y0][x0].mimic = 0;
 
        /* Add inner open space */
        place_floor_bold(y0, x0);
@@ -224,20 +192,18 @@ void build_small_room(int x0, int y0)
 /*!
  * @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 current_floor_ptr->grid_array system.
  * @param x1 範囲の左端
  * @param y1 範囲の上端
  * @param x2 範囲の右端
  * @param y2 範囲の下端
  * @return なし
  */
-static void check_room_boundary(int x1, int y1, int x2, int y2)
+static void check_room_boundary(POSITION x1, POSITION y1, POSITION x2, POSITION y2)
 {
-       int count, x, y;
+       int count;
+       POSITION x, y;
        bool old_is_floor, new_is_floor;
-
-
-       /* Initialize */
        count = 0;
 
        old_is_floor = get_is_floor(x1 - 1, y1);
@@ -317,9 +283,9 @@ static void check_room_boundary(int x1, int y1, int x2, int y2)
  * @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)
@@ -362,8 +328,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;
 
@@ -411,13 +377,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;
@@ -446,7 +411,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);
@@ -477,8 +442,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;
 
@@ -508,7 +473,6 @@ bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
                }
        }
 
-
        /*
         * Hack- See if room will cut off a cavern.
         *
@@ -517,14 +481,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
  */
@@ -534,10 +495,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;
@@ -545,9 +506,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;
@@ -560,17 +521,17 @@ struct fill_data_type
 static fill_data_type fill_data;
 
 
-/* Store routine for the fractal cave generator */
+/* Store routine for the fractal current_floor_ptr->grid_array 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(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;
+       current_floor_ptr->grid_array[y][x].feat = val;
 
        return;
 }
@@ -603,7 +564,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 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.
@@ -611,7 +572,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 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_.
@@ -619,7 +580,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 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.
@@ -627,23 +588,23 @@ 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 current_floor_ptr->grid_array system.
  */
-void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
+void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
 {
-       int xhsize, yhsize, xsize, ysize, maxsize;
+       POSITION xhsize, yhsize, xsize, ysize, maxsize;
 
        /*
         * fixed point variables- these are stored as 256 x normal value
         * 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;
@@ -688,20 +649,20 @@ void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cu
                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);
+                       current_floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
+                       /* Clear icky flag because may be redoing the current_floor_ptr->grid_array */
+                       current_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;
+       current_floor_ptr->grid_array[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
+       current_floor_ptr->grid_array[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
+       current_floor_ptr->grid_array[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
+       current_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;
+       current_floor_ptr->grid_array[y0][x0].feat = 0;
 
        /* Initialize the step sizes */
        xstep = xhstep = xsize * 256;
@@ -738,7 +699,7 @@ void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cu
                                jj = j / 256 + fill_data.ymin;
 
                                /* Test square */
-                               if (cave[jj][ii].feat == -1)
+                               if (current_floor_ptr->grid_array[jj][ii].feat == -1)
                                {
                                        if (xhstep2 > grd)
                                        {
@@ -749,8 +710,8 @@ void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cu
                                        {
                                                /* 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
+                                                       (current_floor_ptr->grid_array[jj][fill_data.xmin + (i - xhstep) / 256].feat
+                                                        + current_floor_ptr->grid_array[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
                                                         + (randint1(xstep2) - xhstep2) * roug / 16);
                                        }
                                }
@@ -768,7 +729,7 @@ void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cu
                                jj = j / 256 + fill_data.ymin;
 
                                /* Test square */
-                               if (cave[jj][ii].feat == -1)
+                               if (current_floor_ptr->grid_array[jj][ii].feat == -1)
                                {
                                        if (xhstep2 > grd)
                                        {
@@ -779,8 +740,8 @@ void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cu
                                        {
                                                /* 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
+                                                       (current_floor_ptr->grid_array[fill_data.ymin + (j - yhstep) / 256][ii].feat
+                                                       + current_floor_ptr->grid_array[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
                                                        + (randint1(ystep2) - yhstep2) * roug / 16);
                                        }
                                }
@@ -797,7 +758,7 @@ void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cu
                                jj = j / 256 + fill_data.ymin;
 
                                /* Test square */
-                               if (cave[jj][ii].feat == -1)
+                               if (current_floor_ptr->grid_array[jj][ii].feat == -1)
                                {
                                        if (xhstep2 > grd)
                                        {
@@ -817,8 +778,8 @@ void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cu
                                                 * 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
+                                                       (current_floor_ptr->grid_array[ym][xm].feat + current_floor_ptr->grid_array[yp][xm].feat
+                                                       + current_floor_ptr->grid_array[ym][xp].feat + current_floor_ptr->grid_array[yp][xp].feat) / 4
                                                        + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
                                        }
                                }
@@ -828,13 +789,13 @@ void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cu
 }
 
 
-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(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 current_floor_ptr->grid_array format
         */
-       if (cave[y][x].info & CAVE_ICKY)
+       if (current_floor_ptr->grid_array[y][x].info & CAVE_ICKY)
        {
                /* already done */
                return FALSE;
@@ -842,50 +803,50 @@ 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);
+               current_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 (current_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;
+                               current_floor_ptr->grid_array[y][x].feat = feat1;
+                               current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                               current_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;
+                               current_floor_ptr->grid_array[y][x].feat = feat2;
+                               current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                               current_floor_ptr->grid_array[y][x].info |= info2;
                                return TRUE;
                        }
                }
-               else if (cave[y][x].feat <= c2)
+               else if (current_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;
+                               current_floor_ptr->grid_array[y][x].feat = feat2;
+                               current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                               current_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;
+                               current_floor_ptr->grid_array[y][x].feat = feat1;
+                               current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                               current_floor_ptr->grid_array[y][x].info |= info1;
                                return TRUE;
                        }
                }
-               else if (cave[y][x].feat <= c3)
+               else if (current_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;
+                       current_floor_ptr->grid_array[y][x].feat = feat3;
+                       current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+                       current_floor_ptr->grid_array[y][x].info |= info3;
                        return TRUE;
                }
                /* if greater than cutoff then is a wall */
@@ -902,12 +863,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 current_floor_ptr->grid_array
  */
 static void cave_fill(POSITION y, POSITION x)
 {
        int i, j, d;
-       int ty, tx;
+       POSITION ty, tx;
 
        int flow_tail = 1;
        int flow_head = 0;
@@ -916,16 +877,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;
@@ -939,11 +899,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 */
+                       /* Paranoia Don't leave the current_floor_ptr->grid_array */
                        if (!in_bounds(j, i))
                        {
                                /* affect boundary */
-                               cave[j][i].info |= CAVE_ICKY;
+                               current_floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
 /*                             return; */
                        }
 
@@ -958,8 +918,8 @@ static void cave_fill(POSITION y, POSITION x)
                                        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;
@@ -971,7 +931,7 @@ static void cave_fill(POSITION y, POSITION x)
                                        }
                                        else
                                        {
-                                               /* keep tally of size of cave system */
+                                               /* keep tally of size of current_floor_ptr->grid_array system */
                                                (fill_data.amount)++;
                                        }
                                }
@@ -979,16 +939,17 @@ static void cave_fill(POSITION y, POSITION x)
                        else
                        {
                                /* affect boundary */
-                               cave[j][i].info |= CAVE_ICKY;
+                               current_floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
                        }
                }
        }
 }
 
 
-bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
+bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
 {
-       int x, y, i, xhsize, yhsize;
+       POSITION x, y, xhsize, yhsize;
+       int i;
 
        /* offsets to middle from corner */
        xhsize = xsize / 2;
@@ -996,7 +957,7 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
 
 
        /*
-        * select region connected to center of cave system
+        * select region connected to center of current_floor_ptr->grid_array system
         * this gets rid of alot of isolated one-sqaures that
         * can make teleport traps instadeaths...
         */
@@ -1007,9 +968,9 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
        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;
@@ -1029,7 +990,7 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
                        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);
+                               current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
                        }
                }
                return FALSE;
@@ -1043,12 +1004,12 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
        for (i = 0; i <= xsize; ++i)
        {
                /* top boundary */
-               if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
+               if ((current_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);
+                       if (light) current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
+                       current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
                        place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
                }
                else
@@ -1058,12 +1019,12 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
                }
 
                /* bottom boundary */
-               if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
+               if ((current_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);
+                       if (light) current_floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
+                       current_floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
                        place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
                }
                else
@@ -1073,20 +1034,20 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
                }
 
                /* 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);
+               current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
+               current_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 ((current_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);
+                       if (light) current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
+                       current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
                        place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
                }
                else
@@ -1095,12 +1056,12 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
                        place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
                }
                /* right boundary */
-               if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
+               if ((current_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);
+                       if (light) current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
+                       current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
                        place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
                }
                else
@@ -1110,8 +1071,8 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
                }
 
                /* 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);
+               current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
+               current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
        }
 
 
@@ -1121,43 +1082,43 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
                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))
+                           (current_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;
+                               current_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) current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
+                               if (room) current_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))
+                                (current_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);
+                               current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
+                               if (light) current_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);
+                                       current_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);
+                                       current_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);
+                               current_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.)
@@ -1172,19 +1133,20 @@ bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool lig
 
 #ifdef ALLOW_CAVERNS_AND_LAKES
 /*
- * Builds a cave system in the center of the dungeon.
+ * Builds a current_floor_ptr->grid_array system in the center of the dungeon.
  */
 void build_cavern(void)
 {
-       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 ((current_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;
+       /* Make a current_floor_ptr->grid_array the size of the dungeon */
+       xsize = current_floor_ptr->width - 1;
+       ysize = current_floor_ptr->height - 1;
        x0 = xsize / 2;
        y0 = ysize / 2;
 
@@ -1211,10 +1173,11 @@ void build_cavern(void)
        }
 }
 
-static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
+bool generate_lake(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;
@@ -1226,21 +1189,21 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
        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 current_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 */
@@ -1258,13 +1221,11 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
                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 current_floor_ptr->grid_array system
         * this gets rid of alot of isolated one-sqaures that
         * can make teleport traps instadeaths...
         */
@@ -1286,7 +1247,7 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
        /* number of filled squares */
        fill_data.amount = 0;
 
-       /* select region connected to center of cave system
+       /* select region connected to center of current_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);
@@ -1300,7 +1261,7 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
                        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);
+                               current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
                        }
                }
                return FALSE;
@@ -1313,8 +1274,8 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
                place_extra_bold(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);
+               current_floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
+               current_floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
        }
 
        /* Do the left and right boundaries minus the corners (done above) */
@@ -1325,8 +1286,8 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
                place_extra_bold(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);
+               current_floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
+               current_floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
        }
 
 
@@ -1336,17 +1297,17 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
                for (y = 1; y < ysize; ++y)
                {
                        /* Fill unconnected regions with granite */
-                       if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
+                       if ((!(current_floor_ptr->grid_array[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);
 
-                       /* turn off icky flag (no longer needed.) */
-                       cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
+                       /* current_world_ptr->game_turn off icky flag (no longer needed.) */
+                       current_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)) current_floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
                        }
                }
        }
@@ -1356,7 +1317,7 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
 
 
 /*
- * makes a lake/collapsed cave system in the center of the dungeon
+ * makes a lake/collapsed current_floor_ptr->grid_array system in the center of the dungeon
  */
 void build_lake(int type)
 {
@@ -1372,8 +1333,8 @@ void build_lake(int type)
        }
 
        /* Make the size of the dungeon */
-       xsize = cur_wid - 1;
-       ysize = cur_hgt - 1;
+       xsize = current_floor_ptr->width - 1;
+       ysize = current_floor_ptr->height - 1;
        x0 = xsize / 2;
        y0 = ysize / 2;
 
@@ -1409,65 +1370,13 @@ void build_lake(int type)
 #endif /* ALLOW_CAVERNS_AND_LAKES */
 
 
-/*
- * Routine used by the random vault creators to add a door to a location
- * Note that range checking has to be done in the calling routine.
- *
- * The doors must be INSIDE the allocated region.
- */
-static void add_door(int x, int y)
-{
-       /* Need to have a wall in the center square */
-       if (!is_outer_bold(y, x)) return;
-
-       /* look at:
-        *  x#x
-        *  .#.
-        *  x#x
-        *
-        *  where x=don't care
-        *  .=floor, #=wall
-        */
-
-       if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
-           (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
-       {
-               /* secret door */
-               place_secret_door(y, x, DOOR_DEFAULT);
-
-               /* set boundarys so don't get wide doors */
-               place_solid_bold(y, x - 1);
-               place_solid_bold(y, x + 1);
-       }
-
-
-       /* look at:
-        *  x#x
-        *  .#.
-        *  x#x
-        *
-        *  where x = don't care
-        *  .=floor, #=wall
-        */
-       if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
-           is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
-       {
-               /* secret door */
-               place_secret_door(y, x, DOOR_DEFAULT);
-
-               /* set boundarys so don't get wide doors */
-               place_solid_bold(y - 1, x);
-               place_solid_bold(y + 1, x);
-       }
-}
-
 
 /*
  * Routine that fills the empty areas of a room with treasure and monsters.
  */
-static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
+void fill_treasure(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:*/
@@ -1496,29 +1405,28 @@ static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
                                if (value < 0)
                                {
                                        /* Meanest monster + treasure */
-                                       monster_level = base_level + 40;
+                                       current_floor_ptr->monster_level = current_floor_ptr->base_level + 40;
                                        place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                       monster_level = base_level;
-                                       object_level = base_level + 20;
+                                       current_floor_ptr->monster_level = current_floor_ptr->base_level;
+                                       current_floor_ptr->object_level = current_floor_ptr->base_level + 20;
                                        place_object(y, x, AM_GOOD);
-                                       object_level = base_level;
+                                       current_floor_ptr->object_level = current_floor_ptr->base_level;
                                }
                                else if (value < 5)
                                {
                                        /* Mean monster +treasure */
-                                       monster_level = base_level + 20;
+                                       current_floor_ptr->monster_level = current_floor_ptr->base_level + 20;
                                        place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                       monster_level = base_level;
-                                       object_level = base_level + 10;
+                                       current_floor_ptr->monster_level = current_floor_ptr->base_level;
+                                       current_floor_ptr->object_level = current_floor_ptr->base_level + 10;
                                        place_object(y, x, AM_GOOD);
-                                       object_level = base_level;
+                                       current_floor_ptr->object_level = current_floor_ptr->base_level;
                                }
                                else if (value < 10)
                                {
-                                       /* Monster */
-                                       monster_level = base_level + 9;
+                                       current_floor_ptr->monster_level = current_floor_ptr->base_level + 9;
                                        place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                       monster_level = base_level;
+                                       current_floor_ptr->monster_level = current_floor_ptr->base_level;
                                }
                                else if (value < 17)
                                {
@@ -1546,9 +1454,9 @@ static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
                                else if (value < 30)
                                {
                                        /* Monster and trap */
-                                       monster_level = base_level + 5;
+                                       current_floor_ptr->monster_level = current_floor_ptr->base_level + 5;
                                        place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                       monster_level = base_level;
+                                       current_floor_ptr->monster_level = current_floor_ptr->base_level;
                                        place_trap(y, x);
                                }
                                else if (value < 40)
@@ -1556,15 +1464,15 @@ static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
                                        /* Monster or object */
                                        if (randint0(100) < 50)
                                        {
-                                               monster_level = base_level + 3;
+                                               current_floor_ptr->monster_level = current_floor_ptr->base_level + 3;
                                                place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                                               monster_level = base_level;
+                                               current_floor_ptr->monster_level = current_floor_ptr->base_level;
                                        }
                                        if (randint0(100) < 50)
                                        {
-                                               object_level = base_level + 7;
+                                               current_floor_ptr->object_level = current_floor_ptr->base_level + 7;
                                                place_object(y, x, 0L);
-                                               object_level = base_level;
+                                               current_floor_ptr->object_level = current_floor_ptr->base_level;
                                        }
                                }
                                else if (value < 50)
@@ -1597,148 +1505,6 @@ static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
 }
 
 
-/*
- * This function creates a random vault that looks like a collection of bubbles.
- * It works by getting a set of coordinates that represent the center of each
- * bubble.  The entire room is made by seeing which bubble center is closest. If
- * two centers are equidistant then the square is a wall, otherwise it is a floor.
- * The only exception is for squares really near a center, these are always floor.
- * (It looks better than without this check.)
- *
- * Note: If two centers are on the same point then this algorithm will create a
- *       blank bubble filled with walls. - This is prevented from happening.
- */
-static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
-{
-       #define BUBBLENUM 10            /* number of bubbles */
-
-       /* array of center points of bubbles */
-       coord center[BUBBLENUM];
-
-       int i, j, x, y;
-       u16b min1, min2, temp;
-       bool done;
-
-       /* Offset from center to top left hand corner */
-       int xhsize = xsize / 2;
-       int yhsize = ysize / 2;
-
-       msg_print_wizard(CHEAT_DUNGEON, _("泡型ランダムVaultを生成しました。", "Room Vault."));
-
-       /* Allocate center of bubbles */
-       center[0].x = (byte)randint1(xsize - 3) + 1;
-       center[0].y = (byte)randint1(ysize - 3) + 1;
-
-       for (i = 1; i < BUBBLENUM; i++)
-       {
-               done = FALSE;
-
-               /* get center and check to see if it is unique */
-               while (!done)
-               {
-                       done = TRUE;
-
-                       x = randint1(xsize - 3) + 1;
-                       y = randint1(ysize - 3) + 1;
-
-                       for (j = 0; j < i; j++)
-                       {
-                               /* rough test to see if there is an overlap */
-                               if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
-                       }
-               }
-
-               center[i].x = (byte_hack)x;
-               center[i].y = (byte_hack)y;
-       }
-
-
-       /* Top and bottom boundaries */
-       for (i = 0; i < xsize; i++)
-       {
-               int side_x = x0 - xhsize + i;
-
-               place_outer_noperm_bold(y0 - yhsize + 0, side_x);
-               cave[y0 - yhsize + 0][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
-               place_outer_noperm_bold(y0 - yhsize + ysize - 1, side_x);
-               cave[y0 - yhsize + ysize - 1][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
-       }
-
-       /* Left and right boundaries */
-       for (i = 1; i < ysize - 1; i++)
-       {
-               int side_y = y0 - yhsize + i;
-
-               place_outer_noperm_bold(side_y, x0 - xhsize + 0);
-               cave[side_y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
-               place_outer_noperm_bold(side_y, x0 - xhsize + xsize - 1);
-               cave[side_y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
-       }
-
-       /* Fill in middle with bubbles */
-       for (x = 1; x < xsize - 1; x++)
-       {
-               for (y = 1; y < ysize - 1; y++)
-               {
-                       /* Get distances to two closest centers */
-
-                       /* initialize */
-                       min1 = (u16b)distance(x, y, center[0].x, center[0].y);
-                       min2 = (u16b)distance(x, y, center[1].x, center[1].y);
-
-                       if (min1 > min2)
-                       {
-                               /* swap if in wrong order */
-                               temp = min1;
-                               min1 = min2;
-                               min2 = temp;
-                       }
-
-                       /* Scan the rest */
-                       for (i = 2; i < BUBBLENUM; i++)
-                       {
-                               temp = (u16b)distance(x, y, center[i].x, center[i].y);
-
-                               if (temp < min1)
-                               {
-                                       /* smallest */
-                                       min2 = min1;
-                                       min1 = temp;
-                               }
-                               else if (temp < min2)
-                               {
-                                       /* second smallest */
-                                       min2 = temp;
-                               }
-                       }
-                       if (((min2 - min1) <= 2) && (!(min1 < 3)))
-                       {
-                               /* Boundary at midpoint+ not at inner region of bubble */
-                               place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
-                       }
-                       else
-                       {
-                               /* middle of a bubble */
-                               place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
-                       }
-
-                       /* clean up rest of flags */
-                       cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
-               }
-       }
-
-       /* Try to add some random doors */
-       for (i = 0; i < 500; i++)
-       {
-               x = randint1(xsize - 3) - xhsize + x0 + 1;
-               y = randint1(ysize - 3) - yhsize + y0 + 1;
-               add_door(x, y);
-       }
-
-       /* Fill with monsters and treasure, low difficulty */
-       fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
-}
-
 
 /*
  * Overlay a rectangular room given its bounds
@@ -1746,14 +1512,14 @@ static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
  * The area inside the walls is not touched:
  * only granite is removed- normal walls stay
  */
-static void build_room(int x1, int x2, int y1, int y2)
+void build_room(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 */
@@ -1779,18 +1545,18 @@ static void build_room(int x1, int x2, int y1, int y2)
        for (i = 0; i <= xsize; i++)
        {
                place_outer_noperm_bold(y1, x1 + i);
-               cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
+               current_floor_ptr->grid_array[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
                place_outer_noperm_bold(y2, x1 + i);
-               cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
+               current_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);
+               current_floor_ptr->grid_array[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
                place_outer_noperm_bold(y1 + i, x2);
-               cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
+               current_floor_ptr->grid_array[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
        }
 
        /* Middle */
@@ -1802,115 +1568,18 @@ static void build_room(int x1, int x2, int y1, int y2)
                        {
                                /* clear the untouched region */
                                place_floor_bold(y1 + y, x1 + x);
-                               cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
+                               current_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);
+                               current_floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
                        }
                }
        }
 }
 
 
-/* Create a random vault that looks like a collection of overlapping rooms */
-
-static void build_room_vault(int x0, int y0, int xsize, int ysize)
-{
-       int i, x1, x2, y1, y2, xhsize, yhsize;
-
-       /* get offset from center */
-       xhsize = xsize / 2;
-       yhsize = ysize / 2;
-
-       msg_print_wizard(CHEAT_DUNGEON, _("部屋型ランダムVaultを生成しました。", "Room Vault."));
-
-       /* fill area so don't get problems with arena levels */
-       for (x1 = 0; x1 < xsize; x1++)
-       {
-               int x = x0 - xhsize + x1;
-
-               for (y1 = 0; y1 < ysize; y1++)
-               {
-                       int y = y0 - yhsize + y1;
-
-                       place_extra_bold(y, x);
-                       cave[y][x].info &= (~CAVE_ICKY);
-               }
-       }
-
-       /* add ten random rooms */
-       for (i = 0; i < 10; i++)
-       {
-               x1 = randint1(xhsize) * 2 + x0 - xhsize;
-               x2 = randint1(xhsize) * 2 + x0 - xhsize;
-               y1 = randint1(yhsize) * 2 + y0 - yhsize;
-               y2 = randint1(yhsize) * 2 + y0 - yhsize;
-               build_room(x1, x2, y1, y2);
-       }
-
-       /* Add some random doors */
-       for (i = 0; i < 500; i++)
-       {
-               x1 = randint1(xsize - 3) - xhsize + x0 + 1;
-               y1 = randint1(ysize - 3) - yhsize + y0 + 1;
-               add_door(x1, y1);
-       }
-
-       /* Fill with monsters and treasure, high difficulty */
-       fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
-}
-
-
-/* Create a random vault out of a fractal cave */
-static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
-{
-       int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
-       bool done, light, room;
-
-       /* round to make sizes even */
-       xhsize = xsiz / 2;
-       yhsize = ysiz / 2;
-       xsize = xhsize * 2;
-       ysize = yhsize * 2;
-
-       msg_print_wizard(CHEAT_DUNGEON, _("洞穴ランダムVaultを生成しました。", "Cave Vault."));
-
-       light = done = FALSE;
-       room = TRUE;
-
-       while (!done)
-       {
-               /* testing values for these parameters feel free to adjust */
-               grd = 1 << randint0(4);
-
-               /* want average of about 16 */
-               roug = randint1(8) * randint1(4);
-
-               /* about size/2 */
-               cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
-                        randint1(xsize / 4) + randint1(ysize / 4);
-
-               /* make it */
-               generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
-
-               /* Convert to normal format+ clean up */
-               done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
-       }
-
-       /* Set icky flag because is a vault */
-       for (x = 0; x <= xsize; x++)
-       {
-               for (y = 0; y <= ysize; y++)
-               {
-                       cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
-               }
-       }
-
-       /* Fill with monsters and treasure, low difficulty */
-       fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
-}
 
 /*
  * maze vault -- rectangular labyrinthine rooms
@@ -1930,8 +1599,7 @@ static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
  * is the randint0(3) below; it governs the relative density of
  * twists and turns in the labyrinth: smaller number, more twists.
  */
-static void r_visit(int y1, int x1, int y2, int x2,
-                   int node, int dir, int *visited)
+void r_visit(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
 {
        int i, j, m, n, temp, x, y, adj[4];
 
@@ -2015,18 +1683,18 @@ static void r_visit(int y1, int x1, int y2, int x2,
 }
 
 
-void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
+void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
 {
-       int y, x, dy, dx;
-       int y1, x1, y2, x2;
+       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 = ((current_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;
@@ -2042,22 +1710,22 @@ void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
        {
                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 = &current_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);
                }
        }
 
@@ -2079,131 +1747,6 @@ void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
 }
 
 
-/* Build a "mini" checkerboard vault
- *
- * This is done by making a permanent wall maze and setting
- * the diagonal sqaures of the checker board to be granite.
- * The vault has two entrances on opposite sides to guarantee
- * a way to get in even if the vault abuts a side of the dungeon.
- */
-static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
-{
-       int dy, dx;
-       int y1, x1, y2, x2, y, x, total;
-       int m, n, num_vertices;
-       int *visited;
-
-       msg_print_wizard(CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault."));
-
-       /* Pick a random room size */
-       dy = ysize / 2 - 1;
-       dx = xsize / 2 - 1;
-
-       y1 = y0 - dy;
-       x1 = x0 - dx;
-       y2 = y0 + dy;
-       x2 = x0 + dx;
-
-
-       /* generate the room */
-       for (x = x1 - 2; x <= x2 + 2; x++)
-       {
-               if (!in_bounds(y1-2,x)) break;
-
-               cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
-
-               place_outer_noperm_bold(y1-2, x);
-       }
-
-       for (x = x1 - 2; x <= x2 + 2; x++)
-       {
-               if (!in_bounds(y2+2,x)) break;
-
-               cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
-
-               place_outer_noperm_bold(y2+2, x);
-       }
-
-       for (y = y1 - 2; y <= y2 + 2; y++)
-       {
-               if (!in_bounds(y,x1-2)) break;
-
-               cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
-
-               place_outer_noperm_bold(y, x1-2);
-       }
-
-       for (y = y1 - 2; y <= y2 + 2; y++)
-       {
-               if (!in_bounds(y,x2+2)) break;
-
-               cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
-
-               place_outer_noperm_bold(y, x2+2);
-       }
-
-       for (y = y1 - 1; y <= y2 + 1; y++)
-       {
-               for (x = x1 - 1; x <= x2 + 1; x++)
-               {
-                       cave_type *c_ptr = &cave[y][x];
-
-                       c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
-
-                       /* Permanent walls */
-                       place_inner_perm_grid(c_ptr);
-               }
-       }
-
-
-       /* dimensions of vertex array */
-       m = dx + 1;
-       n = dy + 1;
-       num_vertices = m * n;
-
-       /* initialize array of visited vertices */
-       C_MAKE(visited, num_vertices, int);
-
-       /* traverse the graph to create a spannng tree, pick a random root */
-       r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
-
-       /* Make it look like a checker board vault */
-       for (x = x1; x <= x2; x++)
-       {
-               for (y = y1; y <= y2; y++)
-               {
-                       total = x - x1 + y - y1;
-                       /* If total is odd- and is a floor then make a wall */
-                       if ((total % 2 == 1) && is_floor_bold(y, x))
-                       {
-                               place_inner_bold(y, x);
-                       }
-               }
-       }
-
-       /* Make a couple of entrances */
-       if (one_in_(2))
-       {
-               /* left and right */
-               y = randint1(dy) + dy / 2;
-               place_inner_bold(y1 + y, x1 - 1);
-               place_inner_bold(y1 + y, x2 + 1);
-       }
-       else
-       {
-               /* top and bottom */
-               x = randint1(dx) + dx / 2;
-               place_inner_bold(y1 - 1, x1 + x);
-               place_inner_bold(y2 + 1, x1 + x);
-       }
-
-       /* Fill with monsters and treasure, highest difficulty */
-       fill_treasure(x1, x2, y1, y2, 10);
-
-       C_KILL(visited, num_vertices, int);
-}
-
-
 /* Build a town/ castle by using a recursive algorithm.
  * Basically divide each region in a probalistic way to create
  * smaller regions.  When the regions get too small stop.
@@ -2211,10 +1754,10 @@ static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
  * The power variable is a measure of how well defended a region is.
  * This alters the possible choices.
  */
-static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
+void build_recursive_room(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 */
@@ -2410,72 +1953,29 @@ static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
 }
 
 
-/* Build a castle */
-
-/* Driver routine: clear the region and call the recursive
-* room routine.
-*
-*This makes a vault that looks like a castle/ city in the dungeon.
-*/
-static void build_castle_vault(int x0, int y0, int xsize, int ysize)
-{
-       int dy, dx;
-       int y1, x1, y2, x2;
-       int y, x;
-
-       /* Pick a random room size */
-       dy = ysize / 2 - 1;
-       dx = xsize / 2 - 1;
-
-       y1 = y0 - dy;
-       x1 = x0 - dx;
-       y2 = y0 + dy;
-       x2 = x0 + dx;
-
-       msg_print_wizard(CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault"));
-
-       /* generate the room */
-       for (y = y1 - 1; y <= y2 + 1; y++)
-       {
-               for (x = x1 - 1; x <= x2 + 1; x++)
-               {
-                       cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
-                       /* Make everything a floor */
-                       place_floor_bold(y, x);
-               }
-       }
-
-       /* Make the castle */
-       build_recursive_room(x1, y1, x2, y2, randint1(5));
-
-       /* Fill with monsters and treasure, low difficulty */
-       fill_treasure(x1, x2, y1, y2, randint1(3));
-}
-
-
 /*
  * Add outer wall to a floored region
  * 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;
 
-       c_ptr = &cave[y][x];
+       g_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))
        {
@@ -2487,7 +1987,7 @@ 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;
                                }
                        }
                }
@@ -2496,12 +1996,12 @@ void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
        {
                /* Set bounding walls */
                place_outer_bold(y, x);
-               if (light) c_ptr->info |= CAVE_GLOW;
+               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;
        }
 }
 
@@ -2510,9 +2010,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);
 
@@ -2532,299 +2032,31 @@ int dist2(int x1, int y1, int x2, int y2, int h1, int h2, int h3, int h4)
 }
 
 
-/*
- * Build target vault.
- * This is made by two concentric "crypts" with perpendicular
- * walls creating the cross-hairs.
- */
-static void build_target_vault(int x0, int y0, int xsize, int ysize)
-{
-       int rad, x, y;
-
-       /* Make a random metric */
-       int h1, h2, h3, h4;
-       h1 = randint1(32) - 16;
-       h2 = randint1(16);
-       h3 = randint1(32);
-       h4 = randint1(32) - 16;
-
-       msg_print_wizard(CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Elemental Vault"));
-
-       /* work out outer radius */
-       if (xsize > ysize)
-       {
-               rad = ysize / 2;
-       }
-       else
-       {
-               rad = xsize / 2;
-       }
-
-       /* Make floor */
-       for (x = x0 - rad; x <= x0 + rad; x++)
-       {
-               for (y = y0 - rad; y <= y0 + rad; y++)
-               {
-                       /* clear room flag */
-                       cave[y][x].info &= ~(CAVE_ROOM);
-
-                       /* Vault - so is "icky" */
-                       cave[y][x].info |= CAVE_ICKY;
-
-                       if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
-                       {
-                               /* inside- so is floor */
-                               place_floor_bold(y, x);
-                       }
-                       else
-                       {
-                               /* make granite outside so arena works */
-                               place_extra_bold(y, x);
-                       }
-
-                       /* proper boundary for arena */
-                       if (((y + rad) == y0) || ((y - rad) == y0) ||
-                           ((x + rad) == x0) || ((x - rad) == x0))
-                       {
-                               place_extra_bold(y, x);
-                       }
-               }
-       }
-
-       /* Find visible outer walls and set to be FEAT_OUTER */
-       add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
-                      x0 + rad + 1, y0 + rad + 1);
-
-       /* Add inner wall */
-       for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
-       {
-               for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
-               {
-                       if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
-                       {
-                               /* Make an internal wall */
-                               place_inner_bold(y, x);
-                       }
-               }
-       }
-
-       /* Add perpendicular walls */
-       for (x = x0 - rad; x <= x0 + rad; x++)
-       {
-               place_inner_bold(y0, x);
-       }
-
-       for (y = y0 - rad; y <= y0 + rad; y++)
-       {
-               place_inner_bold(y, x0);
-       }
-
-       /* Make inner vault */
-       for (y = y0 - 1; y <= y0 + 1; y++)
-       {
-               place_inner_bold(y, x0 - 1);
-               place_inner_bold(y, x0 + 1);
-       }
-       for (x = x0 - 1; x <= x0 + 1; x++)
-       {
-               place_inner_bold(y0 - 1, x);
-               place_inner_bold(y0 + 1, x);
-       }
-
-       place_floor_bold(y0, x0);
-
-
-       /* Add doors to vault */
-       /* get two distances so can place doors relative to centre */
-       x = (rad - 2) / 4 + 1;
-       y = rad / 2 + x;
-
-       add_door(x0 + x, y0);
-       add_door(x0 + y, y0);
-       add_door(x0 - x, y0);
-       add_door(x0 - y, y0);
-       add_door(x0, y0 + x);
-       add_door(x0, y0 + y);
-       add_door(x0, y0 - x);
-       add_door(x0, y0 - y);
-
-       /* Fill with stuff - medium difficulty */
-       fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
-}
-
-
-#ifdef ALLOW_CAVERNS_AND_LAKES
-/*
- * This routine uses a modified version of the lake code to make a
- * distribution of some terrain type over the vault.  This type
- * depends on the dungeon depth.
- *
- * Miniture rooms are then scattered across the vault.
- */
-static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
-{
-       int grd, roug;
-       int c1, c2, c3;
-       bool done = FALSE;
-       int xsize, ysize, xhsize, yhsize, x, y, i;
-       int type;
-
-       msg_print_wizard(CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault"));
-
-       /* round to make sizes even */
-       xhsize = xsiz / 2;
-       yhsize = ysiz / 2;
-       xsize = xhsize * 2;
-       ysize = yhsize * 2;
-
-       if (dun_level < 25)
-       {
-               /* Earth vault  (Rubble) */
-               type = LAKE_T_EARTH_VAULT;
-       }
-       else if (dun_level < 50)
-       {
-               /* Air vault (Trees) */
-               type = LAKE_T_AIR_VAULT;
-       }
-       else if (dun_level < 75)
-       {
-               /* Water vault (shallow water) */
-               type = LAKE_T_WATER_VAULT;
-       }
-       else
-       {
-               /* Fire vault (shallow lava) */
-               type = LAKE_T_FIRE_VAULT;
-       }
-
-       while (!done)
-       {
-               /* testing values for these parameters: feel free to adjust */
-               grd = 1 << (randint0(3));
-
-               /* want average of about 16 */
-               roug = randint1(8) * randint1(4);
-
-               /* Make up size of various componants */
-               /* Floor */
-               c3 = 2 * xsize / 3;
-
-               /* Deep water/lava */
-               c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
-
-               /* Shallow boundary */
-               c2 = (c1 + c3) / 2;
-
-               /* make it */
-               generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
-
-               /* Convert to normal format+ clean up */
-               done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
-       }
-
-       /* Set icky flag because is a vault */
-       for (x = 0; x <= xsize; x++)
-       {
-               for (y = 0; y <= ysize; y++)
-               {
-                       cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
-               }
-       }
-
-       /* make a few rooms in the vault */
-       for (i = 1; i <= (xsize * ysize) / 50; i++)
-       {
-               build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
-                                y0 + randint0(ysize - 4) - ysize / 2 + 2);
-       }
-
-       /* Fill with monsters and treasure, low difficulty */
-       fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
-                     y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
-}
-#endif /* ALLOW_CAVERNS_AND_LAKES */
-
-
-/*!
- * @brief タイプ10の部屋…ランダム生成vault / Type 10 -- Random vaults
- * @return なし
- */
-static bool build_type10(void)
-{
-       POSITION y0, x0, xsize, ysize, vtype;
-
-       /* Get size */
-       /* big enough to look good, small enough to be fairly common. */
-       xsize = randint1(22) + 22;
-       ysize = randint1(11) + 11;
-
-       /* Find and reserve some space in the dungeon.  Get center of room. */
-       if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
-
-       /* Select type of vault */
-#ifdef ALLOW_CAVERNS_AND_LAKES
-       do
-       {
-               vtype = randint1(15);
-       }
-       while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
-               ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
-#else /* ALLOW_CAVERNS_AND_LAKES */
-       do
-       {
-               vtype = randint1(7);
-       }
-       while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
-               ((vtype == 1) || (vtype == 3)));
-#endif /* ALLOW_CAVERNS_AND_LAKES */
-
-       switch (vtype)
-       {
-               /* Build an appropriate room */
-               case 1: case  9: build_bubble_vault(x0, y0, xsize, ysize); break;
-               case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
-               case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
-               case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
-               case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
-               case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
-               case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
-#ifdef ALLOW_CAVERNS_AND_LAKES
-               case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
-#endif /* ALLOW_CAVERNS_AND_LAKES */
-               /* I know how to add a few more... give me some time. */
-
-               /* Paranoia */
-               default: return FALSE;
-       }
-
-       return TRUE;
-}
 
 
 /* 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 = &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++)
        {
@@ -2843,7 +2075,7 @@ 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(EFFECT_ID typ)
 {
        /* Build a room */
        switch (typ)
@@ -2865,9 +2097,8 @@ static bool room_build(int typ)
        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 */
        return FALSE;
 }
 
@@ -2890,8 +2121,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 * (current_floor_ptr->height*current_floor_ptr->width) / (MAX_HGT*MAX_WID);
+       int level_index = MIN(10, div_round(current_floor_ptr->dun_level, 10));
 
        /* Number of each type of room on this level */
        s16b room_num[ROOM_T_MAX];
@@ -2899,7 +2130,7 @@ bool generate_rooms(void)
        /* Limit number of rooms */
        int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
 
-       /* Assume normal cave */
+       /* Assume normal current_floor_ptr->grid_array */
        room_info_type *room_info_ptr = room_info_normal;
 
        /*
@@ -2908,7 +2139,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 (current_floor_ptr->dun_level < room_info_ptr[i].min_level)
                {
                        prob_list[i] = 0;
                }
@@ -2922,8 +2153,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++)
                {
@@ -2933,23 +2166,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 current_floor_ptr->grid_array etc.) */
+       else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CAVE)
        {
                MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
        }
@@ -2961,13 +2200,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;
        }
@@ -2997,8 +2236,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. */