OSDN Git Service

[Refactor] #40570 Separated space-finder.c/h from rooms.c/h
authorHourier <hourier@users.sourceforge.jp>
Fri, 24 Jul 2020 03:54:25 +0000 (12:54 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 26 Jul 2020 08:04:20 +0000 (17:04 +0900)
14 files changed:
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/room/rooms-city.c
src/room/rooms-fractal.c
src/room/rooms-normal.c
src/room/rooms-pit-nest.c
src/room/rooms-special.c
src/room/rooms-trap.c
src/room/rooms-vault.c
src/room/rooms.c
src/room/rooms.h
src/room/space-finder.c [new file with mode: 0644]
src/room/space-finder.h [new file with mode: 0644]

index 22778d2..eb873fe 100644 (file)
     <ClCompile Include="..\..\src\room\room-generator.c" />\r
     <ClCompile Include="..\..\src\room\room-info-table.c" />\r
     <ClCompile Include="..\..\src\room\rooms-maze-vault.c" />\r
+    <ClCompile Include="..\..\src\room\space-finder.c" />\r
     <ClCompile Include="..\..\src\room\treasure-deployment.c" />\r
     <ClCompile Include="..\..\src\save\floor-writer.c" />\r
     <ClCompile Include="..\..\src\save\info-writer.c" />\r
     <ClInclude Include="..\..\src\room\room-info-table.h" />\r
     <ClInclude Include="..\..\src\room\room-types.h" />\r
     <ClInclude Include="..\..\src\room\rooms-maze-vault.h" />\r
+    <ClInclude Include="..\..\src\room\space-finder.h" />\r
     <ClInclude Include="..\..\src\room\treasure-deployment.h" />\r
     <ClInclude Include="..\..\src\save\floor-writer.h" />\r
     <ClInclude Include="..\..\src\save\info-writer.h" />\r
index 86a4794..cd0a7f0 100644 (file)
     <ClCompile Include="..\..\src\room\rooms-maze-vault.c">
       <Filter>room</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\room\space-finder.c">
+      <Filter>room</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\combat\shoot.h">
     <ClInclude Include="..\..\src\room\rooms-maze-vault.h">
       <Filter>room</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\room\space-finder.h">
+      <Filter>room</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index fbfaa5a..683dba1 100644 (file)
@@ -611,10 +611,11 @@ hengband_SOURCES = \
        room/rooms-fractal.c room/rooms-fractal.h \
        room/rooms-maze-vault.c room/rooms-maze-vault.h \
        room/rooms-normal.c room/rooms-normal.h \
+       room/rooms-pit-nest.c room/rooms-pit-nest.h \
        room/rooms-special.c room/rooms-special.h \
        room/rooms-trap.c room/rooms-trap.h \
        room/rooms-vault.c room/rooms-vault.h \
-       room/rooms-pit-nest.c room/rooms-pit-nest.h \
+       room/space-finder.c room/space-finder.h \
        room/pit-nest-kinds-table.c room/pit-nest-kinds-table.h \
        room/treasure-deployment.c room/treasure-deployment.h \
        \
index 20317fb..999410c 100644 (file)
@@ -5,7 +5,7 @@
 #include "game-option/cheat-types.h"
 #include "grid/feature.h"
 #include "grid/grid.h"
-#include "room/rooms.h"
+#include "room/space-finder.h"
 #include "store/store-util.h"
 #include "store/store.h"
 #include "system/floor-type-definition.h"
index f20d551..6abdf50 100644 (file)
@@ -5,7 +5,7 @@
 #include "grid/grid.h"
 #include "room/cave-filler.h"
 #include "room/rooms-normal.h"
-#include "room/rooms.h"
+#include "room/space-finder.h"
 #include "system/floor-type-definition.h"
 
 /*!
index e3e3b22..1e1f959 100644 (file)
@@ -4,7 +4,8 @@
 #include "floor/floor.h"
 #include "grid/grid.h"
 #include "grid/trap.h"
-#include "room/rooms.h"
+#include "room/rooms.h" // todo 相互依存.
+#include "room/space-finder.h"
 #include "system/floor-type-definition.h"
 
 /*!
index 0000c50..4d34211 100644 (file)
@@ -20,7 +20,7 @@
 #include "monster/monster-list.h"
 #include "monster/monster-util.h"
 #include "room/pit-nest-kinds-table.h"
-#include "room/rooms.h"
+#include "room/space-finder.h"
 #include "system/floor-type-definition.h"
 #include "util/sort.h"
 #include "view/display-messages.h"
index ce72e4b..5f30aee 100644 (file)
@@ -13,7 +13,7 @@
 #include "monster-floor/place-monster-types.h"
 #include "object-enchant/item-apply-magic.h"
 #include "object/object-kind-hook.h"
-#include "room/rooms.h"
+#include "room/space-finder.h"
 #include "system/floor-type-definition.h"
 #include "system/system-variables.h"
 #include "wizard/wizard-messages.h"
index 24834be..f043a33 100644 (file)
@@ -5,7 +5,7 @@
 #include "game-option/cheat-types.h"
 #include "grid/feature.h"
 #include "grid/grid.h"
-#include "room/rooms.h"
+#include "room/space-finder.h"
 #include "system/floor-type-definition.h"
 #include "wizard/wizard-messages.h"
 
index 6e85754..75554d2 100644 (file)
@@ -21,7 +21,8 @@
 #include "room/cave-filler.h"
 #include "room/lake-types.h"
 #include "room/rooms-maze-vault.h"
-#include "room/rooms.h"
+#include "room/rooms.h" // todo 相互依存.
+#include "room/space-finder.h"
 #include "room/treasure-deployment.h"
 #include "store/store-util.h"
 #include "store/store.h"
index 54a3475..31ef8bb 100644 (file)
 #include "room/room-info-table.h"
 #include "room/rooms-city.h"
 #include "room/rooms-fractal.h"
-#include "room/rooms-normal.h"
+#include "room/rooms-normal.h" // todo 相互依存.
 #include "room/rooms-pit-nest.h"
 #include "room/rooms-special.h"
 #include "room/rooms-trap.h"
-#include "room/rooms-vault.h"
+#include "room/rooms-vault.h" // todo 相互依存.
 #include "room/treasure-deployment.h"
 #include "system/dungeon-data-definition.h"
 #include "system/floor-type-definition.h"
@@ -112,196 +112,6 @@ void build_small_room(player_type *player_ptr, POSITION x0, POSITION y0)
     place_bold(player_ptr, y0, x0, GB_FLOOR);
 }
 
-/*!
- * @brief
- * 指定範囲に通路が通っていることを確認した上で床で埋める
- * This function tunnels around a room if it will cut off part of a grid system.
- * @param player_ptr プレーヤーへの参照ポインタ
- * @param x1 範囲の左端
- * @param y1 範囲の上端
- * @param x2 範囲の右端
- * @param y2 範囲の下端
- * @return なし
- */
-static void check_room_boundary(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
-{
-    bool old_is_floor;
-    bool new_is_floor;
-    int count = 0;
-
-    floor_type *floor_ptr = player_ptr->current_floor_ptr;
-    old_is_floor = get_is_floor(floor_ptr, x1 - 1, y1);
-
-    for (POSITION x = x1; x <= x2; x++) {
-        new_is_floor = get_is_floor(floor_ptr, x, y1 - 1);
-        if (new_is_floor != old_is_floor)
-            count++;
-
-        old_is_floor = new_is_floor;
-    }
-
-    for (POSITION y = y1; y <= y2; y++) {
-        new_is_floor = get_is_floor(floor_ptr, x2 + 1, y);
-        if (new_is_floor != old_is_floor)
-            count++;
-
-        old_is_floor = new_is_floor;
-    }
-
-    for (POSITION x = x2; x >= x1; x--) {
-        new_is_floor = get_is_floor(floor_ptr, x, y2 + 1);
-        if (new_is_floor != old_is_floor)
-            count++;
-
-        old_is_floor = new_is_floor;
-    }
-
-    for (POSITION y = y2; y >= y1; y--) {
-        new_is_floor = get_is_floor(floor_ptr, x1 - 1, y);
-        if (new_is_floor != old_is_floor)
-            count++;
-
-        old_is_floor = new_is_floor;
-    }
-
-    if (count <= 2)
-        return;
-
-    for (POSITION y = y1; y <= y2; y++)
-        for (POSITION x = x1; x <= x2; x++)
-            set_floor(player_ptr, x, y);
-}
-
-/*!
- * @brief
- * find_space()の予備処理として部屋の生成が可能かを判定する /
- * Helper function for find_space(). Is this a good location?
- * @param blocks_high 範囲の高さ
- * @param blocks_wide 範囲の幅
- * @param block_y 範囲の上端
- * @param block_x 範囲の左端
- * @return なし
- */
-static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
-{
-    if (blocks_wide < 3) {
-        if ((blocks_wide == 2) && (block_x % 3) == 2)
-            return FALSE;
-    } else if ((blocks_wide % 3) == 0) {
-        if ((block_x % 3) != 0)
-            return FALSE;
-    } else {
-        if (block_x + (blocks_wide / 2) <= dun_data->col_rooms / 2) {
-            if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
-                return FALSE;
-            if ((block_x % 3) == 1)
-                return FALSE;
-        } else {
-            if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
-                return FALSE;
-            if ((block_x % 3) == 1)
-                return FALSE;
-        }
-    }
-
-    POSITION by1 = block_y;
-    POSITION bx1 = block_x;
-    POSITION by2 = block_y + blocks_high;
-    POSITION bx2 = block_x + blocks_wide;
-
-    if ((by1 < 0) || (by2 > dun_data->row_rooms) || (bx1 < 0) || (bx2 > dun_data->col_rooms))
-        return FALSE;
-
-    for (POSITION by = by1; by < by2; by++)
-        for (POSITION bx = bx1; bx < bx2; bx++)
-            if (dun_data->room_map[by][bx])
-                return FALSE;
-
-    return TRUE;
-}
-
-/*!
- * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room.  -LM-
- * @param player_ptr プレーヤーへの参照ポインタ
- * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
- * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
- * @param height 確保したい領域の高さ
- * @param width 確保したい領域の幅
- * @return 所定の範囲が確保できた場合TRUEを返す
- * @details
- * Find and allocate a free space in the dungeon large enough to hold\n
- * the room calling this function.\n
- *\n
- * We allocate space in 11x11 blocks, but want to make sure that rooms\n
- * align neatly on the standard screen.  Therefore, we make them use\n
- * blocks in few 11x33 rectangles as possible.\n
- *\n
- * Be careful to include the edges of the room in height and width!\n
- *\n
- * Return TRUE and values for the center of the room if all went well.\n
- * Otherwise, return FALSE.\n
- */
-bool find_space(player_type *player_ptr, POSITION *y, POSITION *x, POSITION height, POSITION width)
-{
-    int pick;
-    POSITION block_y = 0;
-    POSITION block_x = 0;
-    POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
-    POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
-    if ((dun_data->row_rooms < blocks_high) || (dun_data->col_rooms < blocks_wide))
-        return FALSE;
-
-    int candidates = 0;
-    for (block_y = dun_data->row_rooms - blocks_high; block_y >= 0; block_y--) {
-        for (block_x = dun_data->col_rooms - blocks_wide; block_x >= 0; block_x--) {
-            if (find_space_aux(blocks_high, blocks_wide, block_y, block_x)) {
-                /* Find a valid place */
-                candidates++;
-            }
-        }
-    }
-
-    if (!candidates)
-        return FALSE;
-
-    if (!(d_info[player_ptr->current_floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE))
-        pick = randint1(candidates);
-    else
-        pick = candidates / 2 + 1;
-
-    for (block_y = dun_data->row_rooms - blocks_high; block_y >= 0; block_y--) {
-        for (block_x = dun_data->col_rooms - blocks_wide; block_x >= 0; block_x--) {
-            if (find_space_aux(blocks_high, blocks_wide, block_y, block_x)) {
-                pick--;
-                if (!pick)
-                    break;
-            }
-        }
-
-        if (!pick)
-            break;
-    }
-
-    POSITION by1 = block_y;
-    POSITION bx1 = block_x;
-    POSITION by2 = block_y + blocks_high;
-    POSITION bx2 = block_x + blocks_wide;
-    *y = ((by1 + by2) * BLOCK_HGT) / 2;
-    *x = ((bx1 + bx2) * BLOCK_WID) / 2;
-    if (dun_data->cent_n < CENT_MAX) {
-        dun_data->cent[dun_data->cent_n].y = (byte)*y;
-        dun_data->cent[dun_data->cent_n].x = (byte)*x;
-        dun_data->cent_n++;
-    }
-
-    for (POSITION by = by1; by < by2; by++)
-        for (POSITION bx = bx1; bx < bx2; bx++)
-            dun_data->room_map[by][bx] = TRUE;
-
-    check_room_boundary(player_ptr, *x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
-    return TRUE;
-}
-
 /*
  * Builds a cave system in the center of the dungeon.
  */
index 8e2f72c..34fc4b8 100644 (file)
@@ -24,7 +24,6 @@ extern door_type feat_door[MAX_DOOR_TYPES];
 
 void build_lake(player_type *player_ptr, int type);
 void build_cavern(player_type *player_ptr);
-bool find_space(player_type *player_ptr, POSITION *y, POSITION *x, POSITION height, POSITION width);
 void build_small_room(player_type *player_ptr, POSITION x0, POSITION y0);
 void add_outer_wall(player_type *player_ptr, POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2);
 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4);
diff --git a/src/room/space-finder.c b/src/room/space-finder.c
new file mode 100644 (file)
index 0000000..ae38274
--- /dev/null
@@ -0,0 +1,196 @@
+#include "room/space-finder.h"
+#include "dungeon/dungeon-flag-types.h"
+#include "dungeon/dungeon.h"
+#include "floor/floor.h"
+#include "system/dungeon-data-definition.h"
+#include "system/floor-type-definition.h"
+
+/*!
+ * @brief
+ * 指定範囲に通路が通っていることを確認した上で床で埋める
+ * This function tunnels around a room if it will cut off part of a grid system.
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param x1 範囲の左端
+ * @param y1 範囲の上端
+ * @param x2 範囲の右端
+ * @param y2 範囲の下端
+ * @return なし
+ */
+static void check_room_boundary(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
+{
+    bool old_is_floor;
+    bool new_is_floor;
+    int count = 0;
+
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    old_is_floor = get_is_floor(floor_ptr, x1 - 1, y1);
+
+    for (POSITION x = x1; x <= x2; x++) {
+        new_is_floor = get_is_floor(floor_ptr, x, y1 - 1);
+        if (new_is_floor != old_is_floor)
+            count++;
+
+        old_is_floor = new_is_floor;
+    }
+
+    for (POSITION y = y1; y <= y2; y++) {
+        new_is_floor = get_is_floor(floor_ptr, x2 + 1, y);
+        if (new_is_floor != old_is_floor)
+            count++;
+
+        old_is_floor = new_is_floor;
+    }
+
+    for (POSITION x = x2; x >= x1; x--) {
+        new_is_floor = get_is_floor(floor_ptr, x, y2 + 1);
+        if (new_is_floor != old_is_floor)
+            count++;
+
+        old_is_floor = new_is_floor;
+    }
+
+    for (POSITION y = y2; y >= y1; y--) {
+        new_is_floor = get_is_floor(floor_ptr, x1 - 1, y);
+        if (new_is_floor != old_is_floor)
+            count++;
+
+        old_is_floor = new_is_floor;
+    }
+
+    if (count <= 2)
+        return;
+
+    for (POSITION y = y1; y <= y2; y++)
+        for (POSITION x = x1; x <= x2; x++)
+            set_floor(player_ptr, x, y);
+}
+
+/*!
+ * @brief
+ * find_space()の予備処理として部屋の生成が可能かを判定する /
+ * Helper function for find_space(). Is this a good location?
+ * @param blocks_high 範囲の高さ
+ * @param blocks_wide 範囲の幅
+ * @param block_y 範囲の上端
+ * @param block_x 範囲の左端
+ * @return なし
+ */
+static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
+{
+    if (blocks_wide < 3) {
+        if ((blocks_wide == 2) && (block_x % 3) == 2)
+            return FALSE;
+    } else if ((blocks_wide % 3) == 0) {
+        if ((block_x % 3) != 0)
+            return FALSE;
+    } else {
+        if (block_x + (blocks_wide / 2) <= dun_data->col_rooms / 2) {
+            if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
+                return FALSE;
+            if ((block_x % 3) == 1)
+                return FALSE;
+        } else {
+            if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
+                return FALSE;
+            if ((block_x % 3) == 1)
+                return FALSE;
+        }
+    }
+
+    POSITION by1 = block_y;
+    POSITION bx1 = block_x;
+    POSITION by2 = block_y + blocks_high;
+    POSITION bx2 = block_x + blocks_wide;
+
+    if ((by1 < 0) || (by2 > dun_data->row_rooms) || (bx1 < 0) || (bx2 > dun_data->col_rooms))
+        return FALSE;
+
+    for (POSITION by = by1; by < by2; by++)
+        for (POSITION bx = bx1; bx < bx2; bx++)
+            if (dun_data->room_map[by][bx])
+                return FALSE;
+
+    return TRUE;
+}
+
+/*!
+ * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room.  -LM-
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
+ * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
+ * @param height 確保したい領域の高さ
+ * @param width 確保したい領域の幅
+ * @return 所定の範囲が確保できた場合TRUEを返す
+ * @details
+ * Find and allocate a free space in the dungeon large enough to hold\n
+ * the room calling this function.\n
+ *\n
+ * We allocate space in 11x11 blocks, but want to make sure that rooms\n
+ * align neatly on the standard screen.  Therefore, we make them use\n
+ * blocks in few 11x33 rectangles as possible.\n
+ *\n
+ * Be careful to include the edges of the room in height and width!\n
+ *\n
+ * Return TRUE and values for the center of the room if all went well.\n
+ * Otherwise, return FALSE.\n
+ */
+bool find_space(player_type *player_ptr, POSITION *y, POSITION *x, POSITION height, POSITION width)
+{
+    int pick;
+    POSITION block_y = 0;
+    POSITION block_x = 0;
+    POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
+    POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
+    if ((dun_data->row_rooms < blocks_high) || (dun_data->col_rooms < blocks_wide))
+        return FALSE;
+
+    int candidates = 0;
+    for (block_y = dun_data->row_rooms - blocks_high; block_y >= 0; block_y--) {
+        for (block_x = dun_data->col_rooms - blocks_wide; block_x >= 0; block_x--) {
+            if (find_space_aux(blocks_high, blocks_wide, block_y, block_x)) {
+                /* Find a valid place */
+                candidates++;
+            }
+        }
+    }
+
+    if (!candidates)
+        return FALSE;
+
+    if (!(d_info[player_ptr->current_floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE))
+        pick = randint1(candidates);
+    else
+        pick = candidates / 2 + 1;
+
+    for (block_y = dun_data->row_rooms - blocks_high; block_y >= 0; block_y--) {
+        for (block_x = dun_data->col_rooms - blocks_wide; block_x >= 0; block_x--) {
+            if (find_space_aux(blocks_high, blocks_wide, block_y, block_x)) {
+                pick--;
+                if (!pick)
+                    break;
+            }
+        }
+
+        if (!pick)
+            break;
+    }
+
+    POSITION by1 = block_y;
+    POSITION bx1 = block_x;
+    POSITION by2 = block_y + blocks_high;
+    POSITION bx2 = block_x + blocks_wide;
+    *y = ((by1 + by2) * BLOCK_HGT) / 2;
+    *x = ((bx1 + bx2) * BLOCK_WID) / 2;
+    if (dun_data->cent_n < CENT_MAX) {
+        dun_data->cent[dun_data->cent_n].y = (byte)*y;
+        dun_data->cent[dun_data->cent_n].x = (byte)*x;
+        dun_data->cent_n++;
+    }
+
+    for (POSITION by = by1; by < by2; by++)
+        for (POSITION bx = bx1; bx < bx2; bx++)
+            dun_data->room_map[by][bx] = TRUE;
+
+    check_room_boundary(player_ptr, *x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
+    return TRUE;
+}
diff --git a/src/room/space-finder.h b/src/room/space-finder.h
new file mode 100644 (file)
index 0000000..bde2f71
--- /dev/null
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "system/angband.h"
+
+bool find_space(player_type *player_ptr, POSITION *y, POSITION *x, POSITION height, POSITION width);