… | |
… | |
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 |
|
|
160 | INTERFACE_CLASS(layout) |
155 | struct LayoutData |
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 | |
|
|
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 |
168 | void fill (char fill); |
185 | MTH void fill (char fill); |
169 | void clear () { fill (0); } |
186 | MTH void clear () { fill (0); } |
170 | void border (char fill = '#'); |
187 | MTH void border (char fill = '#'); |
171 | void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive |
188 | MTH void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive |
|
|
189 | |
|
|
190 | MTH void fill_rand (int perc); |
172 | |
191 | |
173 | // makes sure all areas are connected. dirty=true carves rounder but also |
192 | // makes sure all areas are connected. dirty=true carves rounder but also |
174 | // mroe walls, dirty=false carves narrow corridors. |
193 | // more walls, dirty=false carves narrow corridors. |
175 | void isolation_remover (bool dirty = 0); |
194 | MTH void isolation_remover (bool dirty = 0); |
176 | }; |
|
|
177 | |
195 | |
178 | struct Layout |
196 | // generates a cave, subtype 0 is a rough cave, randomly open or closed |
179 | { |
197 | MTH void gen_cave (int subtype); |
180 | LayoutData *ptr; |
|
|
181 | |
198 | |
182 | Layout () |
199 | // helper functions to modify the maze |
183 | { |
200 | MTH void erode_1_2 (int c1, int c2 = -1, int repeat = 1); |
184 | } |
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 |
185 | |
206 | |
186 | Layout (int xsize, int ysize) |
|
|
187 | : ptr (new LayoutData (xsize, ysize)) |
|
|
188 | { |
|
|
189 | } |
|
|
190 | |
|
|
191 | Layout (random_map_params *RP) |
207 | void generate (random_map_params *RP); |
192 | : ptr (new LayoutData (RP->Xsize, RP->Ysize)) |
|
|
193 | { |
|
|
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 | }; |
208 | }; |
221 | |
209 | |
222 | // utility functions, to use rmg_rndm instead of rndm. |
210 | // utility functions, to use rmg_rndm instead of rndm. |
223 | static inline int |
211 | static inline int |
224 | 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) |
… | |
… | |
227 | int i = find_free_spot (ob, m, x, y, start, stop); |
215 | int i = find_free_spot (ob, m, x, y, start, stop); |
228 | swap (rmg_rndm, rndm); |
216 | swap (rmg_rndm, rndm); |
229 | return i; |
217 | return i; |
230 | } |
218 | } |
231 | |
219 | |
|
|
220 | // a simple point helper struct |
232 | struct point |
221 | struct point |
233 | { |
222 | { |
234 | short x; |
223 | short x; |
235 | short y; |
224 | short y; |
236 | |
225 | |
… | |
… | |
242 | : x(x), y(y) |
231 | : x(x), y(y) |
243 | { |
232 | { |
244 | } |
233 | } |
245 | }; |
234 | }; |
246 | |
235 | |
|
|
236 | // something like a vector or stack, but without |
|
|
237 | // out of bounds checking |
247 | template<typename T> |
238 | template<typename T> |
248 | struct fixed_stack |
239 | struct fixed_stack |
249 | { |
240 | { |
250 | T *data; |
241 | T *data; |
251 | int size; |
242 | int size; |