… | |
… | |
238 | if (y < dist.h - 1 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); |
238 | if (y < dist.h - 1 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); |
239 | |
239 | |
240 | if (!ncnt) |
240 | if (!ncnt) |
241 | return; |
241 | return; |
242 | |
242 | |
243 | point &p = neigh [perturb ? rmg_rndm (ncnt) : 0]; |
243 | point p = neigh [perturb ? rmg_rndm (ncnt) : 0]; |
244 | |
244 | |
245 | seeds.push (p); |
245 | seeds.push (p); |
246 | |
246 | |
247 | x = p.x; |
247 | x = p.x; |
248 | y = p.y; |
248 | y = p.y; |
… | |
… | |
273 | // dist contains |
273 | // dist contains |
274 | // 0 == invisited rooms |
274 | // 0 == invisited rooms |
275 | // 1 == visited rooms |
275 | // 1 == visited rooms |
276 | // 2+ shortest distance to random near room |
276 | // 2+ shortest distance to random near room |
277 | |
277 | |
278 | max_it (perturb, 0); |
278 | clamp_it (perturb, 0, 2); |
279 | min_it (perturb, 2); |
|
|
280 | |
279 | |
281 | // phase 1, find seed |
280 | // phase 1, find seed |
282 | int cnt = 0; |
281 | int cnt = 0; |
283 | int x, y; |
282 | int x, y; |
284 | |
283 | |
… | |
… | |
358 | /* puts doors at appropriate locations in a maze. */ |
357 | /* puts doors at appropriate locations in a maze. */ |
359 | void |
358 | void |
360 | layout::doorify () |
359 | layout::doorify () |
361 | { |
360 | { |
362 | int ndoors = w * h / 60; /* reasonable number of doors. */ |
361 | int ndoors = w * h / 60; /* reasonable number of doors. */ |
363 | int doorlocs = 0; /* # of available doorlocations */ |
|
|
364 | |
362 | |
365 | uint16 *doorlist_x = salloc<uint16> (w * h); |
363 | fixed_stack<point> doorloc (w * h); |
366 | uint16 *doorlist_y = salloc<uint16> (w * h); |
|
|
367 | |
364 | |
368 | /* make a list of possible door locations */ |
365 | /* make a list of possible door locations */ |
369 | for (int i = 1; i < w - 1; i++) |
366 | for (int i = 1; i < w - 1; i++) |
370 | for (int j = 1; j < h - 1; j++) |
367 | for (int j = 1; j < h - 1; j++) |
371 | { |
368 | { |
372 | int sindex = surround_flag (*this, i, j); |
369 | int sindex = surround_flag (*this, i, j); |
373 | |
370 | |
374 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
371 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
375 | { |
372 | doorloc.push (point (i, j)); |
376 | doorlist_x [doorlocs] = i; |
|
|
377 | doorlist_y [doorlocs] = j; |
|
|
378 | doorlocs++; |
|
|
379 | } |
|
|
380 | } |
373 | } |
381 | |
374 | |
382 | while (ndoors > 0 && doorlocs > 0) |
375 | while (ndoors && doorloc.size) |
383 | { |
376 | { |
384 | int di = rmg_rndm (doorlocs); |
377 | point p = doorloc.remove (rmg_rndm (doorloc.size)); |
385 | int i = doorlist_x [di]; |
378 | |
386 | int j = doorlist_y [di]; |
|
|
387 | int sindex = surround_flag (*this, i, j); |
379 | int sindex = surround_flag (*this, p.x, p.y); |
388 | |
380 | |
389 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
381 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
390 | { |
382 | { |
391 | data [i][j] = 'D'; |
383 | data [p.x][p.y] = 'D'; |
392 | ndoors--; |
384 | --ndoors; |
393 | } |
385 | } |
394 | |
|
|
395 | /* reduce the size of the list */ |
|
|
396 | doorlocs--; |
|
|
397 | doorlist_x[di] = doorlist_x [doorlocs]; |
|
|
398 | doorlist_y[di] = doorlist_y [doorlocs]; |
|
|
399 | } |
386 | } |
400 | |
|
|
401 | sfree (doorlist_x, w * h); |
|
|
402 | sfree (doorlist_y, w * h); |
|
|
403 | } |
387 | } |
404 | |
388 | |
405 | /* takes a map and makes it symmetric: adjusts Xsize and |
389 | /* takes a map and makes it symmetric: adjusts Xsize and |
406 | * Ysize to produce a symmetric map. |
390 | * Ysize to produce a symmetric map. |
407 | */ |
391 | */ |
… | |
… | |
799 | erode_1_2 (5, 2, 10); |
783 | erode_1_2 (5, 2, 10); |
800 | erode_1_2 (5, -1, 10); |
784 | erode_1_2 (5, -1, 10); |
801 | erode_1_2 (5, 2, 1); |
785 | erode_1_2 (5, 2, 1); |
802 | break; |
786 | break; |
803 | |
787 | |
804 | // somewhat open, roundish |
788 | // somewhat open, some room-like structures |
805 | case 2: |
789 | case 2: |
|
|
790 | fill_rand (45); |
|
|
791 | erode_1_2 (5, 2, 4); |
|
|
792 | erode_1_2 (5, -1, 3); |
|
|
793 | break; |
|
|
794 | |
|
|
795 | // wide open, roundish |
|
|
796 | case 3: |
806 | fill_rand (45); |
797 | fill_rand (45); |
807 | erode_1_2 (5, 0, 5); |
798 | erode_1_2 (5, 0, 5); |
808 | erode_1_2 (5, 1, 1); |
799 | erode_1_2 (5, 1, 1); |
809 | break; |
800 | break; |
810 | |
|
|
811 | // wide open, some room-like structures |
|
|
812 | case 3: |
|
|
813 | fill_rand (45); |
|
|
814 | erode_1_2 (5, 2, 4); |
|
|
815 | erode_1_2 (5, -1, 3); |
|
|
816 | break; |
|
|
817 | } |
801 | } |
818 | |
802 | |
819 | border (); |
803 | border (); |
820 | isolation_remover (); |
804 | isolation_remover (1); |
821 | } |
805 | } |
822 | |
806 | |
823 | void |
807 | void |
824 | layout::gen_castle () |
808 | layout::gen_castle () |
825 | { |
809 | { |
… | |
… | |
879 | random_map_params &rp = *new random_map_params (RP); |
863 | random_map_params &rp = *new random_map_params (RP); |
880 | gen_mixed_ (maze, &rp, rmg_rndm (2)); |
864 | gen_mixed_ (maze, &rp, rmg_rndm (2)); |
881 | delete &rp; |
865 | delete &rp; |
882 | |
866 | |
883 | maze.border (); |
867 | maze.border (); |
884 | maze.isolation_remover (); |
868 | maze.isolation_remover (0); |
885 | } |
869 | } |
886 | |
870 | |
887 | //+GPL |
871 | //+GPL |
888 | |
872 | |
889 | /* function selects the maze function and gives it whatever |
873 | /* function selects the maze function and gives it whatever |
… | |
… | |
972 | } |
956 | } |
973 | |
957 | |
974 | //-GPL |
958 | //-GPL |
975 | |
959 | |
976 | #if 0 |
960 | #if 0 |
|
|
961 | static void |
|
|
962 | gen_village (layout &maze) |
|
|
963 | { |
|
|
964 | maze.clear (); |
|
|
965 | maze.border (); |
|
|
966 | |
|
|
967 | for (int n = maze.w * maze.h / 200 + 1; n--; ) |
|
|
968 | { |
|
|
969 | int rw = rmg_rndm (6, 10); |
|
|
970 | int rh = rmg_rndm (6, 10); |
|
|
971 | |
|
|
972 | int rx = rmg_rndm (2, maze.w - rw - 2); |
|
|
973 | int ry = rmg_rndm (2, maze.h - rh - 2); |
|
|
974 | |
|
|
975 | maze.rect (rx, ry, rx + rw, ry + rh, '#'); |
|
|
976 | } |
|
|
977 | |
|
|
978 | maze.border (); |
|
|
979 | maze.isolation_remover (2); |
|
|
980 | } |
|
|
981 | |
977 | static struct demo |
982 | static struct demo |
978 | { |
983 | { |
979 | demo () |
984 | demo () |
980 | { |
985 | { |
981 | rmg_rndm.seed (time (0)); |
986 | rmg_rndm.seed (time (0)); |
982 | |
987 | |
983 | for(int i=1;i<100;i++) |
988 | for(int i=1;i<100;i++) |
984 | { |
989 | { |
985 | layout maze (40, 25); |
990 | layout maze (40, 30); |
986 | maze.gen_castle (); |
991 | gen_village (maze); |
987 | maze.doorify (); |
992 | maze.doorify (); |
988 | maze.print (); |
993 | maze.print (); |
989 | exit(0); |
994 | exit(0); |
990 | } |
995 | } |
991 | |
996 | |