From ca60309fdee13b9b683b1b0428d61a078dfaea60 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 19 Jun 2021 11:17:52 -0400 Subject: [PATCH] Asteroid generator progress --- core/assets/icons/icons.properties | 1 + .../maps/planet/AsteroidGenerator.java | 64 +++++++++++++++++-- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/core/assets/icons/icons.properties b/core/assets/icons/icons.properties index 720a88689c..ac2d241dfd 100755 --- a/core/assets/icons/icons.properties +++ b/core/assets/icons/icons.properties @@ -382,3 +382,4 @@ 63351=redice|block-redice-ui 63350=red-ice|block-red-ice-ui 63349=red-ice-wall|block-red-ice-wall-ui +63348=ferrous|block-ferrous-ui diff --git a/core/src/mindustry/maps/planet/AsteroidGenerator.java b/core/src/mindustry/maps/planet/AsteroidGenerator.java index d2f7605253..d2ec593f4d 100644 --- a/core/src/mindustry/maps/planet/AsteroidGenerator.java +++ b/core/src/mindustry/maps/planet/AsteroidGenerator.java @@ -11,21 +11,77 @@ import mindustry.world.meta.*; import static mindustry.Vars.*; public class AsteroidGenerator extends BlankPlanetGenerator{ + public static int min = 15, max = 25, octaves = 2, foct = 3; + + public static float radMin = 5f, radMax = 50f, persistence = 0.4f, scale = 30f, mag = 0.46f, thresh = 1f; + + public static float fmag = 0.6f, fscl = 50f, fper = 0.6f; + + Rand rand; + int seed; + + void asteroid(int ax, int ay, int radius){ + + for(int x = ax - radius; x <= ax + radius; x++){ + for(int y = ay - radius; y <= ay + radius; y++){ + if(tiles.in(x, y) && Mathf.dst(x, y, ax, ay) / (radius) + Simplex.noise2d(seed, octaves, persistence, 1f / scale, x, y) * mag < thresh){ + tiles.getn(x, y).setFloor(Blocks.stone.asFloor()); + } + } + } + } @Override public void generate(){ - int seed = state.rules.sector.planet.id; + seed = state.rules.sector.planet.id; int sx = width/2, sy = height/2; - Rand rand = new Rand(seed); + rand = new Rand(seed); pass((x, y) -> { floor = Blocks.space; + }); - if(Simplex.noise2d(seed, 5, 0.5f, 1f / 120f, x, y) - Mathf.dst(x, y, sx, sy) / (width/2f) > 0f){ - floor = rand.chance(0.02) ? Blocks.craters : Blocks.stone; + asteroid(sx, sy, rand.random(30, 50)); + + int amount = rand.random(min, max); + for(int i = 0; i < amount; i++){ + float radius = rand.random(radMin, radMax), ax = rand.random(radius, width - radius), ay = rand.random(radius, height - radius); + + asteroid((int)ax, (int)ay, (int)radius); + } + + //tiny asteroids. + int smalls = rand.random(min, max * 2); + for(int i = 0; i < smalls; i++){ + float radius = rand.random(1, 8), ax = rand.random(radius, width - radius), ay = rand.random(radius, height - radius); + + asteroid((int)ax, (int)ay, (int)radius); + } + + pass((x, y) -> { + if(floor != Blocks.space){ + if(Ridged.noise2d(seed, x, y, foct, fper, 1f / fscl) > fmag){ + floor = Blocks.graphiticStone; + } } }); + pass((x, y) -> { + if(floor == Blocks.space || Ridged.noise2d(seed + 1, x, y, 3, 0.5f, 1f / 70f) > 0.5f) return; + + int radius = 5; + for(int dx = x - radius; dx <= x + radius; dx++){ + for(int dy = y - radius; dy <= y + radius; dy++){ + if(Mathf.within(dx, dy, x, y, radius + 0.0001f) && tiles.in(dx, dy) && tiles.getn(dx, dy).floor() == Blocks.space){ + return; + } + } + } + + block = floor.asFloor().wall; + + }); + Schematics.placeLaunchLoadout(sx, sy); state.rules.environment = Env.space;