OSDN Git Service

[Refactor] #40572 Moved try_door() from floor.c/h to floor-generate.c to remove globa...
authorHourier <hourier@users.sourceforge.jp>
Tue, 4 Aug 2020 09:31:39 +0000 (18:31 +0900)
committerHourier <hourier@users.sourceforge.jp>
Tue, 4 Aug 2020 09:31:39 +0000 (18:31 +0900)
src/floor/floor-generate.c
src/floor/floor.c
src/floor/floor.h

index e1c482b..b08cf03 100644 (file)
@@ -403,6 +403,75 @@ static bool has_river_flag(dungeon_type *dungeon_ptr)
 }
 
 /*!
+ * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
+ * @param y1 基準となるマスのY座標
+ * @param x1 基準となるマスのX座標
+ * @return 通路の数
+ * @note Assumes "in_bounds(y1, x1)"
+ * @details
+ * XXX XXX This routine currently only counts actual "empty floor"\n
+ * grids which are not in rooms.  We might want to also count stairs,\n
+ * open doors, closed doors, etc.
+ */
+static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
+{
+    int k = 0;
+    for (int i = 0; i < 4; i++) {
+        POSITION y = y1 + ddy_ddd[i];
+        POSITION x = x1 + ddx_ddd[i];
+        grid_type *g_ptr;
+        g_ptr = &floor_ptr->grid_array[y][x];
+        if (cave_have_flag_grid(g_ptr, FF_WALL) || !is_floor_grid(g_ptr) || ((g_ptr->info & CAVE_ROOM) != 0))
+            continue;
+
+        k++;
+    }
+
+    return k;
+}
+
+/*!
+ * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
+ * @param y 判定を行いたいマスのY座標
+ * @param x 判定を行いたいマスのX座標
+ * @return ドアを設置可能ならばTRUEを返す
+ * @details まず垂直方向に、次に水平方向に調べる
+ */
+static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
+{
+    if (next_to_corr(floor_ptr, y, x) < 2)
+        return FALSE;
+
+    if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) && cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
+        return TRUE;
+
+    if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) && cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
+        return TRUE;
+
+    return FALSE;
+}
+
+/*!
+ * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param y 設置を行いたいマスのY座標
+ * @param x 設置を行いたいマスのX座標
+ * @return なし
+ */
+static void try_door(player_type *player_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;
+    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)
+        place_random_door(player_ptr, y, x, FALSE);
+}
+
+/*!
  * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
  * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
  * @param player_ptr プレーヤーへの参照ポインタ
index 7ce8d17..25ef0f8 100644 (file)
@@ -809,93 +809,6 @@ bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
     return FALSE;
 }
 
-/*!
- * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
- * @param y1 基準となるマスのY座標
- * @param x1 基準となるマスのX座標
- * @return 通路の数
- * @note Assumes "in_bounds(y1, x1)"
- * @details
- * XXX XXX This routine currently only counts actual "empty floor"\n
- * grids which are not in rooms.  We might want to also count stairs,\n
- * open doors, closed doors, etc.
- */
-static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
-{
-    int k = 0;
-    for (int i = 0; i < 4; i++) {
-        POSITION y = y1 + ddy_ddd[i];
-        POSITION x = x1 + ddx_ddd[i];
-        grid_type *g_ptr;
-        g_ptr = &floor_ptr->grid_array[y][x];
-
-        if (cave_have_flag_grid(g_ptr, FF_WALL))
-            continue;
-        if (!is_floor_grid(g_ptr))
-            continue;
-        if (g_ptr->info & (CAVE_ROOM))
-            continue;
-
-        k++;
-    }
-
-    return k;
-}
-
-/*!
- * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
- * @param y 判定を行いたいマスのY座標
- * @param x 判定を行いたいマスのX座標
- * @return ドアを設置可能ならばTRUEを返す
- * @note Assumes "in_bounds()"
- * @details
- * \n
- * Assumes "in_bounds()"\n
- */
-static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
-{
-    if (next_to_corr(floor_ptr, y, x) < 2)
-        return FALSE;
-
-    /* Check Vertical */
-    if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) && cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL)) {
-        return TRUE;
-    }
-
-    /* Check Horizontal */
-    if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) && cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL)) {
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-/*!
- * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
- * @param player_ptr プレーヤーへの参照ポインタ
- * @param y 設置を行いたいマスのY座標
- * @param x 設置を行いたいマスのX座標
- * @return なし
- */
-void try_door(player_type *player_ptr, POSITION y, POSITION x)
-{
-    floor_type *floor_ptr = player_ptr->current_floor_ptr;
-    if (!in_bounds(floor_ptr, y, x))
-        return;
-
-    if (cave_have_flag_bold(floor_ptr, y, x, FF_WALL))
-        return;
-    if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM))
-        return;
-
-    bool can_place_door = randint0(100) < 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) {
-        place_random_door(player_ptr, y, x, FALSE);
-    }
-}
-
 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
 {
     feature_type *f_ptr = &f_info[newfeat];
index 74880db..7811690 100644 (file)
@@ -39,7 +39,6 @@ void place_random_door(player_type *player_ptr, POSITION y, POSITION x, bool roo
 void place_closed_door(player_type *player_ptr, POSITION y, POSITION x, int type);
 void wipe_o_list(floor_type *floor_ptr);
 bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y);
-void try_door(player_type *player_ptr, POSITION y, POSITION x);
 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat);
 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num);
 int project_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg);