From b84d12407fb64be5941fee2bdd572adb5ca20b47 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 19 Dec 2025 00:35:41 -0500 Subject: [PATCH] Rule & control for logic unit deconstruction (off by default) --- core/assets/bundles/bundle.properties | 2 -- core/src/mindustry/game/Rules.java | 2 ++ core/src/mindustry/logic/LExecutor.java | 15 +++++++++++++++ core/src/mindustry/logic/LStatements.java | 12 ++++++------ core/src/mindustry/logic/LUnitControl.java | 1 + core/src/mindustry/mod/Mods.java | 2 +- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index ce25f8afc9..24200d2e46 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2607,8 +2607,6 @@ lglobal.@clientName = Player name 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 -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.shoot = Shoot at a position. lenum.shootp = Shoot at a unit/building with velocity prediction. diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index a268020da1..62b70e6dc2 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -92,6 +92,8 @@ public class Rules{ public boolean ghostBlocks = true; /** Whether to allow units to build with logic. */ 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. */ public boolean allowEditWorldProcessors = false; /** If true, world processors no longer update. Used for testing. */ diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index f036bad977..56fd115ca7 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -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 -> { float range = Math.max(unit.range(), unit.type.buildRange); if(!unit.within(x1, y1, range)){ diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index e138af4a16..96ca6c4e1f 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -1128,12 +1128,12 @@ public class LStatements{ table.button(b -> { b.label(() -> type.name()); - b.clicked(() -> showSelect(b, LUnitControl.all, type, t -> { - if(t == LUnitControl.build && !Vars.state.rules.logicUnitBuild){ - Vars.ui.showInfo("@logic.nounitbuild"); - }else{ - type = t; - } + b.clicked(() -> showSelect(b, Structs.filter(LUnitControl.class, LUnitControl.all, t -> + t == LUnitControl.build ? state.rules.logicUnitBuild : + t == LUnitControl.deconstruct ? state.rules.logicUnitDeconstruct : + true + ), type, t -> { + type = t; rebuild(table); }, 2, cell -> cell.size(120, 50))); }, Styles.logict, () -> {}).size(120, 40).color(table.color).left().padLeft(2); diff --git a/core/src/mindustry/logic/LUnitControl.java b/core/src/mindustry/logic/LUnitControl.java index ccfe9b5d3f..82d497ee49 100644 --- a/core/src/mindustry/logic/LUnitControl.java +++ b/core/src/mindustry/logic/LUnitControl.java @@ -18,6 +18,7 @@ public enum LUnitControl{ mine("x", "y"), flag("value"), build("x", "y", "block", "rotation", "config"), + deconstruct("x", "y"), getBlock("x", "y", "type", "building", "floor"), within("x", "y", "radius", "result"), unbind; diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 31de73e7b4..766eae0f6f 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -1492,7 +1492,7 @@ public class Mods implements Loadable{ disabled, } - public static class ModResolutionContext { + public static class ModResolutionContext{ public final ObjectMap> dependencies = new ObjectMap<>(); public final ObjectSet visited = new ObjectSet<>(); public final OrderedSet ordered = new OrderedSet<>();