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