1 #include "room/rooms-maze-vault.h"
2 #include "dungeon/dungeon-flag-types.h"
3 #include "dungeon/dungeon.h"
4 #include "game-option/cheat-types.h"
6 #include "room/treasure-deployment.h"
7 #include "system/floor-type-definition.h"
8 #include "wizard/wizard-messages.h"
11 * maze vault -- rectangular labyrinthine rooms
13 * maze vault uses two routines:
14 * r_visit - a recursive routine that builds the labyrinth
15 * build_maze_vault - a driver routine that calls r_visit and adds
16 * monsters, traps and treasure
18 * The labyrinth is built by creating a spanning tree of a graph.
19 * The graph vertices are at
20 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
21 * and the edges are the vertical and horizontal nearest neighbors.
23 * The spanning tree is created by performing a suitably randomized
24 * depth-first traversal of the graph. The only adjustable parameter
25 * is the randint0(3) below; it governs the relative density of
26 * twists and turns in the labyrinth: smaller number, more twists.
28 void r_visit(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
31 int m = (x2 - x1) / 2 + 1;
32 int n = (y2 - y1) / 2 + 1;
34 int x = 2 * (node % m) + x1;
35 int y = 2 * (node / m) + y1;
36 place_bold(player_ptr, y, x, GB_FLOOR);
39 for (int i = 0; i < 4; i++)
42 for (int i = 0; i < 4; i++) {
52 for (int i = 1; i < 4; i++)
55 for (int i = 1; i < 4; i++) {
56 int j = 1 + randint0(3);
63 for (int i = 0; i < 4; i++) {
66 /* (0,+) - check for bottom boundary */
67 if ((node / m < n - 1) && (visited[node + m] == 0)) {
68 place_bold(player_ptr, y + 1, x, GB_FLOOR);
69 r_visit(player_ptr, y1, x1, y2, x2, node + m, dir, visited);
73 /* (0,-) - check for top boundary */
74 if ((node / m > 0) && (visited[node - m] == 0)) {
75 place_bold(player_ptr, y - 1, x, GB_FLOOR);
76 r_visit(player_ptr, y1, x1, y2, x2, node - m, dir, visited);
80 /* (+,0) - check for right boundary */
81 if ((node % m < m - 1) && (visited[node + 1] == 0)) {
82 place_bold(player_ptr, y, x + 1, GB_FLOOR);
83 r_visit(player_ptr, y1, x1, y2, x2, node + 1, dir, visited);
87 /* (-,0) - check for left boundary */
88 if ((node % m > 0) && (visited[node - 1] == 0)) {
89 place_bold(player_ptr, y, x - 1, GB_FLOOR);
90 r_visit(player_ptr, y1, x1, y2, x2, node - 1, dir, visited);
96 void build_maze_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
98 msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
99 floor_type *floor_ptr = player_ptr->current_floor_ptr;
100 bool light = ((floor_ptr->dun_level <= randint1(25)) && is_vault && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS));
101 POSITION dy = ysize / 2 - 1;
102 POSITION dx = xsize / 2 - 1;
103 POSITION y1 = y0 - dy;
104 POSITION x1 = x0 - dx;
105 POSITION y2 = y0 + dy;
106 POSITION x2 = x0 + dx;
107 for (POSITION y = y1 - 1; y <= y2 + 1; y++) {
108 for (POSITION x = x1 - 1; x <= x2 + 1; x++) {
110 g_ptr = &floor_ptr->grid_array[y][x];
111 g_ptr->info |= CAVE_ROOM;
113 g_ptr->info |= CAVE_ICKY;
114 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1)) {
115 place_grid(player_ptr, g_ptr, GB_OUTER);
116 } else if (!is_vault) {
117 place_grid(player_ptr, g_ptr, GB_EXTRA);
119 place_grid(player_ptr, g_ptr, GB_INNER);
123 g_ptr->info |= (CAVE_GLOW);
129 int num_vertices = m * n;
132 C_MAKE(visited, num_vertices, int);
133 r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited);
135 fill_treasure(player_ptr, x1, x2, y1, y2, randint1(5));
137 C_KILL(visited, num_vertices, int);