Wall generation
This commit is contained in:
@@ -182,7 +182,7 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
Tile end = tiles.getn(endX, endY);
|
||||
GridBits closed = new GridBits(width, height);
|
||||
IntFloatMap costs = new IntFloatMap();
|
||||
PriorityQueue<Tile> queue = new PriorityQueue<>(tiles.width() * tiles.height()/4, (a, b) -> Float.compare(costs.get(a.pos(), 0f) + dh.cost(a.x, a.y, end.x, end.y), costs.get(b.pos(), 0f) + dh.cost(b.x, b.y, end.x, end.y)));
|
||||
PriorityQueue<Tile> queue = new PriorityQueue<>(tiles.width * tiles.height /4, (a, b) -> Float.compare(costs.get(a.pos(), 0f) + dh.cost(a.x, a.y, end.x, end.y), costs.get(b.pos(), 0f) + dh.cost(b.x, b.y, end.x, end.y)));
|
||||
queue.add(start);
|
||||
boolean found = false;
|
||||
while(!queue.isEmpty()){
|
||||
|
||||
@@ -62,7 +62,7 @@ public class MapGenerator extends Generator{
|
||||
for(Tile tile : tiles){
|
||||
if(tile.overlay() == Blocks.spawn){
|
||||
int rad = 10;
|
||||
Geometry.circle(tile.x, tile.y, tiles.width(), tiles.height(), rad, (wx, wy) -> {
|
||||
Geometry.circle(tile.x, tile.y, tiles.width, tiles.height, rad, (wx, wy) -> {
|
||||
if(tile.overlay().itemDrop != null){
|
||||
tile.clearOverlay();
|
||||
}
|
||||
|
||||
@@ -20,11 +20,14 @@ public abstract class RandomGenerator extends Generator{
|
||||
public void generate(Tiles tiles){
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int y = 0; y < height; y++){
|
||||
floor = Blocks.air;
|
||||
block = Blocks.air;
|
||||
ore = Blocks.air;
|
||||
Tile prev = tiles.getn(x, y);
|
||||
floor = prev.floor();
|
||||
block = prev.block();
|
||||
ore = prev.overlay();
|
||||
generate(x, y);
|
||||
tiles.set(x, y, new Tile(x, y, floor, ore, block));
|
||||
prev.setFloor(floor.asFloor());
|
||||
prev.setBlock(block);
|
||||
prev.setOverlay(ore);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,4 +8,5 @@ public interface PlanetGenerator{
|
||||
float getHeight(Vec3 position);
|
||||
Color getColor(Vec3 position);
|
||||
void generate(Vec3 position, TileGen tile);
|
||||
void decorate(Tiles tiles);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@ package mindustry.maps.planet;
|
||||
import arc.graphics.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
//TODO refactor into generic planet class
|
||||
public class TestPlanetGenerator implements PlanetGenerator{
|
||||
Simplex noise = new Simplex();
|
||||
float scl = 5f;
|
||||
@@ -53,6 +56,57 @@ public class TestPlanetGenerator implements PlanetGenerator{
|
||||
@Override
|
||||
public void generate(Vec3 position, TileGen tile){
|
||||
tile.floor = getBlock(position);
|
||||
tile.block = tile.floor.asFloor().wall;
|
||||
|
||||
if(noise.octaveNoise3D(5, 0.6, 8.0, position.x, position.y, position.z) > 0.65){
|
||||
tile.block = Blocks.air;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(Tiles tiles){
|
||||
//OvergrowthGenerator generator = new OvergrowthGenerator(tiles.width, tiles.height);
|
||||
//generator.init(Loadouts.basicNucleus);
|
||||
//generator.generate(tiles);
|
||||
GridBits write = new GridBits(tiles.width, tiles.height);
|
||||
GridBits read = new GridBits(tiles.width, tiles.height);
|
||||
|
||||
//double removalChance = 0.2;
|
||||
//remove random tiles
|
||||
//tiles.each((x, y) -> {
|
||||
|
||||
//});
|
||||
|
||||
tiles.each((x, y) -> read.set(x, y, !tiles.get(x, y).block().isAir()));
|
||||
|
||||
int iterations = 4, birthLimit = 16, deathLimit = 16, radius = 3;
|
||||
|
||||
for(int i = 0; i < iterations; i++){
|
||||
tiles.each((x, y) -> {
|
||||
int alive = 0;
|
||||
|
||||
for(int cx = -radius; cx <= radius; cx++){
|
||||
for(int cy = -radius; cy <= radius; cy++){
|
||||
if((cx == 0 && cy == 0) || !Mathf.within(cx, cy, radius)) continue;
|
||||
if(!Structs.inBounds(x + cx, y + cy, tiles.width, tiles.height) || read.get(x + cx, y + cy)){
|
||||
alive++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(read.get(x, y)){
|
||||
write.set(x, y, alive >= deathLimit);
|
||||
}else{
|
||||
write.set(x, y, alive > birthLimit);
|
||||
}
|
||||
});
|
||||
|
||||
//flush results.
|
||||
tiles.each((x, y) -> read.set(x, y, write.get(x, y)));
|
||||
}
|
||||
|
||||
tiles.each((x, y) -> tiles.get(x, y).setBlock(!write.get(x, y) ? Blocks.air : tiles.get(x, y).floor().wall));
|
||||
tiles.get(tiles.width /2, tiles.height /2).setBlock(Blocks.coreShard, Team.sharded);
|
||||
}
|
||||
|
||||
Block getBlock(Vec3 position){
|
||||
|
||||
@@ -7,6 +7,7 @@ import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.schematics;
|
||||
|
||||
//TODO remove
|
||||
public class DesertWastesGenerator extends BasicGenerator{
|
||||
|
||||
public DesertWastesGenerator(int width, int height){
|
||||
|
||||
@@ -7,6 +7,7 @@ import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.schematics;
|
||||
|
||||
//TODO remove
|
||||
public class OvergrowthGenerator extends BasicGenerator{
|
||||
|
||||
public OvergrowthGenerator(int width, int height){
|
||||
@@ -15,13 +16,12 @@ public class OvergrowthGenerator extends BasicGenerator{
|
||||
|
||||
@Override
|
||||
public void generate(int x, int y){
|
||||
floor = Blocks.moss;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(Tiles tiles){
|
||||
ores(tiles);
|
||||
terrain(tiles, Blocks.sporePine, 70f, 1.4f, 1f);
|
||||
//terrain(tiles, Blocks.sporePine, 70f, 1.4f, 1f);
|
||||
|
||||
int rand = 40;
|
||||
int border = 25;
|
||||
@@ -36,7 +36,7 @@ public class OvergrowthGenerator extends BasicGenerator{
|
||||
distort(tiles, 20f, 4f);
|
||||
inverseFloodFill(tiles, tiles.getn(spawnX, spawnY), Blocks.sporerocks);
|
||||
|
||||
noise(tiles, Blocks.darksandTaintedWater, Blocks.duneRocks, 4, 0.7f, 120f, 0.64f);
|
||||
//noise(tiles, Blocks.darksandTaintedWater, Blocks.duneRocks, 4, 0.7f, 120f, 0.64f);
|
||||
//scatter(tiles, Blocks.sporePine, Blocks.whiteTreeDead, 1f);
|
||||
|
||||
tiles.getn(endX, endY).setOverlay(Blocks.spawn);
|
||||
|
||||
Reference in New Issue
Block a user