OSDN Git Service

[Refactor] #37353 ファイル名修正。
[hengband/hengband.git] / src / rooms.c
index cfe0caa..361cb25 100644 (file)
@@ -41,6 +41,8 @@
 #include "grid.h"
 #include "rooms.h"
 
+#include "rooms-normal.h"
+
 
 /*!
  * 各部屋タイプの生成比定義
@@ -108,7 +110,7 @@ static byte room_build_order[ROOM_T_MAX] = {
  * @param x 配置したいフロアのX座標
  * @return なし
  */
-static void place_locked_door(int y, int x)
+void place_locked_door(int y, int x)
 {
        if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
        {
@@ -126,10 +128,10 @@ static void place_locked_door(int y, int x)
  * @brief 隠しドアを配置する
  * @param y 配置したいフロアのY座標
  * @param x 配置したいフロアのX座標
- * @param type #DOOR_DEFAULT / #DOOR_DOOR / #DOOR_GLASS_DOOR / #DOOR_CURTAIN のいずれか
+ * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
  * @return なし
  */
-static void place_secret_door(int y, int x, int type)
+void place_secret_door(int y, int x, int type)
 {
        if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
        {
@@ -361,1057 +363,161 @@ static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int bl
 
        /* Never run off the screen */
        if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
-       if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
-       
-       /* Verify available space */
-       for (by = by1; by < by2; by++)
-       {
-               for (bx = bx1; bx < bx2; bx++)
-               {
-                       if (dun->room_map[by][bx])
-                       {
-                               return FALSE;
-                       }
-               }
-       }
-
-       /* This location is okay */
-       return TRUE;
-}
-
-
-/*!
- * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room.  -LM-
- * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
- * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
- * @param height 確保したい領域の高さ
- * @param width 確保したい領域の幅
- * @return 所定の範囲が確保できた場合TRUEを返す
- * @details
- * Find and allocate a free space in the dungeon large enough to hold\n
- * the room calling this function.\n
- *\n
- * We allocate space in 11x11 blocks, but want to make sure that rooms\n
- * align neatly on the standard screen.  Therefore, we make them use\n
- * blocks in few 11x33 rectangles as possible.\n
- *\n
- * Be careful to include the edges of the room in height and width!\n
- *\n
- * Return TRUE and values for the center of the room if all went well.\n
- * Otherwise, return FALSE.\n
- */
-static bool find_space(int *y, int *x, int height, int width)
-{
-       int candidates, pick;
-       int by, bx, by1, bx1, by2, bx2;
-       int 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);
-
-       /* There are no way to allocate such huge space */
-       if (dun->row_rooms < blocks_high) return FALSE;
-       if (dun->col_rooms < blocks_wide) return FALSE;
-
-       /* Initiallize */
-       candidates = 0;
-
-       /* Count the number of valid places */
-       for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
-       {
-               for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
-               {
-                       if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
-                       {
-                               /* Find a valid place */
-                               candidates++;
-                       }
-               }
-       }
-
-       /* No place! */
-       if (!candidates)
-       {
-               return FALSE;
-       }
-
-       /* Normal dungeon */
-       if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
-       {
-               /* Choose a random one */
-               pick = randint1(candidates);
-       }
-
-       /* NO_CAVE dungeon (Castle) */
-       else
-       {
-               /* Always choose the center one */
-               pick = candidates/2 + 1;
-       }
-
-       /* Pick up the choosen location */
-       for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
-       {
-               for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
-               {
-                       if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
-                       {
-                               pick--;
-
-                               /* This one is picked? */
-                               if (!pick) break;
-                       }
-               }
-
-               if (!pick) break;
-       }
-
-       /* Extract blocks */
-       by1 = block_y + 0;
-       bx1 = block_x + 0;
-       by2 = block_y + blocks_high;
-       bx2 = block_x + blocks_wide;
-
-       /*
-        * It is *extremely* important that the following calculation
-        * be *exactly* correct to prevent memory errors
-        */
-
-       /* Acquire the location of the room */
-       (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
-       (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
-
-       /* Save the room location */
-       if (dun->cent_n < CENT_MAX)
-       {
-               dun->cent[dun->cent_n].y = *y;
-               dun->cent[dun->cent_n].x = *x;
-               dun->cent_n++;
-       }
-
-       /* Reserve some blocks. */
-       for (by = by1; by < by2; by++)
-       {
-               for (bx = bx1; bx < bx2; bx++)
-               {
-                       dun->room_map[by][bx] = TRUE;
-               }
-       }
-
-
-       /*
-        * Hack- See if room will cut off a cavern.
-        *
-        * If so, fix by tunneling outside the room in such a
-        * way as to connect the caves.
-        */
-       check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
-
-
-       /* Success. */
-       return TRUE;
-}
-
-
-/*!
- * @brief タイプ1の部屋…通常可変長方形の部屋を生成する / Type 1 -- normal rectangular rooms
- * @return なし
- */
-static bool build_type1(void)
-{
-       int y, x, y2, x2, yval, xval;
-       int y1, x1, xsize, ysize;
-
-       bool light;
-
-       cave_type *c_ptr;
-
-       bool curtain = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
-               one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 48 : 512);
-
-       /* Pick a room size */
-       y1 = randint1(4);
-       x1 = randint1(11);
-       y2 = randint1(3);
-       x2 = randint1(11);
-
-       xsize = x1 + x2 + 1;
-       ysize = y1 + y2 + 1;
-
-       /* Find and reserve some space in the dungeon.  Get center of room. */
-       if (!find_space(&yval, &xval, ysize + 2, xsize + 2))
-       {
-               /* Limit to the minimum room size, and retry */
-               y1 = 1;
-               x1 = 1;
-               y2 = 1;
-               x2 = 1;
-
-               xsize = x1 + x2 + 1;
-               ysize = y1 + y2 + 1;
-
-               /* Find and reserve some space in the dungeon.  Get center of room. */
-               if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
-       }
-
-       /* Choose lite or dark */
-       light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
-
-
-       /* Get corner values */
-       y1 = yval - ysize / 2;
-       x1 = xval - xsize / 2;
-       y2 = yval + (ysize - 1) / 2;
-       x2 = xval + (xsize - 1) / 2;
-
-
-       /* Place a full floor under the room */
-       for (y = y1 - 1; y <= y2 + 1; y++)
-       {
-               for (x = x1 - 1; x <= x2 + 1; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-                       c_ptr->info |= (CAVE_ROOM);
-                       if (light) c_ptr->info |= (CAVE_GLOW);
-               }
-       }
-
-       /* Walls around the room */
-       for (y = y1 - 1; y <= y2 + 1; y++)
-       {
-               c_ptr = &cave[y][x1 - 1];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y][x2 + 1];
-               place_outer_grid(c_ptr);
-       }
-       for (x = x1 - 1; x <= x2 + 1; x++)
-       {
-               c_ptr = &cave[y1 - 1][x];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y2 + 1][x];
-               place_outer_grid(c_ptr);
-       }
-
-
-       /* Hack -- Occasional curtained room */
-       if (curtain && (y2 - y1 > 2) && (x2 - x1 > 2))
-       {
-               for (y = y1; y <= y2; y++)
-               {
-                       c_ptr = &cave[y][x1];
-                       c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
-                       c_ptr->info &= ~(CAVE_MASK);
-                       c_ptr = &cave[y][x2];
-                       c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
-                       c_ptr->info &= ~(CAVE_MASK);
-               }
-               for (x = x1; x <= x2; x++)
-               {
-                       c_ptr = &cave[y1][x];
-                       c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
-                       c_ptr->info &= ~(CAVE_MASK);
-                       c_ptr = &cave[y2][x];
-                       c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
-                       c_ptr->info &= ~(CAVE_MASK);
-               }
-       }
-
-
-       /* Hack -- Occasional pillar room */
-       if (one_in_(20))
-       {
-               for (y = y1; y <= y2; y += 2)
-               {
-                       for (x = x1; x <= x2; x += 2)
-                       {
-                               c_ptr = &cave[y][x];
-                               place_inner_grid(c_ptr);
-                       }
-               }
-       }
-
-       /* Hack -- Occasional room with four pillars */
-       else if (one_in_(20))
-       {
-               if ((y1 + 4 < y2) && (x1 + 4 < x2))
-               {
-                       c_ptr = &cave[y1 + 1][x1 + 1];
-                       place_inner_grid(c_ptr);
-
-                       c_ptr = &cave[y1 + 1][x2 - 1];
-                       place_inner_grid(c_ptr);
-
-                       c_ptr = &cave[y2 - 1][x1 + 1];
-                       place_inner_grid(c_ptr);
-
-                       c_ptr = &cave[y2 - 1][x2 - 1];
-                       place_inner_grid(c_ptr);
-               }
-       }
-
-       /* Hack -- Occasional ragged-edge room */
-       else if (one_in_(50))
-       {
-               for (y = y1 + 2; y <= y2 - 2; y += 2)
-               {
-                       c_ptr = &cave[y][x1];
-                       place_inner_grid(c_ptr);
-                       c_ptr = &cave[y][x2];
-                       place_inner_grid(c_ptr);
-               }
-               for (x = x1 + 2; x <= x2 - 2; x += 2)
-               {
-                       c_ptr = &cave[y1][x];
-                       place_inner_grid(c_ptr);
-                       c_ptr = &cave[y2][x];
-                       place_inner_grid(c_ptr);
-               }
-       }
-       /* Hack -- Occasional divided room */
-       else if (one_in_(50))
-       {
-               bool curtain2 = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
-                       one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 2 : 128);
-
-               if (randint1(100) < 50)
-               {
-                       /* Horizontal wall */
-                       for (x = x1; x <= x2; x++)
-                       {
-                               place_inner_bold(yval, x);
-                               if (curtain2) cave[yval][x].feat = feat_door[DOOR_CURTAIN].closed;
-                       }
-
-                       /* Prevent edge of wall from being tunneled */
-                       place_solid_bold(yval, x1 - 1);
-                       place_solid_bold(yval, x2 + 1);
-               }
-               else
-               {
-                       /* Vertical wall */
-                       for (y = y1; y <= y2; y++)
-                       {
-                               place_inner_bold(y, xval);
-                               if (curtain2) cave[y][xval].feat = feat_door[DOOR_CURTAIN].closed;
-                       }
-
-                       /* Prevent edge of wall from being tunneled */
-                       place_solid_bold(y1 - 1, xval);
-                       place_solid_bold(y2 + 1, xval);
-               }
-
-               place_random_door(yval, xval, TRUE);
-               if (curtain2) cave[yval][xval].feat = feat_door[DOOR_CURTAIN].closed;
-       }
-
-       return TRUE;
-}
-
-/*!
- * @brief タイプ2の部屋…二重長方形の部屋を生成する / Type 2 -- Overlapping rectangular rooms
- * @return なし
- */
-static bool build_type2(void)
-{
-       int                     y, x, xval, yval;
-       int                     y1a, x1a, y2a, x2a;
-       int                     y1b, x1b, y2b, x2b;
-       bool            light;
-       cave_type   *c_ptr;
-
-       /* Find and reserve some space in the dungeon.  Get center of room. */
-       if (!find_space(&yval, &xval, 11, 25)) return FALSE;
-
-       /* Choose lite or dark */
-       light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
-
-       /* Determine extents of the first room */
-       y1a = yval - randint1(4);
-       y2a = yval + randint1(3);
-       x1a = xval - randint1(11);
-       x2a = xval + randint1(10);
-
-       /* Determine extents of the second room */
-       y1b = yval - randint1(3);
-       y2b = yval + randint1(4);
-       x1b = xval - randint1(10);
-       x2b = xval + randint1(11);
-
-
-       /* Place a full floor for room "a" */
-       for (y = y1a - 1; y <= y2a + 1; y++)
-       {
-               for (x = x1a - 1; x <= x2a + 1; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-                       c_ptr->info |= (CAVE_ROOM);
-                       if (light) c_ptr->info |= (CAVE_GLOW);
-               }
-       }
-
-       /* Place a full floor for room "b" */
-       for (y = y1b - 1; y <= y2b + 1; y++)
-       {
-               for (x = x1b - 1; x <= x2b + 1; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-                       c_ptr->info |= (CAVE_ROOM);
-                       if (light) c_ptr->info |= (CAVE_GLOW);
-               }
-       }
-
-
-       /* Place the walls around room "a" */
-       for (y = y1a - 1; y <= y2a + 1; y++)
-       {
-               c_ptr = &cave[y][x1a - 1];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y][x2a + 1];
-               place_outer_grid(c_ptr);
-       }
-       for (x = x1a - 1; x <= x2a + 1; x++)
-       {
-               c_ptr = &cave[y1a - 1][x];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y2a + 1][x];
-               place_outer_grid(c_ptr);
-       }
-
-       /* Place the walls around room "b" */
-       for (y = y1b - 1; y <= y2b + 1; y++)
-       {
-               c_ptr = &cave[y][x1b - 1];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y][x2b + 1];
-               place_outer_grid(c_ptr);
-       }
-       for (x = x1b - 1; x <= x2b + 1; x++)
-       {
-               c_ptr = &cave[y1b - 1][x];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y2b + 1][x];
-               place_outer_grid(c_ptr);
-       }
-
-
-
-       /* Replace the floor for room "a" */
-       for (y = y1a; y <= y2a; y++)
-       {
-               for (x = x1a; x <= x2a; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-               }
-       }
-
-       /* Replace the floor for room "b" */
-       for (y = y1b; y <= y2b; y++)
-       {
-               for (x = x1b; x <= x2b; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-               }
-       }
-
-       return TRUE;
-}
-
-
-
-/*!
- * @brief タイプ2の部屋…十字型の部屋を生成する / Type 3 -- Cross shaped rooms
- * @return なし
- * @details
- * Builds a room at a row, column coordinate\n
- *\n
- * Room "a" runs north/south, and Room "b" runs east/east\n
- * So the "central pillar" runs from x1a, y1b to x2a, y2b.\n
- *\n
- * Note that currently, the "center" is always 3x3, but I think that\n
- * the code below will work (with "bounds checking") for 5x5, or even\n
- * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.\n
- */
-static bool build_type3(void)
-{
-       int                     y, x, dy, dx, wy, wx;
-       int                     y1a, x1a, y2a, x2a;
-       int                     y1b, x1b, y2b, x2b;
-       int                     yval, xval;
-       bool            light;
-       cave_type   *c_ptr;
-
-
-       /* Find and reserve some space in the dungeon.  Get center of room. */
-       if (!find_space(&yval, &xval, 11, 25)) return FALSE;
-
-
-       /* Choose lite or dark */
-       light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
-
-       /* For now, always 3x3 */
-       wx = wy = 1;
-
-       /* Pick max vertical size (at most 4) */
-       dy = rand_range(3, 4);
-
-       /* Pick max horizontal size (at most 15) */
-       dx = rand_range(3, 11);
-
-
-       /* Determine extents of the north/south room */
-       y1a = yval - dy;
-       y2a = yval + dy;
-       x1a = xval - wx;
-       x2a = xval + wx;
-
-       /* Determine extents of the east/west room */
-       y1b = yval - wy;
-       y2b = yval + wy;
-       x1b = xval - dx;
-       x2b = xval + dx;
-
-
-       /* Place a full floor for room "a" */
-       for (y = y1a - 1; y <= y2a + 1; y++)
-       {
-               for (x = x1a - 1; x <= x2a + 1; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-                       c_ptr->info |= (CAVE_ROOM);
-                       if (light) c_ptr->info |= (CAVE_GLOW);
-               }
-       }
-
-       /* Place a full floor for room "b" */
-       for (y = y1b - 1; y <= y2b + 1; y++)
-       {
-               for (x = x1b - 1; x <= x2b + 1; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-                       c_ptr->info |= (CAVE_ROOM);
-                       if (light) c_ptr->info |= (CAVE_GLOW);
-               }
-       }
-
-
-       /* Place the walls around room "a" */
-       for (y = y1a - 1; y <= y2a + 1; y++)
-       {
-               c_ptr = &cave[y][x1a - 1];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y][x2a + 1];
-               place_outer_grid(c_ptr);
-       }
-       for (x = x1a - 1; x <= x2a + 1; x++)
-       {
-               c_ptr = &cave[y1a - 1][x];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y2a + 1][x];
-               place_outer_grid(c_ptr);
-       }
-
-       /* Place the walls around room "b" */
-       for (y = y1b - 1; y <= y2b + 1; y++)
-       {
-               c_ptr = &cave[y][x1b - 1];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y][x2b + 1];
-               place_outer_grid(c_ptr);
-       }
-       for (x = x1b - 1; x <= x2b + 1; x++)
-       {
-               c_ptr = &cave[y1b - 1][x];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y2b + 1][x];
-               place_outer_grid(c_ptr);
-       }
-
-
-       /* Replace the floor for room "a" */
-       for (y = y1a; y <= y2a; y++)
-       {
-               for (x = x1a; x <= x2a; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-               }
-       }
-
-       /* Replace the floor for room "b" */
-       for (y = y1b; y <= y2b; y++)
-       {
-               for (x = x1b; x <= x2b; x++)
-               {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-               }
-       }
-
-
-
-       /* Special features (3/4) */
-       switch (randint0(4))
-       {
-               /* Large solid middle pillar */
-               case 1:
-               {
-                       for (y = y1b; y <= y2b; y++)
-                       {
-                               for (x = x1a; x <= x2a; x++)
-                               {
-                                       c_ptr = &cave[y][x];
-                                       place_inner_grid(c_ptr);
-                               }
-                       }
-                       break;
-               }
-
-               /* Inner treasure vault */
-               case 2:
-               {
-                       /* Build the vault */
-                       for (y = y1b; y <= y2b; y++)
-                       {
-                               c_ptr = &cave[y][x1a];
-                               place_inner_grid(c_ptr);
-                               c_ptr = &cave[y][x2a];
-                               place_inner_grid(c_ptr);
-                       }
-                       for (x = x1a; x <= x2a; x++)
-                       {
-                               c_ptr = &cave[y1b][x];
-                               place_inner_grid(c_ptr);
-                               c_ptr = &cave[y2b][x];
-                               place_inner_grid(c_ptr);
-                       }
-
-                       /* Place a secret door on the inner room */
-                       switch (randint0(4))
-                       {
-                               case 0: place_secret_door(y1b, xval, DOOR_DEFAULT); break;
-                               case 1: place_secret_door(y2b, xval, DOOR_DEFAULT); break;
-                               case 2: place_secret_door(yval, x1a, DOOR_DEFAULT); break;
-                               case 3: place_secret_door(yval, x2a, DOOR_DEFAULT); break;
-                       }
-
-                       /* Place a treasure in the vault */
-                       place_object(yval, xval, 0L);
-
-                       /* Let's guard the treasure well */
-                       vault_monsters(yval, xval, randint0(2) + 3);
-
-                       /* Traps naturally */
-                       vault_traps(yval, xval, 4, 4, randint0(3) + 2);
-
-                       break;
-               }
-
-               /* Something else */
-               case 3:
-               {
-                       /* Occasionally pinch the center shut */
-                       if (one_in_(3))
-                       {
-                               /* Pinch the east/west sides */
-                               for (y = y1b; y <= y2b; y++)
-                               {
-                                       if (y == yval) continue;
-                                       c_ptr = &cave[y][x1a - 1];
-                                       place_inner_grid(c_ptr);
-                                       c_ptr = &cave[y][x2a + 1];
-                                       place_inner_grid(c_ptr);
-                               }
-
-                               /* Pinch the north/south sides */
-                               for (x = x1a; x <= x2a; x++)
-                               {
-                                       if (x == xval) continue;
-                                       c_ptr = &cave[y1b - 1][x];
-                                       place_inner_grid(c_ptr);
-                                       c_ptr = &cave[y2b + 1][x];
-                                       place_inner_grid(c_ptr);
-                               }
-
-                               /* Sometimes shut using secret doors */
-                               if (one_in_(3))
-                               {
-                                       int door_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);
-
-                                       place_secret_door(yval, x1a - 1, door_type);
-                                       place_secret_door(yval, x2a + 1, door_type);
-                                       place_secret_door(y1b - 1, xval, door_type);
-                                       place_secret_door(y2b + 1, xval, door_type);
-                               }
-                       }
-
-                       /* Occasionally put a "plus" in the center */
-                       else if (one_in_(3))
-                       {
-                               c_ptr = &cave[yval][xval];
-                               place_inner_grid(c_ptr);
-                               c_ptr = &cave[y1b][xval];
-                               place_inner_grid(c_ptr);
-                               c_ptr = &cave[y2b][xval];
-                               place_inner_grid(c_ptr);
-                               c_ptr = &cave[yval][x1a];
-                               place_inner_grid(c_ptr);
-                               c_ptr = &cave[yval][x2a];
-                               place_inner_grid(c_ptr);
-                       }
-
-                       /* Occasionally put a pillar in the center */
-                       else if (one_in_(3))
+       if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
+       
+       /* Verify available space */
+       for (by = by1; by < by2; by++)
+       {
+               for (bx = bx1; bx < bx2; bx++)
+               {
+                       if (dun->room_map[by][bx])
                        {
-                               c_ptr = &cave[yval][xval];
-                               place_inner_grid(c_ptr);
+                               return FALSE;
                        }
-
-                       break;
                }
        }
 
+       /* This location is okay */
        return TRUE;
 }
 
 
 /*!
- * @brief タイプ4の部屋…固定サイズの二重構造部屋を生成する / Type 4 -- Large room with inner features
- * @return なし
+ * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room.  -LM-
+ * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
+ * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
+ * @param height 確保したい領域の高さ
+ * @param width 確保したい領域の幅
+ * @return 所定の範囲が確保できた場合TRUEを返す
  * @details
- * Possible sub-types:\n
- *     1 - Just an inner room with one door\n
- *     2 - An inner room within an inner room\n
- *     3 - An inner room with pillar(s)\n
- *     4 - Inner room has a maze\n
- *     5 - A set of four inner rooms\n
+ * Find and allocate a free space in the dungeon large enough to hold\n
+ * the room calling this function.\n
+ *\n
+ * We allocate space in 11x11 blocks, but want to make sure that rooms\n
+ * align neatly on the standard screen.  Therefore, we make them use\n
+ * blocks in few 11x33 rectangles as possible.\n
+ *\n
+ * Be careful to include the edges of the room in height and width!\n
+ *\n
+ * Return TRUE and values for the center of the room if all went well.\n
+ * Otherwise, return FALSE.\n
  */
