Skip to content

Commit

Permalink
Fix segments not forming when bridges are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Mars committed Apr 10, 2023
1 parent 0ed1300 commit 99a3dd6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/me/mars/Bridges.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import arc.graphics.g2d.Draw;
import arc.input.KeyCode;
import arc.math.Mathf;
import arc.math.geom.Geometry;
import arc.math.geom.Point2;
import arc.math.geom.Rect;
import arc.math.geom.Vec2;
Expand All @@ -15,6 +16,7 @@
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.ImageButton;
import arc.struct.IntIntMap;
import arc.struct.IntSeq;
import arc.struct.Seq;
import arc.util.*;
import mindustry.Vars;
Expand Down Expand Up @@ -251,9 +253,10 @@ static void bridgeBuilt(ItemBridgeBuild bridge) {
queue.add(() -> {
// Form for incoming
Seq<Segment> intersected = new Seq<>();
for (int i = 0; i < bridge.incoming.size; i++) {
IntSeq incoming = allIncoming(bridge);
for (int i = 0; i < incoming.size; i++) {
intersected.clear();
int pos = bridge.incoming.items[i];
int pos = incoming.items[i];
both(tree -> tree.intersect(Point2.x(pos), Point2.y(pos), 1, 1, intersected));
intersected.each(Bridges::updateEnd);
formSegment(pos);
Expand Down Expand Up @@ -347,6 +350,22 @@ public static void reloadSegments() {
Log.info("Segments reloaded in @ ms, @/@ segments total",
Time.elapsed(), allSegments.count(segment -> segment.start.team == Vars.player.team()), allSegments.size);
}
private static IntSeq allIncoming(ItemBridgeBuild bridge) {
ItemBridge block = (ItemBridge)bridge.block;
IntSeq ret = new IntSeq();
int x = bridge.tileX(), y = bridge.tileY();
int range = block.range;
for (int d = 0; d < 4; d++) {
for (int i = 1; i-1 < range; i++) {
int cx = x + Geometry.d4x(d)*i, cy = y + Geometry.d4y(d)*i;
if (block.linkValid(bridge.tile, world.tile(cx, cy), false)) {
ItemBridgeBuild inc = (ItemBridgeBuild) world.build(cx, cy);
if (inc.link == bridge.pos()) ret.add(Point2.pack(cx, cy));
}
}
}
return ret;
}

public static boolean linkValid(ItemBridgeBuild build) {
return ((ItemBridge)build.block).linkValid(build.tile, Vars.world.tile(build.link));
Expand Down

0 comments on commit 99a3dd6

Please sign in to comment.