Fixed occassional crashes of Power Tests and continued TDD

This commit is contained in:
Timmeey86
2018-11-27 21:27:35 +01:00
parent 11e071289b
commit f56e1933a6
7 changed files with 72 additions and 37 deletions

View File

@@ -19,17 +19,17 @@ public class PowerBlocks extends BlockList implements ContentList{
thermalGenerator = new LiquidHeatGenerator("thermal-generator"){{
maxLiquidGenerate = 4f;
// TODO: Adapt to new power system
powerProduction = -1;
powerPerLiquid = 0.1f;
// TODO: Balance
powerProduction = 0.17f;
liquidPowerMultiplier = 0.1f;
generateEffect = BlockFx.redgeneratespark;
size = 2;
}};
turbineGenerator = new TurbineGenerator("turbine-generator"){{
// TODO: Adapt to new power system
// TODO: Balance
powerProduction = 0.28f;
powerPerLiquid = 0.1f;
liquidPowerMultiplier = 0.3f;
itemDuration = 30f;
consumes.liquid(Liquids.water, 0.05f);
size = 2;

View File

@@ -14,7 +14,7 @@ import static io.anuke.mindustry.Vars.tilesize;
public abstract class ItemLiquidGenerator extends ItemGenerator{
protected float minLiquidEfficiency = 0.2f;
protected float powerPerLiquid = 0.13f;
protected float liquidPowerMultiplier = 1.3f; // A liquid with 100% flammability will be 30% more efficient than an item with 100% flammability.
/**Maximum liquid used per frame.*/
protected float maxLiquidGenerate = 0.4f;
@@ -46,15 +46,16 @@ public abstract class ItemLiquidGenerator extends ItemGenerator{
}
//liquid takes priority over solids
float calculationDelta = entity.delta();
if(liquid != null && entity.liquids.get(liquid) >= 0.001f && entity.cons.valid()){
float powerPerLiquid = getLiquidEfficiency(liquid) * this.powerPerLiquid;
float used = Math.min(entity.liquids.get(liquid), maxLiquidGenerate * entity.delta());
// TODO: Adapt to new power system
//used = Math.min(used, (powerCapacity - entity.power.amount) / powerPerLiquid);
float baseLiquidEfficiency = getLiquidEfficiency(liquid) * this.liquidPowerMultiplier;
float maximumPossible = maxLiquidGenerate * calculationDelta;
float used = Math.min(entity.liquids.get(liquid), maximumPossible);
entity.liquids.remove(liquid, used);
// TODO: Adapt to new power system
//entity.power.amount += used * powerPerLiquid;
// Note: 1 Item with 100% Flammability = 100% efficiency. This means 100% is not max but rather a reference point for this generator.
entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible;
if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){
Effects.effect(generateEffect, tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f));

View File

@@ -13,7 +13,7 @@ import io.anuke.ucore.util.Mathf;
public abstract class LiquidGenerator extends PowerGenerator{
protected float minEfficiency = 0.2f;
protected float powerPerLiquid;
protected float liquidPowerMultiplier;
/**Maximum liquid used per frame.*/
protected float maxLiquidGenerate;
protected Effect generateEffect = BlockFx.generatespark;
@@ -50,8 +50,9 @@ public abstract class LiquidGenerator extends PowerGenerator{
public void update(Tile tile){
TileEntity entity = tile.entity();
// TODO Code duplication with ItemLiquidGenerator
if(entity.liquids.get(entity.liquids.current()) >= 0.001f){
float powerPerLiquid = getEfficiency(entity.liquids.current()) * this.powerPerLiquid;
//float powerPerLiquid = getEfficiency(entity.liquids.current()) * this.powerPerLiquid;
float used = Math.min(entity.liquids.currentAmount(), maxLiquidGenerate * entity.delta());
// TODO Adapt to new power system
//used = Math.min(used, (powerCapacity - entity.power.amount) / powerPerLiquid);

View File

@@ -14,9 +14,9 @@ public class LiquidHeatGenerator extends LiquidGenerator{
public void setStats(){
super.setStats();
// TODO Verify for new power system
stats.remove(BlockStat.basePowerGeneration);
stats.add(BlockStat.basePowerGeneration, maxLiquidGenerate * powerPerLiquid * 60f, StatUnit.powerSecond);
// TODO Adapt to new new power system. Maybe this override can be removed.
//stats.add(BlockStat.basePowerGeneration, <Do something with maxLiquidGenerate, basePowerGeneration and liquidPowerMultiplier> * 60f, StatUnit.powerSecond);
}
@Override

View File

@@ -10,7 +10,7 @@ import io.anuke.mindustry.world.meta.BlockStat;
public class PowerGenerator extends PowerDistributor{
/** The amount of power produced per tick. */
public float powerProduction;
protected float powerProduction;
public BlockStat generationType = BlockStat.basePowerGeneration;
public PowerGenerator(String name){