-static bool build_type4(void)
+bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
 {
-       int         y, x, y1, x1;
-       int         y2, x2, tmp, yval, xval;
-       bool        light;
-       cave_type   *c_ptr;
+       int candidates, pick;
+       int by, bx, by1, bx1, by2, bx2;
+       int block_y = 0, block_x = 0;
 
 
-       /* Find and reserve some space in the dungeon.  Get center of room. */
-       if (!find_space(&yval, &xval, 11, 25)) return FALSE;
+       /* Find out how many blocks we need. */
+       int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
+       int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
 
-       /* Choose lite or dark */
-       light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
+       /* There are no way to allocate such huge space */
+       if (dun->row_rooms < blocks_high) return FALSE;
+       if (dun->col_rooms < blocks_wide) return FALSE;
 
-       /* Large room */
-       y1 = yval - 4;
-       y2 = yval + 4;
-       x1 = xval - 11;
-       x2 = xval + 11;
+       /* Initiallize */
+       candidates = 0;
 
-       /* Place a full floor under the room */
-       for (y = y1 - 1; y <= y2 + 1; y++)
+       /* Count the number of valid places */
+       for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
        {
-               for (x = x1 - 1; x <= x2 + 1; x++)
+               for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
                {
-                       c_ptr = &cave[y][x];
-                       place_floor_grid(c_ptr);
-                       c_ptr->info |= (CAVE_ROOM);
-                       if (light) c_ptr->info |= (CAVE_GLOW);
+                       if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
+                       {
+                               /* Find a valid place */
+                               candidates++;
+                       }
                }
        }
 
-       /* Outer Walls */
-       for (y = y1 - 1; y <= y2 + 1; y++)
-       {
-               c_ptr = &cave[y][x1 - 1];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y][x2 + 1];
-               place_outer_grid(c_ptr);
-       }
-       for (x = x1 - 1; x <= x2 + 1; x++)
+       /* No place! */
+       if (!candidates)
        {
-               c_ptr = &cave[y1 - 1][x];
-               place_outer_grid(c_ptr);
-               c_ptr = &cave[y2 + 1][x];
-               place_outer_grid(c_ptr);
+               return FALSE;
        }
 
