… | |
… | |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <random_map.h> |
25 | #include <random_map.h> |
26 | #include <rproto.h> |
26 | #include <rproto.h> |
27 | |
27 | |
28 | void |
28 | void noinline |
29 | layout::alloc (int w, int h) |
29 | layout::alloc (int w, int h) |
30 | { |
30 | { |
31 | assert (sizeof (cell) == 1); |
31 | assert (sizeof (cell) == 1); |
32 | |
32 | |
33 | this->w = w; |
33 | this->w = w; |
… | |
… | |
74 | layout::~layout () |
74 | layout::~layout () |
75 | { |
75 | { |
76 | sfree ((char *)data, size); |
76 | sfree ((char *)data, size); |
77 | } |
77 | } |
78 | |
78 | |
79 | void |
79 | void noinline |
80 | layout::fill (char fill) |
80 | layout::fill (char fill) |
81 | { |
81 | { |
82 | //memset (data [0], fill, w * h); // only when contiguous :/ |
82 | //memset (data [0], fill, w * h); // only when contiguous :/ |
83 | fill_rect (0, 0, w, h, fill); |
83 | fill_rect (0, 0, w, h, fill); |
84 | } |
84 | } |
85 | |
85 | |
86 | void |
86 | void noinline |
|
|
87 | layout::replace (char from, char to) |
|
|
88 | { |
|
|
89 | for (int x = 0; x < w; ++x) |
|
|
90 | for (int y = 0; y < h; ++y) |
|
|
91 | if (data [x][y] == from) |
|
|
92 | data [x][y] = to; |
|
|
93 | } |
|
|
94 | |
|
|
95 | void noinline |
87 | layout::rect (int x1, int y1, int x2, int y2, char fill) |
96 | layout::rect (int x1, int y1, int x2, int y2, char fill) |
88 | { |
97 | { |
89 | --x2; |
98 | --x2; |
90 | |
99 | |
91 | memset (data [x1] + y1, fill, y2 - y1); |
100 | memset (data [x1] + y1, fill, y2 - y1); |
… | |
… | |
93 | |
102 | |
94 | while (++x1 < x2) |
103 | while (++x1 < x2) |
95 | data [x1][y1] = data [x1][y2 - 1] = fill; |
104 | data [x1][y1] = data [x1][y2 - 1] = fill; |
96 | } |
105 | } |
97 | |
106 | |
98 | void |
107 | void noinline |
99 | layout::fill_rect (int x1, int y1, int x2, int y2, char fill) |
108 | layout::fill_rect (int x1, int y1, int x2, int y2, char fill) |
100 | { |
109 | { |
101 | for (; x1 < x2; ++x1) |
110 | for (; x1 < x2; ++x1) |
102 | memset (data [x1] + y1, fill, y2 - y1); |
111 | memset (data [x1] + y1, fill, y2 - y1); |
103 | } |
112 | } |
104 | |
113 | |
|
|
114 | void |
105 | void layout::border (char fill) |
115 | layout::border (char fill) |
106 | { |
116 | { |
107 | rect (0, 0, w, h, fill); |
117 | rect (0, 0, w, h, fill); |
108 | } |
118 | } |
109 | |
119 | |
110 | void |
120 | void noinline |
111 | layout::fill_rand (int percent) |
121 | layout::fill_rand (int percent) |
112 | { |
122 | { |
113 | percent = lerp (percent, 0, 100, 0, 256); |
123 | percent = lerp (percent, 0, 100, 0, 256); |
114 | |
124 | |
115 | for (int x = w - 1; --x > 0; ) |
125 | for (int x = 0; x < w; ++x) |
116 | for (int y = h - 1; --y > 0; ) |
126 | for (int y = 0; y < h; ++y) |
117 | data [x][y] = rmg_rndm (256) > percent ? 0 : '#'; |
127 | data [x][y] = rmg_rndm (256) > percent ? 0 : '#'; |
118 | } |
128 | } |
119 | |
129 | |
120 | ///////////////////////////////////////////////////////////////////////////// |
130 | ///////////////////////////////////////////////////////////////////////////// |
121 | |
131 | |
122 | // erode by cellular automata |
132 | // erode by cellular automata |
123 | void |
133 | void noinline |
124 | layout::erode_1_2 (int c1, int c2, int repeat) |
134 | layout::erode_1_2 (int c1, int c2, int repeat) |
125 | { |
135 | { |
126 | layout neu (w, h); |
136 | layout neu (w, h); |
127 | |
137 | |
128 | while (repeat--) |
138 | while (repeat--) |
… | |
… | |
220 | if (x > 0 && !dist [x - 1][y]) push_flood_fill (dist, seeds, x - 1, y); |
230 | if (x > 0 && !dist [x - 1][y]) 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); |
231 | if (x < dist.w - 1 && !dist [x + 1][y]) push_flood_fill (dist, seeds, x + 1, y); |
222 | } |
232 | } |
223 | } |
233 | } |
224 | |
234 | |
225 | static inline void |
235 | static void inline |
226 | make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d) |
236 | make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d, int perturb) |
227 | { |
237 | { |
228 | for (;;) |
238 | for (;;) |
229 | { |
239 | { |
230 | point neigh[4]; |
240 | point neigh[4]; |
231 | int ncnt = 0; |
241 | int ncnt = 0; |
232 | |
242 | |
|
|
243 | d += perturb > 1; |
|
|
244 | |
233 | if (x > 0 && U8 (dist [x - 1][y]) <= d && dist [x - 1][y] > 1) neigh [ncnt++] = point (x - 1, y); |
245 | if (x > 0 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1) neigh [ncnt++] = point (x - 1, y); |
234 | if (x < dist.w - 1 && U8 (dist [x + 1][y]) <= d && dist [x + 1][y] > 1) neigh [ncnt++] = point (x + 1, y); |
246 | if (x < dist.w - 1 && U8 (dist [x + 1][y]) < d && dist [x + 1][y] > 1) neigh [ncnt++] = point (x + 1, y); |
235 | if (y > 0 && U8 (dist [x][y - 1]) <= d && dist [x][y - 1] > 1) neigh [ncnt++] = point (x, y - 1); |
247 | if (y > 0 && U8 (dist [x][y - 1]) < d && dist [x][y - 1] > 1) neigh [ncnt++] = point (x, y - 1); |
236 | if (y < dist.h - 1 && U8 (dist [x][y + 1]) <= d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); |
248 | if (y < dist.h - 1 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); |
237 | |
249 | |
238 | if (!ncnt) |
250 | if (!ncnt) |
239 | return; |
251 | return; |
240 | |
252 | |
241 | point &p = neigh [rmg_rndm (ncnt)]; |
253 | point p = neigh [perturb ? rmg_rndm (ncnt) : 0]; |
242 | |
254 | |
243 | seeds.push (p); |
255 | seeds.push (p); |
244 | |
256 | |
245 | x = p.x; |
257 | x = p.x; |
246 | y = p.y; |
258 | y = p.y; |
… | |
… | |
264 | } |
276 | } |
265 | |
277 | |
266 | // isolation remover, works on a "distance" map |
278 | // isolation remover, works on a "distance" map |
267 | // the map must be initialised with 0 == rooms, 255 = walls |
279 | // the map must be initialised with 0 == rooms, 255 = walls |
268 | static void noinline |
280 | static void noinline |
269 | isolation_remover (layout &dist) |
281 | isolation_remover (layout &dist, unsigned int perturb = 2) |
270 | { |
282 | { |
271 | // dist contains |
283 | // dist contains |
272 | // 0 == invisited rooms |
284 | // 0 == invisited rooms |
273 | // 1 == visited rooms |
285 | // 1 == visited rooms |
274 | // 2+ shortest distance to random near room |
286 | // 2+ shortest distance to random near room |
275 | |
287 | |
|
|
288 | clamp_it (perturb, 0, 2); |
|
|
289 | |
276 | // phase 1, find seed |
290 | // phase 1, find seed |
277 | int cnt = 0; |
291 | int cnt = 0; |
278 | int x, y; |
292 | int x, y; |
279 | |
293 | |
280 | for (int i = 0; i < dist.w; ++i) |
294 | for (int i = 0; i < dist.w; ++i) |
… | |
… | |
311 | |
325 | |
312 | if (!dist [x][y]) |
326 | if (!dist [x][y]) |
313 | { |
327 | { |
314 | // found new isolated area, make tunnel |
328 | // found new isolated area, make tunnel |
315 | push_flood_fill (dist, seeds, x, y); |
329 | push_flood_fill (dist, seeds, x, y); |
316 | make_tunnel (dist, seeds, x, y, 255); |
330 | make_tunnel (dist, seeds, x, y, 254, perturb); |
317 | } |
331 | } |
318 | else |
332 | else |
319 | { |
333 | { |
320 | // nothing here, continue to expand |
334 | // nothing here, continue to expand |
321 | U8 d = U8 (dist [x][y]) + 1; |
335 | U8 d = U8 (dist [x][y]) + 1; |
… | |
… | |
327 | } |
341 | } |
328 | } |
342 | } |
329 | } |
343 | } |
330 | |
344 | |
331 | void |
345 | void |
332 | layout::isolation_remover () |
346 | layout::isolation_remover (int perturb) |
333 | { |
347 | { |
334 | layout dist (w - 2, h - 2); // map without border |
348 | layout dist (w - 2, h - 2); // map without border |
335 | |
349 | |
336 | for (int x = 1; x < w - 1; ++x) |
350 | for (int x = 1; x < w - 1; ++x) |
337 | for (int y = 1; y < h - 1; ++y) |
351 | for (int y = 1; y < h - 1; ++y) |
338 | dist [x - 1][y - 1] = data [x][y] == '#' ? U8 (255) : 0; |
352 | dist [x - 1][y - 1] = data [x][y] == '#' ? U8 (255) : 0; |
339 | |
353 | |
340 | ::isolation_remover (dist); |
354 | ::isolation_remover (dist, perturb); |
341 | |
355 | |
342 | // now copy the tunnels over |
356 | // now copy the tunnels over |
343 | for (int x = 1; x < w - 1; ++x) |
357 | for (int x = 1; x < w - 1; ++x) |
344 | for (int y = 1; y < h - 1; ++y) |
358 | for (int y = 1; y < h - 1; ++y) |
345 | if (data [x][y] == '#' && dist [x - 1][y - 1] == 1) |
359 | if (data [x][y] == '#' && dist [x - 1][y - 1] == 1) |
… | |
… | |
353 | /* puts doors at appropriate locations in a maze. */ |
367 | /* puts doors at appropriate locations in a maze. */ |
354 | void |
368 | void |
355 | layout::doorify () |
369 | layout::doorify () |
356 | { |
370 | { |
357 | int ndoors = w * h / 60; /* reasonable number of doors. */ |
371 | int ndoors = w * h / 60; /* reasonable number of doors. */ |
358 | int doorlocs = 0; /* # of available doorlocations */ |
|
|
359 | |
372 | |
360 | uint16 *doorlist_x = salloc<uint16> (w * h); |
373 | coroapi::cede_to_tick (); |
361 | uint16 *doorlist_y = salloc<uint16> (w * h); |
374 | |
|
|
375 | fixed_stack<point> doorloc (w * h); |
362 | |
376 | |
363 | /* make a list of possible door locations */ |
377 | /* make a list of possible door locations */ |
364 | for (int i = 1; i < w - 1; i++) |
378 | for (int i = 1; i < w - 1; i++) |
365 | for (int j = 1; j < h - 1; j++) |
379 | for (int j = 1; j < h - 1; j++) |
366 | { |
380 | { |
367 | int sindex = surround_flag (*this, i, j); |
381 | int sindex = surround_flag (*this, i, j); |
368 | |
382 | |
369 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
383 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
370 | { |
384 | doorloc.push (point (i, j)); |
371 | doorlist_x [doorlocs] = i; |
|
|
372 | doorlist_y [doorlocs] = j; |
|
|
373 | doorlocs++; |
|
|
374 | } |
|
|
375 | } |
385 | } |
376 | |
386 | |
377 | while (ndoors > 0 && doorlocs > 0) |
387 | while (ndoors && doorloc.size) |
378 | { |
388 | { |
379 | int di = rmg_rndm (doorlocs); |
389 | point p = doorloc.remove (rmg_rndm (doorloc.size)); |
380 | int i = doorlist_x [di]; |
390 | |
381 | int j = doorlist_y [di]; |
|
|
382 | int sindex = surround_flag (*this, i, j); |
391 | int sindex = surround_flag (*this, p.x, p.y); |
383 | |
392 | |
384 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
393 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
385 | { |
394 | { |
386 | data [i][j] = 'D'; |
395 | data [p.x][p.y] = 'D'; |
387 | ndoors--; |
396 | --ndoors; |
388 | } |
397 | } |
389 | |
|
|
390 | /* reduce the size of the list */ |
|
|
391 | doorlocs--; |
|
|
392 | doorlist_x[di] = doorlist_x [doorlocs]; |
|
|
393 | doorlist_y[di] = doorlist_y [doorlocs]; |
|
|
394 | } |
398 | } |
395 | |
|
|
396 | sfree (doorlist_x, w * h); |
|
|
397 | sfree (doorlist_y, w * h); |
|
|
398 | } |
399 | } |
399 | |
400 | |
400 | /* takes a map and makes it symmetric: adjusts Xsize and |
401 | /* takes a map and makes it symmetric: adjusts Xsize and |
401 | * Ysize to produce a symmetric map. |
402 | * Ysize to produce a symmetric map. |
402 | */ |
403 | */ |
… | |
… | |
460 | //-GPL |
461 | //-GPL |
461 | |
462 | |
462 | void |
463 | void |
463 | layout::rotate (int rotation) |
464 | layout::rotate (int rotation) |
464 | { |
465 | { |
|
|
466 | coroapi::cede_to_tick (); |
|
|
467 | |
465 | switch (rotation & 3) |
468 | switch (rotation & 3) |
466 | { |
469 | { |
467 | case 2: /* a reflection */ |
470 | case 2: /* a reflection */ |
468 | { |
471 | { |
469 | layout new_layout (w, h); |
472 | layout new_layout (w, h); |
… | |
… | |
621 | { |
624 | { |
622 | layout new_layout (w * 2 - 1, h * 2 - 1); |
625 | layout new_layout (w * 2 - 1, h * 2 - 1); |
623 | |
626 | |
624 | new_layout.clear (); |
627 | new_layout.clear (); |
625 | |
628 | |
|
|
629 | coroapi::cede_to_tick (); |
|
|
630 | |
626 | for (int i = 0; i < w; i++) |
631 | for (int i = 0; i < w; i++) |
627 | for (int j = 0; j < h; j++) |
632 | for (int j = 0; j < h; j++) |
628 | switch (data [i][j]) |
633 | switch (data [i][j]) |
629 | { |
634 | { |
630 | case '#': expand_wall (new_layout, i, j, *this); break; |
635 | case '#': expand_wall (new_layout, i, j, *this); break; |
… | |
… | |
712 | |
717 | |
713 | return -1; |
718 | return -1; |
714 | } |
719 | } |
715 | |
720 | |
716 | int |
721 | int |
717 | make_wall (char **maze, int x, int y, int dir) |
722 | make_wall (layout &maze, int x, int y, int dir) |
718 | { |
723 | { |
719 | maze[x][y] = 'D'; /* mark a door */ |
724 | maze[x][y] = 'D'; /* mark a door */ |
720 | |
725 | |
721 | switch (dir) |
726 | switch (dir) |
722 | { |
727 | { |
… | |
… | |
739 | |
744 | |
740 | void |
745 | void |
741 | layout::roomify () |
746 | layout::roomify () |
742 | { |
747 | { |
743 | int tries = w * h / 30; |
748 | int tries = w * h / 30; |
|
|
749 | |
|
|
750 | coroapi::cede_to_tick (); |
744 | |
751 | |
745 | for (int ti = 0; ti < tries; ti++) |
752 | for (int ti = 0; ti < tries; ti++) |
746 | { |
753 | { |
747 | /* starting location for looking at creating a door */ |
754 | /* starting location for looking at creating a door */ |
748 | int dx = rmg_rndm (w); |
755 | int dx = rmg_rndm (w); |
… | |
… | |
770 | make_wall (*this, dx, dy, 0); |
777 | make_wall (*this, dx, dy, 0); |
771 | else |
778 | else |
772 | make_wall (*this, dx, dy, 1); |
779 | make_wall (*this, dx, dy, 1); |
773 | } |
780 | } |
774 | } |
781 | } |
|
|
782 | |
|
|
783 | //-GPL |
775 | |
784 | |
776 | ///////////////////////////////////////////////////////////////////////////// |
785 | ///////////////////////////////////////////////////////////////////////////// |
777 | |
786 | |
778 | // inspired mostly by http://www.jimrandomh.org/misc/caves.txt |
787 | // inspired mostly by http://www.jimrandomh.org/misc/caves.txt |
779 | void |
788 | void |
… | |
… | |
792 | erode_1_2 (5, 2, 10); |
801 | erode_1_2 (5, 2, 10); |
793 | erode_1_2 (5, -1, 10); |
802 | erode_1_2 (5, -1, 10); |
794 | erode_1_2 (5, 2, 1); |
803 | erode_1_2 (5, 2, 1); |
795 | break; |
804 | break; |
796 | |
805 | |
797 | // somewhat open, roundish |
806 | // somewhat open, some room-like structures |
798 | case 2: |
807 | case 2: |
|
|
808 | fill_rand (45); |
|
|
809 | erode_1_2 (5, 2, 4); |
|
|
810 | erode_1_2 (5, -1, 3); |
|
|
811 | break; |
|
|
812 | |
|
|
813 | // wide open, roundish |
|
|
814 | case 3: |
799 | fill_rand (45); |
815 | fill_rand (45); |
800 | erode_1_2 (5, 0, 5); |
816 | erode_1_2 (5, 0, 5); |
801 | erode_1_2 (5, 1, 1); |
817 | erode_1_2 (5, 1, 1); |
802 | break; |
818 | break; |
803 | |
|
|
804 | // wide open, some room-like structures |
|
|
805 | case 3: |
|
|
806 | fill_rand (45); |
|
|
807 | erode_1_2 (5, 2, 4); |
|
|
808 | erode_1_2 (5, -1, 3); |
|
|
809 | break; |
|
|
810 | } |
819 | } |
811 | |
820 | |
812 | border (); |
821 | border (); |
813 | isolation_remover (); |
822 | isolation_remover (1); |
|
|
823 | } |
|
|
824 | |
|
|
825 | void |
|
|
826 | layout::gen_castle () |
|
|
827 | { |
|
|
828 | fill ('#'); |
|
|
829 | |
|
|
830 | for (int n = w * h / 30 + 1; n--; ) |
|
|
831 | { |
|
|
832 | int rw = rmg_rndm (6, 10); |
|
|
833 | int rh = rmg_rndm (6, 10); |
|
|
834 | |
|
|
835 | if (rw > w || rh > h) |
|
|
836 | continue; |
|
|
837 | |
|
|
838 | int rx = rmg_rndm (0, w - rw); |
|
|
839 | int ry = rmg_rndm (0, h - rh); |
|
|
840 | |
|
|
841 | rect (rx, ry, rx + rw, ry + rh, '#'); |
|
|
842 | fill_rect (rx + 1, ry + 1, rx + rw - 1, ry + rh - 1, 0); |
|
|
843 | } |
|
|
844 | |
|
|
845 | border (); |
|
|
846 | isolation_remover (0); |
814 | } |
847 | } |
815 | |
848 | |
816 | static void |
849 | static void |
817 | gen_mixed_ (layout &maze, random_map_params *RP, int dir) |
850 | gen_mixed_ (layout &maze, random_map_params *RP) |
818 | { |
851 | { |
819 | if (maze.w < 20 && maze.h < 20 && !rmg_rndm (3)) |
852 | if (maze.w > maze.h && maze.w > 16) |
820 | dir = 2; // stop recursion randomly |
|
|
821 | |
|
|
822 | if (dir == 0 && maze.w > 16) |
|
|
823 | { |
853 | { |
824 | int m = rmg_rndm (8, maze.w - 8); |
854 | int m = rmg_rndm (8, maze.w - 8); |
825 | |
855 | |
826 | layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP, !dir); |
856 | layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP); |
827 | layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP, !dir); |
857 | layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP); |
828 | } |
858 | } |
829 | else if (dir == 1 && maze.h > 16) |
859 | else if (maze.h > 16) |
830 | { |
860 | { |
831 | int m = rmg_rndm (8, maze.h - 8); |
861 | int m = rmg_rndm (8, maze.h - 8); |
832 | |
862 | |
833 | layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP, !dir); |
863 | layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP); |
834 | layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP, !dir); |
864 | layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP); |
835 | } |
865 | } |
836 | else |
866 | else |
837 | { |
867 | { |
838 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1; |
868 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1; |
839 | |
869 | |
840 | if (RP->map_layout_style == LAYOUT_MULTIPLE) |
870 | if (RP->map_layout_style == LAYOUT_MULTIPLE) |
841 | ++RP->map_layout_style; |
871 | ++RP->map_layout_style; |
842 | |
872 | |
843 | maze.generate (RP); |
873 | maze.generate (RP); |
844 | } |
874 | } |
|
|
875 | |
|
|
876 | coroapi::cede_to_tick (); |
845 | } |
877 | } |
846 | |
878 | |
847 | // recursive subdivision with random sublayouts |
879 | // recursive subdivision with random sublayouts |
848 | static void |
880 | static void |
849 | gen_mixed (layout &maze, random_map_params *RP) |
881 | gen_mixed (layout &maze, random_map_params *RP) |
850 | { |
882 | { |
851 | random_map_params &rp = *new random_map_params (RP); |
883 | random_map_params &rp = *new random_map_params (RP); |
852 | gen_mixed_ (maze, &rp, rmg_rndm (2)); |
884 | gen_mixed_ (maze, &rp); |
853 | delete &rp; |
885 | delete &rp; |
854 | |
886 | |
855 | maze.border (); |
887 | maze.border (); |
|
|
888 | |
|
|
889 | // exits currently do not work so well, as they |
|
|
890 | // are currently often found together, so nuke entrances |
|
|
891 | maze.replace ('<', ' '); |
|
|
892 | |
856 | maze.isolation_remover (); |
893 | maze.isolation_remover (0); |
857 | } |
894 | } |
|
|
895 | |
|
|
896 | //+GPL |
858 | |
897 | |
859 | /* function selects the maze function and gives it whatever |
898 | /* function selects the maze function and gives it whatever |
860 | arguments it needs. */ |
899 | arguments it needs. */ |
861 | void |
900 | void |
862 | layout::generate (random_map_params *RP) |
901 | layout::generate (random_map_params *RP) |
… | |
… | |
922 | if (rmg_rndm (2)) |
961 | if (rmg_rndm (2)) |
923 | doorify (); |
962 | doorify (); |
924 | |
963 | |
925 | break; |
964 | break; |
926 | |
965 | |
|
|
966 | case LAYOUT_CASTLE: |
|
|
967 | gen_castle (); |
|
|
968 | |
|
|
969 | if (rmg_rndm (2)) |
|
|
970 | doorify (); |
|
|
971 | |
|
|
972 | break; |
|
|
973 | |
927 | case LAYOUT_MULTIPLE: |
974 | case LAYOUT_MULTIPLE: |
928 | gen_mixed (*this, RP); |
975 | gen_mixed (*this, RP); |
929 | break; |
976 | break; |
930 | |
977 | |
931 | default: |
978 | default: |
… | |
… | |
934 | } |
981 | } |
935 | |
982 | |
936 | //-GPL |
983 | //-GPL |
937 | |
984 | |
938 | #if 0 |
985 | #if 0 |
|
|
986 | static void |
|
|
987 | gen_village (layout &maze) |
|
|
988 | { |
|
|
989 | maze.clear (); |
|
|
990 | maze.border (); |
|
|
991 | |
|
|
992 | for (int n = maze.w * maze.h / 200 + 1; n--; ) |
|
|
993 | { |
|
|
994 | int rw = rmg_rndm (6, 10); |
|
|
995 | int rh = rmg_rndm (6, 10); |
|
|
996 | |
|
|
997 | int rx = rmg_rndm (2, maze.w - rw - 2); |
|
|
998 | int ry = rmg_rndm (2, maze.h - rh - 2); |
|
|
999 | |
|
|
1000 | maze.rect (rx, ry, rx + rw, ry + rh, '#'); |
|
|
1001 | } |
|
|
1002 | |
|
|
1003 | maze.border (); |
|
|
1004 | maze.isolation_remover (2); |
|
|
1005 | } |
|
|
1006 | |
939 | static struct demo |
1007 | static struct demo |
940 | { |
1008 | { |
941 | demo () |
1009 | demo () |
942 | { |
1010 | { |
943 | rmg_rndm.seed (time (0)); |
1011 | rmg_rndm.seed (time (0)); |
944 | |
1012 | |
945 | for(int i=1;i<100;i++) |
1013 | for(int i=1;i<100;i++) |
946 | { |
1014 | { |
947 | layout maze (40, 25); |
1015 | layout maze (40, 30); |
948 | maze.fill_rand (85); |
1016 | gen_village (maze); |
949 | maze.border (); |
1017 | maze.doorify (); |
950 | maze.isolation_remover (); |
|
|
951 | maze.print (); |
1018 | maze.print (); |
|
|
1019 | exit(0); |
952 | } |
1020 | } |
953 | |
1021 | |
954 | exit (1); |
1022 | exit (1); |
955 | } |
1023 | } |
956 | } demo; |
1024 | } demo; |