Skip to content

Commit

Permalink
Improve node connection priority
Browse files Browse the repository at this point in the history
  • Loading branch information
zxtej committed Nov 30, 2024
1 parent e70e5ee commit 7177cce
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/src/mindustry/world/blocks/power/PowerNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import mindustry.ui.*;
import mindustry.ui.fragments.*;
import mindustry.world.*;
import mindustry.world.blocks.distribution.*;
import mindustry.world.meta.*;
import mindustry.world.modules.*;

Expand Down Expand Up @@ -223,6 +224,10 @@ public void getPotentialLinks(Tile tile, Team team, Cons<Building> others){
}

public void getPotentialLinks(Tile tile, Team team, Cons<Building> others, boolean skipExisting){
getPotentialLinks(tile, team, others, true, true);
}

public void getPotentialLinks(Tile tile, Team team, Cons<Building> others, boolean skipExisting, final boolean syncWithServer){
if(!autolink) return;

Boolf<Building> valid = other -> other != null && other.tile() != tile && other.block.connectedPower && other.power != null &&
Expand Down Expand Up @@ -264,6 +269,10 @@ public void getPotentialLinks(Tile tile, Team team, Cons<Building> others, boole
tempBuilds.sort((a, b) -> {
int type = -Boolean.compare(a.block instanceof PowerNode, b.block instanceof PowerNode);
if(type != 0) return type;
if(!syncWithServer && (type = Boolean.compare(
a instanceof ItemBridge.ItemBridgeBuild i && i.link == -1,
b instanceof ItemBridge.ItemBridgeBuild i && i.link == -1
)) != 0) return type;
return Float.compare(a.dst2(tile), b.dst2(tile));
});

Expand Down Expand Up @@ -403,7 +412,7 @@ public void placed(){
if(!power.links.contains(other.pos())){
configureAny(other.pos());
}
});
}, true, false);

super.placed();
}
Expand All @@ -429,7 +438,7 @@ public boolean onConfigureBuildTapped(Building other){
if(!insulated(this, link) && total[0] < maxNodes){
links[total[0]++] = new Point2(link.tileX() - tile.x, link.tileY() - tile.y);
}
});
}, true, false);
configure(Arrays.copyOfRange(links, 0, total[0]));
}else{ // Clear all links
configure(new Point2[0]);
Expand Down

0 comments on commit 7177cce

Please sign in to comment.