OSDN Git Service

[Refactor] #38997 o_pop()、drop_near()、inven_drop() にplayer_type *引数を追加 (コールチェーンが長いのでそ...
[hengband/hengband.git] / src / floor-generate.c
index e711ad5..3b4989a 100644 (file)
@@ -144,7 +144,7 @@ dun_data *dun;
  * @param y 基準のy座標
  * @param x 基準のx座標
  * @return 隣接する外壁の数
- * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y, x)"
+ * @note Assumes "in_bounds()"
  * @details We count only granite walls and permanent walls.
  */
 static int next_to_walls(floor_type* floor_ptr, POSITION y, POSITION x)
@@ -374,13 +374,13 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
 
                        case ALLOC_TYP_GOLD:
                        {
-                               place_gold(y, x);
+                               place_gold(floor_ptr, y, x);
                                break;
                        }
 
                        case ALLOC_TYP_OBJECT:
                        {
-                               place_object(y, x, 0L);
+                               place_object(floor_ptr, y, x, 0L);
                                break;
                        }
                }
@@ -572,14 +572,16 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
 /*!
  * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
  * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
  */
-static bool cave_gen(floor_type *floor_ptr)
+static bool cave_gen(player_type *player_ptr)
 {
        int i, k;
        POSITION y, x;
        dun_data dun_body;
 
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        dungeon_type* dungeon_ptr = &d_info[floor_ptr->dungeon_idx];
 
        floor_ptr->lite_n = 0;
@@ -702,7 +704,7 @@ static bool cave_gen(floor_type *floor_ptr)
                }
 
                /* Destroy the level if necessary */
-               if (dun->destroyed) destroy_level(floor_ptr);
+               if (dun->destroyed) destroy_level(player_ptr);
 
                /* Hack -- Add some rivers */
                if (one_in_(3) && (randint1(floor_ptr->dun_level) > 5))
@@ -976,15 +978,17 @@ static bool cave_gen(floor_type *floor_ptr)
        /* Put the Guardian */
        if (!alloc_guardian(TRUE)) return FALSE;
 
-       if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > floor_ptr->dun_level)) && !(dungeon_ptr->flags1 & DF1_DARKNESS))
+       bool is_empty_or_dark = dun->empty_level;
+       is_empty_or_dark &= !one_in_(DARK_EMPTY) || (randint1(100) > floor_ptr->dun_level);
+       is_empty_or_dark &= !(dungeon_ptr->flags1 & DF1_DARKNESS);
+       if (!is_empty_or_dark) return TRUE;
+
+       /* Lite the floor_ptr->grid_array */
+       for (y = 0; y < floor_ptr->height; y++)
        {
-               /* Lite the floor_ptr->grid_array */
-               for (y = 0; y < floor_ptr->height; y++)
+               for (x = 0; x < floor_ptr->width; x++)
                {
-                       for (x = 0; x < floor_ptr->width; x++)
-                       {
-                               floor_ptr->grid_array[y][x].info |= (CAVE_GLOW);
-                       }
+                       floor_ptr->grid_array[y][x].info |= (CAVE_GLOW);
                }
        }
 
@@ -995,10 +999,10 @@ static bool cave_gen(floor_type *floor_ptr)
  * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
  * @return なし
  */
-static void build_arena(floor_type *floor_ptr)
+static void build_arena(floor_type *floor_ptr, POSITION *start_y, POSITION *start_x)
 {
        POSITION yval, y_height, y_depth, xval, x_left, x_right;
-       register int i, j;
+       POSITION i, j;
 
        yval = SCREEN_HGT / 2;
        xval = SCREEN_WID / 2;
@@ -1032,20 +1036,19 @@ static void build_arena(floor_type *floor_ptr)
                        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
-       place_extra_perm_bold(floor_ptr, y_height+6, x_left+18);
-       floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_depth-6, x_left+18);
-       floor_ptr->grid_array[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_height+6, x_right-18);
-       floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(floor_ptr, y_depth-6, x_right-18);
-       floor_ptr->grid_array[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
+       place_extra_perm_bold(floor_ptr, y_height + 6, x_left + 18);
+       floor_ptr->grid_array[y_height + 6][x_left + 18].info |= (CAVE_GLOW | CAVE_MARK);
+       place_extra_perm_bold(floor_ptr, y_depth - 6, x_left + 18);
+       floor_ptr->grid_array[y_depth - 6][x_left + 18].info |= (CAVE_GLOW | CAVE_MARK);
+       place_extra_perm_bold(floor_ptr, y_height + 6, x_right - 18);
+       floor_ptr->grid_array[y_height + 6][x_right - 18].info |= (CAVE_GLOW | CAVE_MARK);
+       place_extra_perm_bold(floor_ptr, y_depth - 6, x_right - 18);
+       floor_ptr->grid_array[y_depth - 6][x_right - 18].info |= (CAVE_GLOW | CAVE_MARK);
 
-       i = y_height + 5;
-       j = xval;
-       floor_ptr->grid_array[i][j].feat = f_tag_to_index("ARENA_GATE");
-       floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
-       player_place(p_ptr, i, j);
+       *start_y = y_height + 5;
+       *start_x = xval;
+       floor_ptr->grid_array[*start_y][*start_x].feat = f_tag_to_index("ARENA_GATE");
+       floor_ptr->grid_array[*start_y][*start_x].info |= (CAVE_GLOW | CAVE_MARK);
 }
 
 /*!
@@ -1085,7 +1088,8 @@ static void generate_challenge_arena(floor_type *floor_ptr, player_type *challan
                }
        }
 
-       build_arena(floor_ptr);
+       build_arena(floor_ptr, &y, &x);
+       player_place(challanger_ptr, y, x);
 
        if(!place_monster_aux(0, challanger_ptr->y + 5, challanger_ptr->x, arena_info[challanger_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET)))
        {
@@ -1100,7 +1104,7 @@ static void generate_challenge_arena(floor_type *floor_ptr, player_type *challan
  * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
  * @return なし
  */
