… | |
… | |
140 | // 12 has been experimentally :( determined ot be a lot more stable |
140 | // 12 has been experimentally :( determined ot be a lot more stable |
141 | // than 11 or 10, leading to the assumption that something inherently |
141 | // than 11 or 10, leading to the assumption that something inherently |
142 | // needs a minimum size of at least 12 |
142 | // needs a minimum size of at least 12 |
143 | #define MIN_RANDOM_MAP_SIZE 12 |
143 | #define MIN_RANDOM_MAP_SIZE 12 |
144 | |
144 | |
|
|
145 | // we often use signed chars for coordinates (and U8 for distances) |
|
|
146 | #define MAX_RANDOM_MAP_SIZE 120 |
|
|
147 | |
145 | // reference |
148 | // reference |
146 | // |
149 | // |
147 | // \0 floor only |
150 | // \0 floor only |
148 | // # wall |
151 | // # wall |
149 | // D door |
152 | // D door |
150 | // < up |
153 | // < up |
151 | // > down |
154 | // > down |
152 | // C "center" (of onion layout) |
155 | // C "center" (of onion maze) |
153 | // . ?? (rogue) |
156 | // . ?? (rogue) |
154 | // |
157 | // |
155 | |
158 | |
156 | // use this in new code |
159 | // use this in new code |
|
|
160 | INTERFACE_CLASS(layout) |
157 | struct LayoutData |
161 | struct layout |
158 | { |
162 | { |
159 | char **col; |
163 | typedef char cell; |
|
|
164 | |
|
|
165 | cell **data; |
160 | int w, h; |
166 | int w, h; |
161 | |
167 | |
162 | LayoutData (int w, int h); |
168 | layout (int w, int h); |
|
|
169 | layout (layout ©); |
163 | ~LayoutData (); |
170 | ~layout (); |
164 | |
171 | |
165 | operator char **() |
172 | operator cell **() const |
166 | { |
173 | { |
167 | return col; |
174 | return data; |
168 | } |
175 | } |
169 | |
176 | |
|
|
177 | void swap (layout &maze) |
|
|
178 | { |
|
|
179 | ::swap (maze.data, data); |
|
|
180 | ::swap (maze.w , w ); |
|
|
181 | ::swap (maze.h , h ); |
|
|
182 | } |
|
|
183 | |
|
|
184 | MTH void swap (layout *maze) { swap (*maze); } |
|
|
185 | |
170 | // for debugging, print layout to stdout |
186 | // for debugging, print maze to stdout |
171 | void print (); |
187 | MTH void print () const; |
172 | |
188 | |
173 | // simple inpainting |
189 | // simple inpainting |
174 | void fill (char fill); |
190 | MTH void fill (char fill); |
175 | void clear () { fill (0); } |
191 | MTH void clear () { fill (0); } |
176 | void border (char fill = '#'); |
192 | MTH void border (char fill = '#'); |
177 | void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive |
193 | MTH void rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive |
|
|
194 | MTH void fill_rect (int x1, int y1, int x2, int y2, char fill); // x2, y2 exclusive |
178 | |
195 | |
179 | void fill_rand (int perc); |
196 | MTH void fill_rand (int perc); |
180 | |
197 | |
181 | // makes sure all areas are connected. dirty=true carves rounder but also |
198 | // makes sure all areas are connected |
182 | // more walls, dirty=false carves narrow corridors. |
|
|
183 | void isolation_remover (bool dirty = 0); |
199 | MTH void isolation_remover (); |
184 | |
200 | |
185 | // generates a cave, subtype 0 is a rough cave, randomly open or closed |
201 | // generates a cave, subtype 0 is a rough cave, randomly open or closed |
186 | void gen_cave (int subtype); |
202 | MTH void gen_cave (int subtype); |
|
|
203 | |
|
|
204 | // helper functions to modify the maze |
187 | void erode_1_2 (int c1, int c2 = -1, int repeat = 1); |
205 | MTH void erode_1_2 (int c1, int c2 = -1, int repeat = 1); |
|
|
206 | MTH void doorify (); |
|
|
207 | MTH void roomify (); // make some rooms in it, works best on onions |
|
|
208 | MTH void expand2x (); |
|
|
209 | MTH void symmetrize (int symmetry); |
|
|
210 | MTH void rotate (int rotation); // rotate by 1=90, 2=180, 3=270 degrees |
188 | |
211 | |
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 |
|
|
198 | struct Layout |
|
|
199 | { |
|
|
200 | LayoutData *ptr; |
|
|
201 | |
|
|
202 | Layout () |
|
|
203 | { |
|
|
204 | } |
|
|
205 | |
|
|
206 | Layout (int xsize, int ysize) |
|
|
207 | : ptr (new LayoutData (xsize, ysize)) |
|
|
208 | { |
|
|
209 | } |
|
|
210 | |
|
|
211 | Layout (random_map_params *RP) |
212 | void generate (random_map_params *RP); |
212 | : ptr (new LayoutData (RP->Xsize, RP->Ysize)) |
213 | private: |
213 | { |
214 | void alloc (int w, int h); |
214 | } |
|
|
215 | |
|
|
216 | void free () |
|
|
217 | { |
|
|
218 | delete ptr; |
|
|
219 | } |
|
|
220 | |
|
|
221 | LayoutData *operator ->() const |
|
|
222 | { |
|
|
223 | return ptr; |
|
|
224 | } |
|
|
225 | |
|
|
226 | operator char **() const |
|
|
227 | { |
|
|
228 | return *ptr; |
|
|
229 | } |
|
|
230 | |
|
|
231 | void swap (Layout &layout) |
|
|
232 | { |
|
|
233 | ::swap (layout.ptr, ptr); |
|
|
234 | } |
|
|
235 | }; |
215 | }; |
236 | |
216 | |
237 | // utility functions, to use rmg_rndm instead of rndm. |
217 | // utility functions, to use rmg_rndm instead of rndm. |
238 | static inline int |
218 | static inline int |
239 | rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |
219 | rmg_find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |