WIP Disrupt missiles

This commit is contained in:
Anuken
2022-02-04 15:37:51 -05:00
parent 4c9761eae5
commit 60621520ee
22 changed files with 188 additions and 143 deletions

View File

@@ -387,11 +387,17 @@ public class Damage{
/** Damages all entities and blocks in a radius that are enemies of the team. */
public static void damage(Team team, float x, float y, float radius, float damage, boolean complete, boolean air, boolean ground){
damage(team, x, y, radius, damage, complete, air, ground, false);
}
/** Damages all entities and blocks in a radius that are enemies of the team. */
public static void damage(Team team, float x, float y, float radius, float damage, boolean complete, boolean air, boolean ground, boolean scaled){
Cons<Unit> cons = entity -> {
if(entity.team == team || !entity.within(x, y, radius) || (entity.isFlying() && !air) || (entity.isGrounded() && !ground)){
if(entity.team == team || !entity.within(x, y, radius + (scaled ? entity.hitSize / 2f : 0f)) || (entity.isFlying() && !air) || (entity.isGrounded() && !ground)){
return;
}
float amount = calculateDamage(x, y, entity.getX(), entity.getY(), radius, damage);
float amount = calculateDamage(scaled ? Math.max(0, entity.dst(x, y) - entity.type.hitSize/2) : entity.dst(x, y), radius, damage);
entity.damage(amount);
//TODO better velocity displacement
float dst = tr.set(entity.getX() - x, entity.getY() - y).len();
@@ -504,8 +510,7 @@ public class Damage{
}
}
private static float calculateDamage(float x, float y, float tx, float ty, float radius, float damage){
float dist = Mathf.dst(x, y, tx, ty);
private static float calculateDamage(float dist, float radius, float damage){
float falloff = 0.4f;
float scaled = Mathf.lerp(1f - dist / radius, 1f, falloff);
return damage * scaled;

View File

@@ -80,6 +80,8 @@ public class BulletType extends Content implements Cloneable{
public boolean instantDisappear;
/** Damage dealt in splash. 0 to disable.*/
public float splashDamage = 0f;
/** If true, splash damage is "correctly" affected by unit hitbox size. Used for projectiles that do not collide / have splash as their main source of damage. */
public boolean scaledSplashDamage = false;
/** Knockback in velocity. */
public float knockback;
/** Should knockback follow the bullet's direction */
@@ -142,6 +144,7 @@ public class BulletType extends Content implements Cloneable{
public @Nullable BulletType fragBullet = null;
public Color hitColor = Color.white;
public Color healColor = Pal.heal;
public Effect healEffect = Fx.healBlockFull;
/** Bullets spawned when this bullet is created. Rarely necessary, used for visuals. */
public Seq<BulletType> spawnBullets = new Seq<>();
@@ -249,7 +252,7 @@ public class BulletType extends Content implements Cloneable{
}
if(heals()&& build.team == b.team && !(build.block instanceof ConstructBlock)){
Fx.healBlockFull.at(build.x, build.y, build.block.size, healColor);
healEffect.at(build.x, build.y, build.block.size, healColor);
build.heal(healPercent / 100f * build.maxHealth + healAmount);
}else if(build.team != b.team && direct){
hit(b);
@@ -308,7 +311,7 @@ public class BulletType extends Content implements Cloneable{
}
if(splashDamageRadius > 0 && !b.absorbed){
Damage.damage(b.team, x, y, splashDamageRadius, splashDamage * b.damageMultiplier(), collidesAir, collidesGround);
Damage.damage(b.team, x, y, splashDamageRadius, splashDamage * b.damageMultiplier(), false, collidesAir, collidesGround, scaledSplashDamage);
if(status != StatusEffects.none){
Damage.status(b.team, x, y, splashDamageRadius, status, statusDuration, collidesAir, collidesGround);
@@ -316,7 +319,7 @@ public class BulletType extends Content implements Cloneable{
if(heals()){
indexer.eachBlock(b.team, x, y, splashDamageRadius, Building::damaged, other -> {
Fx.healBlockFull.at(other.x, other.y, other.block.size, healColor);
healEffect.at(other.x, other.y, other.block.size, healColor);
other.heal(healPercent / 100f * other.maxHealth() + healAmount);
});
}
@@ -375,7 +378,7 @@ public class BulletType extends Content implements Cloneable{
}
if(instantDisappear){
b.time = lifetime;
b.time = lifetime + 1f;
}
if(spawnBullets.size > 0){

View File

@@ -0,0 +1,28 @@
package mindustry.entities.bullet;
import mindustry.content.*;
public class ExplosionBulletType extends BulletType{
public ExplosionBulletType(float splashDamage, float splashDamageRadius){
this.splashDamage = splashDamage;
this.splashDamageRadius = splashDamageRadius;
rangeOverride = Math.max(rangeOverride, splashDamageRadius * 2f / 3f);
}
public ExplosionBulletType(){
}
{
hittable = false;
lifetime = 1f;
speed = 0f;
rangeOverride = 20f;
shootEffect = Fx.massiveExplosion;
instantDisappear = true;
scaledSplashDamage = true;
killShooter = true;
collides = false;
keepVelocity = false;
}
}

View File

@@ -513,7 +513,9 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
float shake = hitSize / 3f;
Effect.scorch(x, y, (int)(hitSize / 5));
if(type.createScorch){
Effect.scorch(x, y, (int)(hitSize / 5));
}
Effect.shake(shake, shake, this);
type.deathSound.at(this);
@@ -536,7 +538,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
Damage.damage(team, x, y, Mathf.pow(hitSize, 0.94f) * 1.25f, Mathf.pow(hitSize, 0.75f) * type.crashDamageMultiplier * 5f, true, false, true);
}
if(!headless){
if(!headless && type.createScorch){
for(int i = 0; i < type.wreckRegions.length; i++){
if(type.wreckRegions[i].found()){
float range = type.hitSize /4f;

View File

@@ -4,7 +4,7 @@ import arc.graphics.g2d.*;
import arc.math.*;
import arc.struct.*;
public abstract class WeaponPart{
public abstract class DrawPart{
public static final PartParams params = new PartParams();
/** If true, turret shading is used. Don't touch this, it is set up in unit/block init()! */
@@ -37,11 +37,14 @@ public abstract class WeaponPart{
}
public interface PartProgress{
/** Reload of the weapon - 1 right after shooting, 0 when ready to fire*/
PartProgress
reload = p -> p.reload,
/** Reload, but smoothed out, so there is no sudden jump between 0-1. */
smoothReload = p -> p.smoothReload,
/** Weapon warmup, 0 when not firing, 1 when actively shooting. Not equivalent to heat. */
warmup = p -> p.warmup,
/** Weapon heat, 1 when just fired, 0, when it has cooled down (duration depends on weapon) */
heat = p -> p.heat;
float get(PartParams p);
@@ -74,6 +77,10 @@ public abstract class WeaponPart{
return p -> get(p) * other.get(p);
}
default PartProgress mul(float amount){
return p -> get(p) * amount;
}
default PartProgress min(PartProgress other){
return p -> Math.min(get(p), other.get(p));
}

View File

@@ -8,10 +8,13 @@ import arc.struct.*;
import arc.util.*;
import mindustry.graphics.*;
public class RegionPart extends WeaponPart{
public class RegionPart extends DrawPart{
protected PartParams childParam = new PartParams();
/** Appended to unit/weapon/block name and drawn. */
public String suffix = "";
/** Overrides suffix if set. */
public @Nullable String name;
public TextureRegion heat;
public TextureRegion[] regions = {};
public TextureRegion[] outlines = {};
@@ -34,12 +37,19 @@ public class RegionPart extends WeaponPart{
public float x, y, moveX, moveY;
public @Nullable Color color, colorTo;
public Color heatColor = Pal.turretHeat.cpy();
public Seq<WeaponPart> children = new Seq<>();
public Seq<DrawPart> children = new Seq<>();
public RegionPart(String region){
this.suffix = region;
}
public RegionPart(String region, Blending blending, Color color){
this.suffix = region;
this.blending = blending;
this.color = color;
outline = false;
}
public RegionPart(){
}
@@ -119,25 +129,27 @@ public class RegionPart extends WeaponPart{
@Override
public void load(String name){
String realName = this.name == null ? name + suffix : this.name;
if(drawRegion){
//TODO l/r
if(mirror && turretShading){
regions = new TextureRegion[]{
Core.atlas.find(name + suffix + "1"),
Core.atlas.find(name + suffix + "2")
Core.atlas.find(realName + "1"),
Core.atlas.find(realName + "2")
};
outlines = new TextureRegion[]{
Core.atlas.find(name + suffix + "1-outline"),
Core.atlas.find(name + suffix + "2-outline")
Core.atlas.find(realName + "1-outline"),
Core.atlas.find(realName + "2-outline")
};
}else{
regions = new TextureRegion[]{Core.atlas.find(name + suffix)};
outlines = new TextureRegion[]{Core.atlas.find(name + suffix + "-outline")};
regions = new TextureRegion[]{Core.atlas.find(realName)};
outlines = new TextureRegion[]{Core.atlas.find(realName + "-outline")};
}
}
heat = Core.atlas.find(name + suffix + "-heat");
heat = Core.atlas.find(realName + "-heat");
for(var child : children){
child.load(name);
}

View File

@@ -1,36 +0,0 @@
package mindustry.entities.units;
import arc.graphics.*;
import arc.graphics.g2d.*;
import mindustry.graphics.*;
/** A sprite drawn in addition to the base unit sprites. */
public class UnitDecal{
public String region = "error";
public float x, y, rotation;
public float layer = Layer.flyingUnit + 1f;
public float xScale = 1f, yScale = 1f;
public Blending blending = Blending.normal;
public Color color = Color.white;
public TextureRegion loadedRegion;
public UnitDecal(String region, float x, float y, float rotation, float layer, Color color){
this.region = region;
this.x = x;
this.y = y;
this.rotation = rotation;
this.layer = layer;
this.color = color;
}
public UnitDecal(String region, Color color, Blending blending, float layer){
this.region = region;
this.color = color;
this.layer = layer;
this.blending = blending;
}
public UnitDecal(){
}
}