More intelligent suicide units / Bugfixes
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
70
core/src/mindustry/ai/types/SuicideAI.java
Normal file
70
core/src/mindustry/ai/types/SuicideAI.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user