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.4 by root, Thu Jul 1 01:27:14 2010 UTC vs.
Revision 1.9 by root, Fri Jul 2 17:18:04 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines