Asteroid/space improvements

This commit is contained in:
Anuken
2022-01-09 17:07:21 -05:00
parent 61025972eb
commit b31098ed87
8 changed files with 85 additions and 64 deletions

View File

@@ -183,42 +183,53 @@ public class SectorDamage{
if(core == null || spawns.isEmpty()) return;
boolean airOnly = !state.rules.spawns.contains(g -> !g.type.flying);
Tile start = spawns.first();
var field = pathfinder.getField(state.rules.waveTeam, Pathfinder.costGround, Pathfinder.fieldCore);
Seq<Tile> path = new Seq<>();
boolean found = false;
if(field != null && field.weights != null){
int[][] weights = field.weights;
int count = 0;
Tile current = start;
while(count < world.width() * world.height()){
int minCost = Integer.MAX_VALUE;
int cx = current.x, cy = current.y;
for(Point2 p : Geometry.d4){
int nx = cx + p.x, ny = cy + p.y;
//TODO would be nice if this worked in a more generic way, with two different calculations and paths
if(airOnly){
world.raycastEach(start.x, start.y, core.tileX(), core.tileY(), (x, y) -> {
path.add(world.rawTile(x, y));
return false;
});
}else{
var field = pathfinder.getField(state.rules.waveTeam, Pathfinder.costGround, Pathfinder.fieldCore);
boolean found = false;
Tile other = world.tile(nx, ny);
if(other != null && weights[nx][ny] < minCost && weights[nx][ny] != -1){
minCost = weights[nx][ny];
current = other;
if(field != null && field.weights != null){
int[][] weights = field.weights;
int count = 0;
Tile current = start;
while(count < world.width() * world.height()){
int minCost = Integer.MAX_VALUE;
int cx = current.x, cy = current.y;
for(Point2 p : Geometry.d4){
int nx = cx + p.x, ny = cy + p.y;
Tile other = world.tile(nx, ny);
if(other != null && weights[nx][ny] < minCost && weights[nx][ny] != -1){
minCost = weights[nx][ny];
current = other;
}
}
path.add(current);
if(current.build == core){
found = true;
break;
}
count ++;
}
path.add(current);
if(current.build == core){
found = true;
break;
}
count ++;
}
}
if(!found){
path = Astar.pathfind(start, core.tile, SectorDamage::cost, t -> !(t.block().isStatic() && t.solid()));
if(!found){
path.clear();
path.addAll(Astar.pathfind(start, core.tile, SectorDamage::cost, t -> !(t.block().isStatic() && t.solid())));
}
}
//create sparse tile array for fast range query

View File

@@ -118,8 +118,8 @@ public class AsteroidGenerator extends BlankPlanetGenerator{
wallOre(Blocks.beryllicStoneWall, Blocks.wallOreBeryl, 50f, 0.62f * berylliumScale);
//TODO:
//- copper maybe should not exist
//- consider replacing certain ores with something else
//- enemy wave spawns
//- never ending
//titanium
pass((x, y) -> {
@@ -131,6 +131,10 @@ public class AsteroidGenerator extends BlankPlanetGenerator{
}
});
int spawnSide = rand.random(3);
int sizeOffset = width / 2 - 1;
tiles.getn(sizeOffset * Geometry.d8edge[spawnSide].x + width/2, sizeOffset * Geometry.d8edge[spawnSide].y + height/2).setOverlay(Blocks.spawn);
Schematics.placeLaunchLoadout(sx, sy);
state.rules.planetBackground = new PlanetParams(){{
@@ -139,9 +143,19 @@ public class AsteroidGenerator extends BlankPlanetGenerator{
camPos = new Vec3(1.2388899f, 1.6047299f, 2.4758825f);
}};
//state.rules.backgroundTexture = "sprites/space.png";
state.rules.dragMultiplier = 0.7f; //yes, yes space has 0 drag but 0% drag is very annoying
state.rules.dragMultiplier = 0.7f; //yes, space actually has 0 drag but true 0% drag is very annoying
state.rules.borderDarkness = false;
state.rules.environment = Env.space;
state.rules.waves = true;
//TODO maybe make this on by default everywhere
state.rules.showSpawns = true;
//TODO better wavegen, do it by hand even
state.rules.spawns = Waves.generate(0.5f, rand, false, true, false);
}
@Override
public Schematic getDefaultLoadout(){
return Loadouts.spaceNucleus;
}
@Override