Improved world generation

This commit is contained in:
Anuken
2018-06-23 10:36:47 -04:00
parent 0a6614d1b3
commit f9947d2e53
19 changed files with 275 additions and 97 deletions

View File

@@ -117,15 +117,19 @@ public class Blocks extends BlockList implements ContentList{
sand = new Floor("sand") {{
drops = new ItemStack(Items.sand, 1);
minimapColor = Color.valueOf("988a67");
hasOres = true;
}};
ice = new Floor("ice") {{
dragMultiplier = 0.2f;
dragMultiplier = 0.3f;
speedMultiplier = 0.4f;
minimapColor = Color.valueOf("c4e3e7");
hasOres = true;
}};
snow = new Floor("snow"){{
minimapColor = Color.valueOf("c2d1d2");
hasOres = true;
}};
grass = new Floor("grass"){{

View File

@@ -110,6 +110,10 @@ public class ContentLoader {
contentSet.add(list.getAll());
}
if(Block.all().size >= 256){
throw new IllegalArgumentException("THE TIME HAS COME. More than 256 blocks have been created..");
}
Log.info("--- CONTENT INFO ---");
Log.info("Blocks loaded: {0}\nItems loaded: {1}\nLiquids loaded: {2}\nUpgrades loaded: {3}\nUnits loaded: {4}\nAmmo types loaded: {5}\nBullet types loaded: {6}\nStatus effects loaded: {7}\nRecipes loaded: {8}\nEffects loaded: {9}\nTotal content classes: {10}",
Block.all().size, io.anuke.mindustry.type.Item.all().size, Liquid.all().size,

View File

@@ -125,13 +125,13 @@ public class LevelDialog extends FloatingDialog{
maps.addImageButton("icon-editor", 16*4, () -> {
hide();
MapTileData data = WorldGenerator.generate();
Map map = new Map("generated-map", new MapMeta(0, new ObjectMap<>(), data.width(), data.height(), null), true, () -> null);
ui.loadfrag.show();
Timers.run(5f, () -> {
threads.run(() -> {
MapTileData data = WorldGenerator.generate();
Map map = new Map("generated-map", new MapMeta(0, new ObjectMap<>(), data.width(), data.height(), null), true, () -> null);
logic.reset();
world.beginMapLoad();

View File

@@ -17,7 +17,7 @@ public class OreBlock extends Floor {
this.base = base;
this.variants = 3;
this.minimapColor = ore.color;
this.blends = block -> false;
this.blends = block -> block instanceof OreBlock && ((OreBlock) block).base != base;
this.edge = base.name;
}
@@ -32,6 +32,8 @@ public class OreBlock extends Floor {
Draw.rect(variants > 0 ? (drops.item.name + rand) : name, tile.worldx(), tile.worldy() - 1);
Draw.color();
Draw.rect(variants > 0 ? (drops.item.name + rand) : name, tile.worldx(), tile.worldy());
drawEdges(tile, false);
}
@Override
@@ -49,11 +51,6 @@ public class OreBlock extends Floor {
base.drawEdges(tile, true);
}
@Override
protected void drawEdges(Tile tile, boolean sameLayer){
base.drawEdges(tile, sameLayer);
}
@Override
public boolean blendOverride(Block block) {
return block == base;

View File

@@ -140,22 +140,30 @@ public class WorldGenerator {
SeedRandom random = new SeedRandom(Mathf.random(99999));
MapTileData data = new MapTileData(300, 300);
MapTileData data = new MapTileData(400, 400);
TileDataMarker marker = data.newDataMarker();
ObjectMap<Block, Block> decoration = new ObjectMap<>();
decoration.put(Blocks.grass, Blocks.shrub);
decoration.put(Blocks.stone, Blocks.rock);
decoration.put(Blocks.ice, Blocks.icerock);
decoration.put(Blocks.snow, Blocks.icerock);
decoration.put(Blocks.blackstone, Blocks.blackrock);
//TODO implement improved, more interesting generation
for (int x = 0; x < data.width(); x++) {
for (int y = 0; y < data.height(); y++) {
marker.floor = (byte)Blocks.stone.id;
double elevation = sim.octaveNoise2D(3, 0.5, 1f/100, x, y) * 4.1 - 1;
double temp = sim3.octaveNoise2D(7, 0.53, 1f/320f, x, y);
double r = sim2.octaveNoise2D(1, 0.6, 1f/70, x, y);
double elevation = sim.octaveNoise2D(3, 0.5, 1f/70, x, y) * 4 - 1.2;
double edgeDist = Math.max(data.width()/2, data.height()/2) - Math.max(Math.abs(x - data.width()/2), Math.abs(y - data.height()/2));
double dst = Vector2.dst(data.width()/2, data.height()/2, x, y);
double elevDip = 20;
double border = 14;
@@ -163,12 +171,23 @@ public class WorldGenerator {
elevation += (border - edgeDist)/6.0;
}
if(sim3.octaveNoise2D(6, 0.5, 1f/120f, x, y) > 0.5){
if(temp < 0.35){
marker.floor = (byte)Blocks.snow.id;
}else if(temp < 0.45){
marker.floor = (byte)Blocks.stone.id;
}else if(temp < 0.7){
marker.floor = (byte)Blocks.grass.id;
}else if(temp < 0.8){
marker.floor = (byte)Blocks.sand.id;
}else if(temp < 0.9){
marker.floor = (byte)Blocks.blackstone.id;
elevation = 0f;
}else{
marker.floor = (byte)Blocks.lava.id;
}
if(dst < 20){
elevation = 0;
if(dst < elevDip){
elevation -= (elevDip - dst)/elevDip * 4.0;
}else if(r > 0.9){
marker.floor = (byte)Blocks.water.id;
elevation = 0;