This commit is contained in:
Anuken
2020-10-13 15:56:00 -04:00
parent ca875876cd
commit 5d76dd0e2f
7 changed files with 58 additions and 41 deletions

View File

@@ -10,6 +10,7 @@ import arc.util.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.game.Teams.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
@@ -205,13 +206,14 @@ public class BlockIndexer{
/** Get all enemy blocks with a flag. */ /** Get all enemy blocks with a flag. */
public Seq<Tile> getEnemy(Team team, BlockFlag type){ public Seq<Tile> getEnemy(Team team, BlockFlag type){
returnArray.clear(); returnArray.clear();
for(Team enemy : team.enemies()){ Seq<TeamData> data = state.teams.present;
if(state.teams.isActive(enemy)){ for(int i = 0; i < data.size; i++){
TileArray set = getFlagged(enemy)[type.ordinal()]; Team enemy = data.items[i].team;
if(set != null){ if(enemy == team) continue;
for(Tile tile : set){ TileArray set = getFlagged(enemy)[type.ordinal()];
returnArray.add(tile); if(set != null){
} for(Tile tile : set){
returnArray.add(tile);
} }
} }
} }

View File

@@ -14,7 +14,7 @@ import static mindustry.Vars.*;
public class LogicAI extends AIController{ public class LogicAI extends AIController{
/** Minimum delay between item transfers. */ /** 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. */ /** Time after which the unit resets its controlled and reverts to a normal unit. */
public static final float logicControlTimeout = 10f * 60f; public static final float logicControlTimeout = 10f * 60f;

View File

@@ -3,9 +3,11 @@ package mindustry.entities;
import arc.*; import arc.*;
import arc.func.*; import arc.func.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.game.Teams.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
@@ -308,20 +310,12 @@ public class Units{
/** Iterates over all units that are enemies of this team. */ /** 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<Unit> cons){ public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons<Unit> cons){
if(team.active()){ Seq<TeamData> data = state.teams.present;
for(Team enemy : state.teams.enemiesOf(team)){ for(int i = 0; i < data.size; i++){
nearby(enemy, x, y, width, height, cons); if(data.items[i].team != team){
} nearby(data.items[i].team, 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);
}
} }
} }
} }
/** Iterates over all units that are enemies of this team. */ /** Iterates over all units that are enemies of this team. */

View File

@@ -9,6 +9,7 @@ import arc.util.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.entities.bullet.*; import mindustry.entities.bullet.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.game.Teams.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
@@ -28,15 +29,10 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
@Override @Override
public void getCollisions(Cons<QuadTree> consumer){ public void getCollisions(Cons<QuadTree> consumer){
if(team.active()){ Seq<TeamData> data = state.teams.present;
for(Team team : team.enemies()){ for(int i = 0; i < data.size; i++){
consumer.get(team.data().tree()); if(data.items[i].team != team){
} consumer.get(data.items[i].tree);
}else{
for(Team other : Team.all){
if(other != team && team.data().unitCount > 0){
consumer.get(team.data().tree());
}
} }
} }
} }

View File

@@ -83,9 +83,9 @@ public class Team implements Comparable<Team>{
return state.rules.teams.get(this); return state.rules.teams.get(this);
} }
public Team[] enemies(){ //public Team[] enemies(){
return state.teams.enemiesOf(this); // return state.teams.enemiesOf(this);
} //}
public TeamData data(){ public TeamData data(){
return state.teams.get(this); return state.teams.get(this);

View File

@@ -23,7 +23,9 @@ public class Teams{
/** Maps team IDs to team data. */ /** Maps team IDs to team data. */
private TeamData[] map = new TeamData[256]; private TeamData[] map = new TeamData[256];
/** Active teams. */ /** Active teams. */
private Seq<TeamData> active = new Seq<>(); public Seq<TeamData> active = new Seq<>();
/** Teams with block or unit presence. */
public Seq<TeamData> present = new Seq<>(TeamData.class);
public Teams(){ public Teams(){
active.add(get(Team.crux)); active.add(get(Team.crux));
@@ -31,7 +33,7 @@ public class Teams{
@Nullable @Nullable
public CoreBuild closestEnemyCore(float x, float y, Team team){ 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()); CoreBuild tile = Geometry.findClosest(x, y, enemy.cores());
if(tile != null) return tile; if(tile != null) return tile;
} }
@@ -43,9 +45,9 @@ public class Teams{
return Geometry.findClosest(x, y, get(team).cores); return Geometry.findClosest(x, y, get(team).cores);
} }
public Team[] enemiesOf(Team team){ //public Team[] enemiesOf(Team team){
return get(team).enemies; // return get(team).enemies;
} //}
public boolean eachEnemyCore(Team team, Boolf<CoreBuild> ret){ public boolean eachEnemyCore(Team team, Boolf<CoreBuild> ret){
for(TeamData data : active){ for(TeamData data : active){
@@ -145,9 +147,12 @@ public class Teams{
} }
public void updateTeamStats(){ public void updateTeamStats(){
present.clear();
for(Team team : Team.all){ for(Team team : Team.all){
TeamData data = team.data(); TeamData data = team.data();
data.presentFlag = false;
data.unitCount = 0; data.unitCount = 0;
data.units.clear(); data.units.clear();
if(data.tree != null){ 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){ for(Unit unit : Groups.unit){
TeamData data = unit.team.data(); TeamData data = unit.team.data();
data.tree().insert(unit); data.tree().insert(unit);
data.units.add(unit); data.units.add(unit);
data.presentFlag = true;
if(data.unitsByType == null || data.unitsByType.length <= unit.type().id){ if(data.unitsByType == null || data.unitsByType.length <= unit.type().id){
data.unitsByType = new Seq[content.units().size]; data.unitsByType = new Seq[content.units().size];
@@ -185,6 +194,15 @@ public class Teams{
count(unit); 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(){ 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 Team team;
public final BaseAI ai; 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. */ /** Planned blocks for drones. This is usually only blocks that have been broken. */
public Queue<BlockPlan> blocks = new Queue<>(); public Queue<BlockPlan> blocks = new Queue<>();
/** The current command for units to follow. */ /** The current command for units to follow. */

View File

@@ -10,6 +10,7 @@ import mindustry.content.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.game.Teams.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
@@ -674,8 +675,11 @@ public class LExecutor{
bestValue = 0; bestValue = 0;
if(enemies){ if(enemies){
for(Team enemy : state.teams.enemiesOf(r.team())){ Seq<TeamData> data = state.teams.present;
find(r, range, sortDir, enemy); for(int i = 0; i < data.size; i++){
if(data.items[i].team != r.team()){
find(r, range, sortDir, data.items[i].team);
}
} }
}else{ }else{
find(r, range, sortDir, r.team()); find(r, range, sortDir, r.team());