Better logic integration with commands

This commit is contained in:
Anuken 2022-04-10 10:23:35 -04:00
parent 61a11c9f5b
commit a7c898a08f
5 changed files with 6 additions and 4 deletions

View file

@ -1716,9 +1716,9 @@ lenum.config = Building configuration, e.g. sorter item.
lenum.enabled = Whether the block is enabled. lenum.enabled = Whether the block is enabled.
laccess.color = Illuminator color. laccess.color = Illuminator color.
laccess.controller = Unit controller. If processor controlled, returns processor.\nIf in a formation, returns leader.\nOtherwise, returns the unit itself. laccess.controller = Unit controller. If processor controlled, returns processor.\nOtherwise, returns the unit itself.
laccess.dead = Whether a unit/building is dead or no longer valid. laccess.dead = Whether a unit/building is dead or no longer valid.
laccess.controlled = Returns:\n[accent]@ctrlProcessor[] if unit controller is processor\n[accent]@ctrlPlayer[] if unit/building controller is player\nOtherwise, 0. laccess.controlled = Returns:\n[accent]@ctrlProcessor[] if unit controller is processor\n[accent]@ctrlPlayer[] if unit/building controller is player\n[accent]@ctrlCommand[] if unit controller is a player command\nOtherwise, 0.
laccess.progress = Action progress, 0 to 1.\nReturns production, turret reload or construction progress. laccess.progress = Action progress, 0 to 1.\nReturns production, turret reload or construction progress.
lacess.speed = Top speed of a unit, in tiles/sec. lacess.speed = Top speed of a unit, in tiles/sec.

Binary file not shown.

View file

@ -210,6 +210,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
case controlled -> !isValid() ? 0 : case controlled -> !isValid() ? 0 :
controller instanceof LogicAI ? ctrlProcessor : controller instanceof LogicAI ? ctrlProcessor :
controller instanceof Player ? ctrlPlayer : controller instanceof Player ? ctrlPlayer :
controller instanceof CommandAI command && command.hasCommand() ? ctrlCommand :
0; 0;
case payloadCount -> ((Object)this) instanceof Payloadc pay ? pay.payloads().size : 0; case payloadCount -> ((Object)this) instanceof Payloadc pay ? pay.payloads().size : 0;
case size -> hitSize / tilesize; case size -> hitSize / tilesize;

View file

@ -19,7 +19,7 @@ import static mindustry.Vars.*;
/** Stores global constants for logic processors. */ /** Stores global constants for logic processors. */
public class GlobalConstants{ public class GlobalConstants{
public static final int ctrlProcessor = 1, ctrlPlayer = 2; public static final int ctrlProcessor = 1, ctrlPlayer = 2, ctrlCommand = 3;
public static final ContentType[] lookableContent = {ContentType.block, ContentType.unit, ContentType.item, ContentType.liquid}; public static final ContentType[] lookableContent = {ContentType.block, ContentType.unit, ContentType.item, ContentType.liquid};
/** Global random state. */ /** Global random state. */
public static final Rand rand = new Rand(); public static final Rand rand = new Rand();
@ -51,6 +51,7 @@ public class GlobalConstants{
put("@ctrlProcessor", ctrlProcessor); put("@ctrlProcessor", ctrlProcessor);
put("@ctrlPlayer", ctrlPlayer); put("@ctrlPlayer", ctrlPlayer);
put("@ctrlCommand", ctrlCommand);
//store base content //store base content

View file

@ -338,7 +338,7 @@ public class LExecutor{
/** Checks is a unit is valid for logic AI control, and returns the controller. */ /** Checks is a unit is valid for logic AI control, and returns the controller. */
@Nullable @Nullable
public static LogicAI checkLogicAI(LExecutor exec, Object unitObj){ public static LogicAI checkLogicAI(LExecutor exec, Object unitObj){
if(unitObj instanceof Unit unit && unit.isValid() && exec.obj(varUnit) == unit && unit.team == exec.team && !unit.isPlayer()){ if(unitObj instanceof Unit unit && unit.isValid() && exec.obj(varUnit) == unit && unit.team == exec.team && !unit.isPlayer() && !(unit.isCommandable() && unit.command().hasCommand())){
if(unit.controller() instanceof LogicAI la){ if(unit.controller() instanceof LogicAI la){
la.controller = exec.building(varThis); la.controller = exec.building(varThis);
return la; return la;