Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anuken
2021-06-06 21:01:55 -04:00
6 changed files with 51 additions and 20 deletions

View File

@@ -31,11 +31,16 @@ public class Damage{
/** Creates a dynamic explosion based on specified parameters. */
public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, boolean damage){
dynamicExplosion(x, y, flammability, explosiveness, power, radius, damage, true, null);
dynamicExplosion(x, y, flammability, explosiveness, power, radius, damage, true, null, Fx.dynamicExplosion);
}
/** Creates a dynamic explosion based on specified parameters. */
public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, boolean damage, boolean fire, @Nullable Team ignoreTeam){
dynamicExplosion(x, y, flammability, explosiveness, power, radius, damage, fire, ignoreTeam, Fx.dynamicExplosion);
}
/** Creates a dynamic explosion based on specified parameters. */
public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, boolean damage, boolean fire, @Nullable Team ignoreTeam, Effect explosion){
if(damage){
for(int i = 0; i < Mathf.clamp(power / 700, 0, 8); i++){
int length = 5 + Mathf.clamp((int)(power / 500), 1, 20);
@@ -69,7 +74,7 @@ public class Damage{
float shake = Math.min(explosiveness / 4f + 3f, 9f);
Effect.shake(shake, shake, x, y);
Fx.dynamicExplosion.at(x, y, radius / 8f);
explosion.at(x, y, radius / 8f);
}
public static void createIncend(float x, float y, float range, int amount){

View File

@@ -450,7 +450,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
float power = item().charge * stack().amount * 150f;
if(!spawnedByCore){
Damage.dynamicExplosion(x, y, flammability, explosiveness, power, bounds() / 2f, state.rules.damageExplosions, item().flammability > 1, team);
Damage.dynamicExplosion(x, y, flammability, explosiveness, power, bounds() / 2f, state.rules.damageExplosions, item().flammability > 1, team, type.deathExplosionEffect);
}
float shake = hitSize / 3f;

View File

@@ -71,6 +71,7 @@ public class UnitType extends UnlockableContent{
public boolean omniMovement = true;
public Effect fallEffect = Fx.fallSmoke;
public Effect fallThrusterEffect = Fx.fallSmoke;
public Effect deathExplosionEffect = Fx.dynamicExplosion;
public Seq<Ability> abilities = new Seq<>();
public BlockFlag targetFlag = BlockFlag.generator;

View File

@@ -0,0 +1,20 @@
package mindustry.world.blocks.power;
import arc.func.*;
import mindustry.gen.*;
import mindustry.world.consumers.*;
/** A power consumer that uses a dynamic amount of power. */
public class DynamicConsumePower extends ConsumePower{
private final Floatf<Building> usage;
public DynamicConsumePower(Floatf<Building> usage){
super(0, 0, false);
this.usage = usage;
}
@Override
public float requestedPower(Building entity){
return usage.get(entity);
}
}

View File

@@ -68,6 +68,11 @@ public class Consumers{
return add(new ConditionalConsumePower(usage, (Boolf<Building>)cons));
}
/** Creates a consumer that consumes a dynamic amount of power. */
public <T extends Building> ConsumePower powerDynamic(Floatf<T> usage){
return add(new DynamicConsumePower((Floatf<Building>)usage));
}
/**
* Creates a consumer which stores power.
* @param powerCapacity The maximum capacity in power units.