OSDN Git Service

[Refactor] #37353 obj_kind.c を object-hook.c に統合。 / Integrate obj_kind.c to object...
[hengband/hengband.git] / src / cave.c
index 098fd1c..a9af2ba 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * @file cave.c
+ * @file grid_array.c
  * @brief ダンジョンの基礎部分実装(主にマスの実装) / low level dungeon routines -BEN-
  * @date 2013/12/30
  * @author
@@ -17,6 +17,9 @@
 
 
 #include "angband.h"
+#include "world.h"
+#include "projection.h"
+#include "object-hook.h"
 
 static byte display_autopick; /*!< 自動拾い状態の設定フラグ */
 static int match_autopick;
@@ -67,20 +70,20 @@ POSITION distance (POSITION y1, POSITION x1, POSITION y2, POSITION x2)
  * @param feat 地形情報のID
  * @return 罠持ちの地形ならばTRUEを返す。
  */
-bool is_trap(IDX feat)
+bool is_trap(FEAT_IDX feat)
 {
        return have_flag(f_info[feat].flags, FF_TRAP);
 }
 
 /*!
  * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
- * @param c_ptr マス構造体の参照ポインタ
+ * @param g_ptr マス構造体の参照ポインタ
  * @return 看破済みの罠があるならTRUEを返す。
  */
-bool is_known_trap(cave_type *c_ptr)
+bool is_known_trap(grid_type *g_ptr)
 {
-       if (!c_ptr->mimic && !cave_have_flag_grid(c_ptr, FF_SECRET) &&
-           is_trap(c_ptr->feat)) return TRUE;
+       if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
+           is_trap(g_ptr->feat)) return TRUE;
        else
                return FALSE;
 }
@@ -90,7 +93,7 @@ bool is_known_trap(cave_type *c_ptr)
  * @param feat 地形情報のID
  * @return 閉じたドアのある地形ならばTRUEを返す。
  */
