OSDN Git Service

[Refactor] #37353 obj_kind.c を object-hook.c に統合。 / Integrate obj_kind.c to object...
[hengband/hengband.git] / src / cave.c
index 4c7b0fd..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_mon(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,18 +618,16 @@ 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;
-
-               /* Acquire object */
                o_ptr = &o_list[this_o_idx];
 
                /* Acquire next object */
@@ -661,7 +661,7 @@ static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
  * @param cp 本来のシンボル
  * @return なし
  */
-static void image_monster(byte *ap, char *cp)
+static void image_monster(TERM_COLOR *ap, SYMBOL_CODE *cp)
 {
        /* Random symbol from set above */
        if (use_graphics)
@@ -689,7 +689,7 @@ static void image_monster(byte *ap, char *cp)
  * @param cp 本来のシンボル
  * @return なし
  */
-static void image_object(byte *ap, char *cp)
+static void image_object(TERM_COLOR *ap, SYMBOL_CODE *cp)
 {
        if (use_graphics)
        {
@@ -716,7 +716,7 @@ static void image_object(byte *ap, char *cp)
  * @param cp 本来のシンボル
  * @return なし
  */
-static void image_random(byte *ap, char *cp)
+static void image_random(TERM_COLOR *ap, SYMBOL_CODE *cp)
 {
        /* Normally, assume monsters */
        if (randint0(100) < 75)
@@ -740,7 +740,7 @@ static void image_random(byte *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},
@@ -795,10 +795,10 @@ static byte lighting_colours[16][2] =
  * @brief 調査中
  * @todo コメントを付加すること
  */
-void apply_default_feat_lighting(byte f_attr[F_LIT_MAX], byte f_char[F_LIT_MAX])
+void apply_default_feat_lighting(TERM_COLOR f_attr[F_LIT_MAX], SYMBOL_CODE f_char[F_LIT_MAX])
 {
-       byte s_attr = f_attr[F_LIT_STANDARD];
-       byte s_char = f_char[F_LIT_STANDARD];
+       TERM_COLOR s_attr = f_attr[F_LIT_STANDARD];
+       SYMBOL_CODE s_char = f_char[F_LIT_STANDARD];
        int i;
 
        if (is_ascii_graphics(s_attr)) /* For ASCII */
@@ -855,7 +855,7 @@ void apply_default_feat_lighting(byte f_attr[F_LIT_MAX], byte f_char[F_LIT_MAX])
  * 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
@@ -942,21 +942,21 @@ void apply_default_feat_lighting(byte f_attr[F_LIT_MAX], byte f_char[F_LIT_MAX])
  * "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, byte *ap, char *cp, byte *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];
 
-       s16b this_o_idx, next_o_idx = 0;
+       OBJECT_IDX this_o_idx, next_o_idx = 0;
 
        /* Feature code (applying "mimic" field) */
-       s16b feat = get_feat_mimic(c_ptr);
+       FEAT_IDX feat = get_feat_mimic(g_ptr);
 
        /* Access floor */
        feature_type *f_ptr = &f_info[feat];
 
-       byte a;
-       byte c;
+       TERM_COLOR a;
+       SYMBOL_CODE c;
 
        /* Boring grids (floors, etc) */
        if (!have_flag(f_ptr->flags, FF_REMEMBER))
@@ -973,8 +973,8 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                 * - 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];
@@ -993,10 +993,10 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                        }
 
                        /* 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];
@@ -1010,7 +1010,7 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                        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)
@@ -1022,7 +1022,7 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                                }
 
                                /* 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];
@@ -1030,7 +1030,7 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                                }
 
                                /* 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)
@@ -1046,8 +1046,8 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                /* 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];
@@ -1062,7 +1062,7 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
        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];
@@ -1081,12 +1081,12 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                        }
 
                        /* 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];
@@ -1115,7 +1115,7 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                                }
 
                                /* 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)
@@ -1130,7 +1130,7 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                                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];
@@ -1138,7 +1138,7 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                                        }
 
                                        /* 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];
@@ -1159,8 +1159,8 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                /* 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];
@@ -1192,11 +1192,9 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
        }
 
        /* 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;
-
-               /* Acquire object */
                o_ptr = &o_list[this_o_idx];
 
                /* Acquire next object */
@@ -1236,16 +1234,15 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                        /* Hack -- hallucination */
                        if (p_ptr->image) image_object(ap, cp);
 
-                       /* Done */
                        break;
                }
        }
 
 
        /* 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)
@@ -1321,7 +1318,7 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
                                        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
                                        {
@@ -1364,13 +1361,8 @@ void map_info(POSITION y, POSITION x, byte *ap, char *cp, byte *tap, char *tcp)
        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;
        }
 }
@@ -1404,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))
@@ -1413,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;
                }
 
@@ -1467,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;
@@ -1489,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];
 
@@ -1502,72 +1494,66 @@ 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);
 }
 
 
 void display_dungeon(void)
 {
        TERM_LEN x, y;
-       byte a;
-       char c;
+       TERM_COLOR a;
+       SYMBOL_CODE c;
 
-       byte ta = 0;
-       char tc = '\0';
+       TERM_COLOR ta = 0;
+       SYMBOL_CODE tc = '\0';
 
        for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
        {
@@ -1583,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;
                                }
 
@@ -1621,11 +1607,11 @@ void lite_spot(POSITION y, POSITION x)
        /* Redraw if on screen */
        if (panel_contains(y, x) && in_bounds2(y, x))
        {
-               byte a;
-               char c;
+               TERM_COLOR a;
+               SYMBOL_CODE c;
 
-               byte ta;
-               char tc;
+               TERM_COLOR ta;
+               SYMBOL_CODE tc;
 
                /* Examine the grid */
                map_info(y, x, &a, &c, &ta, &tc);
@@ -1634,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;
                }
 
@@ -1656,15 +1642,14 @@ 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;
 
-       /* Get size */
        Term_get_size(&wid, &hgt);
 
        /* Remove map offset */
@@ -1703,11 +1688,11 @@ void prt_map(void)
                /* Scan the columns of row "y" */
                for (x = xmin; x <= xmax; x++)
                {
-                       byte a;
-                       char c;
+                       TERM_COLOR a;
+                       SYMBOL_CODE c;
 
-                       byte ta;
-                       char tc;
+                       TERM_COLOR ta;
+                       SYMBOL_CODE tc;
 
                        /* Determine what is there */
                        map_info(y, x, &a, &c, &ta, &tc);
@@ -1716,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;
                        }
 
@@ -1751,28 +1736,25 @@ void prt_path(POSITION y, POSITION x)
        /* Get projection path */
        path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH|PROJECT_THRU);
 
-       /* Redraw map */
        p_ptr->redraw |= (PR_MAP);
-
-       /* Redraw stuff */
-       redraw_stuff();
+       handle_stuff();
 
        /* Draw path */
        for (i = 0; i < path_n; i++)
        {
-               int ny = GRID_Y(path_g[i]);
-               int nx = GRID_X(path_g[i]);
-               cave_type *c_ptr = &cave[ny][nx];
+               POSITION ny = GRID_Y(path_g[i]);
+               POSITION nx = GRID_X(path_g[i]);
+               grid_type *g_ptr = &grid_array[ny][nx];
 
                if (panel_contains(ny, nx))
                {
-                       byte a = default_color;
+                       TERM_COLOR a = default_color;
                        char c;
 
-                       byte ta;
-                       char tc;
+                       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);
@@ -1788,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;
                        }
 
@@ -1799,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;
@@ -1807,7 +1789,7 @@ void prt_path(POSITION y, POSITION x)
 }
 
 
