OSDN Git Service

Merge remote-tracking branch 'remotes/hengbandosx/english-mind-edits' into feature...
[hengband/hengband.git] / src / room / rooms-maze-vault.c
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"
5 #include "grid/grid.h"
6 #include "room/treasure-deployment.h"
7 #include "system/floor-type-definition.h"
8 #include "wizard/wizard-messages.h"
9
10 /*
11  * maze vault -- rectangular labyrinthine rooms
12  *
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
17  *
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.
22  *
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.
27  */
28 void r_visit(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
29 {
30     int adj[4];
31     int m = (x2 - x1) / 2 + 1;
32     int n = (y2 - y1) / 2 + 1;
33     visited[node] = 1;
34     int x = 2 * (node % m) + x1;
35     int y = 2 * (node / m) + y1;
36     place_bold(player_ptr, y, x, GB_FLOOR);
37
38     if (one_in_(3)) {
39         for (int i = 0; i < 4; i++)
40             adj[i] = i;
41
42         for (int i = 0; i < 4; i++) {
43             int j = randint0(4);
44             int temp = adj[i];
45             adj[i] = adj[j];
46             adj[j] = temp;
47         }
48
49         dir = adj[0];
50     } else {
51         adj[0] = dir;
52         for (int i = 1; i < 4; i++)
53             adj[i] = i;
54
55         for (int i = 1; i < 4; i++) {
56             int j = 1 + randint0(3);
57             int temp = adj[i];
58             adj[i] = adj[j];
59             adj[j] = temp;
60         }
61     }
62
63     for (int i = 0; i < 4; i++) {
64         switch (adj[i]) {
65         case 0:
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);
70             }
71             break;
72         case 1:
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);
77             }
78             break;
79         case 2:
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);
84             }
85             break;
86         case 3:
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);
91             }
92         }
93     }
94 }
95
96 void build_maze_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
97 {
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++) {
109             grid_type *g_ptr;
110             g_ptr = &floor_ptr->grid_array[y][x];
111             g_ptr->info |= CAVE_ROOM;
112             if (is_vault)
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);
118             } else {
119                 place_grid(player_ptr, g_ptr, GB_INNER);
120             }
121
122             if (light)
123                 g_ptr->info |= (CAVE_GLOW);
124         }
125     }
126
127     int m = dx + 1;
128     int n = dy + 1;
129     int num_vertices = m * n;
130
131     int *visited;
132     C_MAKE(visited, num_vertices, int);
133     r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited);
134     if (is_vault)
135         fill_treasure(player_ptr, x1, x2, y1, y2, randint1(5));
136
137     C_KILL(visited, num_vertices, int);
138 }