1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-10 15:05:23 +03:00

Initial Efficiency is now zero. Blocks display efficiency.

This commit is contained in:
Timmeey86 2018-11-28 13:19:52 +01:00
parent cf3d2c3def
commit 2972780bed
5 changed files with 45 additions and 11 deletions

View File

@ -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.<GeneratorEntity>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.<GeneratorEntity>entity().productionEfficiency = 1.0f;
}
};
thoriumReactor = new NuclearReactor("thorium-reactor"){{
size = 3;

View File

@ -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)

View File

@ -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.<GeneratorEntity>entity().productionEfficiency / maxEfficiency));
}
}
public static class GeneratorEntity extends TileEntity{
public float generateTime;
public float productionEfficiency = 1;
public float productionEfficiency = 0.0f;
}
}

View File

@ -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;
}

View File

@ -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.<PowerGenerator.GeneratorEntity>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.<PowerGenerator.GeneratorEntity>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.<PowerGenerator.GeneratorEntity>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.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
Tile consumerTile = createFakeTile(0, 1, createFakeDirectConsumer(5.0f, 0.6f));
PowerGraph powerGraph = new PowerGraph();