From 0d8c07d00769f694fcb8f8b4ab9d6b893884ce2b Mon Sep 17 00:00:00 2001 From: MEEPofFaith <54301439+MEEPofFaith@users.noreply.github.com> Date: Fri, 28 Jul 2023 20:55:20 -0700 Subject: [PATCH] Bullet despawn unit shenanigans (#8859) * Proper despawn unit direction * Despawn unit chance * Merge if statements --- core/src/mindustry/entities/bullet/BulletType.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index 2e91d5f421..300e6f9209 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -194,10 +194,14 @@ public class BulletType extends Content implements Cloneable{ public @Nullable UnitType spawnUnit; /** Unit spawned when this bullet hits something or despawns due to it hitting the end of its lifetime. */ public @Nullable UnitType despawnUnit; + /** The chance for despawn units to spawn. */ + public float despawnUnitChance = 1; /** Amount of units spawned when this bullet despawns. */ public int despawnUnitCount = 1; /** Random offset distance from the original bullet despawn/hit coordinate. */ public float despawnUnitRadius = 0.1f; + /** If true, units spawned when this bullet despawns face away from the bullet instead of the same direction as the bullet. */ + public boolean faceOutwards = false; /** Extra visual parts for this bullet. */ public Seq parts = new Seq<>(); @@ -489,9 +493,11 @@ public class BulletType extends Content implements Cloneable{ } public void createUnits(Bullet b, float x, float y){ - if(despawnUnit != null){ + if(despawnUnit != null && Mathf.chance(despawnUnitChance)){ for(int i = 0; i < despawnUnitCount; i++){ - despawnUnit.spawn(b.team, x + Mathf.range(despawnUnitRadius), y + Mathf.range(despawnUnitRadius)); + Tmp.v1.rnd(Mathf.random(despawnUnitRadius)); + var u = despawnUnit.spawn(b.team, x + Tmp.v1.x, y + Tmp.v1.y); + u.rotation = faceOutwards ? Tmp.v1.angle() : b.rotation(); } } }