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 84b2b6c841..d165925c07 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java @@ -15,13 +15,8 @@ import java.io.DataOutput; import java.io.IOException; public class PowerGenerator extends PowerDistributor{ - /** The amount of power produced per tick. */ + /** The amount of power produced per tick in case of an efficiency of 1.0, which currently represents 200%. */ 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){ @@ -39,8 +34,9 @@ public class PowerGenerator extends PowerDistributor{ @Override public float getPowerProduction(Tile tile){ - // Multiply all efficiencies by two since 0.5 = 100% efficiency - return powerProduction * tile.entity().productionEfficiency * 2.0f; + // While 0.5 efficiency currently reflects 100%, we do not need to multiply by any factor since powerProduction states the + // power which would be produced at 1.0 efficiency + return powerProduction * tile.entity().productionEfficiency; } @Override @@ -57,12 +53,13 @@ public class PowerGenerator extends PowerDistributor{ public void setBars(){ super.setBars(); if(hasPower){ - bars.add(new BlockBar(BarType.power, true, tile -> tile.entity().productionEfficiency / maxEfficiency)); + bars.add(new BlockBar(BarType.power, true, tile -> tile.entity().productionEfficiency)); } } public static class GeneratorEntity extends TileEntity{ public float generateTime; + /** The efficiency of the producer. Currently, an efficiency of 0.5 means 100% */ public float productionEfficiency = 0.0f; @Override diff --git a/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java b/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java index d4d9a3dffb..28d3d4ab66 100644 --- a/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java +++ b/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.world.consumers; +import com.badlogic.gdx.math.MathUtils; import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.mindustry.entities.TileEntity; @@ -86,10 +87,12 @@ public class ConsumePower extends Consume{ * @return The amount of power which is requested per tick. */ public float requestedPower(Block block, TileEntity entity){ - // 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; + if(isBuffered){ + // Stop requesting power once the buffer is full. + return MathUtils.isEqual(entity.power.satisfaction, 1.0f) ? 0.0f : powerPerTick; + }else{ + return powerPerTick; + } } diff --git a/tests/src/test/java/power/PowerTestFixture.java b/tests/src/test/java/power/PowerTestFixture.java index 34d88bd62e..5728f6bc8e 100644 --- a/tests/src/test/java/power/PowerTestFixture.java +++ b/tests/src/test/java/power/PowerTestFixture.java @@ -42,8 +42,9 @@ public class PowerTestFixture{ } protected static PowerGenerator createFakeProducerBlock(float producedPower){ + // Multiply produced power by 2 since production efficiency is defined to be 0.5 = 100% return new PowerGenerator("fakegen"){{ - powerProduction = producedPower; + powerProduction = producedPower * 2.0f; }}; } diff --git a/tests/src/test/java/power/PowerTests.java b/tests/src/test/java/power/PowerTests.java index e8167a4aec..a79089ab91 100644 --- a/tests/src/test/java/power/PowerTests.java +++ b/tests/src/test/java/power/PowerTests.java @@ -98,7 +98,13 @@ public class PowerTests extends PowerTestFixture{ powerGraph.add(bufferedConsumerTile); assertEquals(producedPower * FakeThreadHandler.fakeDelta, powerGraph.getPowerProduced(), MathUtils.FLOAT_ROUNDING_ERROR, parameterDescription + ": Produced power did not match"); - assertEquals(Math.min(maxBuffer, powerConsumedPerTick * FakeThreadHandler.fakeDelta), powerGraph.getPowerNeeded(), MathUtils.FLOAT_ROUNDING_ERROR, parameterDescription + ": ConsumedPower did not match"); + float expectedPowerUsage; + if(initialSatisfaction == 1.0f){ + expectedPowerUsage = 0f; + }else{ + expectedPowerUsage = Math.min(maxBuffer, powerConsumedPerTick * FakeThreadHandler.fakeDelta); + } + assertEquals(expectedPowerUsage, powerGraph.getPowerNeeded(), MathUtils.FLOAT_ROUNDING_ERROR, parameterDescription + ": Consumed power did not match"); // Update and check for the expected power satisfaction of the consumer powerGraph.update(); @@ -128,7 +134,7 @@ public class PowerTests extends PowerTestFixture{ if(producedPower > 0.0f){ Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower)); - producerTile.entity().productionEfficiency = 0.5f; // Currently, 0.5f = 100% + producerTile.entity().productionEfficiency = 0.5f; powerGraph.add(producerTile); } Tile directConsumerTile = null;