--- deliantra/server/random_maps/layout.C 2010/07/03 01:52:52 1.13 +++ deliantra/server/random_maps/layout.C 2010/07/03 03:09:27 1.15 @@ -36,13 +36,12 @@ // we store the layout in a single contiguous memory layout // first part consists of pointers to each column, followed // by the actual columns (not rows!) - int size = (sizeof (cell *) + sizeof (cell) * h) * w; - + size = (sizeof (cell *) + sizeof (cell) * h) * w; data = (cell **)salloc (size); cell *p = (cell *)(data + w); - for (int x = w; x--; ) + for (int x = 0; x < w; ++x) data [x] = p + x * h; } @@ -58,17 +57,30 @@ memcpy (data [0], copy.data [0], sizeof (cell) * h * w); } -layout::~layout () +layout::layout (layout &orig, int x1, int y1, int x2, int y2) { - int size = (sizeof (cell *) + sizeof (cell) * h) * w; + w = x2 - x1; + h = y2 - y1; + // we only allocate space for the pointers + size = sizeof (cell *) * w; + data = (cell **)salloc (size); + + // and now we point back into the original layout + for (int x = 0; x < w; ++x) + data [x] = orig.data [x + x1] + y1; +} + +layout::~layout () +{ sfree ((char *)data, size); } void layout::fill (char fill) { - memset (data [0], fill, w * h); + //memset (data [0], fill, w * h); // only when contiguous :/ + fill_rect (0, 0, w, h, fill); } void @@ -803,6 +815,48 @@ ///////////////////////////////////////////////////////////////////////////// +static void +gen_mixed_ (layout &maze, random_map_params *RP, int dir) +{ + if (maze.w < 20 && maze.h < 20 && !rmg_rndm (3)) + dir = 2; // stop recursion randomly + + if (dir == 0 && maze.w > 16) + { + int m = rmg_rndm (8, maze.w - 8); + + layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP, !dir); + layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP, !dir); + } + else if (dir == 1 && maze.h > 16) + { + int m = rmg_rndm (8, maze.h - 8); + + layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP, !dir); + layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP, !dir); + } + else + { + RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1; + + if (RP->map_layout_style == LAYOUT_MULTIPLE) + ++RP->map_layout_style; + + maze.generate (RP); + } +} + +static void +gen_mixed (layout &maze, random_map_params *RP) +{ + random_map_params &rp = *new random_map_params (RP); + gen_mixed_ (maze, &rp, rmg_rndm (2)); + delete &rp; + + maze.border (); + maze.isolation_remover (); +} + /* function selects the maze function and gives it whatever arguments it needs. */ void @@ -871,21 +925,13 @@ break; + case LAYOUT_MULTIPLE: + gen_mixed (*this, RP); + break; + default: abort (); } - - /* rotate the maze randomly */ - rotate (rmg_rndm (4)); - - symmetrize (RP->symmetry_used); - -#if 0 - print ();//D -#endif - - if (RP->expand2x) - expand2x (); } //-GPL