From b3e7b9e65beaa3e917acf8748ce18c67fb847f6e Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 2 Sep 2020 14:30:56 -0400 Subject: [PATCH] Cleanup --- .../src/main/resources/revisions/Bullet/6.json | 1 + core/src/mindustry/content/Blocks.java | 1 + core/src/mindustry/entities/Damage.java | 18 ++++++++++++++++++ .../entities/bullet/LaserBulletType.java | 17 ++--------------- .../entities/bullet/ShrapnelBulletType.java | 8 +++++--- .../mindustry/entities/comp/BulletComp.java | 1 + 6 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 annotations/src/main/resources/revisions/Bullet/6.json diff --git a/annotations/src/main/resources/revisions/Bullet/6.json b/annotations/src/main/resources/revisions/Bullet/6.json new file mode 100644 index 0000000000..e5306515fc --- /dev/null +++ b/annotations/src/main/resources/revisions/Bullet/6.json @@ -0,0 +1 @@ +{version:6,fields:[{name:collided,type:arc.struct.IntSeq,size:-1},{name:damage,type:float,size:4},{name:data,type:java.lang.Object,size:-1},{name:fdata,type:float,size:4},{name:lifetime,type:float,size:4},{name:owner,type:mindustry.gen.Entityc,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:type,type:mindustry.entities.bullet.BulletType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} \ No newline at end of file diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 8719d6311d..7254bc0eb3 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1808,6 +1808,7 @@ public class Blocks implements ContentList{ upgrades = new UnitType[][]{ {UnitTypes.antumbra, UnitTypes.eclipse}, + {UnitTypes.arkyid, UnitTypes.toxopid}, }; }}; diff --git a/core/src/mindustry/entities/Damage.java b/core/src/mindustry/entities/Damage.java index b6a2a94440..5ff4bee8a6 100644 --- a/core/src/mindustry/entities/Damage.java +++ b/core/src/mindustry/entities/Damage.java @@ -20,6 +20,7 @@ import static mindustry.Vars.*; /** Utility class for damaging in an area. */ public class Damage{ + private static Tile furthest; private static Rect rect = new Rect(); private static Rect hitrect = new Rect(); private static Vec2 tr = new Vec2(); @@ -76,6 +77,23 @@ public class Damage{ } } + /** 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){ + Tmp.v1.trns(b.rotation(), length); + + furthest = null; + + 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.team() != b.team && furthest.block().absorbLasers); + + float resultLength = furthest != null ? Math.max(6f, b.dst(furthest.worldx(), furthest.worldy())) : length; + + Damage.collideLine(b, b.team, b.type.hitEffect, b.x, b.y, b.rotation(), resultLength); + b.fdata = furthest != null ? resultLength : length; + + return resultLength; + } + public static void collideLine(Bullet hitter, Team team, Effect effect, float x, float y, float angle, float length){ collideLine(hitter, team, effect, x, y, angle, length, false); } diff --git a/core/src/mindustry/entities/bullet/LaserBulletType.java b/core/src/mindustry/entities/bullet/LaserBulletType.java index 821129f51d..5fd96f6cc6 100644 --- a/core/src/mindustry/entities/bullet/LaserBulletType.java +++ b/core/src/mindustry/entities/bullet/LaserBulletType.java @@ -10,8 +10,6 @@ import mindustry.gen.*; import mindustry.graphics.*; import mindustry.world.*; -import static mindustry.Vars.world; - public class LaserBulletType extends BulletType{ protected static Tile furthest; @@ -49,24 +47,13 @@ public class LaserBulletType extends BulletType{ @Override public void init(Bullet b){ - Tmp.v1.trns(b.rotation(), length); - - furthest = null; - - 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.team() != b.team && furthest.block().absorbLasers); - - float resultLength = furthest != null ? Math.max(6f, b.dst(furthest.worldx(), furthest.worldy())) : length; - - Damage.collideLine(b, b.team, hitEffect, b.x, b.y, b.rotation(), resultLength); - if(furthest != null) b.data(resultLength); - + float resultLength = Damage.collideLaser(b, length); laserEffect.at(b.x, b.y, b.rotation(), resultLength * 0.75f); } @Override public void draw(Bullet b){ - float realLength = b.data() == null ? length : (Float)b.data(); + float realLength = b.fdata; float f = Mathf.curve(b.fin(), 0f, 0.2f); float baseLen = realLength * f; diff --git a/core/src/mindustry/entities/bullet/ShrapnelBulletType.java b/core/src/mindustry/entities/bullet/ShrapnelBulletType.java index 1bfa155d0b..3303f40fdb 100644 --- a/core/src/mindustry/entities/bullet/ShrapnelBulletType.java +++ b/core/src/mindustry/entities/bullet/ShrapnelBulletType.java @@ -29,19 +29,21 @@ public class ShrapnelBulletType extends BulletType{ @Override public void init(Bullet b){ - Damage.collideLine(b, b.team, hitEffect, b.x, b.y, b.rotation(), length); + Damage.collideLaser(b, length); } @Override public void draw(Bullet b){ + float realLength = b.fdata; + Draw.color(fromColor, toColor, b.fin()); - for(int i = 0; i < serrations; i++){ + for(int i = 0; i < (int)(serrations * realLength / length); i++){ Tmp.v1.trns(b.rotation(), i * serrationSpacing); float sl = Mathf.clamp(b.fout() - serrationFadeOffset) * (serrationSpaceOffset - i * serrationLenScl); Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, serrationWidth, sl, b.rotation() + 90); Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, serrationWidth, sl, b.rotation() - 90); } - Drawf.tri(b.x, b.y, width * b.fout(), (length + 50), b.rotation()); + Drawf.tri(b.x, b.y, width * b.fout(), (realLength + 50), b.rotation()); Drawf.tri(b.x, b.y, width * b.fout(), 10f, b.rotation() + 180f); Draw.reset(); } diff --git a/core/src/mindustry/entities/comp/BulletComp.java b/core/src/mindustry/entities/comp/BulletComp.java index c94216c923..107f1e00f1 100644 --- a/core/src/mindustry/entities/comp/BulletComp.java +++ b/core/src/mindustry/entities/comp/BulletComp.java @@ -25,6 +25,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw Object data; BulletType type; float damage; + float fdata; @Override public void getCollisions(Cons consumer){