… | |
… | |
221 | if (x > 1 && U8 (dist [x - 1][y]) <= d && dist [x - 1][y] > 1) neigh [ncnt++] = point (x - 1, y); |
221 | if (x > 1 && U8 (dist [x - 1][y]) <= d && dist [x - 1][y] > 1) neigh [ncnt++] = point (x - 1, y); |
222 | if (x < dist.w - 2 && U8 (dist [x + 1][y]) <= d && dist [x + 1][y] > 1) neigh [ncnt++] = point (x + 1, y); |
222 | if (x < dist.w - 2 && U8 (dist [x + 1][y]) <= d && dist [x + 1][y] > 1) neigh [ncnt++] = point (x + 1, y); |
223 | if (y > 1 && U8 (dist [x][y - 1]) <= d && dist [x][y - 1] > 1) neigh [ncnt++] = point (x, y - 1); |
223 | if (y > 1 && U8 (dist [x][y - 1]) <= d && dist [x][y - 1] > 1) neigh [ncnt++] = point (x, y - 1); |
224 | if (y < dist.h - 2 && U8 (dist [x][y + 1]) <= d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); |
224 | if (y < dist.h - 2 && U8 (dist [x][y + 1]) <= d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); |
225 | |
225 | |
|
|
226 | printf ("tunnel %d+%d ncnt %d\n", x, y, ncnt);//D |
|
|
227 | |
226 | if (!ncnt) |
228 | if (!ncnt) |
227 | return; |
229 | return; |
228 | |
230 | |
229 | point &p = neigh [rmg_rndm (ncnt)]; |
231 | point &p = neigh [rmg_rndm (ncnt)]; |
230 | |
232 | |
… | |
… | |
272 | |
274 | |
273 | if (!cnt) |
275 | if (!cnt) |
274 | { |
276 | { |
275 | // map is completely massive, this is not good, |
277 | // map is completely massive, this is not good, |
276 | // so make it empty instead. |
278 | // so make it empty instead. |
277 | dist.clear (); |
279 | dist.fill (1); |
278 | dist.border (255); |
280 | dist.border (255); |
279 | return; |
281 | return; |
280 | } |
282 | } |
281 | |
283 | |
282 | fixed_stack<point> seeds (dist.w * dist.h * 5); |
284 | fixed_stack<point> seeds (dist.w * dist.h * 5); |
… | |
… | |
307 | else |
309 | else |
308 | { |
310 | { |
309 | // nothing here, continue to expand |
311 | // nothing here, continue to expand |
310 | U8 d = U8 (dist [x][y]) + 1; |
312 | U8 d = U8 (dist [x][y]) + 1; |
311 | |
313 | |
312 | if (x < dist.w - 1) maybe_push (dist, seeds, x + 1, y, d); |
314 | if (x < dist.w - 2) maybe_push (dist, seeds, x + 1, y, d); |
313 | if (x > 0) maybe_push (dist, seeds, x - 1, y, d); |
315 | if (x > 1) maybe_push (dist, seeds, x - 1, y, d); |
314 | if (y < dist.h - 1) maybe_push (dist, seeds, x, y + 1, d); |
316 | if (y < dist.h - 2) maybe_push (dist, seeds, x, y + 1, d); |
315 | if (y > 0) maybe_push (dist, seeds, x, y - 1, d); |
317 | if (y > 1) maybe_push (dist, seeds, x, y - 1, d); |
316 | } |
318 | } |
317 | } |
319 | } |
318 | } |
320 | } |
319 | |
321 | |
320 | void |
322 | void |
321 | layout::isolation_remover () |
323 | layout::isolation_remover () |
322 | { |
324 | { |
323 | layout dist (w, h); |
325 | layout dist (w, h); |
324 | |
326 | |
325 | for (int x = 0; x < w; ++x) |
327 | for (int x = 1; x < w - 1; ++x) |
326 | for (int y = 0; y < h; ++y) |
328 | for (int y = 1; y < h - 1; ++y) |
327 | dist [x][y] = data [x][y] == '#' ? U8 (255) : 0; |
329 | dist [x][y] = data [x][y] == '#' ? U8 (255) : 0; |
328 | |
330 | |
329 | ::isolation_remover (dist); |
331 | ::isolation_remover (dist); |
330 | |
332 | |
331 | // now copy the tunnels over |
333 | // now copy the tunnels over |
332 | for (int x = 0; x < w; ++x) |
334 | for (int x = 1; x < w - 1; ++x) |
333 | for (int y = 0; y < h; ++y) |
335 | for (int y = 1; y < h - 1; ++y) |
334 | if (data [x][y] == '#' && dist [x][y] == 1) |
336 | if (data [x][y] == '#' && dist [x][y] == 1) |
335 | data [x][y] = 0; |
337 | data [x][y] = 0; |
336 | } |
338 | } |
337 | |
339 | |
338 | ///////////////////////////////////////////////////////////////////////////// |
340 | ///////////////////////////////////////////////////////////////////////////// |