-bool is_closed_door(IDX feat)
+bool is_closed_door(FEAT_IDX feat)
 {
        feature_type *f_ptr = &f_info[feat];
 
@@ -100,13 +103,13 @@ bool is_closed_door(IDX feat)
 
 /*!
  * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
- * @param c_ptr マス構造体の参照ポインタ
+ * @param g_ptr マス構造体の参照ポインタ
  * @return 隠されたドアがあるならTRUEを返す。
  */
-bool is_hidden_door(cave_type *c_ptr)
+bool is_hidden_door(grid_type *g_ptr)
 {
-       if ((c_ptr->mimic || cave_have_flag_grid(c_ptr, FF_SECRET)) &&
-           is_closed_door(c_ptr->feat))
+       if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
+           is_closed_door(g_ptr->feat))
                return TRUE;
        else
                return FALSE;
@@ -160,22 +163,22 @@ bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
        POSITION dx, dy;
 
        /* Absolute */
-       int ax, ay;
+       POSITION ax, ay;
 
        /* Signs */
-       int sx, sy;
+       POSITION sx, sy;
 
        /* Fractions */
-       int qx, qy;
+       POSITION qx, qy;
 
        /* Scanners */
-       int tx, ty;
+       POSITION tx, ty;
 
        /* Scale factors */
-       int f1, f2;
+       POSITION f1, f2;
 
        /* Slope, or 1/Slope, of LOS */
-       int m;
+       POSITION m;
 
 
        /* Extract the offset */
@@ -397,12 +400,12 @@ static bool check_local_illumination(POSITION y, POSITION x)
 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
 
        /* Check for "complex" illumination */
-       if ((feat_supports_los(get_feat_mimic(&cave[yy][xx])) &&
-            (cave[yy][xx].info & CAVE_GLOW)) ||
-           (feat_supports_los(get_feat_mimic(&cave[y][xx])) &&
-            (cave[y][xx].info & CAVE_GLOW)) ||
-           (feat_supports_los(get_feat_mimic(&cave[yy][x])) &&
-            (cave[yy][x].info & CAVE_GLOW)))
+       if ((feat_supports_los(get_feat_mimic(&grid_array[yy][xx])) &&
+            (grid_array[yy][xx].info & CAVE_GLOW)) ||
+           (feat_supports_los(get_feat_mimic(&grid_array[y][xx])) &&
+            (grid_array[y][xx].info & CAVE_GLOW)) ||
+           (feat_supports_los(get_feat_mimic(&grid_array[yy][x])) &&
+            (grid_array[yy][x].info & CAVE_GLOW)))
        {
                return TRUE;
        }
@@ -411,7 +414,7 @@ static bool check_local_illumination(POSITION y, POSITION x)
 #else /* COMPLEX_WALL_ILLUMINATION */
 
        /* Check for "simple" illumination */
-       return (cave[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
+       return (grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
 
 #endif /* COMPLEX_WALL_ILLUMINATION */
 }
@@ -423,7 +426,7 @@ static bool check_local_illumination(POSITION y, POSITION x)
        if (player_has_los_bold((Y), (X))) \
        { \
                /* Update the monster */ \
-               if (cave[(Y)][(X)].m_idx) update_monster(cave[(Y)][(X)].m_idx, FALSE); \
+               if (grid_array[(Y)][(X)].m_idx) update_monster(grid_array[(Y)][(X)].m_idx, FALSE); \
 \
                /* Notice and redraw */ \
                note_spot((Y), (X)); \
@@ -567,16 +570,15 @@ void update_local_illumination(POSITION y, POSITION x)
  */
 bool player_can_see_bold(POSITION y, POSITION x)
 {
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /* Blind players see nothing */
        if (p_ptr->blind) return FALSE;
 
-       /* Access the cave grid */
-       c_ptr = &cave[y][x];
+       g_ptr = &grid_array[y][x];
 
        /* Note that "torch-lite" yields "illumination" */
-       if (c_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
+       if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
 
        /* Require line of sight to the grid */
        if (!player_has_los_bold(y, x)) return FALSE;
@@ -585,11 +587,11 @@ bool player_can_see_bold(POSITION y, POSITION x)
        if (p_ptr->see_nocto) return TRUE;
 
        /* Require "perma-lite" of the grid */
-       if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
+       if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
 
        /* Feature code (applying "mimic" field) */
        /* Floors are simple */
-       if (feat_supports_los(get_feat_mimic(c_ptr))) return TRUE;
+       if (feat_supports_los(get_feat_mimic(g_ptr))) return TRUE;
 
        /* Check for "local" illumination */
        return check_local_illumination(y, x);
@@ -616,14 +618,14 @@ bool no_lite(void)
  */
 bool cave_valid_bold(POSITION y, POSITION x)
 {
-       cave_type *c_ptr = &cave[y][x];
+       grid_type *g_ptr = &grid_array[y][x];
        OBJECT_IDX this_o_idx, next_o_idx = 0;
 
        /* Forbid perma-grids */
-       if (cave_perma_grid(c_ptr)) return (FALSE);
+       if (cave_perma_grid(g_ptr)) return (FALSE);
 
        /* Check objects */
-       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
                o_ptr = &o_list[this_o_idx];
@@ -659,7 +661,7 @@ static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
  * @param cp 本来のシンボル
  * @return なし
  */
-static void image_monster(TERM_COLOR *ap, char *cp)
+static void image_monster(TERM_COLOR *ap, SYMBOL_CODE *cp)
 {
        /* Random symbol from set above */
        if (use_graphics)
@@ -687,7 +689,7 @@ static void image_monster(TERM_COLOR *ap, char *cp)
  * @param cp 本来のシンボル
  * @return なし
  */
-static void image_object(TERM_COLOR *ap, char *cp)
+static void image_object(TERM_COLOR *ap, SYMBOL_CODE *cp)
 {
        if (use_graphics)
        {
@@ -714,7 +716,7 @@ static void image_object(TERM_COLOR *ap, char *cp)
  * @param cp 本来のシンボル
  * @return なし
  */
-static void image_random(TERM_COLOR *ap, char *cp)
+static void image_random(TERM_COLOR *ap, SYMBOL_CODE *cp)
 {
        /* Normally, assume monsters */
        if (randint0(100) < 75)
@@ -738,7 +740,7 @@ static void image_random(TERM_COLOR *ap, char *cp)
  *\n
  * The layout of the array is [x][0] = light and [x][1] = dark.\n
  */
-static byte lighting_colours[16][2] =
+static TERM_COLOR lighting_colours[16][2] =
 {
        /* TERM_DARK */
        {TERM_L_DARK, TERM_DARK},
@@ -853,7 +855,7 @@ void apply_default_feat_lighting(TERM_COLOR f_attr[F_LIT_MAX], SYMBOL_CODE f_cha
  * not any.  If there were, they would have to set "shimmer_objects"\n
  * when they were created, and then new "shimmer" code in "dungeon.c"\n
  * would have to be created handle the "shimmer" effect, and the code\n
- * in "cave.c" would have to be updated to create the shimmer effect.\n
+ * in "grid_array.c" would have to be updated to create the shimmer effect.\n
  *\n
  * Note the effects of hallucination.  Objects always appear as random\n
  * "objects", monsters as random "monsters", and normal grids occasionally\n
@@ -940,21 +942,21 @@ void apply_default_feat_lighting(TERM_COLOR f_attr[F_LIT_MAX], SYMBOL_CODE f_cha
  * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect\n
  * then a whole lot of code should be changed...  XXX XXX\n
  */
-void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap, char *tcp)
+void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp)
 {
-       /* Get the cave */
-       cave_type *c_ptr = &cave[y][x];
+       /* Get the grid_array */
+       grid_type *g_ptr = &grid_array[y][x];
 
        OBJECT_IDX this_o_idx, next_o_idx = 0;
 
        /* Feature code (applying "mimic" field) */
-       FEAT_IDX feat = get_feat_mimic(c_ptr);
+       FEAT_IDX feat = get_feat_mimic(g_ptr);
 
        /* Access floor */
        feature_type *f_ptr = &f_info[feat];
 
        TERM_COLOR a;
-       byte c;
+       SYMBOL_CODE c;
 
        /* Boring grids (floors, etc) */
        if (!have_flag(f_ptr->flags, FF_REMEMBER))
@@ -971,8 +973,8 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                 * - Can see grids with CAVE_VIEW unless darkened by monsters.
                 */
                if (!p_ptr->blind &&
-                   ((c_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
-                    ((c_ptr->info & CAVE_VIEW) && (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
+                   ((g_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
+                    ((g_ptr->info & CAVE_VIEW) && (((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
                {
                        /* Normal attr/char */
                        a = f_ptr->x_attr[F_LIT_STANDARD];
@@ -991,10 +993,10 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                        }
 
                        /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
-                       else if (darkened_grid(c_ptr))
+                       else if (darkened_grid(g_ptr))
                        {
-                               /* Unsafe cave grid -- idea borrowed from Unangband */
-                               feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
+                               /* Unsafe grid -- idea borrowed from Unangband */
+                               feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
 
                                /* Access darkness */
                                f_ptr = &f_info[feat];
@@ -1008,7 +1010,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                        else if (view_special_lite)
                        {
                                /* Handle "torch-lit" grids */
-                               if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
+                               if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
                                {
                                        /* Torch lite */
                                        if (view_yellow_lite)
@@ -1020,7 +1022,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                                }
 
                                /* Handle "dark" grids */
-                               else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
+                               else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
                                {
                                        /* Use a darkened colour/tile */
                                        a = f_ptr->x_attr[F_LIT_DARK];
@@ -1028,7 +1030,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                                }
 
                                /* Handle "out-of-sight" grids */
-                               else if (!(c_ptr->info & CAVE_VIEW))
+                               else if (!(g_ptr->info & CAVE_VIEW))
                                {
                                        /* Special flag */
                                        if (view_bright_lite)
@@ -1044,8 +1046,8 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                /* Unknown */
                else
                {
-                       /* Unsafe cave grid -- idea borrowed from Unangband */
-                       feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
+                       /* Unsafe grid -- idea borrowed from Unangband */
+                       feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
 
                        /* Access darkness */
                        f_ptr = &f_info[feat];
@@ -1060,7 +1062,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
        else
        {
                /* Memorized grids */
-               if (c_ptr->info & CAVE_MARK)
+               if (g_ptr->info & CAVE_MARK)
                {
                        /* Normal attr/char */
                        a = f_ptr->x_attr[F_LIT_STANDARD];
@@ -1079,12 +1081,12 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                        }
 
                        /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
-                       else if (darkened_grid(c_ptr) && !p_ptr->blind)
+                       else if (darkened_grid(g_ptr) && !p_ptr->blind)
                        {
                                if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
                                {
-                                       /* Unsafe cave grid -- idea borrowed from Unangband */
-                                       feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
+                                       /* Unsafe grid -- idea borrowed from Unangband */
+                                       feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
 
                                        /* Access darkness */
                                        f_ptr = &f_info[feat];
@@ -1113,7 +1115,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                                }
 
                                /* Handle "torch-lit" grids */
-                               else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
+                               else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
                                {
                                        /* Torch lite */
                                        if (view_yellow_lite)
@@ -1128,7 +1130,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                                else if (view_bright_lite)
                                {
                                        /* Not viewable */
-                                       if (!(c_ptr->info & CAVE_VIEW))
+                                       if (!(g_ptr->info & CAVE_VIEW))
                                        {
                                                /* Use a darkened colour/tile */
                                                a = f_ptr->x_attr[F_LIT_DARK];
@@ -1136,7 +1138,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                                        }
 
                                        /* Not glowing */
-                                       else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
+                                       else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
                                        {
                                                /* Use a darkened colour/tile */
                                                a = f_ptr->x_attr[F_LIT_DARK];
@@ -1157,8 +1159,8 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                /* Unknown */
                else
                {
-                       /* Unsafe cave grid -- idea borrowed from Unangband */
-                       feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
+                       /* Unsafe grid -- idea borrowed from Unangband */
+                       feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
 
                        /* Access feature */
                        f_ptr = &f_info[feat];
@@ -1190,7 +1192,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
        }
 
        /* Objects */
-       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
                o_ptr = &o_list[this_o_idx];
@@ -1238,9 +1240,9 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
 
 
        /* Handle monsters */
-       if (c_ptr->m_idx && display_autopick == 0 )
+       if (g_ptr->m_idx && display_autopick == 0 )
        {
-               monster_type *m_ptr = &m_list[c_ptr->m_idx];
+               monster_type *m_ptr = &m_list[g_ptr->m_idx];
 
                /* Visible monster */
                if (m_ptr->ml)
@@ -1316,7 +1318,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
                                        else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
                                        {
                                                /* Use semi-random attr (usually mimics' colors vary) */
-                                               *ap = c_ptr->m_idx % 15 + 1;
+                                               *ap = g_ptr->m_idx % 15 + 1;
                                        }
                                        else
                                        {
@@ -1359,13 +1361,8 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap,
        if (player_bold(y, x))
        {
                monster_race *r_ptr = &r_info[0];
-
-               /* Get the "player" attr */
                *ap = r_ptr->x_attr;
-
-               /* Get the "player" char */
                *cp = r_ptr->x_char;
-
                feat_priority = 31;
        }
 }
@@ -1399,7 +1396,7 @@ void move_cursor_relative(int row, int col)
 /*
  * Place an attr/char pair at the given map coordinate, if legal.
  */
-void print_rel(char c, byte a, TERM_LEN y, TERM_LEN x)
+void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
 {
        /* Only do "legal" locations */
        if (panel_contains(y, x))
@@ -1408,7 +1405,7 @@ void print_rel(char c, byte a, TERM_LEN y, TERM_LEN x)
                if (!use_graphics)
                {
                        if (world_monster) a = TERM_DARK;
-                       else if (IS_INVULN() || world_player) a = TERM_WHITE;
+                       else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
                        else if (p_ptr->wraith_form) a = TERM_L_DARK;
                }
 
@@ -1462,20 +1459,20 @@ void print_rel(char c, byte a, TERM_LEN y, TERM_LEN x)
  */
 void note_spot(POSITION y, POSITION x)
 {
-       cave_type *c_ptr = &cave[y][x];
+       grid_type *g_ptr = &grid_array[y][x];
        OBJECT_IDX this_o_idx, next_o_idx = 0;
 
        /* Blind players see nothing */
        if (p_ptr->blind) return;
 
        /* Analyze non-torch-lit grids */
-       if (!(c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
+       if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
        {
                /* Require line of sight to the grid */
-               if (!(c_ptr->info & (CAVE_VIEW))) return;
+               if (!(g_ptr->info & (CAVE_VIEW))) return;
 
                /* Require "perma-lite" of the grid */
-               if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
+               if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
                {
                        /* Not Ninja */
                        if (!p_ptr->see_nocto) return;
@@ -1484,7 +1481,7 @@ void note_spot(POSITION y, POSITION x)
 
 
        /* Hack -- memorize objects */
-       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr = &o_list[this_o_idx];
 
@@ -1497,61 +1494,55 @@ void note_spot(POSITION y, POSITION x)
 
 
        /* Hack -- memorize grids */
-       if (!(c_ptr->info & (CAVE_MARK)))
+       if (!(g_ptr->info & (CAVE_MARK)))
        {
                /* Feature code (applying "mimic" field) */
-               feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
+               feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
 
                /* Memorize some "boring" grids */
                if (!have_flag(f_ptr->flags, FF_REMEMBER))
                {
                        /* Option -- memorize all torch-lit floors */
                        if (view_torch_grids &&
-                           ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
+                           ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
                        {
-                               /* Memorize */
-                               c_ptr->info |= (CAVE_MARK);
+                               g_ptr->info |= (CAVE_MARK);
                        }
 
                        /* Option -- memorize all perma-lit floors */
-                       else if (view_perma_grids && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
+                       else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
                        {
-                               /* Memorize */
-                               c_ptr->info |= (CAVE_MARK);
+                               g_ptr->info |= (CAVE_MARK);
                        }
                }
 
                /* Memorize normal grids */
                else if (have_flag(f_ptr->flags, FF_LOS))
                {
-                       /* Memorize */
-                       c_ptr->info |= (CAVE_MARK);
+                       g_ptr->info |= (CAVE_MARK);
                }
 
                /* Memorize torch-lit walls */
-               else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
+               else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
                {
-                       /* Memorize */
-                       c_ptr->info |= (CAVE_MARK);
+                       g_ptr->info |= (CAVE_MARK);
                }
 
                /* Memorize walls seen by noctovision of Ninja */
                else if (p_ptr->see_nocto)
                {
-                       /* Memorize */
-                       c_ptr->info |= (CAVE_MARK);
+                       g_ptr->info |= (CAVE_MARK);
                }
 
                /* Memorize certain non-torch-lit wall grids */
                else if (check_local_illumination(y, x))
                {
-                       /* Memorize */
-                       c_ptr->info |= (CAVE_MARK);
+                       g_ptr->info |= (CAVE_MARK);
                }
        }
 
        /* Memorize terrain of the grid */
-       c_ptr->info |= (CAVE_KNOWN);
+       g_ptr->info |= (CAVE_KNOWN);
 }
 
 
@@ -1559,10 +1550,10 @@ void display_dungeon(void)
 {
        TERM_LEN x, y;
        TERM_COLOR a;
-       char c;
+       SYMBOL_CODE c;
 
        TERM_COLOR ta = 0;
-       char tc = '\0';
+       SYMBOL_CODE tc = '\0';
 
        for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
        {
@@ -1578,7 +1569,7 @@ void display_dungeon(void)
                                if (!use_graphics)
                                {
                                        if (world_monster) a = TERM_DARK;
-                                       else if (IS_INVULN() || world_player) a = TERM_WHITE;
+                                       else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
                                        else if (p_ptr->wraith_form) a = TERM_L_DARK;
                                }
 
@@ -1617,10 +1608,10 @@ void lite_spot(POSITION y, POSITION x)
        if (panel_contains(y, x) && in_bounds2(y, x))
        {
                TERM_COLOR a;
-               char c;
+               SYMBOL_CODE c;
 
                TERM_COLOR ta;
-               char tc;
+               SYMBOL_CODE tc;
 
                /* Examine the grid */
                map_info(y, x, &a, &c, &ta, &tc);
@@ -1629,7 +1620,7 @@ void lite_spot(POSITION y, POSITION x)
                if (!use_graphics)
                {
                        if (world_monster) a = TERM_DARK;
-                       else if (IS_INVULN() || world_player) a = TERM_WHITE;
+                       else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
                        else if (p_ptr->wraith_form) a = TERM_L_DARK;
                }
 
@@ -1651,13 +1642,13 @@ void lite_spot(POSITION y, POSITION x)
  */
 void prt_map(void)
 {
-       int     x, y;
-       int     v;
+       POSITION x, y;
+       int v;
 
        /* map bounds */
-       s16b xmin, xmax, ymin, ymax;
+       POSITION xmin, xmax, ymin, ymax;
 
-       int wid, hgt;
+       TERM_LEN wid, hgt;
 
        Term_get_size(&wid, &hgt);
 
@@ -1698,10 +1689,10 @@ void prt_map(void)
                for (x = xmin; x <= xmax; x++)
                {
                        TERM_COLOR a;
-                       char c;
+                       SYMBOL_CODE c;
 
                        TERM_COLOR ta;
-                       char tc;
+                       SYMBOL_CODE tc;
 
                        /* Determine what is there */
                        map_info(y, x, &a, &c, &ta, &tc);
@@ -1710,7 +1701,7 @@ void prt_map(void)
                        if (!use_graphics)
                        {
                                if (world_monster) a = TERM_DARK;
-                               else if (IS_INVULN() || world_player) a = TERM_WHITE;
+                               else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
                                else if (p_ptr->wraith_form) a = TERM_L_DARK;
                        }
 
@@ -1753,7 +1744,7 @@ void prt_path(POSITION y, POSITION x)
        {
                POSITION ny = GRID_Y(path_g[i]);
                POSITION nx = GRID_X(path_g[i]);
-               cave_type *c_ptr = &cave[ny][nx];
+               grid_type *g_ptr = &grid_array[ny][nx];
 
                if (panel_contains(ny, nx))
                {
@@ -1763,7 +1754,7 @@ void prt_path(POSITION y, POSITION x)
                        TERM_COLOR ta = default_color;
                        char tc = '*';
 
-                       if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
+                       if (g_ptr->m_idx && m_list[g_ptr->m_idx].ml)
                        {
                                /* Determine what is there */
                                map_info(ny, nx, &a, &c, &ta, &tc);
@@ -1779,7 +1770,7 @@ void prt_path(POSITION y, POSITION x)
                        if (!use_graphics)
                        {
                                if (world_monster) a = TERM_DARK;
-                               else if (IS_INVULN() || world_player) a = TERM_WHITE;
+                               else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
                                else if (p_ptr->wraith_form) a = TERM_L_DARK;
                        }
 
@@ -1790,7 +1781,7 @@ void prt_path(POSITION y, POSITION x)
                }
 
                /* Known Wall */
-               if ((c_ptr->info & CAVE_MARK) && !cave_have_flag_grid(c_ptr, FF_PROJECT)) break;
+               if ((g_ptr->info & CAVE_MARK) && !cave_have_flag_grid(g_ptr, FF_PROJECT)) break;
 
                /* Change color */
                if (nx == x && ny == y) default_color = TERM_L_DARK;
@@ -1798,7 +1789,7 @@ void prt_path(POSITION y, POSITION x)
 }
 
 
-static cptr simplify_list[][2] =
+static concptr simplify_list[][2] =
 {
 #ifdef JP
        {"の魔法書", ""},
@@ -1844,7 +1835,7 @@ static void display_shortened_item_name(object_type *o_ptr, int y)
                int i;
                for (i = 0; simplify_list[i][1]; i++)
                {
-                       cptr org_w = simplify_list[i][0];
+                       concptr org_w = simplify_list[i][0];
 
                        if (*org_w == '^')
                        {
@@ -1857,7 +1848,7 @@ static void display_shortened_item_name(object_type *o_ptr, int y)
                        if (!strncmp(c, org_w, strlen(org_w)))
                        {
                                char *s = c;
-                               cptr tmp = simplify_list[i][1];
+                               concptr tmp = simplify_list[i][1];
                                while (*tmp)
                                        *s++ = *tmp++;
                                tmp = c + strlen(org_w);
@@ -1900,23 +1891,23 @@ void display_map(int *cy, int *cx)
        int i, j, x, y;
 
        TERM_COLOR ta;
-       char tc;
+       SYMBOL_CODE tc;
 
        byte tp;
 
        TERM_COLOR **bigma;
-       char **bigmc;
+       SYMBOL_CODE **bigmc;
        byte **bigmp;
 
        TERM_COLOR **ma;
-       char **mc;
+       SYMBOL_CODE **mc;
        byte **mp;
 
        /* Save lighting effects */
        bool old_view_special_lite = view_special_lite;
        bool old_view_granite_lite = view_granite_lite;
 
-       int hgt, wid, yrat, xrat;
+       TERM_LEN hgt, wid, yrat, xrat;
 
        int **match_autopick_yx;
        object_type ***object_autopick_yx;
@@ -2091,7 +2082,7 @@ void display_map(int *cy, int *cx)
                        if (!use_graphics)
                        {
                                if (world_monster) ta = TERM_DARK;
-                               else if (IS_INVULN() || world_player) ta = TERM_WHITE;
+                               else if (IS_INVULN() || p_ptr->timewalk) ta = TERM_WHITE;
                                else if (p_ptr->wraith_form) ta = TERM_L_DARK;
                        }
 
@@ -2146,7 +2137,7 @@ void display_map(int *cy, int *cx)
        {
                /* Free one row each array */
                C_KILL(ma[y], (wid + 2), TERM_COLOR);
-               C_KILL(mc[y], (wid + 2), char);
+               C_KILL(mc[y], (wid + 2), SYMBOL_CODE);
                C_KILL(mp[y], (wid + 2), byte);
                C_KILL(match_autopick_yx[y], (wid + 2), int);
                C_KILL(object_autopick_yx[y], (wid + 2), object_type *);
@@ -2164,7 +2155,7 @@ void display_map(int *cy, int *cx)
        {
                /* Free one row each array */
                C_KILL(bigma[y], (cur_wid + 2), TERM_COLOR);
-               C_KILL(bigmc[y], (cur_wid + 2), char);
+               C_KILL(bigmc[y], (cur_wid + 2), SYMBOL_CODE);
                C_KILL(bigmp[y], (cur_wid + 2), byte);
        }
 
@@ -2186,12 +2177,9 @@ void do_cmd_view_map(void)
 
        screen_save();
 
-       /* Note */
        prt(_("お待ち下さい...", "Please wait..."), 0, 0);
 
        Term_fresh();
-
-       /* Clear the screen */
        Term_clear();
 
        display_autopick = 0;
@@ -2254,8 +2242,6 @@ void do_cmd_view_map(void)
                /* Get any key */
                inkey();
        }
-
-       /* Restore the screen */
        screen_load();
 }
 
@@ -2264,7 +2250,7 @@ void do_cmd_view_map(void)
 
 
 /*
- * Some comments on the cave grid flags.  -BEN-
+ * Some comments on the grid flags.  -BEN-
  *
  *
  * One of the major bottlenecks in previous versions of Angband was in
@@ -2493,7 +2479,7 @@ void forget_lite(void)
                x = lite_x[i];
 
                /* Forget "LITE" flag */
-               cave[y][x].info &= ~(CAVE_LITE);
+               grid_array[y][x].info &= ~(CAVE_LITE);
 
                /* lite_spot(y, x); Perhaps don't need? */
        }
@@ -2535,9 +2521,9 @@ void forget_lite(void)
  */
 #define cave_lite_hack(Y,X) \
 {\
-       if (!(cave[Y][X].info & (CAVE_LITE))) \
+       if (!(grid_array[Y][X].info & (CAVE_LITE))) \
        { \
-               cave[Y][X].info |= (CAVE_LITE); \
+               grid_array[Y][X].info |= (CAVE_LITE); \
                lite_y[lite_n] = (Y); \
                lite_x[lite_n++] = (X); \
        } \
@@ -2570,9 +2556,10 @@ void forget_lite(void)
  */
 void update_lite(void)
 {
-       int i, x, y, min_x, max_x, min_y, max_y;
+       int i;
+       POSITION x, y, min_x, max_x, min_y, max_y;
        int p = p_ptr->cur_lite;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /*** Special case ***/
 
@@ -2584,7 +2571,7 @@ void update_lite(void)
                /* forget_lite(); Perhaps don't need? */
 
                /* Add it to later visual update */
-               cave_redraw_later(&cave[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
+               cave_redraw_later(&grid_array[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
        }
 #endif
 
@@ -2597,10 +2584,10 @@ void update_lite(void)
                x = lite_x[i];
 
                /* Mark the grid as not "lite" */
-               cave[y][x].info &= ~(CAVE_LITE);
+               grid_array[y][x].info &= ~(CAVE_LITE);
 
                /* Mark the grid as "seen" */
-               cave[y][x].info |= (CAVE_TEMP);
+               grid_array[y][x].info |= (CAVE_TEMP);
 
                /* Add it to the "seen" set */
                temp_y[temp_n] = y;
@@ -2735,7 +2722,7 @@ void update_lite(void)
                                if (d > p) continue;
 
                                /* Viewable, nearby, grids get "torch lit" */
-                               if (cave[y][x].info & CAVE_VIEW)
+                               if (grid_array[y][x].info & CAVE_VIEW)
                                {
                                        /* This grid is "torch lit" */
                                        cave_lite_hack(y, x);
@@ -2753,13 +2740,13 @@ void update_lite(void)
                y = lite_y[i];
                x = lite_x[i];
 
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Update fresh grids */
-               if (c_ptr->info & (CAVE_TEMP)) continue;
+               if (g_ptr->info & (CAVE_TEMP)) continue;
 
                /* Add it to later visual update */
-               cave_note_and_redraw_later(c_ptr, y, x);
+               cave_note_and_redraw_later(g_ptr, y, x);
        }
 
        /* Clear them all */
@@ -2768,16 +2755,16 @@ void update_lite(void)
                y = temp_y[i];
                x = temp_x[i];
 
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* No longer in the array */
-               c_ptr->info &= ~(CAVE_TEMP);
+               g_ptr->info &= ~(CAVE_TEMP);
 
                /* Update stale grids */
-               if (c_ptr->info & (CAVE_LITE)) continue;
+               if (g_ptr->info & (CAVE_LITE)) continue;
 
                /* Add it to later visual update */
-               cave_redraw_later(c_ptr, y, x);
+               cave_redraw_later(g_ptr, y, x);
        }
 
        /* None left */
@@ -2796,19 +2783,19 @@ static POSITION mon_fy, mon_fx;
  */
 static void mon_lite_hack(POSITION y, POSITION x)
 {
-       cave_type *c_ptr;
+       grid_type *g_ptr;
        int dpf, d;
        POSITION midpoint;
 
        /* We trust this grid is in bounds */
        /* if (!in_bounds2(y, x)) return; */
 
-       c_ptr = &cave[y][x];
+       g_ptr = &grid_array[y][x];
 
        /* Want a unlit square in view of the player */
-       if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
+       if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
 
-       if (!cave_los_grid(c_ptr))
+       if (!cave_los_grid(g_ptr))
        {
                /* Hack -- Prevent monster lite leakage in walls */
 
@@ -2858,7 +2845,7 @@ static void mon_lite_hack(POSITION y, POSITION x)
        /* We trust temp_n does not exceed TEMP_MAX */
 
        /* New grid */
-       if (!(c_ptr->info & CAVE_MNDK))
+       if (!(g_ptr->info & CAVE_MNDK))
        {
                /* Save this square */
                temp_x[temp_n] = x;
@@ -2870,11 +2857,11 @@ static void mon_lite_hack(POSITION y, POSITION x)
        else
        {
                /* No longer dark */
-               c_ptr->info &= ~(CAVE_MNDK);
+               g_ptr->info &= ~(CAVE_MNDK);
        }
 
        /* Light it */
-       c_ptr->info |= CAVE_MNLT;
+       g_ptr->info |= CAVE_MNLT;
 }
 
 
@@ -2883,18 +2870,18 @@ static void mon_lite_hack(POSITION y, POSITION x)
  */
 static void mon_dark_hack(POSITION y, POSITION x)
 {
-       cave_type *c_ptr;
+       grid_type *g_ptr;
        int       midpoint, dpf, d;
 
        /* We trust this grid is in bounds */
        /* if (!in_bounds2(y, x)) return; */
 
-       c_ptr = &cave[y][x];
+       g_ptr = &grid_array[y][x];
 
        /* Want a unlit and undarkened square in view of the player */
-       if ((c_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
+       if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
 
-       if (!cave_los_grid(c_ptr) && !cave_have_flag_grid(c_ptr, FF_PROJECT))
+       if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
        {
                /* Hack -- Prevent monster dark lite leakage in walls */
 
@@ -2949,7 +2936,7 @@ static void mon_dark_hack(POSITION y, POSITION x)
        temp_n++;
 
        /* Darken it */
-       c_ptr->info |= CAVE_MNDK;
+       g_ptr->info |= CAVE_MNDK;
 }
 
 
@@ -2966,7 +2953,7 @@ static void mon_dark_hack(POSITION y, POSITION x)
 void update_mon_lite(void)
 {
        int i, rad;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        POSITION fx, fy;
        void (*add_mon_lite)(POSITION, POSITION);
@@ -2975,20 +2962,20 @@ void update_mon_lite(void)
        s16b end_temp;
 
        /* Non-Ninja player in the darkness */
-       int dis_lim = ((d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
+       int dis_lim = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
                (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
 
        /* Clear all monster lit squares */
        for (i = 0; i < mon_lite_n; i++)
        {
                /* Point to grid */
-               c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
+               g_ptr = &grid_array[mon_lite_y[i]][mon_lite_x[i]];
 
                /* Set temp or xtra flag */
-               c_ptr->info |= (c_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
+               g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
 
                /* Clear monster illumination flag */
-               c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
+               g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
        }
 
        /* Empty temp list of new squares to lite up */
@@ -3026,7 +3013,7 @@ void update_mon_lite(void)
                        else if (rad > 0)
                        {
                                if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
-                               if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
+                               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
                                add_mon_lite = mon_lite_hack;
                                f_flag = FF_LOS;
                        }
@@ -3043,7 +3030,7 @@ void update_mon_lite(void)
                        mon_fy = m_ptr->fy;
 
                        /* Is the monster visible? */
-                       mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
+                       mon_invis = !(grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
 
                        /* The square it is on */
                        add_mon_lite(mon_fy, mon_fx);
@@ -3068,10 +3055,10 @@ void update_mon_lite(void)
                                        add_mon_lite(mon_fy + 2, mon_fx);
                                        add_mon_lite(mon_fy + 2, mon_fx - 1);
 
-                                       c_ptr = &cave[mon_fy + 2][mon_fx];
+                                       g_ptr = &grid_array[mon_fy + 2][mon_fx];
 
                                        /* Radius 3 */
-                                       if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
+                                       if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
                                        {
                                                add_mon_lite(mon_fy + 3, mon_fx + 1);
                                                add_mon_lite(mon_fy + 3, mon_fx);
@@ -3086,10 +3073,10 @@ void update_mon_lite(void)
                                        add_mon_lite(mon_fy - 2, mon_fx);
                                        add_mon_lite(mon_fy - 2, mon_fx - 1);
 
-                                       c_ptr = &cave[mon_fy - 2][mon_fx];
+                                       g_ptr = &grid_array[mon_fy - 2][mon_fx];
 
                                        /* Radius 3 */
-                                       if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
+                                       if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
                                        {
                                                add_mon_lite(mon_fy - 3, mon_fx + 1);
                                                add_mon_lite(mon_fy - 3, mon_fx);
@@ -3104,10 +3091,10 @@ void update_mon_lite(void)
                                        add_mon_lite(mon_fy, mon_fx + 2);
                                        add_mon_lite(mon_fy - 1, mon_fx + 2);
 
-                                       c_ptr = &cave[mon_fy][mon_fx + 2];
+                                       g_ptr = &grid_array[mon_fy][mon_fx + 2];
 
                                        /* Radius 3 */
-                                       if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
+                                       if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
                                        {
                                                add_mon_lite(mon_fy + 1, mon_fx + 3);
                                                add_mon_lite(mon_fy, mon_fx + 3);
@@ -3122,10 +3109,10 @@ void update_mon_lite(void)
                                        add_mon_lite(mon_fy, mon_fx - 2);
                                        add_mon_lite(mon_fy - 1, mon_fx - 2);
 
-                                       c_ptr = &cave[mon_fy][mon_fx - 2];
+                                       g_ptr = &grid_array[mon_fy][mon_fx - 2];
 
                                        /* Radius 3 */
-                                       if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
+                                       if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
                                        {
                                                add_mon_lite(mon_fy + 1, mon_fx - 3);
                                                add_mon_lite(mon_fy, mon_fx - 3);
@@ -3178,26 +3165,26 @@ void update_mon_lite(void)
                /* We trust this grid is in bounds */
 
                /* Point to grid */
-               c_ptr = &cave[fy][fx];
+               g_ptr = &grid_array[fy][fx];
 
-               if (c_ptr->info & CAVE_TEMP) /* Pervious lit */
+               if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
                {
                        /* It it no longer lit? */
-                       if ((c_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
+                       if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
                        {
                                /* It is now unlit */
                                /* Add it to later visual update */
-                               cave_note_and_redraw_later(c_ptr, fy, fx);
+                               cave_note_and_redraw_later(g_ptr, fy, fx);
                        }
                }
                else /* Pervious darkened */
                {
                        /* It it no longer darken? */
-                       if ((c_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
+                       if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
                        {
                                /* It is now undarken */
                                /* Add it to later visual update */
-                               cave_note_and_redraw_later(c_ptr, fy, fx);
+                               cave_note_and_redraw_later(g_ptr, fy, fx);
                        }
                }
 
@@ -3219,26 +3206,26 @@ void update_mon_lite(void)
                /* We trust this grid is in bounds */
 
                /* Point to grid */
-               c_ptr = &cave[fy][fx];
+               g_ptr = &grid_array[fy][fx];
 
-               if (c_ptr->info & CAVE_MNLT) /* Lit */
+               if (g_ptr->info & CAVE_MNLT) /* Lit */
                {
                        /* The is the square newly lit and visible? */
-                       if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
+                       if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
                        {
                                /* It is now lit */
                                /* Add it to later visual update */
-                               cave_note_and_redraw_later(c_ptr, fy, fx);
+                               cave_note_and_redraw_later(g_ptr, fy, fx);
                        }
                }
                else /* Darkened */
                {
                        /* The is the square newly darkened and visible? */
-                       if ((c_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
+                       if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
                        {
                                /* It is now darkened */
                                /* Add it to later visual update */
-                               cave_note_and_redraw_later(c_ptr, fy, fx);
+                               cave_note_and_redraw_later(g_ptr, fy, fx);
                        }
                }
 
@@ -3253,7 +3240,7 @@ void update_mon_lite(void)
        {
                /* We trust this grid is in bounds */
 
-               cave[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
+               grid_array[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
        }
 
        /* Finished with temp_n */
@@ -3262,7 +3249,7 @@ void update_mon_lite(void)
        /* Mega-Hack -- Visual update later */
        p_ptr->update |= (PU_DELAY_VIS);
 
-       p_ptr->monlite = (cave[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
+       p_ptr->monlite = (grid_array[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
 
        if (p_ptr->special_defense & NINJA_S_STEALTH)
        {
@@ -3284,16 +3271,16 @@ void update_mon_lite(void)
 void clear_mon_lite(void)
 {
        int i;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /* Clear all monster lit squares */
        for (i = 0; i < mon_lite_n; i++)
        {
                /* Point to grid */
-               c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
+               g_ptr = &grid_array[mon_lite_y[i]][mon_lite_x[i]];
 
                /* Clear monster illumination flag */
-               c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
+               g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
        }
 
        /* Empty the array */
@@ -3309,7 +3296,7 @@ void forget_view(void)
 {
        int i;
 
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /* None to forget */
        if (!view_n) return;
@@ -3319,10 +3306,10 @@ void forget_view(void)
        {
                POSITION y = view_y[i];
                POSITION x = view_x[i];
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Forget that the grid is viewable */
-               c_ptr->info &= ~(CAVE_VIEW);
+               g_ptr->info &= ~(CAVE_VIEW);
 
                /* if (!panel_contains(y, x)) continue; */
 
@@ -3374,14 +3361,14 @@ static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, PO
 {
        bool f1, f2, v1, v2, z1, z2, wall;
 
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
-       cave_type *g1_c_ptr;
-       cave_type *g2_c_ptr;
+       grid_type *g1_c_ptr;
+       grid_type *g2_c_ptr;
 
        /* Access the grids */
-       g1_c_ptr = &cave[y1][x1];
-       g2_c_ptr = &cave[y2][x2];
+       g1_c_ptr = &grid_array[y1][x1];
+       g2_c_ptr = &grid_array[y2][x2];
 
 
        /* Check for walls */
@@ -3399,11 +3386,11 @@ static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, PO
        /* Totally blocked by "unviewable neighbors" */
        if (!v1 && !v2) return (TRUE);
 
-       c_ptr = &cave[y][x];
+       g_ptr = &grid_array[y][x];
 
 
        /* Check for walls */
-       wall = (!cave_los_grid(c_ptr));
+       wall = (!cave_los_grid(g_ptr));
 
 
        /* Check the "ease" of visibility */
@@ -3413,9 +3400,9 @@ static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, PO
        /* Hack -- "easy" plus "easy" yields "easy" */
        if (z1 && z2)
        {
-               c_ptr->info |= (CAVE_XTRA);
+               g_ptr->info |= (CAVE_XTRA);
 
-               cave_view_hack(c_ptr, y, x);
+               cave_view_hack(g_ptr, y, x);
 
                return (wall);
        }
@@ -3423,7 +3410,7 @@ static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, PO
        /* Hack -- primary "easy" yields "viewed" */
        if (z1)
        {
-               cave_view_hack(c_ptr, y, x);
+               cave_view_hack(g_ptr, y, x);
 
                return (wall);
        }
@@ -3431,9 +3418,9 @@ static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, PO
        /* Hack -- "view" plus "view" yields "view" */
        if (v1 && v2)
        {
-               /* c_ptr->info |= (CAVE_XTRA); */
+               /* g_ptr->info |= (CAVE_XTRA); */
 
-               cave_view_hack(c_ptr, y, x);
+               cave_view_hack(g_ptr, y, x);
 
                return (wall);
        }
@@ -3442,7 +3429,7 @@ static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, PO
        /* Mega-Hack -- the "los()" function works poorly on walls */
        if (wall)
        {
-               cave_view_hack(c_ptr, y, x);
+               cave_view_hack(g_ptr, y, x);
 
                return (wall);
        }
@@ -3451,7 +3438,7 @@ static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, PO
        /* Hack -- check line of sight */
        if (los(p_ptr->y, p_ptr->x, y, x))
        {
-               cave_view_hack(c_ptr, y, x);
+               cave_view_hack(g_ptr, y, x);
 
                return (wall);
        }
@@ -3537,10 +3524,10 @@ static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, PO
  *
  * Note the use of "inline" macros for efficiency.  The "cave_los_grid()"
  * macro is a replacement for "cave_los_bold()" which takes a pointer to
- * a cave grid instead of its location.  The "cave_view_hack()" macro is a
+ * a grid instead of its location.  The "cave_view_hack()" macro is a
  * chunk of code which adds the given location to the "view" array if it
  * is not already there, using both the actual location and a pointer to
- * the cave grid.  See above.
+ * the grid.  See above.
  *
  * By the way, the purpose of this code is to reduce the dependancy on the
  * "los()" function which is slow, and, in some cases, not very accurate.
@@ -3566,7 +3553,7 @@ void update_view(void)
        POSITION y_max = cur_hgt - 1;
        POSITION x_max = cur_wid - 1;
 
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /*** Initialize ***/
 
@@ -3598,13 +3585,13 @@ void update_view(void)
        {
                y = view_y[n];
                x = view_x[n];
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Mark the grid as not in "view" */
-               c_ptr->info &= ~(CAVE_VIEW);
+               g_ptr->info &= ~(CAVE_VIEW);
 
                /* Mark the grid as "seen" */
-               c_ptr->info |= (CAVE_TEMP);
+               g_ptr->info |= (CAVE_TEMP);
 
                /* Add it to the "seen" set */
                temp_y[temp_n] = y;
@@ -3620,13 +3607,13 @@ void update_view(void)
        /* Now start on the player */
        y = p_ptr->y;
        x = p_ptr->x;
-       c_ptr = &cave[y][x];
+       g_ptr = &grid_array[y][x];
 
        /* Assume the player grid is easily viewable */
-       c_ptr->info |= (CAVE_XTRA);
+       g_ptr->info |= (CAVE_XTRA);
 
        /* Assume the player grid is viewable */
-       cave_view_hack(c_ptr, y, x);
+       cave_view_hack(g_ptr, y, x);
 
 
        /*** Step 2 -- Major Diagonals ***/
@@ -3637,49 +3624,48 @@ void update_view(void)
        /* Scan south-east */
        for (d = 1; d <= z; d++)
        {
-               c_ptr = &cave[y+d][x+d];
-               c_ptr->info |= (CAVE_XTRA);
-               cave_view_hack(c_ptr, y+d, x+d);
-               if (!cave_los_grid(c_ptr)) break;
+               g_ptr = &grid_array[y+d][x+d];
+               g_ptr->info |= (CAVE_XTRA);
+               cave_view_hack(g_ptr, y+d, x+d);
+               if (!cave_los_grid(g_ptr)) break;
        }
 
        /* Scan south-west */
        for (d = 1; d <= z; d++)
        {
-               c_ptr = &cave[y+d][x-d];
-               c_ptr->info |= (CAVE_XTRA);
-               cave_view_hack(c_ptr, y+d, x-d);
-               if (!cave_los_grid(c_ptr)) break;
+               g_ptr = &grid_array[y+d][x-d];
+               g_ptr->info |= (CAVE_XTRA);
+               cave_view_hack(g_ptr, y+d, x-d);
+               if (!cave_los_grid(g_ptr)) break;
        }
 
        /* Scan north-east */
        for (d = 1; d <= z; d++)
        {
-               c_ptr = &cave[y-d][x+d];
-               c_ptr->info |= (CAVE_XTRA);
-               cave_view_hack(c_ptr, y-d, x+d);
-               if (!cave_los_grid(c_ptr)) break;
+               g_ptr = &grid_array[y-d][x+d];
+               g_ptr->info |= (CAVE_XTRA);
+               cave_view_hack(g_ptr, y-d, x+d);
+               if (!cave_los_grid(g_ptr)) break;
        }
 
        /* Scan north-west */
        for (d = 1; d <= z; d++)
        {
-               c_ptr = &cave[y-d][x-d];
-               c_ptr->info |= (CAVE_XTRA);
-               cave_view_hack(c_ptr, y-d, x-d);
-               if (!cave_los_grid(c_ptr)) break;
+               g_ptr = &grid_array[y-d][x-d];
+               g_ptr->info |= (CAVE_XTRA);
+               cave_view_hack(g_ptr, y-d, x-d);
+               if (!cave_los_grid(g_ptr)) break;
        }
 
-
        /*** Step 3 -- major axes ***/
 
        /* Scan south */
        for (d = 1; d <= full; d++)
        {
-               c_ptr = &cave[y+d][x];
-               c_ptr->info |= (CAVE_XTRA);
-               cave_view_hack(c_ptr, y+d, x);
-               if (!cave_los_grid(c_ptr)) break;
+               g_ptr = &grid_array[y+d][x];
+               g_ptr->info |= (CAVE_XTRA);
+               cave_view_hack(g_ptr, y+d, x);
+               if (!cave_los_grid(g_ptr)) break;
        }
 
        /* Initialize the "south strips" */
@@ -3688,10 +3674,10 @@ void update_view(void)
        /* Scan north */
        for (d = 1; d <= full; d++)
        {
-               c_ptr = &cave[y-d][x];
-               c_ptr->info |= (CAVE_XTRA);
-               cave_view_hack(c_ptr, y-d, x);
-               if (!cave_los_grid(c_ptr)) break;
+               g_ptr = &grid_array[y-d][x];
+               g_ptr->info |= (CAVE_XTRA);
+               cave_view_hack(g_ptr, y-d, x);
+               if (!cave_los_grid(g_ptr)) break;
        }
 
        /* Initialize the "north strips" */
@@ -3700,10 +3686,10 @@ void update_view(void)
        /* Scan east */
        for (d = 1; d <= full; d++)
        {
-               c_ptr = &cave[y][x+d];
-               c_ptr->info |= (CAVE_XTRA);
-               cave_view_hack(c_ptr, y, x+d);
-               if (!cave_los_grid(c_ptr)) break;
+               g_ptr = &grid_array[y][x+d];
+               g_ptr->info |= (CAVE_XTRA);
+               cave_view_hack(g_ptr, y, x+d);
+               if (!cave_los_grid(g_ptr)) break;
        }
 
        /* Initialize the "east strips" */
@@ -3712,10 +3698,10 @@ void update_view(void)
        /* Scan west */
        for (d = 1; d <= full; d++)
        {
-               c_ptr = &cave[y][x-d];
-               c_ptr->info |= (CAVE_XTRA);
-               cave_view_hack(c_ptr, y, x-d);
-               if (!cave_los_grid(c_ptr)) break;
+               g_ptr = &grid_array[y][x-d];
+               g_ptr->info |= (CAVE_XTRA);
+               cave_view_hack(g_ptr, y, x-d);
+               if (!cave_los_grid(g_ptr)) break;
        }
 
        /* Initialize the "west strips" */
@@ -3727,8 +3713,7 @@ void update_view(void)
        /* Now check each "diagonal" (in parallel) */
        for (n = 1; n <= over / 2; n++)
        {
-               int ypn, ymn, xpn, xmn;
-
+               POSITION ypn, ymn, xpn, xmn;
 
                /* Acquire the "bounds" of the maximal circle */
                z = over - n - n;
@@ -3967,16 +3952,16 @@ void update_view(void)
        {
                y = view_y[n];
                x = view_x[n];
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Clear the "CAVE_XTRA" flag */
-               c_ptr->info &= ~(CAVE_XTRA);
+               g_ptr->info &= ~(CAVE_XTRA);
 
                /* Update only newly viewed grids */
-               if (c_ptr->info & (CAVE_TEMP)) continue;
+               if (g_ptr->info & (CAVE_TEMP)) continue;
 
                /* Add it to later visual update */
-               cave_note_and_redraw_later(c_ptr, y, x);
+               cave_note_and_redraw_later(g_ptr, y, x);
        }
 
        /* Wipe the old grids, update as needed */
@@ -3984,16 +3969,16 @@ void update_view(void)
        {
                y = temp_y[n];
                x = temp_x[n];
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* No longer in the array */
-               c_ptr->info &= ~(CAVE_TEMP);
+               g_ptr->info &= ~(CAVE_TEMP);
 
                /* Update only non-viewable grids */
-               if (c_ptr->info & (CAVE_VIEW)) continue;
+               if (g_ptr->info & (CAVE_VIEW)) continue;
 
                /* Add it to later visual update */
-               cave_redraw_later(c_ptr, y, x);
+               cave_redraw_later(g_ptr, y, x);
        }
 
        /* None left */
@@ -4010,29 +3995,30 @@ void update_view(void)
  */
 void delayed_visual_update(void)
 {
-       int       i, y, x;
-       cave_type *c_ptr;
+       int i;
+       POSITION y, x;
+       grid_type *g_ptr;
 
        /* Update needed grids */
        for (i = 0; i < redraw_n; i++)
        {
                y = redraw_y[i];
                x = redraw_x[i];
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Update only needed grids (prevent multiple updating) */
-               if (!(c_ptr->info & CAVE_REDRAW)) continue;
+               if (!(g_ptr->info & CAVE_REDRAW)) continue;
 
                /* If required, note */
-               if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
+               if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
 
                lite_spot(y, x);
 
                /* Hack -- Visual update of monster on this grid */
-               if (c_ptr->m_idx) update_monster(c_ptr->m_idx, FALSE);
+               if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
 
                /* No longer in the array */
-               c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
+               g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
        }
 
        /* None left */
@@ -4053,9 +4039,9 @@ void forget_flow(void)
                for (x = 0; x < cur_wid; x++)
                {
                        /* Forget the old data */
-                       cave[y][x].dist = 0;
-                       cave[y][x].cost = 0;
-                       cave[y][x].when = 0;
+                       grid_array[y][x].dist = 0;
+                       grid_array[y][x].cost = 0;
+                       grid_array[y][x].when = 0;
                }
        }
 }
@@ -4086,7 +4072,8 @@ static POSITION flow_y = 0;
  */
 void update_flow(void)
 {
-       POSITION x, y, d;
+       POSITION x, y;
+       DIRECTION d;
        int flow_head = 1;
        int flow_tail = 0;
 
@@ -4097,7 +4084,7 @@ void update_flow(void)
        if (running && in_bounds(flow_y, flow_x))
        {
                /* The way point is in sight - do not update.  (Speedup) */
-               if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
+               if (grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
        }
 
        /* Erase all of the current flow information */
@@ -4105,8 +4092,8 @@ void update_flow(void)
        {
                for (x = 0; x < cur_wid; x++)
                {
-                       cave[y][x].cost = 0;
-                       cave[y][x].dist = 0;
+                       grid_array[y][x].cost = 0;
+                       grid_array[y][x].dist = 0;
                }
        }
 
@@ -4134,9 +4121,9 @@ void update_flow(void)
                for (d = 0; d < 8; d++)
                {
                        int old_head = flow_head;
-                       byte_hack m = cave[ty][tx].cost + 1;
-                       byte_hack n = cave[ty][tx].dist + 1;
-                       cave_type *c_ptr;
+                       byte_hack m = grid_array[ty][tx].cost + 1;
+                       byte_hack n = grid_array[ty][tx].dist + 1;
+                       grid_type *g_ptr;
 
                        /* Child location */
                        y = ty + ddy_ddd[d];
@@ -4145,19 +4132,19 @@ void update_flow(void)
                        /* Ignore player's grid */
                        if (player_bold(y, x)) continue;
 
-                       c_ptr = &cave[y][x];
+                       g_ptr = &grid_array[y][x];
 
-                       if (is_closed_door(c_ptr->feat)) m += 3;
+                       if (is_closed_door(g_ptr->feat)) m += 3;
 
                        /* Ignore "pre-stamped" entries */
-                       if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
+                       if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
 
                        /* Ignore "walls" and "rubble" */
-                       if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
+                       if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
 
                        /* Save the flow cost */
-                       if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
-                       if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
+                       if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
+                       if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
 
                        /* Hack -- limit flow depth */
                        if (n == MONSTER_FLOW_DEPTH) continue;
@@ -4217,8 +4204,8 @@ void update_smell(void)
                {
                        for (x = 0; x < cur_wid; x++)
                        {
-                               int w = cave[y][x].when;
-                               cave[y][x].when = (w > 128) ? (w - 128) : 0;
+                               int w = grid_array[y][x].when;
+                               grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
                        }
                }
 
@@ -4232,7 +4219,7 @@ void update_smell(void)
        {
                for (j = 0; j < 5; j++)
                {
-                       cave_type *c_ptr;
+                       grid_type *g_ptr;
 
                        /* Translate table to map grids */
                        y = i + p_ptr->y - 2;
@@ -4241,10 +4228,10 @@ void update_smell(void)
                        /* Check Bounds */
                        if (!in_bounds(y, x)) continue;
 
-                       c_ptr = &cave[y][x];
+                       g_ptr = &grid_array[y][x];
 
                        /* Walls, water, and lava cannot hold scent. */
-                       if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
+                       if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
 
                        /* Grid must not be blocked by walls from the character */
                        if (!player_has_los_bold(y, x)) continue;
@@ -4253,7 +4240,7 @@ void update_smell(void)
                        if (scent_adjust[i][j] == -1) continue;
 
                        /* Mark the grid with new scent */
-                       c_ptr->when = scent_when + scent_adjust[i][j];
+                       g_ptr->when = scent_when + scent_adjust[i][j];
                }
        }
 }
@@ -4266,11 +4253,11 @@ void map_area(POSITION range)
 {
        int i;
        POSITION x, y;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
        FEAT_IDX feat;
        feature_type *f_ptr;
 
-       if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
+       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) range /= 3;
 
        /* Scan that area */
        for (y = 1; y < cur_hgt - 1; y++)
@@ -4279,13 +4266,13 @@ void map_area(POSITION range)
                {
                        if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
 
-                       c_ptr = &cave[y][x];
+                       g_ptr = &grid_array[y][x];
 
                        /* Memorize terrain of the grid */
-                       c_ptr->info |= (CAVE_KNOWN);
+                       g_ptr->info |= (CAVE_KNOWN);
 
                        /* Feature code (applying "mimic" field) */
-                       feat = get_feat_mimic(c_ptr);
+                       feat = get_feat_mimic(g_ptr);
                        f_ptr = &f_info[feat];
 
                        /* All non-walls are "checked" */
@@ -4295,23 +4282,23 @@ void map_area(POSITION range)
                                if (have_flag(f_ptr->flags, FF_REMEMBER))
                                {
                                        /* Memorize the object */
-                                       c_ptr->info |= (CAVE_MARK);
+                                       g_ptr->info |= (CAVE_MARK);
                                }
 
                                /* Memorize known walls */
                                for (i = 0; i < 8; i++)
                                {
-                                       c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
+                                       g_ptr = &grid_array[y + ddy_ddd[i]][x + ddx_ddd[i]];
 
                                        /* Feature code (applying "mimic" field) */
-                                       feat = get_feat_mimic(c_ptr);
+                                       feat = get_feat_mimic(g_ptr);
                                        f_ptr = &f_info[feat];
 
                                        /* Memorize walls (etc) */
                                        if (have_flag(f_ptr->flags, FF_REMEMBER))
                                        {
                                                /* Memorize the walls */
-                                               c_ptr->info |= (CAVE_MARK);
+                                               g_ptr->info |= (CAVE_MARK);
                                        }
                                }
                        }
@@ -4369,13 +4356,13 @@ void wiz_lite(bool ninja)
                /* Scan all normal grids */
                for (x = 1; x < cur_wid - 1; x++)
                {
-                       cave_type *c_ptr = &cave[y][x];
+                       grid_type *g_ptr = &grid_array[y][x];
 
                        /* Memorize terrain of the grid */
-                       c_ptr->info |= (CAVE_KNOWN);
+                       g_ptr->info |= (CAVE_KNOWN);
 
                        /* Feature code (applying "mimic" field) */
-                       feat = get_feat_mimic(c_ptr);
+                       feat = get_feat_mimic(g_ptr);
                        f_ptr = &f_info[feat];
 
                        /* Process all non-walls */
@@ -4386,34 +4373,32 @@ void wiz_lite(bool ninja)
                                {
                                        POSITION yy = y + ddy_ddd[i];
                                        POSITION xx = x + ddx_ddd[i];
-
-                                       /* Get the grid */
-                                       c_ptr = &cave[yy][xx];
+                                       g_ptr = &grid_array[yy][xx];
 
                                        /* Feature code (applying "mimic" field) */
-                                       f_ptr = &f_info[get_feat_mimic(c_ptr)];
+                                       f_ptr = &f_info[get_feat_mimic(g_ptr)];
 
                                        /* Perma-lite the grid */
-                                       if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS) && !ninja)
+                                       if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !ninja)
                                        {
-                                               c_ptr->info |= (CAVE_GLOW);
+                                               g_ptr->info |= (CAVE_GLOW);
                                        }
 
                                        /* Memorize normal features */
                                        if (have_flag(f_ptr->flags, FF_REMEMBER))
                                        {
                                                /* Memorize the grid */
-                                               c_ptr->info |= (CAVE_MARK);
+                                               g_ptr->info |= (CAVE_MARK);
                                        }
 
                                        /* Perma-lit grids (newly and previously) */
-                                       else if (c_ptr->info & CAVE_GLOW)
+                                       else if (g_ptr->info & CAVE_GLOW)
                                        {
                                                /* Normally, memorize floors (see above) */
                                                if (view_perma_grids && !view_torch_grids)
                                                {
                                                        /* Memorize the grid */
-                                                       c_ptr->info |= (CAVE_MARK);
+                                                       g_ptr->info |= (CAVE_MARK);
                                                }
                                        }
                                }
@@ -4427,7 +4412,7 @@ void wiz_lite(bool ninja)
 
        if (p_ptr->special_defense & NINJA_S_STEALTH)
        {
-               if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
+               if (grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
        }
 }
 
@@ -4445,26 +4430,26 @@ void wiz_dark(void)
        {
                for (x = 1; x < cur_wid - 1; x++)
                {
-                       cave_type *c_ptr = &cave[y][x];
+                       grid_type *g_ptr = &grid_array[y][x];
 
                        /* Process the grid */
-                       c_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT | CAVE_KNOWN);
-                       c_ptr->info |= (CAVE_UNSAFE);
+                       g_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT | CAVE_KNOWN);
+                       g_ptr->info |= (CAVE_UNSAFE);
                }
        }
 
        /* Forget every grid on horizontal edge */
        for (x = 0; x < cur_wid; x++)
        {
-               cave[0][x].info &= ~(CAVE_MARK);
-               cave[cur_hgt - 1][x].info &= ~(CAVE_MARK);
+               grid_array[0][x].info &= ~(CAVE_MARK);
+               grid_array[cur_hgt - 1][x].info &= ~(CAVE_MARK);
        }
 
        /* Forget every grid on vertical edge */
        for (y = 1; y < (cur_hgt - 1); y++)
        {
-               cave[y][0].info &= ~(CAVE_MARK);
-               cave[y][cur_wid - 1].info &= ~(CAVE_MARK);
+               grid_array[y][0].info &= ~(CAVE_MARK);
+               grid_array[y][cur_wid - 1].info &= ~(CAVE_MARK);
        }
 
        /* Forget all objects */
@@ -4497,20 +4482,20 @@ void wiz_dark(void)
  */
 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
 {
-       cave_type *c_ptr = &cave[y][x];
+       grid_type *g_ptr = &grid_array[y][x];
        feature_type *f_ptr = &f_info[feat];
        bool old_los, old_mirror;
 
        if (!character_dungeon)
        {
                /* Clear mimic type */
-               c_ptr->mimic = 0;
+               g_ptr->mimic = 0;
 
                /* Change the feature */
-               c_ptr->feat = feat;
+               g_ptr->feat = feat;
 
                /* Hack -- glow the GLOW terrain */
-               if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
+               if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
                {
                        DIRECTION i;
                        POSITION yy, xx;
@@ -4520,7 +4505,7 @@ void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
                                yy = y + ddy_ddd[i];
                                xx = x + ddx_ddd[i];
                                if (!in_bounds2(yy, xx)) continue;
-                               cave[yy][xx].info |= CAVE_GLOW;
+                               grid_array[yy][xx].info |= CAVE_GLOW;
                        }
                }
 
@@ -4528,28 +4513,28 @@ void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
        }
 
        old_los = cave_have_flag_bold(y, x, FF_LOS);
-       old_mirror = is_mirror_grid(c_ptr);
+       old_mirror = is_mirror_grid(g_ptr);
 
        /* Clear mimic type */
-       c_ptr->mimic = 0;
+       g_ptr->mimic = 0;
 
        /* Change the feature */
-       c_ptr->feat = feat;
+       g_ptr->feat = feat;
 
        /* Remove flag for mirror/glyph */
-       c_ptr->info &= ~(CAVE_OBJECT);
+       g_ptr->info &= ~(CAVE_OBJECT);
 
-       if (old_mirror && (d_info[dungeon_type].flags1 & DF1_DARKNESS))
+       if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
        {
-               c_ptr->info &= ~(CAVE_GLOW);
-               if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
+               g_ptr->info &= ~(CAVE_GLOW);
+               if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
 
                update_local_illumination(y, x);
        }
 
        /* Check for change to boring grid */
-       if (!have_flag(f_ptr->flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
-       if (c_ptr->m_idx) update_monster(c_ptr->m_idx, FALSE);
+       if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
+       if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
 
        note_spot(y, x);
 
@@ -4570,18 +4555,18 @@ void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
        }
 
        /* Hack -- glow the GLOW terrain */
-       if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
+       if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
        {
                DIRECTION i;
                POSITION yy, xx;
-               cave_type *cc_ptr;
+               grid_type *cc_ptr;
 
                for (i = 0; i < 9; i++)
                {
                        yy = y + ddy_ddd[i];
                        xx = x + ddx_ddd[i];
                        if (!in_bounds2(yy, xx)) continue;
-                       cc_ptr = &cave[yy][xx];
+                       cc_ptr = &grid_array[yy][xx];
                        cc_ptr->info |= CAVE_GLOW;
 
                        if (player_has_los_grid(cc_ptr))
@@ -4598,7 +4583,7 @@ void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
 
                if (p_ptr->special_defense & NINJA_S_STEALTH)
                {
-                       if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
+                       if (grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
                }
        }
 }
@@ -4613,9 +4598,9 @@ FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
                switch (f_ptr->subtype)
                {
                case CONVERT_TYPE_FLOOR:
-                       return floor_type[randint0(100)];
+                       return feat_ground_type[randint0(100)];
                case CONVERT_TYPE_WALL:
-                       return fill_type[randint0(100)];
+                       return feat_wall_type[randint0(100)];
                case CONVERT_TYPE_INNER:
                        return feat_wall_inner;
                case CONVERT_TYPE_OUTER:
@@ -4623,9 +4608,9 @@ FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
                case CONVERT_TYPE_SOLID:
                        return feat_wall_solid;
                case CONVERT_TYPE_STREAM1:
-                       return d_info[dungeon_type].stream1;
+                       return d_info[p_ptr->dungeon_idx].stream1;
                case CONVERT_TYPE_STREAM2:
-                       return d_info[dungeon_type].stream2;
+                       return d_info[p_ptr->dungeon_idx].stream2;
                default:
                        return newfeat;
                }
@@ -4661,10 +4646,10 @@ FEAT_IDX feat_state(FEAT_IDX feat, int action)
 void cave_alter_feat(POSITION y, POSITION x, int action)
 {
        /* Set old feature */
-       IDX oldfeat = cave[y][x].feat;
+       FEAT_IDX oldfeat = grid_array[y][x].feat;
 
        /* Get the new feat */
-       IDX newfeat = feat_state(oldfeat, action);
+       FEAT_IDX newfeat = feat_state(oldfeat, action);
 
        /* No change */
        if (newfeat == oldfeat) return;
@@ -4716,17 +4701,17 @@ void cave_alter_feat(POSITION y, POSITION x, int action)
 /* Remove a mirror */
 void remove_mirror(POSITION y, POSITION x)
 {
-       cave_type *c_ptr = &cave[y][x];
+       grid_type *g_ptr = &grid_array[y][x];
 
        /* Remove the mirror */
-       c_ptr->info &= ~(CAVE_OBJECT);
-       c_ptr->mimic = 0;
+       g_ptr->info &= ~(CAVE_OBJECT);
+       g_ptr->mimic = 0;
 
-       if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
+       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
        {
-               c_ptr->info &= ~(CAVE_GLOW);
-               if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
-               if (c_ptr->m_idx) update_monster(c_ptr->m_idx, FALSE);
+               g_ptr->info &= ~(CAVE_GLOW);
+               if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
+               if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
 
                update_local_illumination(y, x);
        }
@@ -4740,9 +4725,9 @@ void remove_mirror(POSITION y, POSITION x)
 /*
  *  Return TRUE if there is a mirror on the grid.
  */
-bool is_mirror_grid(cave_type *c_ptr)
+bool is_mirror_grid(grid_type *g_ptr)
 {
-       if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MIRROR))
+       if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
                return TRUE;
        else
                return FALSE;
@@ -4752,9 +4737,9 @@ bool is_mirror_grid(cave_type *c_ptr)
 /*
  *  Return TRUE if there is a mirror on the grid.
  */
-bool is_glyph_grid(cave_type *c_ptr)
+bool is_glyph_grid(grid_type *g_ptr)
 {
-       if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_GLYPH))
+       if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
                return TRUE;
        else
                return FALSE;
@@ -4764,9 +4749,9 @@ bool is_glyph_grid(cave_type *c_ptr)
 /*
  *  Return TRUE if there is a mirror on the grid.
  */
-bool is_explosive_rune_grid(cave_type *c_ptr)
+bool is_explosive_rune_grid(grid_type *g_ptr)
 {
-       if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MINOR_GLYPH))
+       if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
                return TRUE;
        else
                return FALSE;
@@ -5028,27 +5013,27 @@ void glow_deep_lava_and_bldg(void)
 {
        POSITION y, x, yy, xx;
        DIRECTION i;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /* Not in the darkness dungeon */
-       if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
+       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) return;
 
        for (y = 0; y < cur_hgt; y++)
        {
                for (x = 0; x < cur_wid; x++)
                {
-                       c_ptr = &cave[y][x];
+                       g_ptr = &grid_array[y][x];
 
                        /* Feature code (applying "mimic" field) */
 
-                       if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_GLOW))
+                       if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_GLOW))
                        {
                                for (i = 0; i < 9; i++)
                                {
                                        yy = y + ddy_ddd[i];
                                        xx = x + ddx_ddd[i];
                                        if (!in_bounds2(yy, xx)) continue;
-                                       cave[yy][xx].info |= CAVE_GLOW;
+                                       grid_array[yy][xx].info |= CAVE_GLOW;
                                }
                        }
                }
@@ -5071,22 +5056,22 @@ void glow_deep_lava_and_bldg(void)
 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
 {
        monster_type *m_ptr = &m_list[m_idx];
-       cave_type    *c_ptr = &cave[y][x];
-       feature_type *f_ptr = &f_info[c_ptr->feat];
+       grid_type    *g_ptr = &grid_array[y][x];
+       feature_type *f_ptr = &f_info[g_ptr->feat];
 
        /* Require "teleportable" space */
        if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
 
-       if (c_ptr->m_idx && (c_ptr->m_idx != m_idx)) return FALSE;
+       if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
        if (player_bold(y, x)) return FALSE;
 
        /* Hack -- no teleport onto glyph of warding */
-       if (is_glyph_grid(c_ptr)) return FALSE;
-       if (is_explosive_rune_grid(c_ptr)) return FALSE;
+       if (is_glyph_grid(g_ptr)) return FALSE;
+       if (is_explosive_rune_grid(g_ptr)) return FALSE;
 
        if (!(mode & TELEPORT_PASSIVE))
        {
-               if (!monster_can_cross_terrain(c_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
+               if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
        }
 
        return TRUE;
@@ -5101,23 +5086,23 @@ bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, B
 */
 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
 {
-       cave_type    *c_ptr = &cave[y][x];
-       feature_type *f_ptr = &f_info[c_ptr->feat];
+       grid_type    *g_ptr = &grid_array[y][x];
+       feature_type *f_ptr = &f_info[g_ptr->feat];
 
        /* Require "teleportable" space */
        if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
 
        /* No magical teleporting into vaults and such */
-       if (!(mode & TELEPORT_NONMAGICAL) && (c_ptr->info & CAVE_ICKY)) return FALSE;
+       if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
 
-       if (c_ptr->m_idx && (c_ptr->m_idx != p_ptr->riding)) return FALSE;
+       if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
 
        /* don't teleport on a trap. */
        if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
 
        if (!(mode & TELEPORT_PASSIVE))
        {
-               if (!player_can_enter(c_ptr->feat, 0)) return FALSE;
+               if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
 
                if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
                {
@@ -5137,3 +5122,14 @@ bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
 
        return TRUE;
 }
+
+/*!
+ * @brief 地形は開くものであって、かつ開かれているかを返す /
+ * Attempt to open the given chest at the given location
+ * @param feat 地形ID
+ * @return 開いた地形である場合TRUEを返す /  Return TRUE if the given feature is an open door
+ */
+bool is_open(FEAT_IDX feat)
+{
+       return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
+}