… | |
… | |
212 | return; |
212 | return; |
213 | |
213 | |
214 | seeds.push (point (x, y)); |
214 | seeds.push (point (x, y)); |
215 | } |
215 | } |
216 | |
216 | |
217 | static void |
217 | void |
218 | isolation_remover (Layout &maze, bool dirty) |
218 | Layout::isolation_remover (bool dirty) |
219 | { |
219 | { |
220 | Layout dist (maze.w, maze.h); |
220 | Layout dist (w, h); |
221 | |
221 | |
222 | // dist contains |
222 | // dist contains |
223 | // 0 == invisited rooms |
223 | // 0 == invisited rooms |
224 | // 1 == visited rooms |
224 | // 1 == visited rooms |
225 | // 2+ shortest distance to random near room |
225 | // 2+ shortest distance to random near room |
226 | |
226 | |
227 | // phase 1, initialise dist array, find seed |
227 | // phase 1, initialise dist array, find seed |
228 | int cnt = 0; |
228 | int cnt = 0; |
229 | int x, y; |
229 | int x, y; |
230 | |
230 | |
231 | for (int i = 0; i < maze.w; ++i) |
231 | for (int i = 0; i < w; ++i) |
232 | for (int j = 0; j < maze.h; ++j) |
232 | for (int j = 0; j < h; ++j) |
233 | { |
233 | { |
234 | if (maze [i][j] == '#') |
234 | if (col [i][j] == '#') |
235 | dist [i][j] = U8 (255); |
235 | dist [i][j] = U8 (255); |
236 | else |
236 | else |
237 | { |
237 | { |
238 | dist [i][j] = 0; |
238 | dist [i][j] = 0; |
239 | if (!rmg_rndm (++cnt)) |
239 | if (!rmg_rndm (++cnt)) |
240 | x = i, y = j; |
240 | x = i, y = j; |
241 | } |
241 | } |
242 | } |
242 | } |
243 | |
243 | |
244 | if (!cnt) |
244 | if (!cnt) |
|
|
245 | { |
|
|
246 | // map is completely massive, this is not good, |
|
|
247 | // so make it empty instead. |
|
|
248 | clear (); |
|
|
249 | border (); |
245 | return; |
250 | return; |
|
|
251 | } |
246 | |
252 | |
247 | fixed_stack<point> seeds (maze.w * maze.h * 5); |
253 | fixed_stack<point> seeds (w * h * 5); |
248 | |
254 | |
249 | // found first free space - picking the first one gives |
255 | // found first free space - picking the first one gives |
250 | // us a slight bias for tunnels, but usually you won't |
256 | // us a slight bias for tunnels, but usually you won't |
251 | // notice that in-game |
257 | // notice that in-game |
252 | seeds.push (point (x, y)); |
258 | seeds.push (point (x, y)); |
… | |
… | |
285 | if (y > 0) maybe_push (dist, seeds, x, y - 1, d); |
291 | if (y > 0) maybe_push (dist, seeds, x, y - 1, d); |
286 | } |
292 | } |
287 | } |
293 | } |
288 | |
294 | |
289 | // now copy the tunnels over |
295 | // now copy the tunnels over |
290 | for (int x = 0; x < maze.w; ++x) |
296 | for (int x = 0; x < w; ++x) |
291 | for (int y = 0; y < maze.h; ++y) |
297 | for (int y = 0; y < h; ++y) |
292 | if (maze [x][y] == '#' && dist [x][y] == 1) |
298 | if (col [x][y] == '#' && dist [x][y] == 1) |
293 | maze [x][y] = 0; |
299 | col [x][y] = 0; |
294 | } |
|
|
295 | |
|
|
296 | void |
|
|
297 | Layout::isolation_remover (bool dirty) |
|
|
298 | { |
|
|
299 | ::isolation_remover (*this, dirty); |
|
|
300 | } |
300 | } |
301 | |
301 | |
302 | ///////////////////////////////////////////////////////////////////////////// |
302 | ///////////////////////////////////////////////////////////////////////////// |
303 | |
303 | |
304 | // inspired mostly by http://www.jimrandomh.org/misc/caves.txt |
304 | // inspired mostly by http://www.jimrandomh.org/misc/caves.txt |
… | |
… | |
858 | #if 0 |
858 | #if 0 |
859 | static struct demo |
859 | static struct demo |
860 | { |
860 | { |
861 | demo () |
861 | demo () |
862 | { |
862 | { |
863 | Layout maze (40, 25); |
|
|
864 | rmg_rndm.seed (time (0)); |
863 | rmg_rndm.seed (time (0)); |
865 | |
864 | |
866 | for(int i=1;i<10;i) |
865 | for(int i=1;i<10;i) |
867 | { |
866 | { |
|
|
867 | Layout maze (10, 10); |
868 | maze.fill_rand (97); |
868 | maze.fill_rand (90); |
869 | maze.border (); |
869 | maze.border (); |
870 | maze.isolation_remover (); |
870 | maze.isolation_remover (); |
|
|
871 | maze.doorify (); |
|
|
872 | maze.symmetrize (rmg_rndm (2, 4)); |
|
|
873 | maze.rotate (rmg_rndm (4)); |
|
|
874 | maze.expand2x (); |
871 | maze.print (); |
875 | maze.print (); |
872 | } |
876 | } |
873 | |
877 | |
874 | exit (1); |
878 | exit (1); |
875 | } |
879 | } |