mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-09 19:49:27 +02:00
yey pathfinder back
This commit is contained in:
@@ -59,6 +59,8 @@ setting.logicLine.name = enable Logic Line
|
||||
setting.logicLine.description = display lines between logic processor and controlled units
|
||||
setting.unitLine.name = enable Unit Line
|
||||
setting.unitLine.description = display ai path each ground unit
|
||||
setting.commandLine.name = enable Command Line
|
||||
setting.cocmmandLine.description = display unit path line, controlled by rts command
|
||||
setting.unitItem.name = enable Unit Item
|
||||
setting.unitItem.description = display item amount under each unit
|
||||
setting.unitBar.name = enable Unit Bar
|
||||
|
||||
@@ -59,7 +59,9 @@ setting.logicLine.name = 로직 조종선 표시
|
||||
setting.logicLine.description = 프로세서와 조종중인 유닛의 관계를 가시화합니다.
|
||||
setting.unitLine.name = 유닛 길 표시
|
||||
setting.unitLine.description = 지상/해상 유닛들의 AI 길찾기를 가시화합니다. 단계 길보다 더 정확합니다.
|
||||
setting.unitItem.name = = 유닛 아이템 표시
|
||||
setting.commandLine.name = 지휘 길 표시
|
||||
setting.commandLine.description = 자동 길찾기 대신 직접 지휘로 인해 이동중인 유닛들의 경로를 가시화합니다.
|
||||
setting.unitItem.name = 유닛 아이템 표시
|
||||
setting.unitItem.description = 유닛이 들고 있는 아이템의 수량을 표시합니다.
|
||||
setting.unitBar.name = 유닛 바 표시
|
||||
setting.unitBar.description = 각 유닛의 체력, 탄약, 방어막, 상태이상, 화물에 대해서 간략하게 표시합니다.
|
||||
|
||||
@@ -2,6 +2,7 @@ package informatis;
|
||||
|
||||
import informatis.shaders.*;
|
||||
import arc.graphics.g2d.TextureRegion;
|
||||
import mindustry.ai.Pathfinder;
|
||||
import mindustry.gen.Teamc;
|
||||
|
||||
import static arc.Core.atlas;
|
||||
@@ -10,7 +11,7 @@ public class SVars {
|
||||
public static TextureRegion clear = atlas.find("clear");
|
||||
public static TextureRegion error = atlas.find("error");
|
||||
public static RangeShader turretRange = new RangeShader();
|
||||
public static informatis.core.Pathfinder pathfinder;
|
||||
public static Teamc target;
|
||||
public static boolean locked;
|
||||
public static float uiResumeRate = 3 * 60f; //default 3s
|
||||
}
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
package informatis.core;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.TextureRegion;
|
||||
import arc.math.*;
|
||||
import arc.scene.style.Drawable;
|
||||
import arc.scene.style.TextureRegionDrawable;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.abilities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.defense.*;
|
||||
import mindustry.world.blocks.defense.turrets.*;
|
||||
import mindustry.world.blocks.distribution.*;
|
||||
import mindustry.world.blocks.environment.*;
|
||||
import mindustry.world.blocks.power.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
import mindustry.world.blocks.units.*;
|
||||
import mindustry.world.consumers.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import static informatis.SUtils.*;
|
||||
import static arc.Core.*;
|
||||
import static mindustry.Vars.*;
|
||||
import static informatis.SVars.*;
|
||||
import static informatis.ui.SIcons.*;
|
||||
|
||||
public 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));
|
||||
}
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,267 +0,0 @@
|
||||
package informatis.core;
|
||||
|
||||
import arc.func.Boolf;
|
||||
import arc.func.Cons;
|
||||
import arc.input.KeyCode;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Bresenham2;
|
||||
import arc.math.geom.Point2;
|
||||
import arc.struct.IntSeq;
|
||||
import arc.util.Structs;
|
||||
import mindustry.content.Blocks;
|
||||
import mindustry.game.Team;
|
||||
import mindustry.world.Block;
|
||||
import mindustry.world.Tile;
|
||||
import informatis.ui.windows.*;
|
||||
|
||||
import static informatis.ui.windows.MapEditorWindow.*;
|
||||
import static informatis.ui.windows.Windows.editorTable;
|
||||
import static mindustry.Vars.world;
|
||||
|
||||
public 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){}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
package informatis.core;
|
||||
|
||||
import arc.input.KeyCode;
|
||||
import informatis.SVars;
|
||||
import informatis.ui.*;
|
||||
import informatis.ui.draws.OverDraws;
|
||||
import informatis.ui.fragments.FragmentManager;
|
||||
import informatis.ui.windows.*;
|
||||
import arc.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ai.Pathfinder;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.mod.*;
|
||||
|
||||
@@ -26,12 +28,6 @@ public class Main extends Mod {
|
||||
});
|
||||
|
||||
Events.run(Trigger.update, () -> {
|
||||
try {
|
||||
BarInfo.getInfo(getTarget());
|
||||
} catch (IllegalAccessException | NoSuchFieldException err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
|
||||
target = getTarget();
|
||||
|
||||
for (Window window : windows) {
|
||||
@@ -49,11 +45,13 @@ public class Main extends Mod {
|
||||
Events.on(ClientLoadEvent.class, e -> {
|
||||
Windows.load();
|
||||
|
||||
SettingS.init();
|
||||
Setting.init();
|
||||
WindowManager.init();
|
||||
FragmentManager.init();
|
||||
OverDraws.init();
|
||||
OverDrawer.init();
|
||||
|
||||
SVars.pathfinder = new informatis.core.Pathfinder();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class OverDrawer {
|
||||
if(settings.getBool("spawnerarrow")) {
|
||||
float leng = (player.unit() != null && player.unit().hitSize > 4 * 8f ? player.unit().hitSize * 1.5f : 4 * 8f) + sin;
|
||||
Tmp.v1.set(camera.position);
|
||||
Lines.stroke(1f + sin / 2, Pal.accent);
|
||||
Lines.stroke(1f + sin / 2, Pal.accent);
|
||||
Lines.circle(Tmp.v1.x, Tmp.v1.y, leng - 4f);
|
||||
spawner.getSpawns().each(t -> Drawf.arrow(Tmp.v1.x, Tmp.v1.y, t.worldx(), t.worldy(), leng, (Math.min(200 * 8f, Mathf.dst(Tmp.v1.x, Tmp.v1.y, t.worldx(), t.worldy())) / (200 * 8f)) * (5f + sin)));
|
||||
}
|
||||
|
||||
542
src/informatis/core/Pathfinder.java
Normal file
542
src/informatis/core/Pathfinder.java
Normal file
@@ -0,0 +1,542 @@
|
||||
package informatis.core;
|
||||
|
||||
|
||||
import arc.Core;
|
||||
import arc.Events;
|
||||
import arc.func.Prov;
|
||||
import arc.math.geom.Geometry;
|
||||
import arc.math.geom.Point2;
|
||||
import arc.math.geom.Position;
|
||||
import arc.struct.IntQueue;
|
||||
import arc.struct.IntSeq;
|
||||
import arc.struct.Seq;
|
||||
import arc.util.Log;
|
||||
import arc.util.Nullable;
|
||||
import arc.util.TaskQueue;
|
||||
import arc.util.Time;
|
||||
import informatis.SVars;
|
||||
import mindustry.content.Blocks;
|
||||
import mindustry.core.World;
|
||||
import mindustry.game.EventType;
|
||||
import mindustry.game.Team;
|
||||
import mindustry.gen.Building;
|
||||
import mindustry.gen.PathTile;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.blocks.environment.Floor;
|
||||
import mindustry.world.blocks.storage.CoreBlock;
|
||||
import mindustry.world.meta.BlockFlag;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Pathfinder implements Runnable{
|
||||
private static final long maxUpdate = Time.millisToNanos(7);
|
||||
private static final int updateFPS = 60;
|
||||
private static final int updateInterval = 1000 / updateFPS;
|
||||
|
||||
/** cached world size */
|
||||
static int wwidth, wheight;
|
||||
|
||||
static final int impassable = -1;
|
||||
|
||||
public static final int
|
||||
fieldCore = 0;
|
||||
|
||||
public static final Seq<Prov<Flowfield>> fieldTypes = Seq.with(
|
||||
EnemyCoreField::new
|
||||
);
|
||||
|
||||
public static final int
|
||||
costGround = 0,
|
||||
costLegs = 1,
|
||||
costNaval = 2;
|
||||
|
||||
public static final Seq<PathCost> costTypes = Seq.with(
|
||||
//ground
|
||||
(team, tile) ->
|
||||
(PathTile.allDeep(tile) || ((PathTile.team(tile) == team && !PathTile.teamPassable(tile)) || PathTile.team(tile) == 0) && PathTile.solid(tile)) ? impassable : 1 +
|
||||
PathTile.health(tile) * 5 +
|
||||
(PathTile.nearSolid(tile) ? 2 : 0) +
|
||||
(PathTile.nearLiquid(tile) ? 6 : 0) +
|
||||
(PathTile.deep(tile) ? 6000 : 0) +
|
||||
(PathTile.damages(tile) ? 30 : 0),
|
||||
|
||||
//legs
|
||||
(team, tile) ->
|
||||
PathTile.legSolid(tile) ? impassable : 1 +
|
||||
(PathTile.deep(tile) ? 6000 : 0) + //leg units can now drown
|
||||
(PathTile.solid(tile) ? 5 : 0),
|
||||
|
||||
//water
|
||||
(team, tile) ->
|
||||
(PathTile.solid(tile) || !PathTile.liquid(tile) ? 6000 : 1) +
|
||||
(PathTile.nearGround(tile) || PathTile.nearSolid(tile) ? 14 : 0) +
|
||||
(PathTile.deep(tile) ? 0 : 1) +
|
||||
(PathTile.damages(tile) ? 35 : 0)
|
||||
);
|
||||
|
||||
/** tile data, see PathTileStruct - kept as a separate array for threading reasons */
|
||||
int[] tiles = new int[0];
|
||||
|
||||
/** maps team, cost, type to flow field*/
|
||||
Flowfield[][][] cache;
|
||||
/** unordered array of path data for iteration only. DO NOT iterate or access this in the main thread. */
|
||||
Seq<Flowfield> threadList = new Seq<>(), mainList = new Seq<>();
|
||||
/** handles task scheduling on the update thread. */
|
||||
TaskQueue queue = new TaskQueue();
|
||||
/** Current pathfinding thread */
|
||||
@Nullable
|
||||
Thread thread;
|
||||
IntSeq tmpArray = new IntSeq();
|
||||
|
||||
public Pathfinder(){
|
||||
clearCache();
|
||||
|
||||
Events.on(EventType.WorldLoadEvent.class, event -> {
|
||||
stop();
|
||||
|
||||
//reset and update internal tile array
|
||||
tiles = new int[world.width() * world.height()];
|
||||
wwidth = world.width();
|
||||
wheight = world.height();
|
||||
threadList = new Seq<>();
|
||||
mainList = new Seq<>();
|
||||
clearCache();
|
||||
|
||||
for(int i = 0; i < tiles.length; i++){
|
||||
Tile tile = world.tiles.geti(i);
|
||||
tiles[i] = packTile(tile);
|
||||
}
|
||||
|
||||
//don't bother setting up paths unless necessary
|
||||
if(state.rules.waveTeam.needsFlowField()){
|
||||
preloadPath(getField(state.rules.waveTeam, costGround, fieldCore));
|
||||
Log.debug("Preloading ground enemy flowfield.");
|
||||
|
||||
//preload water on naval maps
|
||||
if(spawner.getSpawns().contains(t -> t.floor().isLiquid)){
|
||||
preloadPath(getField(state.rules.waveTeam, costNaval, fieldCore));
|
||||
Log.debug("Preloading naval enemy flowfield.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
start();
|
||||
});
|
||||
|
||||
Events.on(EventType.ResetEvent.class, event -> stop());
|
||||
|
||||
Events.on(EventType.TileChangeEvent.class, event -> updateTile(event.tile));
|
||||
|
||||
//remove nearSolid flag for tiles
|
||||
Events.on(EventType.TilePreChangeEvent.class, event -> {
|
||||
Tile tile = event.tile;
|
||||
|
||||
if(tile.solid()){
|
||||
for(int i = 0; i < 4; i++){
|
||||
Tile other = tile.nearby(i);
|
||||
if(other != null){
|
||||
//other tile needs to update its nearSolid to be false if it's not solid and this tile just got un-solidified
|
||||
if(!other.solid()){
|
||||
boolean otherNearSolid = false;
|
||||
for(int j = 0; j < 4; j++){
|
||||
Tile othernear = other.nearby(i);
|
||||
if(othernear != null && othernear.solid()){
|
||||
otherNearSolid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int arr = other.array();
|
||||
//the other tile is no longer near solid, remove the solid bit
|
||||
if(!otherNearSolid && tiles.length > arr){
|
||||
tiles[arr] &= ~(PathTile.bitMaskNearSolid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void clearCache(){
|
||||
cache = new Flowfield[256][5][5];
|
||||
}
|
||||
|
||||
/** Packs a tile into its internal representation. */
|
||||
public int packTile(Tile tile){
|
||||
boolean nearLiquid = false, nearSolid = false, nearGround = false, solid = tile.solid(), allDeep = tile.floor().isDeep();
|
||||
|
||||
for(int i = 0; i < 4; i++){
|
||||
Tile other = tile.nearby(i);
|
||||
if(other != null){
|
||||
Floor floor = other.floor();
|
||||
boolean osolid = other.solid();
|
||||
if(floor.isLiquid) nearLiquid = true;
|
||||
if(osolid && !other.block().teamPassable) nearSolid = true;
|
||||
if(!floor.isLiquid) nearGround = true;
|
||||
if(!floor.isDeep()) allDeep = false;
|
||||
|
||||
//other tile is now near solid
|
||||
if(solid && !tile.block().teamPassable){
|
||||
tiles[other.array()] |= PathTile.bitMaskNearSolid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int tid = tile.getTeamID();
|
||||
|
||||
return PathTile.get(
|
||||
tile.build == null || !solid || tile.block() instanceof CoreBlock ? 0 : Math.min((int)(tile.build.health / 40), 80),
|
||||
tid == 0 && tile.build != null && state.rules.coreCapture ? 255 : tid, //use teamid = 255 when core capture is enabled to mark out derelict structures
|
||||
solid,
|
||||
tile.floor().isLiquid,
|
||||
tile.staticDarkness() >= 2 || (tile.floor().solid && tile.block() == Blocks.air),
|
||||
nearLiquid,
|
||||
nearGround,
|
||||
nearSolid,
|
||||
tile.floor().isDeep(),
|
||||
tile.floor().damageTaken > 0.00001f,
|
||||
allDeep,
|
||||
tile.block().teamPassable
|
||||
);
|
||||
}
|
||||
|
||||
public int get(int x, int y){
|
||||
return tiles[x + y * wwidth];
|
||||
}
|
||||
|
||||
/** Starts or restarts the pathfinding thread. */
|
||||
private void start(){
|
||||
stop();
|
||||
|
||||
thread = new Thread(this, "InformatisPathfinder");
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/** Stops the pathfinding thread. */
|
||||
private void stop(){
|
||||
if(thread != null){
|
||||
thread.interrupt();
|
||||
thread = null;
|
||||
}
|
||||
queue.clear();
|
||||
}
|
||||
|
||||
/** Update a tile in the internal pathfinding grid.
|
||||
* Causes a complete pathfinding recalculation. Main thread only. */
|
||||
public void updateTile(Tile tile){
|
||||
int x = tile.x, y = tile.y;
|
||||
|
||||
tile.getLinkedTiles(t -> {
|
||||
int pos = t.array();
|
||||
if(pos < tiles.length){
|
||||
tiles[pos] = packTile(t);
|
||||
}
|
||||
});
|
||||
|
||||
//can't iterate through array so use the map, which should not lead to problems
|
||||
for(Flowfield path : mainList){
|
||||
if(path != null){
|
||||
synchronized(path.targets){
|
||||
path.targets.clear();
|
||||
path.getPositions(path.targets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
queue.post(() -> {
|
||||
for(Flowfield data : threadList){
|
||||
updateTargets(data, x, y);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Thread implementation. */
|
||||
@Override
|
||||
public void run(){
|
||||
while(true){
|
||||
try{
|
||||
if(state.isPlaying()){
|
||||
queue.run();
|
||||
|
||||
//each update time (not total!) no longer than maxUpdate
|
||||
for(Flowfield data : threadList){
|
||||
updateFrontier(data, maxUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
Thread.sleep(updateInterval);
|
||||
}catch(InterruptedException e){
|
||||
//stop looping when interrupted externally
|
||||
return;
|
||||
}
|
||||
}catch(Throwable e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Flowfield getField(Team team, int costType, int fieldType){
|
||||
if(cache[team.id][costType][fieldType] == null){
|
||||
Flowfield field = fieldTypes.get(fieldType).get();
|
||||
field.team = team;
|
||||
field.cost = costTypes.get(costType);
|
||||
field.targets.clear();
|
||||
field.getPositions(field.targets);
|
||||
|
||||
cache[team.id][costType][fieldType] = field;
|
||||
queue.post(() -> registerPath(field));
|
||||
}
|
||||
return cache[team.id][costType][fieldType];
|
||||
}
|
||||
|
||||
/** Gets next tile to travel to. Main thread only. */
|
||||
public @Nullable Tile getTargetTile(Tile tile, Flowfield path){
|
||||
if(tile == null) return null;
|
||||
|
||||
//uninitialized flowfields are not applicable
|
||||
if(!path.initialized){
|
||||
return tile;
|
||||
}
|
||||
|
||||
//if refresh rate is positive, queue a refresh
|
||||
if(path.refreshRate > 0 && Time.timeSinceMillis(path.lastUpdateTime) > path.refreshRate){
|
||||
path.lastUpdateTime = Time.millis();
|
||||
|
||||
tmpArray.clear();
|
||||
path.getPositions(tmpArray);
|
||||
|
||||
synchronized(path.targets){
|
||||
//make sure the position actually changed
|
||||
if(!(path.targets.size == 1 && tmpArray.size == 1 && path.targets.first() == tmpArray.first())){
|
||||
path.targets.clear();
|
||||
path.getPositions(path.targets);
|
||||
|
||||
//queue an update
|
||||
queue.post(() -> updateTargets(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[] values = path.weights;
|
||||
int apos = tile.array();
|
||||
int value = values[apos];
|
||||
|
||||
Tile current = null;
|
||||
int tl = 0;
|
||||
for(Point2 point : Geometry.d8){
|
||||
int dx = tile.x + point.x, dy = tile.y + point.y;
|
||||
|
||||
Tile other = world.tile(dx, dy);
|
||||
if(other == null) continue;
|
||||
|
||||
int packed = world.packArray(dx, dy);
|
||||
|
||||
if(values[packed] < value && (current == null || values[packed] < tl) && path.passable(packed) &&
|
||||
!(point.x != 0 && point.y != 0 && (!path.passable(world.packArray(tile.x + point.x, tile.y)) || !path.passable(world.packArray(tile.x, tile.y + point.y))))){ //diagonal corner trap
|
||||
current = other;
|
||||
tl = values[packed];
|
||||
}
|
||||
}
|
||||
|
||||
if(current == null || tl == impassable || (path.cost == costTypes.items[costGround] && current.dangerous() && !tile.dangerous())) return tile;
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the frontier, increments the search and sets up all flow sources.
|
||||
* This only occurs for active teams.
|
||||
*/
|
||||
private void updateTargets(Flowfield path, int x, int y){
|
||||
int packed = world.packArray(x, y);
|
||||
|
||||
if(packed > path.weights.length) return;
|
||||
|
||||
if(path.weights[packed] == 0){
|
||||
//this was a previous target
|
||||
path.frontier.clear();
|
||||
}else if(!path.frontier.isEmpty()){
|
||||
//skip if this path is processing
|
||||
return;
|
||||
}
|
||||
|
||||
//update cost of the tile and clear frontier to prevent contamination
|
||||
path.weights[packed] = path.cost.getCost(path.team.id, tiles[packed]);
|
||||
path.frontier.clear();
|
||||
|
||||
updateTargets(path);
|
||||
}
|
||||
|
||||
/** Increments the search and sets up flow sources. Does not change the frontier. */
|
||||
private void updateTargets(Flowfield path){
|
||||
//increment search, but do not clear the frontier
|
||||
path.search++;
|
||||
|
||||
synchronized(path.targets){
|
||||
//add targets
|
||||
for(int i = 0; i < path.targets.size; i++){
|
||||
int pos = path.targets.get(i);
|
||||
|
||||
path.weights[pos] = 0;
|
||||
path.searches[pos] = path.search;
|
||||
path.frontier.addFirst(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void preloadPath(Flowfield path){
|
||||
path.targets.clear();
|
||||
path.getPositions(path.targets);
|
||||
registerPath(path);
|
||||
updateFrontier(path, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Created a new flowfield that aims to get to a certain target for a certain team.
|
||||
* Pathfinding thread only.
|
||||
*/
|
||||
private void registerPath(Flowfield path){
|
||||
path.lastUpdateTime = Time.millis();
|
||||
path.setup(tiles.length);
|
||||
|
||||
threadList.add(path);
|
||||
|
||||
//add to main thread's list of paths
|
||||
Core.app.post(() -> mainList.add(path));
|
||||
|
||||
//fill with impassables by default
|
||||
for(int i = 0; i < tiles.length; i++){
|
||||
path.weights[i] = impassable;
|
||||
}
|
||||
|
||||
//add targets
|
||||
for(int i = 0; i < path.targets.size; i++){
|
||||
int pos = path.targets.get(i);
|
||||
path.weights[pos] = 0;
|
||||
path.frontier.addFirst(pos);
|
||||
}
|
||||
}
|
||||
|
||||
/** Update the frontier for a path. Pathfinding thread only. */
|
||||
private void updateFrontier(Flowfield path, long nsToRun){
|
||||
long start = Time.nanos();
|
||||
|
||||
int counter = 0;
|
||||
|
||||
while(path.frontier.size > 0){
|
||||
int tile = path.frontier.removeLast();
|
||||
if(path.weights == null) return; //something went horribly wrong, bail
|
||||
int cost = path.weights[tile];
|
||||
|
||||
//pathfinding overflowed for some reason, time to bail. the next block update will handle this, hopefully
|
||||
if(path.frontier.size >= world.width() * world.height()){
|
||||
path.frontier.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if(cost != impassable){
|
||||
for(Point2 point : Geometry.d4){
|
||||
int dx = (tile % wwidth) + point.x, dy = (tile / wwidth) + point.y;
|
||||
|
||||
if(dx < 0 || dy < 0 || dx >= wwidth || dy >= wheight) continue;
|
||||
|
||||
int newPos = tile + point.x + point.y * wwidth;
|
||||
int otherCost = path.cost.getCost(path.team.id, tiles[newPos]);
|
||||
|
||||
if((path.weights[newPos] > cost + otherCost || path.searches[newPos] < path.search) && otherCost != impassable){
|
||||
path.frontier.addFirst(newPos);
|
||||
path.weights[newPos] = cost + otherCost;
|
||||
path.searches[newPos] = (short)path.search;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//every N iterations, check the time spent - this prevents extra calls to nano time, which itself is slow
|
||||
if(nsToRun >= 0 && (counter++) >= 200){
|
||||
counter = 0;
|
||||
if(Time.timeSinceNanos(start) >= nsToRun){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EnemyCoreField extends Flowfield {
|
||||
@Override
|
||||
protected void getPositions(IntSeq out){
|
||||
for(Building other : indexer.getEnemy(team, BlockFlag.core)){
|
||||
out.add(other.tile.array());
|
||||
}
|
||||
|
||||
//spawn points are also enemies.
|
||||
if(state.rules.waves && team == state.rules.defaultTeam){
|
||||
for(Tile other : spawner.getSpawns()){
|
||||
out.add(other.array());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PositionTarget extends Flowfield {
|
||||
public final Position position;
|
||||
|
||||
public PositionTarget(Position position){
|
||||
this.position = position;
|
||||
this.refreshRate = 900;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPositions(IntSeq out){
|
||||
out.add(world.packArray(World.toTile(position.getX()), World.toTile(position.getY())));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data for a flow field to some set of destinations.
|
||||
* Concrete subclasses must specify a way to fetch costs and destinations.
|
||||
*/
|
||||
public static abstract class Flowfield{
|
||||
/** Refresh rate in milliseconds. Return any number <= 0 to disable. */
|
||||
protected int refreshRate;
|
||||
/** Team this path is for. Set before using. */
|
||||
protected Team team = Team.derelict;
|
||||
/** Function for calculating path cost. Set before using. */
|
||||
protected PathCost cost = costTypes.get(costGround);
|
||||
|
||||
/** costs of getting to a specific tile */
|
||||
public int[] weights;
|
||||
/** search IDs of each position - the highest, most recent search is prioritized and overwritten */
|
||||
public int[] searches;
|
||||
/** search frontier, these are Pos objects */
|
||||
IntQueue frontier = new IntQueue();
|
||||
/** all target positions; these positions have a cost of 0, and must be synchronized on! */
|
||||
final IntSeq targets = new IntSeq();
|
||||
/** current search ID */
|
||||
int search = 1;
|
||||
/** last updated time */
|
||||
long lastUpdateTime;
|
||||
/** whether this flow field is ready to be used */
|
||||
boolean initialized;
|
||||
|
||||
void setup(int length){
|
||||
this.weights = new int[length];
|
||||
this.searches = new int[length];
|
||||
this.frontier.ensureCapacity((length) / 4);
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
protected boolean passable(int pos){
|
||||
return cost.getCost(team.id, SVars.pathfinder.tiles[pos]) != impassable;
|
||||
}
|
||||
|
||||
/** Gets targets to pathfind towards. This must run on the main thread. */
|
||||
protected abstract void getPositions(IntSeq out);
|
||||
}
|
||||
|
||||
public interface PathCost{
|
||||
int getCost(int team, int tile);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import mindustry.ui.dialogs.*;
|
||||
import static arc.Core.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class SettingS {
|
||||
public class Setting {
|
||||
public static SettingsMenuDialog.SettingsTable sharset;
|
||||
|
||||
public static void addGraphicCheckSetting(String key, boolean def, Seq<SharSetting> list){
|
||||
@@ -151,3 +151,17 @@ public class SettingS {
|
||||
});
|
||||
}
|
||||
}
|
||||
abstract class SharSetting extends SettingsMenuDialog.SettingsTable.Setting {
|
||||
|
||||
public SharSetting(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public SharSetting(String name, Object def) {
|
||||
this(name);
|
||||
Core.settings.defaults(name, def);
|
||||
}
|
||||
|
||||
public void add(Table table) { }
|
||||
public void add(SettingsMenuDialog.SettingsTable table) { }
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package informatis.core;
|
||||
|
||||
import arc.Core;
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.ui.dialogs.SettingsMenuDialog;
|
||||
|
||||
public abstract class SharSetting extends SettingsMenuDialog.SettingsTable.Setting {
|
||||
|
||||
public SharSetting(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public SharSetting(String name, Object def) {
|
||||
this(name);
|
||||
Core.settings.defaults(name, def);
|
||||
}
|
||||
|
||||
public void add(Table table) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(SettingsMenuDialog.SettingsTable table) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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){}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user