From 6b88c7ca04debe7463a155804fe10630ef0c04d5 Mon Sep 17 00:00:00 2001 From: Deskull Date: Sun, 16 Sep 2018 20:29:40 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#37353=E3=80=80room=EF=BD=9Eroom-va?= =?utf8?q?ult=E9=96=93=E6=95=B4=E7=90=86=E3=80=82=20/=20Refactor=20between?= =?utf8?q?=20room=20and=20room-vault.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/rooms-vault.c | 675 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rooms-vault.h | 1 + src/rooms.c | 688 +----------------------------------------------------- src/rooms.h | 7 +- 4 files changed, 688 insertions(+), 683 deletions(-) diff --git a/src/rooms-vault.c b/src/rooms-vault.c index 8a268c8e7..e264a2b93 100644 --- a/src/rooms-vault.c +++ b/src/rooms-vault.c @@ -3,6 +3,245 @@ #include "rooms.h" #include "generate.h" +/* +* This function creates a random vault that looks like a collection of bubbles. +* It works by getting a set of coordinates that represent the center of each +* bubble. The entire room is made by seeing which bubble center is closest. If +* two centers are equidistant then the square is a wall, otherwise it is a floor. +* The only exception is for squares really near a center, these are always floor. +* (It looks better than without this check.) +* +* Note: If two centers are on the same point then this algorithm will create a +* blank bubble filled with walls. - This is prevented from happening. +*/ +static void build_bubble_vault(int x0, int y0, int xsize, int ysize) +{ +#define BUBBLENUM 10 /* number of bubbles */ + + /* array of center points of bubbles */ + coord center[BUBBLENUM]; + + int i, j, x, y; + u16b min1, min2, temp; + bool done; + + /* Offset from center to top left hand corner */ + int xhsize = xsize / 2; + int yhsize = ysize / 2; + + msg_print_wizard(CHEAT_DUNGEON, _("–AŒ^ƒ‰ƒ“ƒ_ƒ€Vault‚𐶐¬‚µ‚Ü‚µ‚½B", "Room Vault.")); + + /* Allocate center of bubbles */ + center[0].x = (byte)randint1(xsize - 3) + 1; + center[0].y = (byte)randint1(ysize - 3) + 1; + + for (i = 1; i < BUBBLENUM; i++) + { + done = FALSE; + + /* get center and check to see if it is unique */ + while (!done) + { + done = TRUE; + + x = randint1(xsize - 3) + 1; + y = randint1(ysize - 3) + 1; + + for (j = 0; j < i; j++) + { + /* rough test to see if there is an overlap */ + if ((x == center[j].x) && (y == center[j].y)) done = FALSE; + } + } + + center[i].x = (byte_hack)x; + center[i].y = (byte_hack)y; + } + + + /* Top and bottom boundaries */ + for (i = 0; i < xsize; i++) + { + int side_x = x0 - xhsize + i; + + place_outer_noperm_bold(y0 - yhsize + 0, side_x); + cave[y0 - yhsize + 0][side_x].info |= (CAVE_ROOM | CAVE_ICKY); + place_outer_noperm_bold(y0 - yhsize + ysize - 1, side_x); + cave[y0 - yhsize + ysize - 1][side_x].info |= (CAVE_ROOM | CAVE_ICKY); + } + + /* Left and right boundaries */ + for (i = 1; i < ysize - 1; i++) + { + int side_y = y0 - yhsize + i; + + place_outer_noperm_bold(side_y, x0 - xhsize + 0); + cave[side_y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY); + place_outer_noperm_bold(side_y, x0 - xhsize + xsize - 1); + cave[side_y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY); + } + + /* Fill in middle with bubbles */ + for (x = 1; x < xsize - 1; x++) + { + for (y = 1; y < ysize - 1; y++) + { + /* Get distances to two closest centers */ + + /* initialize */ + min1 = (u16b)distance(x, y, center[0].x, center[0].y); + min2 = (u16b)distance(x, y, center[1].x, center[1].y); + + if (min1 > min2) + { + /* swap if in wrong order */ + temp = min1; + min1 = min2; + min2 = temp; + } + + /* Scan the rest */ + for (i = 2; i < BUBBLENUM; i++) + { + temp = (u16b)distance(x, y, center[i].x, center[i].y); + + if (temp < min1) + { + /* smallest */ + min2 = min1; + min1 = temp; + } + else if (temp < min2) + { + /* second smallest */ + min2 = temp; + } + } + if (((min2 - min1) <= 2) && (!(min1 < 3))) + { + /* Boundary at midpoint+ not at inner region of bubble */ + place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x); + } + else + { + /* middle of a bubble */ + place_floor_bold(y0 - yhsize + y, x0 - xhsize + x); + } + + /* clean up rest of flags */ + cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY); + } + } + + /* Try to add some random doors */ + for (i = 0; i < 500; i++) + { + x = randint1(xsize - 3) - xhsize + x0 + 1; + y = randint1(ysize - 3) - yhsize + y0 + 1; + add_door(x, y); + } + + /* Fill with monsters and treasure, low difficulty */ + fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5)); +} + +/* Create a random vault that looks like a collection of overlapping rooms */ +static void build_room_vault(int x0, int y0, int xsize, int ysize) +{ + int i, x1, x2, y1, y2, xhsize, yhsize; + + /* get offset from center */ + xhsize = xsize / 2; + yhsize = ysize / 2; + + msg_print_wizard(CHEAT_DUNGEON, _("•”‰®Œ^ƒ‰ƒ“ƒ_ƒ€Vault‚𐶐¬‚µ‚Ü‚µ‚½B", "Room Vault.")); + + /* fill area so don't get problems with arena levels */ + for (x1 = 0; x1 < xsize; x1++) + { + int x = x0 - xhsize + x1; + + for (y1 = 0; y1 < ysize; y1++) + { + int y = y0 - yhsize + y1; + + place_extra_bold(y, x); + cave[y][x].info &= (~CAVE_ICKY); + } + } + + /* add ten random rooms */ + for (i = 0; i < 10; i++) + { + x1 = randint1(xhsize) * 2 + x0 - xhsize; + x2 = randint1(xhsize) * 2 + x0 - xhsize; + y1 = randint1(yhsize) * 2 + y0 - yhsize; + y2 = randint1(yhsize) * 2 + y0 - yhsize; + build_room(x1, x2, y1, y2); + } + + /* Add some random doors */ + for (i = 0; i < 500; i++) + { + x1 = randint1(xsize - 3) - xhsize + x0 + 1; + y1 = randint1(ysize - 3) - yhsize + y0 + 1; + add_door(x1, y1); + } + + /* Fill with monsters and treasure, high difficulty */ + fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5); +} + + +/* Create a random vault out of a fractal cave */ +static void build_cave_vault(int x0, int y0, int xsiz, int ysiz) +{ + int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y; + bool done, light, room; + + /* round to make sizes even */ + xhsize = xsiz / 2; + yhsize = ysiz / 2; + xsize = xhsize * 2; + ysize = yhsize * 2; + + msg_print_wizard(CHEAT_DUNGEON, _("“´ŒŠƒ‰ƒ“ƒ_ƒ€Vault‚𐶐¬‚µ‚Ü‚µ‚½B", "Cave Vault.")); + + light = done = FALSE; + room = TRUE; + + while (!done) + { + /* testing values for these parameters feel free to adjust */ + grd = 1 << randint0(4); + + /* want average of about 16 */ + roug = randint1(8) * randint1(4); + + /* about size/2 */ + cutoff = randint1(xsize / 4) + randint1(ysize / 4) + + randint1(xsize / 4) + randint1(ysize / 4); + + /* make it */ + generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff); + + /* Convert to normal format+ clean up */ + done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room); + } + + /* Set icky flag because is a vault */ + for (x = 0; x <= xsize; x++) + { + for (y = 0; y <= ysize; y++) + { + cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY; + } + } + + /* Fill with monsters and treasure, low difficulty */ + fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5)); +} + /*! @@ -482,3 +721,439 @@ bool build_type8(void) return TRUE; } + + +/* +* Build target vault. +* This is made by two concentric "crypts" with perpendicular +* walls creating the cross-hairs. +*/ +static void build_target_vault(int x0, int y0, int xsize, int ysize) +{ + int rad, x, y; + + /* Make a random metric */ + int h1, h2, h3, h4; + h1 = randint1(32) - 16; + h2 = randint1(16); + h3 = randint1(32); + h4 = randint1(32) - 16; + + msg_print_wizard(CHEAT_DUNGEON, _("‘Ώ̌`ƒ‰ƒ“ƒ_ƒ€Vault‚𐶐¬‚µ‚Ü‚µ‚½B", "Elemental Vault")); + + /* work out outer radius */ + if (xsize > ysize) + { + rad = ysize / 2; + } + else + { + rad = xsize / 2; + } + + /* Make floor */ + for (x = x0 - rad; x <= x0 + rad; x++) + { + for (y = y0 - rad; y <= y0 + rad; y++) + { + /* clear room flag */ + cave[y][x].info &= ~(CAVE_ROOM); + + /* Vault - so is "icky" */ + cave[y][x].info |= CAVE_ICKY; + + if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1) + { + /* inside- so is floor */ + place_floor_bold(y, x); + } + else + { + /* make granite outside so arena works */ + place_extra_bold(y, x); + } + + /* proper boundary for arena */ + if (((y + rad) == y0) || ((y - rad) == y0) || + ((x + rad) == x0) || ((x - rad) == x0)) + { + place_extra_bold(y, x); + } + } + } + + /* Find visible outer walls and set to be FEAT_OUTER */ + add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1, + x0 + rad + 1, y0 + rad + 1); + + /* Add inner wall */ + for (x = x0 - rad / 2; x <= x0 + rad / 2; x++) + { + for (y = y0 - rad / 2; y <= y0 + rad / 2; y++) + { + if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2) + { + /* Make an internal wall */ + place_inner_bold(y, x); + } + } + } + + /* Add perpendicular walls */ + for (x = x0 - rad; x <= x0 + rad; x++) + { + place_inner_bold(y0, x); + } + + for (y = y0 - rad; y <= y0 + rad; y++) + { + place_inner_bold(y, x0); + } + + /* Make inner vault */ + for (y = y0 - 1; y <= y0 + 1; y++) + { + place_inner_bold(y, x0 - 1); + place_inner_bold(y, x0 + 1); + } + for (x = x0 - 1; x <= x0 + 1; x++) + { + place_inner_bold(y0 - 1, x); + place_inner_bold(y0 + 1, x); + } + + place_floor_bold(y0, x0); + + + /* Add doors to vault */ + /* get two distances so can place doors relative to centre */ + x = (rad - 2) / 4 + 1; + y = rad / 2 + x; + + add_door(x0 + x, y0); + add_door(x0 + y, y0); + add_door(x0 - x, y0); + add_door(x0 - y, y0); + add_door(x0, y0 + x); + add_door(x0, y0 + y); + add_door(x0, y0 - x); + add_door(x0, y0 - y); + + /* Fill with stuff - medium difficulty */ + fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3); +} + + +#ifdef ALLOW_CAVERNS_AND_LAKES +/* +* This routine uses a modified version of the lake code to make a +* distribution of some terrain type over the vault. This type +* depends on the dungeon depth. +* +* Miniture rooms are then scattered across the vault. +*/ +static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz) +{ + int grd, roug; + int c1, c2, c3; + bool done = FALSE; + int xsize, ysize, xhsize, yhsize, x, y, i; + int type; + + msg_print_wizard(CHEAT_DUNGEON, _("¸—ìŠEƒ‰ƒ“ƒ_ƒ€Vault‚𐶐¬‚µ‚Ü‚µ‚½B", "Elemental Vault")); + + /* round to make sizes even */ + xhsize = xsiz / 2; + yhsize = ysiz / 2; + xsize = xhsize * 2; + ysize = yhsize * 2; + + if (dun_level < 25) + { + /* Earth vault (Rubble) */ + type = LAKE_T_EARTH_VAULT; + } + else if (dun_level < 50) + { + /* Air vault (Trees) */ + type = LAKE_T_AIR_VAULT; + } + else if (dun_level < 75) + { + /* Water vault (shallow water) */ + type = LAKE_T_WATER_VAULT; + } + else + { + /* Fire vault (shallow lava) */ + type = LAKE_T_FIRE_VAULT; + } + + while (!done) + { + /* testing values for these parameters: feel free to adjust */ + grd = 1 << (randint0(3)); + + /* want average of about 16 */ + roug = randint1(8) * randint1(4); + + /* Make up size of various componants */ + /* Floor */ + c3 = 2 * xsize / 3; + + /* Deep water/lava */ + c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5; + + /* Shallow boundary */ + c2 = (c1 + c3) / 2; + + /* make it */ + generate_hmap(y0, x0, xsize, ysize, grd, roug, c3); + + /* Convert to normal format+ clean up */ + done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type); + } + + /* Set icky flag because is a vault */ + for (x = 0; x <= xsize; x++) + { + for (y = 0; y <= ysize; y++) + { + cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY; + } + } + + /* make a few rooms in the vault */ + for (i = 1; i <= (xsize * ysize) / 50; i++) + { + build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2, + y0 + randint0(ysize - 4) - ysize / 2 + 2); + } + + /* Fill with monsters and treasure, low difficulty */ + fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, + y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5)); +} +#endif /* ALLOW_CAVERNS_AND_LAKES */ + + +/* Build a "mini" checkerboard vault +* +* This is done by making a permanent wall maze and setting +* the diagonal sqaures of the checker board to be granite. +* The vault has two entrances on opposite sides to guarantee +* a way to get in even if the vault abuts a side of the dungeon. +*/ +static void build_mini_c_vault(int x0, int y0, int xsize, int ysize) +{ + int dy, dx; + int y1, x1, y2, x2, y, x, total; + int m, n, num_vertices; + int *visited; + + msg_print_wizard(CHEAT_DUNGEON, _("¬Œ^ƒ`ƒFƒbƒJ[ƒ‰ƒ“ƒ_ƒ€Vault‚𐶐¬‚µ‚Ü‚µ‚½B", "Mini Checker Board Vault.")); + + /* Pick a random room size */ + dy = ysize / 2 - 1; + dx = xsize / 2 - 1; + + y1 = y0 - dy; + x1 = x0 - dx; + y2 = y0 + dy; + x2 = x0 + dx; + + + /* generate the room */ + for (x = x1 - 2; x <= x2 + 2; x++) + { + if (!in_bounds(y1 - 2, x)) break; + + cave[y1 - 2][x].info |= (CAVE_ROOM | CAVE_ICKY); + + place_outer_noperm_bold(y1 - 2, x); + } + + for (x = x1 - 2; x <= x2 + 2; x++) + { + if (!in_bounds(y2 + 2, x)) break; + + cave[y2 + 2][x].info |= (CAVE_ROOM | CAVE_ICKY); + + place_outer_noperm_bold(y2 + 2, x); + } + + for (y = y1 - 2; y <= y2 + 2; y++) + { + if (!in_bounds(y, x1 - 2)) break; + + cave[y][x1 - 2].info |= (CAVE_ROOM | CAVE_ICKY); + + place_outer_noperm_bold(y, x1 - 2); + } + + for (y = y1 - 2; y <= y2 + 2; y++) + { + if (!in_bounds(y, x2 + 2)) break; + + cave[y][x2 + 2].info |= (CAVE_ROOM | CAVE_ICKY); + + place_outer_noperm_bold(y, x2 + 2); + } + + for (y = y1 - 1; y <= y2 + 1; y++) + { + for (x = x1 - 1; x <= x2 + 1; x++) + { + cave_type *c_ptr = &cave[y][x]; + + c_ptr->info |= (CAVE_ROOM | CAVE_ICKY); + + /* Permanent walls */ + place_inner_perm_grid(c_ptr); + } + } + + + /* dimensions of vertex array */ + m = dx + 1; + n = dy + 1; + num_vertices = m * n; + + /* initialize array of visited vertices */ + C_MAKE(visited, num_vertices, int); + + /* traverse the graph to create a spannng tree, pick a random root */ + r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited); + + /* Make it look like a checker board vault */ + for (x = x1; x <= x2; x++) + { + for (y = y1; y <= y2; y++) + { + total = x - x1 + y - y1; + /* If total is odd- and is a floor then make a wall */ + if ((total % 2 == 1) && is_floor_bold(y, x)) + { + place_inner_bold(y, x); + } + } + } + + /* Make a couple of entrances */ + if (one_in_(2)) + { + /* left and right */ + y = randint1(dy) + dy / 2; + place_inner_bold(y1 + y, x1 - 1); + place_inner_bold(y1 + y, x2 + 1); + } + else + { + /* top and bottom */ + x = randint1(dx) + dx / 2; + place_inner_bold(y1 - 1, x1 + x); + place_inner_bold(y2 + 1, x1 + x); + } + + /* Fill with monsters and treasure, highest difficulty */ + fill_treasure(x1, x2, y1, y2, 10); + + C_KILL(visited, num_vertices, int); +} + +/* Build a castle */ +/* Driver routine: clear the region and call the recursive +* room routine. +* +*This makes a vault that looks like a castle/ city in the dungeon. +*/ +static void build_castle_vault(int x0, int y0, int xsize, int ysize) +{ + int dy, dx; + int y1, x1, y2, x2; + int y, x; + + /* Pick a random room size */ + dy = ysize / 2 - 1; + dx = xsize / 2 - 1; + + y1 = y0 - dy; + x1 = x0 - dx; + y2 = y0 + dy; + x2 = x0 + dx; + + msg_print_wizard(CHEAT_DUNGEON, _("éŒ^ƒ‰ƒ“ƒ_ƒ€Vault‚𐶐¬‚µ‚Ü‚µ‚½B", "Castle Vault")); + + /* generate the room */ + for (y = y1 - 1; y <= y2 + 1; y++) + { + for (x = x1 - 1; x <= x2 + 1; x++) + { + cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY); + /* Make everything a floor */ + place_floor_bold(y, x); + } + } + + /* Make the castle */ + build_recursive_room(x1, y1, x2, y2, randint1(5)); + + /* Fill with monsters and treasure, low difficulty */ + fill_treasure(x1, x2, y1, y2, randint1(3)); +} + + + +/*! +* @brief ƒ^ƒCƒv10‚Ì•”‰®cƒ‰ƒ“ƒ_ƒ€¶¬vault / Type 10 -- Random vaults +* @return ‚È‚µ +*/ +bool build_type10(void) +{ + POSITION y0, x0, xsize, ysize, vtype; + + /* Get size */ + /* big enough to look good, small enough to be fairly common. */ + xsize = randint1(22) + 22; + ysize = randint1(11) + 11; + + /* Find and reserve some space in the dungeon. Get center of room. */ + if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE; + + /* Select type of vault */ +#ifdef ALLOW_CAVERNS_AND_LAKES + do + { + vtype = randint1(15); + } while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) && + ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11))); +#else /* ALLOW_CAVERNS_AND_LAKES */ + do + { + vtype = randint1(7); + } while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) && + ((vtype == 1) || (vtype == 3))); +#endif /* ALLOW_CAVERNS_AND_LAKES */ + + switch (vtype) + { + /* Build an appropriate room */ + case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break; + case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break; + case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break; + case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break; + case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break; + case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break; + case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break; +#ifdef ALLOW_CAVERNS_AND_LAKES + case 8: build_elemental_vault(x0, y0, xsize, ysize); break; +#endif /* ALLOW_CAVERNS_AND_LAKES */ + /* I know how to add a few more... give me some time. */ + + /* Paranoia */ + default: return FALSE; + } + + return TRUE; +} + diff --git a/src/rooms-vault.h b/src/rooms-vault.h index b9355316c..9676c1151 100644 --- a/src/rooms-vault.h +++ b/src/rooms-vault.h @@ -1,3 +1,4 @@ extern bool build_type7(void); extern bool build_type8(void); +extern bool build_type10(void); diff --git a/src/rooms.c b/src/rooms.c index d518bcf7c..023017f30 100644 --- a/src/rooms.c +++ b/src/rooms.c @@ -1211,7 +1211,7 @@ void build_cavern(void) } } -static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type) +bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type) { int x, y, i, xhsize, yhsize; int feat1, feat2, feat3; @@ -1415,7 +1415,7 @@ void build_lake(int type) * * The doors must be INSIDE the allocated region. */ -static void add_door(int x, int y) +void add_door(int x, int y) { /* Need to have a wall in the center square */ if (!is_outer_bold(y, x)) return; @@ -1465,7 +1465,7 @@ static void add_door(int x, int y) /* * Routine that fills the empty areas of a room with treasure and monsters. */ -static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty) +void fill_treasure(int x1, int x2, int y1, int y2, int difficulty) { int x, y, cx, cy, size; s32b value; @@ -1597,148 +1597,6 @@ static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty) } -/* - * This function creates a random vault that looks like a collection of bubbles. - * It works by getting a set of coordinates that represent the center of each - * bubble. The entire room is made by seeing which bubble center is closest. If - * two centers are equidistant then the square is a wall, otherwise it is a floor. - * The only exception is for squares really near a center, these are always floor. - * (It looks better than without this check.) - * - * Note: If two centers are on the same point then this algorithm will create a - * blank bubble filled with walls. - This is prevented from happening. - */ -static void build_bubble_vault(int x0, int y0, int xsize, int ysize) -{ - #define BUBBLENUM 10 /* number of bubbles */ - - /* array of center points of bubbles */ - coord center[BUBBLENUM]; - - int i, j, x, y; - u16b min1, min2, temp; - bool done; - - /* Offset from center to top left hand corner */ - int xhsize = xsize / 2; - int yhsize = ysize / 2; - - msg_print_wizard(CHEAT_DUNGEON, _("泡型ランダムVaultを生成しました。", "Room Vault.")); - - /* Allocate center of bubbles */ - center[0].x = (byte)randint1(xsize - 3) + 1; - center[0].y = (byte)randint1(ysize - 3) + 1; - - for (i = 1; i < BUBBLENUM; i++) - { - done = FALSE; - - /* get center and check to see if it is unique */ - while (!done) - { - done = TRUE; - - x = randint1(xsize - 3) + 1; - y = randint1(ysize - 3) + 1; - - for (j = 0; j < i; j++) - { - /* rough test to see if there is an overlap */ - if ((x == center[j].x) && (y == center[j].y)) done = FALSE; - } - } - - center[i].x = (byte_hack)x; - center[i].y = (byte_hack)y; - } - - - /* Top and bottom boundaries */ - for (i = 0; i < xsize; i++) - { - int side_x = x0 - xhsize + i; - - place_outer_noperm_bold(y0 - yhsize + 0, side_x); - cave[y0 - yhsize + 0][side_x].info |= (CAVE_ROOM | CAVE_ICKY); - place_outer_noperm_bold(y0 - yhsize + ysize - 1, side_x); - cave[y0 - yhsize + ysize - 1][side_x].info |= (CAVE_ROOM | CAVE_ICKY); - } - - /* Left and right boundaries */ - for (i = 1; i < ysize - 1; i++) - { - int side_y = y0 - yhsize + i; - - place_outer_noperm_bold(side_y, x0 - xhsize + 0); - cave[side_y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY); - place_outer_noperm_bold(side_y, x0 - xhsize + xsize - 1); - cave[side_y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY); - } - - /* Fill in middle with bubbles */ - for (x = 1; x < xsize - 1; x++) - { - for (y = 1; y < ysize - 1; y++) - { - /* Get distances to two closest centers */ - - /* initialize */ - min1 = (u16b)distance(x, y, center[0].x, center[0].y); - min2 = (u16b)distance(x, y, center[1].x, center[1].y); - - if (min1 > min2) - { - /* swap if in wrong order */ - temp = min1; - min1 = min2; - min2 = temp; - } - - /* Scan the rest */ - for (i = 2; i < BUBBLENUM; i++) - { - temp = (u16b)distance(x, y, center[i].x, center[i].y); - - if (temp < min1) - { - /* smallest */ - min2 = min1; - min1 = temp; - } - else if (temp < min2) - { - /* second smallest */ - min2 = temp; - } - } - if (((min2 - min1) <= 2) && (!(min1 < 3))) - { - /* Boundary at midpoint+ not at inner region of bubble */ - place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x); - } - else - { - /* middle of a bubble */ - place_floor_bold(y0 - yhsize + y, x0 - xhsize + x); - } - - /* clean up rest of flags */ - cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY); - } - } - - /* Try to add some random doors */ - for (i = 0; i < 500; i++) - { - x = randint1(xsize - 3) - xhsize + x0 + 1; - y = randint1(ysize - 3) - yhsize + y0 + 1; - add_door(x, y); - } - - /* Fill with monsters and treasure, low difficulty */ - fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5)); -} - /* * Overlay a rectangular room given its bounds @@ -1746,7 +1604,7 @@ static void build_bubble_vault(int x0, int y0, int xsize, int ysize) * The area inside the walls is not touched: * only granite is removed- normal walls stay */ -static void build_room(int x1, int x2, int y1, int y2) +void build_room(int x1, int x2, int y1, int y2) { int x, y, i, xsize, ysize, temp; @@ -1814,103 +1672,6 @@ static void build_room(int x1, int x2, int y1, int y2) } -/* Create a random vault that looks like a collection of overlapping rooms */ - -static void build_room_vault(int x0, int y0, int xsize, int ysize) -{ - int i, x1, x2, y1, y2, xhsize, yhsize; - - /* get offset from center */ - xhsize = xsize / 2; - yhsize = ysize / 2; - - msg_print_wizard(CHEAT_DUNGEON, _("部屋型ランダムVaultを生成しました。", "Room Vault.")); - - /* fill area so don't get problems with arena levels */ - for (x1 = 0; x1 < xsize; x1++) - { - int x = x0 - xhsize + x1; - - for (y1 = 0; y1 < ysize; y1++) - { - int y = y0 - yhsize + y1; - - place_extra_bold(y, x); - cave[y][x].info &= (~CAVE_ICKY); - } - } - - /* add ten random rooms */ - for (i = 0; i < 10; i++) - { - x1 = randint1(xhsize) * 2 + x0 - xhsize; - x2 = randint1(xhsize) * 2 + x0 - xhsize; - y1 = randint1(yhsize) * 2 + y0 - yhsize; - y2 = randint1(yhsize) * 2 + y0 - yhsize; - build_room(x1, x2, y1, y2); - } - - /* Add some random doors */ - for (i = 0; i < 500; i++) - { - x1 = randint1(xsize - 3) - xhsize + x0 + 1; - y1 = randint1(ysize - 3) - yhsize + y0 + 1; - add_door(x1, y1); - } - - /* Fill with monsters and treasure, high difficulty */ - fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5); -} - - -/* Create a random vault out of a fractal cave */ -static void build_cave_vault(int x0, int y0, int xsiz, int ysiz) -{ - int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y; - bool done, light, room; - - /* round to make sizes even */ - xhsize = xsiz / 2; - yhsize = ysiz / 2; - xsize = xhsize * 2; - ysize = yhsize * 2; - - msg_print_wizard(CHEAT_DUNGEON, _("洞穴ランダムVaultを生成しました。", "Cave Vault.")); - - light = done = FALSE; - room = TRUE; - - while (!done) - { - /* testing values for these parameters feel free to adjust */ - grd = 1 << randint0(4); - - /* want average of about 16 */ - roug = randint1(8) * randint1(4); - - /* about size/2 */ - cutoff = randint1(xsize / 4) + randint1(ysize / 4) + - randint1(xsize / 4) + randint1(ysize / 4); - - /* make it */ - generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff); - - /* Convert to normal format+ clean up */ - done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room); - } - - /* Set icky flag because is a vault */ - for (x = 0; x <= xsize; x++) - { - for (y = 0; y <= ysize; y++) - { - cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY; - } - } - - /* Fill with monsters and treasure, low difficulty */ - fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5)); -} /* * maze vault -- rectangular labyrinthine rooms @@ -1930,8 +1691,7 @@ static void build_cave_vault(int x0, int y0, int xsiz, int ysiz) * is the randint0(3) below; it governs the relative density of * twists and turns in the labyrinth: smaller number, more twists. */ -static void r_visit(int y1, int x1, int y2, int x2, - int node, int dir, int *visited) +void r_visit(int y1, int x1, int y2, int x2, int node, int dir, int *visited) { int i, j, m, n, temp, x, y, adj[4]; @@ -2079,131 +1839,6 @@ void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault) } -/* Build a "mini" checkerboard vault - * - * This is done by making a permanent wall maze and setting - * the diagonal sqaures of the checker board to be granite. - * The vault has two entrances on opposite sides to guarantee - * a way to get in even if the vault abuts a side of the dungeon. - */ -static void build_mini_c_vault(int x0, int y0, int xsize, int ysize) -{ - int dy, dx; - int y1, x1, y2, x2, y, x, total; - int m, n, num_vertices; - int *visited; - - msg_print_wizard(CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault.")); - - /* Pick a random room size */ - dy = ysize / 2 - 1; - dx = xsize / 2 - 1; - - y1 = y0 - dy; - x1 = x0 - dx; - y2 = y0 + dy; - x2 = x0 + dx; - - - /* generate the room */ - for (x = x1 - 2; x <= x2 + 2; x++) - { - if (!in_bounds(y1-2,x)) break; - - cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY); - - place_outer_noperm_bold(y1-2, x); - } - - for (x = x1 - 2; x <= x2 + 2; x++) - { - if (!in_bounds(y2+2,x)) break; - - cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY); - - place_outer_noperm_bold(y2+2, x); - } - - for (y = y1 - 2; y <= y2 + 2; y++) - { - if (!in_bounds(y,x1-2)) break; - - cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY); - - place_outer_noperm_bold(y, x1-2); - } - - for (y = y1 - 2; y <= y2 + 2; y++) - { - if (!in_bounds(y,x2+2)) break; - - cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY); - - place_outer_noperm_bold(y, x2+2); - } - - for (y = y1 - 1; y <= y2 + 1; y++) - { - for (x = x1 - 1; x <= x2 + 1; x++) - { - cave_type *c_ptr = &cave[y][x]; - - c_ptr->info |= (CAVE_ROOM | CAVE_ICKY); - - /* Permanent walls */ - place_inner_perm_grid(c_ptr); - } - } - - - /* dimensions of vertex array */ - m = dx + 1; - n = dy + 1; - num_vertices = m * n; - - /* initialize array of visited vertices */ - C_MAKE(visited, num_vertices, int); - - /* traverse the graph to create a spannng tree, pick a random root */ - r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited); - - /* Make it look like a checker board vault */ - for (x = x1; x <= x2; x++) - { - for (y = y1; y <= y2; y++) - { - total = x - x1 + y - y1; - /* If total is odd- and is a floor then make a wall */ - if ((total % 2 == 1) && is_floor_bold(y, x)) - { - place_inner_bold(y, x); - } - } - } - - /* Make a couple of entrances */ - if (one_in_(2)) - { - /* left and right */ - y = randint1(dy) + dy / 2; - place_inner_bold(y1 + y, x1 - 1); - place_inner_bold(y1 + y, x2 + 1); - } - else - { - /* top and bottom */ - x = randint1(dx) + dx / 2; - place_inner_bold(y1 - 1, x1 + x); - place_inner_bold(y2 + 1, x1 + x); - } - - /* Fill with monsters and treasure, highest difficulty */ - fill_treasure(x1, x2, y1, y2, 10); - - C_KILL(visited, num_vertices, int); -} - - /* Build a town/ castle by using a recursive algorithm. * Basically divide each region in a probalistic way to create * smaller regions. When the regions get too small stop. @@ -2211,7 +1846,7 @@ static void build_mini_c_vault(int x0, int y0, int xsize, int ysize) * The power variable is a measure of how well defended a region is. * This alters the possible choices. */ -static void build_recursive_room(int x1, int y1, int x2, int y2, int power) +void build_recursive_room(int x1, int y1, int x2, int y2, int power) { int xsize, ysize; int x, y; @@ -2410,49 +2045,6 @@ static void build_recursive_room(int x1, int y1, int x2, int y2, int power) } -/* Build a castle */ - -/* Driver routine: clear the region and call the recursive -* room routine. -* -*This makes a vault that looks like a castle/ city in the dungeon. -*/ -static void build_castle_vault(int x0, int y0, int xsize, int ysize) -{ - int dy, dx; - int y1, x1, y2, x2; - int y, x; - - /* Pick a random room size */ - dy = ysize / 2 - 1; - dx = xsize / 2 - 1; - - y1 = y0 - dy; - x1 = x0 - dx; - y2 = y0 + dy; - x2 = x0 + dx; - - msg_print_wizard(CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault")); - - /* generate the room */ - for (y = y1 - 1; y <= y2 + 1; y++) - { - for (x = x1 - 1; x <= x2 + 1; x++) - { - cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY); - /* Make everything a floor */ - place_floor_bold(y, x); - } - } - - /* Make the castle */ - build_recursive_room(x1, y1, x2, y2, randint1(5)); - - /* Fill with monsters and treasure, low difficulty */ - fill_treasure(x1, x2, y1, y2, randint1(3)); -} - - /* * Add outer wall to a floored region * Note: no range checking is done so must be inside dungeon @@ -2532,274 +2124,6 @@ int dist2(int x1, int y1, int x2, int y2, int h1, int h2, int h3, int h4) } -/* - * Build target vault. - * This is made by two concentric "crypts" with perpendicular - * walls creating the cross-hairs. - */ -static void build_target_vault(int x0, int y0, int xsize, int ysize) -{ - int rad, x, y; - - /* Make a random metric */ - int h1, h2, h3, h4; - h1 = randint1(32) - 16; - h2 = randint1(16); - h3 = randint1(32); - h4 = randint1(32) - 16; - - msg_print_wizard(CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Elemental Vault")); - - /* work out outer radius */ - if (xsize > ysize) - { - rad = ysize / 2; - } - else - { - rad = xsize / 2; - } - - /* Make floor */ - for (x = x0 - rad; x <= x0 + rad; x++) - { - for (y = y0 - rad; y <= y0 + rad; y++) - { - /* clear room flag */ - cave[y][x].info &= ~(CAVE_ROOM); - - /* Vault - so is "icky" */ - cave[y][x].info |= CAVE_ICKY; - - if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1) - { - /* inside- so is floor */ - place_floor_bold(y, x); - } - else - { - /* make granite outside so arena works */ - place_extra_bold(y, x); - } - - /* proper boundary for arena */ - if (((y + rad) == y0) || ((y - rad) == y0) || - ((x + rad) == x0) || ((x - rad) == x0)) - { - place_extra_bold(y, x); - } - } - } - - /* Find visible outer walls and set to be FEAT_OUTER */ - add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1, - x0 + rad + 1, y0 + rad + 1); - - /* Add inner wall */ - for (x = x0 - rad / 2; x <= x0 + rad / 2; x++) - { - for (y = y0 - rad / 2; y <= y0 + rad / 2; y++) - { - if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2) - { - /* Make an internal wall */ - place_inner_bold(y, x); - } - } - } - - /* Add perpendicular walls */ - for (x = x0 - rad; x <= x0 + rad; x++) - { - place_inner_bold(y0, x); - } - - for (y = y0 - rad; y <= y0 + rad; y++) - { - place_inner_bold(y, x0); - } - - /* Make inner vault */ - for (y = y0 - 1; y <= y0 + 1; y++) - { - place_inner_bold(y, x0 - 1); - place_inner_bold(y, x0 + 1); - } - for (x = x0 - 1; x <= x0 + 1; x++) - { - place_inner_bold(y0 - 1, x); - place_inner_bold(y0 + 1, x); - } - - place_floor_bold(y0, x0); - - - /* Add doors to vault */ - /* get two distances so can place doors relative to centre */ - x = (rad - 2) / 4 + 1; - y = rad / 2 + x; - - add_door(x0 + x, y0); - add_door(x0 + y, y0); - add_door(x0 - x, y0); - add_door(x0 - y, y0); - add_door(x0, y0 + x); - add_door(x0, y0 + y); - add_door(x0, y0 - x); - add_door(x0, y0 - y); - - /* Fill with stuff - medium difficulty */ - fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3); -} - - -#ifdef ALLOW_CAVERNS_AND_LAKES -/* - * This routine uses a modified version of the lake code to make a - * distribution of some terrain type over the vault. This type - * depends on the dungeon depth. - * - * Miniture rooms are then scattered across the vault. - */ -static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz) -{ - int grd, roug; - int c1, c2, c3; - bool done = FALSE; - int xsize, ysize, xhsize, yhsize, x, y, i; - int type; - - msg_print_wizard(CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault")); - - /* round to make sizes even */ - xhsize = xsiz / 2; - yhsize = ysiz / 2; - xsize = xhsize * 2; - ysize = yhsize * 2; - - if (dun_level < 25) - { - /* Earth vault (Rubble) */ - type = LAKE_T_EARTH_VAULT; - } - else if (dun_level < 50) - { - /* Air vault (Trees) */ - type = LAKE_T_AIR_VAULT; - } - else if (dun_level < 75) - { - /* Water vault (shallow water) */ - type = LAKE_T_WATER_VAULT; - } - else - { - /* Fire vault (shallow lava) */ - type = LAKE_T_FIRE_VAULT; - } - - while (!done) - { - /* testing values for these parameters: feel free to adjust */ - grd = 1 << (randint0(3)); - - /* want average of about 16 */ - roug = randint1(8) * randint1(4); - - /* Make up size of various componants */ - /* Floor */ - c3 = 2 * xsize / 3; - - /* Deep water/lava */ - c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5; - - /* Shallow boundary */ - c2 = (c1 + c3) / 2; - - /* make it */ - generate_hmap(y0, x0, xsize, ysize, grd, roug, c3); - - /* Convert to normal format+ clean up */ - done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type); - } - - /* Set icky flag because is a vault */ - for (x = 0; x <= xsize; x++) - { - for (y = 0; y <= ysize; y++) - { - cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY; - } - } - - /* make a few rooms in the vault */ - for (i = 1; i <= (xsize * ysize) / 50; i++) - { - build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2, - y0 + randint0(ysize - 4) - ysize / 2 + 2); - } - - /* Fill with monsters and treasure, low difficulty */ - fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, - y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5)); -} -#endif /* ALLOW_CAVERNS_AND_LAKES */ - - -/*! - * @brief タイプ10の部屋…ランダム生成vault / Type 10 -- Random vaults - * @return なし - */ -static bool build_type10(void) -{ - POSITION y0, x0, xsize, ysize, vtype; - - /* Get size */ - /* big enough to look good, small enough to be fairly common. */ - xsize = randint1(22) + 22; - ysize = randint1(11) + 11; - - /* Find and reserve some space in the dungeon. Get center of room. */ - if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE; - - /* Select type of vault */ -#ifdef ALLOW_CAVERNS_AND_LAKES - do - { - vtype = randint1(15); - } - while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) && - ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11))); -#else /* ALLOW_CAVERNS_AND_LAKES */ - do - { - vtype = randint1(7); - } - while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) && - ((vtype == 1) || (vtype == 3))); -#endif /* ALLOW_CAVERNS_AND_LAKES */ - - switch (vtype) - { - /* Build an appropriate room */ - case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break; - case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break; - case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break; - case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break; - case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break; - case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break; - case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break; -#ifdef ALLOW_CAVERNS_AND_LAKES - case 8: build_elemental_vault(x0, y0, xsize, ysize); break; -#endif /* ALLOW_CAVERNS_AND_LAKES */ - /* I know how to add a few more... give me some time. */ - - /* Paranoia */ - default: return FALSE; - } - - return TRUE; -} /* Create a new floor room with optional light */ diff --git a/src/rooms.h b/src/rooms.h index 5b11f56f6..76bef097a 100644 --- a/src/rooms.h +++ b/src/rooms.h @@ -91,4 +91,9 @@ extern void generate_room_floor(int y1, int x1, int y2, int x2, int light); extern void generate_fill_perm_bold(int y1, int x1, int y2, int x2); extern void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff); extern bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room); - +extern void fill_treasure(int x1, int x2, int y1, int y2, int difficulty); +extern bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type); +extern void build_recursive_room(int x1, int y1, int x2, int y2, int power); +extern void build_room(int x1, int x2, int y1, int y2); +extern void add_door(int x, int y); +extern void r_visit(int y1, int x1, int y2, int x2, int node, int dir, int *visited); -- 2.11.0