-static void build_battle(floor_type *floor_ptr)
+static void build_battle(floor_type *floor_ptr, POSITION *y, POSITION *x)
 {
        POSITION yval, y_height, y_depth, xval, x_left, x_right;
        register int i, j;
@@ -1156,7 +1160,9 @@ static void build_battle(floor_type *floor_ptr)
        j = xval;
        floor_ptr->grid_array[i][j].feat = f_tag_to_index("BUILDING_3");
        floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
-       player_place(p_ptr, i, j);
+
+       *y = i;
+       *x = j;
 }
 
 /*!
@@ -1193,7 +1199,9 @@ static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature
                }
        }
 
-       build_battle(floor_ptr);
+       build_battle(floor_ptr, &y, &x);
+
+       player_place(creature_ptr, y, x);
 
        for(i = 0; i < 4; i++)
        {
@@ -1213,13 +1221,15 @@ static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature
 
 /*!
  * @brief 固定マップクエストのフロア生成 / Generate a quest level
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
-static void generate_fixed_floor(floor_type *floor_ptr)
+static void generate_fixed_floor(player_type *player_ptr)
 {
        POSITION x, y;
 
        /* Start with perm walls */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        for (y = 0; y < floor_ptr->height; y++)
        {
                for (x = 0; x < floor_ptr->width; x++)
@@ -1239,16 +1249,18 @@ static void generate_fixed_floor(floor_type *floor_ptr)
 
        init_flags = INIT_CREATE_DUNGEON;
 
-       process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
+       process_dungeon_file(player_ptr, "q_info.txt", 0, 0, MAX_HGT, MAX_WID);
 }
 
 /*!
  * @brief ダンジョン時のランダムフロア生成 / Make a real level
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param concptr
  * @return フロアの生成に成功したらTRUE
  */
-static bool level_gen(floor_type *floor_ptr, concptr *why)
+static bool level_gen(player_type *player_ptr, concptr *why)
 {
-       int level_height, level_width;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        DUNGEON_IDX d_idx = floor_ptr->dungeon_idx;
 
        if ((always_small_levels || ironman_small_levels ||
@@ -1257,6 +1269,7 @@ static bool level_gen(floor_type *floor_ptr, concptr *why)
            (d_info[d_idx].flags1 & DF1_SMALLEST)) &&
            !(d_info[d_idx].flags1 & DF1_BIG))
        {
+               int level_height, level_width;
                if (d_info[d_idx].flags1 & DF1_SMALLEST)
                {
                        level_height = 1;
@@ -1269,12 +1282,16 @@ static bool level_gen(floor_type *floor_ptr, concptr *why)
                }
                else
                {
-                       do
+                       level_height = randint1(MAX_HGT / SCREEN_HGT);
+                       level_width = randint1(MAX_WID / SCREEN_WID);
+                       bool is_first_level_area = TRUE;
+                       bool is_max_area = (level_height == MAX_HGT / SCREEN_HGT) && (level_width == MAX_WID / SCREEN_WID);
+                       while (is_first_level_area || is_max_area)
                        {
-                               level_height = randint1(MAX_HGT/SCREEN_HGT);
-                               level_width = randint1(MAX_WID/SCREEN_WID);
+                               level_height = randint1(MAX_HGT / SCREEN_HGT);
+                               level_width = randint1(MAX_WID / SCREEN_WID);
+                               is_max_area = (level_height == MAX_HGT / SCREEN_HGT) && (level_width == MAX_WID / SCREEN_WID);
                        }
-                       while ((level_height == MAX_HGT/SCREEN_HGT) && (level_width == MAX_WID/SCREEN_WID));
                }
 
                floor_ptr->height = level_height * SCREEN_HGT;
@@ -1299,13 +1316,13 @@ static bool level_gen(floor_type *floor_ptr, concptr *why)
                panel_col_min = floor_ptr->width;
        }
 
-       /* Make a dungeon */
        floor_ptr->dungeon_idx = d_idx;
-       if (!cave_gen(floor_ptr))
+       if (!cave_gen(player_ptr))
        {
                *why = _("ダンジョン生成に失敗", "could not place player");
                return FALSE;
        }
+
        else return TRUE;
 }
 
