From 4be101e9fc29f71b2faf7e4215b37fb224c00c3e Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 13 Jun 2018 21:02:47 -0400 Subject: [PATCH] Implemented ore generation --- core/src/io/anuke/mindustry/core/World.java | 2 +- .../io/anuke/mindustry/editor/MapFilter.java | 6 +- core/src/io/anuke/mindustry/io/MapMeta.java | 2 +- .../ui/fragments/PlayerListFragment.java | 2 +- .../anuke/mindustry/world/WorldGenerator.java | 60 ++++++++++++++++++- .../anuke/mindustry/world/blocks/Floor.java | 2 + 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/World.java b/core/src/io/anuke/mindustry/core/World.java index 952b255289..7a893461be 100644 --- a/core/src/io/anuke/mindustry/core/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -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(); } diff --git a/core/src/io/anuke/mindustry/editor/MapFilter.java b/core/src/io/anuke/mindustry/editor/MapFilter.java index 1a49ec4ac6..1faa5c71ea 100644 --- a/core/src/io/anuke/mindustry/editor/MapFilter.java +++ b/core/src/io/anuke/mindustry/editor/MapFilter.java @@ -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; diff --git a/core/src/io/anuke/mindustry/io/MapMeta.java b/core/src/io/anuke/mindustry/io/MapMeta.java index 6750ed982f..7668a76933 100644 --- a/core/src/io/anuke/mindustry/io/MapMeta.java +++ b/core/src/io/anuke/mindustry/io/MapMeta.java @@ -30,6 +30,6 @@ public class MapMeta { } public boolean hasOreGen(){ - return tags.get("oregen", "1").equals("1"); + return !tags.get("oregen", "0").equals("0"); } } diff --git a/core/src/io/anuke/mindustry/ui/fragments/PlayerListFragment.java b/core/src/io/anuke/mindustry/ui/fragments/PlayerListFragment.java index d34b2afcfa..f6c27384ee 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/PlayerListFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/PlayerListFragment.java @@ -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); diff --git a/core/src/io/anuke/mindustry/world/WorldGenerator.java b/core/src/io/anuke/mindustry/world/WorldGenerator.java index a4f21c10f4..a7fd5f9ae1 100644 --- a/core/src/io/anuke/mindustry/world/WorldGenerator.java +++ b/core/src/io/anuke/mindustry/world/WorldGenerator.java @@ -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 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 ++; + } } } diff --git a/core/src/io/anuke/mindustry/world/blocks/Floor.java b/core/src/io/anuke/mindustry/world/blocks/Floor.java index 0d373cf651..6fe5ac763c 100644 --- a/core/src/io/anuke/mindustry/world/blocks/Floor.java +++ b/core/src/io/anuke/mindustry/world/blocks/Floor.java @@ -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);