OSDN Git Service

[Refactor] #2680 wilderness_gen() からgenerate_wild_monsters() を分離して意味を分かりやすくし、MIN_M_AL...
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 30 Oct 2022 14:08:15 +0000 (23:08 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Thu, 3 Nov 2022 00:55:51 +0000 (09:55 +0900)
src/floor/wild.cpp
src/system/gamevalue.h

index 1258ae9..1d2a5ee 100644 (file)
@@ -65,6 +65,8 @@ struct border_type {
     int16_t south_east;
 };
 
+static border_type border;
+
 /*!
  * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
  * @param feat_type 非一様確率を再現するための要素数100の配列
@@ -287,24 +289,14 @@ static void generate_wilderness_area(FloorType *floor_ptr, int terrain, uint32_t
 }
 
 /*!
- * @brief 荒野フロア生成のメインルーチン /
- * Load a town or generate a terrain level using "plasma" fractals.
+ * @brief 荒野フロア生成のメインルーチン
  * @param player_ptr プレイヤーへの参照ポインタ
  * @param y 広域Y座標
  * @param x 広域X座標
- * @param border 広域マップの辺部分としての生成ならばTRUE
- * @param corner 広域マップの角部分としての生成ならばTRUE
- * @details
- * <pre>
- * x and y are the coordinates of the area in the wilderness.
- * Border and corner are optimization flags to speed up the
- * generation of the fractal terrain.
- * If border is set then only the border of the terrain should
- * be generated (for initializing the border structure).
- * If corner is set then only the corners of the area are needed.
- * </pre>
+ * @param is_border 広域マップの辺部分としての生成ならばTRUE
+ * @param is_corner 広域マップの角部分としての生成ならばTRUE
  */
-static void generate_area(PlayerType *player_ptr, POSITION y, POSITION x, bool border, bool corner)
+static void generate_area(PlayerType *player_ptr, POSITION y, POSITION x, bool is_border, bool is_corner)
 {
     player_ptr->town_num = wilderness[y][x].town;
     auto *floor_ptr = player_ptr->current_floor_ptr;
@@ -314,23 +306,23 @@ static void generate_area(PlayerType *player_ptr, POSITION y, POSITION x, bool b
     floor_ptr->object_level = floor_ptr->base_level;
     if (player_ptr->town_num) {
         init_buildings();
-        if (border || corner) {
+        if (is_border || is_corner) {
             init_flags = i2enum<init_flags_type>(INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES);
         } else {
             init_flags = INIT_CREATE_DUNGEON;
         }
 
         parse_fixed_map(player_ptr, TOWN_DEFINITION_LIST, 0, 0, MAX_HGT, MAX_WID);
-        if (!corner && !border) {
+        if (!is_corner && !is_border) {
             player_ptr->visit |= (1UL << (player_ptr->town_num - 1));
         }
     } else {
         int terrain = wilderness[y][x].terrain;
         uint32_t seed = wilderness[y][x].seed;
-        generate_wilderness_area(floor_ptr, terrain, seed, corner);
+        generate_wilderness_area(floor_ptr, terrain, seed, is_corner);
     }
 
-    if (!corner && !wilderness[y][x].town) {
+    if (!is_corner && !wilderness[y][x].town) {
         //!< @todo make the road a bit more interresting.
         if (wilderness[y][x].road) {
             floor_ptr->grid_array[MAX_HGT / 2][MAX_WID / 2].feat = feat_floor;
@@ -386,8 +378,27 @@ static void generate_area(PlayerType *player_ptr, POSITION y, POSITION x, bool b
     w_ptr->rng.set_state(state_backup);
 }
 
-/* Border of the wilderness area */
-static border_type border;
+/*!
+ * @brief 地上マップにモンスターを生成する
+ * @param player_ptr プレイヤーへの参照ポインタ
+ * @details '>' キーで普通に入った時と、襲撃を受けた時でモンスター数は異なる.
+ * また、集団生成や護衛は、最初に生成された1体だけがカウント対象である.
+ * よって、実際に生成されるモンスターは、コードの見た目より多くなる.
+ */
+static void generate_wild_monsters(PlayerType *player_ptr)
+{
+    constexpr auto num_ambush_monsters = 40;
+    constexpr auto num_normal_monsters = 8;
+    const auto lim = generate_encounter ? num_ambush_monsters : num_normal_monsters;
+    for (auto i = 0; i < lim; i++) {
+        BIT_FLAGS mode = 0;
+        if (!(generate_encounter || (one_in_(2) && (!player_ptr->town_num)))) {
+            mode |= PM_ALLOW_SLEEP;
+        }
+
+        (void)alloc_monster(player_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
+    }
+}
 
 /*!
  * @brief 広域マップの生成 /
@@ -562,16 +573,7 @@ void wilderness_gen(PlayerType *player_ptr)
     }
 
     player_place(player_ptr, player_ptr->oldpy, player_ptr->oldpx);
-    int lim = generate_encounter ? 40 : MIN_M_ALLOC_TN;
-    for (int i = 0; i < lim; i++) {
-        BIT_FLAGS mode = 0;
-        if (!(generate_encounter || (one_in_(2) && (!player_ptr->town_num)))) {
-            mode |= PM_ALLOW_SLEEP;
-        }
-
-        (void)alloc_monster(player_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
-    }
-
+    generate_wild_monsters(player_ptr);
     if (generate_encounter) {
         player_ptr->ambush_flag = true;
     }
index 743fc9e..82fb8f7 100644 (file)
@@ -37,9 +37,6 @@
 
 #define AAF_LIMIT 100 /*!< モンスターの限界感知範囲(マス) Limit of sensing radius */
 
-#define MIN_M_ALLOC_TD 4 /*!< 街(昼間)の最低住人配置数 / The town starts out with 4 residents during the day */
-#define MIN_M_ALLOC_TN 8 /*!< 街(夜間)の最低住人配置数 / The town starts out with 8 residents during the night */
-
 #define MAX_SKILLS 10
 
 #define TY_CURSE_CHANCE 200 /*!<太古の怨念の1ターン毎の発動確率(1/n)*/