Power balance info

This commit is contained in:
Anuken
2019-02-13 22:37:12 -05:00
parent ea2ed7d776
commit 8c6c4c2630
8 changed files with 45 additions and 6 deletions

View File

@@ -26,7 +26,7 @@ public class BlockIndexer{
private final static int structQuadrantSize = 12;
/**Set of all ores that are being scanned.*/
private final ObjectSet<Item> scanOres = new ObjectSet<Item>(){{addAll(Item.getAllOres());}};
private final ObjectSet<Item> scanOres = ObjectSet.with(Item.getAllOres().toArray(Item.class));
private final ObjectSet<Item> itemSet = new ObjectSet<>();
/**Stores all ore quadtrants on the map.*/
private ObjectMap<Item, ObjectSet<Tile>> ores;

View File

@@ -833,7 +833,7 @@ public class Blocks implements ContentList{
thermalGenerator = new ThermalGenerator("thermal-generator"){{
requirements(Category.power, ItemStack.with(Items.copper, 80, Items.graphite, 70, Items.lead, 100, Items.silicon, 70, Items.metaglass, 80));
powerProduction = 3f;
powerProduction = 2f;
generateEffect = Fx.redgeneratespark;
size = 2;
}};

View File

@@ -53,6 +53,7 @@ public class Pal{
breakInvalid = Color.valueOf("d44b3d"),
range = Color.valueOf("f4ba6e"),
power = Color.valueOf("fbad67"),
powerBar = Color.valueOf("ec7b4c"),
powerLight = Color.valueOf("fbd367"),
placing = accent,

View File

@@ -378,7 +378,7 @@ public class Block extends BlockStorage{
}
if(hasPower && consumes.has(ConsumePower.class)){
bars.add("power", entity -> new Bar(consumes.get(ConsumePower.class).isBuffered ? "blocks.power" : "blocks.power.satisfaction", Pal.power, () -> entity.power.satisfaction));
bars.add("power", entity -> new Bar(consumes.get(ConsumePower.class).isBuffered ? "blocks.power" : "blocks.power.satisfaction", Pal.powerBar, () -> entity.power.satisfaction));
}
}

View File

@@ -1,8 +1,13 @@
package io.anuke.mindustry.world.blocks.power;
import io.anuke.arc.Core;
import io.anuke.arc.collection.EnumSet;
import io.anuke.arc.util.Strings;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.ui.Bar;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.consumers.ConsumePower;
import io.anuke.mindustry.world.meta.BlockFlag;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit;
@@ -28,6 +33,19 @@ public class PowerGenerator extends PowerDistributor{
stats.add(generationType, powerProduction * 60.0f, StatUnit.powerSecond);
}
@Override
public void setBars(){
super.setBars();
if(hasPower && outputsPower && !consumes.has(ConsumePower.class)){
bars.add("power", entity -> new Bar(() ->
Core.bundle.format("blocks.poweroutput",
Strings.toFixed(entity.tile.block().getPowerProduction(entity.tile)*60, 1)),
() -> Pal.powerBar,
() -> ((GeneratorEntity)entity).productionEfficiency));
}
}
@Override
public float getPowerProduction(Tile tile){
return powerProduction * tile.<GeneratorEntity>entity().productionEfficiency;

View File

@@ -6,6 +6,7 @@ import io.anuke.arc.collection.IntSet;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.collection.Queue;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.WindowedMean;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.consumers.Consume;
import io.anuke.mindustry.world.consumers.ConsumePower;
@@ -22,6 +23,8 @@ public class PowerGraph{
private final ObjectSet<Tile> batteries = new ObjectSet<>();
private final ObjectSet<Tile> all = new ObjectSet<>();
private final WindowedMean powerBalance = new WindowedMean(60);
private long lastFrameUpdated = -1;
private final int graphID;
private static int lastGraphID;
@@ -34,6 +37,10 @@ public class PowerGraph{
return graphID;
}
public float getPowerBalance(){
return powerBalance.getMean();
}
public float getPowerProduced(){
float powerProduced = 0f;
for(Tile producer : producers){
@@ -154,6 +161,8 @@ public class PowerGraph{
}
}
powerBalance.addValue(powerProduced - powerNeeded);
distributePower(powerNeeded, powerProduced);
}

View File

@@ -8,12 +8,14 @@ import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.math.Angles;
import io.anuke.arc.util.Strings;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.ui.Bar;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.PowerBlock;
import io.anuke.mindustry.world.meta.BlockStat;
@@ -23,9 +25,6 @@ import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class PowerNode extends PowerBlock{
public static final float thicknessScl = 0.7f;
public static final float flashScl = 0.12f;
//last distribution block placed
private static int lastPlaced = -1;
@@ -89,6 +88,16 @@ public class PowerNode extends PowerBlock{
}
}
@Override
public void setBars(){
super.setBars();
bars.add("power", entity -> new Bar(() ->
Core.bundle.format("blocks.powerbalance",
(entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.toFixed(entity.power.graph.getPowerBalance()*60, 1)),
() -> Pal.powerBar,
() -> Mathf.clamp(entity.power.graph.getPowerProduced() / entity.power.graph.getPowerNeeded())));
}
@Override
public void playerPlaced(Tile tile){
Tile before = world.tile(lastPlaced);