From 8ae00e69cb1720f239f69e300e618b79e79270c8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 30 Sep 2022 11:22:52 -0400 Subject: [PATCH] Fixed some commanded units not shooting --- core/src/mindustry/ai/types/CommandAI.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/ai/types/CommandAI.java b/core/src/mindustry/ai/types/CommandAI.java index db82fbf102..d5df3af7ae 100644 --- a/core/src/mindustry/ai/types/CommandAI.java +++ b/core/src/mindustry/ai/types/CommandAI.java @@ -78,7 +78,7 @@ public class CommandAI extends AIController{ updateVisuals(); //only autotarget if the unit supports it - if(targetPos == null || unit.type.autoFindTarget){ + if((targetPos == null || nearAttackTarget(unit.x, unit.y, unit.range())) || unit.type.autoFindTarget){ updateTargeting(); }else if(attackTarget == null){ //if the unit does not have an attack target, is currently moving, and does not have autotargeting, stop attacking stuff @@ -205,7 +205,11 @@ public class CommandAI extends AIController{ @Override public Teamc findTarget(float x, float y, float range, boolean air, boolean ground){ - return attackTarget == null || !attackTarget.within(x, y, range + 3f + (attackTarget instanceof Sized s ? s.hitSize()/2f : 0f)) ? super.findTarget(x, y, range, air, ground) : attackTarget; + return !nearAttackTarget(x, y, range) ? super.findTarget(x, y, range, air, ground) : attackTarget; + } + + public boolean nearAttackTarget(float x, float y, float range){ + return attackTarget != null && attackTarget.within(x, y, range + 3f + (attackTarget instanceof Sized s ? s.hitSize()/2f : 0f)); } @Override