From 5d76dd0e2fa7f2297e84aefd926a146747049886 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 13 Oct 2020 15:56:00 -0400 Subject: [PATCH] Fixed #2929 --- core/src/mindustry/ai/BlockIndexer.java | 16 +++++---- core/src/mindustry/ai/types/LogicAI.java | 2 +- core/src/mindustry/entities/Units.java | 18 ++++------ .../mindustry/entities/comp/BulletComp.java | 14 +++----- core/src/mindustry/game/Team.java | 6 ++-- core/src/mindustry/game/Teams.java | 35 +++++++++++++++---- core/src/mindustry/logic/LExecutor.java | 8 +++-- 7 files changed, 58 insertions(+), 41 deletions(-) diff --git a/core/src/mindustry/ai/BlockIndexer.java b/core/src/mindustry/ai/BlockIndexer.java index 63151e0d11..6092c83910 100644 --- a/core/src/mindustry/ai/BlockIndexer.java +++ b/core/src/mindustry/ai/BlockIndexer.java @@ -10,6 +10,7 @@ import arc.util.*; import mindustry.content.*; import mindustry.game.EventType.*; import mindustry.game.*; +import mindustry.game.Teams.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; @@ -205,13 +206,14 @@ public class BlockIndexer{ /** Get all enemy blocks with a flag. */ public Seq getEnemy(Team team, BlockFlag type){ returnArray.clear(); - for(Team enemy : team.enemies()){ - if(state.teams.isActive(enemy)){ - TileArray set = getFlagged(enemy)[type.ordinal()]; - if(set != null){ - for(Tile tile : set){ - returnArray.add(tile); - } + Seq data = state.teams.present; + for(int i = 0; i < data.size; i++){ + Team enemy = data.items[i].team; + if(enemy == team) continue; + TileArray set = getFlagged(enemy)[type.ordinal()]; + if(set != null){ + for(Tile tile : set){ + returnArray.add(tile); } } } diff --git a/core/src/mindustry/ai/types/LogicAI.java b/core/src/mindustry/ai/types/LogicAI.java index a7b606b932..76b81794a2 100644 --- a/core/src/mindustry/ai/types/LogicAI.java +++ b/core/src/mindustry/ai/types/LogicAI.java @@ -14,7 +14,7 @@ import static mindustry.Vars.*; public class LogicAI extends AIController{ /** Minimum delay between item transfers. */ - public static final float transferDelay = 60f * 2f; + public static final float transferDelay = 60f * 3f; /** Time after which the unit resets its controlled and reverts to a normal unit. */ public static final float logicControlTimeout = 10f * 60f; diff --git a/core/src/mindustry/entities/Units.java b/core/src/mindustry/entities/Units.java index c6f592f30f..1babb75e33 100644 --- a/core/src/mindustry/entities/Units.java +++ b/core/src/mindustry/entities/Units.java @@ -3,9 +3,11 @@ package mindustry.entities; import arc.*; import arc.func.*; import arc.math.geom.*; +import arc.struct.*; import mindustry.annotations.Annotations.*; import mindustry.content.*; import mindustry.game.*; +import mindustry.game.Teams.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; @@ -308,20 +310,12 @@ public class Units{ /** Iterates over all units that are enemies of this team. */ public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons cons){ - if(team.active()){ - for(Team enemy : state.teams.enemiesOf(team)){ - nearby(enemy, x, y, width, height, cons); - } - }else{ - //inactive teams have no cache, check everything - //TODO cache all teams with units OR blocks - for(Team other : Team.all){ - if(other != team && other.data().unitCount > 0){ - nearby(other, x, y, width, height, cons); - } + Seq data = state.teams.present; + for(int i = 0; i < data.size; i++){ + if(data.items[i].team != team){ + nearby(data.items[i].team, x, y, width, height, cons); } } - } /** Iterates over all units that are enemies of this team. */ diff --git a/core/src/mindustry/entities/comp/BulletComp.java b/core/src/mindustry/entities/comp/BulletComp.java index 4deb7cc9dc..0eea7d84fe 100644 --- a/core/src/mindustry/entities/comp/BulletComp.java +++ b/core/src/mindustry/entities/comp/BulletComp.java @@ -9,6 +9,7 @@ import arc.util.*; import mindustry.annotations.Annotations.*; import mindustry.entities.bullet.*; import mindustry.game.*; +import mindustry.game.Teams.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -28,15 +29,10 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw @Override public void getCollisions(Cons consumer){ - if(team.active()){ - for(Team team : team.enemies()){ - consumer.get(team.data().tree()); - } - }else{ - for(Team other : Team.all){ - if(other != team && team.data().unitCount > 0){ - consumer.get(team.data().tree()); - } + Seq data = state.teams.present; + for(int i = 0; i < data.size; i++){ + if(data.items[i].team != team){ + consumer.get(data.items[i].tree); } } } diff --git a/core/src/mindustry/game/Team.java b/core/src/mindustry/game/Team.java index 1ab345dc10..83061d20e8 100644 --- a/core/src/mindustry/game/Team.java +++ b/core/src/mindustry/game/Team.java @@ -83,9 +83,9 @@ public class Team implements Comparable{ return state.rules.teams.get(this); } - public Team[] enemies(){ - return state.teams.enemiesOf(this); - } + //public Team[] enemies(){ + // return state.teams.enemiesOf(this); + //} public TeamData data(){ return state.teams.get(this); diff --git a/core/src/mindustry/game/Teams.java b/core/src/mindustry/game/Teams.java index 5e38b43eb2..f10194b80f 100644 --- a/core/src/mindustry/game/Teams.java +++ b/core/src/mindustry/game/Teams.java @@ -23,7 +23,9 @@ public class Teams{ /** Maps team IDs to team data. */ private TeamData[] map = new TeamData[256]; /** Active teams. */ - private Seq active = new Seq<>(); + public Seq active = new Seq<>(); + /** Teams with block or unit presence. */ + public Seq present = new Seq<>(TeamData.class); public Teams(){ active.add(get(Team.crux)); @@ -31,7 +33,7 @@ public class Teams{ @Nullable public CoreBuild closestEnemyCore(float x, float y, Team team){ - for(Team enemy : team.enemies()){ + for(Team enemy : team.data().coreEnemies){ CoreBuild tile = Geometry.findClosest(x, y, enemy.cores()); if(tile != null) return tile; } @@ -43,9 +45,9 @@ public class Teams{ return Geometry.findClosest(x, y, get(team).cores); } - public Team[] enemiesOf(Team team){ - return get(team).enemies; - } + //public Team[] enemiesOf(Team team){ + // return get(team).enemies; + //} public boolean eachEnemyCore(Team team, Boolf ret){ for(TeamData data : active){ @@ -145,9 +147,12 @@ public class Teams{ } public void updateTeamStats(){ + present.clear(); + for(Team team : Team.all){ TeamData data = team.data(); + data.presentFlag = false; data.unitCount = 0; data.units.clear(); if(data.tree != null){ @@ -168,10 +173,14 @@ public class Teams{ } } + //update presence flag. + Groups.build.each( b -> b.team.data().presentFlag = true); + for(Unit unit : Groups.unit){ TeamData data = unit.team.data(); data.tree().insert(unit); data.units.add(unit); + data.presentFlag = true; if(data.unitsByType == null || data.unitsByType.length <= unit.type().id){ data.unitsByType = new Seq[content.units().size]; @@ -185,6 +194,15 @@ public class Teams{ count(unit); } + + //update presence of each team. + for(Team team : Team.all){ + TeamData data = team.data(); + + if(data.presentFlag || data.active()){ + present.add(data); + } + } } private void updateEnemies(){ @@ -201,7 +219,7 @@ public class Teams{ } } - data.enemies = enemies.toArray(Team.class); + data.coreEnemies = enemies.toArray(Team.class); } } @@ -210,7 +228,10 @@ public class Teams{ public final Team team; public final BaseAI ai; - public Team[] enemies = {}; + private boolean presentFlag; + + /** Enemies with cores or spawn points. */ + public Team[] coreEnemies = {}; /** Planned blocks for drones. This is usually only blocks that have been broken. */ public Queue blocks = new Queue<>(); /** The current command for units to follow. */ diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 3bcfaf46ee..a8c5de8a9d 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -10,6 +10,7 @@ import mindustry.content.*; import mindustry.ctype.*; import mindustry.entities.*; import mindustry.game.*; +import mindustry.game.Teams.*; import mindustry.gen.*; import mindustry.type.*; import mindustry.world.*; @@ -674,8 +675,11 @@ public class LExecutor{ bestValue = 0; if(enemies){ - for(Team enemy : state.teams.enemiesOf(r.team())){ - find(r, range, sortDir, enemy); + Seq data = state.teams.present; + for(int i = 0; i < data.size; i++){ + if(data.items[i].team != r.team()){ + find(r, range, sortDir, data.items[i].team); + } } }else{ find(r, range, sortDir, r.team());