--- deliantra/server/random_maps/random_map.h 2010/06/26 23:53:31 1.27 +++ deliantra/server/random_maps/random_map.h 2010/07/03 03:09:27 1.41 @@ -30,15 +30,6 @@ struct random_map_params : zero_initialised { char wall_name[512]; - char monsterstyle[512]; - char treasurestyle[512]; - char layoutstyle[512]; - char doorstyle[512]; - char decorstyle[512]; - shstr origin_map; - shstr final_map; - shstr this_map; - char exit_on_final_map[512]; int xsize, ysize; int expand2x; @@ -53,31 +44,38 @@ int dungeon_level; int dungeon_depth; - int decoroptions; int orientation; - int origin_y; - int origin_x; uint32_t random_seed; uint64_t total_map_hp; int map_layout_style; - int treasureoptions; int symmetry_used; - struct region *region; - HV *hv; + shstr_tmp as_shstr () const; + // fetch something from the options hash - const_utf8_string get_str (const_utf8_string option, const_utf8_string fallback = "") const; - IV get_iv (const_utf8_string option, IV fallback = 0) const; + SV *get_sv (const char *option) const; + const_utf8_string get_str (const char *option, const_utf8_string fallback = "") const; + IV get_iv (const char *option, IV fallback = 0) const; + UV get_uv (const char *option, UV fallback = 0) const; + NV get_nv (const char *option, NV fallback = 0) const; + + void set (const char *option, SV *value) const; + void set (const char *option, const_utf8_string value) const; + void set (const char *option, IV value) const; + void set (const char *option, UV value) const; + void set (const char *option, NV value) const; - void set (const_utf8_string option, const_utf8_string value); - void set (const_utf8_string option, IV value); + void set (const char *option, int value) const { set (option, (IV)value); } // "private", adjusted sizes int Xsize; int Ysize; + random_map_params (); + random_map_params (random_map_params *RP); + random_map_params (HV *hv); ~random_map_params (); }; @@ -89,6 +87,8 @@ LAYOUT_ROGUELIKE, LAYOUT_SNAKE, LAYOUT_SQUARE_SPIRAL, + LAYOUT_CAVE, + LAYOUT_MULTIPLE, NROFLAYOUTS, }; @@ -134,6 +134,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 @@ -141,80 +144,164 @@ // D door // < up // > down -// C "center" (of onion layout) +// C "center" (of onion maze) // . ?? (rogue) // -struct LayoutData : zero_initialised +// 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 ©); + + // 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); + + ~layout (); - operator char **() + operator cell **() const { - return col; + return data; } - void clear (char fill = 0); - void border (char fill = '#'); + void swap (layout &maze) + { + ::swap (maze.data, data); + ::swap (maze.w , w ); + ::swap (maze.h , h ); + ::swap (maze.size, size); + } + + MTH void swap (layout *maze) { swap (*maze); } + + // for debugging, print maze to stdout + MTH void print () const; + + // 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); + + // makes sure all areas are connected + MTH void isolation_remover (); + + // 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 + + void generate (random_map_params *RP); +private: + int size; + void alloc (int w, int h); }; -struct Layout +// utility functions, to use rmg_rndm instead of rndm. +static inline int +rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) +{ + swap (rmg_rndm, rndm); + int i = find_free_spot (ob, m, x, y, start, stop); + swap (rmg_rndm, rndm); + return i; +} + +// a simple point helper struct +struct point { - LayoutData *ptr; + short x; + short y; - Layout () + point () { } - Layout (int xsize, int ysize) - : ptr (new LayoutData (xsize, ysize)) + point (int x, int y) + : x(x), y(y) { } +}; + +// something like a vector or stack, but without +// out of bounds checking +template +struct fixed_stack +{ + T *data; + int size; + int max; - Layout (random_map_params *RP) - : ptr (new LayoutData (RP->Xsize, RP->Ysize)) + fixed_stack () + : size (0), data (0) { } + fixed_stack (int max) + : size (0), max (max) + { + data = salloc (max); + } + + void reset (int new_max) + { + sfree (data, max); + size = 0; + max = new_max; + data = salloc (max); + } + void free () { - delete ptr; + sfree (data, max); + data = 0; } - LayoutData *operator ->() const + ~fixed_stack () { - return ptr; + sfree (data, max); } - operator char **() const + T &operator[](int idx) { - return *ptr; + return data [idx]; } - void swap (const Layout &layout) const + void push (T v) { - ::swap (layout.ptr->col, ptr->col); - ::swap (layout.ptr->w , ptr->w ); - ::swap (layout.ptr->h , ptr->h ); + data [size++] = v; } - // for debugging, print layout to stdout - void print (); -}; + T &pop () + { + return data [--size]; + } -// utility functions, to use rmg_rndm instead of rndm. -static inline int -rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) -{ - swap (rmg_rndm, rndm); - int i = find_free_spot (ob, m, x, y, start, stop); - swap (rmg_rndm, rndm); - return i; -} + T remove (int idx) + { + T v = data [idx]; + + data [idx] = data [--size]; + + return v; + } +}; #endif