Logic pathfind instruction

This commit is contained in:
Anuken
2023-04-24 23:59:46 -04:00
parent 05f158fd51
commit 583a1c69b6
5 changed files with 23 additions and 3 deletions

View File

@@ -2371,7 +2371,7 @@ lenum.stop = Stop moving/mining/building.
lenum.unbind = Completely disable logic control.\nResume standard AI. 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 enemy spawn. lenum.pathfind = Pathfind to the specified position.
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.

View File

@@ -3,6 +3,7 @@ package mindustry.ai.types;
import arc.math.*; import arc.math.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.logic.*; import mindustry.logic.*;
@@ -36,9 +37,18 @@ public class LogicAI extends AIController{
public PosTeam posTarget = PosTeam.create(); public PosTeam posTarget = PosTeam.create();
private ObjectSet<Object> radars = new ObjectSet<>(); private ObjectSet<Object> radars = new ObjectSet<>();
private float lastMoveX, lastMoveY;
private int lastPathId = 0;
@Override @Override
public void updateMovement(){ public void updateMovement(){
if(control == LUnitControl.pathfind){
if(!Mathf.equal(moveX, lastMoveX, 0.1f) || !Mathf.equal(moveY, lastMoveY, 0.1f)){
lastPathId ++;
lastMoveX = moveX;
lastMoveY = moveY;
}
}
if(targetTimer > 0f){ if(targetTimer > 0f){
targetTimer -= Time.delta; targetTimer -= Time.delta;
@@ -62,6 +72,15 @@ public class LogicAI extends AIController{
case approach -> { case approach -> {
moveTo(Tmp.v1.set(moveX, moveY), moveRad - 7f, 7, true, null); moveTo(Tmp.v1.set(moveX, moveY), moveRad - 7f, 7, true, null);
} }
case pathfind -> {
if(unit.isFlying()){
moveTo(Tmp.v1.set(moveX, moveY), 1f, 30f);
}else{
if(Vars.controlPath.getPathPosition(unit, lastPathId, Tmp.v2.set(moveX, moveY), Tmp.v1, null)){
moveTo(Tmp.v1, 1f, Tmp.v2.epsilonEquals(Tmp.v1, 4.1f) ? 30f : 0f);
}
}
}
case stop -> { case stop -> {
unit.clearBuilding(); unit.clearBuilding();
} }

View File

@@ -394,7 +394,7 @@ public class LExecutor{
case idle -> { case idle -> {
ai.control = type; ai.control = type;
} }
case move, stop, approach -> { case move, stop, approach, pathfind -> {
ai.control = type; ai.control = type;
ai.moveX = x1; ai.moveX = x1;
ai.moveY = y1; ai.moveY = y1;

View File

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

View File

@@ -25,4 +25,4 @@ org.gradle.caching=true
#used for slow jitpack builds; TODO see if this actually works #used for slow jitpack builds; TODO see if this actually works
org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.socketTimeout=100000
org.gradle.internal.http.connectionTimeout=100000 org.gradle.internal.http.connectionTimeout=100000
archash=56c0bbf95f archash=513474758f