OSDN Git Service

Add some Heavy Crossbow Artifacts.
[hengband/hengband.git] / src / cave.c
index d0b1662..aa90ad0 100644 (file)
@@ -73,7 +73,7 @@ bool is_trap(int feat)
  */
 bool is_known_trap(cave_type *c_ptr)
 {
-       if (!c_ptr->mimic && !have_flag(f_flags_grid(c_ptr), FF_SECRET) &&
+       if (!c_ptr->mimic && !cave_have_flag_grid(c_ptr, FF_SECRET) &&
            is_trap(c_ptr->feat)) return TRUE;
        else
                return FALSE;
@@ -97,7 +97,7 @@ bool is_closed_door(int feat)
  */
 bool is_hidden_door(cave_type *c_ptr)
 {
-       if ((c_ptr->mimic || have_flag(f_flags_grid(c_ptr), FF_SECRET)) &&
+       if ((c_ptr->mimic || cave_have_flag_grid(c_ptr, FF_SECRET)) &&
            is_closed_door(c_ptr->feat))
                return TRUE;
        else
@@ -174,12 +174,12 @@ bool los(int y1, int x1, int y2, int x2)
 
 
        /* Handle adjacent (or identical) grids */
-       if ((ax < 2) && (ay < 2)) return (TRUE);
+       if ((ax < 2) && (ay < 2)) return TRUE;
 
 
        /* Paranoia -- require "safe" origin */
-       /* if (!in_bounds(y1, x1)) return (FALSE); */
-       /* if (!in_bounds(y2, x2)) return (FALSE); */
+       /* if (!in_bounds(y1, x1)) return FALSE; */
+       /* if (!in_bounds(y2, x2)) return FALSE; */
 
 
        /* Directly South/North */
@@ -190,7 +190,7 @@ bool los(int y1, int x1, int y2, int x2)
                {
                        for (ty = y1 + 1; ty < y2; ty++)
                        {
-                               if (!cave_floor_bold(ty, x1)) return (FALSE);
+                               if (!cave_los_bold(ty, x1)) return FALSE;
                        }
                }
 
@@ -199,12 +199,12 @@ bool los(int y1, int x1, int y2, int x2)
                {
                        for (ty = y1 - 1; ty > y2; ty--)
                        {
-                               if (!cave_floor_bold(ty, x1)) return (FALSE);
+                               if (!cave_los_bold(ty, x1)) return FALSE;
                        }
                }
 
                /* Assume los */
-               return (TRUE);
+               return TRUE;
        }
 
        /* Directly East/West */
@@ -215,7 +215,7 @@ bool los(int y1, int x1, int y2, int x2)
                {
                        for (tx = x1 + 1; tx < x2; tx++)
                        {
-                               if (!cave_floor_bold(y1, tx)) return (FALSE);
+                               if (!cave_los_bold(y1, tx)) return FALSE;
                        }
                }
 
@@ -224,12 +224,12 @@ bool los(int y1, int x1, int y2, int x2)
                {
                        for (tx = x1 - 1; tx > x2; tx--)
                        {
-                               if (!cave_floor_bold(y1, tx)) return (FALSE);
+                               if (!cave_los_bold(y1, tx)) return FALSE;
                        }
                }
 
                /* Assume los */
-               return (TRUE);
+               return TRUE;
        }
 
 
@@ -243,7 +243,7 @@ bool los(int y1, int x1, int y2, int x2)
        {
                if (ay == 2)
                {
-                       if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
+                       if (cave_los_bold(y1 + sy, x1)) return TRUE;
                }
        }
 
@@ -252,7 +252,7 @@ bool los(int y1, int x1, int y2, int x2)
        {
                if (ax == 2)
                {
-                       if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
+                       if (cave_los_bold(y1, x1 + sx)) return TRUE;
                }
        }
 
@@ -288,7 +288,7 @@ bool los(int y1, int x1, int y2, int x2)
                /* the LOS exactly meets the corner of a tile. */
                while (x2 - tx)
                {
-                       if (!cave_floor_bold(ty, tx)) return (FALSE);
+                       if (!cave_los_bold(ty, tx)) return FALSE;
 
                        qy += m;
 
@@ -299,7 +299,7 @@ bool los(int y1, int x1, int y2, int x2)
                        else if (qy > f2)
                        {
                                ty += sy;
-                               if (!cave_floor_bold(ty, tx)) return (FALSE);
+                               if (!cave_los_bold(ty, tx)) return FALSE;
                                qy -= f1;
                                tx += sx;
                        }
@@ -335,7 +335,7 @@ bool los(int y1, int x1, int y2, int x2)
                /* the LOS exactly meets the corner of a tile. */
                while (y2 - ty)
                {
-                       if (!cave_floor_bold(ty, tx)) return (FALSE);
+                       if (!cave_los_bold(ty, tx)) return FALSE;
 
                        qx += m;
 
@@ -346,7 +346,7 @@ bool los(int y1, int x1, int y2, int x2)
                        else if (qx > f2)
                        {
                                tx += sx;
-                               if (!cave_floor_bold(ty, tx)) return (FALSE);
+                               if (!cave_los_bold(ty, tx)) return FALSE;
                                qx -= f1;
                                ty += sy;
                        }
@@ -360,7 +360,7 @@ bool los(int y1, int x1, int y2, int x2)
        }
 
        /* Assume los */
-       return (TRUE);
+       return TRUE;
 }
 
 
@@ -368,6 +368,151 @@ bool los(int y1, int x1, int y2, int x2)
 
 
 
+#define COMPLEX_WALL_ILLUMINATION
+
+/*
+ * Check for "local" illumination
+ */
+static bool check_local_illumination(int y, int x)
+{
+       /* Hack -- move towards player */
+       int yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
+       int xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
+
+       /* Check for "local" illumination */
+
+#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)))
+       {
+               return TRUE;
+       }
+       else return FALSE;
+
+#else /* COMPLEX_WALL_ILLUMINATION */
+
+       /* Check for "simple" illumination */
+       return (cave[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
+
+#endif /* COMPLEX_WALL_ILLUMINATION */
+}
+
+
+#define update_local_illumination_aux(Y, 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); \
+\
+               /* Notice and redraw */ \
+               note_spot((Y), (X)); \
+               lite_spot((Y), (X)); \
+       } \
+}
+
+
+/*
+ * Update "local" illumination
+ */
+void update_local_illumination(int y, int x)
+{
+       int i, yy, xx;
+
+       if (!in_bounds(y, x)) return;
+
+#ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
+
+       if ((y != py) && (x != px))
+       {
+               yy = (y < py) ? (y - 1) : (y + 1);
+               xx = (x < px) ? (x - 1) : (x + 1);
+               update_local_illumination_aux(yy, xx);
+               update_local_illumination_aux(y, xx);
+               update_local_illumination_aux(yy, x);
+       }
+       else if (x != px) /* y == py */
+       {
+               xx = (x < px) ? (x - 1) : (x + 1);
+               for (i = -1; i <= 1; i++)
+               {
+                       yy = y + i;
+                       update_local_illumination_aux(yy, xx);
+               }
+               yy = y - 1;
+               update_local_illumination_aux(yy, x);
+               yy = y + 1;
+               update_local_illumination_aux(yy, x);
+       }
+       else if (y != py) /* x == px */
+       {
+               yy = (y < py) ? (y - 1) : (y + 1);
+               for (i = -1; i <= 1; i++)
+               {
+                       xx = x + i;
+                       update_local_illumination_aux(yy, xx);
+               }
+               xx = x - 1;
+               update_local_illumination_aux(y, xx);
+               xx = x + 1;
+               update_local_illumination_aux(y, xx);
+       }
+       else /* Player's grid */
+       {
+               for (i = 0; i < 8; i++)
+               {
+                       yy = y + ddy_cdd[i];
+                       xx = x + ddx_cdd[i];
+                       update_local_illumination_aux(yy, xx);
+               }
+       }
+
+#else /* COMPLEX_WALL_ILLUMINATION */
+
+       if ((y != py) && (x != px))
+       {
+               yy = (y < py) ? (y - 1) : (y + 1);
+               xx = (x < px) ? (x - 1) : (x + 1);
+               update_local_illumination_aux(yy, xx);
+       }
+       else if (x != px) /* y == py */
+       {
+               xx = (x < px) ? (x - 1) : (x + 1);
+               for (i = -1; i <= 1; i++)
+               {
+                       yy = y + i;
+                       update_local_illumination_aux(yy, xx);
+               }
+       }
+       else if (y != py) /* x == px */
+       {
+               yy = (y < py) ? (y - 1) : (y + 1);
+               for (i = -1; i <= 1; i++)
+               {
+                       xx = x + i;
+                       update_local_illumination_aux(yy, xx);
+               }
+       }
+       else /* Player's grid */
+       {
+               for (i = 0; i < 8; i++)
+               {
+                       yy = y + ddy_cdd[i];
+                       xx = x + ddx_cdd[i];
+                       update_local_illumination_aux(yy, xx);
+               }
+       }
+
+#endif /* COMPLEX_WALL_ILLUMINATION */
+}
+
+
 /*
  * Can the player "see" the given grid in detail?
  *
@@ -402,44 +547,32 @@ bool los(int y1, int x1, int y2, int x2)
  */
 bool player_can_see_bold(int y, int x)
 {
-       int xx, yy;
-
        cave_type *c_ptr;
 
        /* Blind players see nothing */
-       if (p_ptr->blind) return (FALSE);
+       if (p_ptr->blind) return FALSE;
 
        /* Access the cave grid */
        c_ptr = &cave[y][x];
 
        /* Note that "torch-lite" yields "illumination" */
-       if (c_ptr->info & (CAVE_LITE)) return (TRUE);
+       if (c_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
 
        /* Require line of sight to the grid */
-       if (!player_has_los_bold(y, x)) return (FALSE);
+       if (!player_has_los_bold(y, x)) return FALSE;
 
        /* Noctovision of Ninja */
        if (p_ptr->see_nocto) return TRUE;
 
        /* Require "perma-lite" of the grid */
-       if (!(c_ptr->info & CAVE_MNLT) && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)) return FALSE;
+       if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
 
+       /* Feature code (applying "mimic" field) */
        /* Floors are simple */
-       if (cave_floor_bold(y, x)) return (TRUE);
-
-       /* Hack -- move towards player */
-       yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
-       xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
+       if (feat_supports_los(get_feat_mimic(c_ptr))) return TRUE;
 
        /* Check for "local" illumination */
-       if ((cave[yy][xx].info & CAVE_MNLT) || ((cave[yy][xx].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
-       {
-               /* Assume the wall is really illuminated */
-               return (TRUE);
-       }
-
-       /* Assume not visible */
-       return (FALSE);
+       return check_local_illumination(y, x);
 }
 
 
@@ -482,42 +615,7 @@ bool cave_valid_bold(int y, int x)
                next_o_idx = o_ptr->next_o_idx;
 
                /* Forbid artifact grids */
-               if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
-       }
-
-       /* Accept */
-       return (TRUE);
-}
-
-
-
-
-/*
- * Determine if a given location may be "destroyed"
- *
- * Used by destruction spells, and for placing stairs, etc.
- */
-bool cave_valid_grid(cave_type *c_ptr)
-{
-       s16b this_o_idx, next_o_idx = 0;
-
-
-       /* Forbid perma-grids */
-       if (cave_perma_grid(c_ptr)) return (FALSE);
-
-       /* Check objects */
-       for (this_o_idx = c_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 */
-               next_o_idx = o_ptr->next_o_idx;
-
-               /* Forbid artifact grids */
-               if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
+               if (object_is_artifact(o_ptr)) return (FALSE);
        }
 
        /* Accept */
@@ -616,7 +714,7 @@ static void image_random(byte *ap, char *cp)
  * The layout of the array is [x][0] = light and [x][1] = dark.
  */
 
-byte lighting_colours[16][2] =
+static byte lighting_colours[16][2] =
 {
        /* TERM_DARK */
        {TERM_L_DARK, TERM_DARK},
@@ -669,60 +767,33 @@ byte lighting_colours[16][2] =
 
 
 /*
- * Mega-Hack -- Partial code of map_info() for darkened grids
- * Note: Each variable is declared in map_info().
- *       This macro modifies "feat", "f_ptr", "c" and "a".
+ * Apply "default" feature lighting effects
  */
-#define darkened_grid_hack() \
-{ \
-       if (feat_supports_los(feat)) \
-       { \
-               /* Unsafe cave grid -- idea borrowed from Unangband */ \
-               if (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) \
-               { \
-                       feat = FEAT_UNDETECTED; \
-\
-                       /* Access unsafe darkness */ \
-                       f_ptr = &f_info[feat]; \
-\
-                       /* Char and attr of unsafe grid */ \
-                       c = f_ptr->x_char[F_LIT_STANDARD]; \
-                       a = f_ptr->x_attr[F_LIT_STANDARD]; \
-               } \
-               else \
-               { \
-                       /* For feat_priority control */ \
-                       feat = FEAT_NONE; \
-\
-                       /* Access darkness */ \
-                       f_ptr = &f_info[feat]; \
-\
-                       if (use_graphics) \
-                       { \
-                               /* Char and attr of darkness */ \
-                               c = f_ptr->x_char[F_LIT_STANDARD]; \
-                               a = f_ptr->x_attr[F_LIT_STANDARD]; \
-                       } \
-                       else \
-                       { \
-                               /* Use "black" */ \
-                               a = TERM_DARK; \
-                       } \
-               } \
-       } \
-       else if (view_granite_lite && view_yellow_lite) \
-       { \
-               /* Use a darkly darkened colour/tile */ \
-               a = f_ptr->x_attr[F_LIT_DARKDARK]; \
-               c = f_ptr->x_char[F_LIT_DARKDARK]; \
-       } \
-} ;
+void apply_default_feat_lighting(byte f_attr[F_LIT_MAX], byte f_char[F_LIT_MAX])
+{
+       byte s_attr = f_attr[F_LIT_STANDARD];
+       byte s_char = f_char[F_LIT_STANDARD];
+       int i;
+
+       if (is_ascii_graphics(s_attr)) /* For ASCII */
+       {
+               f_attr[F_LIT_LITE] = lighting_colours[s_attr & 0x0f][0];
+               f_attr[F_LIT_DARK] = lighting_colours[s_attr & 0x0f][1];
+               for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_char[i] = s_char;
+       }
+       else /* For tile graphics */
+       {
+               for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_attr[i] = s_attr;
+               f_char[F_LIT_LITE] = s_char + 2;
+               f_char[F_LIT_DARK] = s_char + 1;
+       }
+}
 
 
 /* Is this grid "darkened" by monster? */
 #define darkened_grid(C) \
        ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
-       !p_ptr->see_nocto && !p_ptr->blind)
+       !p_ptr->see_nocto)
 
 
 /*
@@ -862,50 +933,56 @@ void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
        /* Boring grids (floors, etc) */
        if (!have_flag(f_ptr->flags, FF_REMEMBER))
        {
-               /* Memorized (or visible) floor */
-               if ((c_ptr->info & CAVE_MARK) ||
-                 (((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) ||
-                  ((c_ptr->info & CAVE_VIEW) &&
-                 (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))) &&
-                  !p_ptr->blind))
+               /*
+                * Handle Memorized or visible floor
+                *
+                * No visual when blinded.
+                *   (to prevent strange effects on darkness breath)
+                * otherwise,
+                * - Can see grids with CAVE_MARK.
+                * - Can see grids with CAVE_LITE or CAVE_MNLT.
+                *   (Such grids also have CAVE_VIEW)
+                * - 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))))
                {
-                       /* Normal char */
-                       c = f_ptr->x_char[F_LIT_STANDARD];
-
-                       /* Normal attr */
+                       /* Normal attr/char */
                        a = f_ptr->x_attr[F_LIT_STANDARD];
+                       c = f_ptr->x_char[F_LIT_STANDARD];
 
                        if (p_ptr->wild_mode)
                        {
                                /* Special lighting effects */
-                               /* Handle "blind" */
-                               if (view_special_lite && p_ptr->blind)
+                               /* Handle "night" */
+                               if (view_special_lite && !is_daytime())
                                {
-                                       /* Use a darkly darkened colour/tile */
-                                       a = f_ptr->x_attr[F_LIT_DARKDARK];
-                                       c = f_ptr->x_char[F_LIT_DARKDARK];
+                                       /* Use a darkened colour/tile */
+                                       a = f_ptr->x_attr[F_LIT_DARK];
+                                       c = f_ptr->x_char[F_LIT_DARK];
                                }
                        }
 
                        /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
                        else if (darkened_grid(c_ptr))
                        {
-                               darkened_grid_hack();
+                               /* Unsafe cave grid -- idea borrowed from Unangband */
+                               feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
+
+                               /* Access darkness */
+                               f_ptr = &f_info[feat];
+
+                               /* Char and attr of darkness */
+                               a = f_ptr->x_attr[F_LIT_STANDARD];
+                               c = f_ptr->x_char[F_LIT_STANDARD];
                        }
 
                        /* Special lighting effects */
                        else if (view_special_lite)
                        {
-                               /* Handle "blind" */
-                               if (p_ptr->blind)
-                               {
-                                       /* Use a darkly darkened colour/tile */
-                                       a = f_ptr->x_attr[F_LIT_DARKDARK];
-                                       c = f_ptr->x_char[F_LIT_DARKDARK];
-                               }
-
                                /* Handle "torch-lit" grids */
-                               else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
+                               if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
                                {
                                        /* Torch lite */
                                        if (view_yellow_lite)
@@ -919,9 +996,9 @@ void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
                                /* Handle "dark" grids */
                                else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
                                {
-                                       /* Use a darkly darkened colour/tile */
-                                       a = f_ptr->x_attr[F_LIT_DARKDARK];
-                                       c = f_ptr->x_char[F_LIT_DARKDARK];
+                                       /* Use a darkened colour/tile */
+                                       a = f_ptr->x_attr[F_LIT_DARK];
+                                       c = f_ptr->x_char[F_LIT_DARK];
                                }
 
                                /* Handle "out-of-sight" grids */
@@ -942,18 +1019,13 @@ void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
                else
                {
                        /* Unsafe cave grid -- idea borrowed from Unangband */
-                       if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
-                               feat = FEAT_UNDETECTED;
-                       else
-                               feat = FEAT_NONE;
+                       feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
 
                        /* Access darkness */
                        f_ptr = &f_info[feat];
 
-                       /* Normal attr */
+                       /* Normal attr/char */
                        a = f_ptr->x_attr[F_LIT_STANDARD];
-
-                       /* Normal char */
                        c = f_ptr->x_char[F_LIT_STANDARD];
                }
        }
@@ -964,17 +1036,15 @@ void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
                /* Memorized grids */
                if (c_ptr->info & CAVE_MARK)
                {
-                       /* Normal char */
-                       c = f_ptr->x_char[F_LIT_STANDARD];
-
-                       /* Normal attr */
+                       /* Normal attr/char */
                        a = f_ptr->x_attr[F_LIT_STANDARD];
+                       c = f_ptr->x_char[F_LIT_STANDARD];
 
                        if (p_ptr->wild_mode)
                        {
                                /* Special lighting effects */
-                               /* Handle "blind" */
-                               if (view_granite_lite && p_ptr->blind)
+                               /* Handle "blind" or "night" */
+                               if (view_granite_lite && (p_ptr->blind || !is_daytime()))
                                {
                                        /* Use a darkened colour/tile */
                                        a = f_ptr->x_attr[F_LIT_DARK];
@@ -983,9 +1053,26 @@ void map_info(int y, int 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(c_ptr) && !p_ptr->blind)
                        {
-                               darkened_grid_hack();
+                               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;
+
+                                       /* Access darkness */
+                                       f_ptr = &f_info[feat];
+
+                                       /* Char and attr of darkness */
+                                       a = f_ptr->x_attr[F_LIT_STANDARD];
+                                       c = f_ptr->x_char[F_LIT_STANDARD];
+                               }
+                               else if (view_granite_lite && view_bright_lite)
+                               {
+                                       /* Use a darkened colour/tile */
+                                       a = f_ptr->x_attr[F_LIT_DARK];
+                                       c = f_ptr->x_char[F_LIT_DARK];
+                               }
                        }
 
                        /* Special lighting effects */
@@ -1031,21 +1118,11 @@ void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
                                        }
 
                                        /* Not glowing correctly */
-                                       else
+                                       else if (!have_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(y, x))
                                        {
-                                               int xx, yy;
-
-                                               /* Hack -- move towards player */
-                                               yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
-                                               xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
-
-                                               /* Check for "local" illumination */
-                                               if ((cave[yy][xx].info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
-                                               {
-                                                       /* Use a darkened colour/tile */
-                                                       a = f_ptr->x_attr[F_LIT_DARK];
-                                                       c = f_ptr->x_char[F_LIT_DARK];
-                                               }
+                                               /* Use a darkened colour/tile */
+                                               a = f_ptr->x_attr[F_LIT_DARK];
+                                               c = f_ptr->x_char[F_LIT_DARK];
                                        }
                                }
                        }
@@ -1055,18 +1132,13 @@ void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
                else
                {
                        /* Unsafe cave grid -- idea borrowed from Unangband */
-                       if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
-                               feat = FEAT_UNDETECTED;
-                       else
-                               feat = FEAT_NONE;
+                       feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
 
                        /* Access feature */
                        f_ptr = &f_info[feat];
 
-                       /* Normal attr */
+                       /* Normal attr/char */
                        a = f_ptr->x_attr[F_LIT_STANDARD];
-
-                       /* Normal char */
                        c = f_ptr->x_char[F_LIT_STANDARD];
                }
        }
@@ -1084,11 +1156,7 @@ void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
        /* Hack -- rare random hallucination, except on outer dungeon walls */
        if (p_ptr->image)
        {
-               /* Access real feature */
-               feature_type *rf_ptr = &f_info[c_ptr->feat];
-
-               if (!(have_flag(rf_ptr->flags, FF_SOLID) && have_flag(rf_ptr->flags, FF_PERMANENT)) &&
-                       one_in_(256))
+               if (one_in_(256))
                {
                        /* Hallucinate */
                        image_random(ap, cp);
@@ -1107,7 +1175,7 @@ void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
                next_o_idx = o_ptr->next_o_idx;
 
                /* Memorized objects */
-               if (o_ptr->marked)
+               if (o_ptr->marked & OM_FOUND)
                {
                        if (display_autopick)
                        {
@@ -1380,13 +1448,13 @@ void note_spot(int y, int x)
        if (p_ptr->blind) return;
 
        /* Analyze non-torch-lit grids */
-       if (!(c_ptr->info & (CAVE_LITE)))
+       if (!(c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
        {
                /* Require line of sight to the grid */
                if (!(c_ptr->info & (CAVE_VIEW))) return;
 
                /* Require "perma-lite" of the grid */
-               if (!(c_ptr->info & CAVE_MNLT) && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW))
+               if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
                {
                        /* Not Ninja */
                        if (!p_ptr->see_nocto) return;
@@ -1410,8 +1478,11 @@ void note_spot(int y, int x)
        /* Hack -- memorize grids */
        if (!(c_ptr->info & (CAVE_MARK)))
        {
+               /* Feature code (applying "mimic" field) */
+               feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
+
                /* Memorize some "boring" grids */
-               if (!have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_REMEMBER))
+               if (!have_flag(f_ptr->flags, FF_REMEMBER))
                {
                        /* Option -- memorize all torch-lit floors */
                        if (view_torch_grids &&
@@ -1430,7 +1501,7 @@ void note_spot(int y, int x)
                }
 
                /* Memorize normal grids */
-               else if (cave_floor_grid(c_ptr))
+               else if (have_flag(f_ptr->flags, FF_LOS))
                {
                        /* Memorize */
                        c_ptr->info |= (CAVE_MARK);
@@ -1451,20 +1522,10 @@ void note_spot(int y, int x)
                }
 
                /* Memorize certain non-torch-lit wall grids */
-               else
+               else if (check_local_illumination(y, x))
                {
-                       int yy, xx;
-
-                       /* Hack -- move one grid towards player */
-                       yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
-                       xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
-
-                       /* Check for "local" illumination */
-                       if ((cave[yy][xx].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
-                       {
-                               /* Memorize */
-                               c_ptr->info |= (CAVE_MARK);
-                       }
+                       /* Memorize */
+                       c_ptr->info |= (CAVE_MARK);
                }
        }
 }
@@ -1505,7 +1566,7 @@ void display_dungeon(void)
                                /* Clear out-of-bound tiles */
 
                                /* Access darkness */
-                               feature_type *f_ptr = &f_info[FEAT_NONE];
+                               feature_type *f_ptr = &f_info[feat_none];
 
                                /* Normal attr */
                                a = f_ptr->x_attr[F_LIT_STANDARD];
@@ -1672,6 +1733,7 @@ void prt_path(int y, int x)
        {
                int ny = GRID_Y(path_g[i]);
                int nx = GRID_X(path_g[i]);
+               cave_type *c_ptr = &cave[ny][nx];
 
                if (panel_contains(ny, nx))
                {
@@ -1681,7 +1743,7 @@ void prt_path(int y, int x)
                        byte ta;
                        char tc;
 
-                       if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
+                       if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
                        {
                                /* Determine what is there */
                                map_info(ny, nx, &a, &c, &ta, &tc);
@@ -1708,7 +1770,7 @@ void prt_path(int y, int x)
                }
 
                /* Known Wall */
-               if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
+               if ((c_ptr->info & CAVE_MARK) && !cave_have_flag_grid(c_ptr, FF_PROJECT)) break;
 
                /* Change color */
                if (nx == x && ny == y) default_color = TERM_L_DARK;
@@ -2377,7 +2439,7 @@ prt("
  * I am thinking in terms of an algorithm that "walks" from the central point
  * out to the maximal "distance", at each point, determining the "view" code
  * (above).  For each grid not on a major axis or diagonal, the "view" code
- * depends on the "cave_floor_bold()" and "view" of exactly two other grids
+ * depends on the "cave_los_bold()" and "view" of exactly two other grids
  * (the one along the nearest diagonal, and the one next to that one, see
  * "update_view_aux()"...).
  *
@@ -2476,11 +2538,12 @@ void forget_lite(void)
  */
 #define cave_lite_hack(Y,X) \
 {\
-    if (!(cave[Y][X].info & (CAVE_LITE))) { \
-    cave[Y][X].info |= (CAVE_LITE); \
-    lite_y[lite_n] = (Y); \
-    lite_x[lite_n] = (X); \
-                           lite_n++;} \
+       if (!(cave[Y][X].info & (CAVE_LITE))) \
+       { \
+               cave[Y][X].info |= (CAVE_LITE); \
+               lite_y[lite_n] = (Y); \
+               lite_x[lite_n++] = (X); \
+       } \
 }
 
 
@@ -2577,7 +2640,7 @@ void update_lite(void)
        if (p >= 2)
        {
                /* South of the player */
-               if (cave_floor_bold(py+1, px))
+               if (cave_los_bold(py + 1, px))
                {
                        cave_lite_hack(py+2, px);
                        cave_lite_hack(py+2, px+1);
@@ -2585,7 +2648,7 @@ void update_lite(void)
                }
 
                /* North of the player */
-               if (cave_floor_bold(py-1, px))
+               if (cave_los_bold(py - 1, px))
                {
                        cave_lite_hack(py-2, px);
                        cave_lite_hack(py-2, px+1);
@@ -2593,7 +2656,7 @@ void update_lite(void)
                }
 
                /* East of the player */
-               if (cave_floor_bold(py, px+1))
+               if (cave_los_bold(py, px + 1))
                {
                        cave_lite_hack(py, px+2);
                        cave_lite_hack(py+1, px+2);
@@ -2601,7 +2664,7 @@ void update_lite(void)
                }
 
                /* West of the player */
-               if (cave_floor_bold(py, px-1))
+               if (cave_los_bold(py, px - 1))
                {
                        cave_lite_hack(py, px-2);
                        cave_lite_hack(py+1, px-2);
@@ -2618,25 +2681,25 @@ void update_lite(void)
                if (p > 14) p = 14;
 
                /* South-East of the player */
-               if (cave_floor_bold(py+1, px+1))
+               if (cave_los_bold(py + 1, px + 1))
                {
                        cave_lite_hack(py+2, px+2);
                }
 
                /* South-West of the player */
-               if (cave_floor_bold(py+1, px-1))
+               if (cave_los_bold(py + 1, px - 1))
                {
                        cave_lite_hack(py+2, px-2);
                }
 
                /* North-East of the player */
-               if (cave_floor_bold(py-1, px+1))
+               if (cave_los_bold(py - 1, px + 1))
                {
                        cave_lite_hack(py-2, px+2);
                }
 
                /* North-West of the player */
-               if (cave_floor_bold(py-1, px-1))
+               if (cave_los_bold(py - 1, px - 1))
                {
                        cave_lite_hack(py-2, px-2);
                }
@@ -2675,7 +2738,7 @@ void update_lite(void)
                                if (d > p) continue;
 
                                /* Viewable, nearby, grids get "torch lit" */
-                               if (player_has_los_bold(y, x))
+                               if (cave[y][x].info & CAVE_VIEW)
                                {
                                        /* This grid is "torch lit" */
                                        cave_lite_hack(y, x);
@@ -2747,11 +2810,8 @@ static void mon_lite_hack(int y, int x)
        /* Want a unlit square in view of the player */
        if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
 
-       if (!cave_floor_grid(c_ptr))
+       if (!cave_los_grid(c_ptr))
        {
-               /* Hack XXX XXX - Is it a wall and monster not in LOS? */
-               if (mon_invis) return;
-
                /* Hack -- Prevent monster lite leakage in walls */
 
                /* Horizontal walls between player and a monster */
@@ -2764,12 +2824,15 @@ static void mon_lite_hack(int y, int x)
                        /* Only first wall viewed from mid-x is lit */
                        if (x < midpoint)
                        {
-                               if (!cave_floor_bold(y, x + 1)) return;
+                               if (!cave_los_bold(y, x + 1)) return;
                        }
                        else if (x > midpoint)
                        {
-                               if (!cave_floor_bold(y, x - 1)) return;
+                               if (!cave_los_bold(y, x - 1)) return;
                        }
+
+                       /* Hack XXX XXX - Is it a wall and monster not in LOS? */
+                       else if (mon_invis) return;
                }
 
                /* Vertical walls between player and a monster */
@@ -2782,12 +2845,15 @@ static void mon_lite_hack(int y, int x)
                        /* Only first wall viewed from mid-y is lit */
                        if (y < midpoint)
                        {
-                               if (!cave_floor_bold(y + 1, x)) return;
+                               if (!cave_los_bold(y + 1, x)) return;
                        }
                        else if (y > midpoint)
                        {
-                               if (!cave_floor_bold(y - 1, x)) return;
+                               if (!cave_los_bold(y - 1, x)) return;
                        }
+
+                       /* Hack XXX XXX - Is it a wall and monster not in LOS? */
+                       else if (mon_invis) return;
                }
        }
 
@@ -2830,11 +2896,8 @@ static void mon_dark_hack(int y, int 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 (!cave_floor_grid(c_ptr))
+       if (!cave_los_grid(c_ptr) && !cave_have_flag_grid(c_ptr, FF_PROJECT))
        {
-               /* Hack XXX XXX - Is it a wall and monster not in LOS? */
-               if (mon_invis) return;
-
                /* Hack -- Prevent monster dark lite leakage in walls */
 
                /* Horizontal walls between player and a monster */
@@ -2847,12 +2910,15 @@ static void mon_dark_hack(int y, int x)
                        /* Only first wall viewed from mid-x is lit */
                        if (x < midpoint)
                        {
-                               if (!cave_floor_bold(y, x + 1)) return;
+                               if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
                        }
                        else if (x > midpoint)
                        {
-                               if (!cave_floor_bold(y, x - 1)) return;
+                               if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
                        }
+
+                       /* Hack XXX XXX - Is it a wall and monster not in LOS? */
+                       else if (mon_invis) return;
                }
 
                /* Vertical walls between player and a monster */
@@ -2865,12 +2931,15 @@ static void mon_dark_hack(int y, int x)
                        /* Only first wall viewed from mid-y is lit */
                        if (y < midpoint)
                        {
-                               if (!cave_floor_bold(y + 1, x)) return;
+                               if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
                        }
                        else if (y > midpoint)
                        {
-                               if (!cave_floor_bold(y - 1, x)) return;
+                               if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
                        }
+
+                       /* Hack XXX XXX - Is it a wall and monster not in LOS? */
+                       else if (mon_invis) return;
                }
        }
 
@@ -2903,6 +2972,7 @@ void update_mon_lite(void)
 
        s16b fx, fy;
        void (*add_mon_lite)(int, int);
+       int f_flag;
 
        s16b end_temp;
 
@@ -2926,166 +2996,172 @@ void update_mon_lite(void)
        /* Empty temp list of new squares to lite up */
        temp_n = 0;
 
-       /* Loop through monsters, adding newly lit squares to changes list */
-       for (i = 1; i < m_max; i++)
+       /* If a monster stops time, don't process */
+       if (!world_monster)
        {
-               monster_type *m_ptr = &m_list[i];
-               monster_race *r_ptr = &r_info[m_ptr->r_idx];
+               monster_type *m_ptr;
+               monster_race *r_ptr;
 
-               /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
+               /* Loop through monsters, adding newly lit squares to changes list */
+               for (i = 1; i < m_max; i++)
+               {
+                       m_ptr = &m_list[i];
+                       r_ptr = &r_info[m_ptr->r_idx];
 
-               /* Is it too far away? */
-               if (m_ptr->cdis > dis_lim) continue;
+                       /* Skip dead monsters */
+                       if (!m_ptr->r_idx) continue;
 
-               /* If a monster stops time, break */
-               if (world_monster) break;
+                       /* Is it too far away? */
+                       if (m_ptr->cdis > dis_lim) continue;
 
-               /* Get lite radius */
-               rad = 0;
+                       /* Get lite radius */
+                       rad = 0;
 
-               /* Note the radii are cumulative */
-               if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
-               if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
-               if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
-               if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
+                       /* Note the radii are cumulative */
+                       if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
+                       if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
+                       if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
+                       if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
 
-               /* Exit if has no light */
-               if (!rad) continue;
-               else if (rad > 0)
-               {
-                       if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
-                       if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
-                       add_mon_lite = mon_lite_hack;
-               }
-               else
-               {
-                       if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (m_ptr->csleep || (!dun_level && !is_daytime()))) continue;
-                       add_mon_lite = mon_dark_hack;
-                       rad = -rad; /* Use absolute value */
-               }
+                       /* Exit if has no light */
+                       if (!rad) continue;
+                       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;
+                               add_mon_lite = mon_lite_hack;
+                               f_flag = FF_LOS;
+                       }
+                       else
+                       {
+                               if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && !is_daytime()))) continue;
+                               add_mon_lite = mon_dark_hack;
+                               f_flag = FF_PROJECT;
+                               rad = -rad; /* Use absolute value */
+                       }
 
-               /* Access the location */
-               mon_fx = m_ptr->fx;
-               mon_fy = m_ptr->fy;
+                       /* Access the location */
+                       mon_fx = m_ptr->fx;
+                       mon_fy = m_ptr->fy;
 
-               /* Is the monster visible? */
-               mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
+                       /* Is the monster visible? */
+                       mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
 
-               /* The square it is on */
-               add_mon_lite(mon_fy, mon_fx);
+                       /* The square it is on */
+                       add_mon_lite(mon_fy, mon_fx);
 
-               /* Adjacent squares */
-               add_mon_lite(mon_fy + 1, mon_fx);
-               add_mon_lite(mon_fy - 1, mon_fx);
-               add_mon_lite(mon_fy, mon_fx + 1);
-               add_mon_lite(mon_fy, mon_fx - 1);
-               add_mon_lite(mon_fy + 1, mon_fx + 1);
-               add_mon_lite(mon_fy + 1, mon_fx - 1);
-               add_mon_lite(mon_fy - 1, mon_fx + 1);
-               add_mon_lite(mon_fy - 1, mon_fx - 1);
+                       /* Adjacent squares */
+                       add_mon_lite(mon_fy + 1, mon_fx);
+                       add_mon_lite(mon_fy - 1, mon_fx);
+                       add_mon_lite(mon_fy, mon_fx + 1);
+                       add_mon_lite(mon_fy, mon_fx - 1);
+                       add_mon_lite(mon_fy + 1, mon_fx + 1);
+                       add_mon_lite(mon_fy + 1, mon_fx - 1);
+                       add_mon_lite(mon_fy - 1, mon_fx + 1);
+                       add_mon_lite(mon_fy - 1, mon_fx - 1);
 
-               /* Radius 2 */
-               if (rad >= 2)
-               {
-                       /* South of the monster */
-                       if (cave_floor_bold(mon_fy + 1, mon_fx))
+                       /* Radius 2 */
+                       if (rad >= 2)
                        {
-                               add_mon_lite(mon_fy + 2, mon_fx + 1);
-                               add_mon_lite(mon_fy + 2, mon_fx);
-                               add_mon_lite(mon_fy + 2, mon_fx - 1);
+                               /* South of the monster */
+                               if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
+                               {
+                                       add_mon_lite(mon_fy + 2, mon_fx + 1);
+                                       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];
+                                       c_ptr = &cave[mon_fy + 2][mon_fx];
 
-                               /* Radius 3 */
-                               if ((rad == 3) && cave_floor_grid(c_ptr))
-                               {
-                                       add_mon_lite(mon_fy + 3, mon_fx + 1);
-                                       add_mon_lite(mon_fy + 3, mon_fx);
-                                       add_mon_lite(mon_fy + 3, mon_fx - 1);
+                                       /* Radius 3 */
+                                       if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
+                                       {
+                                               add_mon_lite(mon_fy + 3, mon_fx + 1);
+                                               add_mon_lite(mon_fy + 3, mon_fx);
+                                               add_mon_lite(mon_fy + 3, mon_fx - 1);
+                                       }
                                }
-                       }
 
-                       /* North of the monster */
-                       if (cave_floor_bold(mon_fy - 1, mon_fx))
-                       {
-                               add_mon_lite(mon_fy - 2, mon_fx + 1);
-                               add_mon_lite(mon_fy - 2, mon_fx);
-                               add_mon_lite(mon_fy - 2, mon_fx - 1);
+                               /* North of the monster */
+                               if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
+                               {
+                                       add_mon_lite(mon_fy - 2, mon_fx + 1);
+                                       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];
+                                       c_ptr = &cave[mon_fy - 2][mon_fx];
 
-                               /* Radius 3 */
-                               if ((rad == 3) && cave_floor_grid(c_ptr))
-                               {
-                                       add_mon_lite(mon_fy - 3, mon_fx + 1);
-                                       add_mon_lite(mon_fy - 3, mon_fx);
-                                       add_mon_lite(mon_fy - 3, mon_fx - 1);
+                                       /* Radius 3 */
+                                       if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
+                                       {
+                                               add_mon_lite(mon_fy - 3, mon_fx + 1);
+                                               add_mon_lite(mon_fy - 3, mon_fx);
+                                               add_mon_lite(mon_fy - 3, mon_fx - 1);
+                                       }
                                }
-                       }
 
-                       /* East of the monster */
-                       if (cave_floor_bold(mon_fy, mon_fx + 1))
-                       {
-                               add_mon_lite(mon_fy + 1, mon_fx + 2);
-                               add_mon_lite(mon_fy, mon_fx + 2);
-                               add_mon_lite(mon_fy - 1, mon_fx + 2);
+                               /* East of the monster */
+                               if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
+                               {
+                                       add_mon_lite(mon_fy + 1, mon_fx + 2);
+                                       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];
+                                       c_ptr = &cave[mon_fy][mon_fx + 2];
 
-                               /* Radius 3 */
-                               if ((rad == 3) && cave_floor_grid(c_ptr))
-                               {
-                                       add_mon_lite(mon_fy + 1, mon_fx + 3);
-                                       add_mon_lite(mon_fy, mon_fx + 3);
-                                       add_mon_lite(mon_fy - 1, mon_fx + 3);
+                                       /* Radius 3 */
+                                       if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
+                                       {
+                                               add_mon_lite(mon_fy + 1, mon_fx + 3);
+                                               add_mon_lite(mon_fy, mon_fx + 3);
+                                               add_mon_lite(mon_fy - 1, mon_fx + 3);
+                                       }
                                }
-                       }
 
-                       /* West of the monster */
-                       if (cave_floor_bold(mon_fy, mon_fx - 1))
-                       {
-                               add_mon_lite(mon_fy + 1, mon_fx - 2);
-                               add_mon_lite(mon_fy, mon_fx - 2);
-                               add_mon_lite(mon_fy - 1, mon_fx - 2);
+                               /* West of the monster */
+                               if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
+                               {
+                                       add_mon_lite(mon_fy + 1, mon_fx - 2);
+                                       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];
+                                       c_ptr = &cave[mon_fy][mon_fx - 2];
 
-                               /* Radius 3 */
-                               if ((rad == 3) && cave_floor_grid(c_ptr))
-                               {
-                                       add_mon_lite(mon_fy + 1, mon_fx - 3);
-                                       add_mon_lite(mon_fy, mon_fx - 3);
-                                       add_mon_lite(mon_fy - 1, mon_fx - 3);
+                                       /* Radius 3 */
+                                       if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
+                                       {
+                                               add_mon_lite(mon_fy + 1, mon_fx - 3);
+                                               add_mon_lite(mon_fy, mon_fx - 3);
+                                               add_mon_lite(mon_fy - 1, mon_fx - 3);
+                                       }
                                }
                        }
-               }
 
-               /* Radius 3 */
-               if (rad == 3)
-               {
-                       /* South-East of the monster */
-                       if (cave_floor_bold(mon_fy + 1, mon_fx + 1))
+                       /* Radius 3 */
+                       if (rad == 3)
                        {
-                               add_mon_lite(mon_fy + 2, mon_fx + 2);
-                       }
+                               /* South-East of the monster */
+                               if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
+                               {
+                                       add_mon_lite(mon_fy + 2, mon_fx + 2);
+                               }
 
-                       /* South-West of the monster */
-                       if (cave_floor_bold(mon_fy + 1, mon_fx - 1))
-                       {
-                               add_mon_lite(mon_fy + 2, mon_fx - 2);
-                       }
+                               /* South-West of the monster */
+                               if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
+                               {
+                                       add_mon_lite(mon_fy + 2, mon_fx - 2);
+                               }
 
-                       /* North-East of the monster */
-                       if (cave_floor_bold(mon_fy - 1, mon_fx + 1))
-                       {
-                               add_mon_lite(mon_fy - 2, mon_fx + 2);
-                       }
+                               /* North-East of the monster */
+                               if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
+                               {
+                                       add_mon_lite(mon_fy - 2, mon_fx + 2);
+                               }
 
-                       /* North-West of the monster */
-                       if (cave_floor_bold(mon_fy - 1, mon_fx - 1))
-                       {
-                               add_mon_lite(mon_fy - 2, mon_fx - 2);
+                               /* North-West of the monster */
+                               if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
+                               {
+                                       add_mon_lite(mon_fy - 2, mon_fx - 2);
+                               }
                        }
                }
        }
@@ -3260,7 +3336,7 @@ void forget_view(void)
                /* Forget that the grid is viewable */
                c_ptr->info &= ~(CAVE_VIEW);
 
-               if (!panel_contains(y, x)) continue;
+               /* if (!panel_contains(y, x)) continue; */
 
                /* Update the screen */
                /* lite_spot(y, x); Perhaps don't need? */
@@ -3321,8 +3397,8 @@ static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
 
 
        /* Check for walls */
-       f1 = (cave_floor_grid(g1_c_ptr));
-       f2 = (cave_floor_grid(g2_c_ptr));
+       f1 = (cave_los_grid(g1_c_ptr));
+       f2 = (cave_los_grid(g2_c_ptr));
 
        /* Totally blocked by physical walls */
        if (!f1 && !f2) return (TRUE);
@@ -3341,7 +3417,7 @@ static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
 
 
        /* Check for walls */
-       wall = (!cave_floor_grid(c_ptr));
+       wall = (!cave_los_grid(c_ptr));
 
 
        /* Check the "ease" of visibility */
@@ -3457,7 +3533,7 @@ static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
  * Note also the care taken to prevent "running off the map".  The use of
  * explicit checks on the "validity" of the "diagonal", and the fact that
  * the loops are never allowed to "leave" the map, lets "update_view_aux()"
- * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
+ * use the optimized "cave_los_bold()" macro, and to avoid the overhead
  * of multiple checks on the validity of grids.
  *
  * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
@@ -3473,8 +3549,8 @@ static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
  * told not to go farther than the current strip's farthest viewable grid,
  * unless open space is still available.  This uses the "k" variable.
  *
- * Note the use of "inline" macros for efficiency.  The "cave_floor_grid()"
- * macro is a replacement for "cave_floor_bold()" which takes a pointer to
+ * 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
  * 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
@@ -3581,7 +3657,7 @@ void update_view(void)
                c_ptr = &cave[y+d][x+d];
                c_ptr->info |= (CAVE_XTRA);
                cave_view_hack(c_ptr, y+d, x+d);
-               if (!cave_floor_grid(c_ptr)) break;
+               if (!cave_los_grid(c_ptr)) break;
        }
 
        /* Scan south-west */
@@ -3590,7 +3666,7 @@ void update_view(void)
                c_ptr = &cave[y+d][x-d];
                c_ptr->info |= (CAVE_XTRA);
                cave_view_hack(c_ptr, y+d, x-d);
-               if (!cave_floor_grid(c_ptr)) break;
+               if (!cave_los_grid(c_ptr)) break;
        }
 
        /* Scan north-east */
@@ -3599,7 +3675,7 @@ void update_view(void)
                c_ptr = &cave[y-d][x+d];
                c_ptr->info |= (CAVE_XTRA);
                cave_view_hack(c_ptr, y-d, x+d);
-               if (!cave_floor_grid(c_ptr)) break;
+               if (!cave_los_grid(c_ptr)) break;
        }
 
        /* Scan north-west */
@@ -3608,7 +3684,7 @@ void update_view(void)
                c_ptr = &cave[y-d][x-d];
                c_ptr->info |= (CAVE_XTRA);
                cave_view_hack(c_ptr, y-d, x-d);
-               if (!cave_floor_grid(c_ptr)) break;
+               if (!cave_los_grid(c_ptr)) break;
        }
 
 
@@ -3620,7 +3696,7 @@ void update_view(void)
                c_ptr = &cave[y+d][x];
                c_ptr->info |= (CAVE_XTRA);
                cave_view_hack(c_ptr, y+d, x);
-               if (!cave_floor_grid(c_ptr)) break;
+               if (!cave_los_grid(c_ptr)) break;
        }
 
        /* Initialize the "south strips" */
@@ -3632,7 +3708,7 @@ void update_view(void)
                c_ptr = &cave[y-d][x];
                c_ptr->info |= (CAVE_XTRA);
                cave_view_hack(c_ptr, y-d, x);
-               if (!cave_floor_grid(c_ptr)) break;
+               if (!cave_los_grid(c_ptr)) break;
        }
 
        /* Initialize the "north strips" */
@@ -3644,7 +3720,7 @@ void update_view(void)
                c_ptr = &cave[y][x+d];
                c_ptr->info |= (CAVE_XTRA);
                cave_view_hack(c_ptr, y, x+d);
-               if (!cave_floor_grid(c_ptr)) break;
+               if (!cave_los_grid(c_ptr)) break;
        }
 
        /* Initialize the "east strips" */
@@ -3656,7 +3732,7 @@ void update_view(void)
                c_ptr = &cave[y][x-d];
                c_ptr->info |= (CAVE_XTRA);
                cave_view_hack(c_ptr, y, x-d);
-               if (!cave_floor_grid(c_ptr)) break;
+               if (!cave_los_grid(c_ptr)) break;
        }
 
        /* Initialize the "west strips" */
@@ -4101,7 +4177,7 @@ void update_flow(void)
                        if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
 
                        /* Ignore "walls" and "rubble" */
-                       if (!have_flag(f_flags_grid(c_ptr), FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
+                       if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
 
                        /* Save the flow cost */
                        if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
@@ -4192,7 +4268,7 @@ void update_smell(void)
                        c_ptr = &cave[y][x];
 
                        /* Walls, water, and lava cannot hold scent. */
-                       if (!have_flag(f_flags_grid(c_ptr), FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
+                       if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
 
                        /* Grid must not be blocked by walls from the character */
                        if (!player_has_los_bold(y, x)) continue;
@@ -4371,6 +4447,11 @@ void wiz_lite(bool ninja)
 
        /* Window stuff */
        p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
+
+       if (p_ptr->special_defense & NINJA_S_STEALTH)
+       {
+               if (cave[py][px].info & CAVE_GLOW) set_superstealth(FALSE);
+       }
 }
 
 
@@ -4421,7 +4502,7 @@ void wiz_dark(void)
                if (o_ptr->held_m_idx) continue;
 
                /* Forget the object */
-               o_ptr->marked = 0;
+               o_ptr->marked &= OM_TOUCHED;
        }
 
        /* Mega-Hack -- Forget the view and lite */
@@ -4451,49 +4532,143 @@ void cave_set_feat(int y, int x, int feat)
 {
        cave_type *c_ptr = &cave[y][x];
        feature_type *f_ptr = &f_info[feat];
+       bool old_los, old_mirror;
+
+       if (!character_dungeon)
+       {
+               /* Clear mimic type */
+               c_ptr->mimic = 0;
+
+               /* Change the feature */
+               c_ptr->feat = feat;
+
+               /* Hack -- glow the GLOW terrain */
+               if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
+               {
+                       int i, 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;
+                       }
+               }
+
+               return;
+       }
+
+       old_los = cave_have_flag_bold(y, x, FF_LOS);
+       old_mirror = is_mirror_grid(c_ptr);
 
        /* Clear mimic type */
        c_ptr->mimic = 0;
 
+       /* Change the feature */
+       c_ptr->feat = feat;
+
        /* Remove flag for mirror/glyph */
        c_ptr->info &= ~(CAVE_OBJECT);
 
-       /* Change the feature */
-       c_ptr->feat = feat;
+       if (old_mirror && (d_info[dungeon_type].flags1 & DF1_DARKNESS))
+       {
+               c_ptr->info &= ~(CAVE_GLOW);
+               if (!view_torch_grids) c_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);
 
-       /* Check for change to out of sight grid */
-       else if (!player_can_see_bold(y, x)) c_ptr->info &= ~(CAVE_MARK);
+       /* Update the monster */
+       if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
 
-       /* Hack -- glow the deep lava */
+       /* Notice */
+       note_spot(y, x);
+
+       /* Redraw */
+       lite_spot(y, x);
+
+       /* Check if los has changed */
+       if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
+       {
+
+#ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
+
+               update_local_illumination(y, x);
+
+#endif /* COMPLEX_WALL_ILLUMINATION */
+
+               /* Update the visuals */
+               p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
+       }
+
+       /* Hack -- glow the GLOW terrain */
        if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
        {
                int i, yy, xx;
+               cave_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;
-                       cave[yy][xx].info |= CAVE_GLOW;
-                       if (player_has_los_bold(yy, xx))
+                       cc_ptr = &cave[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);
+
                                /* Notice */
                                note_spot(yy, xx);
 
                                /* Redraw */
                                lite_spot(yy, xx);
                        }
+
+                       update_local_illumination(yy, xx);
+               }
+
+               if (p_ptr->special_defense & NINJA_S_STEALTH)
+               {
+                       if (cave[py][px].info & CAVE_GLOW) set_superstealth(FALSE);
                }
        }
+}
 
-       /* Notice */
-       note_spot(y, x);
 
-       /* Redraw */
-       lite_spot(y, x);
+int conv_dungeon_feat(int newfeat)
+{
+       feature_type *f_ptr = &f_info[newfeat];
+
+       if (have_flag(f_ptr->flags, FF_CONVERT))
+       {
+               switch (f_ptr->subtype)
+               {
+               case CONVERT_TYPE_FLOOR:
+                       return floor_type[randint0(100)];
+               case CONVERT_TYPE_WALL:
+                       return fill_type[randint0(100)];
+               case CONVERT_TYPE_INNER:
+                       return feat_wall_inner;
+               case CONVERT_TYPE_OUTER:
+                       return feat_wall_outer;
+               case CONVERT_TYPE_SOLID:
+                       return feat_wall_solid;
+               case CONVERT_TYPE_STREAM1:
+                       return d_info[dungeon_type].stream1;
+               case CONVERT_TYPE_STREAM2:
+                       return d_info[dungeon_type].stream2;
+               default:
+                       return newfeat;
+               }
+       }
+       else return newfeat;
 }
 
 
@@ -4504,26 +4679,17 @@ void cave_set_feat(int y, int x, int feat)
 int feat_state(int feat, int action)
 {
        feature_type *f_ptr = &f_info[feat];
-       int newfeat, i;
+       int i;
 
        /* Get the new feature */
        for (i = 0; i < MAX_FEAT_STATES; i++)
        {
-               if (f_ptr->state[i].action == action)
-               {
-                       newfeat = f_ptr->state[i].result;
-                       return (newfeat == FEAT_FLOOR) ? floor_type[randint0(100)] : newfeat;
-               }
+               if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
        }
 
        if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
 
-       if (feature_action_flags[action] & FAF_DESTROY)
-       {
-               newfeat = f_ptr->destroyed;
-               return (newfeat == FEAT_FLOOR) ? floor_type[randint0(100)] : newfeat;
-       }
-       else return feat;
+       return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
 }
 
 /*
@@ -4575,21 +4741,40 @@ void cave_alter_feat(int y, int x, int action)
 #endif
                }
        }
+
+       if (feature_action_flags[action] & FAF_CRASH_GLASS)
+       {
+               feature_type *old_f_ptr = &f_info[oldfeat];
+
+               if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
+               {
+                       project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(dun_level, 100) / 4, GF_SHARDS,
+                               (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
+               }
+       }
 }
 
 
 /* Remove a mirror */
 void remove_mirror(int y, int x)
 {
+       cave_type *c_ptr = &cave[y][x];
+
        /* Remove the mirror */
-       cave[y][x].info &= ~(CAVE_OBJECT);
-       cave[y][x].mimic = 0;
+       c_ptr->info &= ~(CAVE_OBJECT);
+       c_ptr->mimic = 0;
 
        if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
        {
-               cave[y][x].info &= ~(CAVE_GLOW);
-               if( !view_torch_grids )cave[y][x].info &= ~(CAVE_MARK);
+               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);
+
+               update_local_illumination(y, x);
        }
+
        /* Notice */
        note_spot(y, x);
 
@@ -4706,8 +4891,8 @@ bool projectable(int y1, int x1, int y2, int x2)
        /* Check the projection path */
        grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
 
-       /* No grid is ever projectable from itself */
-       if (!grid_n) return (FALSE);
+       /* Identical grid */
+       if (!grid_n) return TRUE;
 
        /* Final grid */
        y = GRID_Y(grid_g[grid_n - 1]);
@@ -4752,8 +4937,8 @@ void scatter(int *yp, int *xp, int y, int x, int d, int m)
                /* Ignore "excessively distant" locations */
                if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
 
-               /* Require "line of sight" */
-               if (los(y, x, ny, nx)) break;
+               /* Require "line of projection" */
+               if (projectable(y, x, ny, nx)) break;
        }
 
        /* Save the location */
@@ -4859,6 +5044,20 @@ void disturb(int stop_search, int unused_flag)
                p_ptr->update |= (PU_FLOW);
        }
 
+#ifdef TRAVEL
+       if (travel.run)
+       {
+               /* Cancel */
+               travel.run = 0;
+
+               /* Check for new panel if appropriate */
+               if (center_player && !center_running) verify_panel();
+
+               /* Calculate torch radius */
+               p_ptr->update |= (PU_TORCH);
+       }
+#endif
+
        /* Flush the input if requested */
        if (flush_disturb) flush();
 }
@@ -4891,9 +5090,14 @@ void glow_deep_lava_and_bldg(void)
                                        xx = x + ddx_ddd[i];
                                        if (!in_bounds2(yy, xx)) continue;
                                        cave[yy][xx].info |= CAVE_GLOW;
-                                       if (player_has_los_bold(yy, xx)) note_spot(yy, xx);
                                }
                        }
                }
        }
+
+       /* Update the view and lite */
+       p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
+
+       /* Redraw map */
+       p_ptr->redraw |= (PR_MAP);
 }