From 2f991a85afd5244e30af2283ab69eeb39347afe9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 13 Aug 2023 11:05:43 -0400 Subject: [PATCH] Added logic autoPathfind command --- core/assets/bundles/bundle.properties | 1 + core/src/mindustry/ai/types/LogicAI.java | 28 +++++++++++++++++++ core/src/mindustry/logic/LExecutor.java | 2 +- core/src/mindustry/logic/LUnitControl.java | 1 + .../world/blocks/units/Reconstructor.java | 1 + .../world/blocks/units/UnitFactory.java | 1 + 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 5803c8de6e..7bfb819720 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -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. diff --git a/core/src/mindustry/ai/types/LogicAI.java b/core/src/mindustry/ai/types/LogicAI.java index 5987dc2bc7..a40955637a 100644 --- a/core/src/mindustry/ai/types/LogicAI.java +++ b/core/src/mindustry/ai/types/LogicAI.java @@ -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(); } diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index bd4f5cb0f4..a779f99086 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -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 -> { diff --git a/core/src/mindustry/logic/LUnitControl.java b/core/src/mindustry/logic/LUnitControl.java index edcedf4a6f..ccfe9b5d3f 100644 --- a/core/src/mindustry/logic/LUnitControl.java +++ b/core/src/mindustry/logic/LUnitControl.java @@ -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"), diff --git a/core/src/mindustry/world/blocks/units/Reconstructor.java b/core/src/mindustry/world/blocks/units/Reconstructor.java index 68a3f28932..c4da0d2e18 100644 --- a/core/src/mindustry/world/blocks/units/Reconstructor.java +++ b/core/src/mindustry/world/blocks/units/Reconstructor.java @@ -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); } diff --git a/core/src/mindustry/world/blocks/units/UnitFactory.java b/core/src/mindustry/world/blocks/units/UnitFactory.java index 9b28c8a61d..467b725967 100644 --- a/core/src/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/mindustry/world/blocks/units/UnitFactory.java @@ -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); }