OSDN Git Service

[Refactor] #40572 Separated dungeon-tunnel-util.c/h from floor-generate.c/h
authorHourier <hourier@users.sourceforge.jp>
Tue, 4 Aug 2020 09:45:13 +0000 (18:45 +0900)
committerHourier <hourier@users.sourceforge.jp>
Tue, 4 Aug 2020 09:45:13 +0000 (18:45 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/floor/dungeon-tunnel-util.c [new file with mode: 0644]
src/floor/dungeon-tunnel-util.h [new file with mode: 0644]
src/floor/floor-generate.c
src/floor/floor-generate.h
src/floor/floor.c

index 529f683..2854edc 100644 (file)
     <ClCompile Include="..\..\src\flavor\named-item-describer.c" />\r
     <ClCompile Include="..\..\src\flavor\tval-description-switcher.c" />\r
     <ClCompile Include="..\..\src\floor\cave.c" />\r
+    <ClCompile Include="..\..\src\floor\dungeon-tunnel-util.c" />\r
     <ClCompile Include="..\..\src\floor\fixed-map-generator.c" />\r
     <ClCompile Include="..\..\src\floor\floor-util.c" />\r
     <ClCompile Include="..\..\src\floor\object-scanner.c" />\r
     <ClInclude Include="..\..\src\flavor\object-flavor-types.h" />\r
     <ClInclude Include="..\..\src\flavor\tval-description-switcher.h" />\r
     <ClInclude Include="..\..\src\floor\cave.h" />\r
+    <ClInclude Include="..\..\src\floor\dungeon-tunnel-util.h" />\r
     <ClInclude Include="..\..\src\floor\fixed-map-generator.h" />\r
     <ClInclude Include="..\..\src\floor\floor-allocation-types.h" />\r
     <ClInclude Include="..\..\src\floor\floor-base-definitions.h" />\r
index f47386e..9073a5e 100644 (file)
     <ClCompile Include="..\..\src\wizard\fixed-artifacts-spoiler.c">
       <Filter>wizard</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\floor\dungeon-tunnel-util.c">
+      <Filter>floor</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\combat\shoot.h">
     <ClInclude Include="..\..\src\floor\floor-allocation-types.h">
       <Filter>floor</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\floor\dungeon-tunnel-util.h">
+      <Filter>floor</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 2c81879..0bc3ea3 100644 (file)
@@ -203,6 +203,7 @@ hengband_SOURCES = \
        flavor/tval-description-switcher.c flavor/tval-description-switcher.h \
        \
        floor/cave.c floor/cave.h \
+       floor/dungeon-tunnel-util.c floor/dungeon-tunnel-util.h \
        floor/fixed-map-generator.c floor/fixed-map-generator.h \
        floor/floor.c floor/floor.h \
        floor/floor-allocation-types.h \
diff --git a/src/floor/dungeon-tunnel-util.c b/src/floor/dungeon-tunnel-util.c
new file mode 100644 (file)
index 0000000..41973f4
--- /dev/null
@@ -0,0 +1,12 @@
+#include "floor/dungeon-tunnel-util.h"
+#include "system/angband.h"
+
+dt_type *initialize_dt_type(dt_type *dt_ptr)
+{
+    dt_ptr->dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
+    dt_ptr->dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
+    dt_ptr->dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
+    dt_ptr->dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
+    dt_ptr->dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
+    return dt_ptr;
+}
diff --git a/src/floor/dungeon-tunnel-util.h b/src/floor/dungeon-tunnel-util.h
new file mode 100644 (file)
index 0000000..415a8ac
--- /dev/null
@@ -0,0 +1,11 @@
+#pragma once
+
+typedef struct dt_type {
+    int dun_tun_rnd; /*!< ダンジョンの通路方向を掻き回す頻度(一回の試行ごとに%で判定している) */
+    int dun_tun_chg; /*!< ダンジョンの通路をクランクさせる頻度(一回の試行ごとに%で判定している) */
+    int dun_tun_con; /*!< ダンジョンの通路を継続して引き延ばす頻度(一回の試行ごとに%で判定している) */
+    int dun_tun_pen; /*!< ダンジョンの部屋入口にドアを設置する頻度(一回の試行ごとに%で判定している) */
+    int dun_tun_jct; /*!< ダンジョンの通路交差地点付近にドアを設置する頻度(一回の試行ごとに%で判定している) */
+} dt_type;
+
+dt_type *initialize_dt_type(dt_type *dt_ptr);
index b08cf03..b7dbb63 100644 (file)
 #include "dungeon/dungeon.h"
 #include "dungeon/quest.h"
 #include "floor/cave.h"
+#include "floor/dungeon-tunnel-util.h"
 #include "floor/floor-allocation-types.h"
 #include "floor/floor-events.h"
 #include "floor/floor-generate.h"
 #include "floor/floor-save.h"
 #include "floor/floor-streams.h"
-#include "floor/floor.h"
+#include "floor/floor.h" // todo 相互依存している、後で消す.
 #include "floor/wild.h"
 #include "game-option/birth-options.h"
 #include "game-option/cheat-types.h"
 #include "wizard/wizard-messages.h"
 #include "world/world.h"
 
-int dun_tun_rnd;
-int dun_tun_chg;
-int dun_tun_con;
-int dun_tun_pen;
-int dun_tun_jct;
-
 /*!
  * @brief 上下左右の外壁数をカウントする / Count the number of walls adjacent to the given grid.
  * @param y 基準のy座標
@@ -458,13 +453,13 @@ static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
  * @param x 設置を行いたいマスのX座標
  * @return なし
  */
-static void try_door(player_type *player_ptr, POSITION y, POSITION x)
+static void try_door(player_type *player_ptr, dt_type *dt_ptr, POSITION y, POSITION x)
 {
     floor_type *floor_ptr = player_ptr->current_floor_ptr;
     if (!in_bounds(floor_ptr, y, x) || cave_have_flag_bold(floor_ptr, y, x, FF_WALL) || ((floor_ptr->grid_array[y][x].info & CAVE_ROOM) != 0))
         return;
 
-    bool can_place_door = randint0(100) < dun_tun_jct;
+    bool can_place_door = randint0(100) < dt_ptr->dun_tun_jct;
     can_place_door &= possible_doorway(floor_ptr, y, x);
     can_place_door &= (d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) == 0;
     if (can_place_door)
@@ -496,11 +491,8 @@ static bool cave_gen(player_type *player_ptr, concptr *why)
     set_floor_and_wall(floor_ptr->dungeon_idx);
     get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), NULL);
 
