… | |
… | |
27 | 2 = wall to right, |
27 | 2 = wall to right, |
28 | 4 = wall above |
28 | 4 = wall above |
29 | 8 = wall below */ |
29 | 8 = wall below */ |
30 | int surround_index = 0; |
30 | int surround_index = 0; |
31 | |
31 | |
32 | if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.')) |
32 | if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.')) surround_index |= 1; |
33 | surround_index += 1; |
|
|
34 | if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.')) |
33 | if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.')) surround_index |= 2; |
35 | surround_index += 2; |
|
|
36 | if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.')) |
34 | if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.')) surround_index |= 4; |
37 | surround_index += 4; |
|
|
38 | if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.')) |
35 | if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.')) surround_index |= 8; |
39 | surround_index += 8; |
36 | |
40 | return surround_index; |
37 | return surround_index; |
41 | } |
38 | } |
42 | |
39 | |
43 | /* actually make the layout: we work by a reduction process: |
40 | /* actually make the layout: we work by a reduction process: |
44 | * first we make everything a wall, then we remove areas to make rooms |
41 | * first we make everything a wall, then we remove areas to make rooms |
45 | */ |
42 | */ |
46 | Maze |
43 | void |
47 | roguelike_layout_gen (int xsize, int ysize, int options) |
44 | roguelike_layout_gen (Layout maze, int options) |
48 | { |
45 | { |
49 | int i, j; |
46 | int i, j; |
50 | Room *walk; |
47 | Room *walk; |
51 | int nrooms = 0; |
48 | int nrooms = 0; |
52 | int tries = 0; |
49 | int tries = 0; |
53 | |
50 | |
54 | Maze maze (xsize, ysize); |
51 | int xsize = maze->w; |
55 | |
52 | int ysize = maze->h; |
56 | for (i = 0; i < xsize; i++) |
|
|
57 | for (j = 0; j < ysize; j++) |
|
|
58 | maze[i][j] = '#'; |
|
|
59 | |
53 | |
60 | /* minimum room size is basically 5x5: if xsize/ysize is |
54 | /* minimum room size is basically 5x5: if xsize/ysize is |
61 | less than 3x that then hollow things out, stick in |
55 | less than 3x that then hollow things out, stick in |
62 | a stairsup and stairs down, and exit */ |
56 | a stairsup and stairs down, and exit */ |
63 | |
|
|
64 | if (xsize < 11 || ysize < 11) |
57 | if (xsize < 11 || ysize < 11) |
65 | { |
58 | { |
66 | for (i = 1; i < xsize - 1; i++) |
59 | maze->clear (); |
67 | for (j = 1; j < ysize - 1; j++) |
60 | maze->border (); |
68 | maze[i][j] = 0; |
|
|
69 | |
61 | |
70 | maze[(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; |
62 | maze[(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; |
71 | maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
63 | maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
72 | |
64 | |
73 | return maze; |
65 | return; |
74 | } |
66 | } |
|
|
67 | |
|
|
68 | maze->clear ('#'); |
75 | |
69 | |
76 | /* decide on the number of rooms */ |
70 | /* decide on the number of rooms */ |
77 | nrooms = rndm (10) + 6; |
71 | nrooms = rmg_rndm (10) + 6; |
78 | Room *rooms = salloc0<Room> (nrooms + 1); |
72 | Room *rooms = salloc0<Room> (nrooms + 1); |
79 | |
73 | |
80 | /* actually place the rooms */ |
74 | /* actually place the rooms */ |
81 | i = 0; |
75 | i = 0; |
82 | while (tries < 450 && i < nrooms) |
76 | while (tries < 450 && i < nrooms) |
… | |
… | |
86 | tries++; |
80 | tries++; |
87 | else |
81 | else |
88 | i++; |
82 | i++; |
89 | } |
83 | } |
90 | |
84 | |
91 | if (i == 0) |
85 | if (i == 0) /* no can do! */ |
92 | { /* no can do! */ |
86 | { |
93 | for (i = 1; i < xsize - 1; i++) |
87 | maze->clear (); |
94 | for (j = 1; j < ysize - 1; j++) |
88 | maze->border (); |
95 | maze[i][j] = 0; |
|
|
96 | |
89 | |
97 | maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; |
90 | maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; |
98 | maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
91 | maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
99 | |
92 | |
100 | sfree (rooms, nrooms + 1); |
93 | sfree (rooms, nrooms + 1); |
101 | return maze; |
94 | return; |
102 | } |
95 | } |
103 | |
|
|
104 | |
96 | |
105 | /* erase the areas occupied by the rooms */ |
97 | /* erase the areas occupied by the rooms */ |
106 | roguelike_make_rooms (rooms, maze, options); |
98 | roguelike_make_rooms (rooms, maze, options); |
107 | |
99 | |
108 | roguelike_link_rooms (rooms, maze, xsize, ysize); |
100 | roguelike_link_rooms (rooms, maze, xsize, ysize); |
… | |
… | |
153 | } |
145 | } |
154 | } |
146 | } |
155 | } |
147 | } |
156 | |
148 | |
157 | sfree (rooms, nrooms + 1); |
149 | sfree (rooms, nrooms + 1); |
158 | return maze; |
|
|
159 | } |
150 | } |
160 | |
151 | |
161 | static int |
152 | static int |
162 | roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms) |
153 | roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms) |
163 | { |
154 | { |
… | |
… | |
171 | |
162 | |
172 | /* decide on the base x and y sizes */ |
163 | /* decide on the base x and y sizes */ |
173 | x_basesize = xsize / isqrt (nrooms); |
164 | x_basesize = xsize / isqrt (nrooms); |
174 | y_basesize = ysize / isqrt (nrooms); |
165 | y_basesize = ysize / isqrt (nrooms); |
175 | |
166 | |
176 | tx = rndm (xsize); |
167 | tx = rmg_rndm (xsize); |
177 | ty = rndm (ysize); |
168 | ty = rmg_rndm (ysize); |
178 | |
169 | |
179 | /* generate a distribution of sizes centered about basesize */ |
170 | /* generate a distribution of sizes centered about basesize */ |
180 | sx = rndm (x_basesize) + rndm (x_basesize) + rndm (x_basesize); |
171 | sx = rmg_rndm (x_basesize) + rmg_rndm (x_basesize) + rmg_rndm (x_basesize); |
181 | sy = rndm (y_basesize) + rndm (y_basesize) + rndm (y_basesize); |
172 | sy = rmg_rndm (y_basesize) + rmg_rndm (y_basesize) + rmg_rndm (y_basesize); |
182 | sy = (int) (sy * .5); /* renormalize */ |
173 | sy = (int) (sy * .5); /* renormalize */ |
183 | |
174 | |
184 | /* find the corners */ |
175 | /* find the corners */ |
185 | ax = tx - sx / 2; |
176 | ax = tx - sx / 2; |
186 | zx = tx + sx / 2 + sx % 2; |
177 | zx = tx + sx / 2 + sx % 2; |
… | |
… | |
243 | break; |
234 | break; |
244 | case 2: |
235 | case 2: |
245 | making_circle = 1; |
236 | making_circle = 1; |
246 | break; |
237 | break; |
247 | default: |
238 | default: |
248 | making_circle = ((rndm (3) == 0) ? 1 : 0); |
239 | making_circle = ((rmg_rndm (3) == 0) ? 1 : 0); |
249 | break; |
240 | break; |
250 | } |
241 | } |
251 | |
242 | |
252 | if (walk->sx < walk->sy) |
243 | if (walk->sx < walk->sy) |
253 | R = walk->sx / 2; |
244 | R = walk->sx / 2; |
… | |
… | |
278 | int y1 = walk->y; |
269 | int y1 = walk->y; |
279 | int x2 = (walk - 1)->x; |
270 | int x2 = (walk - 1)->x; |
280 | int y2 = (walk - 1)->y; |
271 | int y2 = (walk - 1)->y; |
281 | int in_wall = 0; |
272 | int in_wall = 0; |
282 | |
273 | |
283 | if (rndm (2)) |
274 | if (rmg_rndm (2)) |
284 | { /* connect in x direction first */ |
275 | { /* connect in x direction first */ |
285 | /* horizontal connect */ |
276 | /* horizontal connect */ |
286 | /* swap (x1,y1) (x2,y2) if necessary */ |
277 | /* swap (x1,y1) (x2,y2) if necessary */ |
287 | |
278 | |
288 | if (x2 < x1) |
279 | if (x2 < x1) |