From 44dc3ad9516ba62ab85510edc3824f09ab0bc0d6 Mon Sep 17 00:00:00 2001 From: Hourier Date: Tue, 4 Aug 2020 18:45:13 +0900 Subject: [PATCH] [Refactor] #40572 Separated dungeon-tunnel-util.c/h from floor-generate.c/h --- Hengband/Hengband/Hengband.vcxproj | 2 ++ Hengband/Hengband/Hengband.vcxproj.filters | 6 +++++ src/Makefile.am | 1 + src/floor/dungeon-tunnel-util.c | 12 +++++++++ src/floor/dungeon-tunnel-util.h | 11 ++++++++ src/floor/floor-generate.c | 42 ++++++++++++------------------ src/floor/floor-generate.h | 10 +++---- src/floor/floor.c | 2 +- 8 files changed, 53 insertions(+), 33 deletions(-) create mode 100644 src/floor/dungeon-tunnel-util.c create mode 100644 src/floor/dungeon-tunnel-util.h diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index 529f683cf..2854edcb3 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -216,6 +216,7 @@ + @@ -787,6 +788,7 @@ + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index f47386ecd..9073a5e34 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -1967,6 +1967,9 @@ wizard + + floor + @@ -4279,6 +4282,9 @@ floor + + floor + diff --git a/src/Makefile.am b/src/Makefile.am index 2c8187905..0bc3ea344 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 000000000..41973f44b --- /dev/null +++ b/src/floor/dungeon-tunnel-util.c @@ -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 index 000000000..415a8ac47 --- /dev/null +++ b/src/floor/dungeon-tunnel-util.h @@ -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); diff --git a/src/floor/floor-generate.c b/src/floor/floor-generate.c index b08cf0316..b7dbb6362 100644 --- a/src/floor/floor-generate.c +++ b/src/floor/floor-generate.c @@ -17,12 +17,13 @@ #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" @@ -60,12 +61,6 @@ #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); diff --git a/src/floor/floor-generate.h b/src/floor/floor-generate.h index accc8c3d8..1a13071b9 100644 --- a/src/floor/floor-generate.h +++ b/src/floor/floor-generate.h @@ -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); diff --git a/src/floor/floor.c b/src/floor/floor.c index 25ef0f8e1..6c2b48e81 100644 --- a/src/floor/floor.c +++ b/src/floor/floor.c @@ -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" -- 2.11.0