9 // 1/a chance of any tile being walkable
10 private Map
map_random(int[] flags
) {
16 if (flags
.length
== 1) {
23 if (flags
.length
== 2) {
28 map
.for_all((ref Tile x
) { x
.base
= chances(a
, b
) ? Tiles
.floor
: Tiles
.rock
; });
33 private void mapcaves_postprocess(Map map
) {
34 foreach (y
; 0 .. map_y
-1) {
35 foreach (x
; 0 .. map_x
-1) {
36 if ((map
[y
+1, x
].walkable
&& map
[y
-1, x
].walkable
) ||
(map
[y
, x
+1].walkable
&& map
[y
, x
-1].walkable
)) {
37 map
[y
, x
].base
= Tiles
.floor
;
43 private Map
real_map_caves(int[] flags
, int iters
= 100) {
46 enum Direction
: bool {y
= true, x
= false}
47 enum Sign
: bool {plus
= true, minus
= false}
51 map
.for_all((ref Tile x
) { x
.base
= Tiles
.rock
; });
54 // "burrow" through the cave
58 foreach (_
; 0 .. rnd(8000, 9000)) {
59 foreach (__
; 0 .. rnd(3, 20)) {
60 foreach (i
; tmpx
-rnd(-1, 3)..tmpx
+rnd(-1, 3)) {
61 map
[tmpy
, i
].base
= Tiles
.floor
;
63 foreach (i
; tmpy
-rnd(-1, 3)..tmpy
+rnd(-1, 3)) {
64 map
[i
, tmpx
].base
= Tiles
.floor
;
69 if (d
== Direction
.x
) {
75 } else if (d
== Direction
.y
) {
92 /* if (chances(iters, 1001)) {
93 return real_map_caves(map, flags, iters--);
99 private Map
map_caves(int[] flags
) {
100 Map map
= real_map_caves(flags
);
102 mapcaves_postprocess(map
);
103 mapcaves_postprocess(map
);
104 //mapcaves_postprocess(map);
111 /* Prototypes for different types of dungeons */
117 private enum int[][MapType
] argnums
= [MapType
.random
: [0, 1, 2], MapType
.caves
: [0]];
119 /* Map from a maptype to an array of ints. Those are all the different numbers
120 * of args it can take. So, for example, it might have an option of taking 4
124 private void veriflags(MapType type
, ulong flags
) {
126 foreach (i
; argnums
[type
]) {
129 assert (flags
in tmp
);
132 Map
genmap(MapType type
, int[] flags
= []) {
133 veriflags(type
, flags
.length
);
136 case MapType
.random
: return map_random(flags
);
137 case MapType
.caves
: return map_caves(flags
);