From 9c7eb36431ff23adf82f0e4184691992a91d1daa Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 6 Jul 2022 07:37:17 -0400 Subject: [PATCH] Fixed #7133 --- core/src/mindustry/ai/RtsAI.java | 8 +++++++- core/src/mindustry/ai/types/CommandAI.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/ai/RtsAI.java b/core/src/mindustry/ai/RtsAI.java index 94b138a6f6..752828272a 100644 --- a/core/src/mindustry/ai/RtsAI.java +++ b/core/src/mindustry/ai/RtsAI.java @@ -129,8 +129,12 @@ public class RtsAI{ boolean handleSquad(Seq units, boolean noDefenders){ float health = 0f, dps = 0f; float ax = 0f, ay = 0f; + boolean targetAir = true, targetGround = true; for(var unit : units){ + if(!unit.type.targetAir) targetAir = false; + if(!unit.type.targetGround) targetGround = false; + ax += unit.x; ay += unit.y; health += unit.health; @@ -176,6 +180,8 @@ public class RtsAI{ } } + boolean tair = targetAir, tground = targetGround; + //find aggressor, or else, the thing being attacked Vec2 defendPos = null; Teamc defendTarget = null; @@ -183,7 +189,7 @@ public class RtsAI{ float checkRange = 260f; //TODO could be made faster by storing bullet shooter - Unit aggressor = Units.closestEnemy(data.team, defend.x, defend.y, checkRange, u -> true); + Unit aggressor = Units.closestEnemy(data.team, defend.x, defend.y, checkRange, u -> u.checkTarget(tair, tground)); if(aggressor != null){ defendTarget = aggressor; }else if(false){ //TODO currently ignored, no use defending against nothing diff --git a/core/src/mindustry/ai/types/CommandAI.java b/core/src/mindustry/ai/types/CommandAI.java index 1d5e98211c..8d50b296a5 100644 --- a/core/src/mindustry/ai/types/CommandAI.java +++ b/core/src/mindustry/ai/types/CommandAI.java @@ -129,7 +129,7 @@ public class CommandAI extends AIController{ @Override public void hit(Bullet bullet){ - if(unit.team.isAI() && bullet.owner instanceof Teamc teamc && teamc.team() != unit.team && attackTarget == null){ + if(unit.team.isAI() && bullet.owner instanceof Teamc teamc && teamc.team() != unit.team && attackTarget == null && !(teamc instanceof Unit u && !u.checkTarget(unit.type.targetAir, unit.type.targetGround))){ commandTarget(teamc, true); } }