--- deliantra/server/random_maps/random_map.h 2010/06/30 23:03:40 1.30 +++ deliantra/server/random_maps/random_map.h 2010/07/05 00:07:21 1.45 @@ -30,20 +30,12 @@ struct random_map_params : zero_initialised { char wall_name[512]; - char monsterstyle[512]; - char layoutstyle[512]; - char doorstyle[512]; - shstr origin_map; - shstr final_map; - shstr this_map; - char exit_on_final_map[512]; int xsize, ysize; int expand2x; int layoutoptions1; int layoutoptions2; int layoutoptions3; - int symmetry; int difficulty; int difficulty_given; float difficulty_increase; @@ -51,18 +43,10 @@ int dungeon_level; int dungeon_depth; - int orientation; - int origin_x; - int origin_y; uint32_t random_seed; uint64_t total_map_hp; - int map_layout_style; - int symmetry_used; - - struct region *region; HV *hv; - void hv_clone (); // replaces the hv by a clone'd copy (%new_hv = { %hv }) shstr_tmp as_shstr () const; @@ -85,6 +69,12 @@ int Xsize; int Ysize; + int map_layout_style; + int symmetry_used; + + random_map_params (); + random_map_params (random_map_params *RP); + random_map_params (HV *hv); ~random_map_params (); }; @@ -97,6 +87,8 @@ LAYOUT_SNAKE, LAYOUT_SQUARE_SPIRAL, LAYOUT_CAVE, + LAYOUT_CASTLE, + LAYOUT_MULTIPLE, NROFLAYOUTS, }; @@ -142,96 +134,107 @@ // 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 + +// a simple point helper struct +struct point +{ + int x; + int y; + + point () + { + } + + point (int x, int y) + : x(x), y(y) + { + } +}; + +// // reference // // \0 floor only // # wall // D door -// < up -// > down -// C "center" (of onion layout) +// < entrance (traditionally up) +// > exit (traditionally down) +// C "center" (of onion maze) // . ?? (rogue) // // use this in new code -struct LayoutData +INTERFACE_CLASS(layout) +struct layout { - char **col; - int w, h; - - LayoutData (int w, int h); - ~LayoutData (); + typedef char cell; - operator char **() - { - return col; - } + cell **data; + int w, h; - // for debugging, print layout to stdout - void print (); + layout (int w, int h); + layout (layout ©); - // 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); + // reference rect in other layout - will not keep the data alive, + // so never swap with it's orig, or free the orig when in use. + layout (layout &orig, int x1, int y1, int x2, int y2); - // 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); + ~layout (); - void swap (LayoutData &layout) + operator cell **() const { - ::swap (layout.col, col); - ::swap (layout.w , w ); - ::swap (layout.h , h ); + return data; } -}; -// basically a layoutdata point - do not use in new code -struct Layout -{ - LayoutData *ptr; - - Layout () - { - } - - Layout (int xsize, int ysize) - : ptr (new LayoutData (xsize, ysize)) + void swap (layout &maze) { + ::swap (maze.data, data); + ::swap (maze.w , w ); + ::swap (maze.h , h ); + ::swap (maze.size, size); } - Layout (random_map_params *RP) - : ptr (new LayoutData (RP->Xsize, RP->Ysize)) - { - } + MTH void swap (layout *maze) { swap (*maze); } - void free () - { - delete ptr; - } + // for debugging, print maze to stdout + MTH void print () const; - LayoutData *operator ->() const - { - return 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 + + MTH void fill_rand (int perc); + MTH void replace (char from, char to); + + point find (char target, int mode = 0); // mode 0=random, 1=upleft, 2=upright, 3=downright, 4=downleft + + // makes sure all areas are connected + // perturb = 0 - very horz/vert tunnels + // perturb = 1 - straight but round + // perturb = 2 - snaky tunnels + MTH void isolation_remover (int perturb = 2); - operator char **() const - { - return *ptr; - } + // generates a cave, subtype 0 is a rough cave, randomly open or closed + MTH void gen_cave (int subtype); + MTH void gen_castle (); // generates straightish structures - 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: + int size; + void alloc (int w, int h); }; // utility functions, to use rmg_rndm instead of rndm. @@ -244,22 +247,6 @@ return i; } -// a simple point helper struct -struct point -{ - short x; - short y; - - point () - { - } - - point (int x, int y) - : x(x), y(y) - { - } -}; - // something like a vector or stack, but without // out of bounds checking template