OSDN Git Service

[Refactor] #38997 new_player_spot() に player_type * 引数を追加. / Add player_type * argume...
[hengband/hengband.git] / src / grid.c
index 2a4fd36..459b62a 100644 (file)
 #define FAF_NO_DROP     0x02
 #define FAF_CRASH_GLASS 0x04
 
-#define feat_locked_door_random(DOOR_TYPE) \
-       (feat_door[(DOOR_TYPE)].num_locked ? \
-        feat_door[(DOOR_TYPE)].locked[randint0(feat_door[(DOOR_TYPE)].num_locked)] : feat_none)
-
-#define feat_jammed_door_random(DOOR_TYPE) \
-       (feat_door[(DOOR_TYPE)].num_jammed ? \
-        feat_door[(DOOR_TYPE)].jammed[randint0(feat_door[(DOOR_TYPE)].num_jammed)] : feat_none)
-
 /*!
  * @brief 地形状態フラグテーブル /
  * The table of features' actions
@@ -184,9 +176,10 @@ static const byte feature_action_flags[FF_FLAG_MAX] =
 
 /*!
  * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
+ * @param creature_ptr 配置したいクリーチャーの参照ポインタ
  * @return 配置に成功したらTRUEを返す
  */
-bool new_player_spot(void)
+bool new_player_spot(player_type *creature_ptr)
 {
        POSITION y = 0, x = 0;
        int max_attempts = 10000;
@@ -197,14 +190,14 @@ bool new_player_spot(void)
        while (max_attempts--)
        {
                /* Pick a legal spot */
-               y = (POSITION)rand_range(1, p_ptr->current_floor_ptr->height - 2);
-               x = (POSITION)rand_range(1, p_ptr->current_floor_ptr->width - 2);
+               y = (POSITION)rand_range(1, creature_ptr->current_floor_ptr->height - 2);
+               x = (POSITION)rand_range(1, creature_ptr->current_floor_ptr->width - 2);
 
-               g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
+               g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
 
                /* Must be a "naked" floor grid */
                if (g_ptr->m_idx) continue;
-               if (p_ptr->current_floor_ptr->dun_level)
+               if (creature_ptr->current_floor_ptr->dun_level)
                {
                        f_ptr = &f_info[g_ptr->feat];
 
@@ -222,7 +215,7 @@ bool new_player_spot(void)
                        if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
                }
                if (!player_can_enter(g_ptr->feat, 0)) continue;
-               if (!in_bounds(p_ptr->current_floor_ptr, y, x)) continue;
+               if (!in_bounds(creature_ptr->current_floor_ptr, y, x)) continue;
 
                /* Refuse to start on anti-teleport grids */
                if (g_ptr->info & (CAVE_ICKY)) continue;
@@ -234,8 +227,8 @@ bool new_player_spot(void)
                return FALSE;
 
        /* Save the new player grid */
-       p_ptr->y = y;
-       p_ptr->x = x;
+       creature_ptr->y = y;
+       creature_ptr->x = x;
 
        return TRUE;
 }
@@ -413,75 +406,6 @@ void place_closed_door(POSITION y, POSITION x, int type)
        }
 }
 
