mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-08 23:07:33 +07:00
Added logic autoPathfind command
This commit is contained in:
@ -2397,6 +2397,7 @@ lenum.unbind = Completely disable logic control.\nResume standard AI.
|
|||||||
lenum.move = Move to exact position.
|
lenum.move = Move to exact position.
|
||||||
lenum.approach = Approach a position with a radius.
|
lenum.approach = Approach a position with a radius.
|
||||||
lenum.pathfind = Pathfind to the specified position.
|
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.target = Shoot a position.
|
||||||
lenum.targetp = Shoot a target with velocity prediction.
|
lenum.targetp = Shoot a target with velocity prediction.
|
||||||
lenum.itemdrop = Drop an item.
|
lenum.itemdrop = Drop an item.
|
||||||
|
@ -4,9 +4,13 @@ import arc.math.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
|
import mindustry.ai.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.logic.*;
|
import mindustry.logic.*;
|
||||||
|
import mindustry.world.*;
|
||||||
|
|
||||||
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class LogicAI extends AIController{
|
public class LogicAI extends AIController{
|
||||||
/** Minimum delay between item transfers. */
|
/** 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 -> {
|
case stop -> {
|
||||||
unit.clearBuilding();
|
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));
|
float x1 = World.unconv(exec.numf(p1)), y1 = World.unconv(exec.numf(p2)), d1 = World.unconv(exec.numf(p3));
|
||||||
|
|
||||||
switch(type){
|
switch(type){
|
||||||
case idle -> {
|
case idle, autoPathfind -> {
|
||||||
ai.control = type;
|
ai.control = type;
|
||||||
}
|
}
|
||||||
case move, stop, approach, pathfind -> {
|
case move, stop, approach, pathfind -> {
|
||||||
|
@ -6,6 +6,7 @@ public enum LUnitControl{
|
|||||||
move("x", "y"),
|
move("x", "y"),
|
||||||
approach("x", "y", "radius"),
|
approach("x", "y", "radius"),
|
||||||
pathfind("x", "y"),
|
pathfind("x", "y"),
|
||||||
|
autoPathfind,
|
||||||
boost("enable"),
|
boost("enable"),
|
||||||
target("x", "y", "shoot"),
|
target("x", "y", "shoot"),
|
||||||
targetp("unit", "shoot"),
|
targetp("unit", "shoot"),
|
||||||
|
@ -334,6 +334,7 @@ public class Reconstructor extends UnitBlock{
|
|||||||
@Override
|
@Override
|
||||||
public double sense(LAccess sensor){
|
public double sense(LAccess sensor){
|
||||||
if(sensor == LAccess.progress) return Mathf.clamp(fraction());
|
if(sensor == LAccess.progress) return Mathf.clamp(fraction());
|
||||||
|
if(sensor == LAccess.itemCapacity) return Mathf.round(itemCapacity * state.rules.unitCost(team));
|
||||||
return super.sense(sensor);
|
return super.sense(sensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ public class UnitFactory extends UnitBlock{
|
|||||||
@Override
|
@Override
|
||||||
public double sense(LAccess sensor){
|
public double sense(LAccess sensor){
|
||||||
if(sensor == LAccess.progress) return Mathf.clamp(fraction());
|
if(sensor == LAccess.progress) return Mathf.clamp(fraction());
|
||||||
|
if(sensor == LAccess.itemCapacity) return Mathf.round(itemCapacity * state.rules.unitCost(team));
|
||||||
return super.sense(sensor);
|
return super.sense(sensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user