-    dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
-    dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
-    dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
-    dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
-    dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
+    dt_type tmp_dt;
+    dt_type *dt_ptr = initialize_dt_type(&tmp_dt);
 
     dun_data->row_rooms = floor_ptr->height / BLOCK_HGT;
     dun_data->col_rooms = floor_ptr->width / BLOCK_WID;
@@ -583,7 +575,7 @@ static bool cave_gen(player_type *player_ptr, concptr *why)
             dun_data->wall_n = 0;
             if (randint1(floor_ptr->dun_level) > dungeon_ptr->tunnel_percent)
                 (void)build_tunnel2(player_ptr, dun_data->cent[i].x, dun_data->cent[i].y, x, y, 2, 2);
-            else if (!build_tunnel(player_ptr, dun_data->cent[i].y, dun_data->cent[i].x, y, x))
+            else if (!build_tunnel(player_ptr, dt_ptr, dun_data->cent[i].y, dun_data->cent[i].x, y, x))
                 tunnel_fail_count++;
 
             if (tunnel_fail_count >= 2) {
@@ -612,7 +604,7 @@ static bool cave_gen(player_type *player_ptr, concptr *why)
                 g_ptr = &floor_ptr->grid_array[y][x];
                 g_ptr->mimic = 0;
                 place_grid(player_ptr, g_ptr, GB_FLOOR);
-                if ((randint0(100) < dun_tun_pen) && !(dungeon_ptr->flags1 & DF1_NO_DOORS))
+                if ((randint0(100) < dt_ptr->dun_tun_pen) && !(dungeon_ptr->flags1 & DF1_NO_DOORS))
                     place_random_door(player_ptr, y, x, TRUE);
             }
 
