Skip to content

Commit

Permalink
Sector wave spawning fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Aug 16, 2021
1 parent ff5c48a commit 0c5f781
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 22 deletions.
13 changes: 13 additions & 0 deletions core/src/mindustry/ai/WaveSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class WaveSpawner{
private static final float margin = 40f, coreMargin = tilesize * 2f, maxSteps = 30;

private int tmpCount;
private Seq<Tile> spawns = new Seq<>();
private boolean spawning = false;
private boolean any = false;
Expand Down Expand Up @@ -162,6 +163,18 @@ private void eachFlyerSpawn(Floatc2 cons){
}
}

public int countGroundSpawns(){
tmpCount = 0;
eachGroundSpawn((x, y) -> tmpCount ++);
return tmpCount;
}

public int countFlyerSpawns(){
tmpCount = 0;
eachFlyerSpawn((x, y) -> tmpCount ++);
return tmpCount;
}

public boolean isSpawning(){
return spawning && !net.client();
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/mindustry/game/Schematics.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.sandbox.*;
import mindustry.world.blocks.storage.*;
import mindustry.world.blocks.storage.CoreBlock.*;
import mindustry.world.meta.*;

import java.io.*;
Expand Down Expand Up @@ -450,6 +451,10 @@ public static void placeLoadout(Schematic schem, int x, int y, Team team, Block
if(st.block instanceof Drill){
tile.getLinkedTiles(t -> t.setOverlay(resource));
}

if(tile.build instanceof CoreBuild cb){
state.teams.registerCore(cb);
}
});
}

Expand Down
14 changes: 12 additions & 2 deletions core/src/mindustry/game/Waves.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,23 @@ public static Seq<SpawnGroup> generate(float difficulty){
}

public static Seq<SpawnGroup> generate(float difficulty, Rand rand, boolean attack){
return generate(difficulty, rand, attack, false);
}

public static Seq<SpawnGroup> generate(float difficulty, Rand rand, boolean attack, boolean airOnly){
UnitType[][] species = {
{dagger, mace, fortress, scepter, reign},
{nova, pulsar, quasar, vela, corvus},
{crawler, atrax, spiroct, arkyid, toxopid},
{flare, horizon, zenith, rand.chance(0.5) ? quad : antumbra, rand.chance(0.1) ? quad : eclipse}
};

if(airOnly){
species = Structs.filter(UnitType[].class, species, v -> v[0].flying);
}

UnitType[][] fspec = species;

//required progression:
//- extra periodic patterns

Expand All @@ -281,7 +291,7 @@ public static Seq<SpawnGroup> generate(float difficulty, Rand rand, boolean atta

Intc createProgression = start -> {
//main sequence
UnitType[] curSpecies = Structs.random(species);
UnitType[] curSpecies = Structs.random(fspec);
int curTier = 0;

for(int i = start; i < cap;){
Expand Down Expand Up @@ -326,7 +336,7 @@ public static Seq<SpawnGroup> generate(float difficulty, Rand rand, boolean atta

//small chance to switch species
if(rand.chance(0.3)){
curSpecies = Structs.random(species);
curSpecies = Structs.random(fspec);
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ void connect(Room to){
state.rules.waves = sector.info.waves = true;
state.rules.enemyCoreBuildRadius = 600f;

state.rules.spawns = Waves.generate(difficulty, new Rand(), state.rules.attackMode);
//spawn air only when spawn is blocked
state.rules.spawns = Waves.generate(difficulty, new Rand(sector.id), state.rules.attackMode, state.rules.attackMode && spawner.countGroundSpawns() == 0);
}

@Override
Expand Down
21 changes: 3 additions & 18 deletions core/src/mindustry/net/ArcNetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,24 +342,9 @@ public static class PacketSerializer implements NetSerializer{
//for debugging total read/write speeds
private static final boolean debug = false;

ThreadLocal<ByteBuffer> decompressBuffer = new ThreadLocal<>(){
@Override
protected ByteBuffer initialValue(){
return ByteBuffer.allocate(32768);
}
};
ThreadLocal<Reads> reads = new ThreadLocal<>(){
@Override
protected Reads initialValue(){
return new Reads(new ByteBufferInput(decompressBuffer.get()));
}
};
ThreadLocal<Writes> writes = new ThreadLocal<>(){
@Override
protected Writes initialValue(){
return new Writes(new ByteBufferOutput(decompressBuffer.get()));
}
};
ThreadLocal<ByteBuffer> decompressBuffer = Threads.local(() -> ByteBuffer.allocate(32768));
ThreadLocal<Reads> reads = Threads.local(() -> new Reads(new ByteBufferInput(decompressBuffer.get())));
ThreadLocal<Writes> writes = Threads.local(() -> new Writes(new ByteBufferOutput(decompressBuffer.get())));

//for debugging network write counts
static WindowedMean upload = new WindowedMean(5), download = new WindowedMean(5);
Expand Down
1 change: 1 addition & 0 deletions core/src/mindustry/net/Net.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public void handleClientReceived(Packet object){
builder.add(c.data);

ui.loadfrag.setProgress(builder.progress());
ui.loadfrag.snapProgress();
netClient.resetTimeout();

if(builder.isDone()){
Expand Down
4 changes: 4 additions & 0 deletions core/src/mindustry/ui/Bar.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public void set(Prov<String> name, Floatp fraction, Color color){
update(() -> this.name = name.get());
}

public void snap(){
lastValue = value = fraction.get();
}

public Bar outline(Color color, float stroke){
outlineColor.set(color);
outlineRadius = Scl.scl(stroke);
Expand Down
5 changes: 5 additions & 0 deletions core/src/mindustry/ui/fragments/LoadingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ public void setProgress(Floatp progress){
bar.set(() -> ((int)(progress.get() * 100) + "%"), progress, Pal.accent);
}

public void snapProgress(){
bar.snap();
}

public void setProgress(float progress){
progValue = progress;
if(!bar.visible){
setProgress(() -> progValue);
}

}

public void setButton(Runnable listener){
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ android.useAndroidX=true
#used for slow jitpack builds; TODO see if this actually works
http.socketTimeout=80000
http.connectionTimeout=80000
archash=4582339cd9052be86141fbacf2f2180b09eb585c
archash=0d9a003fc8f70b58f739bfacc3817b4c2522a8af

1 comment on commit 0c5f781

@nekit508
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

,_,

Please sign in to comment.