yey pathfinder back

This commit is contained in:
Sharlotte
2022-09-22 00:12:59 +09:00
parent 4a944387b8
commit 9c865b863d
14 changed files with 1088 additions and 568 deletions

View File

@@ -16,7 +16,6 @@ public class OverDraw {
public boolean enabled = false;
public Seq<String> options = new Seq<>();
OverDraw(String name, TextureRegionDrawable icon) {
this.name = name;
this.icon = icon;

View File

@@ -1,5 +1,7 @@
package informatis.ui.draws;
import informatis.SVars;
import informatis.core.Pathfinder;
import informatis.ui.*;
import arc.graphics.g2d.*;
import arc.math.*;
@@ -8,7 +10,6 @@ import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.Vars;
import mindustry.ai.*;
import mindustry.ai.types.*;
import mindustry.entities.units.*;
import mindustry.game.*;
@@ -25,12 +26,13 @@ import static mindustry.Vars.*;
public class UnitDraw extends OverDraw {
Seq<Tile> pathTiles = new Seq<>();
int otherCores;
Seq<Building> otherCores;
UnitDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("pathLine");
registerOption("logicLine");
registerOption("commandLine");
registerOption("unitLine");
registerOption("unitItem");
registerOption("unitBar");
@@ -43,6 +45,11 @@ public class UnitDraw extends OverDraw {
Groups.unit.each(u -> {
UnitController c = u.controller();
if(settings.getBool("commandLine") && c instanceof CommandAI com && com.hasCommand()) {
Lines.stroke(1, u.team.color);
Lines.line(u.x(), u.y(), com.targetPos.x, com.targetPos.y);
}
if(settings.getBool("logicLine") && c instanceof LogicAI ai && (ai.control == LUnitControl.approach || ai.control == LUnitControl.move)) {
Lines.stroke(1, u.team.color);
Lines.line(u.x(), u.y(), ai.moveX, ai.moveY);
@@ -50,21 +57,14 @@ public class UnitDraw extends OverDraw {
Lines.line(u.x(), u.y(), ai.controller.x, ai.controller.y);
}
if(c instanceof CommandAI com && com.hasCommand()) {
Lines.stroke(1, u.team.color);
Lines.line(u.x(), u.y(), com.targetPos.x, com.targetPos.y);
}
if(settings.getBool("unitLine") && u.team == state.rules.waveTeam && !u.type.flying && !(c instanceof MinerAI || c instanceof BuilderAI || c instanceof RepairAI || c instanceof DefenderAI || c instanceof FlyingAI)) {
Lines.stroke(1, u.team.color);
otherCores = Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != u.team);
pathTiles.clear();
getNextTile(u.tileOn(), u.controller() instanceof SuicideAI ? 0 : u.pathType(), u.team, u.pathType());
for(int i = 0; i < pathTiles.size-1; i++) {
Tile from = pathTiles.get(i);
Tile to = pathTiles.get(i + 1);
otherCores = Groups.build.copy(new Seq<>()).filter(b -> b instanceof CoreBlock.CoreBuild && b.team != u.team);
getNextTile(u.tileOn(), SVars.pathfinder.getField(u.team, u.controller() instanceof SuicideAI ? 0 : u.pathType(), u.pathType()));
for(int i = 0; i < pathTiles.size - 1; i++) {
Tile from = pathTiles.get(i), to = pathTiles.get(i + 1);
if(from == null || to == null) continue;
Lines.line(from.worldx(), from.worldy(), to.worldx(), to.worldy());
}
@@ -80,29 +80,27 @@ public class UnitDraw extends OverDraw {
}
});
if(settings.getBool("pathLine")) spawner.getSpawns().each(t -> {
Team enemyTeam = state.rules.waveTeam;
Lines.stroke(1, enemyTeam.color);
for(int p = 0; p < (Vars.state.rules.spawns.count(g->g.type.naval)>0?3:2); p++) {
pathTiles.clear();
otherCores = Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != enemyTeam);
getNextTile(t, p, enemyTeam, Pathfinder.fieldCore);
for(int i = 0; i < pathTiles.size-1; i++) {
Tile from = pathTiles.get(i);
Tile to = pathTiles.get(i + 1);
if(from == null || to == null) continue;
Lines.line(from.worldx(), from.worldy(), to.worldx(), to.worldy());
if(settings.getBool("pathLine")) {
pathTiles.clear();
otherCores = Groups.build.copy(new Seq<>()).filter(b -> b instanceof CoreBlock.CoreBuild && b.team != state.rules.waveTeam);
spawner.getSpawns().each(t -> {
for(int p = 0; p < 3; p++) {
getNextTile(t, SVars.pathfinder.getField(state.rules.waveTeam, p, Pathfinder.fieldCore));
}
});
Lines.stroke(1, state.rules.waveTeam.color);
for(int i = 0; i < pathTiles.size - 1; i++) {
Tile from = pathTiles.get(i), to = pathTiles.get(i + 1);
if(from == null || to == null) continue;
Lines.line(from.worldx(), from.worldy(), to.worldx(), to.worldy());
}
}
});
}
void getNextTile(Tile tile, int cost, Team team, int finder) {
Pathfinder.Flowfield field = pathfinder.getField(team, cost, Mathf.clamp(finder, 0, 0));
Tile tile1 = pathfinder.getTargetTile(tile, field);
pathTiles.add(tile1);
if(tile1 == tile || tile1 == null ||
(finder == 0 && (otherCores != Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != team) || tile1.build instanceof CoreBlock.CoreBuild))) return;
getNextTile(tile1, cost, team, finder);
void getNextTile(Tile tile, Pathfinder.Flowfield field) {
Tile nextTile = SVars.pathfinder.getTargetTile(tile, field);
pathTiles.add(nextTile);
if(nextTile == tile || nextTile == null) return;
getNextTile(nextTile, field);
}
}

View File

@@ -6,7 +6,6 @@ import arc.math.geom.*;
import arc.scene.*;
import arc.scene.style.*;
import arc.struct.*;
import informatis.core.EditorTool;
import mindustry.editor.*;
import mindustry.game.*;
import mindustry.graphics.*;
@@ -27,6 +26,9 @@ import mindustry.gen.*;
import mindustry.ui.*;
import mindustry.world.*;
import static informatis.ui.windows.MapEditorWindow.drawBlock;
import static informatis.ui.windows.MapEditorWindow.drawTeam;
import static informatis.ui.windows.Windows.editorTable;
import static mindustry.Vars.*;
public class MapEditorWindow extends Window implements Updatable {
@@ -465,3 +467,251 @@ public class MapEditorWindow extends Window implements Updatable {
return false;
}
}
enum EditorTool{
zoom(KeyCode.v),
pick(KeyCode.i){
public void touched(int x, int y){
if(!Structs.inBounds(x, y, world.width(), world.height())) return;
Tile tile = world.tile(x, y);
drawBlock = tile.block() == Blocks.air || !tile.block().inEditor ? tile.overlay() == Blocks.air ? tile.floor() : tile.overlay() : tile.block();
}
},
line(KeyCode.l, "replace", "orthogonal"){
@Override
public void touchedLine(int x1, int y1, int x2, int y2){
//straight
if(mode == 1){
if(Math.abs(x2 - x1) > Math.abs(y2 - y1)){
y2 = y1;
}else{
x2 = x1;
}
}
Bresenham2.line(x1, y1, x2, y2, (x, y) -> {
if(mode == 0){
//replace
editorTable.drawBlocksReplace(x, y);
}else{
//normal
editorTable.drawBlocks(x, y);
}
});
}
},
pencil(KeyCode.b, "replace", "square", "drawteams"){
{
edit = true;
draggable = true;
}
@Override
public void touched(int x, int y){
if(mode == -1){
//normal mode
editorTable.drawBlocks(x, y);
}else if(mode == 0){
//replace mode
editorTable.drawBlocksReplace(x, y);
}else if(mode == 1){
//square mode
editorTable.drawBlocks(x, y, true, tile -> true);
}else if(mode == 2){
//draw teams
editorTable.drawCircle(x, y, tile -> tile.setTeam(drawTeam));
}
}
},
eraser(KeyCode.e, "eraseores"){
{
edit = true;
draggable = true;
}
@Override
public void touched(int x, int y){
editorTable.drawCircle(x, y, tile -> {
if(mode == -1){
//erase block
tile.remove();
}else if(mode == 0){
//erase ore
tile.clearOverlay();
}
});
}
},
fill(KeyCode.g, "replaceall", "fillteams"){
{
edit = true;
}
IntSeq stack = new IntSeq();
@Override
public void touched(int x, int y){
if(!Structs.inBounds(x, y, world.width(), world.height()) || world.tile(x, y).block()!=null&&world.tile(x, y).block().isMultiblock()) return;
Tile tile = world.tile(x, y);
//mode 0 or 1, fill everything with the floor/tile or replace it
if(mode == 0 || mode == -1){
if(tile.block().isMultiblock()) return;
Boolf<Tile> tester;
Cons<Tile> setter;
Block drawBlock = MapEditorWindow.drawBlock;
if(drawBlock.isOverlay()){
Block dest = tile.overlay();
if(dest == drawBlock) return;
tester = t -> t.overlay() == dest && (t.floor().hasSurface() || !t.floor().needsSurface);
setter = t -> t.setOverlay(drawBlock);
}else if(drawBlock.isFloor()){
Block dest = tile.floor();
if(dest == drawBlock) return;
tester = t -> t.floor() == dest;
setter = t -> t.setFloorUnder(drawBlock.asFloor());
}else{
Block dest = tile.block();
if(dest == drawBlock) return;
tester = t -> t.block() == dest;
setter = t -> t.setBlock(drawBlock, drawTeam);
}
//replace only when the mode is 0 using the specified functions
fill(x, y, mode == 0, tester, setter);
}else if(mode == 1){ //mode 1 is team fill
//only fill synthetic blocks, it's meaningless otherwise
if(tile.synthetic()){
Team dest = tile.team();
if(dest == drawTeam) return;
fill(x, y, false, t -> t.getTeamID() == dest.id && t.synthetic(), t -> t.setTeam(drawTeam));
}
}
}
void fill(int x, int y, boolean replace, Boolf<Tile> tester, Cons<Tile> filler){
int width = world.width(), height = world.height();
if(replace){
//just do it on everything
for(int cx = 0; cx < width; cx++){
for(int cy = 0; cy < height; cy++){
Tile tile = world.tile(cx, cy);
if(tester.get(tile)){
filler.get(tile);
}
}
}
}else{
//perform flood fill
int x1;
stack.clear();
stack.add(Point2.pack(x, y));
try{
while(stack.size > 0 && stack.size < width*height){
int popped = stack.pop();
x = Point2.x(popped);
y = Point2.y(popped);
x1 = x;
while(x1 >= 0 && tester.get(world.tile(x1, y))) x1--;
x1++;
boolean spanAbove = false, spanBelow = false;
while(x1 < width && tester.get(world.tile(x1, y))){
filler.get(world.tile(x1, y));
if(!spanAbove && y > 0 && tester.get(world.tile(x1, y - 1))){
stack.add(Point2.pack(x1, y - 1));
spanAbove = true;
}else if(spanAbove && !tester.get(world.tile(x1, y - 1))){
spanAbove = false;
}
if(!spanBelow && y < height - 1 && tester.get(world.tile(x1, y + 1))){
stack.add(Point2.pack(x1, y + 1));
spanBelow = true;
}else if(spanBelow && y < height - 1 && !tester.get(world.tile(x1, y + 1))){
spanBelow = false;
}
x1++;
}
}
stack.clear();
}catch(OutOfMemoryError e){
//hack
stack = null;
System.gc();
e.printStackTrace();
stack = new IntSeq();
}
}
}
},
spray(KeyCode.r, "replace"){
final double chance = 0.012;
{
edit = true;
draggable = true;
}
@Override
public void touched(int x, int y){
//floor spray
if(drawBlock.isFloor()){
editorTable.drawCircle(x, y, tile -> {
if(Mathf.chance(chance)){
tile.setFloor(drawBlock.asFloor());
}
});
}else if(mode == 0){ //replace-only mode, doesn't affect air
editorTable.drawBlocks(x, y, tile -> Mathf.chance(chance) && tile.block() != Blocks.air);
}else{
editorTable.drawBlocks(x, y, tile -> Mathf.chance(chance));
}
}
};
public static final EditorTool[] all = values();
/** All the internal alternate placement modes of this tool. */
public final String[] altModes;
/** Key to activate this tool. */
public KeyCode key = KeyCode.unset;
/** The current alternate placement mode. -1 is the standard mode, no changes.*/
public int mode = -1;
/** Whether this tool causes canvas changes when touched.*/
public boolean edit;
/** Whether this tool should be dragged across the canvas when the mouse moves.*/
public boolean draggable;
EditorTool(){
this(new String[]{});
}
EditorTool(KeyCode code){
this(new String[]{});
this.key = code;
}
EditorTool(String... altModes){
this.altModes = altModes;
}
EditorTool(KeyCode code, String... altModes){
this.altModes = altModes;
this.key = code;
}
public void touched(int x, int y){}
public void touchedLine(int x1, int y1, int x2, int y2){}
}

View File

@@ -3,6 +3,8 @@ package informatis.ui.windows;
import arc.*;
import arc.math.*;
import arc.scene.*;
import arc.scene.style.Drawable;
import arc.scene.style.TextureRegionDrawable;
import informatis.core.*;
import informatis.ui.*;
import arc.graphics.*;
@@ -14,18 +16,48 @@ import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.core.*;
import mindustry.ctype.UnlockableContent;
import mindustry.entities.Units;
import mindustry.entities.abilities.ShieldRegenFieldAbility;
import mindustry.entities.units.*;
import mindustry.game.EventType;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.LAccess;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.defense.ForceProjector;
import mindustry.world.blocks.defense.MendProjector;
import mindustry.world.blocks.defense.OverdriveProjector;
import mindustry.world.blocks.defense.turrets.ItemTurret;
import mindustry.world.blocks.defense.turrets.LiquidTurret;
import mindustry.world.blocks.defense.turrets.PowerTurret;
import mindustry.world.blocks.defense.turrets.ReloadTurret;
import mindustry.world.blocks.distribution.MassDriver;
import mindustry.world.blocks.environment.Floor;
import mindustry.world.blocks.payloads.*;
import mindustry.world.blocks.power.PowerGenerator;
import mindustry.world.blocks.power.PowerNode;
import mindustry.world.blocks.power.ThermalGenerator;
import mindustry.world.blocks.production.AttributeCrafter;
import mindustry.world.blocks.production.Drill;
import mindustry.world.blocks.production.GenericCrafter;
import mindustry.world.blocks.production.SolidPump;
import mindustry.world.blocks.storage.CoreBlock;
import mindustry.world.blocks.storage.StorageBlock;
import mindustry.world.blocks.units.Reconstructor;
import mindustry.world.blocks.units.UnitFactory;
import mindustry.world.consumers.ConsumePower;
import java.lang.reflect.Field;
import java.util.Objects;
import static arc.Core.bundle;
import static informatis.SVars.*;
import static informatis.SUtils.*;
import static informatis.ui.SIcons.*;
import static informatis.ui.SIcons.liquid;
import static mindustry.Vars.*;
public class UnitWindow extends Window {
@@ -37,7 +69,17 @@ public class UnitWindow extends Window {
final Bits statuses = new Bits();
Teamc lastTarget;
public UnitWindow() { super(Icon.units, "unit"); }
public UnitWindow() {
super(Icon.units, "unit");
Events.run(EventType.Trigger.update, () -> {
try {
BarInfo.getInfo(getTarget());
} catch (IllegalAccessException | NoSuchFieldException err) {
err.printStackTrace();
}
});
}
@Override
protected void build(Table table) {
@@ -258,3 +300,196 @@ public class UnitWindow extends Window {
});
}
}
class BarInfo {
public static Seq<BarData> data = new Seq<>();
public static <T extends Teamc> void getInfo(T target) throws IllegalAccessException, NoSuchFieldException {
data.clear();
if(target instanceof Healthc healthc){
data.add(new BarData(bundle.format("shar-stat.health", formatNumber(healthc.health())), Pal.health, healthc.healthf(), health));
}
if(target instanceof Unit unit){
float max = ((ShieldRegenFieldAbility) content.units().copy().max(ut -> {
ShieldRegenFieldAbility ability = (ShieldRegenFieldAbility) ut.abilities.find(ab -> ab instanceof ShieldRegenFieldAbility);
if(ability == null) return 0;
return ability.max;
}).abilities.find(abil -> abil instanceof ShieldRegenFieldAbility)).max;
//float commands = Groups.unit.count(u -> u.controller() instanceof FormationAI && ((FormationAI)u.controller()).leader == target);
data.add(new BarData(bundle.format("shar-stat.shield", formatNumber(unit.shield())), Pal.surge, unit.shield() / max, shield));
data.add(new BarData(bundle.format("shar-stat.capacity", unit.stack.item.localizedName, formatNumber(unit.stack.amount), formatNumber(unit.type.itemCapacity)), unit.stack.amount > 0 && unit.stack().item != null ? unit.stack.item.color.cpy().lerp(Color.white, 0.15f) : Color.white, unit.stack.amount / (unit.type.itemCapacity * 1f), item));
//data.add(new BarData(bundle.format("shar-stat.commandUnits", formatNumber(commands), formatNumber(unit.type().commandLimit)), Pal.powerBar.cpy().lerp(Pal.surge.cpy().mul(Pal.lighterOrange), Mathf.absin(Time.time, 7f / (1f + Mathf.clamp(commands / (unit.type().commandLimit * 1f))), 1f)), commands / (unit.type().commandLimit * 1f)));
if(target instanceof Payloadc pay) data.add(new BarData(bundle.format("shar-stat.payloadCapacity", formatNumber(Mathf.round(Mathf.sqrt(pay.payloadUsed()))), formatNumber(Mathf.round(Mathf.sqrt(unit.type().payloadCapacity)))), Pal.items, pay.payloadUsed() / unit.type().payloadCapacity));
if(state.rules.unitAmmo) data.add(new BarData(bundle.format("shar-stat.ammos", formatNumber(unit.ammo()), formatNumber(unit.type().ammoCapacity)), unit.type().ammoType.color(), unit.ammof()));
}
else if(target instanceof Building build){
if(build.block.hasLiquids) data.add(new BarData(bundle.format("shar-stat.capacity", build.liquids.currentAmount() < 0.01f ? build.liquids.current().localizedName : bundle.get("bar.liquid"), formatNumber(build.liquids.currentAmount()), formatNumber(build.block.liquidCapacity)), build.liquids.current().color, build.liquids.currentAmount() / build.block.liquidCapacity, liquid));
if(build.block.hasPower && build.block.consPower != null){
ConsumePower cons = build.block.consPower;
data.add(new BarData(bundle.format("shar-stat.power", formatNumber(build.power.status * 60f * (cons.buffered ? cons.capacity : cons.usage)), formatNumber(60f * (cons.buffered ? cons.capacity : cons.usage))), Pal.powerBar, Mathf.zero(cons.requestedPower(build)) && build.power.graph.getPowerProduced() + build.power.graph.getBatteryStored() > 0f ? 1f : build.power.status, power));
}
if(build.block.hasItems) {
float value;
if (target instanceof CoreBlock.CoreBuild cb) value = cb.storageCapacity * content.items().count(UnlockableContent::unlockedNow);
else if(target instanceof StorageBlock.StorageBuild sb && !sb.canPickup() && sb.linkedCore instanceof CoreBlock.CoreBuild cb) value = cb.storageCapacity * content.items().count(UnlockableContent::unlockedNow);
else value = build.block.itemCapacity;
data.add(new BarData(bundle.format("shar-stat.capacity", bundle.get("category.items"), formatNumber(build.items.total()), value), Pal.items, build.items.total() / value, item));
}
}
if(target instanceof ReloadTurret.ReloadTurretBuild || target instanceof MassDriver.MassDriverBuild){
float pro;
if(target instanceof ReloadTurret.ReloadTurretBuild turret) pro = turret.reloadCounter / ((ReloadTurret)turret.block).reload;
else {
MassDriver.MassDriverBuild mass = (MassDriver.MassDriverBuild) target;
pro = mass.reloadCounter;
}
data.add(new BarData(bundle.format("shar-stat.reload", formatNumber(pro * 100f)), Pal.accent.cpy().lerp(Color.orange, pro), pro, reload));
}
if(target instanceof ForceProjector.ForceBuild force){
ForceProjector forceBlock = (ForceProjector) force.block;
float max = forceBlock.shieldHealth + forceBlock.phaseShieldBoost * force.phaseHeat;
data.add(new BarData(bundle.format("shar-stat.shield", formatNumber(max-force.buildup), formatNumber(max)), Pal.shield, (max-force.buildup)/max, shield));
}
if(target instanceof MendProjector.MendBuild || target instanceof OverdriveProjector.OverdriveBuild || target instanceof ConstructBlock.ConstructBuild || target instanceof Reconstructor.ReconstructorBuild || target instanceof UnitFactory.UnitFactoryBuild || target instanceof Drill.DrillBuild || target instanceof GenericCrafter.GenericCrafterBuild) {
float pro;
if(target instanceof MendProjector.MendBuild mend){
pro = (float) mend.sense(LAccess.progress);
Tmp.c1.set(Pal.heal);
}
else if(target instanceof OverdriveProjector.OverdriveBuild over){
OverdriveProjector block = (OverdriveProjector)over.block;
Field ohno = OverdriveProjector.OverdriveBuild.class.getDeclaredField("charge");
ohno.setAccessible(true);
pro = (float) ohno.get(over)/((OverdriveProjector)over.block).reload;
Tmp.c1.set(Color.valueOf("feb380"));
data.add(new BarData(bundle.format("bar.boost", (int)(over.realBoost() * 100)), Pal.accent, over.realBoost() / (block.hasBoost ? block.speedBoost + block.speedBoostPhase : block.speedBoost)));
}
else if(target instanceof ConstructBlock.ConstructBuild construct){
pro = construct.progress;
Tmp.c1.set(Pal.darkerMetal);
}
else if(target instanceof UnitFactory.UnitFactoryBuild factory){
pro = factory.fraction();
Tmp.c1.set(Pal.darkerMetal);
if(factory.unit() == null) data.add(new BarData("[lightgray]" + Iconc.cancel, Pal.power, 0f));
else {
float value = factory.team.data().countType(factory.unit());
data.add(new BarData(bundle.format("bar.unitcap", Fonts.getUnicodeStr(factory.unit().name), formatNumber(value), formatNumber(Units.getCap(factory.team))), Pal.power, value / Units.getCap(factory.team)));
}
}
else if(target instanceof Reconstructor.ReconstructorBuild reconstruct){
pro = reconstruct.fraction();
Tmp.c1.set(Pal.darkerMetal);
if(reconstruct.unit() == null) data.add(new BarData("[lightgray]" + Iconc.cancel, Pal.power, 0f));
else {
float value = reconstruct.team.data().countType(reconstruct.unit());
data.add(new BarData(bundle.format("bar.unitcap", Fonts.getUnicodeStr(reconstruct.unit().name), formatNumber(value), formatNumber(Units.getCap(reconstruct.team))), Pal.power, value / Units.getCap(reconstruct.team)));
}
}
else if(target instanceof Drill.DrillBuild drill){
pro = (float) drill.sense(LAccess.progress);
Tmp.c1.set(drill.dominantItem == null ? Pal.items : drill.dominantItem.color);
data.add(new BarData(bundle.format("bar.drillspeed", formatNumber(drill.lastDrillSpeed * 60 * drill.timeScale())), Pal.ammo, drill.warmup));
}
else {
GenericCrafter.GenericCrafterBuild crafter = (GenericCrafter.GenericCrafterBuild) target;
GenericCrafter block = (GenericCrafter) crafter.block;
pro = (float) crafter.sense(LAccess.progress);
if(block.outputItem != null) Tmp.c1.set(block.outputItem.item.color);
else if(block.outputLiquid != null) Tmp.c1.set(block.outputLiquid.liquid.color);
else Tmp.c1.set(Pal.items);
}
data.add(new BarData(bundle.format("shar-stat.progress", formatNumber(pro * 100f)), Tmp.c1, pro));
}
if(target instanceof PowerGenerator.GeneratorBuild generator){
data.add(new BarData(bundle.format("shar-stat.powerIn", formatNumber(generator.getPowerProduction() * generator.timeScale() * 60f)), Pal.powerBar, generator.productionEfficiency, power));
}
if(target instanceof PowerNode.PowerNodeBuild || target instanceof PowerTurret.PowerTurretBuild) {
float value, max;
if(target instanceof PowerNode.PowerNodeBuild node){
max = node.power.graph.getLastPowerStored();
value = node.power.graph.getLastCapacity();
data.add(new BarData(bundle.format("bar.powerlines", node.power.links.size, ((PowerNode)node.block).maxNodes), Pal.items, (float)node.power.links.size / (float)((PowerNode)node.block).maxNodes));
data.add(new BarData(bundle.format("shar-stat.powerOut", "-" + formatNumber(node.power.graph.getLastScaledPowerOut() * 60f)), Pal.powerBar, node.power.graph.getLastScaledPowerOut() / node.power.graph.getLastScaledPowerIn(), power));
data.add(new BarData(bundle.format("shar-stat.powerIn", formatNumber(node.power.graph.getLastScaledPowerIn() * 60f)), Pal.powerBar, node.power.graph.getLastScaledPowerIn() / node.power.graph.getLastScaledPowerOut(), power));
data.add(new BarData(bundle.format("bar.powerbalance", (node.power.graph.getPowerBalance() >= 0 ? "+" : "") + formatNumber(node.power.graph.getPowerBalance() * 60)), Pal.powerBar, node.power.graph.getLastPowerProduced() / node.power.graph.getLastPowerNeeded(), power));
}
else { //TODO: why is this different
PowerTurret.PowerTurretBuild turret = (PowerTurret.PowerTurretBuild) target;
max = turret.block.consPower.usage;
value = turret.power.status * turret.power.graph.getLastScaledPowerIn();
}
data.add(new BarData(bundle.format("shar-stat.power", formatNumber(Math.max(value, max) * 60), formatNumber(max * 60)), Pal.power, value / max));
}
if(target instanceof ItemTurret.ItemTurretBuild turret) {
ItemTurret block = (ItemTurret)turret.block;
data.add(new BarData(bundle.format("shar-stat.capacity", turret.hasAmmo() ? block.ammoTypes.findKey(turret.peekAmmo(), true).localizedName : bundle.get("stat.ammo"), formatNumber(turret.totalAmmo), formatNumber(block.maxAmmo)), turret.hasAmmo() ? block.ammoTypes.findKey(turret.peekAmmo(), true).color : Pal.ammo, turret.totalAmmo / (float)block.maxAmmo, ammo));
}
if(target instanceof LiquidTurret.LiquidTurretBuild turret){
data.add(new BarData(bundle.format("shar-stat.capacity", turret.liquids.currentAmount() < 0.01f ? turret.liquids.current().localizedName : bundle.get("stat.ammo"), formatNumber(turret.liquids.get(turret.liquids.current())), formatNumber(turret.block.liquidCapacity)), turret.liquids.current().color, turret.liquids.get(turret.liquids.current()) / turret.block.liquidCapacity, liquid));
}
if(target instanceof AttributeCrafter.AttributeCrafterBuild || target instanceof ThermalGenerator.ThermalGeneratorBuild || (target instanceof SolidPump.SolidPumpBuild crafter && ((SolidPump)crafter.block).attribute != null)) {
float display, pro;
if (target instanceof AttributeCrafter.AttributeCrafterBuild crafter) {
AttributeCrafter block = (AttributeCrafter) crafter.block;
display = (block.baseEfficiency + Math.min(block.maxBoost, block.boostScale * block.sumAttribute(block.attribute, crafter.tileX(), crafter.tileY()))) * 100f;
pro = block.boostScale * crafter.attrsum / block.maxBoost;
}
else if (target instanceof ThermalGenerator.ThermalGeneratorBuild thermal) {
ThermalGenerator block = (ThermalGenerator) thermal.block;
float max = content.blocks().max(b -> b instanceof Floor f && f.attributes != null ? f.attributes.get(block.attribute) : 0).asFloor().attributes.get(block.attribute);
display = block.sumAttribute(block.attribute, thermal.tileX(), thermal.tileY()) * 100;
pro = block.sumAttribute(block.attribute, thermal.tileX(), thermal.tileY()) / block.size / block.size / max;
}
else {
SolidPump.SolidPumpBuild crafter = (SolidPump.SolidPumpBuild) target;
SolidPump block = (SolidPump) crafter.block;
float fraction = Math.max(crafter.validTiles + crafter.boost + (block.attribute == null ? 0 : block.attribute.env()), 0);
float max = content.blocks().max(b -> b instanceof Floor f && f.attributes != null ? f.attributes.get(block.attribute) : 0).asFloor().attributes.get(block.attribute);
display = Math.max(block.sumAttribute(block.attribute, crafter.tileX(), crafter.tileY()) / block.size / block.size + block.baseEfficiency, 0f) * 100 * block.percentSolid(crafter.tileX(), crafter.tileY());
pro = fraction / max;
}
data.add(new BarData(bundle.format("shar-stat.attr", Mathf.round(display)), Pal.ammo, pro));
}
}
static class BarData {
public String name;
public Color color;
public float number;
public Drawable icon = new TextureRegionDrawable(clear);
BarData(String name, Color color, float number) {
this.name = name;
this.color = color;
this.number = number;
}
BarData(String name, Color color, float number, TextureRegion icon) {
this(name, color, number);
this.icon = new TextureRegionDrawable(icon);
}
}
}