… | |
… | |
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 | void |
43 | void |
47 | roguelike_layout_gen (Maze maze, 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; |
… | |
… | |
69 | } |
66 | } |
70 | |
67 | |
71 | maze->clear ('#'); |
68 | maze->clear ('#'); |
72 | |
69 | |
73 | /* decide on the number of rooms */ |
70 | /* decide on the number of rooms */ |
74 | nrooms = rndm (10) + 6; |
71 | nrooms = rmg_rndm (10) + 6; |
75 | Room *rooms = salloc0<Room> (nrooms + 1); |
72 | Room *rooms = salloc0<Room> (nrooms + 1); |
76 | |
73 | |
77 | /* actually place the rooms */ |
74 | /* actually place the rooms */ |
78 | i = 0; |
75 | i = 0; |
79 | while (tries < 450 && i < nrooms) |
76 | while (tries < 450 && i < nrooms) |
… | |
… | |
83 | tries++; |
80 | tries++; |
84 | else |
81 | else |
85 | i++; |
82 | i++; |
86 | } |
83 | } |
87 | |
84 | |
88 | if (i == 0) |
85 | if (i == 0) /* no can do! */ |
89 | { /* no can do! */ |
86 | { |
90 | maze->clear (); |
87 | maze->clear (); |
91 | maze->border (); |
88 | maze->border (); |
92 | |
89 | |
93 | maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; |
90 | maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; |
94 | maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
91 | maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
95 | |
92 | |
96 | sfree (rooms, nrooms + 1); |
93 | sfree (rooms, nrooms + 1); |
97 | return; |
94 | return; |
98 | } |
95 | } |
99 | |
|
|
100 | |
96 | |
101 | /* erase the areas occupied by the rooms */ |
97 | /* erase the areas occupied by the rooms */ |
102 | roguelike_make_rooms (rooms, maze, options); |
98 | roguelike_make_rooms (rooms, maze, options); |
103 | |
99 | |
104 | roguelike_link_rooms (rooms, maze, xsize, ysize); |
100 | roguelike_link_rooms (rooms, maze, xsize, ysize); |
… | |
… | |
166 | |
162 | |
167 | /* decide on the base x and y sizes */ |
163 | /* decide on the base x and y sizes */ |
168 | x_basesize = xsize / isqrt (nrooms); |
164 | x_basesize = xsize / isqrt (nrooms); |
169 | y_basesize = ysize / isqrt (nrooms); |
165 | y_basesize = ysize / isqrt (nrooms); |
170 | |
166 | |
171 | tx = rndm (xsize); |
167 | tx = rmg_rndm (xsize); |
172 | ty = rndm (ysize); |
168 | ty = rmg_rndm (ysize); |
173 | |
169 | |
174 | /* generate a distribution of sizes centered about basesize */ |
170 | /* generate a distribution of sizes centered about basesize */ |
175 | sx = rndm (x_basesize) + rndm (x_basesize) + rndm (x_basesize); |
171 | sx = rmg_rndm (x_basesize) + rmg_rndm (x_basesize) + rmg_rndm (x_basesize); |
176 | sy = rndm (y_basesize) + rndm (y_basesize) + rndm (y_basesize); |
172 | sy = rmg_rndm (y_basesize) + rmg_rndm (y_basesize) + rmg_rndm (y_basesize); |
177 | sy = (int) (sy * .5); /* renormalize */ |
173 | sy = (int) (sy * .5); /* renormalize */ |
178 | |
174 | |
179 | /* find the corners */ |
175 | /* find the corners */ |
180 | ax = tx - sx / 2; |
176 | ax = tx - sx / 2; |
181 | zx = tx + sx / 2 + sx % 2; |
177 | zx = tx + sx / 2 + sx % 2; |
… | |
… | |
238 | break; |
234 | break; |
239 | case 2: |
235 | case 2: |
240 | making_circle = 1; |
236 | making_circle = 1; |
241 | break; |
237 | break; |
242 | default: |
238 | default: |
243 | making_circle = ((rndm (3) == 0) ? 1 : 0); |
239 | making_circle = ((rmg_rndm (3) == 0) ? 1 : 0); |
244 | break; |
240 | break; |
245 | } |
241 | } |
246 | |
242 | |
247 | if (walk->sx < walk->sy) |
243 | if (walk->sx < walk->sy) |
248 | R = walk->sx / 2; |
244 | R = walk->sx / 2; |
… | |
… | |
273 | int y1 = walk->y; |
269 | int y1 = walk->y; |
274 | int x2 = (walk - 1)->x; |
270 | int x2 = (walk - 1)->x; |
275 | int y2 = (walk - 1)->y; |
271 | int y2 = (walk - 1)->y; |
276 | int in_wall = 0; |
272 | int in_wall = 0; |
277 | |
273 | |
278 | if (rndm (2)) |
274 | if (rmg_rndm (2)) |
279 | { /* connect in x direction first */ |
275 | { /* connect in x direction first */ |
280 | /* horizontal connect */ |
276 | /* horizontal connect */ |
281 | /* swap (x1,y1) (x2,y2) if necessary */ |
277 | /* swap (x1,y1) (x2,y2) if necessary */ |
282 | |
278 | |
283 | if (x2 < x1) |
279 | if (x2 < x1) |