mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-09 20:29:06 +07:00
Added logic autoPathfind command
This commit is contained in:
parent
2b05264093
commit
2f991a85af
@ -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.
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 -> {
|
||||
|
@ -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"),
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user