OSDN Git Service

[Refactor] #38993 cur_wid/hgt を floor_type に取り込み width/heightに改名。 / Move cur_wid...
[hengband/hengband.git] / src / floor-generate.c
index b1e53d4..015cd7c 100644 (file)
@@ -83,7 +83,7 @@
  * demon).  Note that both "nests" and "pits" are now "level dependant",\n
  * and both make 16 "expensive" calls to the "get_mon_num()" function.\n
  *\n
- * Note that the cave grid flags changed in a rather drastic manner\n
+ * Note that the grid flags changed in a rather drastic manner\n
  * for Angband 2.8.0 (and 2.7.9+), in particular, dungeon terrain\n
  * features, such as doors and stairs and traps and rubble and walls,\n
  * are all handled as a set of 64 possible "terrain features", and\n
 #include "rooms.h"
 #include "floor-streams.h"
 #include "trap.h"
+#include "monster.h"
+#include "quest.h"
+#include "player-status.h"
+#include "wild.h"
 
 int dun_tun_rnd; 
 int dun_tun_chg;
@@ -145,12 +149,12 @@ static int next_to_walls(POSITION y, POSITION x)
  */
 static bool alloc_stairs_aux(POSITION y, POSITION x, int walls)
 {
-       cave_type *c_ptr = &cave[y][x];
+       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
 
        /* Require "naked" floor grid */
-       if (!is_floor_grid(c_ptr)) return FALSE;
+       if (!is_floor_grid(g_ptr)) return FALSE;
        if (pattern_tile(y, x)) return FALSE;
-       if (c_ptr->o_idx || c_ptr->m_idx) return FALSE;
+       if (g_ptr->o_idx || g_ptr->m_idx) return FALSE;
 
        /* Require a certain number of adjacent walls */
        if (next_to_walls(y, x) < walls) return FALSE;
@@ -176,17 +180,17 @@ static bool alloc_stairs(IDX feat, int num, int walls)
        if (have_flag(f_ptr->flags, FF_LESS))
        {
                /* No up stairs in town or in ironman mode */
-               if (ironman_downward || !dun_level) return TRUE;
+               if (ironman_downward || !current_floor_ptr->dun_level) return TRUE;
 
-               if (dun_level > d_info[dungeon_type].mindepth)
+               if (current_floor_ptr->dun_level > d_info[p_ptr->dungeon_idx].mindepth)
                        shaft_num = (randint1(num+1))/2;
        }
        else if (have_flag(f_ptr->flags, FF_MORE))
        {
-               QUEST_IDX q_idx = quest_number(dun_level);
+               QUEST_IDX q_idx = quest_number(current_floor_ptr->dun_level);
 
                /* No downstairs on quest levels */
-               if (dun_level > 1 && q_idx)
+               if (current_floor_ptr->dun_level > 1 && q_idx)
                {
                        monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
 
@@ -196,9 +200,9 @@ static bool alloc_stairs(IDX feat, int num, int walls)
                }
 
                /* No downstairs at the bottom */
-               if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
+               if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) return TRUE;
 
-               if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
+               if ((current_floor_ptr->dun_level < d_info[p_ptr->dungeon_idx].maxdepth-1) && !quest_number(current_floor_ptr->dun_level+1))
                        shaft_num = (randint1(num)+1)/2;
        }
 
@@ -212,14 +216,14 @@ static bool alloc_stairs(IDX feat, int num, int walls)
                while (TRUE)
                {
                        POSITION y, x = 0;
-                       cave_type *c_ptr;
+                       grid_type *g_ptr;
 
                        int candidates = 0;
                        int pick;
 
-                       for (y = 1; y < cur_hgt - 1; y++)
+                       for (y = 1; y < current_floor_ptr->height - 1; y++)
                        {
-                               for (x = 1; x < cur_wid - 1; x++)
+                               for (x = 1; x < current_floor_ptr->width - 1; x++)
                                {
                                        if (alloc_stairs_aux(y, x, walls))
                                        {
@@ -243,9 +247,9 @@ static bool alloc_stairs(IDX feat, int num, int walls)
                        /* Choose a random one */
                        pick = randint1(candidates);
 
-                       for (y = 1; y < cur_hgt - 1; y++)
+                       for (y = 1; y < current_floor_ptr->height - 1; y++)
                        {
-                               for (x = 1; x < cur_wid - 1; x++)
+                               for (x = 1; x < current_floor_ptr->width - 1; x++)
                                {
                                        if (alloc_stairs_aux(y, x, walls))
                                        {
@@ -258,16 +262,16 @@ static bool alloc_stairs(IDX feat, int num, int walls)
 
                                if (!pick) break;
                        }
-                       c_ptr = &cave[y][x];
+                       g_ptr = &current_floor_ptr->grid_array[y][x];
 
                        /* Clear possible garbage of hidden trap */
-                       c_ptr->mimic = 0;
+                       g_ptr->mimic = 0;
 
                        /* Clear previous contents, add stairs */
-                       c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
+                       g_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
 
                        /* No longer "FLOOR" */
-                       c_ptr->info &= ~(CAVE_FLOOR);
+                       g_ptr->info &= ~(CAVE_FLOOR);
 
                        /* Success */
                        break;
@@ -288,10 +292,10 @@ static void alloc_object(int set, EFFECT_ID typ, int num)
        POSITION y = 0, x = 0;
        int k;
        int dummy = 0;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /* A small level has few objects. */
-       num = num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID) +1;
+       num = num * current_floor_ptr->height * current_floor_ptr->width / (MAX_HGT*MAX_WID) +1;
 
        /* Place some objects */
        for (k = 0; k < num; k++)
@@ -303,19 +307,19 @@ static void alloc_object(int set, EFFECT_ID typ, int num)
 
                        dummy++;
 
-                       y = randint0(cur_hgt);
-                       x = randint0(cur_wid);
+                       y = randint0(current_floor_ptr->height);
+                       x = randint0(current_floor_ptr->width);
 
-                       c_ptr = &cave[y][x];
+                       g_ptr = &current_floor_ptr->grid_array[y][x];
 
                        /* Require "naked" floor grid */
-                       if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
+                       if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
 
                        /* Avoid player location */
                        if (player_bold(y, x)) continue;
 
                        /* Check for "room" */
-                       room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
+                       room = (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
 
                        /* Require corridor? */
                        if ((set == ALLOC_SET_CORR) && room) continue;
@@ -340,14 +344,14 @@ static void alloc_object(int set, EFFECT_ID typ, int num)
                        case ALLOC_TYP_RUBBLE:
                        {
                                place_rubble(y, x);
-                               cave[y][x].info &= ~(CAVE_FLOOR);
+                               current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
                                break;
                        }
 
                        case ALLOC_TYP_TRAP:
                        {
                                place_trap(y, x);
-                               cave[y][x].info &= ~(CAVE_FLOOR);
+                               current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
                                break;
                        }
 
@@ -387,8 +391,8 @@ bool place_quest_monsters(void)
                if (quest[i].status != QUEST_STATUS_TAKEN ||
                    (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
                     quest[i].type != QUEST_TYPE_RANDOM) ||
-                   quest[i].level != dun_level ||
-                   dungeon_type != quest[i].dungeon ||
+                   quest[i].level != current_floor_ptr->dun_level ||
+                   p_ptr->dungeon_idx != quest[i].dungeon ||
                    (quest[i].flags & QUEST_FLAG_PRESET))
                {
                        /* Ignore it */
@@ -418,19 +422,19 @@ bool place_quest_monsters(void)
                                /* Find an empty grid */
                                for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
                                {
-                                       cave_type    *c_ptr;
+                                       grid_type    *g_ptr;
                                        feature_type *f_ptr;
 
-                                       y = randint0(cur_hgt);
-                                       x = randint0(cur_wid);
+                                       y = randint0(current_floor_ptr->height);
+                                       x = randint0(current_floor_ptr->width);
 
-                                       c_ptr = &cave[y][x];
-                                       f_ptr = &f_info[c_ptr->feat];
+                                       g_ptr = &current_floor_ptr->grid_array[y][x];
+                                       f_ptr = &f_info[g_ptr->feat];
 
                                        if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
                                        if (!monster_can_enter(y, x, r_ptr, 0)) continue;
                                        if (distance(y, x, p_ptr->y, p_ptr->x) < 10) continue;
-                                       if (c_ptr->info & CAVE_ICKY) continue;
+                                       if (g_ptr->info & CAVE_ICKY) continue;
                                        else break;
                                }
 
@@ -458,36 +462,6 @@ bool place_quest_monsters(void)
        return TRUE;
 }
 
-
-/*!
- * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
- * @param c_ptr 永久壁を廃止したいマス構造体の参照ポインタ
- * @return なし
- */
-static void set_bound_perm_wall(cave_type *c_ptr)
-{
-       if (bound_walls_perm)
-       {
-               /* Clear boundary mimic */
-               c_ptr->mimic = 0;
-       }
-       else
-       {
-               feature_type *f_ptr = &f_info[c_ptr->feat];
-
-               /* Hack -- Decline boundary walls with known treasure  */
-               if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
-                   !have_flag(f_ptr->flags, FF_SECRET))
-                       c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
-
-               /* Set boundary mimic */
-               c_ptr->mimic = c_ptr->feat;
-       }
-
-       /* Add "solid" perma-wall */
-       place_solid_perm_grid(c_ptr);
-}
-
 /*!
  * @brief フロアに洞窟や湖を配置する / Generate various caverns and lakes
  * @details There were moved from cave_gen().
@@ -497,7 +471,7 @@ static void gen_caverns_and_lakes(void)
 {
 #ifdef ALLOW_CAVERNS_AND_LAKES
        /* Possible "destroyed" level */
-       if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
+       if ((current_floor_ptr->dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DESTROY))
        {
                dun->destroyed = TRUE;
 
@@ -507,49 +481,49 @@ static void gen_caverns_and_lakes(void)
 
        /* Make a lake some of the time */
        if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
-           (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
+           (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_MASK))
        {
                int count = 0;
-               if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
-               if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
-               if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
-               if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
+               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_WATER) count += 3;
+               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_LAVA) count += 3;
+               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_RUBBLE) count += 3;
+               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_TREE) count += 3;
 
-               if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
+               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_LAVA)
                {
                        /* Lake of Lava */
-                       if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
+                       if ((current_floor_ptr->dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
                        count -= 2;
 
                        /* Lake of Lava2 */
-                       if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
+                       if (!dun->laketype && (current_floor_ptr->dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
                        count--;
                }
 
-               if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
+               if ((d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_WATER) && !dun->laketype)
                {
                        /* Lake of Water */
-                       if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
+                       if ((current_floor_ptr->dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
                        count -= 2;
 
                        /* Lake of Water2 */
-                       if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
+                       if (!dun->laketype && (current_floor_ptr->dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
                        count--;
                }
 
-               if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
+               if ((d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
                {
                        /* Lake of rubble */
-                       if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
+                       if ((current_floor_ptr->dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
                        count -= 2;
 
                        /* Lake of rubble2 */
-                       if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
+                       if (!dun->laketype && (current_floor_ptr->dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
                        count--;
                }
 
                /* Lake of tree */
-               if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
+               if ((current_floor_ptr->dun_level > 5) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
 
                if (dun->laketype)
                {
@@ -558,13 +532,13 @@ static void gen_caverns_and_lakes(void)
                }
        }
 
-       if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
-           (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
-           !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
+       if ((current_floor_ptr->dun_level > DUN_CAVERN) && !dun->empty_level &&
+           (d_info[p_ptr->dungeon_idx].flags1 & DF1_CAVERN) &&
+           !dun->laketype && !dun->destroyed && (randint1(1000) < current_floor_ptr->dun_level))
        {
                dun->cavern = TRUE;
 
-               /* make a large fractal cave in the middle of the dungeon */
+               /* make a large fractal current_floor_ptr->grid_array in the middle of the dungeon */
 
                msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
                build_cavern();
@@ -572,7 +546,7 @@ static void gen_caverns_and_lakes(void)
 #endif /* ALLOW_CAVERNS_AND_LAKES */
 
        /* Hack -- No destroyed "quest" levels */
-       if (quest_number(dun_level)) dun->destroyed = FALSE;
+       if (quest_number(current_floor_ptr->dun_level)) dun->destroyed = FALSE;
 }
 
 
@@ -583,8 +557,8 @@ static void gen_caverns_and_lakes(void)
  */
 static bool cave_gen(void)
 {
-       int i, k, y, x;
-
+       int i, k;
+       POSITION y, x;
        dun_data dun_body;
 
        /* Global data */
@@ -596,9 +570,7 @@ static bool cave_gen(void)
        dun->laketype = 0;
 
        /* Fill the arrays of floors and walls in the good proportions */
-       set_floor_and_wall(dungeon_type);
-
-       /* Prepare allocation table */
+       set_floor_and_wall(p_ptr->dungeon_idx);
        get_mon_num_prep(get_monster_hook(), NULL);
 
        /* Randomize the dungeon creation values */
@@ -609,8 +581,8 @@ static bool cave_gen(void)
        dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
 
        /* Actual maximum number of rooms on this level */
-       dun->row_rooms = cur_hgt / BLOCK_HGT;
-       dun->col_rooms = cur_wid / BLOCK_WID;
+       dun->row_rooms = current_floor_ptr->height / BLOCK_HGT;
+       dun->col_rooms = current_floor_ptr->width / BLOCK_WID;
 
        /* Initialize the room table */
        for (y = 0; y < dun->row_rooms; y++)
@@ -625,7 +597,7 @@ static bool cave_gen(void)
        dun->cent_n = 0;
 
        /* Empty arena levels */
-       if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
+       if (ironman_empty_levels || ((d_info[p_ptr->dungeon_idx].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
        {
                dun->empty_level = TRUE;
                msg_print_wizard(CHEAT_DUNGEON, _("アリーナレベルを生成。", "Arena level."));
@@ -634,49 +606,47 @@ static bool cave_gen(void)
        if (dun->empty_level)
        {
                /* Start with floors */
-               for (y = 0; y < cur_hgt; y++)
+               for (y = 0; y < current_floor_ptr->height; y++)
                {
-                       for (x = 0; x < cur_wid; x++)
+                       for (x = 0; x < current_floor_ptr->width; x++)
                        {
                                place_floor_bold(y, x);
                        }
                }
 
                /* Special boundary walls -- Top and bottom */
-               for (x = 0; x < cur_wid; x++)
+               for (x = 0; x < current_floor_ptr->width; x++)
                {
                        place_extra_bold(0, x);
-                       place_extra_bold(cur_hgt - 1, x);
+                       place_extra_bold(current_floor_ptr->height - 1, x);
                }
 
                /* Special boundary walls -- Left and right */
-               for (y = 1; y < (cur_hgt - 1); y++)
+               for (y = 1; y < (current_floor_ptr->height - 1); y++)
                {
                        place_extra_bold(y, 0);
-                       place_extra_bold(y, cur_wid - 1);
+                       place_extra_bold(y, current_floor_ptr->width - 1);
                }
        }
        else
        {
                /* Start with walls */
-               for (y = 0; y < cur_hgt; y++)
+               for (y = 0; y < current_floor_ptr->height; y++)
                {
-                       for (x = 0; x < cur_wid; x++)
+                       for (x = 0; x < current_floor_ptr->width; x++)
                        {
                                place_extra_bold(y, x);
                        }
                }
        }
 
-
        /* Generate various caverns and lakes */
        gen_caverns_and_lakes();
 
-
        /* Build maze */
-       if (d_info[dungeon_type].flags1 & DF1_MAZE)
+       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_MAZE)
        {
-               build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
+               build_maze_vault(current_floor_ptr->width/2-1, current_floor_ptr->height/2-1, current_floor_ptr->width-4, current_floor_ptr->height-4, FALSE);
 
                /* Place 3 or 4 down stairs near some walls */
                if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
@@ -697,11 +667,11 @@ static bool cave_gen(void)
 
 
                /* Make a hole in the dungeon roof sometimes at level 1 */
-               if (dun_level == 1)
+               if (current_floor_ptr->dun_level == 1)
                {
                        while (one_in_(DUN_MOS_DEN))
                        {
-                               place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
+                               place_trees(randint1(current_floor_ptr->width - 2), randint1(current_floor_ptr->height - 2));
                        }
                }
 
@@ -709,22 +679,45 @@ static bool cave_gen(void)
                if (dun->destroyed) destroy_level();
 
                /* Hack -- Add some rivers */
-               if (one_in_(3) && (randint1(dun_level) > 5))
+               if (one_in_(3) && (randint1(current_floor_ptr->dun_level) > 5))
                {
-                       IDX feat1 = 0, feat2 = 0;
+                       FEAT_IDX feat1 = 0, feat2 = 0;
 
-                       /* Choose water or lava */
-                       if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
+                       /* Choose water mainly */
+                       if ((randint1(MAX_DEPTH * 2) - 1 > current_floor_ptr->dun_level) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_WATER_RIVER))
                        {
                                feat1 = feat_deep_water;
                                feat2 = feat_shallow_water;
                        }
-                       else if  (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
+                       else /* others */
                        {
-                               feat1 = feat_deep_lava;
-                               feat2 = feat_shallow_lava;
+                               FEAT_IDX select_deep_feat[10];
+                               FEAT_IDX select_shallow_feat[10];
+                               int select_id_max = 0, selected;
+
+                               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAVA_RIVER)
+                               {
+                                       select_deep_feat[select_id_max] = feat_deep_lava;
+                                       select_shallow_feat[select_id_max] = feat_shallow_lava;
+                                       select_id_max++;
+                               }
+                               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_POISONOUS_RIVER)
+                               {
+                                       select_deep_feat[select_id_max] = feat_deep_poisonous_puddle;
+                                       select_shallow_feat[select_id_max] = feat_shallow_poisonous_puddle;
+                                       select_id_max++;
+                               }
+                               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_ACID_RIVER)
+                               {
+                                       select_deep_feat[select_id_max] = feat_deep_acid_puddle;
+                                       select_shallow_feat[select_id_max] = feat_shallow_acid_puddle;
+                                       select_id_max++;
+                               }
+
+                               selected = randint0(select_id_max);
+                               feat1 = select_deep_feat[selected];
+                               feat2 = select_shallow_feat[selected];
                        }
-                       else feat1 = 0;
 
                        if (feat1)
                        {
@@ -743,7 +736,7 @@ static bool cave_gen(void)
                /* Hack -- Scramble the room order */
                for (i = 0; i < dun->cent_n; i++)
                {
-                       int ty, tx;
+                       POSITION ty, tx;
                        int pick = rand_range(0, i);
 
                        ty = dun->cent[i].y;
@@ -771,9 +764,9 @@ static bool cave_gen(void)
                        dun->wall_n = 0;
 
                        /* Connect the room to the previous room */
-                       if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
+                       if (randint1(current_floor_ptr->dun_level) > d_info[p_ptr->dungeon_idx].tunnel_percent)
                        {
-                               /* make cave-like tunnel */
+                               /* make cavelike tunnel */
                                (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
                        }
                        else
@@ -787,39 +780,39 @@ static bool cave_gen(void)
                        /* Turn the tunnel into corridor */
                        for (j = 0; j < dun->tunn_n; j++)
                        {
-                               cave_type *c_ptr;
+                               grid_type *g_ptr;
                                feature_type *f_ptr;
                                y = dun->tunn[j].y;
                                x = dun->tunn[j].x;
-                               c_ptr = &cave[y][x];
-                               f_ptr = &f_info[c_ptr->feat];
+                               g_ptr = &current_floor_ptr->grid_array[y][x];
+                               f_ptr = &f_info[g_ptr->feat];
 
                                /* Clear previous contents (if not a lake), add a floor */
                                if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
                                {
                                        /* Clear mimic type */
-                                       c_ptr->mimic = 0;
+                                       g_ptr->mimic = 0;
 
-                                       place_floor_grid(c_ptr);
+                                       place_floor_grid(g_ptr);
                                }
                        }
 
                        /* Apply the piercings that we found */
                        for (j = 0; j < dun->wall_n; j++)
                        {
-                               cave_type *c_ptr;
+                               grid_type *g_ptr;
                                y = dun->wall[j].y;
                                x = dun->wall[j].x;
-                               c_ptr = &cave[y][x];
+                               g_ptr = &current_floor_ptr->grid_array[y][x];
 
                                /* Clear mimic type */
-                               c_ptr->mimic = 0;
+                               g_ptr->mimic = 0;
 
                                /* Clear previous contents, add up floor */
-                               place_floor_grid(c_ptr);
+                               place_floor_grid(g_ptr);
 
                                /* Occasional doorway */
-                               if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
+                               if ((randint0(100) < dun_tun_pen) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
                                {
                                        /* Place a random door */
                                        place_random_door(y, x, TRUE);
@@ -854,37 +847,37 @@ static bool cave_gen(void)
 
        if (!dun->laketype)
        {
-               if (d_info[dungeon_type].stream2)
+               if (d_info[p_ptr->dungeon_idx].stream2)
                {
                        /* Hack -- Add some quartz streamers */
                        for (i = 0; i < DUN_STR_QUA; i++)
                        {
-                               build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
+                               build_streamer(d_info[p_ptr->dungeon_idx].stream2, DUN_STR_QC);
                        }
                }
 
-               if (d_info[dungeon_type].stream1)
+               if (d_info[p_ptr->dungeon_idx].stream1)
                {
                        /* Hack -- Add some magma streamers */
                        for (i = 0; i < DUN_STR_MAG; i++)
                        {
-                               build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
+                               build_streamer(d_info[p_ptr->dungeon_idx].stream1, DUN_STR_MC);
                        }
                }
        }
 
        /* Special boundary walls -- Top and bottom */
-       for (x = 0; x < cur_wid; x++)
+       for (x = 0; x < current_floor_ptr->width; x++)
        {
-               set_bound_perm_wall(&cave[0][x]);
-               set_bound_perm_wall(&cave[cur_hgt - 1][x]);
+               place_bound_perm_wall(&current_floor_ptr->grid_array[0][x]);
+               place_bound_perm_wall(&current_floor_ptr->grid_array[current_floor_ptr->height - 1][x]);
        }
 
        /* Special boundary walls -- Left and right */
-       for (y = 1; y < (cur_hgt - 1); y++)
+       for (y = 1; y < (current_floor_ptr->height - 1); y++)
        {
-               set_bound_perm_wall(&cave[y][0]);
-               set_bound_perm_wall(&cave[y][cur_wid - 1]);
+               place_bound_perm_wall(&current_floor_ptr->grid_array[y][0]);
+               place_bound_perm_wall(&current_floor_ptr->grid_array[y][current_floor_ptr->width - 1]);
        }
 
        /* Determine the character location */
@@ -893,20 +886,20 @@ static bool cave_gen(void)
        if (!place_quest_monsters()) return FALSE;
 
        /* Basic "amount" */
-       k = (dun_level / 3);
+       k = (current_floor_ptr->dun_level / 3);
        if (k > 10) k = 10;
        if (k < 2) k = 2;
 
        /* Pick a base number of monsters */
-       i = d_info[dungeon_type].min_m_alloc_level;
+       i = d_info[p_ptr->dungeon_idx].min_m_alloc_level;
 
        /* To make small levels a bit more playable */
-       if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
+       if (current_floor_ptr->height < MAX_HGT || current_floor_ptr->width < MAX_WID)
        {
                int small_tester = i;
 
-               i = (i * cur_hgt) / MAX_HGT;
-               i = (i * cur_wid) / MAX_WID;
+               i = (i * current_floor_ptr->height) / MAX_HGT;
+               i = (i * current_floor_ptr->width) / MAX_WID;
                i += 1;
 
                if (i > small_tester) i = small_tester;
@@ -927,10 +920,10 @@ static bool cave_gen(void)
        alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
 
        /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
-       if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
+       if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
 
        /* Mega Hack -- No object at first level of deeper dungeon */
-       if (p_ptr->enter_dungeon && dun_level > 1)
+       if (p_ptr->enter_dungeon && current_floor_ptr->dun_level > 1)
        {
                /* No stair scum! */
                object_level = 1;
@@ -944,19 +937,19 @@ static bool cave_gen(void)
        alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
 
        /* Set back to default */
-       object_level = base_level;
+       object_level = current_floor_ptr->base_level;
 
        /* Put the Guardian */
        if (!alloc_guardian(TRUE)) return FALSE;
 
-       if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
+       if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > current_floor_ptr->dun_level)) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
        {
-               /* Lite the cave */
-               for (y = 0; y < cur_hgt; y++)
+               /* Lite the current_floor_ptr->grid_array */
+               for (y = 0; y < current_floor_ptr->height; y++)
                {
-                       for (x = 0; x < cur_wid; x++)
+                       for (x = 0; x < current_floor_ptr->width; x++)
                        {
-                               cave[y][x].info |= (CAVE_GLOW);
+                               current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW);
                        }
                }
        }
@@ -984,56 +977,56 @@ static void build_arena(void)
                for (j = x_left; j <= x_right; j++)
                {
                        place_extra_perm_bold(i, j);
-                       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (i = y_depth; i >= y_depth - 5; i--)
                for (j = x_left; j <= x_right; j++)
                {
                        place_extra_perm_bold(i, j);
-                       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_left; j <= x_left + 17; j++)
                for (i = y_height; i <= y_depth; i++)
                {
                        place_extra_perm_bold(i, j);
-                       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_right; j >= x_right - 17; j--)
                for (i = y_height; i <= y_depth; i++)
                {
                        place_extra_perm_bold(i, j);
-                       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
        place_extra_perm_bold(y_height+6, x_left+18);
-       cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
        place_extra_perm_bold(y_depth-6, x_left+18);
-       cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
        place_extra_perm_bold(y_height+6, x_right-18);
-       cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
        place_extra_perm_bold(y_depth-6, x_right-18);
-       cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
 
        i = y_height + 5;
        j = xval;
-       cave[i][j].feat = f_tag_to_index("ARENA_GATE");
-       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[i][j].feat = f_tag_to_index("ARENA_GATE");
+       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
        player_place(i, j);
 }
 
 /*!
- * @brief 闘技場への入場処理 / Town logic flow for generation of arena -KMW-
+ * @brief 挑戦時闘技場への入場処理 / Town logic flow for generation of arena -KMW-
  * @return なし
  */
-static void arena_gen(void)
+static void generate_challenge_arena(void)
 {
        POSITION y, x;
        POSITION qy = 0;
        POSITION qx = 0;
 
        /* Smallest area */
-       cur_hgt = SCREEN_HGT;
-       cur_wid = SCREEN_WID;
+       current_floor_ptr->height = SCREEN_HGT;
+       current_floor_ptr->width = SCREEN_WID;
 
        /* Start with solid walls */
        for (y = 0; y < MAX_HGT; y++)
@@ -1044,7 +1037,7 @@ static void arena_gen(void)
                        place_solid_perm_bold(y, x);
 
                        /* Illuminate and memorize the walls */
-                       cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
                }
        }
 
@@ -1054,7 +1047,7 @@ static void arena_gen(void)
                for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
                {
                        /* Create empty floor */
-                       cave[y][x].feat = feat_floor;
+                       current_floor_ptr->grid_array[y][x].feat = feat_floor;
                }
        }
 
@@ -1089,46 +1082,46 @@ static void build_battle(void)
                for (j = x_left; j <= x_right; j++)
                {
                        place_extra_perm_bold(i, j);
-                       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (i = y_depth; i >= y_depth - 3; i--)
                for (j = x_left; j <= x_right; j++)
                {
                        place_extra_perm_bold(i, j);
-                       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_left; j <= x_left + 17; j++)
                for (i = y_height; i <= y_depth; i++)
                {
                        place_extra_perm_bold(i, j);
-                       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_right; j >= x_right - 17; j--)
                for (i = y_height; i <= y_depth; i++)
                {
                        place_extra_perm_bold(i, j);
-                       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
        place_extra_perm_bold(y_height+6, x_left+18);
-       cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
        place_extra_perm_bold(y_depth-4, x_left+18);
-       cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
        place_extra_perm_bold(y_height+6, x_right-18);
-       cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
        place_extra_perm_bold(y_depth-4, x_right-18);
-       cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
 
        for (i = y_height + 1; i <= y_height + 5; i++)
                for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
                {
-                       cave[i][j].feat = feat_permanent_glass_wall;
+                       current_floor_ptr->grid_array[i][j].feat = feat_permanent_glass_wall;
                }
 
        i = y_height + 1;
        j = xval;
-       cave[i][j].feat = f_tag_to_index("BUILDING_3");
-       cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
+       current_floor_ptr->grid_array[i][j].feat = f_tag_to_index("BUILDING_3");
+       current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
        player_place(i, j);
 }
 
@@ -1136,7 +1129,7 @@ static void build_battle(void)
  * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
  * @return なし
  */
-static void battle_gen(void)
+static void generate_gambling_arena(void)
 {
        POSITION y, x;
        MONSTER_IDX i;
@@ -1152,7 +1145,7 @@ static void battle_gen(void)
                        place_solid_perm_bold(y, x);
 
                        /* Illuminate and memorize the walls */
-                       cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
+                       current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
                }
        }
 
@@ -1162,7 +1155,7 @@ static void battle_gen(void)
                for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
                {
                        /* Create empty floor */
-                       cave[y][x].feat = feat_floor;
+                       current_floor_ptr->grid_array[y][x].feat = feat_floor;
                }
        }
 
@@ -1170,9 +1163,8 @@ static void battle_gen(void)
 
        for(i = 0; i < 4; i++)
        {
-               place_monster_aux(0, p_ptr->y + 8 + (i/2)*4, p_ptr->x - 2 + (i%2)*4, battle_mon[i],
-                                 (PM_NO_KAGE | PM_NO_PET));
-               set_friendly(&m_list[cave[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
+               place_monster_aux(0, p_ptr->y + 8 + (i/2)*4, p_ptr->x - 2 + (i%2)*4, battle_mon[i], (PM_NO_KAGE | PM_NO_PET));
+               set_friendly(&m_list[current_floor_ptr->grid_array[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
        }
        for(i = 1; i < m_max; i++)
        {
@@ -1180,11 +1172,8 @@ static void battle_gen(void)
 
                if (!m_ptr->r_idx) continue;
 
-               /* Hack -- Detect monster */
                m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
-
-               /* Update the monster */
-               update_mon(i, FALSE);
+               update_monster(i, FALSE);
        }
 }
 
@@ -1192,29 +1181,26 @@ static void battle_gen(void)
  * @brief 固定マップクエストのフロア生成 / Generate a quest level
  * @return なし
  */
-static void quest_gen(void)
+static void generate_fixed_floor(void)
 {
        POSITION x, y;
 
-
        /* Start with perm walls */
-       for (y = 0; y < cur_hgt; y++)
+       for (y = 0; y < current_floor_ptr->height; y++)
        {
-               for (x = 0; x < cur_wid; x++)
+               for (x = 0; x < current_floor_ptr->width; x++)
                {
                        place_solid_perm_bold(y, x);
                }
        }
 
        /* Set the quest level */
-       base_level = quest[p_ptr->inside_quest].level;
-       dun_level = base_level;
-       object_level = base_level;
-       monster_level = base_level;
+       current_floor_ptr->base_level = quest[p_ptr->inside_quest].level;
+       current_floor_ptr->dun_level = current_floor_ptr->base_level;
+       object_level = current_floor_ptr->base_level;
+       monster_level = current_floor_ptr->base_level;
 
        if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
-
-       /* Prepare allocation table */
        get_mon_num_prep(get_monster_hook(), NULL);
 
        init_flags = INIT_CREATE_DUNGEON;
@@ -1226,22 +1212,22 @@ static void quest_gen(void)
  * @brief ダンジョン時のランダムフロア生成 / Make a real level
  * @return フロアの生成に成功したらTRUE
  */
-static bool level_gen(cptr *why)
+static bool level_gen(concptr *why)
 {
        int level_height, level_width;
 
        if ((always_small_levels || ironman_small_levels ||
            (one_in_(SMALL_LEVEL) && small_levels) ||
-            (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
-           (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
-           !(d_info[dungeon_type].flags1 & DF1_BIG))
+            (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER) ||
+           (d_info[p_ptr->dungeon_idx].flags1 & DF1_SMALLEST)) &&
+           !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BIG))
        {
-               if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
+               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_SMALLEST)
                {
                        level_height = 1;
                        level_width = 1;
                }
-               else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
+               else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
                {
                        level_height = 2;
                        level_width = 2;
@@ -1253,78 +1239,72 @@ static bool level_gen(cptr *why)
                                level_height = randint1(MAX_HGT/SCREEN_HGT);
                                level_width = randint1(MAX_WID/SCREEN_WID);
                        }
-                       while ((level_height == MAX_HGT/SCREEN_HGT) &&
-                                  (level_width == MAX_WID/SCREEN_WID));
+                       while ((level_height == MAX_HGT/SCREEN_HGT) && (level_width == MAX_WID/SCREEN_WID));
                }
 
-               cur_hgt = level_height * SCREEN_HGT;
-               cur_wid = level_width * SCREEN_WID;
+               current_floor_ptr->height = level_height * SCREEN_HGT;
+               current_floor_ptr->width = level_width * SCREEN_WID;
 
                /* Assume illegal panel */
-               panel_row_min = cur_hgt;
-               panel_col_min = cur_wid;
+               panel_row_min = current_floor_ptr->height;
+               panel_col_min = current_floor_ptr->width;
 
                msg_format_wizard(CHEAT_DUNGEON,
                        _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."),
-                       cur_wid, cur_hgt);
+                       current_floor_ptr->width, current_floor_ptr->height);
        }
        else
        {
                /* Big dungeon */
-               cur_hgt = MAX_HGT;
-               cur_wid = MAX_WID;
+               current_floor_ptr->height = MAX_HGT;
+               current_floor_ptr->width = MAX_WID;
 
                /* Assume illegal panel */
-               panel_row_min = cur_hgt;
-               panel_col_min = cur_wid;
+               panel_row_min = current_floor_ptr->height;
+               panel_col_min = current_floor_ptr->width;
        }
 
        /* Make a dungeon */
        if (!cave_gen())
        {
-#ifdef JP
-*why = "ダンジョン生成に失敗";
-#else
-               *why = "could not place player";
-#endif
-
+               *why = _("ダンジョン生成に失敗", "could not place player");
                return FALSE;
        }
        else return TRUE;
 }
 
 /*!
- * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after cave generation
+ * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after current_floor_ptr->grid_array generation
  * @return なし
  */
-void wipe_generate_cave_flags(void)
+void wipe_generate_random_floor_flags(void)
 {
        POSITION x, y;
 
-       for (y = 0; y < cur_hgt; y++)
+       for (y = 0; y < current_floor_ptr->height; y++)
        {
-               for (x = 0; x < cur_wid; x++)
+               for (x = 0; x < current_floor_ptr->width; x++)
                {
                        /* Wipe unused flags */
-                       cave[y][x].info &= ~(CAVE_MASK);
+                       current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
                }
        }
 
-       if (dun_level)
+       if (current_floor_ptr->dun_level)
        {
-               for (y = 1; y < cur_hgt - 1; y++)
+               for (y = 1; y < current_floor_ptr->height - 1; y++)
                {
-                       for (x = 1; x < cur_wid - 1; x++)
+                       for (x = 1; x < current_floor_ptr->width - 1; x++)
                        {
                                /* There might be trap */
-                               cave[y][x].info |= CAVE_UNSAFE;
+                               current_floor_ptr->grid_array[y][x].info |= CAVE_UNSAFE;
                        }
                }
        }
 }
 
 /*!
- * @brief フロアの全情報を初期化する / Clear and empty the cave
+ * @brief フロアの全情報を初期化する / Clear and empty the current_floor_ptr->grid_array
  * @return なし
  */
 void clear_cave(void)
@@ -1349,35 +1329,21 @@ void clear_cave(void)
        precalc_cur_num_of_pet();
 
 
-       /* Start with a blank cave */
+       /* Start with a blank current_floor_ptr->grid_array */
        for (y = 0; y < MAX_HGT; y++)
        {
                for (x = 0; x < MAX_WID; x++)
                {
-                       cave_type *c_ptr = &cave[y][x];
-
-                       /* No flags */
-                       c_ptr->info = 0;
-
-                       /* No features */
-                       c_ptr->feat = 0;
-
-                       /* No objects */
-                       c_ptr->o_idx = 0;
-
-                       /* No monsters */
-                       c_ptr->m_idx = 0;
-
-                       /* No special */
-                       c_ptr->special = 0;
-
-                       /* No mimic */
-                       c_ptr->mimic = 0;
-
-                       /* No flow */
-                       c_ptr->cost = 0;
-                       c_ptr->dist = 0;
-                       c_ptr->when = 0;
+                       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
+                       g_ptr->info = 0;
+                       g_ptr->feat = 0;
+                       g_ptr->o_idx = 0;
+                       g_ptr->m_idx = 0;
+                       g_ptr->special = 0;
+                       g_ptr->mimic = 0;
+                       g_ptr->cost = 0;
+                       g_ptr->dist = 0;
+                       g_ptr->when = 0;
                }
        }
 
@@ -1385,13 +1351,13 @@ void clear_cave(void)
        p_ptr->x = p_ptr->y = 0;
 
        /* Set the base level */
-       base_level = dun_level;
+       current_floor_ptr->base_level = current_floor_ptr->dun_level;
 
        /* Reset the monster generation level */
-       monster_level = base_level;
+       monster_level = current_floor_ptr->base_level;
 
        /* Reset the object generation level */
-       object_level = base_level;
+       object_level = current_floor_ptr->base_level;
 }
 
 
@@ -1400,44 +1366,44 @@ void clear_cave(void)
  * @return なし
  * @note Hack -- regenerate any "overflow" levels
  */
-void generate_cave(void)
+void generate_random_floor(void)
 {
        int num;
 
        /* Fill the arrays of floors and walls in the good proportions */
-       set_floor_and_wall(dungeon_type);
+       set_floor_and_wall(p_ptr->dungeon_idx);
 
        /* Generate */
        for (num = 0; TRUE; num++)
        {
                bool okay = TRUE;
 
-               cptr why = NULL;
+               concptr why = NULL;
 
-               /* Clear and empty the cave */
+               /* Clear and empty the current_floor_ptr->grid_array */
                clear_cave();
 
                /* Build the arena -KMW- */
                if (p_ptr->inside_arena)
                {
                        /* Small arena */
-                       arena_gen();
+                       generate_challenge_arena();
                }
 
                /* Build the battle -KMW- */
                else if (p_ptr->inside_battle)
                {
                        /* Small arena */
-                       battle_gen();
+                       generate_gambling_arena();
                }
 
                else if (p_ptr->inside_quest)
                {
-                       quest_gen();
+                       generate_fixed_floor();
                }
 
                /* Build the town */
-               else if (!dun_level)
+               else if (!current_floor_ptr->dun_level)
                {
                        /* Make the wilderness */
                        if (p_ptr->wild_mode) wilderness_gen_small();
@@ -1454,42 +1420,22 @@ void generate_cave(void)
                /* Prevent object over-flow */
                if (o_max >= max_o_idx)
                {
-#ifdef JP
-why = "アイテムが多すぎる";
-#else
-                       why = "too many objects";
-#endif
-
-
+                       why = _("アイテムが多すぎる", "too many objects");
                        okay = FALSE;
                }
                /* Prevent monster over-flow */
                else if (m_max >= max_m_idx)
                {
-#ifdef JP
-why = "モンスターが多すぎる";
-#else
-                       why = "too many monsters";
-#endif
-
-
+                       why = _("モンスターが多すぎる", "too many monsters");
                        okay = FALSE;
                }
 
                /* Accept */
                if (okay) break;
 
-#ifdef JP
-if (why) msg_format("生成やり直し(%s)", why);
-#else
-               if (why) msg_format("Generation restarted (%s)", why);
-#endif
+               if (why) msg_format(_("生成やり直し(%s)", "Generation restarted (%s)"), why);
 
-
-               /* Wipe the objects */
                wipe_o_list();
-
-               /* Wipe the monsters */
                wipe_m_list();
        }
 
@@ -1499,7 +1445,49 @@ if (why) msg_format("生成やり直し(%s)", why);
        /* Reset flag */
        p_ptr->enter_dungeon = FALSE;
 
-       wipe_generate_cave_flags();
+       wipe_generate_random_floor_flags();
+}
+
+/*!
+ * @brief build_tunnel用に通路を掘るための方向をランダムに決める / Pick a random direction
+ * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
+ * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
+ * @return なし
+ */
+static void rand_dir(POSITION *rdir, POSITION *cdir)
+{
+       /* Pick a random direction */
+       int i = randint0(4);
+
+       /* Extract the dy/dx components */
+       *rdir = ddy_ddd[i];
+       *cdir = ddx_ddd[i];
+}
+
+/*!
+ * @brief build_tunnel用に通路を掘るための方向を位置関係通りに決める / Always picks a correct direction
+ * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
+ * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
+ * @param y1 始点Y座標
+ * @param x1 始点X座標
+ * @param y2 終点Y座標
+ * @param x2 終点X座標
+ * @return なし
+ */
+static void correct_dir(POSITION *rdir, POSITION *cdir, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
+{
+       /* Extract vertical and horizontal directions */
+       *rdir = (y1 == y2) ? 0 : (y1 < y2) ? 1 : -1;
+       *cdir = (x1 == x2) ? 0 : (x1 < x2) ? 1 : -1;
+
+       /* Never move diagonally */
+       if (*rdir && *cdir)
+       {
+               if (randint0(100) < 50)
+                       *rdir = 0;
+               else
+                       *cdir = 0;
+       }
 }
 
 /*!
@@ -1541,13 +1529,13 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
 {
        POSITION y, x;
        POSITION tmp_row, tmp_col;
-       DIRECTION row_dir, col_dir;
+       POSITION row_dir, col_dir;
        POSITION start_row, start_col;
        int main_loop_count = 0;
 
        bool door_flag = FALSE;
 
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /* Save the starting location */
        start_row = row1;
@@ -1599,13 +1587,13 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
 
 
                /* Access the location */
-               c_ptr = &cave[tmp_row][tmp_col];
+               g_ptr = &current_floor_ptr->grid_array[tmp_row][tmp_col];
 
                /* Avoid "solid" walls */
-               if (is_solid_grid(c_ptr)) continue;
+               if (is_solid_grid(g_ptr)) continue;
 
                /* Pierce "outer" walls of rooms */
-               if (is_outer_grid(c_ptr))
+               if (is_outer_grid(g_ptr))
                {
                        /* Acquire the "next" location */
                        y = tmp_row + row_dir;
@@ -1616,8 +1604,8 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
                        if (is_solid_bold(y, x)) continue;
 
                        /* Accept this location */
-                       row1 = (POSITION)tmp_row;
-                       col1 = (POSITION)tmp_col;
+                       row1 = tmp_row;
+                       col1 = tmp_col;
 
                        /* Save the wall location */
                        if (dun->wall_n < WALL_MAX)
@@ -1644,7 +1632,7 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
                }
 
                /* Travel quickly through rooms */
-               else if (c_ptr->info & (CAVE_ROOM))
+               else if (g_ptr->info & (CAVE_ROOM))
                {
                        /* Accept the location */
                        row1 = tmp_row;
@@ -1652,7 +1640,7 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
                }
 
                /* Tunnel through all other walls */
-               else if (is_extra_grid(c_ptr) || is_inner_grid(c_ptr) || is_solid_grid(c_ptr))
+               else if (is_extra_grid(g_ptr) || is_inner_grid(g_ptr) || is_solid_grid(g_ptr))
                {
                        /* Accept this location */
                        row1 = tmp_row;
@@ -1737,11 +1725,11 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
 {
        int i, j, dx, dy;
 
-       cave_type *c_ptr = &cave[*y][*x];
+       grid_type *g_ptr = &current_floor_ptr->grid_array[*y][*x];
 
        if (!in_bounds(*y, *x)) return TRUE;
 
-       if (is_inner_grid(c_ptr))
+       if (is_inner_grid(g_ptr))
        {
                return TRUE;
        }
@@ -1766,7 +1754,7 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
                return TRUE;
        }
 
-       if (is_outer_grid(c_ptr) && affectwall)
+       if (is_outer_grid(g_ptr) && affectwall)
        {
                /* Save the wall location */
                if (dun->wall_n < WALL_MAX)
@@ -1792,14 +1780,14 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
                }
 
                /* Clear mimic type */
-               cave[*y][*x].mimic = 0;
+               current_floor_ptr->grid_array[*y][*x].mimic = 0;
 
                place_floor_bold(*y, *x);
 
                return TRUE;
        }
 
-       if (is_solid_grid(c_ptr) && affectwall)
+       if (is_solid_grid(g_ptr) && affectwall)
        {
                /* cannot place tunnel here - use a square to the side */
 
@@ -1826,7 +1814,7 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
                if (i == 0)
                {
                        /* Failed for some reason: hack - ignore the solidness */
-                       place_outer_grid(c_ptr);
+                       place_outer_grid(g_ptr);
                        dx = 0;
                        dy = 0;
                }
@@ -2031,7 +2019,7 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
        int length;
        int i;
        bool retval, firstsuccede;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        length = distance(x1, y1, x2, y2);
 
@@ -2057,9 +2045,9 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
                        x3 = (x1 + x2) / 2;
                        y3 = (y1 + y2) / 2;
                }
-               /* cache c_ptr */
-               c_ptr = &cave[y3][x3];
-               if (is_solid_grid(c_ptr))
+               /* cache g_ptr */
+               g_ptr = &current_floor_ptr->grid_array[y3][x3];
+               if (is_solid_grid(g_ptr))
                {
                        /* move midpoint a bit to avoid problem. */
 
@@ -2088,14 +2076,14 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
                        }
                        y3 += dy;
                        x3 += dx;
-                       c_ptr = &cave[y3][x3];
+                       g_ptr = &current_floor_ptr->grid_array[y3][x3];
                }
 
-               if (is_floor_grid(c_ptr))
+               if (is_floor_grid(g_ptr))
                {
                        if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
                        {
-                               if ((cave[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
+                               if ((current_floor_ptr->grid_array[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
                                {
                                        /* do second half only if works + if have hit a room */
                                        retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
@@ -2108,8 +2096,8 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
                                        /* Save the door location */
                                        if (dun->door_n < DOOR_MAX)
                                        {
-                                               dun->door[dun->door_n].y = (POSITION)y3;
-                                               dun->door[dun->door_n].x = (POSITION)x3;
+                                               dun->door[dun->door_n].y = y3;
+                                               dun->door[dun->door_n].x = x3;
                                                dun->door_n++;
                                        }
                                        else return FALSE;
@@ -2126,9 +2114,9 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type,
                else
                {
                        /* tunnel through walls */
-                       if (build_tunnel2(x1, y1, (POSITION)x3, (POSITION)y3, type, cutoff))
+                       if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
                        {
-                               retval = build_tunnel2((POSITION)x3, (POSITION)y3, x2, y2, type, cutoff);
+                               retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
                                firstsuccede = TRUE;
                        }
                        else