From 3ff6f834a556dbf9b626e11c010d7b314e43e0e1 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 14 Dec 2024 13:25:04 -0500 Subject: [PATCH] Fixed #10373 --- .../maps/generators/BaseGenerator.java | 30 +++++++++++-------- .../maps/generators/BasicGenerator.java | 10 +++---- .../maps/generators/PlanetGenerator.java | 1 - .../maps/planet/SerpuloPlanetGenerator.java | 10 +++---- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/core/src/mindustry/maps/generators/BaseGenerator.java b/core/src/mindustry/maps/generators/BaseGenerator.java index 71ccc7810c..013a4575e4 100644 --- a/core/src/mindustry/maps/generators/BaseGenerator.java +++ b/core/src/mindustry/maps/generators/BaseGenerator.java @@ -74,14 +74,14 @@ public class BaseGenerator{ pass(tile -> { if(!tile.block().alwaysReplace) return; - if(((tile.overlay().asFloor().itemDrop != null || (tile.drop() != null && Mathf.chance(nonResourceChance))) - || (tile.floor().liquidDrop != null && Mathf.chance(nonResourceChance * 2))) && Mathf.chance(resourceChance)){ + if(((tile.overlay().asFloor().itemDrop != null || (tile.drop() != null && Mathf.rand.chance(nonResourceChance))) + || (tile.floor().liquidDrop != null && Mathf.rand.chance(nonResourceChance * 2))) && Mathf.rand.chance(resourceChance)){ Seq parts = bases.forResource(tile.drop() != null ? tile.drop() : tile.floor().liquidDrop); 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)){ - tryPlace(bases.parts.getFrac(Mathf.rand.random(1f)), tile.x, tile.y, team); + }else if(Mathf.rand.chance(nonResourceChance)){ + 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. * @return success state * */ - public static boolean tryPlace(BasePart part, int x, int y, Team team){ - return tryPlace(part, x, y, team, null); + public static boolean tryPlace(BasePart part, int x, int y, Team team, Rand rand){ + return tryPlace(part, x, y, team, rand, null); } /** * Tries to place a base part at a certain location with a certain team. * @return success state * */ - public static boolean tryPlace(BasePart part, int x, int y, Team team, @Nullable Intc2 posc){ - int rotation = Mathf.range(2); + public static boolean tryPlace(BasePart part, int x, int y, Team team, Rand random, @Nullable Intc2 posc){ + int rotation = random.range(2); axis.set((int)(part.schematic.width / 2f), (int)(part.schematic.height / 2f)); 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 int cx = x - (int)rotator.x; int cy = y - (int)rotator.y; @@ -215,7 +214,11 @@ public class BaseGenerator{ if(!insanity && isTaken(tile.block, realX, realY)){ return false; } + } + //only do callback after validation + for(Stile tile : result.tiles){ + int realX = tile.x + cx, realY = tile.y + cy; if(posc != null){ posc.get(realX, realY); } @@ -223,7 +226,6 @@ public class BaseGenerator{ if(part.required instanceof Item item){ 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))){ tile.block.iterateTaken(tile.x + cx, tile.y + cy, (ex, ey) -> { @@ -235,7 +237,7 @@ public class BaseGenerator{ 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()){ //random ores nearby to make it look more natural set(rand, item); @@ -273,6 +275,8 @@ public class BaseGenerator{ } 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 offsety = -(block.size - 1) / 2; int pad = 1; diff --git a/core/src/mindustry/maps/generators/BasicGenerator.java b/core/src/mindustry/maps/generators/BasicGenerator.java index 40f5dc44f5..3daa39c68f 100644 --- a/core/src/mindustry/maps/generators/BasicGenerator.java +++ b/core/src/mindustry/maps/generators/BasicGenerator.java @@ -158,7 +158,7 @@ public abstract class BasicGenerator implements WorldGenerator{ int rotation = 0; 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()){ 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){ 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; } }); @@ -227,14 +227,14 @@ public abstract class BasicGenerator implements WorldGenerator{ int mx = x % secSize, my = 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(Mathf.chance(noise(x + 0x231523, y, 40f, 1f))){ + if(rand.chance(noise(x + 0x231523, y, 40f, 1f))){ floor = floor1; if(Mathf.dst(mx, my, secSize/2, secSize/2) > secSize/2f + 2){ floor = floor2; } } - if(block.solid && Mathf.chance(0.7)){ + if(block.solid && rand.chance(0.7)){ block = wall; } } @@ -262,7 +262,7 @@ public abstract class BasicGenerator implements WorldGenerator{ public void scatter(Block target, Block dst, float chance){ pass((x, y) -> { - if(!Mathf.chance(chance)) return; + if(!rand.chance(chance)) return; if(floor == target){ floor = dst; }else if(block == target){ diff --git a/core/src/mindustry/maps/generators/PlanetGenerator.java b/core/src/mindustry/maps/generators/PlanetGenerator.java index 710e63b0dd..69524884d7 100644 --- a/core/src/mindustry/maps/generators/PlanetGenerator.java +++ b/core/src/mindustry/maps/generators/PlanetGenerator.java @@ -20,7 +20,6 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe public int baseSeed = 0; public int seed = 0; - protected IntSeq ints = new IntSeq(); protected @Nullable Sector sector; /** Should generate sector bases for a planet. */ diff --git a/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java b/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java index 60feb2a2ab..bcc797b6d0 100644 --- a/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java @@ -529,7 +529,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{ //random stuff dec: { 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){ break dec; } @@ -542,11 +542,11 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{ }); float difficulty = sector.threat; - ints.clear(); - ints.ensureCapacity(width * height / 4); - int ruinCount = rand.random(-2, 4); + if(ruinCount > 0){ + IntSeq ints = new IntSeq(width * height / 4); + int padding = 25; //create list of potential positions @@ -586,7 +586,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{ } //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); if(other.floor().hasSurface()){ other.setOverlay(Blocks.oreScrap);