@@ -623,10 +615,10 @@ static bool cave_gen(player_type *player_ptr, concptr *why)
         for (i = 0; i < dun_data->door_n; i++) {
             y = dun_data->door[i].y;
             x = dun_data->door[i].x;
-            try_door(player_ptr, y, x - 1);
-            try_door(player_ptr, y, x + 1);
-            try_door(player_ptr, y - 1, x);
-            try_door(player_ptr, y + 1, x);
+            try_door(player_ptr, dt_ptr, y, x - 1);
+            try_door(player_ptr, dt_ptr, y, x + 1);
+            try_door(player_ptr, dt_ptr, y - 1, x);
+            try_door(player_ptr, dt_ptr, y + 1, x);
         }
 
         if (!alloc_stairs(player_ptr, feat_down_stair, rand_range(3, 4), 3)) {
@@ -1168,7 +1160,7 @@ static void correct_dir(POSITION *rdir, POSITION *cdir, POSITION y1, POSITION x1
  *   outer -- outer room walls\n
  *   solid -- solid room walls\n
  */
-bool build_tunnel(player_type *player_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2)
+bool build_tunnel(player_type *player_ptr, dt_type *dt_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2)
 {
     POSITION tmp_row, tmp_col;
     POSITION row_dir, col_dir;
@@ -1184,9 +1176,9 @@ bool build_tunnel(player_type *player_ptr, POSITION row1, POSITION col1, POSITIO
         if (main_loop_count++ > 2000)
             return FALSE;
 
-        if (randint0(100) < dun_tun_chg) {
+        if (randint0(100) < dt_ptr->dun_tun_chg) {
             correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
-            if (randint0(100) < dun_tun_rnd)
+            if (randint0(100) < dt_ptr->dun_tun_rnd)
                 rand_dir(&row_dir, &col_dir);
         }
 
@@ -1194,7 +1186,7 @@ bool build_tunnel(player_type *player_ptr, POSITION row1, POSITION col1, POSITIO
         tmp_col = col1 + col_dir;
         while (!in_bounds(floor_ptr, tmp_row, tmp_col)) {
             correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
-            if (randint0(100) < dun_tun_rnd)
+            if (randint0(100) < dt_ptr->dun_tun_rnd)
                 rand_dir(&row_dir, &col_dir);
 
             tmp_row = row1 + row_dir;
@@ -1250,7 +1242,7 @@ bool build_tunnel(player_type *player_ptr, POSITION row1, POSITION col1, POSITIO
                 door_flag = TRUE;
             }
 
-            if (randint0(100) >= dun_tun_con) {
+            if (randint0(100) >= dt_ptr->dun_tun_con) {
                 tmp_row = row1 - start_row;
                 if (tmp_row < 0)
                     tmp_row = (-tmp_row);
index accc8c3..1a13071 100644 (file)
@@ -4,15 +4,11 @@
 
 #define SAFE_MAX_ATTEMPTS 5000 /*!< 生成処理基本試行回数 */
 
-extern int dun_tun_rnd; /*!< ダンジョンの通路方向を掻き回す頻度(一回の試行ごとに%で判定している) */
-extern int dun_tun_chg; /*!< ダンジョンの通路をクランクさせる頻度(一回の試行ごとに%で判定している) */
-extern int dun_tun_con; /*!< ダンジョンの通路を継続して引き延ばす頻度(一回の試行ごとに%で判定している) */
-extern int dun_tun_pen; /*!< ダンジョンの部屋入口にドアを設置する頻度(一回の試行ごとに%で判定している) */
-extern int dun_tun_jct; /*!< ダンジョンの通路交差地点付近にドアを設置する頻度(一回の試行ごとに%で判定している) */
-
 bool place_quest_monsters(player_type *creature_ptr);
 void wipe_generate_random_floor_flags(floor_type *floor_ptr);
 void clear_cave(player_type *player_ptr);
 void generate_floor(player_type *player_ptr);
-bool build_tunnel(player_type *player_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2);
+
+typedef struct dt_type dt_type;
+bool build_tunnel(player_type *player_ptr, dt_type *dt_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2);
 bool build_tunnel2(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff);
index 25ef0f8..6c2b48e 100644 (file)
@@ -8,7 +8,7 @@
 #include "effect/effect-characteristics.h"
 #include "effect/spells-effect-util.h"
 #include "floor/cave.h"
-#include "floor/floor-generate.h"
+#include "floor/floor-generate.h" // todo 相互依存している、後で消す.
 #include "floor/floor-object.h"
 #include "game-option/birth-options.h"
 #include "game-option/cheat-options.h"