Improved Serpulo water edge generation
This commit is contained in:
@@ -6,6 +6,8 @@ import arc.struct.*;
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class Astar{
|
public class Astar{
|
||||||
@@ -13,7 +15,7 @@ public class Astar{
|
|||||||
|
|
||||||
private static final Seq<Tile> out = new Seq<>();
|
private static final Seq<Tile> out = new Seq<>();
|
||||||
private static final PQueue<Tile> queue = new PQueue<>(200 * 200 / 4, (a, b) -> 0);
|
private static final PQueue<Tile> queue = new PQueue<>(200 * 200 / 4, (a, b) -> 0);
|
||||||
private static final IntFloatMap costs = new IntFloatMap();
|
private static float[] costs;
|
||||||
private static byte[][] rotations;
|
private static byte[][] rotations;
|
||||||
|
|
||||||
public static Seq<Tile> pathfind(Tile from, Tile to, TileHueristic th, Boolf<Tile> passable){
|
public static Seq<Tile> pathfind(Tile from, Tile to, TileHueristic th, Boolf<Tile> passable){
|
||||||
@@ -32,9 +34,14 @@ public class Astar{
|
|||||||
|
|
||||||
GridBits closed = new GridBits(tiles.width, tiles.height);
|
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.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);
|
queue.add(start);
|
||||||
if(rotations == null || rotations.length != world.width() || rotations[0].length != world.height()){
|
if(rotations == null || rotations.length != world.width() || rotations[0].length != world.height()){
|
||||||
rotations = new byte[world.width()][world.height()];
|
rotations = new byte[world.width()][world.height()];
|
||||||
@@ -43,7 +50,7 @@ public class Astar{
|
|||||||
boolean found = false;
|
boolean found = false;
|
||||||
while(!queue.empty()){
|
while(!queue.empty()){
|
||||||
Tile next = queue.poll();
|
Tile next = queue.poll();
|
||||||
float baseCost = costs.get(next.pos(), 0f);
|
float baseCost = costs[next.array()];
|
||||||
if(next == end){
|
if(next == end){
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@@ -58,7 +65,7 @@ public class Astar{
|
|||||||
if(!closed.get(child.x, child.y)){
|
if(!closed.get(child.x, child.y)){
|
||||||
closed.set(child.x, child.y);
|
closed.set(child.x, child.y);
|
||||||
rotations[child.x][child.y] = child.relativeTo(next.x, next.y);
|
rotations[child.x][child.y] = child.relativeTo(next.x, next.y);
|
||||||
costs.put(child.pos(), newCost);
|
costs[child.array()] = newCost;
|
||||||
queue.add(child);
|
queue.add(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,9 +262,36 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
|
|||||||
for(Room room : roomseq){
|
for(Room room : roomseq){
|
||||||
spawn.connect(room);
|
spawn.connect(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
Room fspawn = spawn;
|
Room fspawn = spawn;
|
||||||
|
|
||||||
cells(1);
|
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);
|
distort(10f, 6f);
|
||||||
|
|
||||||
//rivers
|
//rivers
|
||||||
@@ -286,7 +313,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
|
|||||||
floor = spore ?
|
floor = spore ?
|
||||||
(deep ? Blocks.taintedWater : Blocks.darksandTaintedWater) :
|
(deep ? Blocks.taintedWater : Blocks.darksandTaintedWater) :
|
||||||
(deep ? Blocks.water :
|
(deep ? Blocks.water :
|
||||||
(floor == Blocks.sand ? Blocks.sandWater : Blocks.darksandWater));
|
(floor == Blocks.sand || floor == Blocks.salt ? Blocks.sandWater : Blocks.darksandWater));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ public class Tile implements Position, QuadTreeObject, Displayable{
|
|||||||
return Point2.pack(x, y);
|
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){
|
public byte relativeTo(Tile tile){
|
||||||
return relativeTo(tile.x, tile.y);
|
return relativeTo(tile.x, tile.y);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user