From 75ae76135fed38a8455ce1c386d6795806681dd2 Mon Sep 17 00:00:00 2001 From: MEEPofFaith <54301439+MEEPofFaith@users.noreply.github.com> Date: Sat, 3 Feb 2024 09:17:07 -0800 Subject: [PATCH] targetUnderBlocks for units (#8160) * targetUnderBlocks for units You know, why don't units use the same targeting code as turrets? * prioritize non-under blocks --- core/src/mindustry/content/Blocks.java | 1 + core/src/mindustry/entities/Units.java | 14 ++++++++++++-- .../src/mindustry/entities/units/AIController.java | 2 +- core/src/mindustry/type/UnitType.java | 2 ++ core/src/mindustry/type/Weapon.java | 2 +- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index c86f3ffe56..62af440a16 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -4567,6 +4567,7 @@ public class Blocks{ loopSoundVolume = 0.6f; deathSound = Sounds.largeExplosion; targetAir = false; + targetUnderBlocks = false; fogRadius = 6f; diff --git a/core/src/mindustry/entities/Units.java b/core/src/mindustry/entities/Units.java index a641bac7a8..659112d57a 100644 --- a/core/src/mindustry/entities/Units.java +++ b/core/src/mindustry/entities/Units.java @@ -192,8 +192,18 @@ public class Units{ /** Returns the nearest enemy tile in a range. */ public static Building findEnemyTile(Team team, float x, float y, float range, Boolf pred){ + return findEnemyTile(team, x, y, range, false, pred); + } + + /** Returns the nearest enemy tile in a range. */ + public static Building findEnemyTile(Team team, float x, float y, float range, boolean checkUnder, Boolf pred){ if(team == Team.derelict) return null; + if(checkUnder){ + Building target = indexer.findEnemyTile(team, x, y, range, build -> !build.block.underBullets && pred.get(build)); + if(target != null) return target; + } + return indexer.findEnemyTile(team, x, y, range, pred); } @@ -243,7 +253,7 @@ public class Units{ if(unit != null){ return unit; }else{ - return findEnemyTile(team, x, y, range, tilePred); + return findEnemyTile(team, x, y, range, true, tilePred); } } @@ -255,7 +265,7 @@ public class Units{ if(unit != null){ return unit; }else{ - return findEnemyTile(team, x, y, range, tilePred); + return findEnemyTile(team, x, y, range, true, tilePred); } } diff --git a/core/src/mindustry/entities/units/AIController.java b/core/src/mindustry/entities/units/AIController.java index 2c638bec76..009e56d6ad 100644 --- a/core/src/mindustry/entities/units/AIController.java +++ b/core/src/mindustry/entities/units/AIController.java @@ -227,7 +227,7 @@ public class AIController implements UnitController{ } public Teamc target(float x, float y, float range, boolean air, boolean ground){ - return Units.closestTarget(unit.team, x, y, range, u -> u.checkTarget(air, ground), t -> ground); + return Units.closestTarget(unit.team, x, y, range, u -> u.checkTarget(air, ground), t -> ground && (unit.type.targetUnderBlocks || !t.block.underBullets)); } public boolean retarget(){ diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index b5855f69b5..09dacda4db 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -215,6 +215,8 @@ public class UnitType extends UnlockableContent implements Senseable{ naval = false, /** if false, RTS AI controlled units do not automatically attack things while moving. This is automatically assigned. */ autoFindTarget = true, + /** If false, 'under' blocks like conveyors are not targeted. */ + targetUnderBlocks = true, /** if true, this unit will always shoot while moving regardless of slowdown */ alwaysShootWhenMoving = false, diff --git a/core/src/mindustry/type/Weapon.java b/core/src/mindustry/type/Weapon.java index 0dc9843208..1e4378ebe5 100644 --- a/core/src/mindustry/type/Weapon.java +++ b/core/src/mindustry/type/Weapon.java @@ -430,7 +430,7 @@ public class Weapon implements Cloneable{ } protected Teamc findTarget(Unit unit, float x, float y, float range, boolean air, boolean ground){ - return Units.closestTarget(unit.team, x, y, range + Math.abs(shootY), u -> u.checkTarget(air, ground), t -> ground); + return Units.closestTarget(unit.team, x, y, range + Math.abs(shootY), u -> u.checkTarget(air, ground), t -> ground && (unit.type.targetUnderBlocks || !t.block.underBullets)); } protected boolean checkTarget(Unit unit, Teamc target, float x, float y, float range){