--- deliantra/server/random_maps/random_map.h 2010/07/05 00:07:21 1.45 +++ deliantra/server/random_maps/random_map.h 2010/07/06 20:00:46 1.46 @@ -26,6 +26,7 @@ #define RANDOM_MAP_H #include "util.h" +#include "layout.h" struct random_map_params : zero_initialised { @@ -137,106 +138,6 @@ // 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 -// < entrance (traditionally up) -// > exit (traditionally down) -// C "center" (of onion maze) -// . ?? (rogue) -// - -// use this in new code -INTERFACE_CLASS(layout) -struct layout -{ - typedef char cell; - - cell **data; - int w, h; - - 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 cell **() const - { - return data; - } - - 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); - 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); - - // 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 - - // 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. static inline int rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) @@ -247,69 +148,5 @@ return i; } -// something like a vector or stack, but without -// out of bounds checking -template -struct fixed_stack -{ - T *data; - int size; - int max; - - 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 () - { - sfree (data, max); - data = 0; - } - - ~fixed_stack () - { - sfree (data, max); - } - - T &operator[](int idx) - { - return data [idx]; - } - - void push (T v) - { - data [size++] = v; - } - - T &pop () - { - return data [--size]; - } - - T remove (int idx) - { - T v = data [idx]; - - data [idx] = data [--size]; - - return v; - } -}; - #endif