--- deliantra/server/random_maps/random_map.h 2010/03/26 00:59:21 1.22 +++ deliantra/server/random_maps/random_map.h 2010/06/30 20:51:02 1.29 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2001 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen * @@ -27,23 +27,17 @@ #include "util.h" -struct random_map_params +struct random_map_params : zero_initialised { - char wallstyle[512]; char wall_name[512]; - char floorstyle[512]; char monsterstyle[512]; - char treasurestyle[512]; char layoutstyle[512]; char doorstyle[512]; - char decorstyle[512]; shstr origin_map; shstr final_map; - char exitstyle[512]; shstr this_map; char exit_on_final_map[512]; - char *custom; - + int xsize, ysize; int expand2x; int layoutoptions1; @@ -57,21 +51,41 @@ int dungeon_level; int dungeon_depth; - int decoroptions; int orientation; - int origin_y; int origin_x; + int origin_y; uint32_t random_seed; uint64_t total_map_hp; int map_layout_style; - int treasureoptions; 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; + + // fetch something from the options hash + 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 char *option, int value) const { set (option, (IV)value); } + // "private", adjusted sizes int Xsize; int Ysize; + + ~random_map_params (); }; enum { @@ -138,7 +152,7 @@ // . ?? (rogue) // -struct LayoutData : zero_initialised +struct LayoutData { char **col; int w, h; @@ -151,8 +165,14 @@ return col; } - void clear (char fill = 0); + 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 @@ -194,6 +214,96 @@ ::swap (layout.ptr->w , ptr->w ); ::swap (layout.ptr->h , ptr->h ); } + + // for debugging, print layout to stdout + void print (); +}; + +// 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; +} + +struct point +{ + short x; + short y; + + point () + { + } + + point (int x, int y) + : x(x), y(y) + { + } +}; + +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