--- deliantra/server/random_maps/random_map.h 2010/06/30 20:51:02 1.29 +++ deliantra/server/random_maps/random_map.h 2010/07/03 00:39:57 1.37 @@ -96,6 +96,7 @@ LAYOUT_ROGUELIKE, LAYOUT_SNAKE, LAYOUT_SQUARE_SPIRAL, + LAYOUT_CAVE, NROFLAYOUTS, }; @@ -141,6 +142,9 @@ // needs a minimum size of at least 12 #define MIN_RANDOM_MAP_SIZE 12 +// we often use signed chars for coordinates (and U8 for distances) +#define MAX_RANDOM_MAP_SIZE 120 + // reference // // \0 floor only @@ -148,75 +152,66 @@ // D door // < up // > down -// C "center" (of onion layout) +// C "center" (of onion maze) // . ?? (rogue) // -struct LayoutData +// use this in new code +INTERFACE_CLASS(layout) +struct layout { - char **col; + typedef char cell; + + cell **data; int w, h; - LayoutData (int w, int h); - ~LayoutData (); + layout (int w, int h); + layout (layout ©); + ~layout (); - operator char **() + operator cell **() const { - return col; + return data; } - void fill (char fill); - void clear () { fill (0); } - void border (char fill = '#'); - void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive - - // makes sure all areas are connected. dirty=true carves rounder but also - // mroe walls, dirty=false carves narrow corridors. - void isolation_remover (bool dirty = 0); -}; - -struct Layout -{ - LayoutData *ptr; - - Layout () + void swap (layout &maze) { + ::swap (maze.data, data); + ::swap (maze.w , w ); + ::swap (maze.h , h ); } - Layout (int xsize, int ysize) - : ptr (new LayoutData (xsize, ysize)) - { - } + MTH void swap (layout *maze) { swap (*maze); } - Layout (random_map_params *RP) - : ptr (new LayoutData (RP->Xsize, RP->Ysize)) - { - } + // for debugging, print maze to stdout + MTH void print () const; - void free () - { - delete ptr; - } + // simple inpainting + MTH void fill (char fill); + MTH void clear () { fill (0); } + MTH void border (char fill = '#'); + MTH void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive + MTH void fill_rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive - LayoutData *operator ->() const - { - return ptr; - } + MTH void fill_rand (int perc); - operator char **() const - { - return *ptr; - } + // makes sure all areas are connected + MTH void isolation_remover (); - void swap (const Layout &layout) const - { - ::swap (layout.ptr->col, ptr->col); - ::swap (layout.ptr->w , ptr->w ); - ::swap (layout.ptr->h , ptr->h ); - } + // generates a cave, subtype 0 is a rough cave, randomly open or closed + MTH void gen_cave (int subtype); + + // helper functions to modify the maze + MTH void erode_1_2 (int c1, int c2 = -1, int repeat = 1); + MTH void doorify (); + MTH void roomify (); // make some rooms in it, works best on onions + MTH void expand2x (); + MTH void symmetrize (int symmetry); + MTH void rotate (int rotation); // rotate by 1=90, 2=180, 3=270 degrees - // for debugging, print layout to stdout - void print (); + void generate (random_map_params *RP); +private: + void alloc (int w, int h); }; // utility functions, to use rmg_rndm instead of rndm. @@ -229,6 +224,7 @@ return i; } +// a simple point helper struct struct point { short x; @@ -244,6 +240,8 @@ } }; +// something like a vector or stack, but without +// out of bounds checking template struct fixed_stack {