This commit is contained in:
Anuken
2024-07-26 23:29:28 -04:00
parent 3a1a06e57f
commit 0de1bec554
7 changed files with 32 additions and 10 deletions

View File

@@ -19,6 +19,7 @@ import mindustry.logic.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.defense.turrets.BaseTurret.*;
import mindustry.world.blocks.defense.turrets.*;
import mindustry.world.blocks.storage.*;
import mindustry.world.blocks.storage.CoreBlock.*;
import mindustry.world.meta.*;
@@ -111,7 +112,8 @@ public class RtsAI{
for(var unit : data.units){
if(used.add(unit.id) && unit.isCommandable() && !unit.command().hasCommand() && !unit.command().isAttacking()){
squad.clear();
data.tree().intersect(unit.x - squadRadius/2f, unit.y - squadRadius/2f, squadRadius, squadRadius, squad);
float rad = squadRadius + unit.hitSize*1.5f;
data.tree().intersect(unit.x - rad/2f, unit.y - rad/2f, rad, rad, squad);
squad.truncate(data.team.rules().rtsMaxSquad);
@@ -245,7 +247,7 @@ public class RtsAI{
}
}
var build = anyDefend ? null : findTarget(ax, ay, units.size, dps, health, units.first().flag == 0);
var build = anyDefend ? null : findTarget(ax, ay, units.size, dps, health, units.first().flag == 0, units.first().isFlying());
if(build != null || anyDefend){
for(var unit : units){
@@ -268,7 +270,7 @@ public class RtsAI{
return anyDefend;
}
@Nullable Building findTarget(float x, float y, int total, float dps, float health, boolean checkWeight){
@Nullable Building findTarget(float x, float y, int total, float dps, float health, boolean checkWeight, boolean air){
if(total < data.team.rules().rtsMinSquad) return null;
//flag priority?
@@ -290,7 +292,7 @@ public class RtsAI{
targets.truncate(maxTargetsChecked);
for(var target : targets){
weights.put(target, estimateStats(x, y, target.x, target.y, dps, health));
weights.put(target, estimateStats(x, y, target.x, target.y, dps, health, air));
}
var result = targets.min(
@@ -312,12 +314,12 @@ public class RtsAI{
}
//TODO extremely slow especially with many squads.
float estimateStats(float fromX, float fromY, float x, float y, float selfDps, float selfHealth){
float estimateStats(float fromX, float fromY, float x, float y, float selfDps, float selfHealth, boolean air){
float[] health = {0f}, dps = {0f};
float extraRadius = 50f;
for(var turret : Vars.indexer.getEnemy(data.team, BlockFlag.turret)){
if(turret instanceof BaseTurretBuild t && Intersector.distanceSegmentPoint(fromX, fromY, x, y, t.x, t.y) <= t.range() + extraRadius){
if(turret instanceof BaseTurretBuild t && turret.block instanceof Turret tb && ((tb.targetAir && air) || (tb.targetGround && !air)) && Intersector.distanceSegmentPoint(fromX, fromY, x, y, t.x, t.y) <= t.range() + extraRadius){
health[0] += t.health;
dps[0] += t.estimateDps();
}