Implemented ore generation

This commit is contained in:
Anuken
2018-06-13 21:02:47 -04:00
parent d0302cdbf3
commit 4be101e9fc
6 changed files with 65 additions and 9 deletions

View File

@@ -190,7 +190,7 @@ public class World extends Module{
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize); EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
WorldGenerator.generate(tiles, MapIO.readTileData(map, true)); WorldGenerator.generate(tiles, MapIO.readTileData(map, true), map.meta.hasOreGen(), seed);
endMapLoad(); endMapLoad();
} }

View File

@@ -38,9 +38,9 @@ public class MapFilter{
); );
private Simplex sim = new Simplex(); private Simplex sim = new Simplex();
private RidgedPerlin rid = new RidgedPerlin(1, 10, 20f); private RidgedPerlin rid = new RidgedPerlin(1, 10);
private RidgedPerlin rid2 = new RidgedPerlin(1, 6, 1f); private RidgedPerlin rid2 = new RidgedPerlin(1, 6);
private RidgedPerlin rid3 = new RidgedPerlin(1, 6, 1f); private RidgedPerlin rid3 = new RidgedPerlin(1, 6);
public MapFilter(){ public MapFilter(){
prefs.get("replace").enabled = true; prefs.get("replace").enabled = true;

View File

@@ -30,6 +30,6 @@ public class MapMeta {
} }
public boolean hasOreGen(){ public boolean hasOreGen(){
return tags.get("oregen", "1").equals("1"); return !tags.get("oregen", "0").equals("0");
} }
} }

View File

@@ -160,7 +160,7 @@ public class PlayerListFragment implements Fragment{
netServer.admins.adminPlayer(id, player.usid); netServer.admins.adminPlayer(id, player.usid);
}); });
} }
}).update(b ->{ }).update(b -> {
b.setChecked(player.isAdmin); b.setChecked(player.isAdmin);
b.setDisabled(Net.client()); b.setDisabled(Net.client());
}).get().setTouchable(() -> Net.client() ? Touchable.disabled : Touchable.enabled); }).get().setTouchable(() -> Net.client() ? Touchable.disabled : Touchable.enabled);

View File

@@ -1,22 +1,33 @@
package io.anuke.mindustry.world; package io.anuke.mindustry.world;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.IntArray;
import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.content.blocks.StorageBlocks; import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.io.MapTileData; import io.anuke.mindustry.io.MapTileData;
import io.anuke.mindustry.io.MapTileData.TileDataMarker; import io.anuke.mindustry.io.MapTileData.TileDataMarker;
import io.anuke.ucore.noise.Noise; import io.anuke.ucore.noise.RidgedPerlin;
import io.anuke.ucore.noise.Simplex;
import static io.anuke.mindustry.Vars.state; import static io.anuke.mindustry.Vars.state;
import static io.anuke.mindustry.Vars.world; import static io.anuke.mindustry.Vars.world;
public class WorldGenerator { public class WorldGenerator {
static int oreIndex = 0;
/**Should fill spawns with the correct spawnpoints.*/ /**Should fill spawns with the correct spawnpoints.*/
public static void generate(Tile[][] tiles, MapTileData data){ public static void generate(Tile[][] tiles, MapTileData data, boolean genOres, int seed){
Noise.setSeed(world.getSeed()); oreIndex = 0;
Array<OreEntry> ores = Array.with(
new OreEntry(Blocks.iron, 0.3f, seed),
new OreEntry(Blocks.coal, 0.27f, seed),
new OreEntry(Blocks.lead, 0.28f, seed),
new OreEntry(Blocks.titanium, 0.27f, seed),
new OreEntry(Blocks.thorium, 0.26f, seed)
);
IntArray multiblocks = new IntArray(); IntArray multiblocks = new IntArray();
@@ -74,10 +85,53 @@ public class WorldGenerator {
} }
} }
//update cliffs, occlusion data
for(int x = 0; x < data.width(); x ++){ for(int x = 0; x < data.width(); x ++){
for(int y = 0; y < data.height(); y ++) { for(int y = 0; y < data.height(); y ++) {
tiles[x][y].updateOcclusion(); tiles[x][y].updateOcclusion();
} }
} }
if(genOres) {
for (int x = 0; x < data.width(); x++) {
for (int y = 0; y < data.height(); y++) {
Tile tile = tiles[x][y];
if(!tile.floor().hasOres || tile.cliffs != 0 || tile.block() != Blocks.air){
continue;
}
for(int i = ores.size-1; i >= 0; i --){
OreEntry entry = ores.get(i);
if(entry.noise.octaveNoise2D(2, 0.7, 1f / (20 + i*4), x, y)/2f +
entry.ridge.getValue(x, y, 1f / (28 + i*4)) >= 2.0f - entry.frequency*4.0f
&& entry.ridge.getValue(x+9999, y+9999, 1f/100f) > 0.4){
tile.setFloor(entry.block);
}
}
}
}
}
}
static class OreEntry{
final float frequency;
final Block block;
final Simplex noise;
final RidgedPerlin ridge;
final int index;
int used;
OreEntry(Block block, float frequency, int seed) {
this.frequency = frequency;
this.block = block;
this.noise = new Simplex(seed + oreIndex);
this.ridge = new RidgedPerlin(seed + oreIndex, 2);
this.index = oreIndex ++;
}
} }
} }

View File

@@ -57,6 +57,8 @@ public class Floor extends Block{
public Color liquidColor; public Color liquidColor;
/**liquids that drop from this block, used for pumps*/ /**liquids that drop from this block, used for pumps*/
public Liquid liquidDrop = null; public Liquid liquidDrop = null;
/**Whether ores generate on this block.*/
public boolean hasOres = true;
public Floor(String name) { public Floor(String name) {
super(name); super(name);