Many bugfixes / Support for repairing derelict in selection

This commit is contained in:
Anuken
2024-09-18 16:27:54 -04:00
parent 63e246cc9d
commit e521a56712
8 changed files with 66 additions and 11 deletions
+13 -1
View File
@@ -272,6 +272,13 @@ public class CommandAI extends AIController{
vecOut.set(vecMovePos);
}else{
move = controlPath.getPathPosition(unit, vecMovePos, targetPos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
//TODO: what to do when there's a target and it can't be reached?
/*
if(noFound[0] && attackTarget != null && attackTarget.within(unit, unit.type.range * 2f)){
move = true;
vecOut.set(targetPos);
}*/
}
//rare case where unit must be perfectly aligned (happens with 1-tile gaps)
@@ -403,6 +410,11 @@ public class CommandAI extends AIController{
}
}
@Override
public void removed(Unit unit){
clearCommands();
}
public void commandQueue(Position location){
if(targetPos == null && attackTarget == null){
if(location instanceof Teamc t){
@@ -444,7 +456,7 @@ public class CommandAI extends AIController{
@Override
public Teamc findTarget(float x, float y, float range, boolean air, boolean ground){
return !nearAttackTarget(x, y, range) ? super.findTarget(x, y, range, air, ground) : attackTarget;
return !nearAttackTarget(x, y, range) ? super.findTarget(x, y, range, air, ground) : Units.isHittable(attackTarget, air, ground) ? attackTarget : null;
}
public boolean nearAttackTarget(float x, float y, float range){
+3 -2
View File
@@ -10,6 +10,7 @@ import static mindustry.Vars.*;
import static mindustry.world.meta.BlockFlag.*;
public class FlyingAI extends AIController{
final static Rand rand = new Rand();
final static BlockFlag[] randomTargets = {core, storage, generator, launchPad, factory, repair, battery, reactor, drill};
@Override
@@ -72,10 +73,10 @@ public class FlyingAI extends AIController{
if(state.rules.randomWaveAI){
//when there are no waves, it's just random based on the unit
Mathf.rand.setSeed(unit.type.id + (state.rules.waves ? state.wave : unit.id));
rand.setSeed(unit.type.id + (state.rules.waves ? state.wave : unit.id));
//try a few random flags first
for(int attempt = 0; attempt < 5; attempt++){
Teamc result = targetFlag(x, y, randomTargets[Mathf.rand.random(randomTargets.length - 1)], true);
Teamc result = targetFlag(x, y, randomTargets[rand.random(randomTargets.length - 1)], true);
if(result != null) return result;
}
//try the closest target