From f58eb756394ea5cdf9d3a8677f3bbe384fef3e9d Mon Sep 17 00:00:00 2001 From: Patrick 'Quezler' Mounier Date: Fri, 8 Nov 2019 18:28:49 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=AC=20Factorio=20flavoured=20powerline?= =?UTF-8?q?s=20(#997)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Stash initial prototype * Fix 〃to connect the chain * Add comments * Hook onto convejor pathfinding * Cleanup remnant discovered via pull request diff * Toggle placement between diagonal and pathfinding * Stash questionable prototype * 〃 * Attempt to rewrite away the skip array * Revert "Attempt to rewrite away the skip array" This reverts commit 12753a9b5c8613f5f1edb2af5e06b3d40a3beef1. * Slight cleanup * Subtract conveyor placement * Refractor each to for * Apply @anuke’s coding stype --- .../anuke/mindustry/input/InputHandler.java | 33 +++++++++++++++++++ .../world/blocks/power/PowerNode.java | 4 +++ 2 files changed, 37 insertions(+) diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 16ecdb2e47..5cdbd60574 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -32,6 +32,7 @@ import io.anuke.mindustry.ui.fragments.*; import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.blocks.*; import io.anuke.mindustry.world.blocks.BuildBlock.*; +import io.anuke.mindustry.world.blocks.power.PowerNode; import java.util.*; @@ -806,16 +807,48 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ void iterateLine(int startX, int startY, int endX, int endY, Cons cons){ Array points; boolean diagonal = Core.input.keyDown(Binding.diagonal_placement); + if(Core.settings.getBool("swapdiagonal") && mobile){ diagonal = !diagonal; } + if(block instanceof PowerNode){ + diagonal = !diagonal; + } + if(diagonal){ points = Placement.pathfindLine(block != null && block.conveyorPlacement, startX, startY, endX, endY); }else{ points = Placement.normalizeLine(startX, startY, endX, endY); } + if(block instanceof PowerNode){ + Array skip = new Array<>(); + + for(int i = 1; i < points.size; i++){ + // check with how many powernodes the *next* tile will overlap + int overlaps = 0; + for(int j = 0; j < i; j++){ + // skip powernodes we have already crossed off as air + if(skip.contains(points.get(j))) continue; + + Tile next = world.ltile(points.get(i).x, points.get(i).y); + Tile loop = world.ltile(points.get(j).x, points.get(j).y); + + if(((PowerNode)block).overlaps(next, loop)){ + overlaps++; + } + } + + // if its more than one it can bridge the gap + if(overlaps > 1){ + skip.add(points.get(i-1)); + } + } + // remove the skipped points outside the each + points.removeAll(skip); + } + float angle = Angles.angle(startX, startY, endX, endY); int baseRotation = rotation; if(!overrideLineRotation || diagonal){ diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java index e9d922ba1d..c0f45be6ff 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -302,6 +302,10 @@ public class PowerNode extends PowerBlock{ return overlaps(src.drawx(), src.drawy(), other, range); } + public boolean overlaps(Tile src, Tile other){ + return overlaps(src.drawx(), src.drawy(), other, laserRange * tilesize); + } + protected void drawLaser(Tile tile, Tile target){ int opacityPercentage = Core.settings.getInt("lasersopacity"); if(opacityPercentage == 0) return;