Skip to content

Commit

Permalink
Show spawn radius in vulnerable sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
BalaM314 committed Dec 18, 2023
1 parent 4d28cd7 commit d931f3f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/mindustry/game/Universe.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void runTurn(){

//queue random invasions
if(!sector.isAttacked() && sector.planet.allowSectorInvasion && sector.info.minutesCaptured > invasionGracePeriod && sector.info.hasSpawns){
int count = sector.near().count(s -> s.hasEnemyBase() && !s.hasBase());
int count = sector.nearbyEnemyBases();

//invasion chance depends on # of nearby bases
if(count > 0 && Mathf.chance(baseInvasionChance * (0.8f + (count - 1) * 0.3f))){
Expand Down
8 changes: 4 additions & 4 deletions core/src/mindustry/graphics/OverlayRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ public void drawTop(){
Lines.stroke(2f);
Draw.color(Color.gray, Color.lightGray, Mathf.absin(Time.time, 8f, 1f));

if(state.hasSpawns()){
if(state.hasSpawns() || state.hasSector() && state.getSector().vulnerable()){
Core.camera.bounds(Tmp.r1);
boolean isBuilding = input.isBreaking() || input.isPlacing() || input.selectPlans.any() || Core.settings.getBool("alwaysshowdropzone", true);
int r = state.rules.dropZoneRadius;
float r = state.rules.dropZoneRadius;
for(Tile tile : spawner.getSpawns()){
if(tile.within(player.x, player.y, r + spawnerMargin) || (Tmp.r1.overlaps(tile.getX() - r, tile.getY() - r, r * 2, r * 2) && isBuilding)){
Draw.alpha(building ? 1 : Mathf.clamp(1f - (player.dst(tile) - state.rules.dropZoneRadius) / spawnerMargin));
Lines.dashCircle(tile.worldx(), tile.worldy(), state.rules.dropZoneRadius);
Draw.alpha(!state.hasSpawns() ? 0.3 : isBuilding ? 1 : Mathf.clamp(1f - (player.dst(tile) - r) / spawnerMargin));
Lines.dashCircle(tile.worldx(), tile.worldy(), r);
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions core/src/mindustry/type/Sector.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ public void near(Cons<Sector> cons){
}
}

public int nearbyEnemyBases(){
int bases = 0;
for(Ptile tile : tile.tiles){
Sector s = planet.getSector(tile);
if(s.hasEnemyBase() && !s.hasBase()){
bases ++;
}
}
return bases;
}

public boolean vulnerable(){
if(!planet.allowSectorInvasion) return false;
for(Ptile tile : tile.tiles){
Sector s = planet.getSector(tile);
if(s.hasEnemyBase() && !s.hasBase()){
return true;
}
}
return false;
}

/** Displays threat as a formatted string. */
public String displayThreat(){
float step = 0.25f;
Expand Down

0 comments on commit d931f3f

Please sign in to comment.