From b7ac1e1d74e5e3ed900563b7adb51dd22d46da62 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 24 Nov 2021 13:33:01 -0500 Subject: [PATCH] Stuff. --- core/src/mindustry/content/Blocks.java | 1 + core/src/mindustry/entities/Damage.java | 33 ++++++++++++++++++- .../entities/bullet/ContinuousBulletType.java | 4 ++- .../bullet/ContinuousFlameBulletType.java | 4 +-- .../defense/turrets/ContinuousTurret.java | 1 + 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 272d766bfe..c76b8a6e5d 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -2730,6 +2730,7 @@ public class Blocks implements ContentList{ shootType = new ContinuousFlameBulletType(){{ damage = 4f; length = range; + //pierceMax = 3; }}; shootLength = 7f; size = 3; diff --git a/core/src/mindustry/entities/Damage.java b/core/src/mindustry/entities/Damage.java index 52a2f0d6c7..f4e792a960 100644 --- a/core/src/mindustry/entities/Damage.java +++ b/core/src/mindustry/entities/Damage.java @@ -24,6 +24,7 @@ public class Damage{ private static Rect hitrect = new Rect(); private static Vec2 tr = new Vec2(), seg1 = new Vec2(), seg2 = new Vec2(); private static Seq units = new Seq<>(); + private static int pierceCount = 0; private static IntSet collidedBlocks = new IntSet(); private static Building tmpBuilding; private static Unit tmpUnit; @@ -113,6 +114,18 @@ public class Damage{ return found && furthest != null ? Math.max(6f, b.dst(furthest.worldx(), furthest.worldy())) : length; } + public static float findPierceLength(Bullet b, int pierceCap, float length){ + Tmp.v1.trnsExact(b.rotation(), length); + + furthest = null; + pierceCount = 0; + + boolean found = world.raycast(b.tileX(), b.tileY(), World.toTile(b.x + Tmp.v1.x), World.toTile(b.y + Tmp.v1.y), + (x, y) -> (furthest = world.tile(x, y)) != null && furthest.build != null && furthest.team() != b.team && ++pierceCount >= pierceCap); + + return found && furthest != null ? Math.max(6f, b.dst(furthest.worldx(), furthest.worldy())) : length; + } + /** Collides a bullet with blocks in a laser, taking into account absorption blocks. Resulting length is stored in the bullet's fdata. */ public static float collideLaser(Bullet b, float length, boolean large){ float resultLength = findLaserLength(b, length); @@ -141,7 +154,20 @@ public class Damage{ * Only enemies of the specified team are damaged. */ public static void collideLine(Bullet hitter, Team team, Effect effect, float x, float y, float angle, float length, boolean large, boolean laser){ - if(laser) length = findLaserLength(hitter, length); + collideLine(hitter, team, effect, x, y, angle, length, large, laser, -1); + } + + /** + * Damages entities in a line. + * Only enemies of the specified team are damaged. + */ + public static void collideLine(Bullet hitter, Team team, Effect effect, float x, float y, float angle, float length, boolean large, boolean laser, int pierceCap){ + pierceCount = 0; + if(laser){ + length = findLaserLength(hitter, length); + }else if(pierceCap > 0){ + length = findPierceLength(hitter, pierceCap, length); + } collidedBlocks.clear(); tr.trnsExact(angle, length); @@ -202,6 +228,9 @@ public class Damage{ rect.height += expand * 2; Cons cons = e -> { + //the peirce cap works for units, but really terribly, I'm just disabling it for now. + //if(pierceCap > 0 && pierceCount > pierceCap) return; + e.hitbox(hitrect); Vec2 vec = Geometry.raycastRect(x, y, x2, y2, hitrect.grow(expand * 2)); @@ -210,6 +239,8 @@ public class Damage{ effect.at(vec.x, vec.y); e.collision(hitter, vec.x, vec.y); hitter.collision(e, vec.x, vec.y); + + pierceCount ++; } }; diff --git a/core/src/mindustry/entities/bullet/ContinuousBulletType.java b/core/src/mindustry/entities/bullet/ContinuousBulletType.java index a2624e7475..91b3e69905 100644 --- a/core/src/mindustry/entities/bullet/ContinuousBulletType.java +++ b/core/src/mindustry/entities/bullet/ContinuousBulletType.java @@ -11,6 +11,8 @@ public class ContinuousBulletType extends BulletType{ public float damageInterval = 5f; public boolean largeHit = false; public boolean laserAbsorb = true; + /** can't use pierceCap here for... many reasons. DO NOT USE, BUGGY */ + public int pierceMax = -1; { speed = 0f; @@ -54,7 +56,7 @@ public class ContinuousBulletType extends BulletType{ //damage every 5 ticks if(b.timer(1, damageInterval)){ - Damage.collideLine(b, b.team, hitEffect, b.x, b.y, b.rotation(), currentLength(b), largeHit, laserAbsorb); + Damage.collideLine(b, b.team, hitEffect, b.x, b.y, b.rotation(), currentLength(b), largeHit, laserAbsorb, pierceMax); } if(shake > 0){ diff --git a/core/src/mindustry/entities/bullet/ContinuousFlameBulletType.java b/core/src/mindustry/entities/bullet/ContinuousFlameBulletType.java index 248c6a26a6..5a7f41b84e 100644 --- a/core/src/mindustry/entities/bullet/ContinuousFlameBulletType.java +++ b/core/src/mindustry/entities/bullet/ContinuousFlameBulletType.java @@ -5,6 +5,7 @@ import arc.graphics.g2d.*; import arc.math.*; import arc.util.*; import mindustry.content.*; +import mindustry.entities.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -47,14 +48,13 @@ public class ContinuousFlameBulletType extends ContinuousBulletType{ lifetime = 16f; hitColor = colors[1].cpy().a(1f); lightColor = hitColor; - //TODO what if, instead of piercing, it stopped at the first target regardless? or maybe 2? laserAbsorb = false; } @Override public void draw(Bullet b){ float mult = b.fslope(); - float realLength = length * mult; + float realLength = (pierceMax <= 0 ? length : Damage.findPierceLength(b, pierceMax, length)) * mult; float sin = Mathf.sin(Time.time, oscScl, oscMag); diff --git a/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java b/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java index 0bab669759..684fb0d5f3 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java @@ -42,6 +42,7 @@ public class ContinuousTurret extends Turret{ @Override public boolean hasAmmo(){ + //TODO update ammo in unit so it corresponds to liquids return cons.canConsume(); }