DefenderAI that makes octs follow units (#4757)

This commit is contained in:
MEEP of Faith
2021-03-05 07:21:26 -08:00
committed by GitHub
parent 2bb303e709
commit 0c28bb7dcf
3 changed files with 55 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
package mindustry.ai.types;
import arc.math.*;
import mindustry.entities.*;
import mindustry.entities.Units.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.world.meta.*;
public class DefenderAI extends AIController{
@Override
public void updateMovement(){
if(target != null){
moveTo(target, unit.range(), 5f);
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);
}
@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);
}
}