-
-       /* The inner room */
-       y1 = y1 + 2;
-       y2 = y2 - 2;
-       x1 = x1 + 2;
-       x2 = x2 - 2;
-
-       /* The inner walls */
-       for (y = y1 - 1; y <= y2 + 1; y++)
+       /* Normal dungeon */
+       if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
        {
-               c_ptr = &cave[y][x1 - 1];
-               place_inner_grid(c_ptr);
-               c_ptr = &cave[y][x2 + 1];
-               place_inner_grid(c_ptr);
+               /* Choose a random one */
+               pick = randint1(candidates);
        }
-       for (x = x1 - 1; x <= x2 + 1; x++)
+
+       /* NO_CAVE dungeon (Castle) */
+       else
        {
-               c_ptr = &cave[y1 - 1][x];
-               place_inner_grid(c_ptr);
-               c_ptr = &cave[y2 + 1][x];
-               place_inner_grid(c_ptr);
+               /* Always choose the center one */
+               pick = candidates/2 + 1;
        }
 
-
-       /* Inner room variations */
-       switch (randint1(5))
+       /* Pick up the choosen location */
+       for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
        {
-               /* Just an inner room with a monster */
-               case 1:
-               {
-                       /* Place a secret door */
-                       switch (randint1(4))
-                       {
-                               case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
-                               case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
-                               case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
-                               case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
-                       }
-
-                       /* Place a monster in the room */
-                       vault_monsters(yval, xval, 1);
-
-                       break;
-               }
-
-               /* Treasure Vault (with a door) */
-               case 2:
+               for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
                {
-                       /* Place a secret door */
-                       switch (randint1(4))
-                       {
-                               case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
-                               case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
-                               case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
-                               case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
-                       }
-
-                       /* Place another inner room */
-                       for (y = yval - 1; y <= yval + 1; y++)
-                       {
-                               for (x = xval -  1; x <= xval + 1; x++)
-                               {
-                                       if ((x == xval) && (y == yval)) continue;
-                                       c_ptr = &cave[y][x];
-                                       place_inner_grid(c_ptr);
-                               }
-                       }
-
-                       /* Place a locked door on the inner room */
-                       switch (randint1(4))
-                       {
-                               case 1: place_locked_door(yval - 1, xval); break;
-                               case 2: place_locked_door(yval + 1, xval); break;
-                               case 3: place_locked_door(yval, xval - 1); break;
-                               case 4: place_locked_door(yval, xval + 1); break;
-                       }
-
-                       /* Monsters to guard the "treasure" */
-                       vault_monsters(yval, xval, randint1(3) + 2);
-
-                       /* Object (80%) */
-                       if (randint0(100) < 80)
+                       if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
                        {
-                               place_object(yval, xval, 0L);
-                       }
+                               pick--;
 
-                       /* Stairs (20%) */
-                       else
-                       {
-                               place_random_stairs(yval, xval);
+                               /* This one is picked? */
+                               if (!pick) break;
                        }
-
-                       /* Traps to protect the treasure */
-                       vault_traps(yval, xval, 4, 10, 2 + randint1(3));
-
-                       break;
                }
 
-               /* Inner pillar(s). */
-               case 3:
-               {
-                       /* Place a secret door */
-                       switch (randint1(4))
-                       {
-                               case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
-                               case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
-                               case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
-                               case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
-                       }
-
-                       /* Large Inner Pillar */
-                       for (y = yval - 1; y <= yval + 1; y++)
-                       {
-                               for (x = xval - 1; x <= xval + 1; x++)
-                               {
-                               c_ptr = &cave[y][x];
-                               place_inner_grid(c_ptr);
-                               }
-                       }
-
-                       /* Occasionally, two more Large Inner Pillars */
-                       if (one_in_(2))
-                       {
-                               tmp = randint1(2);
-                               for (y = yval - 1; y <= yval + 1; y++)
-                               {
-                                       for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
-                                       {
-                                       c_ptr = &cave[y][x];
-                                       place_inner_grid(c_ptr);
-                                       }
-                                       for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
-                                       {
-                                       c_ptr = &cave[y][x];
-                                       place_inner_grid(c_ptr);
-                                       }
-                               }
-                       }
-
-                       /* Occasionally, some Inner rooms */
-                       if (one_in_(3))
-                       {
-                               int door_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);
-
-                               /* Long horizontal walls */
-                               for (x = xval - 5; x <= xval + 5; x++)
-                               {
-                               c_ptr = &cave[yval - 1][x];
-                               place_inner_grid(c_ptr);
-                               c_ptr = &cave[yval + 1][x];
-                               place_inner_grid(c_ptr);
-                               }
-
-                               /* Close off the left/right edges */
-                               c_ptr = &cave[yval][xval - 5];
-                               place_inner_grid(c_ptr);
-                               c_ptr = &cave[yval][xval + 5];
-                               place_inner_grid(c_ptr);
+               if (!pick) break;
+       }
 
-                               /* Secret doors (random top/bottom) */
-                               place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3, door_type);
-                               place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3, door_type);
+       /* Extract blocks */
+       by1 = block_y + 0;
+       bx1 = block_x + 0;
+       by2 = block_y + blocks_high;
+       bx2 = block_x + blocks_wide;
 
