2 * @brief ダンジョンフロアの部屋生成処理 / make rooms. Used by generate.c when creating dungeons.
5 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
6 * This software may be copied and distributed for educational, research,\n
7 * and not for profit purposes provided that this copyright and statement\n
8 * are included in all such copies. Other copyrights may also apply.\n
9 * 2014 Deskull rearranged comment for Doxygen. \n
11 * Room building routines.\n
17 * 4 -- large room with features\n
18 * 5 -- monster nests\n
20 * 7 -- simple vaults\n
21 * 8 -- greater vaults\n
22 * 9 -- fractal caves\n
23 * 10 -- random vaults\n
24 * 11 -- circular rooms\n
26 * 13 -- trapped monster pits\n
27 * 14 -- trapped room\n
29 * 16 -- underground arcade\n
31 * Some functions are used to determine if the given monster\n
32 * is appropriate for inclusion in a monster nest or monster pit or\n
35 * None of the pits/nests are allowed to include "unique" monsters.\n
38 #include "room/rooms-builder.h"
39 #include "dungeon/dungeon-flag-types.h"
40 #include "dungeon/dungeon.h"
41 #include "floor/cave.h"
42 #include "grid/door.h"
43 #include "grid/feature.h"
44 #include "grid/grid.h"
45 #include "room/cave-filler.h"
46 #include "room/door-definition.h"
47 #include "room/lake-types.h"
48 #include "system/floor-type-definition.h"
49 #include "system/grid-type-definition.h"
50 #include "system/player-type-definition.h"
51 #include "view/display-messages.h"
54 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
55 * @param player_ptr プレイヤーへの参照ポインタ
56 * @param y0 配置したい中心のY座標
57 * @param x0 配置したい中心のX座標
59 * This funtion makes a very small room centred at (x0, y0)
60 * This is used in crypts, and random elemental vaults.
62 * Note - this should be used only on allocated regions
63 * within another room.
65 void build_small_room(PlayerType *player_ptr, POSITION x0, POSITION y0)
67 for (POSITION y = y0 - 1; y <= y0 + 1; y++) {
68 place_bold(player_ptr, y, x0 - 1, GB_INNER);
69 place_bold(player_ptr, y, x0 + 1, GB_INNER);
72 for (POSITION x = x0 - 1; x <= x0 + 1; x++) {
73 place_bold(player_ptr, y0 - 1, x, GB_INNER);
74 place_bold(player_ptr, y0 + 1, x, GB_INNER);
77 switch (randint0(4)) {
79 place_secret_door(player_ptr, y0, x0 - 1, DOOR_DEFAULT);
82 place_secret_door(player_ptr, y0, x0 + 1, DOOR_DEFAULT);
85 place_secret_door(player_ptr, y0 - 1, x0, DOOR_DEFAULT);
88 place_secret_door(player_ptr, y0 + 1, x0, DOOR_DEFAULT);
92 player_ptr->current_floor_ptr->grid_array[y0][x0].mimic = 0;
93 place_bold(player_ptr, y0, x0, GB_FLOOR);
97 * Builds a cave system in the center of the dungeon.
99 void build_cavern(PlayerType *player_ptr)
103 auto *floor_ptr = player_ptr->current_floor_ptr;
104 if ((floor_ptr->dun_level <= randint1(50)) && d_info[floor_ptr->dungeon_idx].flags.has_not(DungeonFeatureType::DARKNESS))
107 POSITION xsize = floor_ptr->width - 1;
108 POSITION ysize = floor_ptr->height - 1;
109 POSITION x0 = xsize / 2;
110 POSITION y0 = ysize / 2;
115 int grd = randint1(4) + 4;
116 int roug = randint1(8) * randint1(4);
117 int cutoff = xsize / 2;
118 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
119 done = generate_fracave(player_ptr, y0 + 1, x0 + 1, xsize, ysize, cutoff, light, false);
124 * makes a lake/collapsed floor in the center of the dungeon
126 void build_lake(PlayerType *player_ptr, int type)
128 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT)) {
129 msg_format("Invalid lake type (%d)", type);
133 auto *floor_ptr = player_ptr->current_floor_ptr;
134 int xsize = floor_ptr->width - 1;
135 int ysize = floor_ptr->height - 1;
142 int grd = randint1(3) + 4;
143 int roug = randint1(8) * randint1(4);
144 int c3 = 3 * xsize / 4;
145 int c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
146 int c2 = (c1 + c3) / 2;
147 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
148 done = generate_lake(player_ptr, y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
153 * Overlay a rectangular room given its bounds
154 * This routine is used by build_room_vault
155 * The area inside the walls is not touched:
156 * only granite is removed- normal walls stay
158 void build_room(PlayerType *player_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2)
161 if ((x1 == x2) || (y1 == y2))
176 POSITION xsize = x2 - x1;
177 POSITION ysize = y2 - y1;
178 auto *floor_ptr = player_ptr->current_floor_ptr;
179 for (int i = 0; i <= xsize; i++) {
180 place_bold(player_ptr, y1, x1 + i, GB_OUTER_NOPERM);
181 floor_ptr->grid_array[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
182 place_bold(player_ptr, y2, x1 + i, GB_OUTER_NOPERM);
183 floor_ptr->grid_array[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
186 for (int i = 1; i < ysize; i++) {
187 place_bold(player_ptr, y1 + i, x1, GB_OUTER_NOPERM);
188 floor_ptr->grid_array[y1 + i][x1].info |= (CAVE_ROOM | CAVE_ICKY);
189 place_bold(player_ptr, y1 + i, x2, GB_OUTER_NOPERM);
190 floor_ptr->grid_array[y1 + i][x2].info |= (CAVE_ROOM | CAVE_ICKY);
193 for (POSITION x = 1; x < xsize; x++) {
194 for (POSITION y = 1; y < ysize; y++) {
195 auto *g_ptr = &floor_ptr->grid_array[y1 + y][x1 + x];
196 if (g_ptr->is_extra()) {
197 place_bold(player_ptr, y1 + y, x1 + x, GB_FLOOR);
198 g_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
200 g_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
207 * Build a town/ castle by using a recursive algorithm.
208 * Basically divide each region in a probalistic way to create
209 * smaller regions. When the regions get too small stop.
211 * The power variable is a measure of how well defended a region is.
212 * This alters the possible choices.
214 void build_recursive_room(PlayerType *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
216 POSITION xsize = x2 - x1;
217 POSITION ysize = y2 - y1;
220 if ((power < 3) && (xsize > 12) && (ysize > 12)) {
224 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8)) {
227 choice = randint1(2) + 1;
230 choice = randint1(3) + 1;
239 for (x = x1; x <= x2; x++) {
240 place_bold(player_ptr, y1, x, GB_OUTER);
241 place_bold(player_ptr, y2, x, GB_OUTER);
244 for (y = y1 + 1; y < y2; y++) {
245 place_bold(player_ptr, y, x1, GB_OUTER);
246 place_bold(player_ptr, y, x2, GB_OUTER);
250 y = randint1(ysize) + y1;
251 place_bold(player_ptr, y, x1, GB_FLOOR);
252 place_bold(player_ptr, y, x2, GB_FLOOR);
254 x = randint1(xsize) + x1;
255 place_bold(player_ptr, y1, x, GB_FLOOR);
256 place_bold(player_ptr, y2, x, GB_FLOOR);
259 int t1 = randint1(ysize / 3) + y1;
260 int t2 = y2 - randint1(ysize / 3);
261 int t3 = randint1(xsize / 3) + x1;
262 int t4 = x2 - randint1(xsize / 3);
264 /* Do outside areas */
265 build_recursive_room(player_ptr, x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
266 build_recursive_room(player_ptr, x1 + 1, t2, x2 - 1, y2, power + 1);
267 build_recursive_room(player_ptr, x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
268 build_recursive_room(player_ptr, t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
280 /* Try to build a room */
281 if ((xsize < 3) || (ysize < 3)) {
282 for (int y = y1; y < y2; y++) {
283 for (int x = x1; x < x2; x++) {
284 place_bold(player_ptr, y, x, GB_INNER);
291 for (int x = x1 + 1; x <= x2 - 1; x++) {
292 place_bold(player_ptr, y1 + 1, x, GB_INNER);
293 place_bold(player_ptr, y2 - 1, x, GB_INNER);
296 for (int y = y1 + 1; y <= y2 - 1; y++) {
297 place_bold(player_ptr, y, x1 + 1, GB_INNER);
298 place_bold(player_ptr, y, x2 - 1, GB_INNER);
301 int y = randint1(ysize - 3) + y1 + 1;
304 place_bold(player_ptr, y, x1 + 1, GB_FLOOR);
307 place_bold(player_ptr, y, x2 - 1, GB_FLOOR);
310 build_recursive_room(player_ptr, x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
314 /* Try and divide vertically */
316 for (int y = y1; y < y2; y++) {
317 for (int x = x1; x < x2; x++) {
318 place_bold(player_ptr, y, x, GB_INNER);
324 int t1 = randint1(xsize - 2) + x1 + 1;
325 build_recursive_room(player_ptr, x1, y1, t1, y2, power - 2);
326 build_recursive_room(player_ptr, t1 + 1, y1, x2, y2, power - 2);
330 /* Try and divide horizontally */
332 for (int y = y1; y < y2; y++)
333 for (int x = x1; x < x2; x++)
334 place_bold(player_ptr, y, x, GB_INNER);
339 int t1 = randint1(ysize - 2) + y1 + 1;
340 build_recursive_room(player_ptr, x1, y1, x2, t1, power - 2);
341 build_recursive_room(player_ptr, x1, t1 + 1, x2, y2, power - 2);
348 * Add outer wall to a floored region
349 * Note: no range checking is done so must be inside dungeon
350 * This routine also stomps on doors
352 void add_outer_wall(PlayerType *player_ptr, POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
354 auto *floor_ptr = player_ptr->current_floor_ptr;
355 if (!in_bounds(floor_ptr, y, x))
359 g_ptr = &floor_ptr->grid_array[y][x];
360 if (g_ptr->is_room())
363 g_ptr->info |= CAVE_ROOM;
365 f_ptr = &f_info[g_ptr->feat];
366 if (g_ptr->is_floor()) {
367 for (int i = -1; i <= 1; i++) {
368 for (int j = -1; j <= 1; j++) {
369 if ((x + i >= x1) && (x + i <= x2) && (y + j >= y1) && (y + j <= y2)) {
370 add_outer_wall(player_ptr, x + i, y + j, light, x1, y1, x2, y2);
372 g_ptr->info |= CAVE_GLOW;
380 if (g_ptr->is_extra()) {
381 place_bold(player_ptr, y, x, GB_OUTER);
383 g_ptr->info |= CAVE_GLOW;
388 if (permanent_wall(f_ptr)) {
390 g_ptr->info |= CAVE_GLOW;
395 * Hacked distance formula - gives the 'wrong' answer.
396 * Used to build crypts
398 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
400 POSITION dx = abs(x2 - x1);
401 POSITION dy = abs(y2 - y1);
403 return dx + (dy * h1) / h2;
406 return dy + (dx * h1) / h2;
408 return ((dx + dy) * 128) / 181 + (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4;