ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/random_map.h
(Generate patch)

Comparing deliantra/server/random_maps/random_map.h (file contents):
Revision 1.29 by root, Wed Jun 30 20:51:02 2010 UTC vs.
Revision 1.37 by root, Sat Jul 3 00:39:57 2010 UTC

94 LAYOUT_MAZE, 94 LAYOUT_MAZE,
95 LAYOUT_SPIRAL, 95 LAYOUT_SPIRAL,
96 LAYOUT_ROGUELIKE, 96 LAYOUT_ROGUELIKE,
97 LAYOUT_SNAKE, 97 LAYOUT_SNAKE,
98 LAYOUT_SQUARE_SPIRAL, 98 LAYOUT_SQUARE_SPIRAL,
99 LAYOUT_CAVE,
99 NROFLAYOUTS, 100 NROFLAYOUTS,
100}; 101};
101 102
102/* 103/*
103 * Move these defines out of room_gen_onion.c to here, as 104 * Move these defines out of room_gen_onion.c to here, as
139// 12 has been experimentally :( determined ot be a lot more stable 140// 12 has been experimentally :( determined ot be a lot more stable
140// than 11 or 10, leading to the assumption that something inherently 141// than 11 or 10, leading to the assumption that something inherently
141// needs a minimum size of at least 12 142// needs a minimum size of at least 12
142#define MIN_RANDOM_MAP_SIZE 12 143#define MIN_RANDOM_MAP_SIZE 12
143 144
145// we often use signed chars for coordinates (and U8 for distances)
146#define MAX_RANDOM_MAP_SIZE 120
147
144// reference 148// reference
145// 149//
146// \0 floor only 150// \0 floor only
147// # wall 151// # wall
148// D door 152// D door
149// < up 153// < up
150// > down 154// > down
151// C "center" (of onion layout) 155// C "center" (of onion maze)
152// . ?? (rogue) 156// . ?? (rogue)
153// 157//
154 158
159// use this in new code
160INTERFACE_CLASS(layout)
155struct LayoutData 161struct layout
156{ 162{
157 char **col; 163 typedef char cell;
164
165 cell **data;
158 int w, h; 166 int w, h;
159 167
160 LayoutData (int w, int h); 168 layout (int w, int h);
169 layout (layout &copy);
161 ~LayoutData (); 170 ~layout ();
162 171
163 operator char **() 172 operator cell **() const
164 { 173 {
165 return col; 174 return data;
166 } 175 }
167 176
177 void swap (layout &maze)
178 {
179 ::swap (maze.data, data);
180 ::swap (maze.w , w );
181 ::swap (maze.h , h );
182 }
183
184 MTH void swap (layout *maze) { swap (*maze); }
185
186 // for debugging, print maze to stdout
187 MTH void print () const;
188
189 // simple inpainting
168 void fill (char fill); 190 MTH void fill (char fill);
169 void clear () { fill (0); } 191 MTH void clear () { fill (0); }
170 void border (char fill = '#'); 192 MTH void border (char fill = '#');
171 void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive 193 MTH void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive
194 MTH void fill_rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive
172 195
173 // makes sure all areas are connected. dirty=true carves rounder but also 196 MTH void fill_rand (int perc);
174 // mroe walls, dirty=false carves narrow corridors. 197
198 // makes sure all areas are connected
175 void isolation_remover (bool dirty = 0); 199 MTH void isolation_remover ();
176};
177 200
178struct Layout 201 // generates a cave, subtype 0 is a rough cave, randomly open or closed
179{ 202 MTH void gen_cave (int subtype);
180 LayoutData *ptr;
181 203
182 Layout () 204 // helper functions to modify the maze
183 { 205 MTH void erode_1_2 (int c1, int c2 = -1, int repeat = 1);
184 } 206 MTH void doorify ();
207 MTH void roomify (); // make some rooms in it, works best on onions
208 MTH void expand2x ();
209 MTH void symmetrize (int symmetry);
210 MTH void rotate (int rotation); // rotate by 1=90, 2=180, 3=270 degrees
185 211
186 Layout (int xsize, int ysize)
187 : ptr (new LayoutData (xsize, ysize))
188 {
189 }
190
191 Layout (random_map_params *RP) 212 void generate (random_map_params *RP);
192 : ptr (new LayoutData (RP->Xsize, RP->Ysize)) 213private:
193 { 214 void alloc (int w, int h);
194 }
195
196 void free ()
197 {
198 delete ptr;
199 }
200
201 LayoutData *operator ->() const
202 {
203 return ptr;
204 }
205
206 operator char **() const
207 {
208 return *ptr;
209 }
210
211 void swap (const Layout &layout) const
212 {
213 ::swap (layout.ptr->col, ptr->col);
214 ::swap (layout.ptr->w , ptr->w );
215 ::swap (layout.ptr->h , ptr->h );
216 }
217
218 // for debugging, print layout to stdout
219 void print ();
220}; 215};
221 216
222// utility functions, to use rmg_rndm instead of rndm. 217// utility functions, to use rmg_rndm instead of rndm.
223static inline int 218static inline int
224rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) 219rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop)
227 int i = find_free_spot (ob, m, x, y, start, stop); 222 int i = find_free_spot (ob, m, x, y, start, stop);
228 swap (rmg_rndm, rndm); 223 swap (rmg_rndm, rndm);
229 return i; 224 return i;
230} 225}
231 226
227// a simple point helper struct
232struct point 228struct point
233{ 229{
234 short x; 230 short x;
235 short y; 231 short y;
236 232
242 : x(x), y(y) 238 : x(x), y(y)
243 { 239 {
244 } 240 }
245}; 241};
246 242
243// something like a vector or stack, but without
244// out of bounds checking
247template<typename T> 245template<typename T>
248struct fixed_stack 246struct fixed_stack
249{ 247{
250 T *data; 248 T *data;
251 int size; 249 int size;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines