Better DefenderAI / Vela building / Anuken/Mindustry-Suggestions/issues/2074

This commit is contained in:
Anuken
2021-03-05 11:10:12 -05:00
parent 0c28bb7dcf
commit b6c645b701
6 changed files with 26 additions and 19 deletions

View File

@@ -2,7 +2,7 @@ package mindustry.ai.types;
import arc.math.*;
import mindustry.entities.*;
import mindustry.entities.Units.*;
import mindustry.entities.comp.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.world.meta.*;
@@ -12,23 +12,29 @@ public class DefenderAI extends AIController{
@Override
public void updateMovement(){
if(target != null){
moveTo(target, unit.range(), 5f);
moveTo(target, (target instanceof Sized s ? s.hitSize()/2f * 1.1f : 0f) + unit.hitSize/2f + 15f, 50f);
unit.lookAt(target);
}else{
Teamc block = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
if(block == null) block = unit.closestCore();
moveTo(block, 60f);
}
}
@Override
protected void updateTargeting(){
if(retarget()) target = findTarget(unit.x, unit.y, 0f, true, true);
if(retarget()) target = findTarget(unit.x, unit.y, unit.range(), true, true);
}
@Override
protected Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
//Sort by max health and closer target.
return Units.closest(unit.team, x, y, u -> !u.dead() && u.type != unit.type, (u, tx, ty) -> -u.maxHealth + Mathf.dst2(u.x, u.y, tx, ty) / 800f);
//find unit to follow if not in rally mode
if(command() != UnitCommand.rally){
//Sort by max health and closer target.
var result = Units.closest(unit.team, x, y, Math.max(range, 400f), u -> !u.dead() && u.type != unit.type, (u, tx, ty) -> -u.maxHealth + Mathf.dst2(u.x, u.y, tx, ty) / 800f);
if(result != null) return result;
}
//find rally point
var block = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
if(block != null) return block;
//return core if found
return unit.closestCore();
}
}