OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Fix-saved-floor-exceed' into...
[hengband/hengband.git] / src / grid / feature-generator.c
1 #include "grid/feature-generator.h"
2 #include "dungeon/dungeon-flag-types.h"
3 #include "dungeon/dungeon.h"
4 #include "dungeon/quest.h"
5 #include "floor/cave.h"
6 #include "floor/dungeon-tunnel-util.h"
7 #include "game-option/cheat-types.h"
8 #include "game-option/game-play-options.h"
9 #include "grid/door.h"
10 #include "grid/grid.h"
11 #include "room/lake-types.h"
12 #include "room/rooms-builder.h"
13 #include "system/dungeon-data-definition.h"
14 #include "system/floor-type-definition.h"
15 #include "wizard/wizard-messages.h"
16
17 /*!
18  * @brief フロアに洞窟や湖を配置する / Generate various caverns and lakes
19  * @details There were moved from cave_gen().
20  * @return なし
21  */
22 void gen_caverns_and_lakes(player_type *owner_ptr, dungeon_type *dungeon_ptr, dun_data_type *dd_ptr)
23 {
24     floor_type *floor_ptr = owner_ptr->current_floor_ptr;
25     if ((floor_ptr->dun_level > 30) && one_in_(DUN_DEST * 2) && small_levels && (dungeon_ptr->flags1 & DF1_DESTROY)) {
26         dd_ptr->destroyed = TRUE;
27         build_lake(owner_ptr, one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
28     }
29
30     if (one_in_(LAKE_LEVEL) && !dd_ptr->empty_level && !dd_ptr->destroyed && (dungeon_ptr->flags1 & DF1_LAKE_MASK)) {
31         int count = 0;
32         if (dungeon_ptr->flags1 & DF1_LAKE_WATER)
33             count += 3;
34
35         if (dungeon_ptr->flags1 & DF1_LAKE_LAVA)
36             count += 3;
37
38         if (dungeon_ptr->flags1 & DF1_LAKE_RUBBLE)
39             count += 3;
40
41         if (dungeon_ptr->flags1 & DF1_LAKE_TREE)
42             count += 3;
43
44         if (dungeon_ptr->flags1 & DF1_LAKE_LAVA) {
45             if ((floor_ptr->dun_level > 80) && (randint0(count) < 2))
46                 dd_ptr->laketype = LAKE_T_LAVA;
47
48             count -= 2;
49             if (!dd_ptr->laketype && (floor_ptr->dun_level > 80) && one_in_(count))
50                 dd_ptr->laketype = LAKE_T_FIRE_VAULT;
51
52             count--;
53         }
54
55         if ((dungeon_ptr->flags1 & DF1_LAKE_WATER) && !dd_ptr->laketype) {
56             if ((floor_ptr->dun_level > 50) && randint0(count) < 2)
57                 dd_ptr->laketype = LAKE_T_WATER;
58
59             count -= 2;
60             if (!dd_ptr->laketype && (floor_ptr->dun_level > 50) && one_in_(count))
61                 dd_ptr->laketype = LAKE_T_WATER_VAULT;
62
63             count--;
64         }
65
66         if ((dungeon_ptr->flags1 & DF1_LAKE_RUBBLE) && !dd_ptr->laketype) {
67             if ((floor_ptr->dun_level > 35) && (randint0(count) < 2))
68                 dd_ptr->laketype = LAKE_T_CAVE;
69
70             count -= 2;
71             if (!dd_ptr->laketype && (floor_ptr->dun_level > 35) && one_in_(count))
72                 dd_ptr->laketype = LAKE_T_EARTH_VAULT;
73
74             count--;
75         }
76
77         if ((floor_ptr->dun_level > 5) && (dungeon_ptr->flags1 & DF1_LAKE_TREE) && !dd_ptr->laketype)
78             dd_ptr->laketype = LAKE_T_AIR_VAULT;
79
80         if (dd_ptr->laketype) {
81             msg_print_wizard(owner_ptr, CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
82             build_lake(owner_ptr, dd_ptr->laketype);
83         }
84     }
85
86     if ((floor_ptr->dun_level > DUN_CAVERN) && !dd_ptr->empty_level && (dungeon_ptr->flags1 & DF1_CAVERN) && !dd_ptr->laketype && !dd_ptr->destroyed
87         && (randint1(1000) < floor_ptr->dun_level)) {
88         dd_ptr->cavern = TRUE;
89         msg_print_wizard(owner_ptr, CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
90         build_cavern(owner_ptr);
91     }
92
93     if (quest_number(owner_ptr, floor_ptr->dun_level))
94         dd_ptr->destroyed = FALSE;
95 }
96
97 bool has_river_flag(dungeon_type *dungeon_ptr)
98 {
99     return (dungeon_ptr->flags1 & (DF1_WATER_RIVER | DF1_LAVA_RIVER | DF1_ACID_RIVER | DF1_POISONOUS_RIVER)) != 0;
100 }
101
102 /*!
103  * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
104  * @param y1 基準となるマスのY座標
105  * @param x1 基準となるマスのX座標
106  * @return 通路の数
107  * @note Assumes "in_bounds(y1, x1)"
108  * @details
109  * XXX XXX This routine currently only counts actual "empty floor"\n
110  * grids which are not in rooms.  We might want to also count stairs,\n
111  * open doors, closed doors, etc.
112  */
113 static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
114 {
115     int k = 0;
116     for (int i = 0; i < 4; i++) {
117         POSITION y = y1 + ddy_ddd[i];
118         POSITION x = x1 + ddx_ddd[i];
119         grid_type *g_ptr;
120         g_ptr = &floor_ptr->grid_array[y][x];
121         if (cave_has_flag_grid(g_ptr, FF_WALL) || !is_floor_grid(g_ptr) || ((g_ptr->info & CAVE_ROOM) != 0))
122             continue;
123
124         k++;
125     }
126
127     return k;
128 }
129
130 /*!
131  * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
132  * @param y 判定を行いたいマスのY座標
133  * @param x 判定を行いたいマスのX座標
134  * @return ドアを設置可能ならばTRUEを返す
135  * @details まず垂直方向に、次に水平方向に調べる
136  */
137 static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
138 {
139     if (next_to_corr(floor_ptr, y, x) < 2)
140         return FALSE;
141
142     if (cave_has_flag_bold(floor_ptr, y - 1, x, FF_WALL) && cave_has_flag_bold(floor_ptr, y + 1, x, FF_WALL))
143         return TRUE;
144
145     if (cave_has_flag_bold(floor_ptr, y, x - 1, FF_WALL) && cave_has_flag_bold(floor_ptr, y, x + 1, FF_WALL))
146         return TRUE;
147
148     return FALSE;
149 }
150
151 /*!
152  * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
153  * @param player_ptr プレーヤーへの参照ポインタ
154  * @param y 設置を行いたいマスのY座標
155  * @param x 設置を行いたいマスのX座標
156  * @return なし
157  */
158 void try_door(player_type *player_ptr, dt_type *dt_ptr, POSITION y, POSITION x)
159 {
160     floor_type *floor_ptr = player_ptr->current_floor_ptr;
161     if (!in_bounds(floor_ptr, y, x) || cave_has_flag_bold(floor_ptr, y, x, FF_WALL) || ((floor_ptr->grid_array[y][x].info & CAVE_ROOM) != 0))
162         return;
163
164     bool can_place_door = randint0(100) < dt_ptr->dun_tun_jct;
165     can_place_door &= possible_doorway(floor_ptr, y, x);
166     can_place_door &= (d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) == 0;
167     if (can_place_door)
168         place_random_door(player_ptr, y, x, FALSE);
169 }