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