-static cptr simplify_list[][2] =
+static concptr simplify_list[][2] =
 {
 #ifdef JP
        {"の魔法書", ""},
@@ -1837,7 +1819,7 @@ static void display_shortened_item_name(object_type *o_ptr, int y)
        char buf[MAX_NLEN];
        char *c = buf;
        int len = 0;
-       byte attr;
+       TERM_COLOR attr;
 
        object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
        attr = tval_to_attr[o_ptr->tval % 128];
@@ -1853,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 == '^')
                        {
@@ -1866,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);
@@ -1908,29 +1890,28 @@ void display_map(int *cy, int *cx)
 {
        int i, j, x, y;
 
-       byte ta;
-       char tc;
+       TERM_COLOR ta;
+       SYMBOL_CODE tc;
 
        byte tp;
 
-       byte **bigma;
-       char **bigmc;
+       TERM_COLOR **bigma;
+       SYMBOL_CODE **bigmc;
        byte **bigmp;
 
-       byte **ma;
-       char **mc;
+       TERM_COLOR **ma;
+       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;
 
-       /* Get size */
        Term_get_size(&wid, &hgt);
        hgt -= 2;
        wid -= 14;
@@ -1944,7 +1925,7 @@ void display_map(int *cy, int *cx)
        view_granite_lite = FALSE;
 
        /* Allocate the maps */
-       C_MAKE(ma, (hgt + 2), byte_ptr);
+       C_MAKE(ma, (hgt + 2), TERM_COLOR *);
        C_MAKE(mc, (hgt + 2), char_ptr);
        C_MAKE(mp, (hgt + 2), byte_ptr);
        C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
@@ -1954,7 +1935,7 @@ void display_map(int *cy, int *cx)
        for (y = 0; y < (hgt + 2); y++)
        {
                /* Allocate one row each array */
-               C_MAKE(ma[y], (wid + 2), byte);
+               C_MAKE(ma[y], (wid + 2), TERM_COLOR);
                C_MAKE(mc[y], (wid + 2), char);
                C_MAKE(mp[y], (wid + 2), byte);
                C_MAKE(match_autopick_yx[y], (wid + 2), int);
@@ -1975,7 +1956,7 @@ void display_map(int *cy, int *cx)
        }
 
        /* Allocate the maps */
-       C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
+       C_MAKE(bigma, (cur_hgt + 2), TERM_COLOR *);
        C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
        C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
 
@@ -1983,7 +1964,7 @@ void display_map(int *cy, int *cx)
        for (y = 0; y < (cur_hgt + 2); y++)
        {
                /* Allocate one row each array */
-               C_MAKE(bigma[y], (cur_wid + 2), byte);
+               C_MAKE(bigma[y], (cur_wid + 2), TERM_COLOR);
                C_MAKE(bigmc[y], (cur_wid + 2), char);
                C_MAKE(bigmp[y], (cur_wid + 2), byte);
 
@@ -2003,7 +1984,6 @@ void display_map(int *cy, int *cx)
        {
                for (j = 0; j < cur_hgt; ++j)
                {
-                       /* Location */
                        x = i / xrat + 1;
                        y = j / yrat + 1;
 
@@ -2037,7 +2017,6 @@ void display_map(int *cy, int *cx)
        {
                for (i = 0; i < cur_wid; ++i)
                {
-                       /* Location */
                        x = i / xrat + 1;
                        y = j / yrat + 1;
 
@@ -2103,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;
                        }
 
@@ -2157,15 +2136,15 @@ void display_map(int *cy, int *cx)
        for (y = 0; y < (hgt + 2); y++)
        {
                /* Free one row each array */
-               C_KILL(ma[y], (wid + 2), byte);
-               C_KILL(mc[y], (wid + 2), char);
+               C_KILL(ma[y], (wid + 2), TERM_COLOR);
+               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 *);
        }
 
        /* Free each line map */
-       C_KILL(ma, (hgt + 2), byte_ptr);
+       C_KILL(ma, (hgt + 2), TERM_COLOR *);
        C_KILL(mc, (hgt + 2), char_ptr);
        C_KILL(mp, (hgt + 2), byte_ptr);
        C_KILL(match_autopick_yx, (hgt + 2), sint_ptr);
@@ -2175,13 +2154,13 @@ void display_map(int *cy, int *cx)
        for (y = 0; y < (cur_hgt + 2); y++)
        {
                /* Free one row each array */
-               C_KILL(bigma[y], (cur_wid + 2), byte);
-               C_KILL(bigmc[y], (cur_wid + 2), char);
+               C_KILL(bigma[y], (cur_wid + 2), TERM_COLOR);
+               C_KILL(bigmc[y], (cur_wid + 2), SYMBOL_CODE);
                C_KILL(bigmp[y], (cur_wid + 2), byte);
        }
 
        /* Free each line map */
-       C_KILL(bigma, (cur_hgt + 2), byte_ptr);
+       C_KILL(bigma, (cur_hgt + 2), TERM_COLOR *);
        C_KILL(bigmc, (cur_hgt + 2), char_ptr);
        C_KILL(bigmp, (cur_hgt + 2), byte_ptr);
 }
@@ -2190,23 +2169,17 @@ void display_map(int *cy, int *cx)
 /*
  * Display a "small-scale" map of the dungeon for the player
  *
- * Currently, the "player" is displayed on the map.  XXX XXX XXX
+ * Currently, the "player" is displayed on the map.  
  */
 void do_cmd_view_map(void)
 {
        int cy, cx;
 
-
-       /* Save the screen */
        screen_save();
 
-       /* Note */
        prt(_("お待ち下さい...", "Please wait..."), 0, 0);
 
-       /* Flush */
        Term_fresh();
-
-       /* Clear the screen */
        Term_clear();
 
        display_autopick = 0;
@@ -2269,8 +2242,6 @@ void do_cmd_view_map(void)
                /* Get any key */
                inkey();
        }
-
-       /* Restore the screen */
        screen_load();
 }
 
@@ -2279,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
@@ -2508,9 +2479,8 @@ void forget_lite(void)
                x = lite_x[i];
 
                /* Forget "LITE" flag */
-               cave[y][x].info &= ~(CAVE_LITE);
+               grid_array[y][x].info &= ~(CAVE_LITE);
 
-               /* Redraw */
                /* lite_spot(y, x); Perhaps don't need? */
        }
 
@@ -2544,8 +2514,6 @@ void forget_lite(void)
 
 
 /*
- * XXX XXX XXX
- *
  * This macro allows us to efficiently add a grid to the "lite" array,
  * note that we are never called for illegal grids, or for grids which
  * have already been placed into the "lite" array, and we are never
@@ -2553,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); \
        } \
@@ -2588,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 ***/
 
@@ -2602,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
 
@@ -2615,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;
@@ -2753,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);
@@ -2771,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 */
@@ -2786,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 */
@@ -2814,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 */
 
