Added logic autoPathfind command

This commit is contained in:
Anuken 2023-08-13 11:05:43 -04:00
parent 2b05264093
commit 2f991a85af
6 changed files with 33 additions and 1 deletions

View File

@ -2397,6 +2397,7 @@ lenum.unbind = Completely disable logic control.\nResume standard AI.
lenum.move = Move to exact position.
lenum.approach = Approach a position with a radius.
lenum.pathfind = Pathfind to the specified position.
lenum.autopathfind = Automatically pathfinds to the nearest enemy core or drop point.\nThis is the same as standard wave enemy pathfinding.
lenum.target = Shoot a position.
lenum.targetp = Shoot a target with velocity prediction.
lenum.itemdrop = Drop an item.

View File

@ -4,9 +4,13 @@ import arc.math.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.ai.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.logic.*;
import mindustry.world.*;
import static mindustry.Vars.*;
public class LogicAI extends AIController{
/** Minimum delay between item transfers. */
@ -81,6 +85,30 @@ public class LogicAI extends AIController{
}
}
}
case autoPathfind -> {
Building core = unit.closestEnemyCore();
if((core == null || !unit.within(core, unit.range() * 0.5f))){
boolean move = true;
Tile spawner = null;
if(state.rules.waves && unit.team == state.rules.defaultTeam){
spawner = getClosestSpawner();
if(spawner != null && unit.within(spawner, state.rules.dropZoneRadius + 120f)) move = false;
}
if(move){
if(unit.isFlying()){
var target = core == null ? spawner : core;
if(target != null){
moveTo(target, unit.range() * 0.5f);
}
}else{
pathfind(Pathfinder.fieldCore);
}
}
}
}
case stop -> {
unit.clearBuilding();
}

View File

@ -407,7 +407,7 @@ public class LExecutor{
float x1 = World.unconv(exec.numf(p1)), y1 = World.unconv(exec.numf(p2)), d1 = World.unconv(exec.numf(p3));
switch(type){
case idle -> {
case idle, autoPathfind -> {
ai.control = type;
}
case move, stop, approach, pathfind -> {

View File

@ -6,6 +6,7 @@ public enum LUnitControl{
move("x", "y"),
approach("x", "y", "radius"),
pathfind("x", "y"),
autoPathfind,
boost("enable"),
target("x", "y", "shoot"),
targetp("unit", "shoot"),

View File

@ -334,6 +334,7 @@ public class Reconstructor extends UnitBlock{
@Override
public double sense(LAccess sensor){
if(sensor == LAccess.progress) return Mathf.clamp(fraction());
if(sensor == LAccess.itemCapacity) return Mathf.round(itemCapacity * state.rules.unitCost(team));
return super.sense(sensor);
}

View File

@ -207,6 +207,7 @@ public class UnitFactory extends UnitBlock{
@Override
public double sense(LAccess sensor){
if(sensor == LAccess.progress) return Mathf.clamp(fraction());
if(sensor == LAccess.itemCapacity) return Mathf.round(itemCapacity * state.rules.unitCost(team));
return super.sense(sensor);
}