From 2972780bed875a0129829d358699b13f1e903ac7 Mon Sep 17 00:00:00 2001 From: Timmeey86 Date: Wed, 28 Nov 2018 13:19:52 +0100 Subject: [PATCH] Initial Efficiency is now zero. Blocks display efficiency. --- .../mindustry/content/blocks/PowerBlocks.java | 27 ++++++++++++++----- core/src/io/anuke/mindustry/world/Block.java | 3 +-- .../world/blocks/power/PowerGenerator.java | 17 +++++++++++- .../world/consumers/ConsumePower.java | 4 ++- tests/src/test/java/power/PowerTests.java | 5 ++++ 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/blocks/PowerBlocks.java b/core/src/io/anuke/mindustry/content/blocks/PowerBlocks.java index db497f5043..cf59a636d1 100644 --- a/core/src/io/anuke/mindustry/content/blocks/PowerBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/PowerBlocks.java @@ -4,6 +4,7 @@ import io.anuke.mindustry.content.Liquids; import io.anuke.mindustry.content.fx.BlockFx; import io.anuke.mindustry.game.ContentList; import io.anuke.mindustry.world.Block; +import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.power.*; public class PowerBlocks extends BlockList implements ContentList{ @@ -41,14 +42,26 @@ public class PowerBlocks extends BlockList implements ContentList{ itemDuration = 220f; }}; - solarPanel = new PowerGenerator("solar-panel"){{ - powerProduction = 0.0045f; - }}; + // TODO: Maybe reintroduce a class for the initial production efficiency + solarPanel = new PowerGenerator("solar-panel"){ + { + powerProduction = 0.0045f; + } + @Override + public void update(Tile tile){ + tile.entity().productionEfficiency = 1.0f; + } + }; - largeSolarPanel = new PowerGenerator("solar-panel-large"){{ - powerProduction = 0.055f; - size = 3; - }}; + largeSolarPanel = new PowerGenerator("solar-panel-large"){ + { + powerProduction = 0.055f; + } + @Override + public void update(Tile tile){ + tile.entity().productionEfficiency = 1.0f; + } + }; thoriumReactor = new NuclearReactor("thorium-reactor"){{ size = 3; diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 21ee395822..4e6caa78d2 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -337,9 +337,8 @@ public class Block extends BaseBlock { } public void setBars(){ - if(consumes.has(ConsumePower.class)){ + if(consumes.has(ConsumePower.class)) bars.add(new BlockBar(BarType.power, true, tile -> tile.entity.power.satisfaction)); - } if(hasLiquids) bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.total() / liquidCapacity)); if(hasItems) diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java index 48d8bd0106..8a3e59dd9d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java @@ -1,5 +1,7 @@ package io.anuke.mindustry.world.blocks.power; +import io.anuke.mindustry.world.BarType; +import io.anuke.mindustry.world.meta.BlockBar; import io.anuke.mindustry.world.meta.StatUnit; import io.anuke.ucore.util.EnumSet; @@ -11,6 +13,11 @@ import io.anuke.mindustry.world.meta.BlockStat; public class PowerGenerator extends PowerDistributor{ /** The amount of power produced per tick. */ protected float powerProduction; + /** The maximum possible efficiency for this generator. Supply values larger than 1.0f if more than 100% is possible. + * This could be the case when e.g. an item with 100% flammability is the reference point, but a more effective liquid + * can be supplied as an alternative. + */ + protected float maxEfficiency = 1.0f; public BlockStat generationType = BlockStat.basePowerGeneration; public PowerGenerator(String name){ @@ -40,8 +47,16 @@ public class PowerGenerator extends PowerDistributor{ return new GeneratorEntity(); } + @Override + public void setBars(){ + super.setBars(); + if(hasPower){ + bars.add(new BlockBar(BarType.power, true, tile -> tile.entity().productionEfficiency / maxEfficiency)); + } + } + public static class GeneratorEntity extends TileEntity{ public float generateTime; - public float productionEfficiency = 1; + public float productionEfficiency = 0.0f; } } diff --git a/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java b/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java index 2fd27ace54..d4d9a3dffb 100644 --- a/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java +++ b/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java @@ -86,7 +86,9 @@ public class ConsumePower extends Consume{ * @return The amount of power which is requested per tick. */ public float requestedPower(Block block, TileEntity entity){ - // TODO Is it possible to make the block not consume power while items/liquids are missing? + // TODO Make the block not consume power on the following conditions, either here or in PowerGraph: + // - Other consumers are not valid, e.g. additional input items/liquids are missing + // - Buffer is full return powerPerTick; } diff --git a/tests/src/test/java/power/PowerTests.java b/tests/src/test/java/power/PowerTests.java index 36d4e258dc..25a85c58d2 100644 --- a/tests/src/test/java/power/PowerTests.java +++ b/tests/src/test/java/power/PowerTests.java @@ -2,6 +2,7 @@ package power; import com.badlogic.gdx.math.MathUtils; import io.anuke.mindustry.world.Tile; +import io.anuke.mindustry.world.blocks.power.PowerGenerator; import io.anuke.mindustry.world.blocks.power.PowerGraph; import io.anuke.mindustry.world.consumers.ConsumePower; import org.junit.jupiter.api.*; @@ -48,6 +49,7 @@ public class PowerTests extends PowerTestFixture{ } void test_directConsumptionCalculation(float producedPower, float requiredPower, float expectedSatisfaction, String parameterDescription){ Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower)); + producerTile.entity().productionEfficiency = 1.0f; Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requiredPower, 0.6f)); PowerGraph powerGraph = new PowerGraph(); @@ -87,6 +89,7 @@ public class PowerTests extends PowerTestFixture{ } void test_bufferedConsumptionCalculation(float producedPower, float maxBuffer, float powerConsumedPerTick, float initialSatisfaction, float expectedSatisfaction, String parameterDescription){ Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower)); + producerTile.entity().productionEfficiency = 1.0f; Tile bufferedConsumerTile = createFakeTile(0, 1, createFakeBufferedConsumer(maxBuffer, maxBuffer > 0.0f ? maxBuffer/powerConsumedPerTick : 1.0f)); bufferedConsumerTile.entity.power.satisfaction = initialSatisfaction; @@ -125,6 +128,7 @@ public class PowerTests extends PowerTestFixture{ if(producedPower > 0.0f){ Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower)); + producerTile.entity().productionEfficiency = 1.0f; powerGraph.add(producerTile); } Tile directConsumerTile = null; @@ -149,6 +153,7 @@ public class PowerTests extends PowerTestFixture{ @Test void testDirectConsumptionStopsWithNoPower(){ Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(10.0f)); + producerTile.entity().productionEfficiency = 1.0f; Tile consumerTile = createFakeTile(0, 1, createFakeDirectConsumer(5.0f, 0.6f)); PowerGraph powerGraph = new PowerGraph();