mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-13 17:27:35 +07:00
- Fixed double power production
- Buffered consumers no longer request power when full
This commit is contained in:
@ -15,13 +15,8 @@ import java.io.DataOutput;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class PowerGenerator extends PowerDistributor{
|
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;
|
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){
|
||||||
@ -39,8 +34,9 @@ public class PowerGenerator extends PowerDistributor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getPowerProduction(Tile tile){
|
public float getPowerProduction(Tile tile){
|
||||||
// Multiply all efficiencies by two since 0.5 = 100% efficiency
|
// While 0.5 efficiency currently reflects 100%, we do not need to multiply by any factor since powerProduction states the
|
||||||
return powerProduction * tile.<GeneratorEntity>entity().productionEfficiency * 2.0f;
|
// power which would be produced at 1.0 efficiency
|
||||||
|
return powerProduction * tile.<GeneratorEntity>entity().productionEfficiency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,12 +53,13 @@ public class PowerGenerator extends PowerDistributor{
|
|||||||
public void setBars(){
|
public void setBars(){
|
||||||
super.setBars();
|
super.setBars();
|
||||||
if(hasPower){
|
if(hasPower){
|
||||||
bars.add(new BlockBar(BarType.power, true, tile -> tile.<GeneratorEntity>entity().productionEfficiency / maxEfficiency));
|
bars.add(new BlockBar(BarType.power, true, tile -> tile.<GeneratorEntity>entity().productionEfficiency));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GeneratorEntity extends TileEntity{
|
public static class GeneratorEntity extends TileEntity{
|
||||||
public float generateTime;
|
public float generateTime;
|
||||||
|
/** The efficiency of the producer. Currently, an efficiency of 0.5 means 100% */
|
||||||
public float productionEfficiency = 0.0f;
|
public float productionEfficiency = 0.0f;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.anuke.mindustry.world.consumers;
|
package io.anuke.mindustry.world.consumers;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
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.
|
* @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 Make the block not consume power on the following conditions, either here or in PowerGraph:
|
if(isBuffered){
|
||||||
// - Other consumers are not valid, e.g. additional input items/liquids are missing
|
// Stop requesting power once the buffer is full.
|
||||||
// - Buffer is full
|
return MathUtils.isEqual(entity.power.satisfaction, 1.0f) ? 0.0f : powerPerTick;
|
||||||
return powerPerTick;
|
}else{
|
||||||
|
return powerPerTick;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,8 +42,9 @@ public class PowerTestFixture{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static PowerGenerator createFakeProducerBlock(float producedPower){
|
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"){{
|
return new PowerGenerator("fakegen"){{
|
||||||
powerProduction = producedPower;
|
powerProduction = producedPower * 2.0f;
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,13 @@ public class PowerTests extends PowerTestFixture{
|
|||||||
powerGraph.add(bufferedConsumerTile);
|
powerGraph.add(bufferedConsumerTile);
|
||||||
|
|
||||||
assertEquals(producedPower * FakeThreadHandler.fakeDelta, powerGraph.getPowerProduced(), MathUtils.FLOAT_ROUNDING_ERROR, parameterDescription + ": Produced power did not match");
|
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
|
// Update and check for the expected power satisfaction of the consumer
|
||||||
powerGraph.update();
|
powerGraph.update();
|
||||||
@ -128,7 +134,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 = 0.5f; // Currently, 0.5f = 100%
|
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 0.5f;
|
||||||
powerGraph.add(producerTile);
|
powerGraph.add(producerTile);
|
||||||
}
|
}
|
||||||
Tile directConsumerTile = null;
|
Tile directConsumerTile = null;
|
||||||
|
Reference in New Issue
Block a user