-/*!
-* @brief 鍵のかかったドアを配置する
-* @param y 配置したいフロアのY座標
-* @param x 配置したいフロアのX座標
-* @return なし
-*/
-void place_locked_door(POSITION y, POSITION x)
-{
-       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
-       {
-               place_floor_bold(y, x);
-       }
-       else
-       {
-               set_cave_feat(p_ptr->current_floor_ptr, y, x, feat_locked_door_random((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
-               p_ptr->current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
-               delete_monster(y, x);
-       }
-}
-
-
-/*!
-* @brief 隠しドアを配置する
-* @param y 配置したいフロアのY座標
-* @param x 配置したいフロアのX座標
-* @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
-* @return なし
-*/
-void place_secret_door(POSITION y, POSITION x, int type)
-{
-       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
-       {
-               place_floor_bold(y, x);
-       }
-       else
-       {
-               grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
-
-               if (type == DOOR_DEFAULT)
-               {
-                       type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
-                               one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
-                               ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
-               }
-
-               /* Create secret door */
-               place_closed_door(y, x, type);
-
-               if (type != DOOR_CURTAIN)
-               {
-                       /* 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))
-                               {
-                                       g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
-                               }
-                               g_ptr->mimic = 0;
-                       }
-               }
-
-               g_ptr->info &= ~(CAVE_FLOOR);
-               delete_monster(y, x);
-       }
-}
-
 /*
  * 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.
@@ -491,7 +415,7 @@ void place_secret_door(POSITION y, POSITION x, int type)
 void add_door(POSITION x, POSITION y)
 {
        /* Need to have a wall in the center square */
-       if (!is_outer_bold(y, x)) return;
+       if (!is_outer_bold(p_ptr->current_floor_ptr, y, x)) return;
 
        /* look at:
        *  x#x
@@ -502,11 +426,11 @@ void add_door(POSITION x, POSITION y)
        *  .=floor, #=wall
        */
 
-       if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
-               (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
+       if (is_floor_bold(p_ptr->current_floor_ptr, y - 1, x) && is_floor_bold(p_ptr->current_floor_ptr, y + 1, x) &&
+               (is_outer_bold(p_ptr->current_floor_ptr, y, x - 1) && is_outer_bold(p_ptr->current_floor_ptr, y, x + 1)))
        {
                /* secret door */
-               place_secret_door(y, x, DOOR_DEFAULT);
+               place_secret_door(p_ptr->current_floor_ptr, y, x, DOOR_DEFAULT);
 
                /* set boundarys so don't get wide doors */
                place_solid_bold(y, x - 1);
@@ -522,11 +446,11 @@ void add_door(POSITION x, POSITION y)
        *  where x = don't care
        *  .=floor, #=wall
        */
-       if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
-               is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
+       if (is_outer_bold(p_ptr->current_floor_ptr, y - 1, x) && is_outer_bold(p_ptr->current_floor_ptr, y + 1, x) &&
+               is_floor_bold(p_ptr->current_floor_ptr, y, x - 1) && is_floor_bold(p_ptr->current_floor_ptr, y, x + 1))
        {
                /* secret door */
-               place_secret_door(y, x, DOOR_DEFAULT);
+               place_secret_door(p_ptr->current_floor_ptr, y, x, DOOR_DEFAULT);
 
                /* set boundarys so don't get wide doors */
                place_solid_bold(y - 1, x);
@@ -654,8 +578,8 @@ void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
                for (x = x1 - 1; x <= x2 + 1; x++)
                {
                        place_floor_bold(y, x);
-                       add_cave_info(y, x, CAVE_ROOM);
-                       if (light) add_cave_info(y, x, CAVE_GLOW);
+                       add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_ROOM);
+                       if (light) add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_GLOW);
                }
        }
 }
@@ -867,7 +791,7 @@ bool get_is_floor(POSITION x, POSITION y)
        }
 
        /* Do the real check */
-       if (is_floor_bold(y, x)) return (TRUE);
+       if (is_floor_bold(p_ptr->current_floor_ptr, y, x)) return (TRUE);
 
        return (FALSE);
 }
@@ -893,7 +817,7 @@ void set_floor(POSITION x, POSITION y)
        }
 
        /* Set to be floor if is a wall (don't touch lakes). */
-       if (is_extra_bold(y, x))
+       if (is_extra_bold(p_ptr->current_floor_ptr, y, x))
                place_floor_bold(y, x);
 }
 
@@ -1311,7 +1235,7 @@ void note_spot(POSITION y, POSITION x)
 void lite_spot(POSITION y, POSITION x)
 {
        /* Redraw if on screen */
-       if (panel_contains(y, x) && in_bounds2(y, x))
+       if (panel_contains(y, x) && in_bounds2(p_ptr->current_floor_ptr, y, x))
        {
                TERM_COLOR a;
                SYMBOL_CODE c;
@@ -1580,27 +1504,6 @@ void delayed_visual_update(void)
 
 
 /*
- * Hack -- forget the "flow" information
- */
-void forget_flow(void)
-{
-       POSITION x, y;
-
-       /* Check the entire dungeon */
-       for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
-       {
-               for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
-               {
-                       /* Forget the old data */
-                       p_ptr->current_floor_ptr->grid_array[y][x].dist = 0;
-                       p_ptr->current_floor_ptr->grid_array[y][x].cost = 0;
-                       p_ptr->current_floor_ptr->grid_array[y][x].when = 0;
-               }
-       }
-}
-
-
-/*
  * Hack - speed up the update_flow algorithm by only doing
  * it everytime the player moves out of LOS of the last
  * "way-point".
@@ -1683,7 +1586,7 @@ void update_flow(void)
                        x = tx + ddx_ddd[d];
 
                        /* Ignore player's grid */
-                       if (player_bold(y, x)) continue;
+                       if (player_bold(p_ptr, y, x)) continue;
 
                        g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
@@ -1715,91 +1618,6 @@ void update_flow(void)
        }
 }
 
-
-static int scent_when = 0;
-
-/*
- * Characters leave scent trails for perceptive monsters to track.
- *
- * Smell is rather more limited than sound.  Many creatures cannot use
- * it at all, it doesn't extend very far outwards from the character's
- * current position, and monsters can use it to home in the character,
- * but not to run away from him.
- *
- * Smell is valued according to age.  When a character takes his current_world_ptr->game_turn,
- * scent is aged by one, and new scent of the current age is laid down.
- * Speedy characters leave more scent, true, but it also ages faster,
- * which makes it harder to hunt them down.
- *
- * Whenever the age count loops, most of the scent trail is erased and
- * the age of the remainder is recalculated.
- */
-void update_smell(void)
-{
-       POSITION i, j;
-       POSITION y, x;
-
-       /* Create a table that controls the spread of scent */
-       const int scent_adjust[5][5] =
-       {
-               { -1, 0, 0, 0,-1 },
-               {  0, 1, 1, 1, 0 },
-               {  0, 1, 2, 1, 0 },
-               {  0, 1, 1, 1, 0 },
-               { -1, 0, 0, 0,-1 },
-       };
-
-       /* Loop the age and adjust scent values when necessary */
-       if (++scent_when == 254)
-       {
-               /* Scan the entire dungeon */
-               for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
-               {
-                       for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
-                       {
-                               int w = p_ptr->current_floor_ptr->grid_array[y][x].when;
-                               p_ptr->current_floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
-                       }
-               }
-
-               /* Restart */
-               scent_when = 126;
-       }
-
-
-       /* Lay down new scent */
-       for (i = 0; i < 5; i++)
-       {
-               for (j = 0; j < 5; j++)
-               {
-                       grid_type *g_ptr;
-
-                       /* Translate table to map grids */
-                       y = i + p_ptr->y - 2;
-                       x = j + p_ptr->x - 2;
-
-                       /* Check Bounds */
-                       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) continue;
-
-                       g_ptr = &p_ptr->current_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;
-
-                       /* Grid must not be blocked by walls from the character */
-                       if (!player_has_los_bold(y, x)) continue;
-
-                       /* Note grids that are too far away */
-                       if (scent_adjust[i][j] == -1) continue;
-
-                       /* Mark the grid with new scent */
-                       g_ptr->when = scent_when + scent_adjust[i][j];
-               }
-       }
-}
-
-
-
 /*
  * Change the "feat" flag for a grid, and notice/redraw the grid
  */
@@ -1827,7 +1645,7 @@ void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
                        {
                                yy = y + ddy_ddd[i];
                                xx = x + ddx_ddd[i];
-                               if (!in_bounds2(yy, xx)) continue;
+                               if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
                                p_ptr->current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
                        }
                }
@@ -1887,7 +1705,7 @@ void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
                {
                        yy = y + ddy_ddd[i];
                        xx = x + ddx_ddd[i];
-                       if (!in_bounds2(yy, xx)) continue;
+                       if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
                        cc_ptr = &p_ptr->current_floor_ptr->grid_array[yy][xx];
                        cc_ptr->info |= CAVE_GLOW;
 
@@ -2096,7 +1914,7 @@ bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, B
        if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
 
        if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
-       if (player_bold(y, x)) return FALSE;
+       if (player_bold(p_ptr, y, x)) return FALSE;
 
        /* Hack -- no teleport onto glyph of warding */
        if (is_glyph_grid(g_ptr)) return FALSE;