--- deliantra/server/random_maps/random_map.h 2010/06/30 23:03:40 1.30 +++ deliantra/server/random_maps/random_map.h 2010/07/03 00:39:57 1.37 @@ -142,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 @@ -149,89 +152,66 @@ // D door // < up // > down -// C "center" (of onion layout) +// C "center" (of onion maze) // . ?? (rogue) // // use this in new code -struct LayoutData +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; } - // for debugging, print layout to stdout - void print (); - - // simple inpainting - 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 - - void fill_rand (int perc); - - // makes sure all areas are connected. dirty=true carves rounder but also - // more walls, dirty=false carves narrow corridors. - void isolation_remover (bool dirty = 0); - - // generates a cave, subtype 0 is a rough cave, randomly open or closed - void gen_cave (int subtype); - void erode_1_2 (int c1, int c2 = -1, int repeat = 1); - - void swap (LayoutData &layout) + void swap (layout &maze) { - ::swap (layout.col, col); - ::swap (layout.w , w ); - ::swap (layout.h , h ); + ::swap (maze.data, data); + ::swap (maze.w , w ); + ::swap (maze.h , h ); } -}; - -// basically a layoutdata point - do not use in new code -struct Layout -{ - LayoutData *ptr; - Layout () - { - } + MTH void swap (layout *maze) { swap (*maze); } - Layout (int xsize, int ysize) - : ptr (new LayoutData (xsize, ysize)) - { - } + // for debugging, print maze to stdout + MTH void print () const; - Layout (random_map_params *RP) - : ptr (new LayoutData (RP->Xsize, RP->Ysize)) - { - } + // 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 - void free () - { - delete ptr; - } + MTH void fill_rand (int perc); - LayoutData *operator ->() const - { - return ptr; - } + // makes sure all areas are connected + MTH void isolation_remover (); - operator char **() const - { - return *ptr; - } + // generates a cave, subtype 0 is a rough cave, randomly open or closed + MTH void gen_cave (int subtype); - void swap (Layout &layout) - { - ::swap (layout.ptr, ptr); - } + // 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 + + void generate (random_map_params *RP); +private: + void alloc (int w, int h); }; // utility functions, to use rmg_rndm instead of rndm.