More logic commands

This commit is contained in:
Anuken
2020-10-06 14:03:21 -04:00
parent 9182b48b85
commit 2d539565c3
10 changed files with 63 additions and 9 deletions
+6
View File
@@ -22,6 +22,7 @@ public class LogicAI extends AIController{
public float moveX, moveY, moveRad; public float moveX, moveY, moveRad;
public float itemTimer, controlTimer = logicControlTimeout, targetTimer; public float itemTimer, controlTimer = logicControlTimeout, targetTimer;
public Building controller; public Building controller;
public BuildPlan plan = new BuildPlan();
//special cache for instruction to store data //special cache for instruction to store data
public ObjectMap<Object, Object> execCache = new ObjectMap<>(); 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){ if(unit.type().canBoost && !unit.type().flying){
+1 -1
View File
@@ -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)); requirements(Category.power, with(Items.titanium, 7, Items.lead, 10, Items.silicon, 15, Items.surgealloy, 15));
size = 2; size = 2;
maxNodes = 2; maxNodes = 2;
laserRange = 30f; laserRange = 40f;
}}; }};
diode = new PowerDiode("diode"){{ diode = new PowerDiode("diode"){{
@@ -208,7 +208,7 @@ abstract class BuilderComp implements Unitc{
BuildPlan plan = buildPlan(); BuildPlan plan = buildPlan();
Tile tile = world.tile(plan.x, plan.y); Tile tile = world.tile(plan.x, plan.y);
if(dst(tile) > buildingRange && !state.isEditor()){ if((dst(tile) > buildingRange && !state.isEditor()) || !plan.initialized){
return; return;
} }
@@ -1247,7 +1247,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return switch(sensor){ return switch(sensor){
case type -> block; case type -> block;
case firstItem -> items == null ? null : items.first(); 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; 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()); 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 @Override
public void update(){ public void update(){
Building core = closestCore(); 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 if(core == null || !validMine(mineTile)){
|| mineTile.drop() == null || !canMine(mineTile.drop())){
mineTile = null; mineTile = null;
mineTimer = 0f; mineTimer = 0f;
}else if(mining()){ }else if(mining()){
@@ -104,7 +104,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
public Object senseObject(LAccess sensor){ public Object senseObject(LAccess sensor){
return switch(sensor){ return switch(sensor){
case type -> type; 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(); case firstItem -> stack().amount == 0 ? null : item();
default -> noSensed; default -> noSensed;
}; };
+1
View File
@@ -29,6 +29,7 @@ public enum LAccess{
type, type,
flag, flag,
name, name,
config,
//values with parameters are considered controllable //values with parameters are considered controllable
enabled("to"), //"to" is standard for single parameter access enabled("to"), //"to" is standard for single parameter access
+3
View File
@@ -4,6 +4,7 @@ import arc.func.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.*; import mindustry.*;
import mindustry.content.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.logic.LExecutor.*; import mindustry.logic.LExecutor.*;
import mindustry.logic.LStatements.*; import mindustry.logic.LStatements.*;
@@ -51,6 +52,8 @@ public class LAssembler{
} }
} }
putConst("@air", Blocks.air);
for(UnitType type : Vars.content.units()){ for(UnitType type : Vars.content.units()){
putConst("@" + type.name, type); putConst("@" + type.name, type);
} }
+41 -3
View File
@@ -330,6 +330,16 @@ public class LExecutor{
if(type == LUnitControl.approach){ if(type == LUnitControl.approach){
ai.moveRad = exec.numf(p3); 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 -> { case within -> {
exec.setnum(p4, unit.within(exec.numf(p1), exec.numf(p2), exec.numf(p3)) ? 1 : 0); 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 -> { case mine -> {
Tile tile = world.tileWorld(exec.numf(p1), exec.numf(p2)); Tile tile = world.tileWorld(exec.numf(p1), exec.numf(p2));
if(unit instanceof Minerc miner){ if(unit instanceof Minerc miner){
miner.mineTile(tile); miner.mineTile(miner.validMine(tile) ? tile : null);
if(tile != null && (!unit.acceptsItem(tile.drop()) || !miner.canMine(tile.drop()))){ }
miner.mineTile(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 -> { case itemDrop -> {
@@ -12,6 +12,8 @@ public enum LUnitControl{
itemTake("from", "item", "amount"), itemTake("from", "item", "amount"),
mine("x", "y"), mine("x", "y"),
flag("value"), flag("value"),
build("x", "y", "block", "rotation"),
getBlock("x", "y", "result"),
within("x", "y", "radius", "result"); within("x", "y", "radius", "result");
public final String[] params; public final String[] params;