@@ -2876,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;
@@ -2888,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;
 }
 
 
@@ -2901,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 */
 
@@ -2967,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;
 }
 
 
@@ -2984,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);
@@ -2993,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 */
@@ -3044,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;
                        }
@@ -3061,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);
@@ -3086,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);
@@ -3104,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);
@@ -3122,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);
@@ -3140,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);
@@ -3196,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);
                        }
                }
 
@@ -3237,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);
                        }
                }
 
@@ -3271,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 */
@@ -3280,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)
        {
@@ -3302,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 */
@@ -3327,7 +3296,7 @@ void forget_view(void)
 {
        int i;
 
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        /* None to forget */
        if (!view_n) return;
@@ -3337,12 +3306,10 @@ void forget_view(void)
        {
                POSITION y = view_y[i];
                POSITION x = view_x[i];
-
-               /* Access the grid */
-               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; */
 
@@ -3394,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 */
@@ -3419,13 +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);
 
-
-       /* Access the grid */
-       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 */
@@ -3435,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);
        }
@@ -3445,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);
        }
@@ -3453,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);
        }
@@ -3464,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);
        }
@@ -3473,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);
        }
@@ -3559,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.
@@ -3588,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 ***/
 
@@ -3620,15 +3585,13 @@ void update_view(void)
        {
                y = view_y[n];
                x = view_x[n];
-
-               /* Access the grid */
-               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;
@@ -3644,15 +3607,13 @@ void update_view(void)
        /* Now start on the player */
        y = p_ptr->y;
        x = p_ptr->x;
-
-       /* Access the grid */
-       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 ***/
@@ -3663,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" */
@@ -3714,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" */
@@ -3726,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" */
@@ -3738,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" */
@@ -3753,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;
@@ -3993,18 +3952,16 @@ void update_view(void)
        {
                y = view_y[n];
                x = view_x[n];
-
-               /* Access the grid */
-               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 */
@@ -4012,18 +3969,16 @@ void update_view(void)
        {
                y = temp_y[n];
                x = temp_x[n];
-
-               /* Access the grid */
-               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 */
@@ -4040,32 +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];
-
-               /* Access the grid */
-               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);
 
-               /* Redraw */
                lite_spot(y, x);
 
                /* Hack -- Visual update of monster on this grid */
-               if (c_ptr->m_idx) update_mon(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 */
@@ -4086,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;
                }
        }
 }
