From 0c5f781702a5327c0ed640d6c2354d30c5ea9c9e Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 16 Aug 2021 11:42:59 -0400 Subject: [PATCH] Sector wave spawning fixes --- core/src/mindustry/ai/WaveSpawner.java | 13 ++++++++++++ core/src/mindustry/game/Schematics.java | 5 +++++ core/src/mindustry/game/Waves.java | 14 +++++++++++-- .../maps/planet/SerpuloPlanetGenerator.java | 3 ++- core/src/mindustry/net/ArcNetProvider.java | 21 +++---------------- core/src/mindustry/net/Net.java | 1 + core/src/mindustry/ui/Bar.java | 4 ++++ .../ui/fragments/LoadingFragment.java | 5 +++++ gradle.properties | 2 +- 9 files changed, 46 insertions(+), 22 deletions(-) diff --git a/core/src/mindustry/ai/WaveSpawner.java b/core/src/mindustry/ai/WaveSpawner.java index a895af863f20..40be2defadb6 100644 --- a/core/src/mindustry/ai/WaveSpawner.java +++ b/core/src/mindustry/ai/WaveSpawner.java @@ -21,6 +21,7 @@ public class WaveSpawner{ private static final float margin = 40f, coreMargin = tilesize * 2f, maxSteps = 30; + private int tmpCount; private Seq spawns = new Seq<>(); private boolean spawning = false; private boolean any = false; @@ -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(); } diff --git a/core/src/mindustry/game/Schematics.java b/core/src/mindustry/game/Schematics.java index 0a91c9d1b3f2..011d289f05d4 100644 --- a/core/src/mindustry/game/Schematics.java +++ b/core/src/mindustry/game/Schematics.java @@ -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.*; @@ -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); + } }); } diff --git a/core/src/mindustry/game/Waves.java b/core/src/mindustry/game/Waves.java index bdd95abedf19..415ccea8fc4f 100644 --- a/core/src/mindustry/game/Waves.java +++ b/core/src/mindustry/game/Waves.java @@ -261,6 +261,10 @@ public static Seq generate(float difficulty){ } public static Seq generate(float difficulty, Rand rand, boolean attack){ + return generate(difficulty, rand, attack, false); + } + + public static Seq generate(float difficulty, Rand rand, boolean attack, boolean airOnly){ UnitType[][] species = { {dagger, mace, fortress, scepter, reign}, {nova, pulsar, quasar, vela, corvus}, @@ -268,6 +272,12 @@ public static Seq generate(float difficulty, Rand rand, boolean atta {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 @@ -281,7 +291,7 @@ public static Seq 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;){ @@ -326,7 +336,7 @@ public static Seq 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); } } }; diff --git a/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java b/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java index 0effbc80f230..112838d40564 100644 --- a/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/SerpuloPlanetGenerator.java @@ -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 diff --git a/core/src/mindustry/net/ArcNetProvider.java b/core/src/mindustry/net/ArcNetProvider.java index ba8ff4cfa0f2..4cc05ecccb78 100644 --- a/core/src/mindustry/net/ArcNetProvider.java +++ b/core/src/mindustry/net/ArcNetProvider.java @@ -342,24 +342,9 @@ public static class PacketSerializer implements NetSerializer{ //for debugging total read/write speeds private static final boolean debug = false; - ThreadLocal decompressBuffer = new ThreadLocal<>(){ - @Override - protected ByteBuffer initialValue(){ - return ByteBuffer.allocate(32768); - } - }; - ThreadLocal reads = new ThreadLocal<>(){ - @Override - protected Reads initialValue(){ - return new Reads(new ByteBufferInput(decompressBuffer.get())); - } - }; - ThreadLocal writes = new ThreadLocal<>(){ - @Override - protected Writes initialValue(){ - return new Writes(new ByteBufferOutput(decompressBuffer.get())); - } - }; + ThreadLocal decompressBuffer = Threads.local(() -> ByteBuffer.allocate(32768)); + ThreadLocal reads = Threads.local(() -> new Reads(new ByteBufferInput(decompressBuffer.get()))); + ThreadLocal writes = Threads.local(() -> new Writes(new ByteBufferOutput(decompressBuffer.get()))); //for debugging network write counts static WindowedMean upload = new WindowedMean(5), download = new WindowedMean(5); diff --git a/core/src/mindustry/net/Net.java b/core/src/mindustry/net/Net.java index 9081b194f44b..2463c8fed916 100644 --- a/core/src/mindustry/net/Net.java +++ b/core/src/mindustry/net/Net.java @@ -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()){ diff --git a/core/src/mindustry/ui/Bar.java b/core/src/mindustry/ui/Bar.java index d8e2b4b6da4b..eb4fcf9a54d8 100644 --- a/core/src/mindustry/ui/Bar.java +++ b/core/src/mindustry/ui/Bar.java @@ -62,6 +62,10 @@ public void set(Prov 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); diff --git a/core/src/mindustry/ui/fragments/LoadingFragment.java b/core/src/mindustry/ui/fragments/LoadingFragment.java index fcd18dfcbede..4f977fa64431 100644 --- a/core/src/mindustry/ui/fragments/LoadingFragment.java +++ b/core/src/mindustry/ui/fragments/LoadingFragment.java @@ -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){ diff --git a/gradle.properties b/gradle.properties index 52e61753e2c9..5eb904834f07 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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