mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-28 13:47:32 +07:00
Continued work on power generators
This commit is contained in:
@ -26,7 +26,6 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||
private ItemLiquidGenerator generator;
|
||||
private Tile tile;
|
||||
private ItemLiquidGenerator.ItemLiquidGeneratorEntity entity;
|
||||
private final float fakeLiquidPowerMultiplier = 2.0f;
|
||||
private final float fakeItemDuration = 60f; // 60 ticks
|
||||
private final float maximumLiquidUsage = 0.5f;
|
||||
|
||||
@ -35,7 +34,6 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||
{
|
||||
powerProduction = 0.1f;
|
||||
itemDuration = 60f;
|
||||
liquidPowerMultiplier = fakeLiquidPowerMultiplier;
|
||||
itemDuration = fakeItemDuration;
|
||||
maxLiquidGenerate = maximumLiquidUsage;
|
||||
}
|
||||
@ -79,7 +77,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||
}
|
||||
|
||||
void simulateLiquidConsumption(ItemLiquidGenerator.InputType inputType, Liquid liquid, float availableLiquidAmount, String parameterDescription){
|
||||
final float baseEfficiency = fakeLiquidPowerMultiplier * liquid.flammability;
|
||||
final float baseEfficiency = liquid.flammability;
|
||||
final float expectedEfficiency = Math.min(1.0f, availableLiquidAmount / maximumLiquidUsage) * baseEfficiency;
|
||||
final float expectedConsumptionPerTick = Math.min(maximumLiquidUsage, availableLiquidAmount);
|
||||
final float expectedRemainingLiquidAmount = Math.max(0.0f, availableLiquidAmount - expectedConsumptionPerTick * FakeThreadHandler.fakeDelta);
|
||||
|
74
tests/src/test/java/power/PowerBalancingTests.java
Normal file
74
tests/src/test/java/power/PowerBalancingTests.java
Normal file
@ -0,0 +1,74 @@
|
||||
package power;
|
||||
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.content.Liquids;
|
||||
import io.anuke.mindustry.content.blocks.PowerBlocks;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.power.BurnerGenerator;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/** Sets expectations to specific production blocks using specific inputs. */
|
||||
|
||||
public class PowerBalancingTests extends PowerTestFixture{
|
||||
// Last updated to values of: v63
|
||||
|
||||
/**
|
||||
* Tests the produced power of a power block with items or liquids.
|
||||
* @apiNote Tests only a single tick with a fixed delta and interpolates that to match one second.
|
||||
* @param powerBlock The block to be tested.
|
||||
* @param inputItem The item to be supplied (may be null).
|
||||
* @param inputLiquid The liquid to be supplied (may be null).
|
||||
* @param expectedPowerPerSecond The amount of power which should be produced per second.
|
||||
*/
|
||||
public void testPowerGenerator(Block powerBlock, Item inputItem, Liquid inputLiquid, float expectedPowerPerSecond){
|
||||
Tile fakeTile = createFakeTile(0, 0, powerBlock);
|
||||
if(inputItem != null){
|
||||
fakeTile.entity.items.add(inputItem, 1);
|
||||
}
|
||||
if(inputLiquid != null){
|
||||
fakeTile.entity.liquids.add(inputLiquid, 1);
|
||||
}
|
||||
fakeTile.entity.cons.update(fakeTile.entity);
|
||||
powerBlock.update(fakeTile);
|
||||
|
||||
assertEquals(expectedPowerPerSecond, fakeTile.entity.power.graph.getPowerProduced() * 60f, MathUtils.FLOAT_ROUNDING_ERROR * 10.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombustionWithCoal(){
|
||||
testPowerGenerator(PowerBlocks.combustionGenerator, Items.coal, null, 2.7f); // 100% flammability
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombustionWithOil(){
|
||||
testPowerGenerator(PowerBlocks.combustionGenerator, null, Liquids.oil, 2.7f * 1.2f); // 120% flammability
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombustionWithBlastCompound(){
|
||||
testPowerGenerator(PowerBlocks.combustionGenerator, Items.blastCompound, null, 2.7f * 0.4f); // 40% flammability
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTurbineWithCoal(){
|
||||
testPowerGenerator(PowerBlocks.turbineGenerator, Items.coal, Liquids.water, 8.4f); // 100% flammability
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTurbineWithBiomatter(){
|
||||
testPowerGenerator(PowerBlocks.turbineGenerator, Items.biomatter, Liquids.water, 8.4f * 0.8f); // 100% flammability
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThermalWithLava(){
|
||||
testPowerGenerator(PowerBlocks.thermalGenerator, null, Liquids.lava, 36f); // 100% flammability
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ public class PowerTests extends PowerTestFixture{
|
||||
}
|
||||
void simulateDirectConsumption(float producedPower, float requiredPower, float expectedSatisfaction, String parameterDescription){
|
||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 0.5f; // Currently, 0.5f = 100%
|
||||
Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requiredPower, 0.6f));
|
||||
|
||||
PowerGraph powerGraph = new PowerGraph();
|
||||
@ -89,7 +89,7 @@ public class PowerTests extends PowerTestFixture{
|
||||
}
|
||||
void simulateBufferedConsumption(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;
|
||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 0.5f; // Currently, 0.5 = 100%
|
||||
Tile bufferedConsumerTile = createFakeTile(0, 1, createFakeBufferedConsumer(maxBuffer, maxBuffer > 0.0f ? maxBuffer/powerConsumedPerTick : 1.0f));
|
||||
bufferedConsumerTile.entity.power.satisfaction = initialSatisfaction;
|
||||
|
||||
@ -128,7 +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;
|
||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 0.5f; // Currently, 0.5f = 100%
|
||||
powerGraph.add(producerTile);
|
||||
}
|
||||
Tile directConsumerTile = null;
|
||||
|
Reference in New Issue
Block a user