-                               /* Monsters */
-                               vault_monsters(yval, xval - 2, randint1(2));
-                               vault_monsters(yval, xval + 2, randint1(2));
+       /*
+        * It is *extremely* important that the following calculation
+        * be *exactly* correct to prevent memory errors
+        */
 
-                               /* Objects */
-                               if (one_in_(3)) place_object(yval, xval - 2, 0L);
-                               if (one_in_(3)) place_object(yval, xval + 2, 0L);
-                       }
+       /* Acquire the location of the room */
+       (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
+       (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
 
-                       break;
-               }
+       /* Save the room location */
+       if (dun->cent_n < CENT_MAX)
+       {
+               dun->cent[dun->cent_n].y = (byte_hack)*y;
+               dun->cent[dun->cent_n].x = (byte_hack)*x;
+               dun->cent_n++;
+       }
 
-               /* Maze inside. */
-               case 4:
+       /* Reserve some blocks. */
+       for (by = by1; by < by2; by++)
+       {
+               for (bx = bx1; bx < bx2; bx++)
                {
-                       /* Place a secret door */
-                       switch (randint1(4))
-                       {
-                               case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
-                               case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
-                               case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
-                               case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
-                       }
-
-                       /* Maze (really a checkerboard) */
-                       for (y = y1; y <= y2; y++)
-                       {
-                               for (x = x1; x <= x2; x++)
-                               {
-                                       if (0x1 & (x + y))
-                                       {
-                                               c_ptr = &cave[y][x];
-                                               place_inner_grid(c_ptr);
-                                       }
-                               }
-                       }
-
-                       /* Monsters just love mazes. */
-                       vault_monsters(yval, xval - 5, randint1(3));
-                       vault_monsters(yval, xval + 5, randint1(3));
-
-                       /* Traps make them entertaining. */
-                       vault_traps(yval, xval - 3, 2, 8, randint1(3));
-                       vault_traps(yval, xval + 3, 2, 8, randint1(3));
-
-                       /* Mazes should have some treasure too. */
-                       vault_objects(yval, xval, 3);
-
-                       break;
+                       dun->room_map[by][bx] = TRUE;
                }
+       }
 
-               /* Four small rooms. */
-               case 5:
-               {
-                       int door_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);
 
-                       /* Inner "cross" */
-                       for (y = y1; y <= y2; y++)
-                       {
-                               c_ptr = &cave[y][xval];
-                               place_inner_grid(c_ptr);
-                       }
-                       for (x = x1; x <= x2; x++)
-                       {
-                               c_ptr = &cave[yval][x];
-                               place_inner_grid(c_ptr);
-                       }
+       /*
+        * Hack- See if room will cut off a cavern.
+        *
+        * If so, fix by tunneling outside the room in such a
+        * way as to connect the caves.
+        */
+       check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
 
-                       /* Doors into the rooms */
-                       if (randint0(100) < 50)
-                       {
-                               int i = randint1(10);
-                               place_secret_door(y1 - 1, xval - i, door_type);
-                               place_secret_door(y1 - 1, xval + i, door_type);
-                               place_secret_door(y2 + 1, xval - i, door_type);
-                               place_secret_door(y2 + 1, xval + i, door_type);
-                       }
-                       else
-                       {
-                               int i = randint1(3);
-                               place_secret_door(yval + i, x1 - 1, door_type);
-                               place_secret_door(yval - i, x1 - 1, door_type);
-                               place_secret_door(yval + i, x2 + 1, door_type);
-                               place_secret_door(yval - i, x2 + 1, door_type);
-                       }
 
-                       /* Treasure, centered at the center of the cross */
-                       vault_objects(yval, xval, 2 + randint1(2));
+       /* Success. */
+       return TRUE;
+}
 
