ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/layout.C
Revision: 1.8
Committed: Fri Jul 2 15:43:37 2010 UTC (13 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.7: +29 -24 lines
Log Message:
more useless perl accessors

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) Crossfire Development Team (restored, original file without copyright notice)
6 *
7 * Deliantra is free software: you can redistribute it and/or modify it under
8 * the terms of the Affero GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the Affero GNU General Public License
18 * and the GNU General Public License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */
23
24 #include <global.h>
25 #include <random_map.h>
26 #include <rproto.h>
27
28 layout::layout (int w, int h)
29 : w(w), h(h)
30 {
31 assert (sizeof (cell) == 1);
32
33 // we store the layout in a single contiguous memory layout
34 // first part consists of pointers to each column, followed
35 // by the actual columns (not rows!)
36 int size = (sizeof (cell *) + sizeof (cell) * h) * w;
37
38 data = (cell **)salloc<char> (size);
39
40 cell *p = (cell *)(data + w);
41
42 for (int x = w; x--; )
43 data [x] = p + x * h;
44 }
45
46 layout::~layout ()
47 {
48 int size = (sizeof (cell *) + sizeof (cell) * h) * w;
49
50 sfree ((char *)data, size);
51 }
52
53 void
54 layout::fill (char fill)
55 {
56 memset (data [0], fill, w * h);
57 }
58
59 void
60 layout::rect (int x1, int y1, int x2, int y2, char fill)
61 {
62 for (; x1 < x2; ++x1)
63 memset (data [x1] + y1, fill, y2 - y1);
64 }
65
66 void layout::border (char fill)
67 {
68 for (int i = 0; i < w; i++) data [i][0] = data [i][h - 1] = fill;
69 for (int j = 0; j < h; j++) data [0][j] = data [w - 1][j] = fill;
70 }
71
72 void
73 layout::fill_rand (int percent)
74 {
75 percent = lerp (percent, 0, 100, 0, 256);
76
77 for (int x = w - 1; --x > 0; )
78 for (int y = h - 1; --y > 0; )
79 data [x][y] = rmg_rndm (256) > percent ? 0 : '#';
80 }
81
82 /////////////////////////////////////////////////////////////////////////////
83
84 // erode by cellular automata
85 void
86 layout::erode_1_2 (int c1, int c2, int repeat)
87 {
88 layout neu (w, h);
89
90 while (repeat--)
91 {
92 for (int x = 0; x < w; ++x)
93 {
94 coroapi::cede_to_tick ();
95
96 for (int y = 0; y < h; ++y)
97 {
98 int n1 = 0, n2 = 0;
99
100 // a 5x5 area, dx, dy, distance (1 == <= 1, 0 <= 2)
101 static I8 dds[][3] = {
102 { -2, -1, 0 }, { -2, 0, 0 }, { -2, 1, 0 },
103 { -1, -2, 0 }, { -1, -1, 1 }, { -1, 0, 1 }, { -1, 1, 1 }, { -1, 2, 0 },
104 { 0, -2, 0 }, { 0, -1, 1 }, { 0, 0, 1 }, { 0, 1, 1 }, { 0, 2, 0 },
105 { 1, -2, 0 }, { 1, -1, 1 }, { 1, 0, 1 }, { 1, 1, 1 }, { 1, 2, 0 },
106 { 2, -1, 0 }, { 2, 0, 0 }, { 2, 1, 0 },
107 };
108
109 for (int i = array_length (dds); i--; )
110 {
111 int nx = x + dds [i][0];
112 int ny = y + dds [i][1];
113
114 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !data [nx][ny])
115 {
116 n1 += dds [i][2];
117 n2++;
118 }
119 }
120
121 neu [x][y] = n1 >= c1 || n2 <= c2 ? '#' : 0;
122 }
123 }
124
125 swap (neu);
126 }
127 }
128
129 /////////////////////////////////////////////////////////////////////////////
130
131 void
132 layout::print () const
133 {
134 for (int y = 0; y < h; y++)
135 {
136 for (int x = 0; x < w; x++)
137 {
138 U8 c = (U8)data [x][y];
139
140 if (!c)
141 c = ' ';
142 else if (c < 10)
143 c += '0';
144 else if (c < 32)
145 c += 'a' - 10;
146
147 putc ((char)c, stdout);
148 }
149
150 putc ('\n', stdout);
151 }
152
153 putc ('\n', stdout);
154 }
155
156 /////////////////////////////////////////////////////////////////////////////
157 // isolation remover - ensures single connected area
158
159 typedef fixed_stack<point> pointlist;
160
161 static noinline void
162 push_flood_fill (layout &dist, pointlist &seeds, int x, int y)
163 {
164 if (dist [x][y])
165 return;
166
167 while (y > 0 && !dist [x][y - 1])
168 --y;
169
170 int y0 = y;
171
172 while (y < dist.h && !dist [x][y])
173 {
174 seeds.push (point (x, y));
175
176 dist [x][y] = 1;
177 ++y;
178 }
179
180 while (--y >= y0)
181 {
182 if (x > 0) push_flood_fill (dist, seeds, x - 1, y);
183 if (x < dist.w - 1) push_flood_fill (dist, seeds, x + 1, y);
184 }
185 }
186
187 static inline void
188 make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d)
189 {
190 for (;;)
191 {
192 if (x > 1 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1)
193 --x;
194 else if (x < dist.w - 2 && U8 (dist [x + 1][y]) < d && dist [x + 1][y] > 1)
195 ++x;
196 else if (y > 1 && U8 (dist [x][y - 1]) < d && dist [x][y - 1] > 1)
197 --y;
198 else if (y < dist.h - 2 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1)
199 ++y;
200 else
201 break;
202
203 d = dist [x][y];
204 dist [x][y] = 1;
205 seeds.push (point (x, y));
206 }
207 }
208
209 static void inline
210 maybe_push (layout &dist, pointlist &seeds, int x, int y, U8 d)
211 {
212 char &D = dist [x][y];
213
214 if (U8 (D) > d) // if wall and higher distance, lower distance
215 D = d;
216 else if (D) // otherwise, if it's no room, this space is uninteresting
217 return;
218
219 seeds.push (point (x, y));
220 }
221
222 void
223 layout::isolation_remover (bool dirty)
224 {
225 layout dist (w, h);
226
227 // dist contains
228 // 0 == invisited rooms
229 // 1 == visited rooms
230 // 2+ shortest distance to random near room
231
232 // phase 1, initialise dist array, find seed
233 int cnt = 0;
234 int x, y;
235
236 for (int i = 0; i < w; ++i)
237 for (int j = 0; j < h; ++j)
238 {
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;
246 }
247 }
248
249 if (!cnt)
250 {
251 // map is completely massive, this is not good,
252 // so make it empty instead.
253 clear ();
254 border ();
255 return;
256 }
257
258 fixed_stack<point> seeds (w * h * 5);
259
260 // found first free space - picking the first one gives
261 // us a slight bias for tunnels, but usually you won't
262 // notice that in-game
263 seeds.push (point (x, y));
264
265 // phase 2, while we have seeds, if
266 // seed is empty, floodfill, else grow
267
268 while (seeds.size)
269 {
270 coroapi::cede_to_tick ();
271
272 point p = seeds.remove (rmg_rndm (seeds.size));
273
274 x = p.x;
275 y = p.y;
276
277 if (!dist [x][y])
278 {
279 // found new isolated area, make tunnel
280 if (!dirty)
281 push_flood_fill (dist, seeds, x, y);
282
283 make_tunnel (dist, seeds, x, y, 255);
284
285 if (dirty)
286 push_flood_fill (dist, seeds, x, y);
287 }
288 else
289 {
290 // nothing here, continue to expand
291 U8 d = U8 (dist [x][y]) + 1;
292
293 if (x < dist.w - 1) maybe_push (dist, seeds, x + 1, y, d);
294 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);
296 if (y > 0) maybe_push (dist, seeds, x, y - 1, d);
297 }
298 }
299
300 // now copy the tunnels over
301 for (int x = 0; x < w; ++x)
302 for (int y = 0; y < h; ++y)
303 if (data [x][y] == '#' && dist [x][y] == 1)
304 data [x][y] = 0;
305 }
306
307 /////////////////////////////////////////////////////////////////////////////
308
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
350
351 /* puts doors at appropriate locations in a maze. */
352 void
353 layout::doorify ()
354 {
355 int ndoors = w * h / 60; /* reasonable number of doors. */
356 int doorlocs = 0; /* # of available doorlocations */
357
358 uint16 *doorlist_x = salloc<uint16> (w * h);
359 uint16 *doorlist_y = salloc<uint16> (w * h);
360
361 /* make a list of possible door locations */
362 for (int i = 1; i < w - 1; i++)
363 for (int j = 1; j < h - 1; j++)
364 {
365 int sindex = surround_flag (*this, i, j);
366
367 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
368 {
369 doorlist_x [doorlocs] = i;
370 doorlist_y [doorlocs] = j;
371 doorlocs++;
372 }
373 }
374
375 while (ndoors > 0 && doorlocs > 0)
376 {
377 int di = rmg_rndm (doorlocs);
378 int i = doorlist_x [di];
379 int j = doorlist_y [di];
380 int sindex = surround_flag (*this, i, j);
381
382 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
383 {
384 data [i][j] = 'D';
385 ndoors--;
386 }
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 }
393
394 sfree (doorlist_x, w * h);
395 sfree (doorlist_y, w * h);
396 }
397
398 /* takes a map and makes it symmetric: adjusts Xsize and
399 * Ysize to produce a symmetric map.
400 */
401 void
402 layout::symmetrize (int symmetry)
403 {
404 if (symmetry == SYMMETRY_NONE)
405 return;
406
407 layout sym_layout (
408 symmetry == SYMMETRY_X || symmetry == SYMMETRY_XY ? w * 2 - 3 : w,
409 symmetry == SYMMETRY_Y || symmetry == SYMMETRY_XY ? h * 2 - 3 : h
410 );
411
412 if (symmetry == SYMMETRY_X)
413 for (int i = 0; i < sym_layout.w / 2 + 1; i++)
414 for (int j = 0; j < sym_layout.h; j++)
415 {
416 sym_layout[i ][j] =
417 sym_layout[sym_layout.w - i - 1][j] = data [i][j];
418 }
419
420 if (symmetry == SYMMETRY_Y)
421 for (int i = 0; i < sym_layout.w; i++)
422 for (int j = 0; j < sym_layout.h / 2 + 1; j++)
423 {
424 sym_layout[i][j ] =
425 sym_layout[i][sym_layout.h - j - 1] = data [i][j];
426 }
427
428 if (symmetry == SYMMETRY_XY)
429 for (int i = 0; i < sym_layout.w / 2 + 1; i++)
430 for (int j = 0; j < sym_layout.h / 2 + 1; j++)
431 {
432 sym_layout[i ][j ] =
433 sym_layout[i ][sym_layout.h - j - 1] =
434 sym_layout[sym_layout.w - i - 1][j ] =
435 sym_layout[sym_layout.w - i - 1][sym_layout.h - j - 1] = data [i][j];
436 }
437
438 /* need to run the isolation remover for some layouts */
439 #if 0
440 switch (RP->map_layout_style)
441 {
442 case LAYOUT_ONION:
443 case LAYOUT_SNAKE:
444 case LAYOUT_SQUARE_SPIRAL:
445 // safe
446 break;
447
448 default:
449 sym_layout.isolation_remover ();
450 break;
451 }
452 #endif
453 sym_layout.isolation_remover ();
454
455 swap (sym_layout);
456 }
457
458 //-GPL
459
460 void
461 layout::rotate (int rotation)
462 {
463 switch (rotation & 3)
464 {
465 case 2: /* a reflection */
466 {
467 layout new_layout (w, h);
468
469 for (int i = 0; i < w; i++) /* copy a reflection back */
470 for (int j = 0; j < h; j++)
471 new_layout [i][j] = data [w - i - 1][h - j - 1];
472
473 swap (new_layout);
474 }
475 break;
476
477 case 1:
478 case 3:
479 {
480 layout new_layout (h, w);
481
482 if (rotation == 1) /* swap x and y */
483 for (int i = 0; i < w; i++)
484 for (int j = 0; j < h; j++)
485 new_layout [j][i] = data [i][j];
486
487 if (rotation == 3) /* swap x and y */
488 for (int i = 0; i < w; i++)
489 for (int j = 0; j < h; j++)
490 new_layout [j][i] = data [w - i - 1][h - j - 1];
491
492 swap (new_layout);
493 }
494 break;
495 }
496 }
497
498 /////////////////////////////////////////////////////////////////////////////
499
500 //+GPL
501
502 /*
503 * Expands a maze by 2x in each dimension.
504 * H. S. Teoh
505 */
506
507 /* Copy the old tile X into the new one at location (i*2, j*2) and
508 * fill up the rest of the 2x2 result with \0:
509 * X ---> X \0
510 * \0 \0
511 */
512 static void inline
513 expand_misc (layout &newlayout, int i, int j, layout &maze)
514 {
515 newlayout[i * 2 + rmg_rndm (1)][j * 2 + rmg_rndm (1)] = maze[i][j];
516 /* (Note: no need to reset rest of 2x2 area to \0 because calloc does that
517 * for us.) */
518 }
519
520 /* Returns a bitmap that represents which squares on the right and bottom
521 * edges of a square (i,j) match the given character:
522 * 1 match on (i+1, j)
523 * 2 match on (i, j+1)
524 * 4 match on (i+1, j+1)
525 * and the possible combinations thereof.
526 */
527 static int noinline
528 calc_pattern (char ch, layout &maze, int i, int j)
529 {
530 int pattern = 0;
531
532 if (i + 1 < maze.w && maze[i + 1][j] == ch)
533 pattern |= 1;
534
535 if (j + 1 < maze.h)
536 {
537 if (maze[i][j + 1] == ch)
538 pattern |= 2;
539
540 if (i + 1 < maze.w && maze[i + 1][j + 1] == ch)
541 pattern |= 4;
542 }
543
544 return pattern;
545 }
546
547 /* Expand a wall. This function will try to sensibly connect the resulting
548 * wall to adjacent wall squares, so that the result won't have disconnected
549 * walls.
550 */
551 static void inline
552 expand_wall (layout &newlayout, int i, int j, layout &maze)
553 {
554 int wall_pattern = calc_pattern ('#', maze, i, j);
555 int door_pattern = calc_pattern ('D', maze, i, j);
556 int both_pattern = wall_pattern | door_pattern;
557
558 newlayout[i * 2][j * 2] = '#';
559
560 if (i + 1 < maze.w)
561 {
562 if (both_pattern & 1)
563 { /* join walls/doors to the right */
564 /* newlayout[i*2+1][j*2] = '#'; */
565 newlayout[i * 2 + 1][j * 2] = maze[i + 1][j];
566 }
567 }
568
569 if (j + 1 < maze.h)
570 {
571 if (both_pattern & 2)
572 { /* join walls/doors to the bottom */
573 /* newlayout[i*2][j*2+1] = '#'; */
574 newlayout[i * 2][j * 2 + 1] = maze[i][j + 1];
575 }
576
577 if (wall_pattern == 7)
578 { /* if orig maze is a 2x2 wall block,
579 * we fill the result with walls. */
580 newlayout[i * 2 + 1][j * 2 + 1] = '#';
581 }
582 }
583 }
584
585 /* This function will try to sensibly connect doors so that they meet up with
586 * adjacent walls. Note that it will also presumptuously delete (ignore) doors
587 * that it doesn't know how to correctly expand.
588 */
589 static void inline
590 expand_door (layout &newlayout, int i, int j, layout &maze)
591 {
592 int wall_pattern = calc_pattern ('#', maze, i, j);
593 int door_pattern = calc_pattern ('D', maze, i, j);
594 int join_pattern;
595
596 /* Doors "like" to connect to walls more than other doors. If there is
597 * a wall and another door, this door will connect to the wall and
598 * disconnect from the other door. */
599 if (wall_pattern & 3)
600 join_pattern = wall_pattern;
601 else
602 join_pattern = door_pattern;
603
604 newlayout[i * 2][j * 2] = 'D';
605
606 if (i + 1 < maze.w)
607 if (join_pattern & 1)
608 /* there is a door/wall to the right */
609 newlayout[i * 2 + 1][j * 2] = 'D';
610
611 if (j + 1 < maze.h)
612 if (join_pattern & 2)
613 /* there is a door/wall below */
614 newlayout[i * 2][j * 2 + 1] = 'D';
615 }
616
617 void
618 layout::expand2x ()
619 {
620 layout new_layout (w * 2 - 1, h * 2 - 1);
621
622 new_layout.clear ();
623
624 for (int i = 0; i < w; i++)
625 for (int j = 0; j < h; j++)
626 switch (data [i][j])
627 {
628 case '#': expand_wall (new_layout, i, j, *this); break;
629 case 'D': expand_door (new_layout, i, j, *this); break;
630 default: expand_misc (new_layout, i, j, *this); break;
631 }
632
633 swap (new_layout);
634 }
635
636 /////////////////////////////////////////////////////////////////////////////
637
638 /* checks the maze to see if I can stick a horizontal(dir = 0) wall
639 (or vertical, dir == 1)
640 here which ends up on other walls sensibly. */
641 static int
642 can_make_wall (const layout &maze, int dx, int dy, int dir)
643 {
644 int i1;
645 int length = 0;
646
647 /* dont make walls if we're on the edge. */
648 if (dx == 0 || dx == (maze.w - 1) || dy == 0 || dy == (maze.h - 1))
649 return -1;
650
651 /* don't make walls if we're ON a wall. */
652 if (maze [dx][dy] != 0)
653 return -1;
654
655 if (dir == 0) /* horizontal */
656 {
657 int y = dy;
658
659 for (i1 = dx - 1; i1 > 0; i1--)
660 {
661 int sindex = surround_flag2 (maze, i1, y);
662
663 if (sindex == 1) break;
664 if (sindex != 0) return -1; /* can't make horiz. wall here */
665 if (maze[i1][y] != 0) return -1; /* can't make horiz. wall here */
666
667 length++;
668 }
669
670 for (i1 = dx + 1; i1 < maze.w - 1; i1++)
671 {
672 int sindex = surround_flag2 (maze, i1, y);
673
674 if (sindex == 2) break;
675 if (sindex != 0) return -1; /* can't make horiz. wall here */
676 if (maze[i1][y] != 0) return -1; /* can't make horiz. wall here */
677
678 length++;
679 }
680 return length;
681 }
682 else
683 { /* vertical */
684 int x = dx;
685
686 for (i1 = dy - 1; i1 > 0; i1--)
687 {
688 int sindex = surround_flag2 (maze, x, i1);
689
690 if (sindex == 4) break;
691 if (sindex != 0) return -1; /* can't make vert. wall here */
692 if (maze[x][i1] != 0) return -1; /* can't make horiz. wall here */
693
694 length++;
695 }
696
697 for (i1 = dy + 1; i1 < maze.h - 1; i1++)
698 {
699 int sindex = surround_flag2 (maze, x, i1);
700
701 if (sindex == 8) break;
702 if (sindex != 0) return -1; /* can't make verti. wall here */
703 if (maze[x][i1] != 0) return -1; /* can't make horiz. wall here */
704
705 length++;
706 }
707
708 return length;
709 }
710
711 return -1;
712 }
713
714 int
715 make_wall (char **maze, int x, int y, int dir)
716 {
717 maze[x][y] = 'D'; /* mark a door */
718
719 switch (dir)
720 {
721 case 0: /* horizontal */
722 {
723 for (int i1 = x - 1; maze[i1][y] == 0; --i1) maze[i1][y] = '#';
724 for (int i1 = x + 1; maze[i1][y] == 0; ++i1) maze[i1][y] = '#';
725 break;
726 }
727 case 1: /* vertical */
728 {
729 for (int i1 = y - 1; maze[x][i1] == 0; --i1) maze[x][i1] = '#';
730 for (int i1 = y + 1; maze[x][i1] == 0; ++i1) maze[x][i1] = '#';
731 break;
732 }
733 }
734
735 return 0;
736 }
737
738 void
739 layout::roomify ()
740 {
741 int tries = w * h / 30;
742
743 for (int ti = 0; ti < tries; ti++)
744 {
745 /* starting location for looking at creating a door */
746 int dx = rmg_rndm (w);
747 int dy = rmg_rndm (h);
748
749 /* results of checking on creating walls. */
750 int cx = can_make_wall (*this, dx, dy, 0); /* horizontal */
751 int cy = can_make_wall (*this, dx, dy, 1); /* vertical */
752
753 if (cx == -1)
754 {
755 if (cy != -1)
756 make_wall (*this, dx, dy, 1);
757
758 continue;
759 }
760
761 if (cy == -1)
762 {
763 make_wall (*this, dx, dy, 0);
764 continue;
765 }
766
767 if (cx < cy)
768 make_wall (*this, dx, dy, 0);
769 else
770 make_wall (*this, dx, dy, 1);
771 }
772 }
773
774 /////////////////////////////////////////////////////////////////////////////
775
776 /* function selects the maze function and gives it whatever
777 arguments it needs. */
778 void
779 layout::generate (random_map_params *RP)
780 {
781 switch (RP->map_layout_style)
782 {
783 case LAYOUT_ONION:
784 map_gen_onion (*this, RP->layoutoptions1, RP->layoutoptions2);
785
786 if (!(rmg_rndm (3)) && !(RP->layoutoptions1 & (RMOPT_WALLS_ONLY | RMOPT_WALL_OFF)))
787 roomify ();
788
789 break;
790
791 case LAYOUT_MAZE:
792 maze_gen (*this, RP->get_iv ("maze_type", rmg_rndm (4)));
793
794 if (rmg_rndm (2))
795 doorify ();
796
797 break;
798
799 case LAYOUT_SPIRAL:
800 map_gen_spiral (*this, RP->layoutoptions1);
801
802 if (rmg_rndm (2))
803 doorify ();
804
805 break;
806
807 case LAYOUT_ROGUELIKE:
808 /* Don't put symmetry in rogue maps. There isn't much reason to
809 * do so in the first place (doesn't make it any more interesting),
810 * but more importantly, the symmetry code presumes we are symmetrizing
811 * spirals, or maps with lots of passages - making a symmetric rogue
812 * map fails because its likely that the passages the symmetry process
813 * creates may not connect the rooms.
814 */
815 RP->symmetry_used = SYMMETRY_NONE;
816 roguelike_layout_gen (*this, RP->layoutoptions1);
817 /* no doorifying... done already */
818 break;
819
820 case LAYOUT_SNAKE:
821 make_snake_layout (*this, RP->layoutoptions1);
822
823 if (rmg_rndm (2))
824 roomify ();
825
826 break;
827
828 case LAYOUT_SQUARE_SPIRAL:
829 make_square_spiral_layout (*this, RP->layoutoptions1);
830
831 if (rmg_rndm (2))
832 roomify ();
833
834 break;
835
836 case LAYOUT_CAVE:
837 gen_cave (RP->get_iv ("cave_type", rmg_rndm (4)));
838
839 if (rmg_rndm (2))
840 doorify ();
841
842 break;
843
844 default:
845 abort ();
846 }
847
848 /* rotate the maze randomly */
849 rotate (rmg_rndm (4));
850
851 symmetrize (RP->symmetry_used);
852
853 #if 0
854 print ();//D
855 #endif
856
857 if (RP->expand2x)
858 expand2x ();
859 }
860
861 //-GPL
862
863 #if 0
864 static struct demo
865 {
866 demo ()
867 {
868 rmg_rndm.seed (time (0));
869
870 for(int i=1;i<10;i)
871 {
872 layout maze (10, 10);
873 maze.fill_rand (90);
874 maze.border ();
875 maze.isolation_remover ();
876 maze.doorify ();
877 maze.symmetrize (rmg_rndm (2, 4));
878 maze.rotate (rmg_rndm (4));
879 maze.expand2x ();
880 maze.print ();
881 }
882
883 exit (1);
884 }
885 } demo;
886 #endif