Various unit logic additions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package mindustry.logic;
|
||||
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.noise.*;
|
||||
@@ -14,6 +15,7 @@ import mindustry.world.*;
|
||||
import mindustry.world.blocks.logic.LogicDisplay.*;
|
||||
import mindustry.world.blocks.logic.MemoryBlock.*;
|
||||
import mindustry.world.blocks.logic.MessageBlock.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -117,6 +119,10 @@ public class LExecutor{
|
||||
return (int)num(index);
|
||||
}
|
||||
|
||||
public void setbool(int index, boolean value){
|
||||
setnum(index, value ? 1 : 0);
|
||||
}
|
||||
|
||||
public void setnum(int index, double value){
|
||||
Var v = vars[index];
|
||||
if(v.constant) return;
|
||||
@@ -194,8 +200,25 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
/** Binds the processor to a unit based on some filters. */
|
||||
/** Uses a unit to find something that may not be in its range. */
|
||||
public static class UnitLocateI implements LInstruction{
|
||||
public LLocate locate = LLocate.building;
|
||||
public BlockFlag flag = BlockFlag.core;
|
||||
public int enemy, ore;
|
||||
public int outX, outY, outFound;
|
||||
|
||||
public UnitLocateI(LLocate locate, BlockFlag flag, int enemy, int ore, int outX, int outY, int outFound){
|
||||
this.locate = locate;
|
||||
this.flag = flag;
|
||||
this.enemy = enemy;
|
||||
this.ore = ore;
|
||||
this.outX = outX;
|
||||
this.outY = outY;
|
||||
this.outFound = outFound;
|
||||
}
|
||||
|
||||
public UnitLocateI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
@@ -205,8 +228,49 @@ public class LExecutor{
|
||||
if(unitObj instanceof Unit unit && ai != null){
|
||||
ai.controlTimer = LogicAI.logicControlTimeout;
|
||||
|
||||
Cache cache = (Cache)ai.execCache.get(this, Cache::new);
|
||||
|
||||
if(ai.checkTargetTimer(this)){
|
||||
Tile res = null;
|
||||
boolean build = false;
|
||||
|
||||
switch(locate){
|
||||
case ore -> {
|
||||
if(exec.obj(ore) instanceof Item item){
|
||||
res = indexer.findClosestOre(unit.x, unit.y, item);
|
||||
}
|
||||
}
|
||||
case building -> {
|
||||
res = Geometry.findClosest(unit.x, unit.y, exec.bool(enemy) ? indexer.getEnemy(unit.team, flag) : indexer.getAllied(unit.team, flag));
|
||||
build = true;
|
||||
}
|
||||
case spawn -> {
|
||||
res = Geometry.findClosest(unit.x, unit.y, Vars.spawner.getSpawns());
|
||||
}
|
||||
}
|
||||
|
||||
if(res != null && (!build || res.build != null)){
|
||||
cache.found = true;
|
||||
//set result if found
|
||||
exec.setnum(outX, cache.x = build ? res.build.x : res.worldx());
|
||||
exec.setnum(outY, cache.y = build ? res.build.y : res.worldy());
|
||||
exec.setnum(outFound, 1);
|
||||
}else{
|
||||
cache.found = false;
|
||||
exec.setnum(outFound, 0);
|
||||
}
|
||||
}else{
|
||||
exec.setbool(outFound, cache.found);
|
||||
exec.setnum(outX, cache.x);
|
||||
exec.setnum(outY, cache.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class Cache{
|
||||
float x, y;
|
||||
boolean found;
|
||||
}
|
||||
}
|
||||
|
||||
/** Controls the unit based on some parameters. */
|
||||
@@ -267,6 +331,9 @@ public class LExecutor{
|
||||
ai.moveRad = exec.numf(p3);
|
||||
}
|
||||
}
|
||||
case within -> {
|
||||
exec.setnum(p4, unit.within(exec.numf(p1), exec.numf(p2), exec.numf(p3)) ? 1 : 0);
|
||||
}
|
||||
case pathfind -> {
|
||||
ai.control = type;
|
||||
}
|
||||
@@ -281,6 +348,9 @@ public class LExecutor{
|
||||
ai.mainTarget = exec.obj(p1) instanceof Teamc t ? t : null;
|
||||
ai.shoot = exec.bool(p2);
|
||||
}
|
||||
case boost -> {
|
||||
ai.boost = exec.bool(p1);
|
||||
}
|
||||
case flag -> {
|
||||
unit.flag = exec.num(p1);
|
||||
}
|
||||
@@ -288,6 +358,9 @@ public class LExecutor{
|
||||
Tile tile = world.tileWorld(exec.numf(p1), exec.numf(p2));
|
||||
if(unit instanceof Minerc miner){
|
||||
miner.mineTile(tile);
|
||||
if(tile != null && (!unit.acceptsItem(tile.drop()) || !miner.canMine(tile.drop()))){
|
||||
miner.mineTile(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
case itemDrop -> {
|
||||
|
||||
Reference in New Issue
Block a user