From e28d7b8d8d16a02f4fa4e01eb52cb62c00549719 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Aug 2022 13:13:37 -0400 Subject: [PATCH] Generator explosion system cleanup --- core/src/mindustry/ai/BaseRegistry.java | 4 +- core/src/mindustry/content/Blocks.java | 13 ++--- core/src/mindustry/content/Liquids.java | 1 + .../mindustry/entities/comp/PuddleComp.java | 2 +- core/src/mindustry/type/Liquid.java | 2 + .../world/blocks/power/ConsumeGenerator.java | 10 ++++ .../world/blocks/power/ImpactReactor.java | 29 ++++------- .../world/blocks/power/NuclearReactor.java | 33 ++++++------- .../world/blocks/power/PowerGenerator.java | 49 +++++++++++++++++++ .../world/blocks/power/VariableReactor.java | 42 +++++----------- 10 files changed, 103 insertions(+), 82 deletions(-) diff --git a/core/src/mindustry/ai/BaseRegistry.java b/core/src/mindustry/ai/BaseRegistry.java index 735e9162ef..d37f7b8826 100644 --- a/core/src/mindustry/ai/BaseRegistry.java +++ b/core/src/mindustry/ai/BaseRegistry.java @@ -39,8 +39,8 @@ public class BaseRegistry{ //load ore types and corresponding items for(Block block : content.blocks()){ - if(block instanceof OreBlock && block.asFloor().itemDrop != null){ - ores.put(block.asFloor().itemDrop, (OreBlock)block); + if(block instanceof OreBlock ore && ore.itemDrop != null && !ore.wallOre && !ores.containsKey(ore.itemDrop)){ + ores.put(ore.itemDrop, ore); }else if(block.isFloor() && block.asFloor().itemDrop != null && !oreFloors.containsKey(block.asFloor().itemDrop)){ oreFloors.put(block.asFloor().itemDrop, block.asFloor()); } diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index cdb1cf9817..7dfa38d5a6 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -127,7 +127,7 @@ public class Blocks{ cliffCrusher, plasmaBore, largePlasmaBore, impactDrill, eruptionDrill, //storage - coreShard, coreFoundation, /*TODO core foundation is a bad name, rename to fragment */ coreNucleus, vault, container, unloader, + coreShard, coreFoundation, coreNucleus, vault, container, unloader, //storage - erekir coreBastion, coreCitadel, coreAcropolis, reinforcedContainer, reinforcedVault, @@ -162,7 +162,6 @@ public class Blocks{ worldProcessor, worldCell, //campaign - //TODO launch pad on erekir, 5x5, uses nuclear(?) fuel launchPad, interplanetaryAccelerator ; @@ -1161,7 +1160,6 @@ public class Blocks{ consumePower(6f); }}; - //TODO better name electrolyzer = new GenericCrafter("electrolyzer"){{ requirements(Category.crafting, with(Items.silicon, 50, Items.graphite, 40, Items.beryllium, 130, Items.tungsten, 80)); size = 3; @@ -1222,7 +1220,6 @@ public class Blocks{ heatRequirement = 6f; - //TODO continuous output outputLiquid = new LiquidStack(Liquids.nitrogen, 4f / 60f); }}; @@ -1380,10 +1377,9 @@ public class Blocks{ }}); consumeItem(Items.silicon, 3); - //TODO must consume from 2 pumps, 1, or 1.5? //TODO consume hydrogen/ozone? consumeLiquid(Liquids.slag, 40f / 60f); - consumePower(2f); //TODO necessary? + consumePower(2f); }}; cyanogenSynthesizer = new HeatCrafter("cyanogen-synthesizer"){{ @@ -1415,7 +1411,6 @@ public class Blocks{ consumePower(2f); }}; - //TODO bad name, and there's no use for phase yet... phaseSynthesizer = new HeatCrafter("phase-synthesizer"){{ requirements(Category.crafting, with(Items.carbide, 90, Items.silicon, 100, Items.thorium, 100, Items.tungsten, 200)); @@ -1512,7 +1507,6 @@ public class Blocks{ envDisabled |= Env.scorching; }}; - //TODO all these should be hidden from view completely thoriumWall = new Wall("thorium-wall"){{ requirements(Category.defense, with(Items.thorium, 6)); health = 200 * wallHealthMultiplier; @@ -2492,7 +2486,6 @@ public class Blocks{ color = Pal.slagOrange; }}); - //TODO ratios, extra requirements? consumeLiquids(LiquidStack.with(Liquids.slag, 20f / 60f, Liquids.arkycite, 30f / 60f)); size = 3; @@ -2509,7 +2502,7 @@ public class Blocks{ //TODO still very much WIP, stats are bad fluxReactor = new VariableReactor("flux-reactor"){{ requirements(Category.power, with(Items.graphite, 300, Items.carbide, 200, Items.oxide, 100, Items.silicon, 600, Items.surgeAlloy, 300)); - powerProduction = 140f; + powerProduction = 120f; maxHeat = 150f; consumeLiquid(Liquids.cyanogen, 9f / 60f); diff --git a/core/src/mindustry/content/Liquids.java b/core/src/mindustry/content/Liquids.java index 347408fb34..90c194294a 100644 --- a/core/src/mindustry/content/Liquids.java +++ b/core/src/mindustry/content/Liquids.java @@ -52,6 +52,7 @@ public class Liquids{ capPuddles = false; hidden = true; spreadTarget = Liquids.water; + moveThroughBlocks = true; colorFrom = Color.valueOf("e8803f"); colorTo = Color.valueOf("8c1225"); diff --git a/core/src/mindustry/entities/comp/PuddleComp.java b/core/src/mindustry/entities/comp/PuddleComp.java index 100298828d..a9c154088b 100644 --- a/core/src/mindustry/entities/comp/PuddleComp.java +++ b/core/src/mindustry/entities/comp/PuddleComp.java @@ -61,7 +61,7 @@ abstract class PuddleComp implements Posc, Puddlec, Drawc{ int targets = 0; for(Point2 point : Geometry.d4){ Tile other = world.tile(tile.x + point.x, tile.y + point.y); - if(other != null && other.block() == Blocks.air){ + if(other != null && (other.block() == Blocks.air || liquid.moveThroughBlocks)){ targets ++; Puddles.deposit(other, tile, liquid, deposited, false); } diff --git a/core/src/mindustry/type/Liquid.java b/core/src/mindustry/type/Liquid.java index 306f663420..b76a595dda 100644 --- a/core/src/mindustry/type/Liquid.java +++ b/core/src/mindustry/type/Liquid.java @@ -45,6 +45,8 @@ public class Liquid extends UnlockableContent implements Senseable{ public float explosiveness; /** if false, this liquid cannot be a coolant */ public boolean coolant = true; + /** if true, this liquid can move through blocks as a puddle. */ + public boolean moveThroughBlocks = false; /** The associated status effect. */ public StatusEffect effect = StatusEffects.none; /** Effect shown in puddles. */ diff --git a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java index 64359882cd..e4757fdec2 100644 --- a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java +++ b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java @@ -21,6 +21,8 @@ public class ConsumeGenerator extends PowerGenerator{ public float generateEffectRange = 3f; public @Nullable LiquidStack outputLiquid; + /** If true, this block explodes when outputLiquid exceeds capacity. */ + public boolean explodeOnFull = false; public @Nullable ConsumeItemFilter filterItem; public @Nullable ConsumeLiquidFilter filterLiquid; @@ -48,6 +50,10 @@ public class ConsumeGenerator extends PowerGenerator{ hasLiquids = true; } + if(explodeOnFull && outputLiquid != null && explosionPuddleLiquid == null){ + explosionPuddleLiquid = outputLiquid.liquid; + } + //TODO hardcoded emitLight = true; lightRadius = 65f * size; @@ -106,6 +112,10 @@ public class ConsumeGenerator extends PowerGenerator{ float added = Math.min(productionEfficiency * delta() * outputLiquid.amount, liquidCapacity - liquids.get(outputLiquid.liquid)); liquids.add(outputLiquid.liquid, added); dumpLiquid(outputLiquid.liquid); + + if(explodeOnFull && liquids.get(outputLiquid.liquid) >= liquidCapacity - 0.0001f){ + kill(); + } } //generation time always goes down, but only at the end so consumeTriggerValid doesn't assume fake items diff --git a/core/src/mindustry/world/blocks/power/ImpactReactor.java b/core/src/mindustry/world/blocks/power/ImpactReactor.java index 30b988e97b..a39216cf95 100644 --- a/core/src/mindustry/world/blocks/power/ImpactReactor.java +++ b/core/src/mindustry/world/blocks/power/ImpactReactor.java @@ -1,13 +1,11 @@ package mindustry.world.blocks.power; import arc.*; -import arc.audio.*; import arc.math.*; import arc.struct.*; import arc.util.*; import arc.util.io.*; import mindustry.content.*; -import mindustry.entities.*; import mindustry.game.EventType.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -16,17 +14,10 @@ import mindustry.ui.*; import mindustry.world.draw.*; import mindustry.world.meta.*; -import static mindustry.Vars.*; - public class ImpactReactor extends PowerGenerator{ public final int timerUse = timers++; - public float warmupSpeed = 0.001f; public float itemDuration = 60f; - public int explosionRadius = 23; - public int explosionDamage = 1900; - public Effect explodeEffect = Fx.impactReactorExplosion; - public Sound explodeSound = Sounds.explosionbig; public ImpactReactor(String name){ super(name); @@ -41,6 +32,12 @@ public class ImpactReactor extends PowerGenerator{ envEnabled = Env.any; drawer = new DrawMulti(new DrawRegion("-bottom"), new DrawPlasma(), new DrawDefault()); + + explosionShake = 6f; + explosionShakeDuration = 16f; + explosionDamage = 1900 * 4; + explodeEffect = Fx.impactReactorExplosion; + explodeSound = Sounds.explosionbig; } @Override @@ -114,16 +111,10 @@ public class ImpactReactor extends PowerGenerator{ } @Override - public void onDestroyed(){ - super.onDestroyed(); - - if(warmup < 0.3f || !state.rules.reactorExplosions) return; - - Damage.damage(x, y, explosionRadius * tilesize, explosionDamage * 4); - - Effect.shake(6f, 16f, x, y); - explodeEffect.at(this); - explodeSound.at(this); + public void createExplosion(){ + if(warmup >= 0.3f){ + super.createExplosion(); + } } @Override diff --git a/core/src/mindustry/world/blocks/power/NuclearReactor.java b/core/src/mindustry/world/blocks/power/NuclearReactor.java index bcc3d104b1..3b3757dcae 100644 --- a/core/src/mindustry/world/blocks/power/NuclearReactor.java +++ b/core/src/mindustry/world/blocks/power/NuclearReactor.java @@ -1,7 +1,6 @@ package mindustry.world.blocks.power; import arc.*; -import arc.audio.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; @@ -10,7 +9,6 @@ import arc.util.*; import arc.util.io.*; import mindustry.annotations.Annotations.*; import mindustry.content.*; -import mindustry.entities.*; import mindustry.game.EventType.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -27,8 +25,6 @@ public class NuclearReactor extends PowerGenerator{ public Color lightColor = Color.valueOf("7f19ea"); public Color coolColor = new Color(1, 1, 1, 0f); public Color hotColor = Color.valueOf("ff9575a3"); - public Effect explodeEffect = Fx.reactorExplosion; - public Sound explodeSound = Sounds.explosionbig; /** ticks to consume 1 fuel */ public float itemDuration = 120; /** heating per frame * fullness */ @@ -37,8 +33,7 @@ public class NuclearReactor extends PowerGenerator{ public float smokeThreshold = 0.3f; /** heat threshold at which lights start flashing */ public float flashThreshold = 0.46f; - public int explosionRadius = 19; - public int explosionDamage = 1250; + /** heat removed per unit of coolant */ public float coolantPower = 0.5f; public float smoothLight; @@ -58,6 +53,15 @@ public class NuclearReactor extends PowerGenerator{ flags = EnumSet.of(BlockFlag.reactor, BlockFlag.generator); schematicPriority = -5; envEnabled = Env.any; + + explosionShake = 6f; + explosionShakeDuration = 16f; + + explosionRadius = 19; + explosionDamage = 1250 * 4; + + explodeEffect = Fx.reactorExplosion; + explodeSound = Sounds.explosionbig; } @Override @@ -124,19 +128,10 @@ public class NuclearReactor extends PowerGenerator{ } @Override - public void onDestroyed(){ - super.onDestroyed(); - - int fuel = items.get(fuelItem); - - if((fuel < 5 && heat < 0.5f) || !state.rules.reactorExplosions) return; - - Effect.shake(6f, 16f, x, y); - // * ((float)fuel / itemCapacity) to scale based on fullness - Damage.damage(x, y, explosionRadius * tilesize, explosionDamage * 4); - - explodeEffect.at(this); - explodeSound.at(this); + public void createExplosion(){ + if(items.get(fuelItem) >= 5 && heat >= 0.5f){ + super.createExplosion(); + } } @Override diff --git a/core/src/mindustry/world/blocks/power/PowerGenerator.java b/core/src/mindustry/world/blocks/power/PowerGenerator.java index c3da8f2d85..9500de8030 100644 --- a/core/src/mindustry/world/blocks/power/PowerGenerator.java +++ b/core/src/mindustry/world/blocks/power/PowerGenerator.java @@ -1,24 +1,43 @@ package mindustry.world.blocks.power; import arc.*; +import arc.audio.*; import arc.graphics.g2d.*; import arc.math.*; import arc.struct.*; import arc.util.*; import arc.util.io.*; +import mindustry.content.*; +import mindustry.entities.*; import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.graphics.*; +import mindustry.type.*; import mindustry.ui.*; +import mindustry.world.*; import mindustry.world.draw.*; import mindustry.world.meta.*; +import static mindustry.Vars.*; + public class PowerGenerator extends PowerDistributor{ /** The amount of power produced per tick in case of an efficiency of 1.0, which represents 100%. */ public float powerProduction; public Stat generationType = Stat.basePowerGeneration; public DrawBlock drawer = new DrawDefault(); + public int explosionRadius = 12; + public int explosionDamage = 0; + public Effect explodeEffect = Fx.none; + public Sound explodeSound = Sounds.none; + + public int explosionPuddles = 10; + public float explosionPuddleRange = tilesize * 2f; + public float explosionPuddleAmount = 100f; + public @Nullable Liquid explosionPuddleLiquid; + + public float explosionShake = 0f, explosionShakeDuration = 6f; + public PowerGenerator(String name){ super(name); sync = true; @@ -81,6 +100,36 @@ public class PowerGenerator extends PowerDistributor{ return productionEfficiency; } + @Override + public void onDestroyed(){ + super.onDestroyed(); + + if(state.rules.reactorExplosions){ + createExplosion(); + } + } + + public void createExplosion(){ + if(explosionDamage > 0){ + Damage.damage(x, y, explosionRadius * tilesize, explosionDamage); + } + + explodeEffect.at(this); + explodeSound.at(this); + + if(explosionPuddleLiquid != null){ + for(int i = 0; i < explosionPuddles; i++){ + Tmp.v1.trns(Mathf.random(360f), Mathf.random(explosionPuddleRange)); + Tile tile = world.tileWorld(x + Tmp.v1.x, y + Tmp.v1.y); + Puddles.deposit(tile, explosionPuddleLiquid, explosionPuddleAmount); + } + } + + if(explosionShake > 0){ + Effect.shake(explosionShake, explosionShakeDuration, this); + } + } + @Override public void drawLight(){ super.drawLight(); diff --git a/core/src/mindustry/world/blocks/power/VariableReactor.java b/core/src/mindustry/world/blocks/power/VariableReactor.java index d834ad577f..038bb39a44 100644 --- a/core/src/mindustry/world/blocks/power/VariableReactor.java +++ b/core/src/mindustry/world/blocks/power/VariableReactor.java @@ -1,7 +1,6 @@ package mindustry.world.blocks.power; import arc.*; -import arc.audio.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; @@ -13,9 +12,7 @@ import mindustry.entities.*; import mindustry.entities.effect.*; import mindustry.gen.*; import mindustry.graphics.*; -import mindustry.type.*; import mindustry.ui.*; -import mindustry.world.*; import mindustry.world.blocks.heat.*; import static mindustry.Vars.*; @@ -32,22 +29,23 @@ public class VariableReactor extends PowerGenerator{ public float flashThreshold = 0.01f, flashAlpha = 0.4f, flashSpeed = 7f; public Color flashColor1 = Color.red, flashColor2 = Color.valueOf("89e8b6"); - public int explosionRadius = 12; - public int explosionDamage = 1000; - public Effect explodeEffect = new MultiEffect(Fx.bigShockwave, new WrapEffect(Fx.titanSmoke, Color.valueOf("e3ae6f"))); - public Sound explodeSound = Sounds.explosionbig; - - public int puddles = 70; - public float puddleRange = tilesize * 6f; - public Liquid puddleLiquid = Liquids.slag; - public float puddleAmount = 100f; - public @Load("@-lights") TextureRegion lightsRegion; public VariableReactor(String name){ super(name); powerProduction = 20f; rebuildable = false; + + + explosionRadius = 12; + explosionDamage = 1000; + explodeEffect = new MultiEffect(Fx.bigShockwave, new WrapEffect(Fx.titanSmoke, Color.valueOf("e3ae6f"))); + explodeSound = Sounds.explosionbig; + + explosionPuddles = 70; + explosionPuddleRange = tilesize * 6f; + explosionPuddleLiquid = Liquids.slag; + explosionPuddleAmount = 100f; } @Override @@ -86,24 +84,6 @@ public class VariableReactor extends PowerGenerator{ } } - @Override - public void onDestroyed(){ - super.onDestroyed(); - - if(!state.rules.reactorExplosions) return; - - Damage.damage(x, y, explosionRadius * tilesize, explosionDamage); - - explodeEffect.at(this); - explodeSound.at(this); - - for(int i = 0; i < puddles; i++){ - Tmp.v1.trns(Mathf.random(360f), Mathf.random(puddleRange)); - Tile tile = world.tileWorld(x + Tmp.v1.x, y + Tmp.v1.y); - Puddles.deposit(tile, puddleLiquid, puddleAmount); - } - } - @Override public void draw(){ super.draw();