@@ -4119,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;
 
@@ -4130,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 */
@@ -4138,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;
                }
        }
 
@@ -4167,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];
@@ -4178,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;
@@ -4229,8 +4183,8 @@ static int scent_when = 0;
  */
 void update_smell(void)
 {
-       int i, j;
-       int y, x;
+       POSITION i, j;
+       POSITION y, x;
 
        /* Create a table that controls the spread of scent */
        const int scent_adjust[5][5] = 
@@ -4250,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;
                        }
                }
 
@@ -4265,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;
@@ -4274,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;
@@ -4286,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];
                }
        }
 }
@@ -4297,12 +4251,13 @@ void update_smell(void)
  */
 void map_area(POSITION range)
 {
-       int             i, x, y;
-       cave_type       *c_ptr;
-       s16b            feat;
-       feature_type    *f_ptr;
+       int i;
+       POSITION x, y;
+       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++)
@@ -4311,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" */
@@ -4327,33 +4282,31 @@ 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);
                                        }
                                }
                        }
                }
        }
 
-       /* Redraw map */
        p_ptr->redraw |= (PR_MAP);
 
-       /* Window stuff */
        p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
 }
 
@@ -4377,8 +4330,9 @@ void map_area(POSITION range)
  */
 void wiz_lite(bool ninja)
 {
-       int i, y, x;
-       s16b feat;
+       OBJECT_IDX i;
+       POSITION y, x;
+       FEAT_IDX feat;
        feature_type *f_ptr;
 
        /* Memorize objects */
@@ -4402,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 */
@@ -4419,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);
                                                }
                                        }
                                }
