… | |
… | |
34 | this->h = h; |
34 | this->h = h; |
35 | |
35 | |
36 | // we store the layout in a single contiguous memory layout |
36 | // we store the layout in a single contiguous memory layout |
37 | // first part consists of pointers to each column, followed |
37 | // first part consists of pointers to each column, followed |
38 | // by the actual columns (not rows!) |
38 | // by the actual columns (not rows!) |
39 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
39 | size = (sizeof (cell *) + sizeof (cell) * h) * w; |
40 | |
|
|
41 | data = (cell **)salloc<char> (size); |
40 | data = (cell **)salloc<char> (size); |
42 | |
41 | |
43 | cell *p = (cell *)(data + w); |
42 | cell *p = (cell *)(data + w); |
44 | |
43 | |
45 | for (int x = w; x--; ) |
44 | for (int x = 0; x < w; ++x) |
46 | data [x] = p + x * h; |
45 | data [x] = p + x * h; |
47 | } |
46 | } |
48 | |
47 | |
49 | layout::layout (int w, int h) |
48 | layout::layout (int w, int h) |
50 | { |
49 | { |
… | |
… | |
56 | alloc (copy.w, copy.h); |
55 | alloc (copy.w, copy.h); |
57 | |
56 | |
58 | memcpy (data [0], copy.data [0], sizeof (cell) * h * w); |
57 | memcpy (data [0], copy.data [0], sizeof (cell) * h * w); |
59 | } |
58 | } |
60 | |
59 | |
|
|
60 | layout::layout (layout &orig, int x1, int y1, int x2, int y2) |
|
|
61 | { |
|
|
62 | w = x2 - x1; |
|
|
63 | h = y2 - y1; |
|
|
64 | |
|
|
65 | // we only allocate space for the pointers |
|
|
66 | size = sizeof (cell *) * w; |
|
|
67 | data = (cell **)salloc<char> (size); |
|
|
68 | |
|
|
69 | // and now we point back into the original layout |
|
|
70 | for (int x = 0; x < w; ++x) |
|
|
71 | data [x] = orig.data [x + x1] + y1; |
|
|
72 | } |
|
|
73 | |
61 | layout::~layout () |
74 | layout::~layout () |
62 | { |
75 | { |
63 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
|
|
64 | |
|
|
65 | sfree ((char *)data, size); |
76 | sfree ((char *)data, size); |
66 | } |
77 | } |
67 | |
78 | |
68 | void |
79 | void |
69 | layout::fill (char fill) |
80 | layout::fill (char fill) |
70 | { |
81 | { |
71 | memset (data [0], fill, w * h); |
82 | //memset (data [0], fill, w * h); // only when contiguous :/ |
|
|
83 | fill_rect (0, 0, w, h, fill); |
72 | } |
84 | } |
73 | |
85 | |
74 | void |
86 | void |
75 | layout::rect (int x1, int y1, int x2, int y2, char fill) |
87 | layout::rect (int x1, int y1, int x2, int y2, char fill) |
|
|
88 | { |
|
|
89 | --x2; |
|
|
90 | |
|
|
91 | memset (data [x1] + y1, fill, y2 - y1); |
|
|
92 | memset (data [x2] + y1, fill, y2 - y1); |
|
|
93 | |
|
|
94 | while (++x1 < x2) |
|
|
95 | data [x1][y1] = data [x1][y2 - 1] = fill; |
|
|
96 | } |
|
|
97 | |
|
|
98 | void |
|
|
99 | layout::fill_rect (int x1, int y1, int x2, int y2, char fill) |
76 | { |
100 | { |
77 | for (; x1 < x2; ++x1) |
101 | for (; x1 < x2; ++x1) |
78 | memset (data [x1] + y1, fill, y2 - y1); |
102 | memset (data [x1] + y1, fill, y2 - y1); |
79 | } |
103 | } |
80 | |
104 | |
81 | void layout::border (char fill) |
105 | void layout::border (char fill) |
82 | { |
106 | { |
83 | for (int i = 0; i < w; i++) data [i][0] = data [i][h - 1] = fill; |
107 | rect (0, 0, w, h, fill); |
84 | for (int j = 0; j < h; j++) data [0][j] = data [w - 1][j] = fill; |
|
|
85 | } |
108 | } |
86 | |
109 | |
87 | void |
110 | void |
88 | layout::fill_rand (int percent) |
111 | layout::fill_rand (int percent) |
89 | { |
112 | { |
… | |
… | |
171 | ///////////////////////////////////////////////////////////////////////////// |
194 | ///////////////////////////////////////////////////////////////////////////// |
172 | // isolation remover - ensures single connected area |
195 | // isolation remover - ensures single connected area |
173 | |
196 | |
174 | typedef fixed_stack<point> pointlist; |
197 | typedef fixed_stack<point> pointlist; |
175 | |
198 | |
176 | static noinline void |
199 | static void noinline |
177 | push_flood_fill (layout &dist, pointlist &seeds, int x, int y) |
200 | push_flood_fill (layout &dist, pointlist &seeds, int x, int y) |
178 | { |
201 | { |
179 | if (dist [x][y]) |
202 | if (dist [x][y]) |
180 | return; |
203 | return; |
181 | |
204 | |
… | |
… | |
192 | ++y; |
215 | ++y; |
193 | } |
216 | } |
194 | |
217 | |
195 | while (--y >= y0) |
218 | while (--y >= y0) |
196 | { |
219 | { |
197 | if (x > 0) push_flood_fill (dist, seeds, x - 1, y); |
220 | if (x > 0 && !dist [x - 1][y]) push_flood_fill (dist, seeds, x - 1, y); |
198 | if (x < dist.w - 1) push_flood_fill (dist, seeds, x + 1, y); |
221 | if (x < dist.w - 1 && !dist [x + 1][y]) push_flood_fill (dist, seeds, x + 1, y); |
199 | } |
222 | } |
200 | } |
223 | } |
201 | |
224 | |
202 | static inline void |
225 | static inline void |
203 | make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d) |
226 | make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d, int perturb) |
204 | { |
227 | { |
205 | for (;;) |
228 | for (;;) |
206 | { |
229 | { |
|
|
230 | point neigh[4]; |
|
|
231 | int ncnt = 0; |
|
|
232 | |
|
|
233 | d += perturb > 1; |
|
|
234 | |
207 | if (x > 1 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1) |
235 | if (x > 0 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1) neigh [ncnt++] = point (x - 1, y); |
208 | --x; |
|
|
209 | else if (x < dist.w - 2 && U8 (dist [x + 1][y]) < d && dist [x + 1][y] > 1) |
236 | if (x < dist.w - 1 && U8 (dist [x + 1][y]) < d && dist [x + 1][y] > 1) neigh [ncnt++] = point (x + 1, y); |
210 | ++x; |
|
|
211 | else if (y > 1 && U8 (dist [x][y - 1]) < d && dist [x][y - 1] > 1) |
237 | if (y > 0 && U8 (dist [x][y - 1]) < d && dist [x][y - 1] > 1) neigh [ncnt++] = point (x, y - 1); |
212 | --y; |
|
|
213 | else if (y < dist.h - 2 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) |
238 | if (y < dist.h - 1 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); |
214 | ++y; |
239 | |
215 | else |
240 | if (!ncnt) |
216 | break; |
241 | return; |
|
|
242 | |
|
|
243 | point p = neigh [perturb ? rmg_rndm (ncnt) : 0]; |
|
|
244 | |
|
|
245 | seeds.push (p); |
|
|
246 | |
|
|
247 | x = p.x; |
|
|
248 | y = p.y; |
217 | |
249 | |
218 | d = dist [x][y]; |
250 | d = dist [x][y]; |
219 | dist [x][y] = 1; |
251 | dist [x][y] = 1; |
220 | seeds.push (point (x, y)); |
|
|
221 | } |
252 | } |
222 | } |
253 | } |
223 | |
254 | |
224 | static void inline |
255 | static void inline |
225 | maybe_push (layout &dist, pointlist &seeds, int x, int y, U8 d) |
256 | maybe_push (layout &dist, pointlist &seeds, int x, int y, U8 d) |
… | |
… | |
232 | return; |
263 | return; |
233 | |
264 | |
234 | seeds.push (point (x, y)); |
265 | seeds.push (point (x, y)); |
235 | } |
266 | } |
236 | |
267 | |
237 | void |
268 | // isolation remover, works on a "distance" map |
238 | layout::isolation_remover (bool dirty) |
269 | // the map must be initialised with 0 == rooms, 255 = walls |
|
|
270 | static void noinline |
|
|
271 | isolation_remover (layout &dist, unsigned int perturb = 2) |
239 | { |
272 | { |
240 | layout dist (w, h); |
|
|
241 | |
|
|
242 | // dist contains |
273 | // dist contains |
243 | // 0 == invisited rooms |
274 | // 0 == invisited rooms |
244 | // 1 == visited rooms |
275 | // 1 == visited rooms |
245 | // 2+ shortest distance to random near room |
276 | // 2+ shortest distance to random near room |
246 | |
277 | |
247 | // phase 1, initialise dist array, find seed |
278 | clamp_it (perturb, 0, 2); |
|
|
279 | |
|
|
280 | // phase 1, find seed |
248 | int cnt = 0; |
281 | int cnt = 0; |
249 | int x, y; |
282 | int x, y; |
250 | |
283 | |
251 | for (int i = 0; i < w; ++i) |
284 | for (int i = 0; i < dist.w; ++i) |
252 | for (int j = 0; j < h; ++j) |
285 | for (int j = 0; j < dist.h; ++j) |
253 | { |
286 | if (!dist [i][j] && !rmg_rndm (++cnt)) |
254 | if (data [i][j] == '#') |
|
|
255 | dist [i][j] = U8 (255); |
|
|
256 | else |
|
|
257 | { |
|
|
258 | dist [i][j] = 0; |
|
|
259 | if (!rmg_rndm (++cnt)) |
|
|
260 | x = i, y = j; |
287 | x = i, y = j; |
261 | } |
|
|
262 | } |
|
|
263 | |
288 | |
264 | if (!cnt) |
289 | if (!cnt) |
265 | { |
290 | { |
266 | // map is completely massive, this is not good, |
291 | // map is completely massive, this is not good, |
267 | // so make it empty instead. |
292 | // so make it empty instead. |
268 | clear (); |
293 | dist.fill (1); |
269 | border (); |
|
|
270 | return; |
294 | return; |
271 | } |
295 | } |
272 | |
296 | |
273 | fixed_stack<point> seeds (w * h * 5); |
297 | fixed_stack<point> seeds (dist.w * dist.h * 5); |
274 | |
298 | |
275 | // found first free space - picking the first one gives |
299 | // found first free space - picking the first one gives |
276 | // us a slight bias for tunnels, but usually you won't |
300 | // us a slight bias for tunnels, but usually you won't |
277 | // notice that in-game |
301 | // notice that in-game |
278 | seeds.push (point (x, y)); |
302 | seeds.push (point (x, y)); |
… | |
… | |
290 | y = p.y; |
314 | y = p.y; |
291 | |
315 | |
292 | if (!dist [x][y]) |
316 | if (!dist [x][y]) |
293 | { |
317 | { |
294 | // found new isolated area, make tunnel |
318 | // found new isolated area, make tunnel |
295 | if (!dirty) |
|
|
296 | push_flood_fill (dist, seeds, x, y); |
319 | push_flood_fill (dist, seeds, x, y); |
297 | |
|
|
298 | make_tunnel (dist, seeds, x, y, 255); |
320 | make_tunnel (dist, seeds, x, y, 254, perturb); |
299 | |
|
|
300 | if (dirty) |
|
|
301 | push_flood_fill (dist, seeds, x, y); |
|
|
302 | } |
321 | } |
303 | else |
322 | else |
304 | { |
323 | { |
305 | // nothing here, continue to expand |
324 | // nothing here, continue to expand |
306 | U8 d = U8 (dist [x][y]) + 1; |
325 | U8 d = U8 (dist [x][y]) + 1; |
… | |
… | |
309 | if (x > 0) maybe_push (dist, seeds, x - 1, y, d); |
328 | if (x > 0) maybe_push (dist, seeds, x - 1, y, d); |
310 | if (y < dist.h - 1) maybe_push (dist, seeds, x, y + 1, d); |
329 | if (y < dist.h - 1) maybe_push (dist, seeds, x, y + 1, d); |
311 | if (y > 0) maybe_push (dist, seeds, x, y - 1, d); |
330 | if (y > 0) maybe_push (dist, seeds, x, y - 1, d); |
312 | } |
331 | } |
313 | } |
332 | } |
|
|
333 | } |
|
|
334 | |
|
|
335 | void |
|
|
336 | layout::isolation_remover (int perturb) |
|
|
337 | { |
|
|
338 | layout dist (w - 2, h - 2); // map without border |
|
|
339 | |
|
|
340 | for (int x = 1; x < w - 1; ++x) |
|
|
341 | for (int y = 1; y < h - 1; ++y) |
|
|
342 | dist [x - 1][y - 1] = data [x][y] == '#' ? U8 (255) : 0; |
|
|
343 | |
|
|
344 | ::isolation_remover (dist, perturb); |
314 | |
345 | |
315 | // now copy the tunnels over |
346 | // now copy the tunnels over |
316 | for (int x = 0; x < w; ++x) |
347 | for (int x = 1; x < w - 1; ++x) |
317 | for (int y = 0; y < h; ++y) |
348 | for (int y = 1; y < h - 1; ++y) |
318 | if (data [x][y] == '#' && dist [x][y] == 1) |
349 | if (data [x][y] == '#' && dist [x - 1][y - 1] == 1) |
319 | data [x][y] = 0; |
350 | data [x][y] = 0; |
320 | } |
351 | } |
321 | |
352 | |
322 | ///////////////////////////////////////////////////////////////////////////// |
353 | ///////////////////////////////////////////////////////////////////////////// |
323 | |
354 | |
324 | // inspired mostly by http://www.jimrandomh.org/misc/caves.txt |
|
|
325 | void |
|
|
326 | layout::gen_cave (int subtype) |
|
|
327 | { |
|
|
328 | switch (subtype) |
|
|
329 | { |
|
|
330 | // a rough cave |
|
|
331 | case 0: |
|
|
332 | fill_rand (rmg_rndm (80, 95)); |
|
|
333 | break; |
|
|
334 | |
|
|
335 | // corridors |
|
|
336 | case 1: |
|
|
337 | fill_rand (rmg_rndm (5, 40)); |
|
|
338 | erode_1_2 (5, 2, 10); |
|
|
339 | erode_1_2 (5, -1, 10); |
|
|
340 | erode_1_2 (5, 2, 1); |
|
|
341 | break; |
|
|
342 | |
|
|
343 | // somewhat open, roundish |
|
|
344 | case 2: |
|
|
345 | fill_rand (45); |
|
|
346 | erode_1_2 (5, 0, 5); |
|
|
347 | erode_1_2 (5, 1, 1); |
|
|
348 | break; |
|
|
349 | |
|
|
350 | // wide open, some room-like structures |
|
|
351 | case 3: |
|
|
352 | fill_rand (45); |
|
|
353 | erode_1_2 (5, 2, 4); |
|
|
354 | erode_1_2 (5, -1, 3); |
|
|
355 | break; |
|
|
356 | } |
|
|
357 | |
|
|
358 | border (); |
|
|
359 | isolation_remover (); |
|
|
360 | } |
|
|
361 | |
|
|
362 | ///////////////////////////////////////////////////////////////////////////// |
|
|
363 | |
|
|
364 | //+GPL |
355 | //+GPL |
365 | |
356 | |
366 | /* puts doors at appropriate locations in a maze. */ |
357 | /* puts doors at appropriate locations in a maze. */ |
367 | void |
358 | void |
368 | layout::doorify () |
359 | layout::doorify () |
369 | { |
360 | { |
370 | int ndoors = w * h / 60; /* reasonable number of doors. */ |
361 | int ndoors = w * h / 60; /* reasonable number of doors. */ |
371 | int doorlocs = 0; /* # of available doorlocations */ |
|
|
372 | |
362 | |
373 | uint16 *doorlist_x = salloc<uint16> (w * h); |
363 | fixed_stack<point> doorloc (w * h); |
374 | uint16 *doorlist_y = salloc<uint16> (w * h); |
|
|
375 | |
364 | |
376 | /* make a list of possible door locations */ |
365 | /* make a list of possible door locations */ |
377 | for (int i = 1; i < w - 1; i++) |
366 | for (int i = 1; i < w - 1; i++) |
378 | for (int j = 1; j < h - 1; j++) |
367 | for (int j = 1; j < h - 1; j++) |
379 | { |
368 | { |
380 | int sindex = surround_flag (*this, i, j); |
369 | int sindex = surround_flag (*this, i, j); |
381 | |
370 | |
382 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
371 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
383 | { |
372 | doorloc.push (point (i, j)); |
384 | doorlist_x [doorlocs] = i; |
|
|
385 | doorlist_y [doorlocs] = j; |
|
|
386 | doorlocs++; |
|
|
387 | } |
|
|
388 | } |
373 | } |
389 | |
374 | |
390 | while (ndoors > 0 && doorlocs > 0) |
375 | while (ndoors && doorloc.size) |
391 | { |
376 | { |
392 | int di = rmg_rndm (doorlocs); |
377 | point p = doorloc.remove (rmg_rndm (doorloc.size)); |
393 | int i = doorlist_x [di]; |
378 | |
394 | int j = doorlist_y [di]; |
|
|
395 | int sindex = surround_flag (*this, i, j); |
379 | int sindex = surround_flag (*this, p.x, p.y); |
396 | |
380 | |
397 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
381 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
398 | { |
382 | { |
399 | data [i][j] = 'D'; |
383 | data [p.x][p.y] = 'D'; |
400 | ndoors--; |
384 | --ndoors; |
401 | } |
385 | } |
402 | |
|
|
403 | /* reduce the size of the list */ |
|
|
404 | doorlocs--; |
|
|
405 | doorlist_x[di] = doorlist_x [doorlocs]; |
|
|
406 | doorlist_y[di] = doorlist_y [doorlocs]; |
|
|
407 | } |
386 | } |
408 | |
|
|
409 | sfree (doorlist_x, w * h); |
|
|
410 | sfree (doorlist_y, w * h); |
|
|
411 | } |
387 | } |
412 | |
388 | |
413 | /* takes a map and makes it symmetric: adjusts Xsize and |
389 | /* takes a map and makes it symmetric: adjusts Xsize and |
414 | * Ysize to produce a symmetric map. |
390 | * Ysize to produce a symmetric map. |
415 | */ |
391 | */ |
… | |
… | |
784 | else |
760 | else |
785 | make_wall (*this, dx, dy, 1); |
761 | make_wall (*this, dx, dy, 1); |
786 | } |
762 | } |
787 | } |
763 | } |
788 | |
764 | |
|
|
765 | //-GPL |
|
|
766 | |
789 | ///////////////////////////////////////////////////////////////////////////// |
767 | ///////////////////////////////////////////////////////////////////////////// |
|
|
768 | |
|
|
769 | // inspired mostly by http://www.jimrandomh.org/misc/caves.txt |
|
|
770 | void |
|
|
771 | layout::gen_cave (int subtype) |
|
|
772 | { |
|
|
773 | switch (subtype) |
|
|
774 | { |
|
|
775 | // a rough cave |
|
|
776 | case 0: |
|
|
777 | fill_rand (rmg_rndm (85, 97)); |
|
|
778 | break; |
|
|
779 | |
|
|
780 | // corridors |
|
|
781 | case 1: |
|
|
782 | fill_rand (rmg_rndm (5, 40)); |
|
|
783 | erode_1_2 (5, 2, 10); |
|
|
784 | erode_1_2 (5, -1, 10); |
|
|
785 | erode_1_2 (5, 2, 1); |
|
|
786 | break; |
|
|
787 | |
|
|
788 | // somewhat open, some room-like structures |
|
|
789 | case 2: |
|
|
790 | fill_rand (45); |
|
|
791 | erode_1_2 (5, 2, 4); |
|
|
792 | erode_1_2 (5, -1, 3); |
|
|
793 | break; |
|
|
794 | |
|
|
795 | // wide open, roundish |
|
|
796 | case 3: |
|
|
797 | fill_rand (45); |
|
|
798 | erode_1_2 (5, 0, 5); |
|
|
799 | erode_1_2 (5, 1, 1); |
|
|
800 | break; |
|
|
801 | } |
|
|
802 | |
|
|
803 | border (); |
|
|
804 | isolation_remover (1); |
|
|
805 | } |
|
|
806 | |
|
|
807 | void |
|
|
808 | layout::gen_castle () |
|
|
809 | { |
|
|
810 | fill ('#'); |
|
|
811 | |
|
|
812 | for (int n = w * h / 30 + 1; n--; ) |
|
|
813 | { |
|
|
814 | int rw = rmg_rndm (6, 10); |
|
|
815 | int rh = rmg_rndm (6, 10); |
|
|
816 | |
|
|
817 | int rx = rmg_rndm (0, w - rw); |
|
|
818 | int ry = rmg_rndm (0, h - rh); |
|
|
819 | |
|
|
820 | rect (rx, ry, rx + rw, ry + rh, '#'); |
|
|
821 | fill_rect (rx + 1, ry + 1, rx + rw - 1, ry + rh - 1, 0); |
|
|
822 | } |
|
|
823 | |
|
|
824 | border (); |
|
|
825 | isolation_remover (0); |
|
|
826 | } |
|
|
827 | |
|
|
828 | static void |
|
|
829 | gen_mixed_ (layout &maze, random_map_params *RP, int dir) |
|
|
830 | { |
|
|
831 | if (maze.w < 20 && maze.h < 20 && !rmg_rndm (3)) |
|
|
832 | dir = 2; // stop recursion randomly |
|
|
833 | |
|
|
834 | if (dir == 0 && maze.w > 16) |
|
|
835 | { |
|
|
836 | int m = rmg_rndm (8, maze.w - 8); |
|
|
837 | |
|
|
838 | layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP, !dir); |
|
|
839 | layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP, !dir); |
|
|
840 | } |
|
|
841 | else if (dir == 1 && maze.h > 16) |
|
|
842 | { |
|
|
843 | int m = rmg_rndm (8, maze.h - 8); |
|
|
844 | |
|
|
845 | layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP, !dir); |
|
|
846 | layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP, !dir); |
|
|
847 | } |
|
|
848 | else |
|
|
849 | { |
|
|
850 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1; |
|
|
851 | |
|
|
852 | if (RP->map_layout_style == LAYOUT_MULTIPLE) |
|
|
853 | ++RP->map_layout_style; |
|
|
854 | |
|
|
855 | maze.generate (RP); |
|
|
856 | } |
|
|
857 | } |
|
|
858 | |
|
|
859 | // recursive subdivision with random sublayouts |
|
|
860 | static void |
|
|
861 | gen_mixed (layout &maze, random_map_params *RP) |
|
|
862 | { |
|
|
863 | random_map_params &rp = *new random_map_params (RP); |
|
|
864 | gen_mixed_ (maze, &rp, rmg_rndm (2)); |
|
|
865 | delete &rp; |
|
|
866 | |
|
|
867 | maze.border (); |
|
|
868 | maze.isolation_remover (0); |
|
|
869 | } |
|
|
870 | |
|
|
871 | //+GPL |
790 | |
872 | |
791 | /* function selects the maze function and gives it whatever |
873 | /* function selects the maze function and gives it whatever |
792 | arguments it needs. */ |
874 | arguments it needs. */ |
793 | void |
875 | void |
794 | layout::generate (random_map_params *RP) |
876 | layout::generate (random_map_params *RP) |
… | |
… | |
854 | if (rmg_rndm (2)) |
936 | if (rmg_rndm (2)) |
855 | doorify (); |
937 | doorify (); |
856 | |
938 | |
857 | break; |
939 | break; |
858 | |
940 | |
|
|
941 | case LAYOUT_CASTLE: |
|
|
942 | gen_castle (); |
|
|
943 | |
|
|
944 | if (rmg_rndm (2)) |
|
|
945 | doorify (); |
|
|
946 | |
|
|
947 | break; |
|
|
948 | |
|
|
949 | case LAYOUT_MULTIPLE: |
|
|
950 | gen_mixed (*this, RP); |
|
|
951 | break; |
|
|
952 | |
859 | default: |
953 | default: |
860 | abort (); |
954 | abort (); |
861 | } |
955 | } |
|
|
956 | } |
862 | |
957 | |
863 | /* rotate the maze randomly */ |
958 | //-GPL |
864 | rotate (rmg_rndm (4)); |
|
|
865 | |
|
|
866 | symmetrize (RP->symmetry_used); |
|
|
867 | |
959 | |
868 | #if 0 |
960 | #if 0 |
869 | print ();//D |
961 | static void |
870 | #endif |
962 | gen_village (layout &maze) |
|
|
963 | { |
|
|
964 | maze.clear (); |
|
|
965 | maze.border (); |
871 | |
966 | |
872 | if (RP->expand2x) |
967 | for (int n = maze.w * maze.h / 200 + 1; n--; ) |
873 | expand2x (); |
968 | { |
874 | } |
969 | int rw = rmg_rndm (6, 10); |
|
|
970 | int rh = rmg_rndm (6, 10); |
875 | |
971 | |
876 | //-GPL |
972 | int rx = rmg_rndm (2, maze.w - rw - 2); |
|
|
973 | int ry = rmg_rndm (2, maze.h - rh - 2); |
877 | |
974 | |
878 | #if 0 |
975 | maze.rect (rx, ry, rx + rw, ry + rh, '#'); |
|
|
976 | } |
|
|
977 | |
|
|
978 | maze.border (); |
|
|
979 | maze.isolation_remover (2); |
|
|
980 | } |
|
|
981 | |
879 | static struct demo |
982 | static struct demo |
880 | { |
983 | { |
881 | demo () |
984 | demo () |
882 | { |
985 | { |
883 | rmg_rndm.seed (time (0)); |
986 | rmg_rndm.seed (time (0)); |
884 | |
987 | |
885 | for(int i=1;i<10;i) |
988 | for(int i=1;i<100;i++) |
886 | { |
989 | { |
887 | layout maze (10, 10); |
990 | layout maze (40, 30); |
888 | maze.fill_rand (90); |
991 | gen_village (maze); |
889 | maze.border (); |
|
|
890 | maze.isolation_remover (); |
|
|
891 | maze.doorify (); |
992 | maze.doorify (); |
892 | maze.symmetrize (rmg_rndm (2, 4)); |
|
|
893 | maze.rotate (rmg_rndm (4)); |
|
|
894 | maze.expand2x (); |
|
|
895 | maze.print (); |
993 | maze.print (); |
|
|
994 | exit(0); |
896 | } |
995 | } |
897 | |
996 | |
898 | exit (1); |
997 | exit (1); |
899 | } |
998 | } |
900 | } demo; |
999 | } demo; |