More intelligent suicide units / Bugfixes

This commit is contained in:
Anuken
2020-06-06 11:36:14 -04:00
parent 1e3a190d5a
commit 0f76aeba05
9 changed files with 144 additions and 54 deletions

View File

@@ -25,13 +25,11 @@ public class GroundAI extends AIController{
Tilec core = unit.closestEnemyCore();
if(core != null){
float dst = unit.dst(core);
if(dst < unit.range() / 1.1f){
if(unit.within(core,unit.range() / 1.1f)){
target = core;
}
if(dst > unit.range() * 0.5f){
if(!unit.within(core, unit.range() * 0.5f)){
moveToCore(FlagTarget.enemyCores);
}
}

View File

@@ -0,0 +1,70 @@
package mindustry.ai.types;
import mindustry.*;
import mindustry.ai.Pathfinder.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.world.*;
public class SuicideAI extends GroundAI{
static boolean blockedByBlock;
@Override
public void update(){
if(Units.invalidateTarget(target, unit.team(), unit.x(), unit.y(), Float.MAX_VALUE)){
target = null;
}
if(retarget()){
targetClosest();
}
Tilec core = unit.closestEnemyCore();
boolean rotate = false, shoot = false;
if(!Units.invalidateTarget(target, unit, unit.range())){
rotate = true;
shoot = unit.within(target, unit.type().weapons.first().bullet.range() +
(target instanceof Tilec ? ((Tilec)target).block().size * Vars.tilesize / 2f : ((Hitboxc)target).hitSize() / 2f));
if(unit.type().hasWeapons()){
unit.aimLook(Predict.intercept(unit, target, unit.type().weapons.first().bullet.speed));
}
blockedByBlock = false;
//raycast for target
boolean blocked = Vars.world.raycast(unit.tileX(), unit.tileY(), target.tileX(), target.tileY(), (x, y) -> {
Tile tile = Vars.world.tile(x, y);
if(tile != null && tile.entity == target) return false;
if(tile != null && tile.entity != null && tile.entity.team() != unit.team()){
blockedByBlock = true;
return true;
}else{
return tile == null || tile.solid();
}
});
//shoot when there's an enemy block in the way
if(blockedByBlock){
shoot = true;
}
if(!blocked){
//move towards target directly
unit.moveAt(vec.set(target).sub(unit).limit(unit.type().speed));
}
}else{
if(core != null){
moveToCore(FlagTarget.enemyCores);
}
if(unit.moving()) unit.lookAt(unit.vel().angle());
}
unit.controlWeapons(rotate, shoot);
}
}