fix deprecation warnings from latest dmd
[SmugglerRL.git] / src / mapgen.d
blob2a04b36eeafacdd1b3cef739c5f526f66aecaee5
1 import constants;
2 import game;
3 import util;
4 import logging;
5 import map;
6 import rng;
7 import tile;
9 // 1/a chance of any tile being walkable
10 private Map map_random(int[] flags) {
11 Map map = new Map();
13 uint a, b;
14 a = 1;
15 b = 2;
16 if (flags.length == 1) {
17 b = flags[0];
18 if (flags[0] < 0) {
19 b = -b;
20 a = b-1;
23 if (flags.length == 2) {
24 a = flags[0];
25 b = flags[1];
28 map.for_all((ref Tile x) { x.base = chances(a, b) ? Tiles.floor : Tiles.rock; });
30 return map;
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) {
44 Map map = new Map();
46 enum Direction: bool {y = true, x = false}
47 enum Sign: bool {plus = true, minus = false}
48 bool d = Direction.x;
49 bool s = Sign.plus;
51 map.for_all((ref Tile x) { x.base = Tiles.rock; });
53 int tmpx, tmpy;
54 // "burrow" through the cave
56 tmpy = rnd(0, map_y);
57 tmpx = rnd(0, map_x);
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) {
70 if (s == Sign.plus) {
71 tmpx++;
72 } else {
73 tmpx--;
75 } else if (d == Direction.y) {
76 if (s == Sign.plus) {
77 tmpy++;
78 } else {
79 tmpy--;
84 if (rnd(0, 3)) {
85 d = !d;
87 if (rnd(0, 3)) {
88 s = !s;
92 /* if (chances(iters, 1001)) {
93 return real_map_caves(map, flags, iters--);
94 } else {*/
95 return map;
96 /*}*/
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);
106 return map;
111 /* Prototypes for different types of dungeons */
112 enum MapType {
113 random,
114 caves
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
121 * OR 5 args
124 private void veriflags(MapType type, ulong flags) {
125 bool[ulong] tmp;
126 foreach (i; argnums[type]) {
127 tmp[i] = false;
129 assert (flags in tmp);
132 Map genmap(MapType type, int[] flags = []) {
133 veriflags(type, flags.length);
135 switch(type) {
136 case MapType.random: return map_random(flags);
137 case MapType.caves: return map_caves(flags);
138 default: assert(0);