|
@@ -24,11 +24,11 @@ public class TileMapGenerator
|
|
* @param height the height of the map
|
|
* @param height the height of the map
|
|
* @return a random test map
|
|
* @return a random test map
|
|
*/
|
|
*/
|
|
- public static TileMap getMap(int width, int height)
|
|
|
|
|
|
+ public static TileMap getMap(int width, int height, long seed)
|
|
{
|
|
{
|
|
- Random r = new Random();
|
|
|
|
|
|
+ Random r = new Random(seed);
|
|
|
|
|
|
- HighMap highMap = HighMap.generate(width, height, Math.min(width, height) * 0.125f);
|
|
|
|
|
|
+ HighMap highMap = HighMap.generate(seed, width, height, Math.min(width, height) * 0.125f);
|
|
|
|
|
|
TileMap map = new TileMap(width, height);
|
|
TileMap map = new TileMap(width, height);
|
|
for(int x = 0; x < width; x++)
|
|
for(int x = 0; x < width; x++)
|
|
@@ -38,13 +38,19 @@ public class TileMapGenerator
|
|
switch((int) (highMap.get(x, y) * 5))
|
|
switch((int) (highMap.get(x, y) * 5))
|
|
{
|
|
{
|
|
case 0: map.setTile(x, y, Tiles.DEEP_WATER); break;
|
|
case 0: map.setTile(x, y, Tiles.DEEP_WATER); break;
|
|
- case 1: map.setTile(x, y, Tiles.SHALLOW_WATER); break;
|
|
|
|
|
|
+ case 1: map.setTile(x, y, Tiles.SHALLOW_WATER); break;
|
|
case 2: map.setTile(x, y, randomGrass(r)); break;
|
|
case 2: map.setTile(x, y, randomGrass(r)); break;
|
|
- case 3: map.setTile(x, y, Tiles.FOREST); break;
|
|
|
|
- case 4: map.setTile(x, y, Tiles.FOREST); break;
|
|
|
|
|
|
+ case 3: map.setTile(x, y, Tiles.HILL); break;
|
|
|
|
+ case 4: map.setTile(x, y, Tiles.MOUNTAIN); break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // max forest size: squared 20% of map size
|
|
|
|
+ int forestSize = ((width + height) / 2) / 5;
|
|
|
|
+ forestSize *= forestSize;
|
|
|
|
+
|
|
|
|
+ generateForest(map, r, forestSize, 10, 1);
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -52,4 +58,39 @@ public class TileMapGenerator
|
|
{
|
|
{
|
|
return GRASS_MAP.floorEntry(r.nextInt(100)).getValue();
|
|
return GRASS_MAP.floorEntry(r.nextInt(100)).getValue();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private static void generateForest(TileMap map, Random r, int depth, int placements, int jumpRadius)
|
|
|
|
+ {
|
|
|
|
+ for(int i = 0; i < placements; i++)
|
|
|
|
+ {
|
|
|
|
+ int x = r.nextInt(map.getWidth());
|
|
|
|
+ int y = r.nextInt(map.getHeight());
|
|
|
|
+ while(map.getTile(x, y).getForestReplaceChance() < 1.0f)
|
|
|
|
+ {
|
|
|
|
+ x = r.nextInt(map.getWidth());
|
|
|
|
+ y = r.nextInt(map.getHeight());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for(int j = 0; j < depth; j++)
|
|
|
|
+ {
|
|
|
|
+ int oldX = x;
|
|
|
|
+ int oldY = y;
|
|
|
|
+
|
|
|
|
+ x += r.nextInt(jumpRadius * 2 + 1) - jumpRadius;
|
|
|
|
+ y += r.nextInt(jumpRadius * 2 + 1) - jumpRadius;
|
|
|
|
+ x = Math.min(Math.max(x, 0), map.getWidth() - 1);
|
|
|
|
+ y = Math.min(Math.max(y, 0), map.getHeight() - 1);
|
|
|
|
+
|
|
|
|
+ if(r.nextFloat() < map.getTile(x, y).getForestReplaceChance())
|
|
|
|
+ {
|
|
|
|
+ map.setTile(x, y, Tiles.FOREST);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ x = oldX;
|
|
|
|
+ y = oldY;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|