… | |
… | |
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 | layout::layout (int w, int h) |
29 | layout::alloc (int w, int h) |
29 | : w(w), h(h) |
|
|
30 | { |
30 | { |
31 | assert (sizeof (cell) == 1); |
31 | assert (sizeof (cell) == 1); |
|
|
32 | |
|
|
33 | this->w = w; |
|
|
34 | this->h = h; |
32 | |
35 | |
33 | // we store the layout in a single contiguous memory layout |
36 | // we store the layout in a single contiguous memory layout |
34 | // first part consists of pointers to each column, followed |
37 | // first part consists of pointers to each column, followed |
35 | // by the actual columns (not rows!) |
38 | // by the actual columns (not rows!) |
36 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
39 | size = (sizeof (cell *) + sizeof (cell) * h) * w; |
37 | |
|
|
38 | data = (cell **)salloc<char> (size); |
40 | data = (cell **)salloc<char> (size); |
39 | |
41 | |
40 | cell *p = (cell *)(data + w); |
42 | cell *p = (cell *)(data + w); |
41 | |
43 | |
42 | for (int x = w; x--; ) |
44 | for (int x = 0; x < w; ++x) |
43 | data [x] = p + x * h; |
45 | data [x] = p + x * h; |
44 | } |
46 | } |
45 | |
47 | |
|
|
48 | layout::layout (int w, int h) |
|
|
49 | { |
|
|
50 | alloc (w, h); |
|
|
51 | } |
|
|
52 | |
|
|
53 | layout::layout (layout ©) |
|
|
54 | { |
|
|
55 | alloc (copy.w, copy.h); |
|
|
56 | |
|
|
57 | memcpy (data [0], copy.data [0], sizeof (cell) * h * w); |
|
|
58 | } |
|
|
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 | |
46 | layout::~layout () |
74 | layout::~layout () |
47 | { |
75 | { |
48 | int size = (sizeof (cell *) + sizeof (cell) * h) * w; |
|
|
49 | |
|
|
50 | sfree ((char *)data, size); |
76 | sfree ((char *)data, size); |
51 | } |
77 | } |
52 | |
78 | |
53 | void |
79 | void |
54 | layout::fill (char fill) |
80 | layout::fill (char fill) |
55 | { |
81 | { |
56 | memset (data [0], fill, w * h); |
82 | //memset (data [0], fill, w * h); // only when contiguous :/ |
|
|
83 | fill_rect (0, 0, w, h, fill); |
57 | } |
84 | } |
58 | |
85 | |
59 | void |
86 | void |
60 | 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) |
61 | { |
100 | { |
62 | for (; x1 < x2; ++x1) |
101 | for (; x1 < x2; ++x1) |
63 | memset (data [x1] + y1, fill, y2 - y1); |
102 | memset (data [x1] + y1, fill, y2 - y1); |
64 | } |
103 | } |
65 | |
104 | |
66 | void layout::border (char fill) |
105 | void layout::border (char fill) |
67 | { |
106 | { |
68 | for (int i = 0; i < w; i++) data [i][0] = data [i][h - 1] = fill; |
107 | rect (0, 0, w, h, fill); |
69 | for (int j = 0; j < h; j++) data [0][j] = data [w - 1][j] = fill; |
|
|
70 | } |
108 | } |
71 | |
109 | |
72 | void |
110 | void |
73 | layout::fill_rand (int percent) |
111 | layout::fill_rand (int percent) |
74 | { |
112 | { |
… | |
… | |
156 | ///////////////////////////////////////////////////////////////////////////// |
194 | ///////////////////////////////////////////////////////////////////////////// |
157 | // isolation remover - ensures single connected area |
195 | // isolation remover - ensures single connected area |
158 | |
196 | |
159 | typedef fixed_stack<point> pointlist; |
197 | typedef fixed_stack<point> pointlist; |
160 | |
198 | |
161 | static noinline void |
199 | static void noinline |
162 | push_flood_fill (layout &dist, pointlist &seeds, int x, int y) |
200 | push_flood_fill (layout &dist, pointlist &seeds, int x, int y) |
163 | { |
201 | { |
164 | if (dist [x][y]) |
202 | if (dist [x][y]) |
165 | return; |
203 | return; |
166 | |
204 | |
… | |
… | |
177 | ++y; |
215 | ++y; |
178 | } |
216 | } |
179 | |
217 | |
180 | while (--y >= y0) |
218 | while (--y >= y0) |
181 | { |
219 | { |
182 | 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); |
183 | 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); |
184 | } |
222 | } |
185 | } |
223 | } |
186 | |
224 | |
187 | static inline void |
225 | static inline void |
188 | 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) |
189 | { |
227 | { |
190 | for (;;) |
228 | for (;;) |
191 | { |
229 | { |
|
|
230 | point neigh[4]; |
|
|
231 | int ncnt = 0; |
|
|
232 | |
|
|
233 | d += perturb > 1; |
|
|
234 | |
192 | 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); |
193 | --x; |
|
|
194 | 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); |
195 | ++x; |
|
|
196 | 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); |
197 | --y; |
|
|
198 | 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); |
199 | ++y; |
239 | |
200 | else |
240 | if (!ncnt) |
201 | 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; |
202 | |
249 | |
203 | d = dist [x][y]; |
250 | d = dist [x][y]; |
204 | dist [x][y] = 1; |
251 | dist [x][y] = 1; |
205 | seeds.push (point (x, y)); |
|
|
206 | } |
252 | } |
207 | } |
253 | } |
208 | |
254 | |
209 | static void inline |
255 | static void inline |
210 | 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) |
… | |
… | |
217 | return; |
263 | return; |
218 | |
264 | |
219 | seeds.push (point (x, y)); |
265 | seeds.push (point (x, y)); |
220 | } |
266 | } |
221 | |
267 | |
222 | void |
268 | // isolation remover, works on a "distance" map |
223 | 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) |
224 | { |
272 | { |
225 | layout dist (w, h); |
|
|
226 | |
|
|
227 | // dist contains |
273 | // dist contains |
228 | // 0 == invisited rooms |
274 | // 0 == invisited rooms |
229 | // 1 == visited rooms |
275 | // 1 == visited rooms |
230 | // 2+ shortest distance to random near room |
276 | // 2+ shortest distance to random near room |
231 | |
277 | |
232 | // phase 1, initialise dist array, find seed |
278 | clamp_it (perturb, 0, 2); |
|
|
279 | |
|
|
280 | // phase 1, find seed |
233 | int cnt = 0; |
281 | int cnt = 0; |
234 | int x, y; |
282 | int x, y; |
235 | |
283 | |
236 | for (int i = 0; i < w; ++i) |
284 | for (int i = 0; i < dist.w; ++i) |
237 | for (int j = 0; j < h; ++j) |
285 | for (int j = 0; j < dist.h; ++j) |
238 | { |
286 | if (!dist [i][j] && !rmg_rndm (++cnt)) |
239 | if (data [i][j] == '#') |
|
|
240 | dist [i][j] = U8 (255); |
|
|
241 | else |
|
|
242 | { |
|
|
243 | dist [i][j] = 0; |
|
|
244 | if (!rmg_rndm (++cnt)) |
|
|
245 | x = i, y = j; |
287 | x = i, y = j; |
246 | } |
|
|
247 | } |
|
|
248 | |
288 | |
249 | if (!cnt) |
289 | if (!cnt) |
250 | { |
290 | { |
251 | // map is completely massive, this is not good, |
291 | // map is completely massive, this is not good, |
252 | // so make it empty instead. |
292 | // so make it empty instead. |
253 | clear (); |
293 | dist.fill (1); |
254 | border (); |
|
|
255 | return; |
294 | return; |
256 | } |
295 | } |
257 | |
296 | |
258 | fixed_stack<point> seeds (w * h * 5); |
297 | fixed_stack<point> seeds (dist.w * dist.h * 5); |
259 | |
298 | |
260 | // found first free space - picking the first one gives |
299 | // found first free space - picking the first one gives |
261 | // us a slight bias for tunnels, but usually you won't |
300 | // us a slight bias for tunnels, but usually you won't |
262 | // notice that in-game |
301 | // notice that in-game |
263 | seeds.push (point (x, y)); |
302 | seeds.push (point (x, y)); |
… | |
… | |
275 | y = p.y; |
314 | y = p.y; |
276 | |
315 | |
277 | if (!dist [x][y]) |
316 | if (!dist [x][y]) |
278 | { |
317 | { |
279 | // found new isolated area, make tunnel |
318 | // found new isolated area, make tunnel |
280 | if (!dirty) |
|
|
281 | push_flood_fill (dist, seeds, x, y); |
319 | push_flood_fill (dist, seeds, x, y); |
282 | |
|
|
283 | make_tunnel (dist, seeds, x, y, 255); |
320 | make_tunnel (dist, seeds, x, y, 254, perturb); |
284 | |
|
|
285 | if (dirty) |
|
|
286 | push_flood_fill (dist, seeds, x, y); |
|
|
287 | } |
321 | } |
288 | else |
322 | else |
289 | { |
323 | { |
290 | // nothing here, continue to expand |
324 | // nothing here, continue to expand |
291 | U8 d = U8 (dist [x][y]) + 1; |
325 | U8 d = U8 (dist [x][y]) + 1; |
… | |
… | |
294 | if (x > 0) maybe_push (dist, seeds, x - 1, y, d); |
328 | if (x > 0) maybe_push (dist, seeds, x - 1, y, d); |
295 | 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); |
296 | if (y > 0) maybe_push (dist, seeds, x, y - 1, d); |
330 | if (y > 0) maybe_push (dist, seeds, x, y - 1, d); |
297 | } |
331 | } |
298 | } |
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); |
299 | |
345 | |
300 | // now copy the tunnels over |
346 | // now copy the tunnels over |
301 | for (int x = 0; x < w; ++x) |
347 | for (int x = 1; x < w - 1; ++x) |
302 | for (int y = 0; y < h; ++y) |
348 | for (int y = 1; y < h - 1; ++y) |
303 | if (data [x][y] == '#' && dist [x][y] == 1) |
349 | if (data [x][y] == '#' && dist [x - 1][y - 1] == 1) |
304 | data [x][y] = 0; |
350 | data [x][y] = 0; |
305 | } |
351 | } |
306 | |
352 | |
307 | ///////////////////////////////////////////////////////////////////////////// |
353 | ///////////////////////////////////////////////////////////////////////////// |
308 | |
354 | |
309 | // inspired mostly by http://www.jimrandomh.org/misc/caves.txt |
|
|
310 | void |
|
|
311 | layout::gen_cave (int subtype) |
|
|
312 | { |
|
|
313 | switch (subtype) |
|
|
314 | { |
|
|
315 | // a rough cave |
|
|
316 | case 0: |
|
|
317 | fill_rand (rmg_rndm (80, 95)); |
|
|
318 | break; |
|
|
319 | |
|
|
320 | // corridors |
|
|
321 | case 1: |
|
|
322 | fill_rand (rmg_rndm (5, 40)); |
|
|
323 | erode_1_2 (5, 2, 10); |
|
|
324 | erode_1_2 (5, -1, 10); |
|
|
325 | erode_1_2 (5, 2, 1); |
|
|
326 | break; |
|
|
327 | |
|
|
328 | // somewhat open, roundish |
|
|
329 | case 2: |
|
|
330 | fill_rand (45); |
|
|
331 | erode_1_2 (5, 0, 5); |
|
|
332 | erode_1_2 (5, 1, 1); |
|
|
333 | break; |
|
|
334 | |
|
|
335 | // wide open, some room-like structures |
|
|
336 | case 3: |
|
|
337 | fill_rand (45); |
|
|
338 | erode_1_2 (5, 2, 4); |
|
|
339 | erode_1_2 (5, -1, 3); |
|
|
340 | break; |
|
|
341 | } |
|
|
342 | |
|
|
343 | border (); |
|
|
344 | isolation_remover (); |
|
|
345 | } |
|
|
346 | |
|
|
347 | ///////////////////////////////////////////////////////////////////////////// |
|
|
348 | |
|
|
349 | //+GPL |
355 | //+GPL |
350 | |
356 | |
351 | /* puts doors at appropriate locations in a maze. */ |
357 | /* puts doors at appropriate locations in a maze. */ |
352 | void |
358 | void |
353 | layout::doorify () |
359 | layout::doorify () |
354 | { |
360 | { |
355 | int ndoors = w * h / 60; /* reasonable number of doors. */ |
361 | int ndoors = w * h / 60; /* reasonable number of doors. */ |
356 | int doorlocs = 0; /* # of available doorlocations */ |
|
|
357 | |
362 | |
358 | uint16 *doorlist_x = salloc<uint16> (w * h); |
363 | fixed_stack<point> doorloc (w * h); |
359 | uint16 *doorlist_y = salloc<uint16> (w * h); |
|
|
360 | |
364 | |
361 | /* make a list of possible door locations */ |
365 | /* make a list of possible door locations */ |
362 | for (int i = 1; i < w - 1; i++) |
366 | for (int i = 1; i < w - 1; i++) |
363 | for (int j = 1; j < h - 1; j++) |
367 | for (int j = 1; j < h - 1; j++) |
364 | { |
368 | { |
365 | int sindex = surround_flag (*this, i, j); |
369 | int sindex = surround_flag (*this, i, j); |
366 | |
370 | |
367 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
371 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
368 | { |
372 | doorloc.push (point (i, j)); |
369 | doorlist_x [doorlocs] = i; |
|
|
370 | doorlist_y [doorlocs] = j; |
|
|
371 | doorlocs++; |
|
|
372 | } |
|
|
373 | } |
373 | } |
374 | |
374 | |
375 | while (ndoors > 0 && doorlocs > 0) |
375 | while (ndoors && doorloc.size) |
376 | { |
376 | { |
377 | int di = rmg_rndm (doorlocs); |
377 | point p = doorloc.remove (rmg_rndm (doorloc.size)); |
378 | int i = doorlist_x [di]; |
378 | |
379 | int j = doorlist_y [di]; |
|
|
380 | int sindex = surround_flag (*this, i, j); |
379 | int sindex = surround_flag (*this, p.x, p.y); |
381 | |
380 | |
382 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
381 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
383 | { |
382 | { |
384 | data [i][j] = 'D'; |
383 | data [p.x][p.y] = 'D'; |
385 | ndoors--; |
384 | --ndoors; |
386 | } |
385 | } |
387 | |
|
|
388 | /* reduce the size of the list */ |
|
|
389 | doorlocs--; |
|
|
390 | doorlist_x[di] = doorlist_x [doorlocs]; |
|
|
391 | doorlist_y[di] = doorlist_y [doorlocs]; |
|
|
392 | } |
386 | } |
393 | |
|
|
394 | sfree (doorlist_x, w * h); |
|
|
395 | sfree (doorlist_y, w * h); |
|
|
396 | } |
387 | } |
397 | |
388 | |
398 | /* takes a map and makes it symmetric: adjusts Xsize and |
389 | /* takes a map and makes it symmetric: adjusts Xsize and |
399 | * Ysize to produce a symmetric map. |
390 | * Ysize to produce a symmetric map. |
400 | */ |
391 | */ |
… | |
… | |
769 | else |
760 | else |
770 | make_wall (*this, dx, dy, 1); |
761 | make_wall (*this, dx, dy, 1); |
771 | } |
762 | } |
772 | } |
763 | } |
773 | |
764 | |
|
|
765 | //-GPL |
|
|
766 | |
774 | ///////////////////////////////////////////////////////////////////////////// |
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 | if (rw > w || rh > h) |
|
|
818 | continue; |
|
|
819 | |
|
|
820 | int rx = rmg_rndm (0, w - rw); |
|
|
821 | int ry = rmg_rndm (0, h - rh); |
|
|
822 | |
|
|
823 | rect (rx, ry, rx + rw, ry + rh, '#'); |
|
|
824 | fill_rect (rx + 1, ry + 1, rx + rw - 1, ry + rh - 1, 0); |
|
|
825 | } |
|
|
826 | |
|
|
827 | border (); |
|
|
828 | isolation_remover (0); |
|
|
829 | } |
|
|
830 | |
|
|
831 | static void |
|
|
832 | gen_mixed_ (layout &maze, random_map_params *RP) |
|
|
833 | { |
|
|
834 | if (maze.w > maze.h && 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); |
|
|
839 | layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP); |
|
|
840 | } |
|
|
841 | else if (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); |
|
|
846 | layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP); |
|
|
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); |
|
|
865 | delete &rp; |
|
|
866 | |
|
|
867 | maze.border (); |
|
|
868 | maze.isolation_remover (0); |
|
|
869 | } |
|
|
870 | |
|
|
871 | //+GPL |
775 | |
872 | |
776 | /* function selects the maze function and gives it whatever |
873 | /* function selects the maze function and gives it whatever |
777 | arguments it needs. */ |
874 | arguments it needs. */ |
778 | void |
875 | void |
779 | layout::generate (random_map_params *RP) |
876 | layout::generate (random_map_params *RP) |
… | |
… | |
839 | if (rmg_rndm (2)) |
936 | if (rmg_rndm (2)) |
840 | doorify (); |
937 | doorify (); |
841 | |
938 | |
842 | break; |
939 | break; |
843 | |
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 | |
844 | default: |
953 | default: |
845 | abort (); |
954 | abort (); |
846 | } |
955 | } |
|
|
956 | } |
847 | |
957 | |
848 | /* rotate the maze randomly */ |
958 | //-GPL |
849 | rotate (rmg_rndm (4)); |
|
|
850 | |
|
|
851 | symmetrize (RP->symmetry_used); |
|
|
852 | |
959 | |
853 | #if 0 |
960 | #if 0 |
854 | print ();//D |
961 | static void |
855 | #endif |
962 | gen_village (layout &maze) |
|
|
963 | { |
|
|
964 | maze.clear (); |
|
|
965 | maze.border (); |
856 | |
966 | |
857 | if (RP->expand2x) |
967 | for (int n = maze.w * maze.h / 200 + 1; n--; ) |
858 | expand2x (); |
968 | { |
859 | } |
969 | int rw = rmg_rndm (6, 10); |
|
|
970 | int rh = rmg_rndm (6, 10); |
860 | |
971 | |
861 | //-GPL |
972 | int rx = rmg_rndm (2, maze.w - rw - 2); |
|
|
973 | int ry = rmg_rndm (2, maze.h - rh - 2); |
862 | |
974 | |
863 | #if 0 |
975 | maze.rect (rx, ry, rx + rw, ry + rh, '#'); |
|
|
976 | } |
|
|
977 | |
|
|
978 | maze.border (); |
|
|
979 | maze.isolation_remover (2); |
|
|
980 | } |
|
|
981 | |
864 | static struct demo |
982 | static struct demo |
865 | { |
983 | { |
866 | demo () |
984 | demo () |
867 | { |
985 | { |
868 | rmg_rndm.seed (time (0)); |
986 | rmg_rndm.seed (time (0)); |
869 | |
987 | |
870 | for(int i=1;i<10;i) |
988 | for(int i=1;i<100;i++) |
871 | { |
989 | { |
872 | layout maze (10, 10); |
990 | layout maze (40, 30); |
873 | maze.fill_rand (90); |
991 | gen_village (maze); |
874 | maze.border (); |
|
|
875 | maze.isolation_remover (); |
|
|
876 | maze.doorify (); |
992 | maze.doorify (); |
877 | maze.symmetrize (rmg_rndm (2, 4)); |
|
|
878 | maze.rotate (rmg_rndm (4)); |
|
|
879 | maze.expand2x (); |
|
|
880 | maze.print (); |
993 | maze.print (); |
|
|
994 | exit(0); |
881 | } |
995 | } |
882 | |
996 | |
883 | exit (1); |
997 | exit (1); |
884 | } |
998 | } |
885 | } demo; |
999 | } demo; |