Skip to content

Commit

Permalink
Fixed #10373
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Dec 14, 2024
1 parent 14b98fd commit 3ff6f83
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
30 changes: 17 additions & 13 deletions core/src/mindustry/maps/generators/BaseGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public void generate(Tiles tiles, Seq<Tile> cores, Tile spawn, Team team, Sector
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<BasePart> 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);
}
});
}
Expand Down Expand Up @@ -191,21 +191,20 @@ void pass(Cons<Tile> cons){
* 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;
Expand All @@ -215,15 +214,18 @@ public static boolean tryPlace(BasePart part, int x, int y, Team team, @Nullable
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);
}
}

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) -> {
Expand All @@ -235,7 +237,7 @@ public static boolean tryPlace(BasePart part, int x, int y, Team team, @Nullable
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);
Expand Down Expand Up @@ -273,6 +275,8 @@ static void set(Tile tile, Item item){
}

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;
Expand Down
10 changes: 5 additions & 5 deletions core/src/mindustry/maps/generators/BasicGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void cliffs(){

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);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public void noise(Block floor, Block block, int octaves, float falloff, float sc

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;
}
});
Expand All @@ -227,14 +227,14 @@ public void tech(Block floor1, Block floor2, Block wall){
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;
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ public void distort(float scl, float mag){

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){
Expand Down
1 change: 0 additions & 1 deletion core/src/mindustry/maps/generators/PlanetGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
10 changes: 5 additions & 5 deletions core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ void connectLiquid(Room to){
//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;
}
Expand All @@ -542,11 +542,11 @@ void connectLiquid(Room to){
});

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
Expand Down Expand Up @@ -586,7 +586,7 @@ void connectLiquid(Room to){
}

//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);
Expand Down

0 comments on commit 3ff6f83

Please sign in to comment.