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.13 by root, Sat Jul 3 01:52:52 2010 UTC vs.
Revision 1.15 by root, Sat Jul 3 03:09:27 2010 UTC

34 this->h = h; 34 this->h = h;
35 35
36 // we store the layout in a single contiguous memory layout 36 // we store the layout in a single contiguous memory layout
37 // first part consists of pointers to each column, followed 37 // first part consists of pointers to each column, followed
38 // by the actual columns (not rows!) 38 // by the actual columns (not rows!)
39 int size = (sizeof (cell *) + sizeof (cell) * h) * w; 39 size = (sizeof (cell *) + sizeof (cell) * h) * w;
40
41 data = (cell **)salloc<char> (size); 40 data = (cell **)salloc<char> (size);
42 41
43 cell *p = (cell *)(data + w); 42 cell *p = (cell *)(data + w);
44 43
45 for (int x = w; x--; ) 44 for (int x = 0; x < w; ++x)
46 data [x] = p + x * h; 45 data [x] = p + x * h;
47} 46}
48 47
49layout::layout (int w, int h) 48layout::layout (int w, int h)
50{ 49{
56 alloc (copy.w, copy.h); 55 alloc (copy.w, copy.h);
57 56
58 memcpy (data [0], copy.data [0], sizeof (cell) * h * w); 57 memcpy (data [0], copy.data [0], sizeof (cell) * h * w);
59} 58}
60 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;
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
61layout::~layout () 74layout::~layout ()
62{ 75{
63 int size = (sizeof (cell *) + sizeof (cell) * h) * w;
64
65 sfree ((char *)data, size); 76 sfree ((char *)data, size);
66} 77}
67 78
68void 79void
69layout::fill (char fill) 80layout::fill (char fill)
70{ 81{
71 memset (data [0], fill, w * h); 82 //memset (data [0], fill, w * h); // only when contiguous :/
83 fill_rect (0, 0, w, h, fill);
72} 84}
73 85
74void 86void
75layout::rect (int x1, int y1, int x2, int y2, char fill) 87layout::rect (int x1, int y1, int x2, int y2, char fill)
76{ 88{
800 make_wall (*this, dx, dy, 1); 812 make_wall (*this, dx, dy, 1);
801 } 813 }
802} 814}
803 815
804///////////////////////////////////////////////////////////////////////////// 816/////////////////////////////////////////////////////////////////////////////
817
818static void
819gen_mixed_ (layout &maze, random_map_params *RP, int dir)
820{
821 if (maze.w < 20 && maze.h < 20 && !rmg_rndm (3))
822 dir = 2; // stop recursion randomly
823
824 if (dir == 0 && maze.w > 16)
825 {
826 int m = rmg_rndm (8, maze.w - 8);
827
828 layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP, !dir);
829 layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP, !dir);
830 }
831 else if (dir == 1 && maze.h > 16)
832 {
833 int m = rmg_rndm (8, maze.h - 8);
834
835 layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP, !dir);
836 layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP, !dir);
837 }
838 else
839 {
840 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1;
841
842 if (RP->map_layout_style == LAYOUT_MULTIPLE)
843 ++RP->map_layout_style;
844
845 maze.generate (RP);
846 }
847}
848
849static void
850gen_mixed (layout &maze, random_map_params *RP)
851{
852 random_map_params &rp = *new random_map_params (RP);
853 gen_mixed_ (maze, &rp, rmg_rndm (2));
854 delete &rp;
855
856 maze.border ();
857 maze.isolation_remover ();
858}
805 859
806/* function selects the maze function and gives it whatever 860/* function selects the maze function and gives it whatever
807 arguments it needs. */ 861 arguments it needs. */
808void 862void
809layout::generate (random_map_params *RP) 863layout::generate (random_map_params *RP)
869 if (rmg_rndm (2)) 923 if (rmg_rndm (2))
870 doorify (); 924 doorify ();
871 925
872 break; 926 break;
873 927
928 case LAYOUT_MULTIPLE:
929 gen_mixed (*this, RP);
930 break;
931
874 default: 932 default:
875 abort (); 933 abort ();
876 } 934 }
877
878 /* rotate the maze randomly */
879 rotate (rmg_rndm (4));
880
881 symmetrize (RP->symmetry_used);
882
883#if 0
884 print ();//D
885#endif
886
887 if (RP->expand2x)
888 expand2x ();
889} 935}
890 936
891//-GPL 937//-GPL
892 938
893#if 0 939#if 0

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines