… | |
… | |
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 |
… | |
… | |
150 | // > down |
154 | // > down |
151 | // C "center" (of onion layout) |
155 | // C "center" (of onion layout) |
152 | // . ?? (rogue) |
156 | // . ?? (rogue) |
153 | // |
157 | // |
154 | |
158 | |
155 | struct LayoutData : zero_initialised |
159 | // use this in new code |
|
|
160 | struct Layout |
156 | { |
161 | { |
157 | char **col; |
162 | char **col; |
158 | int w, h; |
163 | int w, h; |
159 | |
164 | |
160 | LayoutData (int w, int h); |
165 | Layout (int w, int h); |
161 | ~LayoutData (); |
166 | ~Layout (); |
162 | |
167 | |
163 | operator char **() |
168 | operator char **() const |
164 | { |
169 | { |
165 | return col; |
170 | return col; |
166 | } |
171 | } |
167 | |
172 | |
|
|
173 | void swap (Layout &layout) |
|
|
174 | { |
|
|
175 | ::swap (layout.col, col); |
|
|
176 | ::swap (layout.w , w ); |
|
|
177 | ::swap (layout.h , h ); |
|
|
178 | } |
|
|
179 | |
|
|
180 | // for debugging, print layout to stdout |
|
|
181 | void print () const; |
|
|
182 | |
|
|
183 | // simple inpainting |
|
|
184 | void fill (char fill); |
168 | void clear (char fill = 0); |
185 | void clear () { fill (0); } |
169 | void border (char fill = '#'); |
186 | void border (char fill = '#'); |
170 | }; |
187 | void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive |
171 | |
188 | |
172 | struct Layout |
189 | void fill_rand (int perc); |
173 | { |
|
|
174 | LayoutData *ptr; |
|
|
175 | |
190 | |
176 | Layout () |
191 | // makes sure all areas are connected. dirty=true carves rounder but also |
177 | { |
192 | // more walls, dirty=false carves narrow corridors. |
178 | } |
193 | void isolation_remover (bool dirty = 0); |
179 | |
194 | |
180 | Layout (int xsize, int ysize) |
195 | // generates a cave, subtype 0 is a rough cave, randomly open or closed |
181 | : ptr (new LayoutData (xsize, ysize)) |
196 | void gen_cave (int subtype); |
182 | { |
|
|
183 | } |
|
|
184 | |
197 | |
|
|
198 | // helper functions to modify the layout |
|
|
199 | void erode_1_2 (int c1, int c2 = -1, int repeat = 1); |
|
|
200 | void doorify (); |
|
|
201 | void roomify (); // make some rooms in it, works best on onions |
|
|
202 | void expand2x (); |
|
|
203 | void symmetrize (int symmetry); |
|
|
204 | void rotate (int rotation); // rotate by 1=90, 2=180, 3=270 degrees |
|
|
205 | |
185 | Layout (random_map_params *RP) |
206 | void generate (random_map_params *RP); |
186 | : ptr (new LayoutData (RP->Xsize, RP->Ysize)) |
|
|
187 | { |
|
|
188 | } |
|
|
189 | |
|
|
190 | void free () |
|
|
191 | { |
|
|
192 | delete ptr; |
|
|
193 | } |
|
|
194 | |
|
|
195 | LayoutData *operator ->() const |
|
|
196 | { |
|
|
197 | return ptr; |
|
|
198 | } |
|
|
199 | |
|
|
200 | operator char **() const |
|
|
201 | { |
|
|
202 | return *ptr; |
|
|
203 | } |
|
|
204 | |
|
|
205 | void swap (const Layout &layout) const |
|
|
206 | { |
|
|
207 | ::swap (layout.ptr->col, ptr->col); |
|
|
208 | ::swap (layout.ptr->w , ptr->w ); |
|
|
209 | ::swap (layout.ptr->h , ptr->h ); |
|
|
210 | } |
|
|
211 | |
|
|
212 | // for debugging, print layout to stdout |
|
|
213 | void print (); |
|
|
214 | }; |
207 | }; |
215 | |
208 | |
216 | // utility functions, to use rmg_rndm instead of rndm. |
209 | // utility functions, to use rmg_rndm instead of rndm. |
217 | static inline int |
210 | static inline int |
218 | rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |
211 | rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |
… | |
… | |
221 | int i = find_free_spot (ob, m, x, y, start, stop); |
214 | int i = find_free_spot (ob, m, x, y, start, stop); |
222 | swap (rmg_rndm, rndm); |
215 | swap (rmg_rndm, rndm); |
223 | return i; |
216 | return i; |
224 | } |
217 | } |
225 | |
218 | |
|
|
219 | // a simple point helper struct |
|
|
220 | struct point |
|
|
221 | { |
|
|
222 | short x; |
|
|
223 | short y; |
|
|
224 | |
|
|
225 | point () |
|
|
226 | { |
|
|
227 | } |
|
|
228 | |
|
|
229 | point (int x, int y) |
|
|
230 | : x(x), y(y) |
|
|
231 | { |
|
|
232 | } |
|
|
233 | }; |
|
|
234 | |
|
|
235 | // something like a vector or stack, but without |
|
|
236 | // out of bounds checking |
|
|
237 | template<typename T> |
|
|
238 | struct fixed_stack |
|
|
239 | { |
|
|
240 | T *data; |
|
|
241 | int size; |
|
|
242 | int max; |
|
|
243 | |
|
|
244 | fixed_stack () |
|
|
245 | : size (0), data (0) |
|
|
246 | { |
|
|
247 | } |
|
|
248 | |
|
|
249 | fixed_stack (int max) |
|
|
250 | : size (0), max (max) |
|
|
251 | { |
|
|
252 | data = salloc<T> (max); |
|
|
253 | } |
|
|
254 | |
|
|
255 | void reset (int new_max) |
|
|
256 | { |
|
|
257 | sfree (data, max); |
|
|
258 | size = 0; |
|
|
259 | max = new_max; |
|
|
260 | data = salloc<T> (max); |
|
|
261 | } |
|
|
262 | |
|
|
263 | void free () |
|
|
264 | { |
|
|
265 | sfree (data, max); |
|
|
266 | data = 0; |
|
|
267 | } |
|
|
268 | |
|
|
269 | ~fixed_stack () |
|
|
270 | { |
|
|
271 | sfree (data, max); |
|
|
272 | } |
|
|
273 | |
|
|
274 | T &operator[](int idx) |
|
|
275 | { |
|
|
276 | return data [idx]; |
|
|
277 | } |
|
|
278 | |
|
|
279 | void push (T v) |
|
|
280 | { |
|
|
281 | data [size++] = v; |
|
|
282 | } |
|
|
283 | |
|
|
284 | T &pop () |
|
|
285 | { |
|
|
286 | return data [--size]; |
|
|
287 | } |
|
|
288 | |
|
|
289 | T remove (int idx) |
|
|
290 | { |
|
|
291 | T v = data [idx]; |
|
|
292 | |
|
|
293 | data [idx] = data [--size]; |
|
|
294 | |
|
|
295 | return v; |
|
|
296 | } |
|
|
297 | }; |
|
|
298 | |
226 | #endif |
299 | #endif |
227 | |
300 | |