This commit is contained in:
MEEPofFaith 2025-12-02 21:42:50 +01:00 committed by GitHub
commit b36bf77075
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 67 additions and 13 deletions

View file

@ -2513,6 +2513,10 @@ public class Blocks{
ambientSoundVolume = 0.03f;
generateEffect = Fx.generatespark;
explosionShake = 1f;
explosionScorchSize = 1;
explosionIgnitionChance = 0.2f;
consume(new ConsumeItemFlammable());
consume(new ConsumeItemExplode());
@ -2542,6 +2546,10 @@ public class Blocks{
ambientSound = Sounds.smelter;
ambientSoundVolume = 0.06f;
explosionShake = 1f;
explosionScorchSize = 2;
explosionIgnitionChance = 0.2f;
consume(new ConsumeItemFlammable());
consume(new ConsumeItemExplode());
@ -2611,6 +2619,10 @@ public class Blocks{
powerProduction = 15f;
heating = 0.02f;
explosionShake = 4f;
explosionScorchSize = 8;
explosionIgnitionChance = 0.5f;
consumeItem(Items.thorium);
consumeLiquid(Liquids.cryofluid, heating / coolantPower).update(false);
}};

View file

@ -4,9 +4,11 @@ import arc.*;
import arc.audio.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.units.*;
@ -15,6 +17,7 @@ import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.draw.*;
import mindustry.world.meta.*;
@ -38,6 +41,15 @@ public class PowerGenerator extends PowerDistributor{
public float explosionMinWarmup = 0f;
public float explosionShake = 0f, explosionShakeDuration = 6f;
public boolean explosionBreaksProps = true;
/** Size of scorch effect on the ground after explosion. Value from 1-9. < 1 to disable. */
public int explosionScorchSize = 0;
/** Chance for each tile in the explosion radius to catch on fire. */
public float explosionIgnitionChance = 0f;
/** If true, the ignition chance decreases with distance. */
public boolean explosionScaleIgnitionChance = true;
/** The speed at which ignition spreads. */
public float explosionSpeed = 0.5f;
public PowerGenerator(String name){
super(name);
@ -120,10 +132,37 @@ public class PowerGenerator extends PowerDistributor{
public void createExplosion(){
if(shouldExplode()){
onExplosion();
}
}
public void onExplosion(){
if(explosionDamage > 0){
Damage.damage(x, y, explosionRadius * tilesize, explosionDamage);
}
if(explosionIgnitionChance > 0 || explosionBreaksProps){
Geometry.circle(tileX(), tileY(), explosionRadius, (tx, ty) -> {
Tile t = Vars.world.tile(tx, ty);
float dst = Mathf.dst(tileX(), tileY(), tx, ty);
//Create fires
if(explosionIgnitionChance > 0 &&
Mathf.chance(explosionIgnitionChance *
(explosionScaleIgnitionChance ? 1 - Mathf.sqrt(dst / explosionRadius) : 1))
){
Time.run(dst / explosionSpeed, () -> {
Fires.create(t);
});
}
//Break boulders
if(explosionBreaksProps && t != null && t.block().unitMoveBreakable){ //Probably a good enough indicator
ConstructBlock.deconstructFinish(t, t.block(), null);
}
});
}
explodeEffect.at(this);
explodeSound.at(this);
@ -138,6 +177,9 @@ public class PowerGenerator extends PowerDistributor{
if(explosionShake > 0){
Effect.shake(explosionShake, explosionShakeDuration, this);
}
if(explosionScorchSize > 0){
Effect.scorch(x, y, explosionScorchSize);
}
}