@@ -4454,18 +4406,13 @@ void wiz_lite(bool ninja)
                }
        }
 
-       /* Update the monsters */
        p_ptr->update |= (PU_MONSTERS);
-
-       /* Redraw map */
        p_ptr->redraw |= (PR_MAP);
-
-       /* Window stuff */
        p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
 
        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);
        }
 }
 
@@ -4475,34 +4422,34 @@ void wiz_lite(bool ninja)
  */
 void wiz_dark(void)
 {
-       int i, y, x;
-
+       OBJECT_IDX i;
+       POSITION y, x;
 
        /* Forget every grid */
        for (y = 1; y < cur_hgt - 1; y++)
        {
                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 */
@@ -4523,54 +4470,42 @@ void wiz_dark(void)
        /* Forget travel route when we have forgotten map */
        forget_travel_flow();
 
-       /* Mega-Hack -- Forget the view and lite */
        p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
-
-       /* Update the view and lite */
        p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
-
-       /* Update the monsters */
        p_ptr->update |= (PU_MONSTERS);
-
-       /* Redraw map */
        p_ptr->redraw |= (PR_MAP);
-
-       /* Window stuff */
        p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
 }
 
-
-
-
-
 /*
  * Change the "feat" flag for a grid, and notice/redraw the grid
  */
-void cave_set_feat(POSITION y, POSITION x, IDX feat)
+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))
                {
-                       int i, yy, xx;
+                       DIRECTION i;
+                       POSITION yy, xx;
 
                        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;
                        }
                }
 
