diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 5dba049954..da3a01689a 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -303,6 +303,8 @@ error.title = [crimson]An error has occured error.crashtitle = An error has occured blocks.unknown = [LIGHT_GRAY]??? blocks.blockinfo = Block Info +blocks.powerbalance = Power: {0} +blocks.poweroutput = Power Output: {0} blocks.powercapacity = Power Capacity blocks.powershot = Power/Shot blocks.targetsair = Targets Air diff --git a/core/src/io/anuke/mindustry/ai/BlockIndexer.java b/core/src/io/anuke/mindustry/ai/BlockIndexer.java index d7ebcad8eb..d82c6a8fe6 100644 --- a/core/src/io/anuke/mindustry/ai/BlockIndexer.java +++ b/core/src/io/anuke/mindustry/ai/BlockIndexer.java @@ -26,7 +26,7 @@ public class BlockIndexer{ private final static int structQuadrantSize = 12; /**Set of all ores that are being scanned.*/ - private final ObjectSet scanOres = new ObjectSet(){{addAll(Item.getAllOres());}}; + private final ObjectSet scanOres = ObjectSet.with(Item.getAllOres().toArray(Item.class)); private final ObjectSet itemSet = new ObjectSet<>(); /**Stores all ore quadtrants on the map.*/ private ObjectMap> ores; diff --git a/core/src/io/anuke/mindustry/content/Blocks.java b/core/src/io/anuke/mindustry/content/Blocks.java index 2f580c5a79..52eb86fdbd 100644 --- a/core/src/io/anuke/mindustry/content/Blocks.java +++ b/core/src/io/anuke/mindustry/content/Blocks.java @@ -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; }}; diff --git a/core/src/io/anuke/mindustry/graphics/Pal.java b/core/src/io/anuke/mindustry/graphics/Pal.java index cad77809cb..b5c17c8604 100644 --- a/core/src/io/anuke/mindustry/graphics/Pal.java +++ b/core/src/io/anuke/mindustry/graphics/Pal.java @@ -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, diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 0867765cda..eab9e1cf0b 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -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)); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java index 5b5e675558..9da9cff4e5 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerGenerator.java @@ -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.entity().productionEfficiency; diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java index c1ad348d2e..7f5f0fd1e2 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java @@ -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 batteries = new ObjectSet<>(); private final ObjectSet 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); } diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java index 3f7969efd8..707392f2f0 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -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);