🐬 Factorio flavoured powerlines (#997)

* 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 12753a9b5c.

* Slight cleanup

* Subtract conveyor placement

* Refractor each to for

* Apply @anuke’s coding stype
This commit is contained in:
Patrick 'Quezler' Mounier
2019-11-08 18:28:49 +01:00
committed by Anuken
parent 8b2934c60e
commit f58eb75639
2 changed files with 37 additions and 0 deletions

View File

@ -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<PlaceLine> cons){
Array<Point2> 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<Point2> 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){

View File

@ -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;