From 304ad74084c06793b26bbee38fdd21c7bc57c9c3 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 6 Oct 2024 10:05:51 -0400 Subject: [PATCH] Fixed packet spam on sector capture --- core/src/mindustry/content/Planets.java | 1 + core/src/mindustry/game/Teams.java | 38 ++++++++----------- core/src/mindustry/world/Tile.java | 11 ++++++ .../blocks/environment/OverlayFloor.java | 6 +++ .../world/blocks/environment/RemoveWall.java | 3 ++ gradle.properties | 2 +- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index a37488943c..338e25cadc 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -145,6 +145,7 @@ public class Planets{ r.waveTeam = Team.crux; r.placeRangeCheck = false; r.showSpawns = false; + r.coreDestroyClear = true; }; iconColor = Color.valueOf("7d4dff"); atmosphereColor = Color.valueOf("3c1b8f"); diff --git a/core/src/mindustry/game/Teams.java b/core/src/mindustry/game/Teams.java index c9a38fcb17..036cbc2d43 100644 --- a/core/src/mindustry/game/Teams.java +++ b/core/src/mindustry/game/Teams.java @@ -240,6 +240,8 @@ public class Teams{ } public static class TeamData{ + private static final IntSeq derelictBuffer = new IntSeq(); + public final Team team; /** Handles building ""bases"". */ @@ -317,6 +319,8 @@ public class Teams{ } } + finishScheduleDerelict(); + //kill all units randomly units.each(u -> Time.run(Mathf.random(0f, 60f * 5f), () -> { //ensure unit hasn't switched teams for whatever reason @@ -326,21 +330,7 @@ public class Teams{ })); } - /** Make all buildings within this range derelict / explode. */ - public void makeDerelict(float x, float y, float range){ - var builds = new Seq(); - if(buildingTree != null){ - buildingTree.intersect(x - range, y - range, range * 2f, range * 2f, builds); - } - - for(var build : builds){ - if(build.within(x, y, range) && !build.block.privileged){ - scheduleDerelict(build); - } - } - } - - /** Make all buildings within this range explode. */ + /** Make all buildings within this range derelict/explode. */ public void timeDestroy(float x, float y, float range){ var builds = new Seq(); if(buildingTree != null){ @@ -348,27 +338,31 @@ public class Teams{ } for(var build : builds){ - if(build.within(x, y, range) && !cores.contains(c -> c.within(build, range))){ - //TODO GPU driver bugs? - build.kill(); - //Time.run(Mathf.random(0f, 60f * 6f), build::kill); + if(!build.block.privileged && build.within(x, y, range) && !cores.contains(c -> c.within(build, range))){ + scheduleDerelict(build); } } + finishScheduleDerelict(); } private void scheduleDerelict(Building build){ - //TODO this may cause a lot of packet spam, optimize? - Call.setTeam(build, Team.derelict); + //queue block to be handled later, avoid packet spam + derelictBuffer.add(build.pos()); if(build.getPayload() instanceof UnitPayload){ Call.destroyPayload(build); } - if(Mathf.chance(0.25)){ + if(Mathf.chance(0.2)){ Time.run(Mathf.random(0f, 60f * 6f), build::kill); } } + private void finishScheduleDerelict(){ + derelictBuffer.chunked(1000, values -> Call.setTeams(values, Team.derelict)); + derelictBuffer.clear(); + } + //this is just an alias for consistency @Nullable public Seq getUnits(UnitType type){ diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index fb1a912853..4cd41c2b45 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -755,6 +755,17 @@ public class Tile implements Position, QuadTreeObject, Displayable{ } } + @Remote(called = Loc.server) + public static void setTeams(int[] positions, Team team){ + if(positions == null) return; + for(int pos : positions){ + Tile tile = world.tile(pos); + if(tile != null && tile.build != null){ + tile.build.changeTeam(team); + } + } + } + @Remote(called = Loc.server) public static void buildDestroyed(Building build){ if(build == null) return; diff --git a/core/src/mindustry/world/blocks/environment/OverlayFloor.java b/core/src/mindustry/world/blocks/environment/OverlayFloor.java index c20eccceaf..c7d5a10f28 100644 --- a/core/src/mindustry/world/blocks/environment/OverlayFloor.java +++ b/core/src/mindustry/world/blocks/environment/OverlayFloor.java @@ -2,6 +2,7 @@ package mindustry.world.blocks.environment; import arc.graphics.g2d.*; import arc.math.*; +import mindustry.game.*; import mindustry.world.*; /**A type of floor that is overlaid on top of other floors.*/ @@ -12,6 +13,11 @@ public class OverlayFloor extends Floor{ useColor = false; } + @Override + public boolean canPlaceOn(Tile tile, Team team, int rotation){ + return !wallOre || tile.block().solid; + } + @Override public void drawBase(Tile tile){ Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy()); diff --git a/core/src/mindustry/world/blocks/environment/RemoveWall.java b/core/src/mindustry/world/blocks/environment/RemoveWall.java index 039997acdc..0359ee7052 100644 --- a/core/src/mindustry/world/blocks/environment/RemoveWall.java +++ b/core/src/mindustry/world/blocks/environment/RemoveWall.java @@ -45,6 +45,9 @@ public class RemoveWall extends Block{ @Override public void placeEnded(Tile tile, @Nullable Unit builder){ tile.setBlock(Blocks.air); + if(tile.overlay().wallOre){ + tile.setOverlay(Blocks.air); + } } } diff --git a/gradle.properties b/gradle.properties index df1e036f95..edfdba6f2f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,4 +26,4 @@ org.gradle.caching=true org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 android.enableR8.fullMode=false -archash=e2aba22b1f +archash=89c7f1aee6