-                       /* Gotta have some monsters. */
-                       vault_monsters(yval + 1, xval - 4, randint1(4));
-                       vault_monsters(yval + 1, xval + 4, randint1(4));
-                       vault_monsters(yval - 1, xval - 4, randint1(4));
-                       vault_monsters(yval - 1, xval + 4, randint1(4));
 
-                       break;
-               }
-       }
 
-       return TRUE;
-}
 
 
 
@@ -1446,7 +552,7 @@ static u32b vault_aux_dragon_mask4;
  * @param r_idx 確認したいモンスター種族ID
  * @return Vault生成の最低必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_simple(int r_idx)
+static bool vault_aux_simple(MONRACE_IDX r_idx)
 {
        /* Okay */
        return (vault_monster_okay(r_idx));
@@ -1459,7 +565,7 @@ static bool vault_aux_simple(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_jelly(int r_idx)
+static bool vault_aux_jelly(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1484,7 +590,7 @@ static bool vault_aux_jelly(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_animal(int r_idx)
+static bool vault_aux_animal(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1505,7 +611,7 @@ static bool vault_aux_animal(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_undead(int r_idx)
+static bool vault_aux_undead(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1525,7 +631,7 @@ static bool vault_aux_undead(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_chapel_g(int r_idx)
+static bool vault_aux_chapel_g(MONRACE_IDX r_idx)
 {
        static int chapel_list[] = {
                MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G, 
@@ -1559,7 +665,7 @@ static bool vault_aux_chapel_g(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_kennel(int r_idx)
+static bool vault_aux_kennel(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1579,7 +685,7 @@ static bool vault_aux_kennel(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_mimic(int r_idx)
+static bool vault_aux_mimic(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1599,7 +705,7 @@ static bool vault_aux_mimic(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_clone(int r_idx)
+static bool vault_aux_clone(MONRACE_IDX r_idx)
 {
        /* Validate the monster */
        if (!vault_monster_okay(r_idx)) return (FALSE);
@@ -1614,7 +720,7 @@ static bool vault_aux_clone(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_symbol_e(int r_idx)
+static bool vault_aux_symbol_e(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1639,7 +745,7 @@ static bool vault_aux_symbol_e(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_symbol_g(int r_idx)
+static bool vault_aux_symbol_g(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1664,7 +770,7 @@ static bool vault_aux_symbol_g(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_orc(int r_idx)
+static bool vault_aux_orc(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1688,7 +794,7 @@ static bool vault_aux_orc(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_troll(int r_idx)
+static bool vault_aux_troll(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1712,7 +818,7 @@ static bool vault_aux_troll(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_giant(int r_idx)
+static bool vault_aux_giant(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1738,7 +844,7 @@ static bool vault_aux_giant(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_dragon(int r_idx)
+static bool vault_aux_dragon(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1765,7 +871,7 @@ static bool vault_aux_dragon(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_demon(int r_idx)
+static bool vault_aux_demon(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1788,7 +894,7 @@ static bool vault_aux_demon(int r_idx)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_cthulhu(int r_idx)
+static bool vault_aux_cthulhu(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -1828,7 +934,7 @@ static void vault_prep_clone(void)
  */
 static void vault_prep_symbol(void)
 {
-       int r_idx;
+       MONRACE_IDX r_idx;
 
        /* Apply the monster restriction */
        get_mon_num_prep(vault_aux_simple, NULL);
@@ -1923,7 +1029,7 @@ static void vault_prep_dragon(void)
  * @param r_idx 確認したいモンスター種族ID
  * @return 生成必要条件を満たしているならTRUEを返す。
  */
-static bool vault_aux_dark_elf(int r_idx)
+static bool vault_aux_dark_elf(MONRACE_IDX r_idx)
 {
        int i;
        static int dark_elf_list[] =
@@ -1951,7 +1057,7 @@ typedef struct vault_aux_type vault_aux_type;
 struct vault_aux_type
 {
        cptr name;
-       bool (*hook_func)(int r_idx);
+       bool (*hook_func)(MONRACE_IDX r_idx);
        void (*prep_func)(void);
        int level;
        int chance;
@@ -2260,7 +1366,7 @@ static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
  */
 static bool build_type5(void)
 {
-       int y, x, y1, x1, y2, x2, xval, yval;
+       POSITION y, x, y1, x1, y2, x2, xval, yval;
        int i;
        nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
 
@@ -2287,7 +1393,8 @@ static bool build_type5(void)
        /* Pick some monster types */
        for (i = 0; i < NUM_NEST_MON_TYPE; i++)
        {
-               int r_idx = 0, attempts = 100;
+               MONRACE_IDX r_idx = 0;
+               int attempts = 100;
                monster_race *r_ptr = NULL;
 
                while (attempts--)
@@ -2310,7 +1417,7 @@ static bool build_type5(void)
                if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
                if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
 
-               nest_mon_info[i].r_idx = r_idx;
+               nest_mon_info[i].r_idx = (s16b)r_idx;
                nest_mon_info[i].used = FALSE;
        }
 
@@ -2397,7 +1504,7 @@ static bool build_type5(void)
        {
                for (x = xval - 9; x <= xval + 9; x++)
                {
-                       int r_idx;
+                       MONRACE_IDX r_idx;
 
                        i = randint0(NUM_NEST_MON_TYPE);
                        r_idx = nest_mon_info[i].r_idx;
@@ -2471,10 +1578,10 @@ static bool build_type5(void)
  */
 static bool build_type6(void)
 {
-       int y, x, y1, x1, y2, x2, xval, yval;
+       POSITION y, x, y1, x1, y2, x2, xval, yval;
        int i, j;
 
-       int what[16];
+       MONRACE_IDX what[16];
 
        monster_type align;
 
@@ -2499,7 +1606,8 @@ static bool build_type6(void)
        /* Pick some monster types */
        for (i = 0; i < 16; i++)
        {
-               int r_idx = 0, attempts = 100;
+               MONRACE_IDX r_idx = 0;
+               int attempts = 100;
                monster_race *r_ptr = NULL;
 
                while (attempts--)
@@ -2614,7 +1722,7 @@ static bool build_type6(void)
                        /* Bubble */
                        if (p1 > p2)
                        {
-                               int tmp = what[i1];
+                               MONRACE_IDX tmp = what[i1];
                                what[i1] = what[i2];
                                what[i2] = tmp;
                        }
@@ -2693,7 +1801,7 @@ static bool build_type6(void)
  * @param transno 処理ID
  * @return なし
  */
-static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
+static void coord_trans(POSITION *x, POSITION *y, POSITION xoffset, POSITION yoffset, int transno)
 {
        int i;
        int temp;
@@ -2738,16 +1846,13 @@ static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
  * @param transno 変換ID
  * @return なし
  */
-static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
-               int xoffset, int yoffset, int transno)
+static void build_vault(POSITION yval, POSITION xval, POSITION ymax, POSITION xmax, cptr data,
+               POSITION xoffset, POSITION yoffset, int transno)
 {
-       int dx, dy, x, y, i, j;
-
+       POSITION dx, dy, x, y, i, j;
        cptr t;
-
        cave_type *c_ptr;
 
-
        /* Place dungeon features and objects */
        for (t = data, dy = 0; dy < ymax; dy++)
        {
@@ -3004,9 +2109,9 @@ static bool build_type7(void)
 {
        vault_type *v_ptr = NULL;
        int dummy;
-       int x, y;
-       int xval, yval;
-       int xoffset, yoffset;
+       POSITION x, y;
+       POSITION xval, yval;
+       POSITION xoffset, yoffset;
        int transno;
 
        /* Pick a lesser vault */
@@ -3085,8 +2190,8 @@ static bool build_type8(void)
 {
        vault_type *v_ptr;
        int dummy;
-       int xval, yval;
-       int x, y;
+       POSITION xval, yval;
+       POSITION x, y;
        int transno;
        int xoffset, yoffset;
 
@@ -3148,7 +2253,7 @@ static bool build_type8(void)
         * prevent generation of vaults with no-entrance.
         */
        /* Find and reserve some space in the dungeon.  Get center of room. */
-       if (!find_space(&yval, &xval, abs(y) + 2, abs(x) + 2)) return FALSE;
+       if (!find_space(&yval, &xval, (POSITION)(abs(y) + 2), (POSITION)(abs(x) + 2))) return FALSE;
 
 #ifdef FORCE_V_IDX
        v_ptr = &v_info[76 + randint1(3)];
@@ -3208,7 +2313,7 @@ static void store_height(int x, int y, int val)
            (val <= fill_data.c1)) val = fill_data.c1 + 1;
 
        /* store the value in height-map format */
-       cave[y][x].feat = val;
+       cave[y][x].feat = (s16b)val;
 
        return;
 }
@@ -3333,10 +2438,10 @@ static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug,
        }
 
        /* Boundaries are walls */
-       cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
-       cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
-       cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
-       cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
+       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;
 
        /* Set the middle square to be an open area. */
        cave[y0][x0].feat = 0;
@@ -3488,14 +2593,14 @@ static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int
                        /* 25% of the time use the other tile : it looks better this way */
                        if (randint1(100) < 75)
                        {
-                               cave[y][x].feat = feat1;
+                               cave[y][x].feat = (s16b)feat1;
                                cave[y][x].info &= ~(CAVE_MASK);
                                cave[y][x].info |= info1;
                                return TRUE;
                        }
                        else
                        {
-                               cave[y][x].feat = feat2;
+                               cave[y][x].feat = (s16b)feat2;
                                cave[y][x].info &= ~(CAVE_MASK);
                                cave[y][x].info |= info2;
                                return TRUE;
@@ -3506,14 +2611,14 @@ static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int
                        /* 25% of the time use the other tile : it looks better this way */
                        if (randint1(100) < 75)
                        {
-                               cave[y][x].feat = feat2;
+                               cave[y][x].feat = (s16b)feat2;
                                cave[y][x].info &= ~(CAVE_MASK);
                                cave[y][x].info |= info2;
                                return TRUE;
                        }
                        else
                        {
-                               cave[y][x].feat = feat1;
+                               cave[y][x].feat = (s16b)feat1;
                                cave[y][x].info &= ~(CAVE_MASK);
                                cave[y][x].info |= info1;
                                return TRUE;
@@ -3521,7 +2626,7 @@ static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int
                }
                else if (cave[y][x].feat <= c3)
                {
-                       cave[y][x].feat = feat3;
+                       cave[y][x].feat = (s16b)feat3;
                        cave[y][x].info &= ~(CAVE_MASK);
                        cave[y][x].info |= info3;
                        return TRUE;
@@ -3542,7 +2647,7 @@ 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
  */
-static void cave_fill(byte y, byte x)
+static void cave_fill(POSITION y, POSITION x)
 {
        int i, j, d;
        int ty, tx;
@@ -3596,8 +2701,8 @@ static void cave_fill(byte y, byte x)
                                        fill_data.info1, fill_data.info2, fill_data.info3))
                                {
                                        /* Enqueue that entry */
-                                       temp_y[flow_tail] = j;
-                                       temp_x[flow_tail] = i;
+                                       temp_y[flow_tail] = (byte_hack)j;
+                                       temp_x[flow_tail] = (byte_hack)i;
 
                                        /* Advance the queue */
                                        if (++flow_tail == TEMP_MAX) flow_tail = 0;
@@ -3814,7 +2919,8 @@ static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, b
  */
 static bool build_type9(void)
 {
-       int grd, roug, cutoff, xsize, ysize, y0, x0;
+       int grd, roug, cutoff;
+       POSITION xsize, ysize, y0, x0;
 
        bool done, light, room;
 
@@ -4348,8 +3454,8 @@ static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
                        }
                }
 
-               center[i].x = x;
-               center[i].y = y;
+               center[i].x = (byte_hack)x;
+               center[i].y = (byte_hack)y;
        }
 
 
@@ -4383,8 +3489,8 @@ static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
                        /* Get distances to two closest centers */
 
                        /* initialize */
-                       min1 = distance(x, y, center[0].x, center[0].y);
-                       min2 = distance(x, y, center[1].x, center[1].y);
+                       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)
                        {
@@ -4397,7 +3503,7 @@ static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
                        /* Scan the rest */
                        for (i = 2; i < BUBBLENUM; i++)
                        {
-                               temp = distance(x, y, center[i].x, center[i].y);
+                               temp = (u16b)distance(x, y, center[i].x, center[i].y);
 
                                if (temp < min1)
                                {
@@ -5453,7 +4559,7 @@ static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
  */
 static bool build_type10(void)
 {
-       int y0, x0, xsize, ysize, vtype;
+       POSITION y0, x0, xsize, ysize, vtype;
 
        /* Get size */
        /* big enough to look good, small enough to be fairly common. */
@@ -5514,7 +4620,7 @@ static bool build_type10(void)
  */
 static bool build_type11(void)
 {
-       int rad, x, y, x0, y0;
+       POSITION rad, x, y, x0, y0;
        int light = FALSE;
 
        /* Occasional light */
@@ -5561,7 +4667,7 @@ static bool build_type11(void)
  */
 static bool build_type12(void)
 {
-       int rad, x, y, x0, y0;
+       POSITION rad, x, y, x0, y0;
        int light = FALSE;
        bool emptyflag = TRUE;
 
@@ -5651,7 +4757,7 @@ static bool build_type12(void)
 /*
  * Helper function for "trapped monster pit"
  */
-static bool vault_aux_trapped_pit(int r_idx)
+static bool vault_aux_trapped_pit(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -5742,10 +4848,10 @@ static bool build_type13(void)
                {0, 0, -1}
        };
 
-       int y, x, y1, x1, y2, x2, xval, yval;
+       POSITION y, x, y1, x1, y2, x2, xval, yval;
        int i, j;
 
-       int what[16];
+       MONRACE_IDX what[16];
 
        monster_type align;
 
@@ -5773,7 +4879,8 @@ static bool build_type13(void)
        /* Pick some monster types */
        for (i = 0; i < 16; i++)
        {
-               int r_idx = 0, attempts = 100;
+               MONRACE_IDX r_idx = 0;
+               int attempts = 100;
                monster_race *r_ptr = NULL;
 
                while (attempts--)
@@ -5917,14 +5024,14 @@ static bool build_type13(void)
                        /* Bubble */
                        if (p1 > p2)
                        {
-                               int tmp = what[i1];
+                               MONRACE_IDX tmp = what[i1];
                                what[i1] = what[i2];
                                what[i2] = tmp;
                        }
                }
        }
 
-       msg_format_wizard(CHEAT_DUNGEON, _("WIZ: %s%sの罠ピットが生成されました。", "WIZ: Trapped monster pit (%s%s)"),
+       msg_format_wizard(CHEAT_DUNGEON, _("%s%sの罠ピットが生成されました。", "Trapped monster pit (%s%s)"),
                n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
 
        /* Select the entries */
@@ -5959,8 +5066,8 @@ static bool build_type13(void)
  */
 static bool build_type14(void)
 {
-       int y, x, y2, x2, yval, xval;
-       int y1, x1, xsize, ysize;
+       POSITION y, x, y2, x2, yval, xval;
+       POSITION y1, x1, xsize, ysize;
 
        bool light;
 
@@ -6028,7 +5135,7 @@ static bool build_type14(void)
        c_ptr->mimic = c_ptr->feat;
        c_ptr->feat = trap;
 
-       msg_format_wizard(CHEAT_DUNGEON, _("WIZ: %sの部屋が生成されました。", "WIZ: Room of %s was generated."), f_name + f_info[trap].name);
+       msg_format_wizard(CHEAT_DUNGEON, _("%sの部屋が生成されました。", "Room of %s was generated."), f_name + f_info[trap].name);
 
        return TRUE;
 }
@@ -6037,7 +5144,7 @@ static bool build_type14(void)
 /*
  * Helper function for "glass room"
  */
-static bool vault_aux_lite(int r_idx)
+static bool vault_aux_lite(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -6059,7 +5166,7 @@ static bool vault_aux_lite(int r_idx)
 /*
  * Helper function for "glass room"
  */
-static bool vault_aux_shards(int r_idx)
+static bool vault_aux_shards(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -6075,7 +5182,7 @@ static bool vault_aux_shards(int r_idx)
 /*
  * Hack -- determine if a template is potion
  */
-static bool kind_is_potion(int k_idx)
+static bool kind_is_potion(KIND_OBJECT_IDX k_idx)
 {
        return k_info[k_idx].tval == TV_POTION;
 }
@@ -6086,8 +5193,8 @@ static bool kind_is_potion(int k_idx)
  */
 static bool build_type15(void)
 {
-       int y, x, y2, x2, yval, xval;
-       int y1, x1, xsize, ysize;
+       POSITION y, x, y2, x2, yval, xval;
+       POSITION y1, x1, xsize, ysize;
        bool light;
 
        cave_type *c_ptr;
@@ -6153,7 +5260,7 @@ static bool build_type15(void)
                        /* Place fixed lite berathers */
                        for (dir1 = 4; dir1 < 8; dir1++)
                        {
-                               int r_idx = get_mon_num(dun_level);
+                               MONRACE_IDX r_idx = get_mon_num(dun_level);
 
                                y = yval + 2 * ddy_ddd[dir1];
                                x = xval + 2 * ddx_ddd[dir1];
@@ -6196,7 +5303,8 @@ static bool build_type15(void)
 
        case 2: /* 1 lite breather + random object */
                {
-                       int r_idx, dir1;
+                       MONRACE_IDX r_idx;
+                       DIRECTION dir1;
 
                        /* Pillars */
                        c_ptr = &cave[y1 + 1][x1 + 1];
@@ -6283,7 +5391,7 @@ static bool build_type15(void)
                        /* Place shard berathers */
                        for (dir1 = 4; dir1 < 8; dir1++)
                        {
-                               int r_idx = get_mon_num(dun_level);
+                               MONRACE_IDX r_idx = get_mon_num(dun_level);
 
                                y = yval + ddy_ddd[dir1];
                                x = xval + ddx_ddd[dir1];
@@ -6462,7 +5570,8 @@ static bool precalc_ugarcade(int town_hgt, int town_wid, int n)
  */
 static void build_stores(int ltcy, int ltcx, int stores[], int n)
 {
-       int i, j, y, x;
+       int i, y, x;
+       IDX j;
        ugbldg_type *cur_ugbldg;
 
        for (i = 0; i < n; i++)
@@ -6555,7 +5664,7 @@ static bool build_type16(void)
                STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,
        };
        int n = sizeof stores / sizeof (int);
-       int i, y, x, y1, x1, yval, xval;
+       POSITION i, y, x, y1, x1, yval, xval;
        int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
        int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
        bool prevent_bm = FALSE;