@@ -4578,35 +4513,31 @@ void cave_set_feat(POSITION y, POSITION x, 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);
-
-       /* Update the monster */
-       if (c_ptr->m_idx) update_mon(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);
 
-       /* Notice */
        note_spot(y, x);
 
-       /* Redraw */
        lite_spot(y, x);
 
        /* Check if los has changed */
@@ -4624,28 +4555,26 @@ void cave_set_feat(POSITION y, POSITION x, 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))
        {
-               int i, yy, xx;
-               cave_type *cc_ptr;
+               DIRECTION i;
+               POSITION yy, xx;
+               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))
                        {
-                               /* Update the monster */
-                               if (cc_ptr->m_idx) update_mon(cc_ptr->m_idx, FALSE);
+                               if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
 
-                               /* Notice */
                                note_spot(yy, xx);
 
-                               /* Redraw */
                                lite_spot(yy, xx);
                        }
 
@@ -4654,13 +4583,13 @@ void cave_set_feat(POSITION y, POSITION x, 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);
                }
        }
 }
 
 
-IDX conv_dungeon_feat(IDX newfeat)
+FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
 {
        feature_type *f_ptr = &f_info[newfeat];
 
@@ -4669,9 +4598,9 @@ IDX conv_dungeon_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:
@@ -4679,9 +4608,9 @@ IDX conv_dungeon_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;
                }
@@ -4694,7 +4623,7 @@ IDX conv_dungeon_feat(IDX newfeat)
  * Take a feature, determine what that feature becomes
  * through applying the given action.
  */
-IDX feat_state(IDX feat, int action)
+FEAT_IDX feat_state(FEAT_IDX feat, int action)
 {
        feature_type *f_ptr = &f_info[feat];
        int i;
@@ -4717,10 +4646,10 @@ IDX feat_state(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;
@@ -4772,27 +4701,23 @@ 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);
-
-               /* Update the monster */
-               if (c_ptr->m_idx) update_mon(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);
        }
 
-       /* Notice */
        note_spot(y, x);
 
-       /* Redraw */
        lite_spot(y, x);
 }
 
@@ -4800,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;
@@ -4812,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;
@@ -4824,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;
@@ -4992,7 +4917,6 @@ void monster_race_track(MONRACE_IDX r_idx)
        /* Save this monster ID */
        p_ptr->monster_race_idx = r_idx;
 
-       /* Window stuff */
        p_ptr->window |= (PW_MONSTER);
 }
 
@@ -5001,12 +4925,11 @@ void monster_race_track(MONRACE_IDX r_idx)
 /*
  * Hack -- track the given object kind
  */
-void object_kind_track(IDX k_idx)
+void object_kind_track(KIND_OBJECT_IDX k_idx)
 {
        /* Save this monster ID */
        p_ptr->object_kind_idx = k_idx;
 
-       /* Window stuff */
        p_ptr->window |= (PW_OBJECT);
 }
 
@@ -5021,7 +4944,7 @@ void object_kind_track(IDX k_idx)
  *
  * All disturbance cancels repeated commands, resting, and running.
  */
-void disturb(int stop_search, int stop_travel)
+void disturb(bool stop_search, bool stop_travel)
 {
 #ifndef TRAVEL
        /* Unused */
@@ -5088,28 +5011,29 @@ void disturb(int stop_search, int stop_travel)
  */
 void glow_deep_lava_and_bldg(void)
 {
-       int y, x, i, yy, xx;
-       cave_type *c_ptr;
+       POSITION y, x, yy, xx;
+       DIRECTION i;
+       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;
                                }
                        }
                }
@@ -5118,7 +5042,6 @@ void glow_deep_lava_and_bldg(void)
        /* Update the view and lite */
        p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
 
-       /* Redraw map */
        p_ptr->redraw |= (PR_MAP);
 }
 
@@ -5133,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;
@@ -5163,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))
                {
@@ -5199,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));
+}