Automatic conveyor/conduit bridging

This commit is contained in:
Anuken
2021-02-22 10:15:40 -05:00
parent 9e8a2b8296
commit e2515fc4bf
8 changed files with 95 additions and 18 deletions

View File

@@ -30,11 +30,10 @@ import mindustry.net.*;
import mindustry.type.*;
import mindustry.ui.fragments.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.ConstructBlock.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.distribution.*;
import mindustry.world.blocks.payloads.*;
import mindustry.world.blocks.power.*;
import mindustry.world.blocks.storage.CoreBlock.*;
import mindustry.world.meta.*;
@@ -771,7 +770,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Draw.reset();
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
Draw.alpha(1f);
request.block.drawRequestConfigTop(request, selectRequests);
request.block.drawRequestConfigTop(request, cons -> {
selectRequests.each(cons);
lineRequests.each(cons);
});
Draw.reset();
}
@@ -859,7 +861,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
req.animScale = 1f;
lineRequests.add(req);
});
block.handlePlacementLine(lineRequests);
if(Core.settings.getBool("blockreplace")){
lineRequests.each(req -> {
@@ -868,6 +869,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
req.block = replace;
}
});
block.handlePlacementLine(lineRequests);
}
}

View File

@@ -314,6 +314,7 @@ public class MobileInput extends InputHandler implements GestureListener{
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation) && getRequest(request.x, request.y, request.block.size, null) == null);
drawSelected(request.x, request.y, request.block, Pal.accent);
}
lineRequests.each(this::drawOverRequest);
}else if(mode == breaking){
drawBreakSelection(lineStartX, lineStartY, tileX, tileY);
}

View File

@@ -6,12 +6,14 @@ import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.pooling.*;
import mindustry.entities.units.*;
import mindustry.world.*;
import mindustry.world.blocks.distribution.*;
import static mindustry.Vars.*;
public class Placement{
private static final Seq<BuildPlan> plans1 = new Seq<>();
private static final Seq<Point2> tmpPoints = new Seq<>(), tmpPoints2 = new Seq<>();
private static final NormalizeResult result = new NormalizeResult();
private static final NormalizeDrawResult drawResult = new NormalizeDrawResult();
@@ -75,7 +77,7 @@ public class Placement{
var base = tmpPoints2;
var result = tmpPoints.clear();
base.selectFrom(points, p -> p == points.first() || p == points.peek() || Build.validPlace(block, player.team(), p.x, p.y, rotation, false));
base.selectFrom(points, p -> p == points.first() || p == points.peek() || Build.validPlace(block, player.team(), p.x, p.y, rotation));
boolean addedLast = false;
outer:
@@ -106,6 +108,59 @@ public class Placement{
points.addAll(result);
}
public static void calculateBridges(Seq<BuildPlan> plans, ItemBridge bridge){
//check for orthogonal placement + unlocked state
if(!(plans.first().x == plans.peek().x || plans.first().y == plans.peek().y || !bridge.unlockedNow())){
return;
}
var result = plans1.clear();
var team = player.team();
outer:
for(int i = 0; i < plans.size;){
var cur = plans.get(i);
result.add(cur);
//gap found
if(i < plans.size - 1 && cur.placeable(team) && !plans.get(i + 1).placeable(team)){
//find the closest valid position within range
for(int j = i + 1; j < plans.size; j++){
var other = plans.get(j);
//out of range now, set to current position and keep scanning forward for next occurrence
if(!bridge.positionsValid(cur.x, cur.y, other.x, other.y)){
//add 'missed' conveyors
for(int k = i + 1; k < j; k++){
result.add(plans.get(k));
}
i = j;
continue outer;
}else if(other.placeable(team)){
//found a link, assign bridges
cur.block = bridge;
other.block = bridge;
cur.config = new Point2(other.x - cur.x, other.y - cur.y);
i = j;
continue outer;
}
}
//if it got here, that means nothing was found. this likely means there's a bunch of stuff at the end; add it and bail out
for(int j = i + 1; j < plans.size; j++){
result.add(plans.get(j));
}
break;
}else{
i ++;
}
}
plans.set(result);
}
private static float tileHeuristic(Tile tile, Tile other){
Block block = control.input.block;