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.6 by root, Fri Jul 2 04:05:15 2010 UTC vs.
Revision 1.9 by root, Fri Jul 2 17:18:04 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
28Layout::Layout (int w, int h) 29layout::alloc (int w, int h)
29: w(w), h(h)
30{ 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!)
31 int size = (sizeof (char *) + sizeof (char) * h) * w; 39 int size = (sizeof (cell *) + sizeof (cell) * h) * w;
32 40
33 col = (char **)salloc<char> (size); 41 data = (cell **)salloc<char> (size);
34 42
35 char *data = (char *)(col + w); 43 cell *p = (cell *)(data + w);
36 44
37 for (int x = w; x--; ) 45 for (int x = w; x--; )
38 col [x] = data + x * h; 46 data [x] = p + x * h;
39} 47}
40 48
49layout::layout (int w, int h)
50{
51 alloc (w, h);
52}
53
54layout::layout (layout &copy)
55{
56 alloc (copy.w, copy.h);
57
58 memcpy (data [0], copy.data [0], sizeof (cell) * h * w);
59}
60
41Layout::~Layout () 61layout::~layout ()
42{ 62{
43 int size = (sizeof (char *) + sizeof (char) * h) * w; 63 int size = (sizeof (cell *) + sizeof (cell) * h) * w;
44 64
45 sfree ((char *)col, size); 65 sfree ((char *)data, size);
46} 66}
47 67
48void 68void
49Layout::fill (char fill) 69layout::fill (char fill)
50{ 70{
51 memset (col [0], fill, w * h); 71 memset (data [0], fill, w * h);
52} 72}
53 73
54void 74void
55Layout::rect (int x1, int y1, int x2, int y2, char fill) 75layout::rect (int x1, int y1, int x2, int y2, char fill)
56{ 76{
57 for (; x1 < x2; ++x1) 77 for (; x1 < x2; ++x1)
58 memset (col [x1] + y1, fill, y2 - y1); 78 memset (data [x1] + y1, fill, y2 - y1);
59} 79}
60 80
61void Layout::border (char fill) 81void layout::border (char fill)
62{ 82{
63 for (int i = 0; i < w; i++) col [i][0] = col [i][h - 1] = fill; 83 for (int i = 0; i < w; i++) data [i][0] = data [i][h - 1] = fill;
64 for (int j = 0; j < h; j++) col [0][j] = col [w - 1][j] = fill; 84 for (int j = 0; j < h; j++) data [0][j] = data [w - 1][j] = fill;
65} 85}
66 86
67void 87void
68Layout::fill_rand (int percent) 88layout::fill_rand (int percent)
69{ 89{
70 percent = lerp (percent, 0, 100, 0, 256); 90 percent = lerp (percent, 0, 100, 0, 256);
71 91
72 for (int x = w - 1; --x > 0; ) 92 for (int x = w - 1; --x > 0; )
73 for (int y = h - 1; --y > 0; ) 93 for (int y = h - 1; --y > 0; )
74 col [x][y] = rmg_rndm (256) > percent ? 0 : '#'; 94 data [x][y] = rmg_rndm (256) > percent ? 0 : '#';
75} 95}
76 96
77///////////////////////////////////////////////////////////////////////////// 97/////////////////////////////////////////////////////////////////////////////
78 98
79// erode by cellular automata 99// erode by cellular automata
80void 100void
81Layout::erode_1_2 (int c1, int c2, int repeat) 101layout::erode_1_2 (int c1, int c2, int repeat)
82{ 102{
83 Layout neu (w, h); 103 layout neu (w, h);
84 104
85 while (repeat--) 105 while (repeat--)
86 { 106 {
87 for (int x = 0; x < w; ++x) 107 for (int x = 0; x < w; ++x)
88 { 108 {
104 for (int i = array_length (dds); i--; ) 124 for (int i = array_length (dds); i--; )
105 { 125 {
106 int nx = x + dds [i][0]; 126 int nx = x + dds [i][0];
107 int ny = y + dds [i][1]; 127 int ny = y + dds [i][1];
108 128
109 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !col [nx][ny]) 129 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !data [nx][ny])
110 { 130 {
111 n1 += dds [i][2]; 131 n1 += dds [i][2];
112 n2++; 132 n2++;
113 } 133 }
114 } 134 }
122} 142}
123 143
124///////////////////////////////////////////////////////////////////////////// 144/////////////////////////////////////////////////////////////////////////////
125 145
126void 146void
127Layout::print () const 147layout::print () const
128{ 148{
129 for (int y = 0; y < h; y++) 149 for (int y = 0; y < h; y++)
130 { 150 {
131 for (int x = 0; x < w; x++) 151 for (int x = 0; x < w; x++)
132 { 152 {
133 U8 c = (U8)col [x][y]; 153 U8 c = (U8)data [x][y];
134 154
135 if (!c) 155 if (!c)
136 c = ' '; 156 c = ' ';
137 else if (c < 10) 157 else if (c < 10)
138 c += '0'; 158 c += '0';
152// isolation remover - ensures single connected area 172// isolation remover - ensures single connected area
153 173
154typedef fixed_stack<point> pointlist; 174typedef fixed_stack<point> pointlist;
155 175
156static noinline void 176static noinline void
157push_flood_fill (Layout &dist, pointlist &seeds, int x, int y) 177push_flood_fill (layout &dist, pointlist &seeds, int x, int y)
158{ 178{
159 if (dist [x][y]) 179 if (dist [x][y])
160 return; 180 return;
161 181
162 while (y > 0 && !dist [x][y - 1]) 182 while (y > 0 && !dist [x][y - 1])
178 if (x < dist.w - 1) push_flood_fill (dist, seeds, x + 1, y); 198 if (x < dist.w - 1) push_flood_fill (dist, seeds, x + 1, y);
179 } 199 }
180} 200}
181 201
182static inline void 202static inline void
183make_tunnel (Layout &dist, pointlist &seeds, int x, int y, U8 d) 203make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d)
184{ 204{
185 for (;;) 205 for (;;)
186 { 206 {
187 if (x > 1 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1) 207 if (x > 1 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1)
188 --x; 208 --x;
200 seeds.push (point (x, y)); 220 seeds.push (point (x, y));
201 } 221 }
202} 222}
203 223
204static void inline 224static void inline
205maybe_push (Layout &dist, pointlist &seeds, int x, int y, U8 d) 225maybe_push (layout &dist, pointlist &seeds, int x, int y, U8 d)
206{ 226{
207 char &D = dist [x][y]; 227 char &D = dist [x][y];
208 228
209 if (U8 (D) > d) // if wall and higher distance, lower distance 229 if (U8 (D) > d) // if wall and higher distance, lower distance
210 D = d; 230 D = d;
213 233
214 seeds.push (point (x, y)); 234 seeds.push (point (x, y));
215} 235}
216 236
217void 237void
218Layout::isolation_remover (bool dirty) 238layout::isolation_remover (bool dirty)
219{ 239{
220 Layout dist (w, h); 240 layout dist (w, h);
221 241
222 // dist contains 242 // dist contains
223 // 0 == invisited rooms 243 // 0 == invisited rooms
224 // 1 == visited rooms 244 // 1 == visited rooms
225 // 2+ shortest distance to random near room 245 // 2+ shortest distance to random near room
229 int x, y; 249 int x, y;
230 250
231 for (int i = 0; i < w; ++i) 251 for (int i = 0; i < w; ++i)
232 for (int j = 0; j < h; ++j) 252 for (int j = 0; j < h; ++j)
233 { 253 {
234 if (col [i][j] == '#') 254 if (data [i][j] == '#')
235 dist [i][j] = U8 (255); 255 dist [i][j] = U8 (255);
236 else 256 else
237 { 257 {
238 dist [i][j] = 0; 258 dist [i][j] = 0;
239 if (!rmg_rndm (++cnt)) 259 if (!rmg_rndm (++cnt))
293 } 313 }
294 314
295 // now copy the tunnels over 315 // now copy the tunnels over
296 for (int x = 0; x < w; ++x) 316 for (int x = 0; x < w; ++x)
297 for (int y = 0; y < h; ++y) 317 for (int y = 0; y < h; ++y)
298 if (col [x][y] == '#' && dist [x][y] == 1) 318 if (data [x][y] == '#' && dist [x][y] == 1)
299 col [x][y] = 0; 319 data [x][y] = 0;
300} 320}
301 321
302///////////////////////////////////////////////////////////////////////////// 322/////////////////////////////////////////////////////////////////////////////
303 323
304// inspired mostly by http://www.jimrandomh.org/misc/caves.txt 324// inspired mostly by http://www.jimrandomh.org/misc/caves.txt
305void 325void
306Layout::gen_cave (int subtype) 326layout::gen_cave (int subtype)
307{ 327{
308 switch (subtype) 328 switch (subtype)
309 { 329 {
310 // a rough cave 330 // a rough cave
311 case 0: 331 case 0:
341 361
342///////////////////////////////////////////////////////////////////////////// 362/////////////////////////////////////////////////////////////////////////////
343 363
344//+GPL 364//+GPL
345 365
346/* puts doors at appropriate locations in a layout. */ 366/* puts doors at appropriate locations in a maze. */
347void 367void
348Layout::doorify () 368layout::doorify ()
349{ 369{
350 int ndoors = w * h / 60; /* reasonable number of doors. */ 370 int ndoors = w * h / 60; /* reasonable number of doors. */
351 int doorlocs = 0; /* # of available doorlocations */ 371 int doorlocs = 0; /* # of available doorlocations */
352 372
353 uint16 *doorlist_x = salloc<uint16> (w * h); 373 uint16 *doorlist_x = salloc<uint16> (w * h);
374 int j = doorlist_y [di]; 394 int j = doorlist_y [di];
375 int sindex = surround_flag (*this, i, j); 395 int sindex = surround_flag (*this, i, j);
376 396
377 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 397 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
378 { 398 {
379 col [i][j] = 'D'; 399 data [i][j] = 'D';
380 ndoors--; 400 ndoors--;
381 } 401 }
382 402
383 /* reduce the size of the list */ 403 /* reduce the size of the list */
384 doorlocs--; 404 doorlocs--;
392 412
393/* takes a map and makes it symmetric: adjusts Xsize and 413/* takes a map and makes it symmetric: adjusts Xsize and
394 * Ysize to produce a symmetric map. 414 * Ysize to produce a symmetric map.
395 */ 415 */
396void 416void
397Layout::symmetrize (int symmetry) 417layout::symmetrize (int symmetry)
398{ 418{
399 if (symmetry == SYMMETRY_NONE) 419 if (symmetry == SYMMETRY_NONE)
400 return; 420 return;
401 421
402 Layout sym_layout ( 422 layout sym_layout (
403 symmetry == SYMMETRY_X || symmetry == SYMMETRY_XY ? w * 2 - 3 : w, 423 symmetry == SYMMETRY_X || symmetry == SYMMETRY_XY ? w * 2 - 3 : w,
404 symmetry == SYMMETRY_Y || symmetry == SYMMETRY_XY ? h * 2 - 3 : h 424 symmetry == SYMMETRY_Y || symmetry == SYMMETRY_XY ? h * 2 - 3 : h
405 ); 425 );
406 426
407 if (symmetry == SYMMETRY_X) 427 if (symmetry == SYMMETRY_X)
408 for (int i = 0; i < sym_layout.w / 2 + 1; i++) 428 for (int i = 0; i < sym_layout.w / 2 + 1; i++)
409 for (int j = 0; j < sym_layout.h; j++) 429 for (int j = 0; j < sym_layout.h; j++)
410 { 430 {
411 sym_layout[i ][j] = 431 sym_layout[i ][j] =
412 sym_layout[sym_layout.w - i - 1][j] = col[i][j]; 432 sym_layout[sym_layout.w - i - 1][j] = data [i][j];
413 } 433 }
414 434
415 if (symmetry == SYMMETRY_Y) 435 if (symmetry == SYMMETRY_Y)
416 for (int i = 0; i < sym_layout.w; i++) 436 for (int i = 0; i < sym_layout.w; i++)
417 for (int j = 0; j < sym_layout.h / 2 + 1; j++) 437 for (int j = 0; j < sym_layout.h / 2 + 1; j++)
418 { 438 {
419 sym_layout[i][j ] = 439 sym_layout[i][j ] =
420 sym_layout[i][sym_layout.h - j - 1] = col[i][j]; 440 sym_layout[i][sym_layout.h - j - 1] = data [i][j];
421 } 441 }
422 442
423 if (symmetry == SYMMETRY_XY) 443 if (symmetry == SYMMETRY_XY)
424 for (int i = 0; i < sym_layout.w / 2 + 1; i++) 444 for (int i = 0; i < sym_layout.w / 2 + 1; i++)
425 for (int j = 0; j < sym_layout.h / 2 + 1; j++) 445 for (int j = 0; j < sym_layout.h / 2 + 1; j++)
426 { 446 {
427 sym_layout[i ][j ] = 447 sym_layout[i ][j ] =
428 sym_layout[i ][sym_layout.h - j - 1] = 448 sym_layout[i ][sym_layout.h - j - 1] =
429 sym_layout[sym_layout.w - i - 1][j ] = 449 sym_layout[sym_layout.w - i - 1][j ] =
430 sym_layout[sym_layout.w - i - 1][sym_layout.h - j - 1] = col[i][j]; 450 sym_layout[sym_layout.w - i - 1][sym_layout.h - j - 1] = data [i][j];
431 } 451 }
432 452
433 /* need to run the isolation remover for some layouts */ 453 /* need to run the isolation remover for some layouts */
434#if 0 454#if 0
435 switch (RP->map_layout_style) 455 switch (RP->map_layout_style)
451} 471}
452 472
453//-GPL 473//-GPL
454 474
455void 475void
456Layout::rotate (int rotation) 476layout::rotate (int rotation)
457{ 477{
458 switch (rotation & 3) 478 switch (rotation & 3)
459 { 479 {
460 case 2: /* a reflection */ 480 case 2: /* a reflection */
461 { 481 {
462 Layout new_layout (w, h); 482 layout new_layout (w, h);
463 483
464 for (int i = 0; i < w; i++) /* copy a reflection back */ 484 for (int i = 0; i < w; i++) /* copy a reflection back */
465 for (int j = 0; j < h; j++) 485 for (int j = 0; j < h; j++)
466 new_layout [i][j] = col [w - i - 1][h - j - 1]; 486 new_layout [i][j] = data [w - i - 1][h - j - 1];
467 487
468 swap (new_layout); 488 swap (new_layout);
469 } 489 }
470 break; 490 break;
471 491
472 case 1: 492 case 1:
473 case 3: 493 case 3:
474 { 494 {
475 Layout new_layout (h, w); 495 layout new_layout (h, w);
476 496
477 if (rotation == 1) /* swap x and y */ 497 if (rotation == 1) /* swap x and y */
478 for (int i = 0; i < w; i++) 498 for (int i = 0; i < w; i++)
479 for (int j = 0; j < h; j++) 499 for (int j = 0; j < h; j++)
480 new_layout [j][i] = col [i][j]; 500 new_layout [j][i] = data [i][j];
481 501
482 if (rotation == 3) /* swap x and y */ 502 if (rotation == 3) /* swap x and y */
483 for (int i = 0; i < w; i++) 503 for (int i = 0; i < w; i++)
484 for (int j = 0; j < h; j++) 504 for (int j = 0; j < h; j++)
485 new_layout [j][i] = col [w - i - 1][h - j - 1]; 505 new_layout [j][i] = data [w - i - 1][h - j - 1];
486 506
487 swap (new_layout); 507 swap (new_layout);
488 } 508 }
489 break; 509 break;
490 } 510 }
493///////////////////////////////////////////////////////////////////////////// 513/////////////////////////////////////////////////////////////////////////////
494 514
495//+GPL 515//+GPL
496 516
497/* 517/*
498 * Expands a layout by 2x in each dimension. 518 * Expands a maze by 2x in each dimension.
499 * H. S. Teoh 519 * H. S. Teoh
500 */ 520 */
501 521
502/* Copy the old tile X into the new one at location (i*2, j*2) and 522/* Copy the old tile X into the new one at location (i*2, j*2) and
503 * fill up the rest of the 2x2 result with \0: 523 * fill up the rest of the 2x2 result with \0:
504 * X ---> X \0 524 * X ---> X \0
505 * \0 \0 525 * \0 \0
506 */ 526 */
507static void inline 527static void inline
508expand_misc (Layout &newlayout, int i, int j, Layout &layout) 528expand_misc (layout &newlayout, int i, int j, layout &maze)
509{ 529{
510 newlayout[i * 2 + rmg_rndm (1)][j * 2 + rmg_rndm (1)] = layout[i][j]; 530 newlayout[i * 2 + rmg_rndm (1)][j * 2 + rmg_rndm (1)] = maze[i][j];
511 /* (Note: no need to reset rest of 2x2 area to \0 because calloc does that 531 /* (Note: no need to reset rest of 2x2 area to \0 because calloc does that
512 * for us.) */ 532 * for us.) */
513} 533}
514 534
515/* Returns a bitmap that represents which squares on the right and bottom 535/* Returns a bitmap that represents which squares on the right and bottom
518 * 2 match on (i, j+1) 538 * 2 match on (i, j+1)
519 * 4 match on (i+1, j+1) 539 * 4 match on (i+1, j+1)
520 * and the possible combinations thereof. 540 * and the possible combinations thereof.
521 */ 541 */
522static int noinline 542static int noinline
523calc_pattern (char ch, Layout &layout, int i, int j) 543calc_pattern (char ch, layout &maze, int i, int j)
524{ 544{
525 int pattern = 0; 545 int pattern = 0;
526 546
527 if (i + 1 < layout.w && layout[i + 1][j] == ch) 547 if (i + 1 < maze.w && maze[i + 1][j] == ch)
528 pattern |= 1; 548 pattern |= 1;
529 549
530 if (j + 1 < layout.h) 550 if (j + 1 < maze.h)
531 { 551 {
532 if (layout[i][j + 1] == ch) 552 if (maze[i][j + 1] == ch)
533 pattern |= 2; 553 pattern |= 2;
534 554
535 if (i + 1 < layout.w && layout[i + 1][j + 1] == ch) 555 if (i + 1 < maze.w && maze[i + 1][j + 1] == ch)
536 pattern |= 4; 556 pattern |= 4;
537 } 557 }
538 558
539 return pattern; 559 return pattern;
540} 560}
542/* Expand a wall. This function will try to sensibly connect the resulting 562/* Expand a wall. This function will try to sensibly connect the resulting
543 * wall to adjacent wall squares, so that the result won't have disconnected 563 * wall to adjacent wall squares, so that the result won't have disconnected
544 * walls. 564 * walls.
545 */ 565 */
546static void inline 566static void inline
547expand_wall (Layout &newlayout, int i, int j, Layout &layout) 567expand_wall (layout &newlayout, int i, int j, layout &maze)
548{ 568{
549 int wall_pattern = calc_pattern ('#', layout, i, j); 569 int wall_pattern = calc_pattern ('#', maze, i, j);
550 int door_pattern = calc_pattern ('D', layout, i, j); 570 int door_pattern = calc_pattern ('D', maze, i, j);
551 int both_pattern = wall_pattern | door_pattern; 571 int both_pattern = wall_pattern | door_pattern;
552 572
553 newlayout[i * 2][j * 2] = '#'; 573 newlayout[i * 2][j * 2] = '#';
554 574
555 if (i + 1 < layout.w) 575 if (i + 1 < maze.w)
556 { 576 {
557 if (both_pattern & 1) 577 if (both_pattern & 1)
558 { /* join walls/doors to the right */ 578 { /* join walls/doors to the right */
559/* newlayout[i*2+1][j*2] = '#'; */ 579/* newlayout[i*2+1][j*2] = '#'; */
560 newlayout[i * 2 + 1][j * 2] = layout[i + 1][j]; 580 newlayout[i * 2 + 1][j * 2] = maze[i + 1][j];
561 } 581 }
562 } 582 }
563 583
564 if (j + 1 < layout.h) 584 if (j + 1 < maze.h)
565 { 585 {
566 if (both_pattern & 2) 586 if (both_pattern & 2)
567 { /* join walls/doors to the bottom */ 587 { /* join walls/doors to the bottom */
568/* newlayout[i*2][j*2+1] = '#'; */ 588/* newlayout[i*2][j*2+1] = '#'; */
569 newlayout[i * 2][j * 2 + 1] = layout[i][j + 1]; 589 newlayout[i * 2][j * 2 + 1] = maze[i][j + 1];
570 } 590 }
571 591
572 if (wall_pattern == 7) 592 if (wall_pattern == 7)
573 { /* if orig layout is a 2x2 wall block, 593 { /* if orig maze is a 2x2 wall block,
574 * we fill the result with walls. */ 594 * we fill the result with walls. */
575 newlayout[i * 2 + 1][j * 2 + 1] = '#'; 595 newlayout[i * 2 + 1][j * 2 + 1] = '#';
576 } 596 }
577 } 597 }
578} 598}
580/* This function will try to sensibly connect doors so that they meet up with 600/* This function will try to sensibly connect doors so that they meet up with
581 * adjacent walls. Note that it will also presumptuously delete (ignore) doors 601 * adjacent walls. Note that it will also presumptuously delete (ignore) doors
582 * that it doesn't know how to correctly expand. 602 * that it doesn't know how to correctly expand.
583 */ 603 */
584static void inline 604static void inline
585expand_door (Layout &newlayout, int i, int j, Layout &layout) 605expand_door (layout &newlayout, int i, int j, layout &maze)
586{ 606{
587 int wall_pattern = calc_pattern ('#', layout, i, j); 607 int wall_pattern = calc_pattern ('#', maze, i, j);
588 int door_pattern = calc_pattern ('D', layout, i, j); 608 int door_pattern = calc_pattern ('D', maze, i, j);
589 int join_pattern; 609 int join_pattern;
590 610
591 /* Doors "like" to connect to walls more than other doors. If there is 611 /* Doors "like" to connect to walls more than other doors. If there is
592 * a wall and another door, this door will connect to the wall and 612 * a wall and another door, this door will connect to the wall and
593 * disconnect from the other door. */ 613 * disconnect from the other door. */
596 else 616 else
597 join_pattern = door_pattern; 617 join_pattern = door_pattern;
598 618
599 newlayout[i * 2][j * 2] = 'D'; 619 newlayout[i * 2][j * 2] = 'D';
600 620
601 if (i + 1 < layout.w) 621 if (i + 1 < maze.w)
602 if (join_pattern & 1) 622 if (join_pattern & 1)
603 /* there is a door/wall to the right */ 623 /* there is a door/wall to the right */
604 newlayout[i * 2 + 1][j * 2] = 'D'; 624 newlayout[i * 2 + 1][j * 2] = 'D';
605 625
606 if (j + 1 < layout.h) 626 if (j + 1 < maze.h)
607 if (join_pattern & 2) 627 if (join_pattern & 2)
608 /* there is a door/wall below */ 628 /* there is a door/wall below */
609 newlayout[i * 2][j * 2 + 1] = 'D'; 629 newlayout[i * 2][j * 2 + 1] = 'D';
610} 630}
611 631
612void 632void
613Layout::expand2x () 633layout::expand2x ()
614{ 634{
615 Layout new_layout (w * 2 - 1, h * 2 - 1); 635 layout new_layout (w * 2 - 1, h * 2 - 1);
616 636
617 new_layout.clear (); 637 new_layout.clear ();
618 638
619 for (int i = 0; i < w; i++) 639 for (int i = 0; i < w; i++)
620 for (int j = 0; j < h; j++) 640 for (int j = 0; j < h; j++)
621 switch (col [i][j]) 641 switch (data [i][j])
622 { 642 {
623 case '#': expand_wall (new_layout, i, j, *this); break; 643 case '#': expand_wall (new_layout, i, j, *this); break;
624 case 'D': expand_door (new_layout, i, j, *this); break; 644 case 'D': expand_door (new_layout, i, j, *this); break;
625 default: expand_misc (new_layout, i, j, *this); break; 645 default: expand_misc (new_layout, i, j, *this); break;
626 } 646 }
628 swap (new_layout); 648 swap (new_layout);
629} 649}
630 650
631///////////////////////////////////////////////////////////////////////////// 651/////////////////////////////////////////////////////////////////////////////
632 652
633/* checks the layout to see if I can stick a horizontal(dir = 0) wall 653/* checks the maze to see if I can stick a horizontal(dir = 0) wall
634 (or vertical, dir == 1) 654 (or vertical, dir == 1)
635 here which ends up on other walls sensibly. */ 655 here which ends up on other walls sensibly. */
636static int 656static int
637can_make_wall (const Layout &maze, int dx, int dy, int dir) 657can_make_wall (const layout &maze, int dx, int dy, int dir)
638{ 658{
639 int i1; 659 int i1;
640 int length = 0; 660 int length = 0;
641 661
642 /* dont make walls if we're on the edge. */ 662 /* dont make walls if we're on the edge. */
729 749
730 return 0; 750 return 0;
731} 751}
732 752
733void 753void
734Layout::roomify () 754layout::roomify ()
735{ 755{
736 int tries = w * h / 30; 756 int tries = w * h / 30;
737 757
738 for (int ti = 0; ti < tries; ti++) 758 for (int ti = 0; ti < tries; ti++)
739 { 759 {
766 } 786 }
767} 787}
768 788
769///////////////////////////////////////////////////////////////////////////// 789/////////////////////////////////////////////////////////////////////////////
770 790
771/* function selects the layout function and gives it whatever 791/* function selects the maze function and gives it whatever
772 arguments it needs. */ 792 arguments it needs. */
773void 793void
774Layout::generate (random_map_params *RP) 794layout::generate (random_map_params *RP)
775{ 795{
776 switch (RP->map_layout_style) 796 switch (RP->map_layout_style)
777 { 797 {
778 case LAYOUT_ONION: 798 case LAYOUT_ONION:
779 map_gen_onion (*this, RP->layoutoptions1, RP->layoutoptions2); 799 map_gen_onion (*this, RP->layoutoptions1, RP->layoutoptions2);
838 858
839 default: 859 default:
840 abort (); 860 abort ();
841 } 861 }
842 862
843 /* rotate the layout randomly */ 863 /* rotate the maze randomly */
844 rotate (rmg_rndm (4)); 864 rotate (rmg_rndm (4));
845 865
846 symmetrize (RP->symmetry_used); 866 symmetrize (RP->symmetry_used);
847 867
848#if 0 868#if 0
862 { 882 {
863 rmg_rndm.seed (time (0)); 883 rmg_rndm.seed (time (0));
864 884
865 for(int i=1;i<10;i) 885 for(int i=1;i<10;i)
866 { 886 {
867 Layout maze (10, 10); 887 layout maze (10, 10);
868 maze.fill_rand (90); 888 maze.fill_rand (90);
869 maze.border (); 889 maze.border ();
870 maze.isolation_remover (); 890 maze.isolation_remover ();
871 maze.doorify (); 891 maze.doorify ();
872 maze.symmetrize (rmg_rndm (2, 4)); 892 maze.symmetrize (rmg_rndm (2, 4));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines