From 264d13f827980707a7aac6743ec02058c5ff5794 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 17 Apr 2025 16:28:56 -0400 Subject: [PATCH] Closes Anuken/Mindustry-Suggestions/issues/5537, partially implements Anuken/Mindustry-Suggestions/issues/5535 --- core/src/mindustry/content/UnitTypes.java | 3 +++ core/src/mindustry/input/MobileInput.java | 2 +- core/src/mindustry/logic/LAccess.java | 4 +++- core/src/mindustry/type/UnitType.java | 2 ++ .../src/mindustry/world/blocks/logic/LogicDisplay.java | 10 +++++++++- .../world/blocks/logic/TileableLogicDisplay.java | 10 ++++++++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index c95f75068e..32108c65a3 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -2376,6 +2376,7 @@ public class UnitTypes{ controller = u -> u.team.isAI() ? aiController.get() : new CommandAI(); isEnemy = false; + targetBuildingsMobile = false; lowAltitude = true; flying = true; mineSpeed = 6.5f; @@ -2415,6 +2416,7 @@ public class UnitTypes{ controller = u -> u.team.isAI() ? aiController.get() : new CommandAI(); isEnemy = false; + targetBuildingsMobile = false; flying = true; mineSpeed = 7f; mineTier = 1; @@ -2457,6 +2459,7 @@ public class UnitTypes{ controller = u -> u.team.isAI() ? aiController.get() : new CommandAI(); isEnemy = false; + targetBuildingsMobile = false; lowAltitude = true; flying = true; mineSpeed = 8f; diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index bd16b6f9d6..d0282a1c8d 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -1063,7 +1063,7 @@ public class MobileInput extends InputHandler implements GestureListener{ player.shooting = false; if(Core.settings.getBool("autotarget") && !(player.unit() instanceof BlockUnitUnit u && u.tile() instanceof ControlBlock c && !c.shouldAutoTarget())){ if(unit.type.canAttack){ - target = Units.closestTarget(unit.team, unit.x, unit.y, range, u -> u.checkTarget(type.targetAir, type.targetGround), u -> type.targetGround); + target = Units.closestTarget(unit.team, unit.x, unit.y, range, u -> u.checkTarget(type.targetAir, type.targetGround), u -> type.targetGround && !type.targetBuildingsMobile); } if(allowHealing && target == null){ diff --git a/core/src/mindustry/logic/LAccess.java b/core/src/mindustry/logic/LAccess.java index 146ed91de1..f6dfd82c2c 100644 --- a/core/src/mindustry/logic/LAccess.java +++ b/core/src/mindustry/logic/LAccess.java @@ -38,10 +38,12 @@ public enum LAccess{ cameraY, cameraWidth, cameraHeight, + displayWidth, + displayHeight, size, solid, dead, - range, + range, shooting, boosting, mineX, diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 260a0f3656..c99fa2090d 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -163,6 +163,8 @@ public class UnitType extends UnlockableContent implements Senseable{ circleTarget = false, /** AI flag: if true, this unit will drop bombs under itself even when it is not next to its 'real' target. used for carpet bombers */ autoDropBombs = false, + /** For the mobile version only: If false, this unit will not auto-target buildings to attach when a player controls it. */ + targetBuildingsMobile = true, /** if true, this unit can boost into the air if a player/processors controls it*/ canBoost = false, /** if true, this unit will always boost when using builder AI */ diff --git a/core/src/mindustry/world/blocks/logic/LogicDisplay.java b/core/src/mindustry/world/blocks/logic/LogicDisplay.java index 2fda8ca7fd..3f9d772219 100644 --- a/core/src/mindustry/world/blocks/logic/LogicDisplay.java +++ b/core/src/mindustry/world/blocks/logic/LogicDisplay.java @@ -71,7 +71,7 @@ public class LogicDisplay extends Block{ clipSize = Math.max(clipSize, scaleFactor * Draw.scl * displaySize); } - + public class LogicDisplayBuild extends Building{ public @Nullable FrameBuffer buffer; public float color = Color.whiteFloatBits; @@ -106,6 +106,14 @@ public class LogicDisplay extends Block{ Draw.blend(); } + @Override + public double sense(LAccess sensor){ + return switch(sensor){ + case displayWidth, displayHeight -> displaySize; + default -> super.sense(sensor); + }; + } + public void flushCommands(LongSeq graphicsBuffer){ int added = Math.min(graphicsBuffer.size, LExecutor.maxDisplayBuffer - commands.size); diff --git a/core/src/mindustry/world/blocks/logic/TileableLogicDisplay.java b/core/src/mindustry/world/blocks/logic/TileableLogicDisplay.java index b09bce00bc..de77766c9f 100644 --- a/core/src/mindustry/world/blocks/logic/TileableLogicDisplay.java +++ b/core/src/mindustry/world/blocks/logic/TileableLogicDisplay.java @@ -11,6 +11,7 @@ import arc.util.*; import mindustry.*; import mindustry.annotations.Annotations.*; import mindustry.graphics.*; +import mindustry.logic.*; import mindustry.world.*; import static mindustry.Vars.*; @@ -144,6 +145,15 @@ public class TileableLogicDisplay extends LogicDisplay{ public int bits = 0; public boolean needsUpdate = false; + @Override + public double sense(LAccess sensor){ + return switch(sensor){ + case displayWidth -> tilesWidth * 32f; + case displayHeight -> tilesHeight * 32f; + default -> super.sense(sensor); + }; + } + @Override public void display(Table table){ super.display(table);