Resolved some of the power-related TODOs

This commit is contained in:
Timmeey86
2018-11-29 00:38:53 +01:00
parent 12ccc10e83
commit 4cb72c1998
4 changed files with 38 additions and 29 deletions

View File

@@ -40,7 +40,6 @@ public class DebugBlocks extends BlockList implements ContentList{
public void load(){
powerVoid = new PowerBlock("powervoid"){
{
// TODO Adapt to new power system if necessary
consumes.powerDirect(Float.MAX_VALUE);
shadow = "shadow-round-1";
}
@@ -54,8 +53,7 @@ public class DebugBlocks extends BlockList implements ContentList{
@Override
public void init(){
super.init();
// TODO Adapt to new power system if necessary
//stats.remove(BlockStat.powerCapacity);
stats.remove(BlockStat.powerUse);
}
};
@@ -67,7 +65,6 @@ public class DebugBlocks extends BlockList implements ContentList{
shadow = "shadow-round-1";
}
// TODO Adapt to new power system if necessary
@Override
public float getPowerProduction(Tile tile){
return 10000f;

View File

@@ -22,8 +22,6 @@ public class LiquidBlocks extends BlockList implements ContentList{
pumpAmount = 0.2f;
consumes.powerDirect(0.015f);
liquidCapacity = 30f;
// TODO Verify: No longer buffered
consumes.powerDirect(20f / 60f);
hasPower = true;
size = 2;
tier = 1;
@@ -35,8 +33,6 @@ public class LiquidBlocks extends BlockList implements ContentList{
consumes.powerDirect(0.03f);
liquidCapacity = 40f;
hasPower = true;
// TODO Verify: No longer buffered
consumes.powerDirect(20f / 60f);
size = 2;
tier = 2;
}};

View File

@@ -4,17 +4,17 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class FusionReactor extends PowerGenerator{
protected int plasmas = 4;
protected float maxPowerProduced = 2f;
protected float warmupSpeed = 0.001f;
protected Color plasma1 = Color.valueOf("ffd06b"), plasma2 = Color.valueOf("ff361b");
@@ -24,35 +24,25 @@ public class FusionReactor extends PowerGenerator{
super(name);
hasPower = true;
hasLiquids = true;
// TODO Adapt to new power system
//powerCapacity = 100f;
powerProduction = 2.0f;
liquidCapacity = 30f;
hasItems = true;
}
@Override
public void setStats(){
super.setStats();
// TODO Verify for new power system
stats.remove(BlockStat.basePowerGeneration);
stats.add(BlockStat.basePowerGeneration, maxPowerProduced * 60f, StatUnit.powerSecond);
}
@Override
public void update(Tile tile){
FusionReactorEntity entity = tile.entity();
float increaseOrDecrease = 1.0f;
if(entity.cons.valid()){
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
}else{
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
increaseOrDecrease = -1.0f;
}
// TODO Adapt to new power system
//float powerAdded = Math.min(powerCapacity - entity.power.amount, maxPowerProduced * Mathf.pow(entity.warmup, 4f) * Timers.delta());
//entity.power.amount += powerAdded;
entity.totalProgress += entity.warmup * Timers.delta();
float efficiencyAdded = Mathf.pow(entity.warmup, 4f) * Timers.delta();
entity.productionEfficiency = Mathf.clamp(entity.productionEfficiency + efficiencyAdded * increaseOrDecrease);
tile.entity.power.graph.update();
}
@@ -100,7 +90,7 @@ public class FusionReactor extends PowerGenerator{
Draw.rect(name + "-top", tile.drawx(), tile.drawy());
Draw.color(ind1, ind2, entity.warmup + Mathf.absin(entity.totalProgress, 3f, entity.warmup * 0.5f));
Draw.color(ind1, ind2, entity.warmup + Mathf.absin(entity.productionEfficiency, 3f, entity.warmup * 0.5f));
Draw.rect(name + "-light", tile.drawx(), tile.drawy());
Draw.color();
@@ -127,7 +117,19 @@ public class FusionReactor extends PowerGenerator{
//TODO catastrophic failure
}
public static class FusionReactorEntity extends GenericCrafterEntity{
public static class FusionReactorEntity extends GeneratorEntity{
public float warmup;
@Override
public void write(DataOutput stream) throws IOException{
super.write(stream);
stream.writeFloat(warmup);
}
@Override
public void read(DataInput stream) throws IOException{
super.read(stream);
warmup = stream.readFloat();
}
}
}

View File

@@ -10,6 +10,10 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.mindustry.world.meta.BlockStat;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class PowerGenerator extends PowerDistributor{
/** The amount of power produced per tick. */
protected float powerProduction;
@@ -58,5 +62,15 @@ public class PowerGenerator extends PowerDistributor{
public static class GeneratorEntity extends TileEntity{
public float generateTime;
public float productionEfficiency = 0.0f;
@Override
public void write(DataOutput stream) throws IOException{
stream.writeFloat(productionEfficiency);
}
@Override
public void read(DataInput stream) throws IOException{
productionEfficiency = stream.readFloat();
}
}
}