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