Automatic conveyor/conduit bridging
This commit is contained in:
@@ -62,6 +62,10 @@ public class BuildPlan implements Position{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean placeable(Team team){
|
||||||
|
return Build.validPlace(block, team, x, y, rotation);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isRotation(Team team){
|
public boolean isRotation(Team team){
|
||||||
if(breaking) return false;
|
if(breaking) return false;
|
||||||
Tile tile = tile();
|
Tile tile = tile();
|
||||||
|
|||||||
@@ -30,11 +30,10 @@ import mindustry.net.*;
|
|||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.ui.fragments.*;
|
import mindustry.ui.fragments.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.*;
|
|
||||||
import mindustry.world.blocks.ConstructBlock.*;
|
import mindustry.world.blocks.ConstructBlock.*;
|
||||||
|
import mindustry.world.blocks.*;
|
||||||
import mindustry.world.blocks.distribution.*;
|
import mindustry.world.blocks.distribution.*;
|
||||||
import mindustry.world.blocks.payloads.*;
|
import mindustry.world.blocks.payloads.*;
|
||||||
import mindustry.world.blocks.power.*;
|
|
||||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
@@ -771,7 +770,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
Draw.reset();
|
Draw.reset();
|
||||||
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
|
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
|
||||||
Draw.alpha(1f);
|
Draw.alpha(1f);
|
||||||
request.block.drawRequestConfigTop(request, selectRequests);
|
request.block.drawRequestConfigTop(request, cons -> {
|
||||||
|
selectRequests.each(cons);
|
||||||
|
lineRequests.each(cons);
|
||||||
|
});
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -859,7 +861,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
req.animScale = 1f;
|
req.animScale = 1f;
|
||||||
lineRequests.add(req);
|
lineRequests.add(req);
|
||||||
});
|
});
|
||||||
block.handlePlacementLine(lineRequests);
|
|
||||||
|
|
||||||
if(Core.settings.getBool("blockreplace")){
|
if(Core.settings.getBool("blockreplace")){
|
||||||
lineRequests.each(req -> {
|
lineRequests.each(req -> {
|
||||||
@@ -868,6 +869,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
req.block = replace;
|
req.block = replace;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
block.handlePlacementLine(lineRequests);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
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);
|
drawSelected(request.x, request.y, request.block, Pal.accent);
|
||||||
}
|
}
|
||||||
|
lineRequests.each(this::drawOverRequest);
|
||||||
}else if(mode == breaking){
|
}else if(mode == breaking){
|
||||||
drawBreakSelection(lineStartX, lineStartY, tileX, tileY);
|
drawBreakSelection(lineStartX, lineStartY, tileX, tileY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import arc.math.*;
|
|||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.pooling.*;
|
import arc.util.pooling.*;
|
||||||
|
import mindustry.entities.units.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.distribution.*;
|
import mindustry.world.blocks.distribution.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class Placement{
|
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 Seq<Point2> tmpPoints = new Seq<>(), tmpPoints2 = new Seq<>();
|
||||||
private static final NormalizeResult result = new NormalizeResult();
|
private static final NormalizeResult result = new NormalizeResult();
|
||||||
private static final NormalizeDrawResult drawResult = new NormalizeDrawResult();
|
private static final NormalizeDrawResult drawResult = new NormalizeDrawResult();
|
||||||
@@ -75,7 +77,7 @@ public class Placement{
|
|||||||
var base = tmpPoints2;
|
var base = tmpPoints2;
|
||||||
var result = tmpPoints.clear();
|
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;
|
boolean addedLast = false;
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
@@ -106,6 +108,59 @@ public class Placement{
|
|||||||
points.addAll(result);
|
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){
|
private static float tileHeuristic(Tile tile, Tile other){
|
||||||
Block block = control.input.block;
|
Block block = control.input.block;
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class LoadoutDialog extends BaseDialog{
|
|||||||
|
|
||||||
public void maxItems() {
|
public void maxItems() {
|
||||||
for(ItemStack stack : stacks){
|
for(ItemStack stack : stacks){
|
||||||
stack.amount = total == null ? capacity : Math.min(capacity, total.get(stack.item));
|
stack.amount = total == null ? capacity : Math.max(Math.min(capacity, total.get(stack.item)), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import mindustry.content.*;
|
|||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
|
import mindustry.input.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
@@ -71,6 +72,17 @@ public class Conveyor extends Block implements Autotiler{
|
|||||||
&& lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock);
|
&& lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//stack conveyors should be bridged over, not replaced
|
||||||
|
@Override
|
||||||
|
public boolean canReplace(Block other){
|
||||||
|
return super.canReplace(other) && !(other instanceof StackConveyor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handlePlacementLine(Seq<BuildPlan> plans){
|
||||||
|
Placement.calculateBridges(plans, (ItemBridge)Blocks.itemBridge);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextureRegion[] icons(){
|
public TextureRegion[] icons(){
|
||||||
return new TextureRegion[]{regions[0][0]};
|
return new TextureRegion[]{regions[0][0]};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package mindustry.world.blocks.distribution;
|
package mindustry.world.blocks.distribution;
|
||||||
|
|
||||||
import arc.*;
|
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
@@ -32,10 +31,7 @@ public class ItemBridge extends Block{
|
|||||||
public @Load("@-arrow") TextureRegion arrowRegion;
|
public @Load("@-arrow") TextureRegion arrowRegion;
|
||||||
|
|
||||||
//for autolink
|
//for autolink
|
||||||
@Nullable
|
public @Nullable ItemBridgeBuild lastBuild;
|
||||||
public ItemBridgeBuild lastBuild;
|
|
||||||
@Nullable
|
|
||||||
public BuildPlan lastPlan;
|
|
||||||
|
|
||||||
public ItemBridge(String name){
|
public ItemBridge(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -151,12 +147,12 @@ public class ItemBridge extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewPlan(BuildPlan plan){
|
public void handlePlacementLine(Seq<BuildPlan> plans){
|
||||||
if(lastPlan != null && lastPlan.config == null && positionsValid(lastPlan.x, lastPlan.y, plan.x, plan.y)){
|
for(int i = 0; i < plans.size - 1; i++){
|
||||||
lastPlan.config = new Point2(plan.x - lastPlan.x, plan.y - lastPlan.y);
|
var cur = plans.get(i);
|
||||||
|
var next = plans.get(i + 1);
|
||||||
|
cur.config = new Point2(next.x - cur.x, next.y - cur.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPlan = plan;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,12 +172,12 @@ public class ItemBridge extends Block{
|
|||||||
public void playerPlaced(Object config){
|
public void playerPlaced(Object config){
|
||||||
super.playerPlaced(config);
|
super.playerPlaced(config);
|
||||||
|
|
||||||
if(config == null){
|
//if(config == null){
|
||||||
Tile link = findLink(tile.x, tile.y);
|
Tile link = findLink(tile.x, tile.y);
|
||||||
if(linkValid(tile, link) && !proximity.contains(link.build)){
|
if(linkValid(tile, link) && !proximity.contains(link.build)){
|
||||||
link.build.configure(tile.pos());
|
link.build.configure(tile.pos());
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
|
|
||||||
lastBuild = this;
|
lastBuild = this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import mindustry.content.*;
|
|||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
|
import mindustry.input.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
import mindustry.world.blocks.*;
|
import mindustry.world.blocks.*;
|
||||||
@@ -69,6 +70,11 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
|||||||
return otherblock.hasLiquids && (otherblock.outputsLiquid || (lookingAt(tile, rotation, otherx, othery, otherblock))) && lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock);
|
return otherblock.hasLiquids && (otherblock.outputsLiquid || (lookingAt(tile, rotation, otherx, othery, otherblock))) && lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handlePlacementLine(Seq<BuildPlan> plans){
|
||||||
|
Placement.calculateBridges(plans, (ItemBridge)Blocks.bridgeConduit);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextureRegion[] icons(){
|
public TextureRegion[] icons(){
|
||||||
return new TextureRegion[]{Core.atlas.find("conduit-bottom"), topRegions[0]};
|
return new TextureRegion[]{Core.atlas.find("conduit-bottom"), topRegions[0]};
|
||||||
|
|||||||
Reference in New Issue
Block a user