diff --git a/core/assets-raw/sprites/blocks/power/pyrolysis-generator-bottom.png b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-bottom.png new file mode 100644 index 0000000000..4f4b6a2b8f Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-bottom.png differ diff --git a/core/assets-raw/sprites/blocks/power/pyrolysis-generator-glow.png b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-glow.png new file mode 100644 index 0000000000..f49f17b58e Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-glow.png differ diff --git a/core/assets-raw/sprites/blocks/power/pyrolysis-generator-mid.png b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-mid.png new file mode 100644 index 0000000000..828dec466d Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-mid.png differ diff --git a/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston-t.png b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston-t.png new file mode 100644 index 0000000000..ec2c057559 Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston-t.png differ diff --git a/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston.png b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston.png new file mode 100644 index 0000000000..79f0f31908 Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston.png differ diff --git a/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston1.png b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston1.png new file mode 100644 index 0000000000..f1b62ced4a Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/pyrolysis-generator-piston1.png differ diff --git a/core/assets-raw/sprites/blocks/power/pyrolysis-generator.png b/core/assets-raw/sprites/blocks/power/pyrolysis-generator.png new file mode 100644 index 0000000000..356a2f0fb6 Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/pyrolysis-generator.png differ diff --git a/core/assets/icons/icons.properties b/core/assets/icons/icons.properties index c9171b1526..58f2e2dcf2 100755 --- a/core/assets/icons/icons.properties +++ b/core/assets/icons/icons.properties @@ -470,3 +470,4 @@ 63236=chemical-combustion-chamber|block-chemical-combustion-chamber-ui 63235=arkyic-stone|block-arkyic-stone-ui 63234=yellow-stone-boulder|block-yellow-stone-boulder-ui +63233=pyrolysis-generator|block-pyrolysis-generator-ui diff --git a/core/assets/logicids.dat b/core/assets/logicids.dat index 44fd6af049..00ce8adfa6 100644 Binary files a/core/assets/logicids.dat and b/core/assets/logicids.dat differ diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 7874ee6b67..2c2eee028b 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1769,14 +1769,14 @@ public class Blocks{ //TODO is this necessary? junctions are not good design //TODO make it leak reinforcedLiquidJunction = new LiquidJunction("reinforced-liquid-junction"){{ - requirements(Category.liquid, with(Items.tungsten, 4, Items.beryllium, 8)); + requirements(Category.liquid, with(Items.graphite, 4, Items.beryllium, 8)); buildCostMultiplier = 3f; health = 260; ((Conduit)reinforcedConduit).junctionReplacement = this; }}; reinforcedBridgeConduit = new DirectionLiquidBridge("reinforced-bridge-conduit"){{ - requirements(Category.liquid, with(Items.tungsten, 6, Items.beryllium, 10)); + requirements(Category.liquid, with(Items.graphite, 6, Items.beryllium, 10)); range = 4; hasPower = false; @@ -1897,7 +1897,7 @@ public class Blocks{ ambientSoundVolume = 0.06f; }}; - differentialGenerator = new SingleTypeGenerator("differential-generator"){{ + differentialGenerator = new ConsumeGenerator("differential-generator"){{ requirements(Category.power, with(Items.copper, 70, Items.titanium, 50, Items.lead, 100, Items.silicon, 65, Items.metaglass, 50)); powerProduction = 18f; itemDuration = 220f; @@ -1907,7 +1907,9 @@ public class Blocks{ ambientSound = Sounds.steam; ambientSoundVolume = 0.03f; - consumes.item(Items.pyratite).optional(true, false); + drawer = new DrawMulti(new DrawBlock(), new DrawWarmupRegion()); + + consumes.item(Items.pyratite); consumes.liquid(Liquids.cryofluid, 0.1f); }}; @@ -1978,12 +1980,11 @@ public class Blocks{ }}; //TODO rename - chemicalCombustionChamber = new SingleTypeGenerator("chemical-combustion-chamber"){{ + chemicalCombustionChamber = new ConsumeGenerator("chemical-combustion-chamber"){{ requirements(Category.power, with(Items.graphite, 40, Items.tungsten, 40, Items.oxide, 40f, Items.silicon, 30)); powerProduction = 6f; consumes.liquids(LiquidStack.with(Liquids.ozone, 1f / 60f, Liquids.arkycite, 20f / 60f)); size = 3; - useItems = false; drawer = new DrawMulti(new DrawRegion("-bottom"), new DrawPistons(){{ sinMag = 3f; sinScl = 5f; @@ -1995,22 +1996,36 @@ public class Blocks{ iconOverride = new String[]{"-bottom", ""}; generateEffect = Fx.none; + liquidCapacity = 20f * 5; + ambientSound = Sounds.smelter; ambientSoundVolume = 0.06f; }}; - if(false) - pyrolysisGenerator = new SingleTypeGenerator("pyrolysis-generator"){{ + //TODO coolr name? + pyrolysisGenerator = new ConsumeGenerator("pyrolysis-generator"){{ //TODO requirements - requirements(Category.power, with(Items.graphite, 50, Items.carbide, 50, Items.oxide, 60f, Items.silicon, 40)); + requirements(Category.power, with(Items.graphite, 50, Items.carbide, 50, Items.oxide, 60f, Items.silicon, 50)); powerProduction = 12f; - //TODO ratios, extra requirements - consumes.liquids(LiquidStack.with(Liquids.slag, 20f / 60f, Liquids.arkycite, 20f / 60f)); - size = 3; - useItems = false; + drawer = new DrawMulti(new DrawRegion("-bottom"), new DrawPistons(){{ + sinMag = 2.75f; + sinScl = 5f; + sides = 8; + sideOffset = Mathf.PI / 2f; + }}, new DrawRegion("-mid"), new DrawLiquidTile(Liquids.arkycite, 38f / 4f), new DrawBlock(), new DrawGlowRegion(){{ + alpha = 1f; + glowScale = 6f; + color = Pal.slagOrange; + }}); - //TODO water output? hydrogen?? + //TODO ratios, extra requirements? + consumes.liquids(LiquidStack.with(Liquids.slag, 20f / 60f, Liquids.arkycite, 30f / 60f)); + size = 3; + + liquidCapacity = 30f * 5; + + liquidOutput = new LiquidStack(Liquids.water, 5f / 60f); iconOverride = new String[]{"-bottom", ""}; generateEffect = Fx.none; @@ -2019,10 +2034,6 @@ public class Blocks{ ambientSoundVolume = 0.06f; }}; - //TODO volatile reactor; - //- input arkycite, ozone(?), some item(?), maybe slag or heat? - //- output water, power - //endregion power //region production diff --git a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java index edd1daf54e..c04b8333fb 100644 --- a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java @@ -184,20 +184,20 @@ public class ErekirPlanetGenerator extends PlanetGenerator{ if(block != Blocks.air){ //TODO use d4 instead of d8 for no out-of-reach ores? if(nearAir(x, y)){ - if(noise(x + 78, y, 4, 0.7f, 35f, 1f) > 0.67f && block == Blocks.carbonWall){ + if(noise(x + 78, y, 4, 0.7f, 35f, 1f) > 0.6f && block == Blocks.carbonWall){ block = Blocks.graphiticWall; - }else if(noise(x + 782, y, 4, 0.8f, 40f, 1f) > 0.7f && block != Blocks.carbonWall){ + }else if(noise(x + 782, y, 4, 0.8f, 38f, 1f) > 0.68f && block != Blocks.carbonWall){ ore = Blocks.wallOreBeryl; } } }else if(!nearWall(x, y)){ - if(noise(x + 150, y + x*2 + 100, 4, 0.8f, 40f, 1f) > 0.71f/* && floor == Blocks.yellowStone*/){ + if(noise(x + 150, y + x*2 + 100, 4, 0.8f, 60f, 1f) > 0.76f/* && floor == Blocks.yellowStone*/){ ore = Blocks.oreTungsten; } //TODO design ore generation so it doesn't overlap - if(noise(x + 999, y + 600, 4, 0.63f, 37f, 1f) < 0.25f/* && floor == Blocks.yellowStone*/){ + if(noise(x + 999, y + 600, 4, 0.63f, 50f, 1f) < 0.22f/* && floor == Blocks.yellowStone*/){ ore = Blocks.oreThorium; } } diff --git a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java new file mode 100644 index 0000000000..464e8e1d08 --- /dev/null +++ b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java @@ -0,0 +1,112 @@ +package mindustry.world.blocks.power; + +import arc.graphics.*; +import arc.math.*; +import arc.util.*; +import mindustry.content.*; +import mindustry.entities.*; +import mindustry.graphics.*; +import mindustry.type.*; +import mindustry.world.meta.*; + +/** + * A generator that just takes in certain items or liquids. Basically SingleTypeGenerator, but not unreliable garbage. + * TODO at the moment, these generators require at least one item in their inventory to work, meaning they cannot be "kickstarted" with only one item. + */ +public class ConsumeGenerator extends PowerGenerator{ + /** The time in number of ticks during which a single item will produce power. */ + public float itemDuration = 120f; + + public float effectChance = 0.01f; + public Effect generateEffect = Fx.none; + public float generateEffectRange = 3f; + + public @Nullable LiquidStack liquidOutput; + + public ConsumeGenerator(String name){ + super(name); + } + + @Override + public void setBars(){ + super.setBars(); + + if(liquidOutput != null){ + addLiquidBar(liquidOutput.liquid); + } + } + + @Override + public void init(){ + if(liquidOutput != null){ + outputsLiquid = true; + hasLiquids = true; + } + emitLight = true; + lightRadius = 65f * size; + super.init(); + } + + @Override + public void setStats(){ + super.setStats(); + + if(hasItems){ + stats.add(Stat.productionTime, itemDuration / 60f, StatUnit.seconds); + } + + if(liquidOutput != null){ + stats.add(Stat.output, StatValues.liquid(liquidOutput.liquid, liquidOutput.amount * 60f, true)); + } + } + + public class ConsumeGeneratorBuild extends GeneratorBuild{ + public float warmup, totalTime; + + @Override + public void updateTile(){ + boolean valid = consValid(); + + warmup = Mathf.lerpDelta(warmup, enabled && valid ? 1f : 0f, 0.05f); + + productionEfficiency = valid ? 1f : 0f; + totalTime += warmup * Time.delta; + + //generation time always goes down + generateTime -= Math.min(1f / itemDuration * delta(), generateTime); + + //randomly produce the effect + if(valid && Mathf.chanceDelta(effectChance)){ + generateEffect.at(x + Mathf.range(generateEffectRange), y + Mathf.range(generateEffectRange)); + } + + //take in items periodically + if(hasItems && valid && generateTime <= 0f && items.any()){ + cons.trigger(); + generateTime = 1f; + } + + if(liquidOutput != null){ + float added = Math.min(productionEfficiency * delta() * liquidOutput.amount, liquidCapacity - liquids.get(liquidOutput.liquid)); + liquids.add(liquidOutput.liquid, added); + dumpLiquid(liquidOutput.liquid); + } + } + + @Override + public float warmup(){ + return warmup; + } + + @Override + public float totalProgress(){ + return totalTime; + } + + @Override + public void drawLight(){ + //TODO + Drawf.light(team, x, y, (60f + Mathf.absin(10f, 5f)) * size, Color.orange, 0.5f * warmup); + } + } +} diff --git a/core/src/mindustry/world/blocks/power/ItemLiquidGenerator.java b/core/src/mindustry/world/blocks/power/ItemLiquidGenerator.java index 1b14dd78d8..5c7daab1bd 100644 --- a/core/src/mindustry/world/blocks/power/ItemLiquidGenerator.java +++ b/core/src/mindustry/world/blocks/power/ItemLiquidGenerator.java @@ -25,6 +25,7 @@ public class ItemLiquidGenerator extends PowerGenerator{ /** The time in number of ticks during which a single item will produce power. */ public float itemDuration = 70f; + /** Minimum liquid efficiency for a generator to accept it. */ public float minLiquidEfficiency = 0.2f; /** Maximum liquid used per frame. */ public float maxLiquidGenerate = 0.4f; @@ -36,6 +37,7 @@ public class ItemLiquidGenerator extends PowerGenerator{ public boolean defaults = false; /** @deprecated unused, use a custom drawer instead */ + @Deprecated public Color heatColor = Color.valueOf("ff9b59"); /** @deprecated unused, use a custom drawer instead */ @Deprecated @@ -129,14 +131,17 @@ public class ItemLiquidGenerator extends PowerGenerator{ totalTime += heat * Time.delta; //liquid takes priority over solids + //TODO several issues with this! - it does not work correctly, consumption should not be handled here, why am I re-implementing consumes + //TODO what an awful class if(hasLiquids && liquid != null && liquids.get(liquid) >= 0.001f){ float baseLiquidEfficiency = getLiquidEfficiency(liquid); float maximumPossible = maxLiquidGenerate * calculationDelta; float used = Math.min(liquids.get(liquid) * calculationDelta, maximumPossible); - liquids.remove(liquid, used * power.graph.getUsageFraction()); + liquids.remove(liquid, used); productionEfficiency = baseLiquidEfficiency * used / maximumPossible; + //TODO this aggressively spams the generate effect why would anyone want this why is this here if(used > 0.001f && (generateTime -= delta()) <= 0f){ generateEffect.at(x + Mathf.range(generateEffectRnd), y + Mathf.range(generateEffectRnd)); generateTime = 1f; @@ -152,7 +157,7 @@ public class ItemLiquidGenerator extends PowerGenerator{ } if(generateTime > 0f){ - generateTime -= Math.min(1f / itemDuration * delta() * power.graph.getUsageFraction(), generateTime); + generateTime -= Math.min(1f / itemDuration * delta(), generateTime); if(randomlyExplode && state.rules.reactorExplosions && Mathf.chance(delta() * 0.06 * Mathf.clamp(explosiveness - 0.5f))){ //this block is run last so that in the event of a block destruction, no code relies on the block type diff --git a/core/src/mindustry/world/blocks/power/PowerGraph.java b/core/src/mindustry/world/blocks/power/PowerGraph.java index 735af932ec..33f552f186 100644 --- a/core/src/mindustry/world/blocks/power/PowerGraph.java +++ b/core/src/mindustry/world/blocks/power/PowerGraph.java @@ -83,7 +83,8 @@ public class PowerGraph{ return Mathf.clamp(lastPowerProduced / lastPowerNeeded); } - /** @return multiplier of speed at which resources should be consumed for power generation. */ + /** @deprecated unused mechanic that always returns 1, I really don't know why you would use this outside of copy-pasted code */ + @Deprecated public float getUsageFraction(){ return 1f; } diff --git a/core/src/mindustry/world/blocks/power/SingleTypeGenerator.java b/core/src/mindustry/world/blocks/power/SingleTypeGenerator.java index 95919f105b..549251c44a 100644 --- a/core/src/mindustry/world/blocks/power/SingleTypeGenerator.java +++ b/core/src/mindustry/world/blocks/power/SingleTypeGenerator.java @@ -2,6 +2,8 @@ package mindustry.world.blocks.power; import mindustry.type.*; +/** @deprecated use ConsumeGenerator instead, this class does not have a sane implementation. */ +@Deprecated public class SingleTypeGenerator extends ItemLiquidGenerator{ public boolean useItems = true; diff --git a/core/src/mindustry/world/draw/DrawPistons.java b/core/src/mindustry/world/draw/DrawPistons.java index 4e47945c91..d4e550e43a 100644 --- a/core/src/mindustry/world/draw/DrawPistons.java +++ b/core/src/mindustry/world/draw/DrawPistons.java @@ -3,7 +3,6 @@ package mindustry.world.draw; import arc.*; import arc.graphics.g2d.*; import arc.math.*; -import arc.math.geom.*; import arc.util.*; import mindustry.entities.units.*; import mindustry.gen.*; @@ -11,7 +10,8 @@ import mindustry.world.*; public class DrawPistons extends DrawBlock{ public float sinMag = 4f, sinScl = 6f, sinOffset = 50f, sideOffset = 0f, lenOffset = -1f; - public TextureRegion region1, region2; + public int sides = 4; + public TextureRegion region1, region2, regiont; @Override public void drawPlan(Block block, BuildPlan plan, Eachable list){ @@ -20,9 +20,20 @@ public class DrawPistons extends DrawBlock{ @Override public void drawBase(Building build){ - for(int i = 0; i < 4; i++){ + for(int i = 0; i < sides; i++){ float len = Mathf.absin(build.totalProgress() + sinOffset + sideOffset * sinScl * i, sinScl, sinMag) + lenOffset; - Draw.rect(i >= 2 ? region2 : region1, build.x + Geometry.d4[i].x * len, build.y + Geometry.d4[i].y * len, i * 90); + float angle = i * 360f / sides; + TextureRegion reg = + regiont.found() && (Mathf.equal(angle, 315) || Mathf.equal(angle, 135)) ? regiont : + angle >= 135 && angle < 315 ? region2 : region1; + + if(Mathf.equal(angle, 315)){ + Draw.yscl = -1f; + } + + Draw.rect(reg, build.x + Angles.trnsx(angle, len), build.y + Angles.trnsy(angle, len), angle); + + Draw.yscl = 1f; } } @@ -30,7 +41,8 @@ public class DrawPistons extends DrawBlock{ public void load(Block block){ super.load(block); - region1 = Core.atlas.find(block.name + "-piston0"); - region2 = Core.atlas.find(block.name + "-piston1"); + region1 = Core.atlas.find(block.name + "-piston0", block.name + "-piston"); + region2 = Core.atlas.find(block.name + "-piston1", block.name + "-piston"); + regiont = Core.atlas.find(block.name + "-piston-t"); } } diff --git a/core/src/mindustry/world/draw/DrawRotator.java b/core/src/mindustry/world/draw/DrawRotator.java index 13ea1f3eb6..6c2b55a66b 100644 --- a/core/src/mindustry/world/draw/DrawRotator.java +++ b/core/src/mindustry/world/draw/DrawRotator.java @@ -11,6 +11,14 @@ public class DrawRotator extends DrawBlock{ public boolean drawSpinSprite = false; public float spinSpeed = 2f; + public DrawRotator(boolean drawSpinSprite, float spinSpeed){ + this.drawSpinSprite = drawSpinSprite; + this.spinSpeed = spinSpeed; + } + + public DrawRotator(){ + } + @Override public void drawBase(Building build){ Draw.rect(build.block.region, build.x, build.y);