OSDN Git Service

[Refactor] #38997 関数マクロpattern_tile() を普通の関数に展開し、player-type * 引数を追加 / Changed macro...
[hengband/hengband.git] / src / floor.c
index bd6c273..c9ff4ff 100644 (file)
@@ -27,73 +27,93 @@ floor_type floor_info;
  */
 saved_floor_type saved_floors[MAX_SAVED_FLOORS];
 
+/*
+ * Grid based version of "cave_empty_bold()"
+ */
+bool is_cave_empty_grid(player_type *player_ptr, grid_type *g_ptr)
+{
+       bool is_empty_grid = cave_have_flag_grid(g_ptr, FF_PLACE);
+       is_empty_grid &= g_ptr->m_idx == 0;
+       is_empty_grid &= !player_grid(player_ptr, g_ptr);
+       return is_empty_grid;
+}
+
+
+bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x)
+{
+       return cave_have_flag_bold(floor_ptr, y, x, FF_PATTERN);
+}
+
+
 /*!
 * @brief 鍵のかかったドアを配置する
+* @param player_ptr プレーヤーへの参照ポインタ
 * @param y 配置したいフロアのY座標
 * @param x 配置したいフロアのX座標
 * @return なし
 */
-void place_locked_door(floor_type *floor_ptr, POSITION y, POSITION x)
+void place_locked_door(player_type *player_ptr, POSITION y, POSITION x)
 {
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
        {
-               place_floor_bold(floor_ptr, y, x);
-       }
-       else
-       {
-               set_cave_feat(floor_ptr, y, x, feat_locked_door_random((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
-               floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
-               delete_monster(floor_ptr, y, x);
+               place_bold(player_ptr, y, x, floor);
+               return;
        }
+
+       set_cave_feat(floor_ptr, y, x, feat_locked_door_random((d_info[player_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
+       floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
+       delete_monster(player_ptr, y, x);
 }
 
 
 /*!
 * @brief 隠しドアを配置する
+* @param player_ptr プレーヤーへの参照ポインタ
 * @param y 配置したいフロアのY座標
 * @param x 配置したいフロアのX座標
 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
 * @return なし
 */
-void place_secret_door(floor_type *floor_ptr, POSITION y, POSITION x, int type)
+void place_secret_door(player_type *player_ptr, POSITION y, POSITION x, int type)
 {
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
        {
-               place_floor_bold(floor_ptr, y, x);
+               place_bold(player_ptr, y, x, floor);
+               return;
        }
-       else
+
+       if (type == DOOR_DEFAULT)
        {
-               grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+               type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
+                       one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
+                       ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
+       }
 
-               if (type == DOOR_DEFAULT)
-               {
-                       type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
-                               one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
-                               ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
-               }
+       /* Create secret door */
+       place_closed_door(player_ptr, y, x, type);
 
-               /* Create secret door */
-               place_closed_door(floor_ptr, y, x, type);
+       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+       if (type != DOOR_CURTAIN)
+       {
+               /* Hide by inner wall because this is used in rooms only */
+               g_ptr->mimic = feat_wall_inner;
 
-               if (type != DOOR_CURTAIN)
+               /* Floor type terrain cannot hide a door */
+               if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
                {
-                       /* Hide by inner wall because this is used in rooms only */
-                       g_ptr->mimic = feat_wall_inner;
-
-                       /* Floor type terrain cannot hide a door */
-                       if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
+                       if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
                        {
-                               if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
-                               {
-                                       g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
-                               }
-                               g_ptr->mimic = 0;
+                               g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
                        }
-               }
 
-               g_ptr->info &= ~(CAVE_FLOOR);
-               delete_monster(floor_ptr, y, x);
+                       g_ptr->mimic = 0;
+               }
        }
+
+       g_ptr->info &= ~(CAVE_FLOOR);
+       delete_monster(player_ptr, y, x);
 }
 
 static int scent_when = 0;
@@ -116,9 +136,6 @@ static int scent_when = 0;
  */
 void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
 {
-       POSITION i, j;
-       POSITION y, x;
-
        /* Create a table that controls the spread of scent */
        const int scent_adjust[5][5] =
        {
@@ -133,9 +150,9 @@ void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
        if (++scent_when == 254)
        {
                /* Scan the entire dungeon */
-               for (y = 0; y < floor_ptr->height; y++)
+               for (POSITION y = 0; y < floor_ptr->height; y++)
                {
-                       for (x = 0; x < floor_ptr->width; x++)
+                       for (POSITION x = 0; x < floor_ptr->width; x++)
                        {
                                int w = floor_ptr->grid_array[y][x].when;
                                floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
@@ -146,17 +163,16 @@ void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
                scent_when = 126;
        }
 
-
        /* Lay down new scent */
-       for (i = 0; i < 5; i++)
+       for (POSITION i = 0; i < 5; i++)
        {
-               for (j = 0; j < 5; j++)
+               for (POSITION j = 0; j < 5; j++)
                {
                        grid_type *g_ptr;
 
                        /* Translate table to map grids */
-                       y = i + subject_ptr->y - 2;
-                       x = j + subject_ptr->x - 2;
+                       POSITION y = i + subject_ptr->y - 2;
+                       POSITION x = j + subject_ptr->x - 2;
 
                        /* Check Bounds */
                        if (!in_bounds(floor_ptr, y, x)) continue;
@@ -164,7 +180,7 @@ void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
                        g_ptr = &floor_ptr->grid_array[y][x];
 
                        /* Walls, water, and lava cannot hold scent. */
-                       if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
+                       if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(subject_ptr, g_ptr->feat)) continue;
 
                        /* Grid must not be blocked by walls from the character */
                        if (!player_has_los_bold(subject_ptr, y, x)) continue;
@@ -184,12 +200,10 @@ void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
  */
 void forget_flow(floor_type *floor_ptr)
 {
-       POSITION x, y;
-
        /* Check the entire dungeon */
-       for (y = 0; y < floor_ptr->height; y++)
+       for (POSITION y = 0; y < floor_ptr->height; y++)
        {
-               for (x = 0; x < floor_ptr->width; x++)
+               for (POSITION x = 0; x < floor_ptr->width; x++)
                {
                        /* Forget the old data */
                        floor_ptr->grid_array[y][x].dist = 0;
@@ -199,15 +213,17 @@ void forget_flow(floor_type *floor_ptr)
        }
 }
 
+
 /*
  * Routine used by the random vault creators to add a door to a location
  * Note that range checking has to be done in the calling routine.
  *
  * The doors must be INSIDE the allocated region.
  */
-void add_door(floor_type* floor_ptr, POSITION x, POSITION y)
+void add_door(player_type *player_ptr, POSITION x, POSITION y)
 {
        /* Need to have a wall in the center square */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (!is_outer_bold(floor_ptr, y, x)) return;
 
        /* look at:
@@ -223,14 +239,13 @@ void add_door(floor_type* floor_ptr, POSITION x, POSITION y)
                (is_outer_bold(floor_ptr, y, x - 1) && is_outer_bold(floor_ptr, y, x + 1)))
        {
                /* secret door */
-               place_secret_door(floor_ptr, y, x, DOOR_DEFAULT);
+               place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
 
                /* set boundarys so don't get wide doors */
-               place_solid_bold(floor_ptr, y, x - 1);
-               place_solid_bold(floor_ptr, y, x + 1);
+               place_bold(player_ptr, y, x - 1, solid);
+               place_bold(player_ptr, y, x + 1, solid);
        }
 
-
        /* look at:
        *  x#x
        *  .#.
@@ -243,32 +258,35 @@ void add_door(floor_type* floor_ptr, POSITION x, POSITION y)
                is_floor_bold(floor_ptr, y, x - 1) && is_floor_bold(floor_ptr, y, x + 1))
        {
                /* secret door */
-               place_secret_door(floor_ptr, y, x, DOOR_DEFAULT);
+               place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
 
                /* set boundarys so don't get wide doors */
-               place_solid_bold(floor_ptr, y - 1, x);
-               place_solid_bold(floor_ptr, y + 1, x);
+               place_bold(player_ptr, y - 1, x, solid);
+               place_bold(player_ptr, y + 1, x, solid);
        }
 }
 
+
 /*!
  * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y 配置を試みたいマスのY座標
  * @param x 配置を試みたいマスのX座標
  * @return なし
  */
-void place_random_stairs(floor_type *floor_ptr, POSITION y, POSITION x)
+void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
 {
        bool up_stairs = TRUE;
        bool down_stairs = TRUE;
        grid_type *g_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        g_ptr = &floor_ptr->grid_array[y][x];
        if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
 
        if (!floor_ptr->dun_level) up_stairs = FALSE;
        if (ironman_downward) up_stairs = FALSE;
-       if (floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
-       if (quest_number(floor_ptr->dun_level) && (floor_ptr->dun_level > 1)) down_stairs = FALSE;
+       if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
+       if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1)) down_stairs = FALSE;
 
        /* We can't place both */
        if (down_stairs && up_stairs)
@@ -283,8 +301,10 @@ void place_random_stairs(floor_type *floor_ptr, POSITION y, POSITION x)
        else if (down_stairs) set_cave_feat(floor_ptr, y, x, feat_down_stair);
 }
 
+
 /*!
  * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y1 始点のy座標
  * @param x1 始点のx座標
  * @param y2 終点のy座標
@@ -325,49 +345,22 @@ void place_random_stairs(floor_type *floor_ptr, POSITION y, POSITION x)
  *\n
  * Use the "update_view()" function to determine player line-of-sight.\n
  */
-bool los(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
+bool los(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
 {
-       /* Delta */
-       POSITION dx, dy;
-
-       /* Absolute */
-       POSITION ax, ay;
-
-       /* Signs */
-       POSITION sx, sy;
-
-       /* Fractions */
-       POSITION qx, qy;
-
-       /* Scanners */
-       POSITION tx, ty;
-
-       /* Scale factors */
-       POSITION f1, f2;
-
-       /* Slope, or 1/Slope, of LOS */
-       POSITION m;
-
-
        /* Extract the offset */
-       dy = y2 - y1;
-       dx = x2 - x1;
+       POSITION dy = y2 - y1;
+       POSITION dx = x2 - x1;
 
        /* Extract the absolute offset */
-       ay = ABS(dy);
-       ax = ABS(dx);
-
+       POSITION ay = ABS(dy);
+       POSITION ax = ABS(dx);
 
        /* Handle adjacent (or identical) grids */
        if ((ax < 2) && (ay < 2)) return TRUE;
 
-
-       /* Paranoia -- require "safe" origin */
-       /* if (!in_bounds(floor_ptr, y1, x1)) return FALSE; */
-       /* if (!in_bounds(floor_ptr, y2, x2)) return FALSE; */
-
-
        /* Directly South/North */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       POSITION tx, ty;
        if (!dx)
        {
                /* South -- check for walls */
@@ -417,11 +410,9 @@ bool los(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION
                return TRUE;
        }
 
-
        /* Extract some signs */
-       sx = (dx < 0) ? -1 : 1;
-       sy = (dy < 0) ? -1 : 1;
-
+       POSITION sx = (dx < 0) ? -1 : 1;
+       POSITION sy = (dy < 0) ? -1 : 1;
 
        /* Vertical "knights" */
        if (ax == 1)
@@ -441,15 +432,15 @@ bool los(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION
                }
        }
 
-
        /* Calculate scale factor div 2 */
-       f2 = (ax * ay);
+       POSITION f2 = (ax * ay);
 
        /* Calculate scale factor */
-       f1 = f2 << 1;
-
+       POSITION f1 = f2 << 1;
 
        /* Travel horizontally */
+       POSITION qy;
+       POSITION m;
        if (ax >= ay)
        {
                /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
@@ -480,71 +471,71 @@ bool los(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION
                        if (qy < f2)
                        {
                                tx += sx;
+                               continue;
                        }
-                       else if (qy > f2)
+                       
+                       if (qy > f2)
                        {
                                ty += sy;
                                if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
                                qy -= f1;
                                tx += sx;
+                               continue;
                        }
-                       else
-                       {
-                               ty += sy;
-                               qy -= f1;
-                               tx += sx;
-                       }
+
+                       ty += sy;
+                       qy -= f1;
+                       tx += sx;
                }
+
+               return TRUE;
        }
 
        /* Travel vertically */
+       /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
+       POSITION qx = ax * ax;
+       m = qx << 1;
+
+       ty = y1 + sy;
+
+       if (qx == f2)
+       {
+               tx = x1 + sx;
+               qx -= f1;
+       }
        else
        {
-               /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
-               qx = ax * ax;
-               m = qx << 1;
+               tx = x1;
+       }
 
-               ty = y1 + sy;
+       /* Note (below) the case (qx == f2), where */
+       /* the LOS exactly meets the corner of a tile. */
+       while (y2 - ty)
+       {
+               if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
 
-               if (qx == f2)
-               {
-                       tx = x1 + sx;
-                       qx -= f1;
-               }
-               else
+               qx += m;
+
+               if (qx < f2)
                {
-                       tx = x1;
+                       ty += sy;
+                       continue;
                }
 
-               /* Note (below) the case (qx == f2), where */
-               /* the LOS exactly meets the corner of a tile. */
-               while (y2 - ty)
+               if (qx > f2)
                {
+                       tx += sx;
                        if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
-
-                       qx += m;
-
-                       if (qx < f2)
-                       {
-                               ty += sy;
-                       }
-                       else if (qx > f2)
-                       {
-                               tx += sx;
-                               if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
-                               qx -= f1;
-                               ty += sy;
-                       }
-                       else
-                       {
-                               tx += sx;
-                               qx -= f1;
-                               ty += sy;
-                       }
+                       qx -= f1;
+                       ty += sy;
+                       continue;
                }
+
+               tx += sx;
+               qx -= f1;
+               ty += sy;
        }
 
-       /* Assume los */
        return TRUE;
 }
 
@@ -555,33 +546,29 @@ bool los(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION
  *
  * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
  */
-bool projectable(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
+bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
 {
-       POSITION y, x;
-
-       int grid_n = 0;
-       u16b grid_g[512];
-
        /* Check the projection path */
-       grid_n = project_path(floor_ptr, grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
+       u16b grid_g[512];
+       int grid_n = project_path(player_ptr, grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
 
        /* Identical grid */
        if (!grid_n) return TRUE;
 
        /* Final grid */
-       y = GRID_Y(grid_g[grid_n - 1]);
-       x = GRID_X(grid_g[grid_n - 1]);
+       POSITION y = GRID_Y(grid_g[grid_n - 1]);
+       POSITION x = GRID_X(grid_g[grid_n - 1]);
 
        /* May not end in an unrequested grid */
-       if ((y != y2) || (x != x2)) return (FALSE);
+       if ((y != y2) || (x != x2)) return FALSE;
 
-       /* Assume okay */
-       return (TRUE);
+       return TRUE;
 }
 
 
 /*!
  * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y1 モンスターを配置したいマスの中心Y座標
  * @param x1 モンスターを配置したいマスの中心X座標
  * @param num 配置したいモンスターの数
@@ -589,30 +576,29 @@ bool projectable(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, P
  * @details
  * Only really called by some of the "vault" routines.
  */
-void vault_monsters(floor_type *floor_ptr, POSITION y1, POSITION x1, int num)
+void vault_monsters(player_type *player_ptr, POSITION y1, POSITION x1, int num)
 {
-       int k, i;
-       POSITION y, x;
-       grid_type *g_ptr;
-
        /* Try to summon "num" monsters "near" the given location */
-       for (k = 0; k < num; k++)
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       for (int k = 0; k < num; k++)
        {
                /* Try nine locations */
-               for (i = 0; i < 9; i++)
+               for (int i = 0; i < 9; i++)
                {
                        int d = 1;
 
                        /* Pick a nearby location */
-                       scatter(&y, &x, y1, x1, d, 0);
+                       POSITION y, x;
+                       scatter(player_ptr, &y, &x, y1, x1, d, 0);
 
                        /* Require "empty" floor grids */
-                       g_ptr = &floor_ptr->grid_array[y][x];
-                       if (!cave_empty_grid(g_ptr)) continue;
+                       grid_type *g_ptr;
+                       g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
+                       if (!is_cave_empty_grid(player_ptr, g_ptr)) continue;
 
                        /* Place the monster (allow groups) */
                        floor_ptr->monster_level = floor_ptr->base_level + 2;
-                       (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
+                       (void)place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
                        floor_ptr->monster_level = floor_ptr->base_level;
                }
        }
@@ -621,6 +607,7 @@ void vault_monsters(floor_type *floor_ptr, POSITION y1, POSITION x1, int num)
 
 /*!
  * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y y座標
  * @param x x座標
  * @return 各種の変更が可能ならTRUEを返す。
@@ -629,36 +616,34 @@ void vault_monsters(floor_type *floor_ptr, POSITION y1, POSITION x1, int num)
  */
 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
 {
-       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
-       OBJECT_IDX this_o_idx, next_o_idx = 0;
-
        /* Forbid perma-grids */
-       if (cave_perma_grid(g_ptr)) return (FALSE);
+       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+       if (cave_perma_grid(g_ptr)) return FALSE;
 
        /* Check objects */
-       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       OBJECT_IDX next_o_idx = 0;
+       for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
                o_ptr = &floor_ptr->o_list[this_o_idx];
                next_o_idx = o_ptr->next_o_idx;
 
                /* Forbid artifact grids */
-               if (object_is_artifact(o_ptr)) return (FALSE);
+               if (object_is_artifact(o_ptr)) return FALSE;
        }
 
-       /* Accept */
-       return (TRUE);
+       return TRUE;
 }
 
+
 /*
  * Change the "feat" flag for a grid, and notice/redraw the grid
  */
-void cave_set_feat(floor_type *floor_ptr, POSITION y, POSITION x, FEAT_IDX feat)
+void cave_set_feat(player_type *player_ptr, POSITION y, POSITION x, FEAT_IDX feat)
 {
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        grid_type *g_ptr = &floor_ptr->grid_array[y][x];
        feature_type *f_ptr = &f_info[feat];
-       bool old_los, old_mirror;
-
        if (!current_world_ptr->character_dungeon)
        {
                /* Clear mimic type */
@@ -685,8 +670,8 @@ void cave_set_feat(floor_type *floor_ptr, POSITION y, POSITION x, FEAT_IDX feat)
                return;
        }
 
-       old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
-       old_mirror = is_mirror_grid(g_ptr);
+       bool old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
+       bool old_mirror = is_mirror_grid(g_ptr);
 
        /* Clear mimic type */
        g_ptr->mimic = 0;
@@ -702,15 +687,15 @@ void cave_set_feat(floor_type *floor_ptr, POSITION y, POSITION x, FEAT_IDX feat)
                g_ptr->info &= ~(CAVE_GLOW);
                if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
 
-               update_local_illumination(p_ptr, y, x);
+               update_local_illumination(player_ptr, y, x);
        }
 
        /* Check for change to boring grid */
        if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
-       if (g_ptr->m_idx) update_monster(p_ptr, g_ptr->m_idx, FALSE);
+       if (g_ptr->m_idx) update_monster(player_ptr, g_ptr->m_idx, FALSE);
 
-       note_spot(y, x);
-       lite_spot(y, x);
+       note_spot(player_ptr, y, x);
+       lite_spot(player_ptr, y, x);
 
        /* Check if los has changed */
        if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
@@ -718,77 +703,74 @@ void cave_set_feat(floor_type *floor_ptr, POSITION y, POSITION x, FEAT_IDX feat)
 
 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
 
-               update_local_illumination(p_ptr, y, x);
+               update_local_illumination(player_ptr, y, x);
 
 #endif /* COMPLEX_WALL_ILLUMINATION */
 
                /* Update the visuals */
-               p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
+               player_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[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
+       if (!have_flag(f_ptr->flags, FF_GLOW) || (d_info[player_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
+               return;
+
+       for (DIRECTION i = 0; i < 9; i++)
        {
-               DIRECTION i;
-               POSITION yy, xx;
+               POSITION yy = y + ddy_ddd[i];
+               POSITION xx = x + ddx_ddd[i];
+               if (!in_bounds2(floor_ptr, yy, xx)) continue;
+
                grid_type *cc_ptr;
+               cc_ptr = &floor_ptr->grid_array[yy][xx];
+               cc_ptr->info |= CAVE_GLOW;
 
-               for (i = 0; i < 9; i++)
+               if (player_has_los_grid(cc_ptr))
                {
-                       yy = y + ddy_ddd[i];
-                       xx = x + ddx_ddd[i];
-                       if (!in_bounds2(floor_ptr, yy, xx)) continue;
-                       cc_ptr = &floor_ptr->grid_array[yy][xx];
-                       cc_ptr->info |= CAVE_GLOW;
-
-                       if (player_has_los_grid(cc_ptr))
-                       {
-                               if (cc_ptr->m_idx) update_monster(p_ptr, cc_ptr->m_idx, FALSE);
-                               note_spot(yy, xx);
-                               lite_spot(yy, xx);
-                       }
-
-                       update_local_illumination(p_ptr, yy, xx);
+                       if (cc_ptr->m_idx) update_monster(player_ptr, cc_ptr->m_idx, FALSE);
+                       note_spot(player_ptr, yy, xx);
+                       lite_spot(player_ptr, yy, xx);
                }
 
-               if (p_ptr->special_defense & NINJA_S_STEALTH)
-               {
-                       if (floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(p_ptr, FALSE);
-               }
+               update_local_illumination(player_ptr, yy, xx);
+       }
+
+       if (player_ptr->special_defense & NINJA_S_STEALTH)
+       {
+               if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW) set_superstealth(player_ptr, FALSE);
        }
 }
 
 
 /*!
  * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y ドアの配置を試みたいマスのY座標
  * @param x ドアの配置を試みたいマスのX座標
  * @param room 部屋に接している場合向けのドア生成か否か
  * @return なし
  */
-void place_random_door(floor_type *floor_ptr, POSITION y, POSITION x, bool room)
+void place_random_door(player_type *player_ptr, POSITION y, POSITION x, bool room)
 {
-       int tmp, type;
-       FEAT_IDX feat = feat_none;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        grid_type *g_ptr = &floor_ptr->grid_array[y][x];
-
-       /* Initialize mimic info */
        g_ptr->mimic = 0;
 
        if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
        {
-               place_floor_bold(floor_ptr, y, x);
+               place_bold(player_ptr, y, x, floor);
                return;
        }
 
-       type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
+       int type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
                one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
                ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
 
        /* Choose an object */
-       tmp = randint0(1000);
+       int tmp = randint0(1000);
 
        /* Open doors (300/1000) */
+       FEAT_IDX feat = feat_none;
        if (tmp < 300)
        {
                /* Create open door */
@@ -806,7 +788,7 @@ void place_random_door(floor_type *floor_ptr, POSITION y, POSITION x, bool room)
        else if (tmp < 600)
        {
                /* Create secret door */
-               place_closed_door(floor_ptr, y, x, type);
+               place_closed_door(player_ptr, y, x, type);
 
                if (type != DOOR_CURTAIN)
                {
@@ -826,23 +808,25 @@ void place_random_door(floor_type *floor_ptr, POSITION y, POSITION x, bool room)
        }
 
        /* Closed, locked, or stuck doors (400/1000) */
-       else place_closed_door(floor_ptr, y, x, type);
+       else place_closed_door(player_ptr, y, x, type);
 
-       if (tmp < 400)
+       if (tmp >= 400)
        {
-               if (feat != feat_none)
-               {
-                       set_cave_feat(floor_ptr, y, x, feat);
-               }
-               else
-               {
-                       place_floor_bold(floor_ptr, y, x);
-               }
+               delete_monster(player_ptr, y, x);
+               return;
        }
 
-       delete_monster(floor_ptr, y, x);
-}
+       if (feat != feat_none)
+       {
+               set_cave_feat(floor_ptr, y, x, feat);
+       }
+       else
+       {
+               place_bold(player_ptr, y, x, floor);
+       }
 
+       delete_monster(player_ptr, y, x);
+}
 
 
 /*!
@@ -859,10 +843,8 @@ void place_random_door(floor_type *floor_ptr, POSITION y, POSITION x, bool room)
  */
 void wipe_o_list(floor_type *floor_ptr)
 {
-       int i;
-
        /* Delete the existing objects */
-       for (i = 1; i < floor_ptr->o_max; i++)
+       for (int i = 1; i < floor_ptr->o_max; i++)
        {
                object_type *o_ptr = &floor_ptr->o_list[i];
 
@@ -886,56 +868,52 @@ void wipe_o_list(floor_type *floor_ptr)
 
                        /* Hack -- see above */
                        m_ptr->hold_o_idx = 0;
+                       object_wipe(o_ptr);
+                       continue;
                }
 
                /* Dungeon */
-               else
-               {
-                       grid_type *g_ptr;
+               grid_type *g_ptr;
 
-                       /* Access location */
-                       POSITION y = o_ptr->iy;
-                       POSITION x = o_ptr->ix;
+               /* Access location */
+               POSITION y = o_ptr->iy;
+               POSITION x = o_ptr->ix;
 
-                       /* Access grid */
-                       g_ptr = &floor_ptr->grid_array[y][x];
+               /* Access grid */
+               g_ptr = &floor_ptr->grid_array[y][x];
 
-                       /* Hack -- see above */
-                       g_ptr->o_idx = 0;
-               }
+               /* Hack -- see above */
+               g_ptr->o_idx = 0;
                object_wipe(o_ptr);
        }
 
-       /* Reset "floor_ptr->o_max" */
        floor_ptr->o_max = 1;
-
-       /* Reset "floor_ptr->o_cnt" */
        floor_ptr->o_cnt = 0;
 }
 
 
 /*!
  * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y ドアの配置を試みたいマスのY座標
  * @param x ドアの配置を試みたいマスのX座標
  * @param type ドアの地形ID
  * @return なし
  */
-void place_closed_door(floor_type *floor_ptr, POSITION y, POSITION x, int type)
+void place_closed_door(player_type *player_ptr, POSITION y, POSITION x, int type)
 {
-       int tmp;
-       FEAT_IDX feat = feat_none;
-
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
        {
-               place_floor_bold(floor_ptr, y, x);
+               place_bold(player_ptr, y, x, floor);
                return;
        }
 
        /* Choose an object */
-       tmp = randint0(400);
+       int tmp = randint0(400);
 
        /* Closed doors (300/400) */
+       FEAT_IDX feat = feat_none;
        if (tmp < 300)
        {
                /* Create closed door */
@@ -956,19 +934,17 @@ void place_closed_door(floor_type *floor_ptr, POSITION y, POSITION x, int type)
                feat = feat_jammed_door_random(type);
        }
 
-       if (feat != feat_none)
-       {
-               cave_set_feat(floor_ptr, y, x, feat);
-
-               /* Now it is not floor */
-               floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
-       }
-       else
+       if (feat == feat_none)
        {
-               place_floor_bold(floor_ptr, y, x);
+               place_bold(player_ptr, y, x, floor);
+               return;
        }
+
+       cave_set_feat(player_ptr, y, x, feat);
+       floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
 }
 
+
 /*!
  * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
  * @param y トラップを配置したいマスの中心Y座標
@@ -979,15 +955,15 @@ void place_closed_door(floor_type *floor_ptr, POSITION y, POSITION x, int type)
  * @details
  * Only really called by some of the "vault" routines.
  */
-void vault_trap_aux(floor_type *floor_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
+void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
 {
-       int count = 0, y1 = y, x1 = x;
-       int dummy = 0;
-
        grid_type *g_ptr;
 
        /* Place traps */
-       for (count = 0; count <= 5; count++)
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       int y1 = y, x1 = x;
+       int dummy = 0;
+       for (int count = 0; count <= 5; count++)
        {
                /* Get a location */
                while (dummy < SAFE_MAX_ATTEMPTS)
@@ -1009,12 +985,13 @@ void vault_trap_aux(floor_type *floor_ptr, POSITION y, POSITION x, POSITION yd,
                if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
 
                /* Place the trap */
-               place_trap(floor_ptr, y1, x1);
+               place_trap(player_ptr, y1, x1);
 
                break;
        }
 }
 
+
 /*!
  * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor.  (Includes range checking.)
  * @param x チェックするマスのX座標
@@ -1026,15 +1003,16 @@ bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
        if (!in_bounds(floor_ptr, y, x))
        {
                /* Out of bounds */
-               return (FALSE);
+               return FALSE;
        }
 
        /* Do the real check */
-       if (is_floor_bold(floor_ptr, y, x)) return (TRUE);
+       if (is_floor_bold(floor_ptr, y, x)) return TRUE;
 
-       return (FALSE);
+       return FALSE;
 }
 
+
 /*!
 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
 * @param y1 基準となるマスのY座標
@@ -1048,16 +1026,13 @@ bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
 */
 static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
 {
-       int i, k = 0;
-       POSITION y, x;
-
-       grid_type *g_ptr;
-
        /* Scan adjacent grids */
-       for (i = 0; i < 4; i++)
+       int k = 0;
+       for (int i = 0; i < 4; i++)
        {
-               y = y1 + ddy_ddd[i];
-               x = x1 + ddx_ddd[i];
+               POSITION y = y1 + ddy_ddd[i];
+               POSITION x = x1 + ddx_ddd[i];
+               grid_type *g_ptr;
                g_ptr = &floor_ptr->grid_array[y][x];
 
                /* Skip non floors */
@@ -1075,7 +1050,7 @@ static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
        }
 
        /* Return the number of corridors */
-       return (k);
+       return k;
 }
 
 /*!
@@ -1091,35 +1066,36 @@ static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
 static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
 {
        /* Count the adjacent corridors */
-       if (next_to_corr(floor_ptr, y, x) >= 2)
+       if (next_to_corr(floor_ptr, y, x) < 2) return FALSE;
+
+       /* Check Vertical */
+       if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) &&
+               cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
        {
-               /* Check Vertical */
-               if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) &&
-                       cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
-               {
-                       return (TRUE);
-               }
+               return TRUE;
+       }
 
-               /* Check Horizontal */
-               if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) &&
-                       cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
-               {
-                       return (TRUE);
-               }
+       /* Check Horizontal */
+       if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) &&
+               cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
+       {
+               return TRUE;
        }
 
-       /* No doorway */
-       return (FALSE);
+       return FALSE;
 }
 
+
 /*!
 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
+* @param player_ptr プレーヤーへの参照ポインタ
 * @param y 設置を行いたいマスのY座標
 * @param x 設置を行いたいマスのX座標
 * @return なし
 */
-void try_door(floor_type *floor_ptr, POSITION y, POSITION x)
+void try_door(player_type *player_ptr, POSITION y, POSITION x)
 {
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (!in_bounds(floor_ptr, y, x)) return;
 
        /* Ignore walls */
@@ -1129,10 +1105,10 @@ void try_door(floor_type *floor_ptr, POSITION y, POSITION x)
        if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
 
        /* Occasional door (if allowed) */
-       if ((randint0(100) < dun_tun_jct) && possible_doorway(floor_ptr, y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
+       if ((randint0(100) < dun_tun_jct) && possible_doorway(floor_ptr, y, x) && !(d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
        {
                /* Place a door */
-               place_random_door(floor_ptr, y, x, FALSE);
+               place_random_door(player_ptr, y, x, FALSE);
        }
 }
 
@@ -1140,7 +1116,6 @@ void try_door(floor_type *floor_ptr, POSITION y, POSITION x)
 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
 {
        feature_type *f_ptr = &f_info[newfeat];
-
        if (have_flag(f_ptr->flags, FF_CONVERT))
        {
                switch (f_ptr->subtype)
@@ -1169,6 +1144,7 @@ FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
 
 /*!
  * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y 配置したい中心マスのY座標
  * @param x 配置したい中心マスのX座標
  * @param num 配置したい数
@@ -1176,19 +1152,17 @@ FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
  * @details
  * Only really called by some of the "vault" routines.
  */
-void vault_objects(floor_type *floor_ptr, POSITION y, POSITION x, int num)
+void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
 {
-       int dummy = 0;
-       int i = 0, j = y, k = x;
-
-       grid_type *g_ptr;
-
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
 
        /* Attempt to place 'num' objects */
        for (; num > 0; --num)
        {
                /* Try up to 11 spots looking for empty space */
-               for (i = 0; i < 11; ++i)
+               int j = y, k = x;
+               int dummy = 0;
+               for (int i = 0; i < 11; ++i)
                {
                        /* Pick a random location */
                        while (dummy < SAFE_MAX_ATTEMPTS)
@@ -1206,16 +1180,17 @@ void vault_objects(floor_type *floor_ptr, POSITION y, POSITION x, int num)
                        }
 
                        /* Require "clean" floor space */
+                       grid_type *g_ptr;
                        g_ptr = &floor_ptr->grid_array[j][k];
                        if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
 
                        if (randint0(100) < 75)
                        {
-                               place_object(floor_ptr, j, k, 0L);
+                               place_object(player_ptr, j, k, 0L);
                        }
                        else
                        {
-                               place_gold(floor_ptr, j, k);
+                               place_gold(player_ptr, j, k);
                        }
 
                        /* Placement accomplished */
@@ -1224,9 +1199,11 @@ void vault_objects(floor_type *floor_ptr, POSITION y, POSITION x, int num)
        }
 }
 
+
 /*!
  * @brief 始点から終点への直線経路を返す /
  * Determine the path taken by a projection.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param gp 経路座標リストを返す参照ポインタ
  * @param range 距離
  * @param y1 始点Y座標
@@ -1275,33 +1252,18 @@ void vault_objects(floor_type *floor_ptr, POSITION y, POSITION x, int num)
  * by "update_view_los()", and very different from the one used by "los()".
  * </pre>
  */
-sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
+sint project_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
 {
-       POSITION y, x;
-
-       int n = 0;
-       int k = 0;
+       /* No path necessary (or allowed) */
+       if ((x1 == x2) && (y1 == y2)) return 0;
 
-       /* Absolute */
+       /* Analyze "dy" */
+       POSITION y, x;
        POSITION ay, ax;
-
-       /* Offsets */
        POSITION sy, sx;
-
-       /* Fractions */
        int frac;
-
-       /* Scale factors */
-       int full, half;
-
-       /* Slope */
        int m;
 
-       /* No path necessary (or allowed) */
-       if ((x1 == x2) && (y1 == y2)) return (0);
-
-
-       /* Analyze "dy" */
        if (y2 < y1)
        {
                ay = (y1 - y2);
@@ -1325,14 +1287,16 @@ sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1,
                sx = 1;
        }
 
-
        /* Number of "units" in one "half" grid */
-       half = (ay * ax);
+       int half = (ay * ax);
 
        /* Number of "units" in one "full" grid */
-       full = half << 1;
+       int full = half << 1;
 
        /* Vertical */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       int n = 0;
+       int k = 0;
        if (ay > ax)
        {
                /* Let m = ((dx/dy) * full) = (dx * dx * 2) */
@@ -1357,7 +1321,7 @@ sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1,
                }
 
                /* Create the projection path */
-               while (1)
+               while (TRUE)
                {
                        /* Save grid */
                        gp[n++] = GRID(y, x);
@@ -1389,7 +1353,7 @@ sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1,
                        if (flg & (PROJECT_STOP))
                        {
                                if ((n > 0) &&
-                                       (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                                       (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
                                        break;
                        }
 
@@ -1418,10 +1382,12 @@ sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1,
                        /* Advance (Y) */
                        y += sy;
                }
+
+               return n;
        }
 
        /* Horizontal */
-       else if (ax > ay)
+       if (ax > ay)
        {
                /* Let m = ((dy/dx) * full) = (dy * dy * 2) */
                m = ay * ay * 2;
@@ -1446,7 +1412,7 @@ sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1,
                }
 
                /* Create the projection path */
-               while (1)
+               while (TRUE)
                {
                        /* Save grid */
                        gp[n++] = GRID(y, x);
@@ -1478,7 +1444,7 @@ sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1,
                        if (flg & (PROJECT_STOP))
                        {
                                if ((n > 0) &&
-                                       (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                                       (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
                                        break;
                        }
 
@@ -1507,75 +1473,71 @@ sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1,
                        /* Advance (X) */
                        x += sx;
                }
+
+               return n;
        }
 
        /* Diagonal */
-       else
-       {
-               /* Start */
-               y = y1 + sy;
-               x = x1 + sx;
-
-               /* Create the projection path */
-               while (1)
-               {
-                       /* Save grid */
-                       gp[n++] = GRID(y, x);
+       y = y1 + sy;
+       x = x1 + sx;
 
-                       /* Hack -- Check maximum range */
-                       if ((n + (n >> 1)) >= range) break;
+       /* Create the projection path */
+       while (TRUE)
+       {
+               /* Save grid */
+               gp[n++] = GRID(y, x);
 
-                       /* Sometimes stop at destination grid */
-                       if (!(flg & (PROJECT_THRU)))
-                       {
-                               if ((x == x2) && (y == y2)) break;
-                       }
+               /* Hack -- Check maximum range */
+               if ((n + (n >> 1)) >= range) break;
 
-                       if (flg & (PROJECT_DISI))
-                       {
-                               if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
-                       }
-                       else if (flg & (PROJECT_LOS))
-                       {
-                               if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
-                       }
-                       else if (!(flg & (PROJECT_PATH)))
-                       {
-                               /* Always stop at non-initial wall grids */
-                               if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
-                       }
+               /* Sometimes stop at destination grid */
+               if (!(flg & (PROJECT_THRU)))
+               {
+                       if ((x == x2) && (y == y2)) break;
+               }
 
-                       /* Sometimes stop at non-initial monsters/players */
-                       if (flg & (PROJECT_STOP))
-                       {
-                               if ((n > 0) &&
-                                       (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
-                                       break;
-                       }
+               if (flg & (PROJECT_DISI))
+               {
+                       if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
+               }
+               else if (flg & (PROJECT_LOS))
+               {
+                       if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
+               }
+               else if (!(flg & (PROJECT_PATH)))
+               {
+                       /* Always stop at non-initial wall grids */
+                       if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
+               }
 
-                       if (!in_bounds(floor_ptr, y, x)) break;
+               /* Sometimes stop at non-initial monsters/players */
+               if (flg & (PROJECT_STOP))
+               {
+                       if ((n > 0) &&
+                               (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                               break;
+               }
 
-                       /* Advance (Y) */
-                       y += sy;
+               if (!in_bounds(floor_ptr, y, x)) break;
 
-                       /* Advance (X) */
-                       x += sx;
-               }
+               y += sy;
+               x += sx;
        }
 
-       /* Length */
-       return (n);
+       return n;
 }
 
 
 /*!
  * @brief 指定のマスを床地形に変える / Set a square to be floor.  (Includes range checking.)
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param x 地形を変えたいマスのX座標
  * @param y 地形を変えたいマスのY座標
  * @return なし
  */
-void set_floor(floor_type *floor_ptr, POSITION x, POSITION y)
+void set_floor(player_type *player_ptr, POSITION x, POSITION y)
 {
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (!in_bounds(floor_ptr, y, x))
        {
                /* Out of bounds */
@@ -1590,13 +1552,14 @@ void set_floor(floor_type *floor_ptr, POSITION x, POSITION y)
 
        /* Set to be floor if is a wall (don't touch lakes). */
        if (is_extra_bold(floor_ptr, y, x))
-               place_floor_bold(floor_ptr, y, x);
+               place_bold(player_ptr, y, x, floor);
 }
 
 
 /*!
  * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
  * Attempt to place an object (normal or good/great) at the given location.
+ * @param owner_ptr プレーヤーへの参照ポインタ
  * @param y 配置したいフロアのY座標
  * @param x 配置したいフロアのX座標
  * @param mode オプションフラグ
@@ -1606,9 +1569,9 @@ void set_floor(floor_type *floor_ptr, POSITION x, POSITION y)
  * This routine uses "object_level" for the "generation level".\n
  * This routine requires a clean floor grid destination.\n
  */
-void place_object(floor_type *floor_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
+void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
 {
-       OBJECT_IDX o_idx;
+       floor_type *floor_ptr = owner_ptr->current_floor_ptr;
 
        /* Acquire grid */
        grid_type *g_ptr = &floor_ptr->grid_array[y][x];
@@ -1616,7 +1579,6 @@ void place_object(floor_type *floor_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
        object_type forge;
        object_type *q_ptr;
 
-
        /* Paranoia -- check bounds */
        if (!in_bounds(floor_ptr, y, x)) return;
 
@@ -1630,61 +1592,56 @@ void place_object(floor_type *floor_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
        object_wipe(q_ptr);
 
        /* Make an object (if possible) */
-       if (!make_object(q_ptr, mode)) return;
+       if (!make_object(owner_ptr, q_ptr, mode)) return;
 
-       o_idx = o_pop();
+       OBJECT_IDX o_idx = o_pop(floor_ptr);
 
        /* Success */
-       if (o_idx)
-       {
-               object_type *o_ptr;
-               o_ptr = &floor_ptr->o_list[o_idx];
-
-               /* Structure Copy */
-               object_copy(o_ptr, q_ptr);
-
-               o_ptr->iy = y;
-               o_ptr->ix = x;
-
-               /* Build a stack */
-               o_ptr->next_o_idx = g_ptr->o_idx;
-
-               g_ptr->o_idx = o_idx;
-               note_spot(y, x);
-               lite_spot(y, x);
-       }
-       else
+       if (o_idx == 0)
        {
                /* Hack -- Preserve artifacts */
                if (object_is_fixed_artifact(q_ptr))
                {
                        a_info[q_ptr->name1].cur_num = 0;
                }
+
+               return;
        }
-}
 
+       object_type *o_ptr;
+       o_ptr = &floor_ptr->o_list[o_idx];
+
+       /* Structure Copy */
+       object_copy(o_ptr, q_ptr);
+
+       o_ptr->iy = y;
+       o_ptr->ix = x;
+
+       /* Build a stack */
+       o_ptr->next_o_idx = g_ptr->o_idx;
+
+       g_ptr->o_idx = o_idx;
+       note_spot(owner_ptr, y, x);
+       lite_spot(owner_ptr, y, x);
+}
 
 
 /*!
  * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
  * Places a treasure (Gold or Gems) at given location
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y 配置したいフロアのY座標
  * @param x 配置したいフロアのX座標
  * @return 生成に成功したらTRUEを返す。
  * @details
  * The location must be a legal, clean, floor grid.
  */
-void place_gold(floor_type *floor_ptr, POSITION y, POSITION x)
+void place_gold(player_type *player_ptr, POSITION y, POSITION x)
 {
-       OBJECT_IDX o_idx;
-
        /* Acquire grid */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        grid_type *g_ptr = &floor_ptr->grid_array[y][x];
 
-       object_type forge;
-       object_type *q_ptr;
-
-
        /* Paranoia -- check bounds */
        if (!in_bounds(floor_ptr, y, x)) return;
 
@@ -1694,55 +1651,57 @@ void place_gold(floor_type *floor_ptr, POSITION y, POSITION x)
        /* Avoid stacking on other objects */
        if (g_ptr->o_idx) return;
 
+       object_type forge;
+       object_type *q_ptr;
        q_ptr = &forge;
        object_wipe(q_ptr);
 
        /* Make some gold */
-       if (!make_gold(q_ptr)) return;
+       if (!make_gold(floor_ptr, q_ptr)) return;
 
-       o_idx = o_pop();
+       OBJECT_IDX o_idx = o_pop(floor_ptr);
 
        /* Success */
-       if (o_idx)
-       {
-               object_type *o_ptr;
-               o_ptr = &floor_ptr->o_list[o_idx];
-               object_copy(o_ptr, q_ptr);
+       if (o_idx == 0) return;
 
-               /* Save location */
-               o_ptr->iy = y;
-               o_ptr->ix = x;
+       object_type *o_ptr;
+       o_ptr = &floor_ptr->o_list[o_idx];
+       object_copy(o_ptr, q_ptr);
 
-               /* Build a stack */
-               o_ptr->next_o_idx = g_ptr->o_idx;
+       /* Save location */
+       o_ptr->iy = y;
+       o_ptr->ix = x;
 
-               g_ptr->o_idx = o_idx;
-               note_spot(y, x);
-               lite_spot(y, x);
-       }
+       /* Build a stack */
+       o_ptr->next_o_idx = g_ptr->o_idx;
+
+       g_ptr->o_idx = o_idx;
+       note_spot(player_ptr, y, x);
+       lite_spot(player_ptr, y, x);
 }
 
 
 /*!
  * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param x 削除位置x座標
  * @param y 削除位置y座標
  * @return なし
  */
-void delete_monster(floor_type *floor_ptr, POSITION y, POSITION x)
+void delete_monster(player_type *player_ptr, POSITION y, POSITION x)
 {
        grid_type *g_ptr;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (!in_bounds(floor_ptr, y, x)) return;
 
        /* Check the grid */
        g_ptr = &floor_ptr->grid_array[y][x];
 
        /* Delete the monster (if any) */
-       if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
+       if (g_ptr->m_idx) delete_monster_idx(player_ptr, g_ptr->m_idx);
 }
 
 
-
 /*!
  * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
  * Move an object from index i1 to index i2 in the object list
@@ -1752,15 +1711,12 @@ void delete_monster(floor_type *floor_ptr, POSITION y, POSITION x)
  */
 static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX i2)
 {
-       OBJECT_IDX i;
-       grid_type *g_ptr;
-       object_type *o_ptr;
-
        /* Do nothing */
        if (i1 == i2) return;
 
        /* Repair objects */
-       for (i = 1; i < floor_ptr->o_max; i++)
+       object_type *o_ptr;
+       for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
        {
                o_ptr = &floor_ptr->o_list[i];
 
@@ -1774,6 +1730,7 @@ static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX
                        o_ptr->next_o_idx = i2;
                }
        }
+
        o_ptr = &floor_ptr->o_list[i1];
 
        if (OBJECT_IS_HELD_MONSTER(o_ptr))
@@ -1799,6 +1756,7 @@ static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX
                x = o_ptr->ix;
 
                /* Acquire grid */
+               grid_type *g_ptr;
                g_ptr = &floor_ptr->grid_array[y][x];
 
                /* Repair grid */
@@ -1809,16 +1767,15 @@ static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX
                }
        }
 
-       /* Structure copy */
        floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
-
-       /* Wipe the hole */
        object_wipe(o_ptr);
 }
 
+
 /*!
  * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
  * Compact and Reorder the object list.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param size 最低でも減らしたいオブジェクト数の水準
  * @return なし
  * @details
@@ -1832,34 +1789,30 @@ static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX
  * After "compacting" (if needed), we "reorder" the objects into a more\n
  * compact order, and we reset the allocation info, and the "live" array.\n
  */
-void compact_objects(floor_type *floor_ptr, int size)
+void compact_objects(player_type *player_ptr, int size)
 {
-       OBJECT_IDX i;
-       POSITION y, x;
-       int num, cnt;
-       int cur_lev, cur_dis, chance;
        object_type *o_ptr;
 
        /* Compact */
        if (size)
        {
                msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
-               p_ptr->redraw |= (PR_MAP);
-               p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
+               player_ptr->redraw |= (PR_MAP);
+               player_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
        }
 
-
        /* Compact at least 'size' objects */
-       for (num = 0, cnt = 1; num < size; cnt++)
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       for (int num = 0, cnt = 1; num < size; cnt++)
        {
                /* Get more vicious each iteration */
-               cur_lev = 5 * cnt;
+               int cur_lev = 5 * cnt;
 
                /* Get closer each iteration */
-               cur_dis = 5 * (20 - cnt);
+               int cur_dis = 5 * (20 - cnt);
 
                /* Examine the objects */
-               for (i = 1; i < floor_ptr->o_max; i++)
+               for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
                {
                        o_ptr = &floor_ptr->o_list[i];
 
@@ -1868,6 +1821,7 @@ void compact_objects(floor_type *floor_ptr, int size)
                        /* Hack -- High level objects start out "immune" */
                        if (k_info[o_ptr->k_idx].level > cur_lev) continue;
 
+                       POSITION y, x;
                        if (OBJECT_IS_HELD_MONSTER(o_ptr))
                        {
                                monster_type *m_ptr;
@@ -1888,10 +1842,10 @@ void compact_objects(floor_type *floor_ptr, int size)
                        }
 
                        /* Nearby objects start out "immune" */
-                       if ((cur_dis > 0) && (distance(p_ptr->y, p_ptr->x, y, x) < cur_dis)) continue;
+                       if ((cur_dis > 0) && (distance(player_ptr->y, player_ptr->x, y, x) < cur_dis)) continue;
 
                        /* Saving throw */
-                       chance = 90;
+                       int chance = 90;
 
                        /* Hack -- only compact artifacts in emergencies */
                        if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
@@ -1900,16 +1854,13 @@ void compact_objects(floor_type *floor_ptr, int size)
                        /* Apply the saving throw */
                        if (randint0(100) < chance) continue;
 
-                       delete_object_idx(i);
-
-                       /* Count it */
+                       delete_object_idx(player_ptr, i);
                        num++;
                }
        }
 
-
        /* Excise dead objects (backwards!) */
-       for (i = floor_ptr->o_max - 1; i >= 1; i--)
+       for (OBJECT_IDX i = floor_ptr->o_max - 1; i >= 1; i--)
        {
                o_ptr = &floor_ptr->o_list[i];
 
@@ -1924,8 +1875,10 @@ void compact_objects(floor_type *floor_ptr, int size)
        }
 }
 
+
 /*!
  * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y トラップを配置したいマスの中心Y座標
  * @param x トラップを配置したいマスの中心X座標
  * @param yd Y方向の配置分散マス数
@@ -1935,12 +1888,52 @@ void compact_objects(floor_type *floor_ptr, int size)
  * @details
  * Only really called by some of the "vault" routines.
  */
-void vault_traps(floor_type *floor_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
+void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
 {
-       int i;
+       for (int i = 0; i < num; i++)
+       {
+               vault_trap_aux(player_ptr, y, x, yd, xd);
+       }
+}
 
-       for (i = 0; i < num; i++)
+
+/*
+ * Standard "find me a location" function
+ *
+ * Obtains a legal location within the given distance of the initial
+ * location, and with "los()" from the source to destination location.
+ *
+ * This function is often called from inside a loop which searches for
+ * locations while increasing the "d" distance.
+ *
+ * Currently the "m" parameter is unused.
+ */
+void scatter(player_type *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
+{
+       /* Pick a location */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       POSITION nx, ny;
+       while (TRUE)
        {
-               vault_trap_aux(floor_ptr, y, x, yd, xd);
+               /* Pick a new location */
+               ny = rand_spread(y, d);
+               nx = rand_spread(x, d);
+
+               /* Ignore annoying locations */
+               if (!in_bounds(floor_ptr, ny, nx)) continue;
+
+               /* Ignore "excessively distant" locations */
+               if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
+
+               if (mode & PROJECT_LOS)
+               {
+                       if (los(player_ptr, y, x, ny, nx)) break;
+                       continue;
+               }
+
+               if (projectable(player_ptr, y, x, ny, nx)) break;
        }
+
+       *yp = ny;
+       *xp = nx;
 }