More logic commands
This commit is contained in:
@@ -22,6 +22,7 @@ public class LogicAI extends AIController{
|
||||
public float moveX, moveY, moveRad;
|
||||
public float itemTimer, controlTimer = logicControlTimeout, targetTimer;
|
||||
public Building controller;
|
||||
public BuildPlan plan = new BuildPlan();
|
||||
|
||||
//special cache for instruction to store data
|
||||
public ObjectMap<Object, Object> execCache = new ObjectMap<>();
|
||||
@@ -90,6 +91,11 @@ public class LogicAI extends AIController{
|
||||
}
|
||||
}
|
||||
}
|
||||
case stop -> {
|
||||
if(unit instanceof Builderc build){
|
||||
build.clearBuilding();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(unit.type().canBoost && !unit.type().flying){
|
||||
|
||||
@@ -1119,7 +1119,7 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.power, with(Items.titanium, 7, Items.lead, 10, Items.silicon, 15, Items.surgealloy, 15));
|
||||
size = 2;
|
||||
maxNodes = 2;
|
||||
laserRange = 30f;
|
||||
laserRange = 40f;
|
||||
}};
|
||||
|
||||
diode = new PowerDiode("diode"){{
|
||||
|
||||
@@ -208,7 +208,7 @@ abstract class BuilderComp implements Unitc{
|
||||
BuildPlan plan = buildPlan();
|
||||
Tile tile = world.tile(plan.x, plan.y);
|
||||
|
||||
if(dst(tile) > buildingRange && !state.isEditor()){
|
||||
if((dst(tile) > buildingRange && !state.isEditor()) || !plan.initialized){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1247,7 +1247,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
return switch(sensor){
|
||||
case type -> block;
|
||||
case firstItem -> items == null ? null : items.first();
|
||||
case name -> block.name;
|
||||
case config -> block.configurations.containsKey(Item.class) || block.configurations.containsKey(Liquid.class) ? config() : null;
|
||||
default -> noSensed;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,11 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
|
||||
return mineTile != null && !(((Object)this) instanceof Builderc && ((Builderc)(Object)this).activelyBuilding());
|
||||
}
|
||||
|
||||
public boolean validMine(Tile tile){
|
||||
return !(tile == null || tile.block() != Blocks.air || !within(tile.worldx(), tile.worldy(), miningRange)
|
||||
|| tile.drop() == null || !canMine(tile.drop()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
Building core = closestCore();
|
||||
@@ -49,8 +54,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
|
||||
}
|
||||
}
|
||||
|
||||
if(mineTile == null || core == null || mineTile.block() != Blocks.air || dst(mineTile.worldx(), mineTile.worldy()) > miningRange
|
||||
|| mineTile.drop() == null || !canMine(mineTile.drop())){
|
||||
if(core == null || !validMine(mineTile)){
|
||||
mineTile = null;
|
||||
mineTimer = 0f;
|
||||
}else if(mining()){
|
||||
|
||||
@@ -104,7 +104,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
public Object senseObject(LAccess sensor){
|
||||
return switch(sensor){
|
||||
case type -> type;
|
||||
case name -> controller instanceof Player p ? p.name : type.name;
|
||||
case name -> controller instanceof Player p ? p.name : null;
|
||||
case firstItem -> stack().amount == 0 ? null : item();
|
||||
default -> noSensed;
|
||||
};
|
||||
|
||||
@@ -29,6 +29,7 @@ public enum LAccess{
|
||||
type,
|
||||
flag,
|
||||
name,
|
||||
config,
|
||||
|
||||
//values with parameters are considered controllable
|
||||
enabled("to"), //"to" is standard for single parameter access
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.func.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.logic.LExecutor.*;
|
||||
import mindustry.logic.LStatements.*;
|
||||
@@ -51,6 +52,8 @@ public class LAssembler{
|
||||
}
|
||||
}
|
||||
|
||||
putConst("@air", Blocks.air);
|
||||
|
||||
for(UnitType type : Vars.content.units()){
|
||||
putConst("@" + type.name, type);
|
||||
}
|
||||
|
||||
@@ -330,6 +330,16 @@ public class LExecutor{
|
||||
if(type == LUnitControl.approach){
|
||||
ai.moveRad = exec.numf(p3);
|
||||
}
|
||||
|
||||
//stop mining/building
|
||||
if(type == LUnitControl.stop){
|
||||
if(unit instanceof Minerc miner){
|
||||
miner.mineTile(null);
|
||||
}
|
||||
if(unit instanceof Builderc build){
|
||||
build.clearBuilding();
|
||||
}
|
||||
}
|
||||
}
|
||||
case within -> {
|
||||
exec.setnum(p4, unit.within(exec.numf(p1), exec.numf(p2), exec.numf(p3)) ? 1 : 0);
|
||||
@@ -357,10 +367,38 @@ public class LExecutor{
|
||||
case mine -> {
|
||||
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);
|
||||
miner.mineTile(miner.validMine(tile) ? tile : null);
|
||||
}
|
||||
}
|
||||
case build -> {
|
||||
if(unit instanceof Builderc builder && exec.obj(p3) instanceof Block block){
|
||||
int x = world.toTile(exec.numf(p1)), y = world.toTile(exec.numf(p2));
|
||||
int rot = exec.numi(p4);
|
||||
|
||||
//reset state if:
|
||||
//
|
||||
if(ai.plan.x != x || ai.plan.y != y || ai.plan.block != block || builder.plans().isEmpty()){
|
||||
ai.plan.progress = 0;
|
||||
ai.plan.initialized = false;
|
||||
ai.plan.stuck = false;
|
||||
}
|
||||
|
||||
ai.plan.set(x, y, rot, block);
|
||||
ai.plan.config = null;
|
||||
|
||||
builder.clearBuilding();
|
||||
builder.updateBuilding(true);
|
||||
builder.addBuild(ai.plan);
|
||||
}
|
||||
}
|
||||
case getBlock -> {
|
||||
float x = exec.numf(p1), y = exec.numf(p2);
|
||||
if(unit.within(x, y, unit.range())){
|
||||
exec.setobj(p3, null);
|
||||
}else{
|
||||
Tile tile = world.tileWorld(x, y);
|
||||
Block block = tile == null || !tile.synthetic() ? null : tile.block();
|
||||
exec.setobj(p3, block);
|
||||
}
|
||||
}
|
||||
case itemDrop -> {
|
||||
|
||||
@@ -12,6 +12,8 @@ public enum LUnitControl{
|
||||
itemTake("from", "item", "amount"),
|
||||
mine("x", "y"),
|
||||
flag("value"),
|
||||
build("x", "y", "block", "rotation"),
|
||||
getBlock("x", "y", "result"),
|
||||
within("x", "y", "radius", "result");
|
||||
|
||||
public final String[] params;
|
||||
|
||||
Reference in New Issue
Block a user