More logic commands
This commit is contained in:
@@ -20,7 +20,7 @@ public class LogicAI extends AIController{
|
|||||||
|
|
||||||
public LUnitControl control = LUnitControl.stop;
|
public LUnitControl control = LUnitControl.stop;
|
||||||
public float moveX, moveY, moveRad;
|
public float moveX, moveY, moveRad;
|
||||||
public float itemTimer, controlTimer = logicControlTimeout, targetTimer;
|
public float itemTimer, payTimer, controlTimer = logicControlTimeout, targetTimer;
|
||||||
public Building controller;
|
public Building controller;
|
||||||
public BuildPlan plan = new BuildPlan();
|
public BuildPlan plan = new BuildPlan();
|
||||||
|
|
||||||
@@ -43,9 +43,8 @@ public class LogicAI extends AIController{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateMovement(){
|
protected void updateMovement(){
|
||||||
if(itemTimer > 0){
|
if(itemTimer > 0) itemTimer -= Time.delta;
|
||||||
itemTimer -= Time.delta;
|
if(payTimer > 0) payTimer -= Time.delta;
|
||||||
}
|
|
||||||
|
|
||||||
if(targetTimer > 0f){
|
if(targetTimer > 0f){
|
||||||
targetTimer -= Time.delta;
|
targetTimer -= Time.delta;
|
||||||
@@ -67,7 +66,7 @@ public class LogicAI extends AIController{
|
|||||||
moveTo(Tmp.v1.set(moveX, moveY), 1f, 30f);
|
moveTo(Tmp.v1.set(moveX, moveY), 1f, 30f);
|
||||||
}
|
}
|
||||||
case approach -> {
|
case approach -> {
|
||||||
moveTo(Tmp.v1.set(moveX, moveY), moveRad, 1f);
|
moveTo(Tmp.v1.set(moveX, moveY), moveRad - 8f, 8f);
|
||||||
}
|
}
|
||||||
case pathfind -> {
|
case pathfind -> {
|
||||||
Building core = unit.closestEnemyCore();
|
Building core = unit.closestEnemyCore();
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ public class Blocks implements ContentList{
|
|||||||
|
|
||||||
salt = new Floor("salt"){{
|
salt = new Floor("salt"){{
|
||||||
variants = 0;
|
variants = 0;
|
||||||
attributes.set(Attribute.water, -0.25f);
|
attributes.set(Attribute.water, -0.3f);
|
||||||
attributes.set(Attribute.oil, 0.3f);
|
attributes.set(Attribute.oil, 0.3f);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@@ -718,7 +718,7 @@ public class Blocks implements ContentList{
|
|||||||
size = 2;
|
size = 2;
|
||||||
hasPower = hasItems = hasLiquids = true;
|
hasPower = hasItems = hasLiquids = true;
|
||||||
|
|
||||||
consumes.liquid(Liquids.oil, 0.09f);
|
consumes.liquid(Liquids.oil, 0.1f);
|
||||||
consumes.power(0.5f);
|
consumes.power(0.5f);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
|||||||
@@ -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()) || !plan.initialized){
|
if(dst(tile) > buildingRange && !state.isEditor()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
static final Seq<Tile> tempTiles = new Seq<>();
|
static final Seq<Tile> tempTiles = new Seq<>();
|
||||||
static int sleepingEntities = 0;
|
static int sleepingEntities = 0;
|
||||||
|
|
||||||
@Import float x, y, health;
|
@Import float x, y, health, maxHealth;
|
||||||
@Import Team team;
|
@Import Team team;
|
||||||
|
|
||||||
transient Tile tile;
|
transient Tile tile;
|
||||||
@@ -1224,7 +1224,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
case y -> y;
|
case y -> y;
|
||||||
case team -> team.id;
|
case team -> team.id;
|
||||||
case health -> health;
|
case health -> health;
|
||||||
case maxHealth -> maxHealth();
|
case maxHealth -> maxHealth;
|
||||||
case efficiency -> efficiency();
|
case efficiency -> efficiency();
|
||||||
case rotation -> rotation;
|
case rotation -> rotation;
|
||||||
case totalItems -> items == null ? 0 : items.total();
|
case totalItems -> items == null ? 0 : items.total();
|
||||||
@@ -1238,6 +1238,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
case powerNetStored -> power == null ? 0 : power.graph.getLastPowerStored();
|
case powerNetStored -> power == null ? 0 : power.graph.getLastPowerStored();
|
||||||
case powerNetCapacity -> power == null ? 0 : power.graph.getLastCapacity();
|
case powerNetCapacity -> power == null ? 0 : power.graph.getLastCapacity();
|
||||||
case enabled -> enabled ? 1 : 0;
|
case enabled -> enabled ? 1 : 0;
|
||||||
|
case payloadCount -> getPayload() != null ? 1 : 0;
|
||||||
default -> 0;
|
default -> 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1248,6 +1249,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
case type -> block;
|
case type -> block;
|
||||||
case firstItem -> items == null ? null : items.first();
|
case firstItem -> items == null ? null : items.first();
|
||||||
case config -> block.configurations.containsKey(Item.class) || block.configurations.containsKey(Liquid.class) ? config() : null;
|
case config -> block.configurations.containsKey(Item.class) || block.configurations.containsKey(Liquid.class) ? config() : null;
|
||||||
|
case payloadType -> getPayload() instanceof UnitPayload p1 ? p1.unit.type() : getPayload() instanceof BlockPayload p2 ? p2.block() : null;
|
||||||
default -> noSensed;
|
default -> noSensed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import mindustry.type.*;
|
|||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.environment.*;
|
import mindustry.world.blocks.environment.*;
|
||||||
|
import mindustry.world.blocks.payloads.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -96,6 +97,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
|||||||
case shootX -> aimX();
|
case shootX -> aimX();
|
||||||
case shootY -> aimY();
|
case shootY -> aimY();
|
||||||
case flag -> flag;
|
case flag -> flag;
|
||||||
|
case payloadCount -> self() instanceof Payloadc pay ? pay.payloads().size : 0;
|
||||||
default -> 0;
|
default -> 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -106,6 +108,10 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
|||||||
case type -> type;
|
case type -> type;
|
||||||
case name -> controller instanceof Player p ? p.name : null;
|
case name -> controller instanceof Player p ? p.name : null;
|
||||||
case firstItem -> stack().amount == 0 ? null : item();
|
case firstItem -> stack().amount == 0 ? null : item();
|
||||||
|
case payloadType -> self() instanceof Payloadc pay ?
|
||||||
|
(pay.payloads().isEmpty() ? null :
|
||||||
|
pay.payloads().peek() instanceof UnitPayload p1 ? p1.unit.type() :
|
||||||
|
pay.payloads().peek() instanceof BlockPayload p2 ? p2.block() : null) : null;
|
||||||
default -> noSensed;
|
default -> noSensed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
|
|
||||||
if(target.isAI() && target.isGrounded() && pay.canPickup(target)
|
if(target.isAI() && target.isGrounded() && pay.canPickup(target)
|
||||||
&& target.within(unit, unit.type().hitSize * 2f + target.type().hitSize * 2f)){
|
&& target.within(unit, unit.type().hitSize * 2f + target.type().hitSize * 2f)){
|
||||||
Call.pickedUnitPayload(player, target);
|
Call.pickedUnitPayload(unit, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,41 +174,28 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
&& unit.within(tile, tilesize * tile.block.size * 1.2f + tilesize * 5f)){
|
&& unit.within(tile, tilesize * tile.block.size * 1.2f + tilesize * 5f)){
|
||||||
//pick up block directly
|
//pick up block directly
|
||||||
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
||||||
Call.pickedBlockPayload(player, tile, true);
|
Call.pickedBlockPayload(unit, tile, true);
|
||||||
}else{ //pick up block payload
|
}else{ //pick up block payload
|
||||||
Payload current = tile.getPayload();
|
Payload current = tile.getPayload();
|
||||||
if(current != null && pay.canPickupPayload(current)){
|
if(current != null && pay.canPickupPayload(current)){
|
||||||
Call.pickedBlockPayload(player, tile, false);
|
Call.pickedBlockPayload(unit, tile, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.server, called = Loc.server)
|
@Remote(targets = Loc.server, called = Loc.server)
|
||||||
public static void pickedUnitPayload(Player player, Unit target){
|
public static void pickedUnitPayload(Unit unit, Unit target){
|
||||||
if(player == null || target == null || !(player.unit() instanceof Payloadc)){
|
if(target != null && unit instanceof Payloadc pay){
|
||||||
if(target != null){
|
pay.pickup(target);
|
||||||
|
}else if(target != null){
|
||||||
target.remove();
|
target.remove();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
((Payloadc)player.unit()).pickup(target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.server, called = Loc.server)
|
@Remote(targets = Loc.server, called = Loc.server)
|
||||||
public static void pickedBlockPayload(Player player, Building tile, boolean onGround){
|
public static void pickedBlockPayload(Unit unit, Building tile, boolean onGround){
|
||||||
if(player == null || tile == null || !(player.unit() instanceof Payloadc)){
|
if(tile != null && unit instanceof Payloadc pay){
|
||||||
if(tile != null && onGround){
|
|
||||||
Fx.unitPickup.at(tile);
|
|
||||||
tile.tile.remove();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Unit unit = player.unit();
|
|
||||||
Payloadc pay = (Payloadc)unit;
|
|
||||||
|
|
||||||
if(onGround){
|
if(onGround){
|
||||||
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
||||||
pay.pickup(tile);
|
pay.pickup(tile);
|
||||||
@@ -226,6 +213,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}else if(tile != null && onGround){
|
||||||
|
Fx.unitPickup.at(tile);
|
||||||
|
tile.tile.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.server)
|
@Remote(targets = Loc.both, called = Loc.server)
|
||||||
@@ -238,20 +230,18 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
Tmp.v1.set(x, y).sub(pay).limit(tilesize * 4f).add(pay);
|
Tmp.v1.set(x, y).sub(pay).limit(tilesize * 4f).add(pay);
|
||||||
float cx = Tmp.v1.x, cy = Tmp.v1.y;
|
float cx = Tmp.v1.x, cy = Tmp.v1.y;
|
||||||
|
|
||||||
Call.payloadDropped(player, cx, cy);
|
Call.payloadDropped(player.unit(), cx, cy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(called = Loc.server, targets = Loc.server)
|
@Remote(called = Loc.server, targets = Loc.server)
|
||||||
public static void payloadDropped(Player player, float x, float y){
|
public static void payloadDropped(Unit unit, float x, float y){
|
||||||
if(player == null) return;
|
if(unit instanceof Payloadc pay){
|
||||||
|
|
||||||
Payloadc pay = (Payloadc)player.unit();
|
|
||||||
|
|
||||||
float prevx = pay.x(), prevy = pay.y();
|
float prevx = pay.x(), prevy = pay.y();
|
||||||
pay.set(x, y);
|
pay.set(x, y);
|
||||||
pay.dropLastPayload();
|
pay.dropLastPayload();
|
||||||
pay.set(prevx, prevy);
|
pay.set(prevx, prevy);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.client, called = Loc.server)
|
@Remote(targets = Loc.client, called = Loc.server)
|
||||||
public static void dropItem(Player player, float angle){
|
public static void dropItem(Player player, float angle){
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ public enum LAccess{
|
|||||||
flag,
|
flag,
|
||||||
name,
|
name,
|
||||||
config,
|
config,
|
||||||
|
payloadCount,
|
||||||
|
payloadType,
|
||||||
|
|
||||||
//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
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import mindustry.world.*;
|
|||||||
import mindustry.world.blocks.logic.LogicDisplay.*;
|
import mindustry.world.blocks.logic.LogicDisplay.*;
|
||||||
import mindustry.world.blocks.logic.MemoryBlock.*;
|
import mindustry.world.blocks.logic.MemoryBlock.*;
|
||||||
import mindustry.world.blocks.logic.MessageBlock.*;
|
import mindustry.world.blocks.logic.MessageBlock.*;
|
||||||
|
import mindustry.world.blocks.payloads.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
@@ -370,13 +371,47 @@ public class LExecutor{
|
|||||||
miner.mineTile(miner.validMine(tile) ? tile : null);
|
miner.mineTile(miner.validMine(tile) ? tile : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case payDrop -> {
|
||||||
|
if(ai.payTimer > 0) return;
|
||||||
|
|
||||||
|
if(unit instanceof Payloadc pay && pay.hasPayload()){
|
||||||
|
Call.payloadDropped(unit, unit.x, unit.y);
|
||||||
|
ai.payTimer = LogicAI.transferDelay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case payTake -> {
|
||||||
|
if(ai.payTimer > 0) return;
|
||||||
|
|
||||||
|
if(unit instanceof Payloadc pay){
|
||||||
|
//units
|
||||||
|
if(exec.bool(p1)){
|
||||||
|
Unit result = Units.closest(unit.team, unit.x, unit.y, unit.type().hitSize * 2f, u -> u.isAI() && u.isGrounded() && pay.canPickup(u) && u.within(unit, u.hitSize + unit.hitSize * 1.2f));
|
||||||
|
|
||||||
|
Call.pickedUnitPayload(unit, result);
|
||||||
|
}else{ //buildings
|
||||||
|
Building tile = world.buildWorld(unit.x, unit.y);
|
||||||
|
|
||||||
|
//TODO copy pasted code
|
||||||
|
if(tile != null && tile.team == unit.team){
|
||||||
|
if(tile.block.buildVisibility != BuildVisibility.hidden && tile.canPickup() && pay.canPickup(tile)){
|
||||||
|
Call.pickedBlockPayload(unit, tile, true);
|
||||||
|
}else{ //pick up block payload
|
||||||
|
Payload current = tile.getPayload();
|
||||||
|
if(current != null && pay.canPickupPayload(current)){
|
||||||
|
Call.pickedBlockPayload(unit, tile, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ai.payTimer = LogicAI.transferDelay;
|
||||||
|
}
|
||||||
|
}
|
||||||
case build -> {
|
case build -> {
|
||||||
if(unit instanceof Builderc builder && exec.obj(p3) instanceof Block block){
|
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 x = world.toTile(exec.numf(p1)), y = world.toTile(exec.numf(p2));
|
||||||
int rot = exec.numi(p4);
|
int rot = exec.numi(p4);
|
||||||
|
|
||||||
//reset state if:
|
//reset state of last request when necessary
|
||||||
//
|
|
||||||
if(ai.plan.x != x || ai.plan.y != y || ai.plan.block != block || builder.plans().isEmpty()){
|
if(ai.plan.x != x || ai.plan.y != y || ai.plan.block != block || builder.plans().isEmpty()){
|
||||||
ai.plan.progress = 0;
|
ai.plan.progress = 0;
|
||||||
ai.plan.initialized = false;
|
ai.plan.initialized = false;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public enum LUnitControl{
|
|||||||
targetp("unit", "shoot"),
|
targetp("unit", "shoot"),
|
||||||
itemDrop("to", "amount"),
|
itemDrop("to", "amount"),
|
||||||
itemTake("from", "item", "amount"),
|
itemTake("from", "item", "amount"),
|
||||||
|
payDrop,
|
||||||
|
payTake("takeUnits"),
|
||||||
mine("x", "y"),
|
mine("x", "y"),
|
||||||
flag("value"),
|
flag("value"),
|
||||||
build("x", "y", "block", "rotation"),
|
build("x", "y", "block", "rotation"),
|
||||||
|
|||||||
Reference in New Issue
Block a user