This commit is contained in:
Anuken 2024-12-14 13:25:04 -05:00
parent 14b98fd1e6
commit 3ff6f834a5
4 changed files with 27 additions and 24 deletions

View File

@ -74,14 +74,14 @@ public class BaseGenerator{
pass(tile -> { pass(tile -> {
if(!tile.block().alwaysReplace) return; if(!tile.block().alwaysReplace) return;
if(((tile.overlay().asFloor().itemDrop != null || (tile.drop() != null && Mathf.chance(nonResourceChance))) if(((tile.overlay().asFloor().itemDrop != null || (tile.drop() != null && Mathf.rand.chance(nonResourceChance)))
|| (tile.floor().liquidDrop != null && Mathf.chance(nonResourceChance * 2))) && Mathf.chance(resourceChance)){ || (tile.floor().liquidDrop != null && Mathf.rand.chance(nonResourceChance * 2))) && Mathf.rand.chance(resourceChance)){
Seq<BasePart> parts = bases.forResource(tile.drop() != null ? tile.drop() : tile.floor().liquidDrop); Seq<BasePart> parts = bases.forResource(tile.drop() != null ? tile.drop() : tile.floor().liquidDrop);
if(!parts.isEmpty()){ if(!parts.isEmpty()){
tryPlace(parts.getFrac(difficulty + Mathf.range(bracketRange)), tile.x, tile.y, team); tryPlace(parts.getFrac(difficulty + Mathf.rand.range(bracketRange)), tile.x, tile.y, team, Mathf.rand);
} }
}else if(Mathf.chance(nonResourceChance)){ }else if(Mathf.rand.chance(nonResourceChance)){
tryPlace(bases.parts.getFrac(Mathf.rand.random(1f)), tile.x, tile.y, team); tryPlace(bases.parts.getFrac(Mathf.rand.random(1f)), tile.x, tile.y, team, Mathf.rand);
} }
}); });
} }
@ -191,21 +191,20 @@ public class BaseGenerator{
* Tries to place a base part at a certain location with a certain team. * Tries to place a base part at a certain location with a certain team.
* @return success state * @return success state
* */ * */
public static boolean tryPlace(BasePart part, int x, int y, Team team){ public static boolean tryPlace(BasePart part, int x, int y, Team team, Rand rand){
return tryPlace(part, x, y, team, null); return tryPlace(part, x, y, team, rand, null);
} }
/** /**
* Tries to place a base part at a certain location with a certain team. * Tries to place a base part at a certain location with a certain team.
* @return success state * @return success state
* */ * */
public static boolean tryPlace(BasePart part, int x, int y, Team team, @Nullable Intc2 posc){ public static boolean tryPlace(BasePart part, int x, int y, Team team, Rand random, @Nullable Intc2 posc){
int rotation = Mathf.range(2); int rotation = random.range(2);
axis.set((int)(part.schematic.width / 2f), (int)(part.schematic.height / 2f)); axis.set((int)(part.schematic.width / 2f), (int)(part.schematic.height / 2f));
Schematic result = Schematics.rotate(part.schematic, rotation); Schematic result = Schematics.rotate(part.schematic, rotation);
int rotdeg = rotation*90;
rotator.set(part.centerX, part.centerY).rotateAround(axis, rotdeg); rotator.set(part.centerX, part.centerY).rotateAround(axis, rotation * 90);
//bottom left schematic corner //bottom left schematic corner
int cx = x - (int)rotator.x; int cx = x - (int)rotator.x;
int cy = y - (int)rotator.y; int cy = y - (int)rotator.y;
@ -215,7 +214,11 @@ public class BaseGenerator{
if(!insanity && isTaken(tile.block, realX, realY)){ if(!insanity && isTaken(tile.block, realX, realY)){
return false; return false;
} }
}
//only do callback after validation
for(Stile tile : result.tiles){
int realX = tile.x + cx, realY = tile.y + cy;
if(posc != null){ if(posc != null){
posc.get(realX, realY); posc.get(realX, realY);
} }
@ -223,7 +226,6 @@ public class BaseGenerator{
if(part.required instanceof Item item){ if(part.required instanceof Item item){
for(Stile tile : result.tiles){ for(Stile tile : result.tiles){
//uncomment for extra checks if changed above
if(tile.block instanceof Drill && (!insanity || !isTaken(tile.block, tile.x + cx, tile.y + cy))){ if(tile.block instanceof Drill && (!insanity || !isTaken(tile.block, tile.x + cx, tile.y + cy))){
tile.block.iterateTaken(tile.x + cx, tile.y + cy, (ex, ey) -> { tile.block.iterateTaken(tile.x + cx, tile.y + cy, (ex, ey) -> {
@ -235,7 +237,7 @@ public class BaseGenerator{
set(placed, item); set(placed, item);
} }
Tile rand = world.tiles.getc(ex + Mathf.rand.range(1), ey + Mathf.rand.range(1)); Tile rand = world.tiles.getc(ex + random.range(1), ey + random.range(1));
if(rand.floor().hasSurface()){ if(rand.floor().hasSurface()){
//random ores nearby to make it look more natural //random ores nearby to make it look more natural
set(rand, item); set(rand, item);
@ -273,6 +275,8 @@ public class BaseGenerator{
} }
static boolean isTaken(Block block, int x, int y){ static boolean isTaken(Block block, int x, int y){
if(state.teams.anyEnemyCoresWithin(state.rules.waveTeam, x * tilesize + block.offset, y * tilesize + block.offset, state.rules.enemyCoreBuildRadius + tilesize)) return true;
int offsetx = -(block.size - 1) / 2; int offsetx = -(block.size - 1) / 2;
int offsety = -(block.size - 1) / 2; int offsety = -(block.size - 1) / 2;
int pad = 1; int pad = 1;

View File

@ -158,7 +158,7 @@ public abstract class BasicGenerator implements WorldGenerator{
int rotation = 0; int rotation = 0;
for(int i = 0; i < 8; i++){ for(int i = 0; i < 8; i++){
Tile other = world.tiles.get(tile.x + Geometry.d8[i].x, tile.y + Geometry.d8[i].y); Tile other = tiles.get(tile.x + Geometry.d8[i].x, tile.y + Geometry.d8[i].y);
if(other != null && !other.block().isStatic()){ if(other != null && !other.block().isStatic()){
rotation |= (1 << i); rotation |= (1 << i);
} }
@ -209,7 +209,7 @@ public abstract class BasicGenerator implements WorldGenerator{
public void overlay(Block floor, Block block, float chance, int octaves, float falloff, float scl, float threshold){ public void overlay(Block floor, Block block, float chance, int octaves, float falloff, float scl, float threshold){
pass((x, y) -> { pass((x, y) -> {
if(noise(x, y, octaves, falloff, scl) > threshold && Mathf.chance(chance) && tiles.getn(x, y).floor() == floor){ if(noise(x, y, octaves, falloff, scl) > threshold && rand.chance(chance) && tiles.getn(x, y).floor() == floor){
ore = block; ore = block;
} }
}); });
@ -227,14 +227,14 @@ public abstract class BasicGenerator implements WorldGenerator{
int mx = x % secSize, my = y % secSize; int mx = x % secSize, my = y % secSize;
int sclx = x / secSize, scly = y / secSize; int sclx = x / secSize, scly = y / secSize;
if(noise(sclx, scly, 0.2f, 1f) > 0.63f && noise(sclx, scly + 999, 200f, 1f) > 0.6f && (mx == 0 || my == 0 || mx == secSize - 1 || my == secSize - 1)){ if(noise(sclx, scly, 0.2f, 1f) > 0.63f && noise(sclx, scly + 999, 200f, 1f) > 0.6f && (mx == 0 || my == 0 || mx == secSize - 1 || my == secSize - 1)){
if(Mathf.chance(noise(x + 0x231523, y, 40f, 1f))){ if(rand.chance(noise(x + 0x231523, y, 40f, 1f))){
floor = floor1; floor = floor1;
if(Mathf.dst(mx, my, secSize/2, secSize/2) > secSize/2f + 2){ if(Mathf.dst(mx, my, secSize/2, secSize/2) > secSize/2f + 2){
floor = floor2; floor = floor2;
} }
} }
if(block.solid && Mathf.chance(0.7)){ if(block.solid && rand.chance(0.7)){
block = wall; block = wall;
} }
} }
@ -262,7 +262,7 @@ public abstract class BasicGenerator implements WorldGenerator{
public void scatter(Block target, Block dst, float chance){ public void scatter(Block target, Block dst, float chance){
pass((x, y) -> { pass((x, y) -> {
if(!Mathf.chance(chance)) return; if(!rand.chance(chance)) return;
if(floor == target){ if(floor == target){
floor = dst; floor = dst;
}else if(block == target){ }else if(block == target){

View File

@ -20,7 +20,6 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe
public int baseSeed = 0; public int baseSeed = 0;
public int seed = 0; public int seed = 0;
protected IntSeq ints = new IntSeq();
protected @Nullable Sector sector; protected @Nullable Sector sector;
/** Should generate sector bases for a planet. */ /** Should generate sector bases for a planet. */

View File

@ -529,7 +529,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
//random stuff //random stuff
dec: { dec: {
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
Tile near = world.tile(x + Geometry.d4[i].x, y + Geometry.d4[i].y); Tile near = tiles.get(x + Geometry.d4[i].x, y + Geometry.d4[i].y);
if(near != null && near.block() != Blocks.air){ if(near != null && near.block() != Blocks.air){
break dec; break dec;
} }
@ -542,11 +542,11 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
}); });
float difficulty = sector.threat; float difficulty = sector.threat;
ints.clear();
ints.ensureCapacity(width * height / 4);
int ruinCount = rand.random(-2, 4); int ruinCount = rand.random(-2, 4);
if(ruinCount > 0){ if(ruinCount > 0){
IntSeq ints = new IntSeq(width * height / 4);
int padding = 25; int padding = 25;
//create list of potential positions //create list of potential positions
@ -586,7 +586,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
} }
//actually place the part //actually place the part
if(part != null && BaseGenerator.tryPlace(part, x, y, Team.derelict, (cx, cy) -> { if(part != null && BaseGenerator.tryPlace(part, x, y, Team.derelict, rand, (cx, cy) -> {
Tile other = tiles.getn(cx, cy); Tile other = tiles.getn(cx, cy);
if(other.floor().hasSurface()){ if(other.floor().hasSurface()){
other.setOverlay(Blocks.oreScrap); other.setOverlay(Blocks.oreScrap);