mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-19 20:27:44 +07:00
Per-unit cap (still broken)
This commit is contained in:
@ -4,6 +4,7 @@ import arc.math.geom.*;
|
||||
import mindustry.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -11,6 +12,7 @@ import java.util.*;
|
||||
public class TeamIndexProcess implements AsyncProcess{
|
||||
private QuadTree<Unit>[] trees = new QuadTree[Team.all.length];
|
||||
private int[] counts = new int[Team.all.length];
|
||||
private int[][] typeCounts = new int[Team.all.length][0];
|
||||
|
||||
public QuadTree<Unit> tree(Team team){
|
||||
if(trees[team.id] == null) trees[team.id] = new QuadTree<>(Vars.world.getQuadBounds(new Rect()));
|
||||
@ -22,8 +24,18 @@ public class TeamIndexProcess implements AsyncProcess{
|
||||
return counts[team.id];
|
||||
}
|
||||
|
||||
public void updateCount(Team team, int amount){
|
||||
public int countType(Team team, UnitType type){
|
||||
return typeCounts[team.id].length < type.id ? 0 : typeCounts[team.id][type.id];
|
||||
}
|
||||
|
||||
public void updateCount(Team team, UnitType type, int amount){
|
||||
int tid = type.id;
|
||||
|
||||
counts[team.id] += amount;
|
||||
if(typeCounts[team.id].length < tid){
|
||||
typeCounts[team.id] = new int[Vars.content.units().size];
|
||||
}
|
||||
typeCounts[team.id][tid] += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,13 +51,16 @@ public class TeamIndexProcess implements AsyncProcess{
|
||||
if(trees[team.id] != null){
|
||||
trees[team.id].clear();
|
||||
}
|
||||
|
||||
Arrays.fill(typeCounts[team.id], 0);
|
||||
}
|
||||
|
||||
Arrays.fill(counts, 0);
|
||||
|
||||
for(Unit unit : Groups.unit){
|
||||
tree(unit.team).insert(unit);
|
||||
counts[unit.team.id] ++;
|
||||
|
||||
updateCount(unit.team, unit.type(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user