@@ -1341,14 +1358,16 @@ void wipe_generate_random_floor_flags(floor_type *floor_ptr)
 
 /*!
  * @brief フロアの全情報を初期化する / Clear and empty floor.
+ * @parama player_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
-void clear_cave(floor_type *floor_ptr)
+void clear_cave(player_type *player_ptr)
 {
        POSITION x, y;
        int i;
 
        /* Very simplified version of wipe_o_list() */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        (void)C_WIPE(floor_ptr->o_list, floor_ptr->o_max, object_type);
        floor_ptr->o_max = 1;
        floor_ptr->o_cnt = 0;
@@ -1362,7 +1381,7 @@ void clear_cave(floor_type *floor_ptr)
        for (i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0;
 
        /* Pre-calc cur_num of pets in party_mon[] */
-       precalc_cur_num_of_pet();
+       precalc_cur_num_of_pet(player_ptr);
 
 
        /* Start with a blank floor_ptr->grid_array */
@@ -1396,14 +1415,16 @@ void clear_cave(floor_type *floor_ptr)
 
 /*!
  * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
+ * @parama player_ptr プレーヤーへの参照ポインタ
  * @return なし
  * @note Hack -- regenerate any "overflow" levels
  */
-void generate_floor(floor_type *floor_ptr)
+void generate_floor(player_type *player_ptr)
 {
        int num;
 
        /* Fill the arrays of floors and walls in the good proportions */
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        set_floor_and_wall(floor_ptr->dungeon_idx);
 
        /* Generate */
@@ -1412,38 +1433,38 @@ void generate_floor(floor_type *floor_ptr)
                bool okay = TRUE;
                concptr why = NULL;
 
-               clear_cave(floor_ptr);
+               clear_cave(player_ptr);
 
                /* Mega-Hack -- no player yet */
-               p_ptr->x = p_ptr->y = 0;
+               player_ptr->x = player_ptr->y = 0;
 
                if (floor_ptr->inside_arena)
                {
-                       generate_challenge_arena(floor_ptr, p_ptr);
+                       generate_challenge_arena(floor_ptr, player_ptr);
                }
 
-               else if (p_ptr->phase_out)
+               else if (player_ptr->phase_out)
                {
-                       generate_gambling_arena(floor_ptr, p_ptr);
+                       generate_gambling_arena(floor_ptr, player_ptr);
                }
 
                else if (floor_ptr->inside_quest)
                {
-                       generate_fixed_floor(floor_ptr);
+                       generate_fixed_floor(player_ptr);
                }
 
                /* Build the town */
                else if (!floor_ptr->dun_level)
                {
                        /* Make the wilderness */
-                       if (p_ptr->wild_mode) wilderness_gen_small(p_ptr, floor_ptr);
-                       else wilderness_gen(p_ptr, floor_ptr);
+                       if (player_ptr->wild_mode) wilderness_gen_small(player_ptr);
+                       else wilderness_gen(player_ptr);
                }
 
                /* Build a real level */
                else
                {
-                       okay = level_gen(floor_ptr, &why);
+                       okay = level_gen(player_ptr, &why);
                }
 
 
@@ -1473,7 +1494,7 @@ void generate_floor(floor_type *floor_ptr)
        glow_deep_lava_and_bldg(floor_ptr);
 
        /* Reset flag */
-       p_ptr->enter_dungeon = FALSE;
+       player_ptr->enter_dungeon = FALSE;
 
        wipe_generate_random_floor_flags(floor_ptr);
 }
@@ -1653,7 +1674,7 @@ bool build_tunnel(floor_type *floor_ptr, POSITION row1, POSITION col1, POSITION
                                        if (is_outer_bold(floor_ptr, y, x))
                                        {
                                                /* Change the wall to a "solid" wall */
-                                               place_solid_noperm_bold(y, x);
+                                               place_solid_noperm_bold(floor_ptr, y, x);
                                        }
                                }
                        }
@@ -1802,7 +1823,7 @@ static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool aff
                                if (is_outer_bold(floor_ptr, j, i))
                                {
                                        /* Change the wall to a "solid" wall */
-                                       place_solid_noperm_bold(j, i);
+                                       place_solid_noperm_bold(floor_ptr, j, i);
                                }
                        }
                }