… | |
… | |
17 | } Room; |
17 | } Room; |
18 | |
18 | |
19 | static int roguelike_place_room (Room * Rooms, int xsize, int ysize, int nrooms); |
19 | static int roguelike_place_room (Room * Rooms, int xsize, int ysize, int nrooms); |
20 | static void roguelike_make_rooms (Room * Rooms, char **maze, int options); |
20 | static void roguelike_make_rooms (Room * Rooms, char **maze, int options); |
21 | static void roguelike_link_rooms (Room * Rooms, char **maze, int xsize, int ysize); |
21 | static void roguelike_link_rooms (Room * Rooms, char **maze, int xsize, int ysize); |
22 | |
|
|
23 | |
22 | |
24 | int |
23 | int |
25 | surround_check (char **layout, int i, int j, int Xsize, int Ysize) |
24 | surround_check (char **layout, int i, int j, int Xsize, int Ysize) |
26 | { |
25 | { |
27 | /* 1 = wall to left, |
26 | /* 1 = wall to left, |
… | |
… | |
78 | maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
77 | maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; |
79 | return maze; |
78 | return maze; |
80 | } |
79 | } |
81 | |
80 | |
82 | /* decide on the number of rooms */ |
81 | /* decide on the number of rooms */ |
83 | nrooms = RANDOM () % 10 + 6; |
82 | nrooms = rndm (10) + 6; |
84 | Rooms = (Room *) calloc (nrooms + 1, sizeof (Room)); |
83 | Rooms = (Room *) calloc (nrooms + 1, sizeof (Room)); |
85 | |
84 | |
86 | /* actually place the rooms */ |
85 | /* actually place the rooms */ |
87 | i = 0; |
86 | i = 0; |
88 | while (tries < 450 && i < nrooms) |
87 | while (tries < 450 && i < nrooms) |
… | |
… | |
174 | /* decide on the base x and y sizes */ |
173 | /* decide on the base x and y sizes */ |
175 | |
174 | |
176 | x_basesize = xsize / isqrt (nrooms); |
175 | x_basesize = xsize / isqrt (nrooms); |
177 | y_basesize = ysize / isqrt (nrooms); |
176 | y_basesize = ysize / isqrt (nrooms); |
178 | |
177 | |
179 | |
178 | tx = rndm (xsize); |
180 | tx = RANDOM () % xsize; |
179 | ty = rndm (ysize); |
181 | ty = RANDOM () % ysize; |
|
|
182 | |
180 | |
183 | /* generate a distribution of sizes centered about basesize */ |
181 | /* generate a distribution of sizes centered about basesize */ |
184 | sx = (RANDOM () % x_basesize) + (RANDOM () % x_basesize) + (RANDOM () % x_basesize); |
182 | sx = rndm (x_basesize) + rndm (x_basesize) + rndm (x_basesize); |
185 | sy = (RANDOM () % y_basesize) + (RANDOM () % y_basesize) + (RANDOM () % y_basesize); |
183 | sy = rndm (y_basesize) + rndm (y_basesize) + rndm (y_basesize); |
186 | sy = (int) (sy * .5); /* renormalize */ |
184 | sy = (int) (sy * .5); /* renormalize */ |
187 | |
185 | |
188 | /* find the corners */ |
186 | /* find the corners */ |
189 | ax = tx - sx / 2; |
187 | ax = tx - sx / 2; |
190 | zx = tx + sx / 2 + sx % 2; |
188 | zx = tx + sx / 2 + sx % 2; |
… | |
… | |
241 | for (walk = Rooms; walk->x != 0; walk++) |
239 | for (walk = Rooms; walk->x != 0; walk++) |
242 | { |
240 | { |
243 | /* first decide what shape to make */ |
241 | /* first decide what shape to make */ |
244 | switch (options) |
242 | switch (options) |
245 | { |
243 | { |
246 | case 1: |
244 | case 1: |
247 | making_circle = 0; |
245 | making_circle = 0; |
248 | break; |
246 | break; |
249 | case 2: |
247 | case 2: |
250 | making_circle = 1; |
248 | making_circle = 1; |
251 | break; |
249 | break; |
252 | default: |
250 | default: |
253 | making_circle = ((RANDOM () % 3 == 0) ? 1 : 0); |
251 | making_circle = ((rndm (3) == 0) ? 1 : 0); |
254 | break; |
252 | break; |
255 | } |
253 | } |
256 | |
254 | |
257 | if (walk->sx < walk->sy) |
255 | if (walk->sx < walk->sy) |
258 | R = walk->sx / 2; |
256 | R = walk->sx / 2; |
259 | else |
257 | else |
… | |
… | |
287 | int y1 = walk->y; |
285 | int y1 = walk->y; |
288 | int x2 = (walk - 1)->x; |
286 | int x2 = (walk - 1)->x; |
289 | int y2 = (walk - 1)->y; |
287 | int y2 = (walk - 1)->y; |
290 | int in_wall = 0; |
288 | int in_wall = 0; |
291 | |
289 | |
292 | if (RANDOM () % 2) |
290 | if (rndm (2)) |
293 | { /* connect in x direction first */ |
291 | { /* connect in x direction first */ |
294 | /* horizontal connect */ |
292 | /* horizontal connect */ |
295 | /* swap (x1,y1) (x2,y2) if necessary */ |
293 | /* swap (x1,y1) (x2,y2) if necessary */ |
296 | |
294 | |
297 | if (x2 < x1) |
295 | if (x2 < x1) |