Rule & control for logic unit deconstruction (off by default)

This commit is contained in:
Anuken
2025-12-19 00:35:41 -05:00
parent f391126b5b
commit b84d12407f
6 changed files with 25 additions and 9 deletions

View File

@@ -2607,8 +2607,6 @@ lglobal.@clientName = Player name of client running the code
lglobal.@clientTeam = Team ID of client running the code lglobal.@clientTeam = Team ID of client running the code
lglobal.@clientMobile = True if the client running the code is on mobile, false otherwise lglobal.@clientMobile = True if the client running the code is on mobile, false otherwise
logic.nounitbuild = [red]Unit building logic is not allowed here.
lenum.type = Type of building/unit.\ne.g. for any router, this will return [accent]@router[].\nNot a string. lenum.type = Type of building/unit.\ne.g. for any router, this will return [accent]@router[].\nNot a string.
lenum.shoot = Shoot at a position. lenum.shoot = Shoot at a position.
lenum.shootp = Shoot at a unit/building with velocity prediction. lenum.shootp = Shoot at a unit/building with velocity prediction.

View File

@@ -92,6 +92,8 @@ public class Rules{
public boolean ghostBlocks = true; public boolean ghostBlocks = true;
/** Whether to allow units to build with logic. */ /** Whether to allow units to build with logic. */
public boolean logicUnitBuild = true; public boolean logicUnitBuild = true;
/** Whether to allow units to deconstruct blocks with logic. */
public boolean logicUnitDeconstruct = false;
/** If true, world processors can be edited and placed on this map. */ /** If true, world processors can be edited and placed on this map. */
public boolean allowEditWorldProcessors = false; public boolean allowEditWorldProcessors = false;
/** If true, world processors no longer update. Used for testing. */ /** If true, world processors no longer update. Used for testing. */

View File

@@ -430,6 +430,21 @@ public class LExecutor{
} }
} }
} }
case deconstruct -> {
if((state.rules.logicUnitDeconstruct || exec.privileged) && unit.canBuild()){
ai.plan.x = World.toTile(x1);
ai.plan.y = World.toTile(y1);
ai.plan.breaking = true;
unit.clearBuilding();
Tile tile = ai.plan.tile();
if(tile != null && Build.validBreak(unit.team, ai.plan.x, ai.plan.y)){
unit.updateBuilding = true;
unit.addBuild(ai.plan);
}
}
}
case getBlock -> { case getBlock -> {
float range = Math.max(unit.range(), unit.type.buildRange); float range = Math.max(unit.range(), unit.type.buildRange);
if(!unit.within(x1, y1, range)){ if(!unit.within(x1, y1, range)){

View File

@@ -1128,12 +1128,12 @@ public class LStatements{
table.button(b -> { table.button(b -> {
b.label(() -> type.name()); b.label(() -> type.name());
b.clicked(() -> showSelect(b, LUnitControl.all, type, t -> { b.clicked(() -> showSelect(b, Structs.filter(LUnitControl.class, LUnitControl.all, t ->
if(t == LUnitControl.build && !Vars.state.rules.logicUnitBuild){ t == LUnitControl.build ? state.rules.logicUnitBuild :
Vars.ui.showInfo("@logic.nounitbuild"); t == LUnitControl.deconstruct ? state.rules.logicUnitDeconstruct :
}else{ true
type = t; ), type, t -> {
} type = t;
rebuild(table); rebuild(table);
}, 2, cell -> cell.size(120, 50))); }, 2, cell -> cell.size(120, 50)));
}, Styles.logict, () -> {}).size(120, 40).color(table.color).left().padLeft(2); }, Styles.logict, () -> {}).size(120, 40).color(table.color).left().padLeft(2);

View File

@@ -18,6 +18,7 @@ public enum LUnitControl{
mine("x", "y"), mine("x", "y"),
flag("value"), flag("value"),
build("x", "y", "block", "rotation", "config"), build("x", "y", "block", "rotation", "config"),
deconstruct("x", "y"),
getBlock("x", "y", "type", "building", "floor"), getBlock("x", "y", "type", "building", "floor"),
within("x", "y", "radius", "result"), within("x", "y", "radius", "result"),
unbind; unbind;

View File

@@ -1492,7 +1492,7 @@ public class Mods implements Loadable{
disabled, disabled,
} }
public static class ModResolutionContext { public static class ModResolutionContext{
public final ObjectMap<String, Seq<ModDependency>> dependencies = new ObjectMap<>(); public final ObjectMap<String, Seq<ModDependency>> dependencies = new ObjectMap<>();
public final ObjectSet<String> visited = new ObjectSet<>(); public final ObjectSet<String> visited = new ObjectSet<>();
public final OrderedSet<String> ordered = new OrderedSet<>(); public final OrderedSet<String> ordered = new OrderedSet<>();