ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/layout.C
(Generate patch)

Comparing deliantra/server/random_maps/layout.C (file contents):
Revision 1.7 by root, Fri Jul 2 15:03:57 2010 UTC vs.
Revision 1.23 by root, Sun Jul 4 22:12:26 2010 UTC

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
28void
29layout::alloc (int w, int h)
30{
31 assert (sizeof (cell) == 1);
32
33 this->w = w;
34 this->h = h;
35
36 // we store the layout in a single contiguous memory layout
37 // first part consists of pointers to each column, followed
38 // by the actual columns (not rows!)
39 size = (sizeof (cell *) + sizeof (cell) * h) * w;
40 data = (cell **)salloc<char> (size);
41
42 cell *p = (cell *)(data + w);
43
44 for (int x = 0; x < w; ++x)
45 data [x] = p + x * h;
46}
47
28layout::layout (int w, int h) 48layout::layout (int w, int h)
29: w(w), h(h)
30{ 49{
31 int size = (sizeof (char *) + sizeof (char) * h) * w; 50 alloc (w, h);
51}
32 52
53layout::layout (layout &copy)
54{
55 alloc (copy.w, copy.h);
56
57 memcpy (data [0], copy.data [0], sizeof (cell) * h * w);
58}
59
60layout::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;
33 col = (char **)salloc<char> (size); 67 data = (cell **)salloc<char> (size);
34 68
35 char *data = (char *)(col + w); 69 // and now we point back into the original layout
36
37 for (int x = w; x--; ) 70 for (int x = 0; x < w; ++x)
38 col [x] = data + x * h; 71 data [x] = orig.data [x + x1] + y1;
39} 72}
40 73
41layout::~layout () 74layout::~layout ()
42{ 75{
43 int size = (sizeof (char *) + sizeof (char) * h) * w;
44
45 sfree ((char *)col, size); 76 sfree ((char *)data, size);
46} 77}
47 78
48void 79void
49layout::fill (char fill) 80layout::fill (char fill)
50{ 81{
51 memset (col [0], fill, w * h); 82 //memset (data [0], fill, w * h); // only when contiguous :/
83 fill_rect (0, 0, w, h, fill);
52} 84}
53 85
54void 86void
55layout::rect (int x1, int y1, int x2, int y2, char fill) 87layout::rect (int x1, int y1, int x2, int y2, char fill)
56{ 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
98void
99layout::fill_rect (int x1, int y1, int x2, int y2, char fill)
100{
57 for (; x1 < x2; ++x1) 101 for (; x1 < x2; ++x1)
58 memset (col [x1] + y1, fill, y2 - y1); 102 memset (data [x1] + y1, fill, y2 - y1);
59} 103}
60 104
61void layout::border (char fill) 105void layout::border (char fill)
62{ 106{
63 for (int i = 0; i < w; i++) col [i][0] = col [i][h - 1] = fill; 107 rect (0, 0, w, h, fill);
64 for (int j = 0; j < h; j++) col [0][j] = col [w - 1][j] = fill;
65} 108}
66 109
67void 110void
68layout::fill_rand (int percent) 111layout::fill_rand (int percent)
69{ 112{
70 percent = lerp (percent, 0, 100, 0, 256); 113 percent = lerp (percent, 0, 100, 0, 256);
71 114
72 for (int x = w - 1; --x > 0; ) 115 for (int x = 0; x < w; ++x)
73 for (int y = h - 1; --y > 0; ) 116 for (int y = 0; y < h; ++y)
74 col [x][y] = rmg_rndm (256) > percent ? 0 : '#'; 117 data [x][y] = rmg_rndm (256) > percent ? 0 : '#';
75} 118}
76 119
77///////////////////////////////////////////////////////////////////////////// 120/////////////////////////////////////////////////////////////////////////////
78 121
79// erode by cellular automata 122// erode by cellular automata
104 for (int i = array_length (dds); i--; ) 147 for (int i = array_length (dds); i--; )
105 { 148 {
106 int nx = x + dds [i][0]; 149 int nx = x + dds [i][0];
107 int ny = y + dds [i][1]; 150 int ny = y + dds [i][1];
108 151
109 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !col [nx][ny]) 152 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !data [nx][ny])
110 { 153 {
111 n1 += dds [i][2]; 154 n1 += dds [i][2];
112 n2++; 155 n2++;
113 } 156 }
114 } 157 }
128{ 171{
129 for (int y = 0; y < h; y++) 172 for (int y = 0; y < h; y++)
130 { 173 {
131 for (int x = 0; x < w; x++) 174 for (int x = 0; x < w; x++)
132 { 175 {
133 U8 c = (U8)col [x][y]; 176 U8 c = (U8)data [x][y];
134 177
135 if (!c) 178 if (!c)
136 c = ' '; 179 c = ' ';
137 else if (c < 10) 180 else if (c < 10)
138 c += '0'; 181 c += '0';
151///////////////////////////////////////////////////////////////////////////// 194/////////////////////////////////////////////////////////////////////////////
152// isolation remover - ensures single connected area 195// isolation remover - ensures single connected area
153 196
154typedef fixed_stack<point> pointlist; 197typedef fixed_stack<point> pointlist;
155 198
156static noinline void 199static void noinline
157push_flood_fill (layout &dist, pointlist &seeds, int x, int y) 200push_flood_fill (layout &dist, pointlist &seeds, int x, int y)
158{ 201{
159 if (dist [x][y]) 202 if (dist [x][y])
160 return; 203 return;
161 204
172 ++y; 215 ++y;
173 } 216 }
174 217
175 while (--y >= y0) 218 while (--y >= y0)
176 { 219 {
177 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);
178 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);
179 } 222 }
180} 223}
181 224
182static inline void 225static inline void
183make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d) 226make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d, int perturb)
184{ 227{
185 for (;;) 228 for (;;)
186 { 229 {
230 point neigh[4];
231 int ncnt = 0;
232
233 d += perturb > 1;
234
187 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);
188 --x;
189 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);
190 ++x;
191 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);
192 --y;
193 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);
194 ++y; 239
195 else 240 if (!ncnt)
196 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;
197 249
198 d = dist [x][y]; 250 d = dist [x][y];
199 dist [x][y] = 1; 251 dist [x][y] = 1;
200 seeds.push (point (x, y));
201 } 252 }
202} 253}
203 254
204static void inline 255static void inline
205maybe_push (layout &dist, pointlist &seeds, int x, int y, U8 d) 256maybe_push (layout &dist, pointlist &seeds, int x, int y, U8 d)
212 return; 263 return;
213 264
214 seeds.push (point (x, y)); 265 seeds.push (point (x, y));
215} 266}
216 267
217void 268// isolation remover, works on a "distance" map
218layout::isolation_remover (bool dirty) 269// the map must be initialised with 0 == rooms, 255 = walls
270static void noinline
271isolation_remover (layout &dist, unsigned int perturb = 2)
219{ 272{
220 layout dist (w, h);
221
222 // dist contains 273 // dist contains
223 // 0 == invisited rooms 274 // 0 == invisited rooms
224 // 1 == visited rooms 275 // 1 == visited rooms
225 // 2+ shortest distance to random near room 276 // 2+ shortest distance to random near room
226 277
227 // phase 1, initialise dist array, find seed 278 clamp_it (perturb, 0, 2);
279
280 // phase 1, find seed
228 int cnt = 0; 281 int cnt = 0;
229 int x, y; 282 int x, y;
230 283
231 for (int i = 0; i < w; ++i) 284 for (int i = 0; i < dist.w; ++i)
232 for (int j = 0; j < h; ++j) 285 for (int j = 0; j < dist.h; ++j)
233 { 286 if (!dist [i][j] && !rmg_rndm (++cnt))
234 if (col [i][j] == '#')
235 dist [i][j] = U8 (255);
236 else
237 {
238 dist [i][j] = 0;
239 if (!rmg_rndm (++cnt))
240 x = i, y = j; 287 x = i, y = j;
241 }
242 }
243 288
244 if (!cnt) 289 if (!cnt)
245 { 290 {
246 // map is completely massive, this is not good, 291 // map is completely massive, this is not good,
247 // so make it empty instead. 292 // so make it empty instead.
248 clear (); 293 dist.fill (1);
249 border ();
250 return; 294 return;
251 } 295 }
252 296
253 fixed_stack<point> seeds (w * h * 5); 297 fixed_stack<point> seeds (dist.w * dist.h * 5);
254 298
255 // found first free space - picking the first one gives 299 // found first free space - picking the first one gives
256 // us a slight bias for tunnels, but usually you won't 300 // us a slight bias for tunnels, but usually you won't
257 // notice that in-game 301 // notice that in-game
258 seeds.push (point (x, y)); 302 seeds.push (point (x, y));
270 y = p.y; 314 y = p.y;
271 315
272 if (!dist [x][y]) 316 if (!dist [x][y])
273 { 317 {
274 // found new isolated area, make tunnel 318 // found new isolated area, make tunnel
275 if (!dirty)
276 push_flood_fill (dist, seeds, x, y); 319 push_flood_fill (dist, seeds, x, y);
277
278 make_tunnel (dist, seeds, x, y, 255); 320 make_tunnel (dist, seeds, x, y, 254, perturb);
279
280 if (dirty)
281 push_flood_fill (dist, seeds, x, y);
282 } 321 }
283 else 322 else
284 { 323 {
285 // nothing here, continue to expand 324 // nothing here, continue to expand
286 U8 d = U8 (dist [x][y]) + 1; 325 U8 d = U8 (dist [x][y]) + 1;
289 if (x > 0) maybe_push (dist, seeds, x - 1, y, d); 328 if (x > 0) maybe_push (dist, seeds, x - 1, y, d);
290 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);
291 if (y > 0) maybe_push (dist, seeds, x, y - 1, d); 330 if (y > 0) maybe_push (dist, seeds, x, y - 1, d);
292 } 331 }
293 } 332 }
333}
334
335void
336layout::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);
294 345
295 // now copy the tunnels over 346 // now copy the tunnels over
296 for (int x = 0; x < w; ++x) 347 for (int x = 1; x < w - 1; ++x)
297 for (int y = 0; y < h; ++y) 348 for (int y = 1; y < h - 1; ++y)
298 if (col [x][y] == '#' && dist [x][y] == 1) 349 if (data [x][y] == '#' && dist [x - 1][y - 1] == 1)
299 col [x][y] = 0; 350 data [x][y] = 0;
300} 351}
301 352
302///////////////////////////////////////////////////////////////////////////// 353/////////////////////////////////////////////////////////////////////////////
303 354
304// inspired mostly by http://www.jimrandomh.org/misc/caves.txt
305void
306layout::gen_cave (int subtype)
307{
308 switch (subtype)
309 {
310 // a rough cave
311 case 0:
312 fill_rand (rmg_rndm (80, 95));
313 break;
314
315 // corridors
316 case 1:
317 fill_rand (rmg_rndm (5, 40));
318 erode_1_2 (5, 2, 10);
319 erode_1_2 (5, -1, 10);
320 erode_1_2 (5, 2, 1);
321 break;
322
323 // somewhat open, roundish
324 case 2:
325 fill_rand (45);
326 erode_1_2 (5, 0, 5);
327 erode_1_2 (5, 1, 1);
328 break;
329
330 // wide open, some room-like structures
331 case 3:
332 fill_rand (45);
333 erode_1_2 (5, 2, 4);
334 erode_1_2 (5, -1, 3);
335 break;
336 }
337
338 border ();
339 isolation_remover ();
340}
341
342/////////////////////////////////////////////////////////////////////////////
343
344//+GPL 355//+GPL
345 356
346/* puts doors at appropriate locations in a maze. */ 357/* puts doors at appropriate locations in a maze. */
347void 358void
348layout::doorify () 359layout::doorify ()
349{ 360{
350 int ndoors = w * h / 60; /* reasonable number of doors. */ 361 int ndoors = w * h / 60; /* reasonable number of doors. */
351 int doorlocs = 0; /* # of available doorlocations */
352 362
353 uint16 *doorlist_x = salloc<uint16> (w * h); 363 fixed_stack<point> doorloc (w * h);
354 uint16 *doorlist_y = salloc<uint16> (w * h);
355 364
356 /* make a list of possible door locations */ 365 /* make a list of possible door locations */
357 for (int i = 1; i < w - 1; i++) 366 for (int i = 1; i < w - 1; i++)
358 for (int j = 1; j < h - 1; j++) 367 for (int j = 1; j < h - 1; j++)
359 { 368 {
360 int sindex = surround_flag (*this, i, j); 369 int sindex = surround_flag (*this, i, j);
361 370
362 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 371 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
363 { 372 doorloc.push (point (i, j));
364 doorlist_x [doorlocs] = i;
365 doorlist_y [doorlocs] = j;
366 doorlocs++;
367 }
368 } 373 }
369 374
370 while (ndoors > 0 && doorlocs > 0) 375 while (ndoors && doorloc.size)
371 { 376 {
372 int di = rmg_rndm (doorlocs); 377 point p = doorloc.remove (rmg_rndm (doorloc.size));
373 int i = doorlist_x [di]; 378
374 int j = doorlist_y [di];
375 int sindex = surround_flag (*this, i, j); 379 int sindex = surround_flag (*this, p.x, p.y);
376 380
377 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 381 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
378 { 382 {
379 col [i][j] = 'D'; 383 data [p.x][p.y] = 'D';
380 ndoors--; 384 --ndoors;
381 } 385 }
382
383 /* reduce the size of the list */
384 doorlocs--;
385 doorlist_x[di] = doorlist_x [doorlocs];
386 doorlist_y[di] = doorlist_y [doorlocs];
387 } 386 }
388
389 sfree (doorlist_x, w * h);
390 sfree (doorlist_y, w * h);
391} 387}
392 388
393/* takes a map and makes it symmetric: adjusts Xsize and 389/* takes a map and makes it symmetric: adjusts Xsize and
394 * Ysize to produce a symmetric map. 390 * Ysize to produce a symmetric map.
395 */ 391 */
407 if (symmetry == SYMMETRY_X) 403 if (symmetry == SYMMETRY_X)
408 for (int i = 0; i < sym_layout.w / 2 + 1; i++) 404 for (int i = 0; i < sym_layout.w / 2 + 1; i++)
409 for (int j = 0; j < sym_layout.h; j++) 405 for (int j = 0; j < sym_layout.h; j++)
410 { 406 {
411 sym_layout[i ][j] = 407 sym_layout[i ][j] =
412 sym_layout[sym_layout.w - i - 1][j] = col[i][j]; 408 sym_layout[sym_layout.w - i - 1][j] = data [i][j];
413 } 409 }
414 410
415 if (symmetry == SYMMETRY_Y) 411 if (symmetry == SYMMETRY_Y)
416 for (int i = 0; i < sym_layout.w; i++) 412 for (int i = 0; i < sym_layout.w; i++)
417 for (int j = 0; j < sym_layout.h / 2 + 1; j++) 413 for (int j = 0; j < sym_layout.h / 2 + 1; j++)
418 { 414 {
419 sym_layout[i][j ] = 415 sym_layout[i][j ] =
420 sym_layout[i][sym_layout.h - j - 1] = col[i][j]; 416 sym_layout[i][sym_layout.h - j - 1] = data [i][j];
421 } 417 }
422 418
423 if (symmetry == SYMMETRY_XY) 419 if (symmetry == SYMMETRY_XY)
424 for (int i = 0; i < sym_layout.w / 2 + 1; i++) 420 for (int i = 0; i < sym_layout.w / 2 + 1; i++)
425 for (int j = 0; j < sym_layout.h / 2 + 1; j++) 421 for (int j = 0; j < sym_layout.h / 2 + 1; j++)
426 { 422 {
427 sym_layout[i ][j ] = 423 sym_layout[i ][j ] =
428 sym_layout[i ][sym_layout.h - j - 1] = 424 sym_layout[i ][sym_layout.h - j - 1] =
429 sym_layout[sym_layout.w - i - 1][j ] = 425 sym_layout[sym_layout.w - i - 1][j ] =
430 sym_layout[sym_layout.w - i - 1][sym_layout.h - j - 1] = col[i][j]; 426 sym_layout[sym_layout.w - i - 1][sym_layout.h - j - 1] = data [i][j];
431 } 427 }
432 428
433 /* need to run the isolation remover for some layouts */ 429 /* need to run the isolation remover for some layouts */
434#if 0 430#if 0
435 switch (RP->map_layout_style) 431 switch (RP->map_layout_style)
461 { 457 {
462 layout new_layout (w, h); 458 layout new_layout (w, h);
463 459
464 for (int i = 0; i < w; i++) /* copy a reflection back */ 460 for (int i = 0; i < w; i++) /* copy a reflection back */
465 for (int j = 0; j < h; j++) 461 for (int j = 0; j < h; j++)
466 new_layout [i][j] = col [w - i - 1][h - j - 1]; 462 new_layout [i][j] = data [w - i - 1][h - j - 1];
467 463
468 swap (new_layout); 464 swap (new_layout);
469 } 465 }
470 break; 466 break;
471 467
475 layout new_layout (h, w); 471 layout new_layout (h, w);
476 472
477 if (rotation == 1) /* swap x and y */ 473 if (rotation == 1) /* swap x and y */
478 for (int i = 0; i < w; i++) 474 for (int i = 0; i < w; i++)
479 for (int j = 0; j < h; j++) 475 for (int j = 0; j < h; j++)
480 new_layout [j][i] = col [i][j]; 476 new_layout [j][i] = data [i][j];
481 477
482 if (rotation == 3) /* swap x and y */ 478 if (rotation == 3) /* swap x and y */
483 for (int i = 0; i < w; i++) 479 for (int i = 0; i < w; i++)
484 for (int j = 0; j < h; j++) 480 for (int j = 0; j < h; j++)
485 new_layout [j][i] = col [w - i - 1][h - j - 1]; 481 new_layout [j][i] = data [w - i - 1][h - j - 1];
486 482
487 swap (new_layout); 483 swap (new_layout);
488 } 484 }
489 break; 485 break;
490 } 486 }
616 612
617 new_layout.clear (); 613 new_layout.clear ();
618 614
619 for (int i = 0; i < w; i++) 615 for (int i = 0; i < w; i++)
620 for (int j = 0; j < h; j++) 616 for (int j = 0; j < h; j++)
621 switch (col [i][j]) 617 switch (data [i][j])
622 { 618 {
623 case '#': expand_wall (new_layout, i, j, *this); break; 619 case '#': expand_wall (new_layout, i, j, *this); break;
624 case 'D': expand_door (new_layout, i, j, *this); break; 620 case 'D': expand_door (new_layout, i, j, *this); break;
625 default: expand_misc (new_layout, i, j, *this); break; 621 default: expand_misc (new_layout, i, j, *this); break;
626 } 622 }
705 701
706 return -1; 702 return -1;
707} 703}
708 704
709int 705int
710make_wall (char **maze, int x, int y, int dir) 706make_wall (layout &maze, int x, int y, int dir)
711{ 707{
712 maze[x][y] = 'D'; /* mark a door */ 708 maze[x][y] = 'D'; /* mark a door */
713 709
714 switch (dir) 710 switch (dir)
715 { 711 {
764 else 760 else
765 make_wall (*this, dx, dy, 1); 761 make_wall (*this, dx, dy, 1);
766 } 762 }
767} 763}
768 764
765//-GPL
766
769///////////////////////////////////////////////////////////////////////////// 767/////////////////////////////////////////////////////////////////////////////
768
769// inspired mostly by http://www.jimrandomh.org/misc/caves.txt
770void
771layout::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
807void
808layout::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
831static void
832gen_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
860static void
861gen_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
770 872
771/* function selects the maze function and gives it whatever 873/* function selects the maze function and gives it whatever
772 arguments it needs. */ 874 arguments it needs. */
773void 875void
774layout::generate (random_map_params *RP) 876layout::generate (random_map_params *RP)
834 if (rmg_rndm (2)) 936 if (rmg_rndm (2))
835 doorify (); 937 doorify ();
836 938
837 break; 939 break;
838 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
839 default: 953 default:
840 abort (); 954 abort ();
841 } 955 }
956}
842 957
843 /* rotate the maze randomly */ 958//-GPL
844 rotate (rmg_rndm (4));
845
846 symmetrize (RP->symmetry_used);
847 959
848#if 0 960#if 0
849 print ();//D 961static void
850#endif 962gen_village (layout &maze)
963{
964 maze.clear ();
965 maze.border ();
851 966
852 if (RP->expand2x) 967 for (int n = maze.w * maze.h / 200 + 1; n--; )
853 expand2x (); 968 {
854} 969 int rw = rmg_rndm (6, 10);
970 int rh = rmg_rndm (6, 10);
855 971
856//-GPL 972 int rx = rmg_rndm (2, maze.w - rw - 2);
973 int ry = rmg_rndm (2, maze.h - rh - 2);
857 974
858#if 0 975 maze.rect (rx, ry, rx + rw, ry + rh, '#');
976 }
977
978 maze.border ();
979 maze.isolation_remover (2);
980}
981
859static struct demo 982static struct demo
860{ 983{
861 demo () 984 demo ()
862 { 985 {
863 rmg_rndm.seed (time (0)); 986 rmg_rndm.seed (time (0));
864 987
865 for(int i=1;i<10;i) 988 for(int i=1;i<100;i++)
866 { 989 {
867 layout maze (10, 10); 990 layout maze (40, 30);
868 maze.fill_rand (90); 991 gen_village (maze);
869 maze.border ();
870 maze.isolation_remover ();
871 maze.doorify (); 992 maze.doorify ();
872 maze.symmetrize (rmg_rndm (2, 4));
873 maze.rotate (rmg_rndm (4));
874 maze.expand2x ();
875 maze.print (); 993 maze.print ();
994 exit(0);
876 } 995 }
877 996
878 exit (1); 997 exit (1);
879 } 998 }
880} demo; 999} demo;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines