mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-04 23:38:10 +07:00
Initial Efficiency is now zero. Blocks display efficiency.
This commit is contained in:
@ -4,6 +4,7 @@ import io.anuke.mindustry.content.Liquids;
|
|||||||
import io.anuke.mindustry.content.fx.BlockFx;
|
import io.anuke.mindustry.content.fx.BlockFx;
|
||||||
import io.anuke.mindustry.game.ContentList;
|
import io.anuke.mindustry.game.ContentList;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.power.*;
|
import io.anuke.mindustry.world.blocks.power.*;
|
||||||
|
|
||||||
public class PowerBlocks extends BlockList implements ContentList{
|
public class PowerBlocks extends BlockList implements ContentList{
|
||||||
@ -41,14 +42,26 @@ public class PowerBlocks extends BlockList implements ContentList{
|
|||||||
itemDuration = 220f;
|
itemDuration = 220f;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
solarPanel = new PowerGenerator("solar-panel"){{
|
// TODO: Maybe reintroduce a class for the initial production efficiency
|
||||||
|
solarPanel = new PowerGenerator("solar-panel"){
|
||||||
|
{
|
||||||
powerProduction = 0.0045f;
|
powerProduction = 0.0045f;
|
||||||
}};
|
}
|
||||||
|
@Override
|
||||||
|
public void update(Tile tile){
|
||||||
|
tile.<GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
largeSolarPanel = new PowerGenerator("solar-panel-large"){{
|
largeSolarPanel = new PowerGenerator("solar-panel-large"){
|
||||||
|
{
|
||||||
powerProduction = 0.055f;
|
powerProduction = 0.055f;
|
||||||
size = 3;
|
}
|
||||||
}};
|
@Override
|
||||||
|
public void update(Tile tile){
|
||||||
|
tile.<GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
thoriumReactor = new NuclearReactor("thorium-reactor"){{
|
thoriumReactor = new NuclearReactor("thorium-reactor"){{
|
||||||
size = 3;
|
size = 3;
|
||||||
|
@ -337,9 +337,8 @@ public class Block extends BaseBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBars(){
|
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));
|
bars.add(new BlockBar(BarType.power, true, tile -> tile.entity.power.satisfaction));
|
||||||
}
|
|
||||||
if(hasLiquids)
|
if(hasLiquids)
|
||||||
bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.total() / liquidCapacity));
|
bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.total() / liquidCapacity));
|
||||||
if(hasItems)
|
if(hasItems)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.anuke.mindustry.world.blocks.power;
|
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.mindustry.world.meta.StatUnit;
|
||||||
import io.anuke.ucore.util.EnumSet;
|
import io.anuke.ucore.util.EnumSet;
|
||||||
|
|
||||||
@ -11,6 +13,11 @@ import io.anuke.mindustry.world.meta.BlockStat;
|
|||||||
public class PowerGenerator extends PowerDistributor{
|
public class PowerGenerator extends PowerDistributor{
|
||||||
/** The amount of power produced per tick. */
|
/** The amount of power produced per tick. */
|
||||||
protected float powerProduction;
|
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 BlockStat generationType = BlockStat.basePowerGeneration;
|
||||||
|
|
||||||
public PowerGenerator(String name){
|
public PowerGenerator(String name){
|
||||||
@ -40,8 +47,16 @@ public class PowerGenerator extends PowerDistributor{
|
|||||||
return new GeneratorEntity();
|
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 static class GeneratorEntity extends TileEntity{
|
||||||
public float generateTime;
|
public float generateTime;
|
||||||
public float productionEfficiency = 1;
|
public float productionEfficiency = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,9 @@ public class ConsumePower extends Consume{
|
|||||||
* @return The amount of power which is requested per tick.
|
* @return The amount of power which is requested per tick.
|
||||||
*/
|
*/
|
||||||
public float requestedPower(Block block, TileEntity entity){
|
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;
|
return powerPerTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package power;
|
|||||||
|
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import io.anuke.mindustry.world.Tile;
|
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.blocks.power.PowerGraph;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||||
import org.junit.jupiter.api.*;
|
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){
|
void test_directConsumptionCalculation(float producedPower, float requiredPower, float expectedSatisfaction, String parameterDescription){
|
||||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||||
|
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||||
Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requiredPower, 0.6f));
|
Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requiredPower, 0.6f));
|
||||||
|
|
||||||
PowerGraph powerGraph = new PowerGraph();
|
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){
|
void test_bufferedConsumptionCalculation(float producedPower, float maxBuffer, float powerConsumedPerTick, float initialSatisfaction, float expectedSatisfaction, String parameterDescription){
|
||||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
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));
|
Tile bufferedConsumerTile = createFakeTile(0, 1, createFakeBufferedConsumer(maxBuffer, maxBuffer > 0.0f ? maxBuffer/powerConsumedPerTick : 1.0f));
|
||||||
bufferedConsumerTile.entity.power.satisfaction = initialSatisfaction;
|
bufferedConsumerTile.entity.power.satisfaction = initialSatisfaction;
|
||||||
|
|
||||||
@ -125,6 +128,7 @@ public class PowerTests extends PowerTestFixture{
|
|||||||
|
|
||||||
if(producedPower > 0.0f){
|
if(producedPower > 0.0f){
|
||||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||||
|
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||||
powerGraph.add(producerTile);
|
powerGraph.add(producerTile);
|
||||||
}
|
}
|
||||||
Tile directConsumerTile = null;
|
Tile directConsumerTile = null;
|
||||||
@ -149,6 +153,7 @@ public class PowerTests extends PowerTestFixture{
|
|||||||
@Test
|
@Test
|
||||||
void testDirectConsumptionStopsWithNoPower(){
|
void testDirectConsumptionStopsWithNoPower(){
|
||||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(10.0f));
|
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));
|
Tile consumerTile = createFakeTile(0, 1, createFakeDirectConsumer(5.0f, 0.6f));
|
||||||
|
|
||||||
PowerGraph powerGraph = new PowerGraph();
|
PowerGraph powerGraph = new PowerGraph();
|
||||||
|
Reference in New Issue
Block a user