Implemented ore generation
This commit is contained in:
@@ -190,7 +190,7 @@ public class World extends Module{
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ public class MapFilter{
|
||||
);
|
||||
|
||||
private Simplex sim = new Simplex();
|
||||
private RidgedPerlin rid = new RidgedPerlin(1, 10, 20f);
|
||||
private RidgedPerlin rid2 = new RidgedPerlin(1, 6, 1f);
|
||||
private RidgedPerlin rid3 = new RidgedPerlin(1, 6, 1f);
|
||||
private RidgedPerlin rid = new RidgedPerlin(1, 10);
|
||||
private RidgedPerlin rid2 = new RidgedPerlin(1, 6);
|
||||
private RidgedPerlin rid3 = new RidgedPerlin(1, 6);
|
||||
|
||||
public MapFilter(){
|
||||
prefs.get("replace").enabled = true;
|
||||
|
||||
@@ -30,6 +30,6 @@ public class MapMeta {
|
||||
}
|
||||
|
||||
public boolean hasOreGen(){
|
||||
return tags.get("oregen", "1").equals("1");
|
||||
return !tags.get("oregen", "0").equals("0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public class PlayerListFragment implements Fragment{
|
||||
netServer.admins.adminPlayer(id, player.usid);
|
||||
});
|
||||
}
|
||||
}).update(b ->{
|
||||
}).update(b -> {
|
||||
b.setChecked(player.isAdmin);
|
||||
b.setDisabled(Net.client());
|
||||
}).get().setTouchable(() -> Net.client() ? Touchable.disabled : Touchable.enabled);
|
||||
|
||||
@@ -1,22 +1,33 @@
|
||||
package io.anuke.mindustry.world;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.content.blocks.StorageBlocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.io.MapTileData;
|
||||
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.world;
|
||||
|
||||
|
||||
public class WorldGenerator {
|
||||
static int oreIndex = 0;
|
||||
|
||||
/**Should fill spawns with the correct spawnpoints.*/
|
||||
public static void generate(Tile[][] tiles, MapTileData data){
|
||||
Noise.setSeed(world.getSeed());
|
||||
public static void generate(Tile[][] tiles, MapTileData data, boolean genOres, int seed){
|
||||
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();
|
||||
|
||||
@@ -74,10 +85,53 @@ public class WorldGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
//update cliffs, occlusion data
|
||||
for(int x = 0; x < data.width(); x ++){
|
||||
for(int y = 0; y < data.height(); y ++) {
|
||||
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 ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ public class Floor extends Block{
|
||||
public Color liquidColor;
|
||||
/**liquids that drop from this block, used for pumps*/
|
||||
public Liquid liquidDrop = null;
|
||||
/**Whether ores generate on this block.*/
|
||||
public boolean hasOres = true;
|
||||
|
||||
public Floor(String name) {
|
||||
super(name);
|
||||
|
||||
Reference in New Issue
Block a user