From 71543f2ab25c59956cde5e4eca8553fbe71fb6d9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 28 Sep 2021 17:20:20 -0400 Subject: [PATCH] Improved Serpulo water edge generation --- core/src/mindustry/ai/Astar.java | 17 +++++++---- .../maps/planet/SerpuloPlanetGenerator.java | 29 ++++++++++++++++++- core/src/mindustry/world/Tile.java | 5 ++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/core/src/mindustry/ai/Astar.java b/core/src/mindustry/ai/Astar.java index df50547d22..76d73d84b0 100644 --- a/core/src/mindustry/ai/Astar.java +++ b/core/src/mindustry/ai/Astar.java @@ -6,6 +6,8 @@ import arc.struct.*; import arc.util.*; import mindustry.world.*; +import java.util.*; + import static mindustry.Vars.*; public class Astar{ @@ -13,7 +15,7 @@ public class Astar{ private static final Seq out = new Seq<>(); private static final PQueue queue = new PQueue<>(200 * 200 / 4, (a, b) -> 0); - private static final IntFloatMap costs = new IntFloatMap(); + private static float[] costs; private static byte[][] rotations; public static Seq pathfind(Tile from, Tile to, TileHueristic th, Boolf passable){ @@ -32,9 +34,14 @@ public class Astar{ GridBits closed = new GridBits(tiles.width, tiles.height); - costs.clear(); + if(costs == null || costs.length != tiles.width * tiles.height){ + costs = new float[tiles.width * tiles.height]; + } + + Arrays.fill(costs, 0); + queue.clear(); - queue.comparator = Structs.comparingFloat(a -> costs.get(a.pos(), 0f) + dh.cost(a.x, a.y, end.x, end.y)); + queue.comparator = Structs.comparingFloat(a -> costs[a.array()] + dh.cost(a.x, a.y, end.x, end.y)); queue.add(start); if(rotations == null || rotations.length != world.width() || rotations[0].length != world.height()){ rotations = new byte[world.width()][world.height()]; @@ -43,7 +50,7 @@ public class Astar{ boolean found = false; while(!queue.empty()){ Tile next = queue.poll(); - float baseCost = costs.get(next.pos(), 0f); + float baseCost = costs[next.array()]; if(next == end){ found = true; break; @@ -58,7 +65,7 @@ public class Astar{ if(!closed.get(child.x, child.y)){ closed.set(child.x, child.y); rotations[child.x][child.y] = child.relativeTo(next.x, next.y); - costs.put(child.pos(), newCost); + costs[child.array()] = newCost; queue.add(child); } } diff --git a/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java b/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java index 862835f2e9..adcc67c603 100644 --- a/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java @@ -262,9 +262,36 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{ for(Room room : roomseq){ spawn.connect(room); } + Room fspawn = spawn; cells(1); + + //shoreline setup + int deepRadius = 4; + + pass((x, y) -> { + if(floor.asFloor().isLiquid && !floor.asFloor().isDeep()){ + + for(int cx = -deepRadius; cx <= deepRadius; cx++){ + for(int cy = -deepRadius; cy <= deepRadius; cy++){ + + if((cx) * (cx) + (cy) * (cy) <= deepRadius * deepRadius){ + int wx = cx + x, wy = cy + y; + + Tile tile = tiles.get(wx, wy); + if(tile != null && (!tile.floor().isLiquid || tile.block() != Blocks.air)){ + //found something solid, skip replacing anything + return; + } + } + } + } + + floor = floor == Blocks.darksandTaintedWater ? Blocks.taintedWater : Blocks.water; + } + }); + distort(10f, 6f); //rivers @@ -286,7 +313,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{ floor = spore ? (deep ? Blocks.taintedWater : Blocks.darksandTaintedWater) : (deep ? Blocks.water : - (floor == Blocks.sand ? Blocks.sandWater : Blocks.darksandWater)); + (floor == Blocks.sand || floor == Blocks.salt ? Blocks.sandWater : Blocks.darksandWater)); } } }); diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index 4131a22c4e..300e8d0e2d 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -62,6 +62,11 @@ public class Tile implements Position, QuadTreeObject, Displayable{ return Point2.pack(x, y); } + /** @return this tile's position, packed to the world width - for use in width*height arrays. */ + public int array(){ + return x + y * world.tiles.width; + } + public byte relativeTo(Tile tile){ return relativeTo(tile.x, tile.y); }