From b4a9d546aa32369506bcfe8d9d0ede4af24fe9c2 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 8 Feb 2022 14:49:31 -0500 Subject: [PATCH] Repair beam weapon snap --- core/src/mindustry/content/UnitTypes.java | 6 +++--- .../mindustry/type/weapons/RepairBeamWeapon.java | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index c46c3cd63d..ad1aa9ce61 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -3154,7 +3154,7 @@ public class UnitTypes{ weapons.add(new RepairBeamWeapon(){{ widthSinMag = 0.11f; - reload = 25f; + reload = 20f; x = 0f; y = 6.5f; rotate = false; @@ -3211,7 +3211,7 @@ public class UnitTypes{ weapons.add(new RepairBeamWeapon(){{ widthSinMag = 0.11f; - reload = 25f; + reload = 20f; x = 0f; y = 7.5f; rotate = false; @@ -3280,7 +3280,7 @@ public class UnitTypes{ weapons.add(new RepairBeamWeapon(){{ widthSinMag = 0.11f; - reload = 25f; + reload = 20f; x = 19f/4f; y = 19f/4f; rotate = false; diff --git a/core/src/mindustry/type/weapons/RepairBeamWeapon.java b/core/src/mindustry/type/weapons/RepairBeamWeapon.java index fa6d21a869..e39d6e658f 100644 --- a/core/src/mindustry/type/weapons/RepairBeamWeapon.java +++ b/core/src/mindustry/type/weapons/RepairBeamWeapon.java @@ -17,6 +17,8 @@ import mindustry.type.*; import mindustry.world.blocks.units.*; import mindustry.world.meta.*; +import static mindustry.Vars.*; + /** * Note that this weapon requires a bullet with a positive maxRange. * Rotation must be set to true. Fixed repair points are not supported. @@ -122,10 +124,16 @@ public class RepairBeamWeapon extends Weapon{ heal.lastEnd.sub(wx, wy).limit(range()).add(wx, wy); if(targetBuildings){ - var build = Vars.world.buildWorld(mount.aimX, mount.aimY); - if(build != null && build.team == unit.team){ - heal.target = build; - } + //snap to closest building + Vars.world.raycastEachWorld(wx, wy, mount.aimX, mount.aimY, (x, y) -> { + var build = Vars.world.build(x, y); + if(build != null && build.team == unit.team && build.damaged()){ + heal.target = build; + heal.lastEnd.set(x * tilesize, y * tilesize); + return true; + } + return false; + }); } if(targetUnits){ //TODO does not support healing units manually yet