Hook onto convejor pathfinding

This commit is contained in:
Patrick 'Quezler' Mounier
2019-11-05 08:11:58 +01:00
parent 645ff56096
commit 20e1af3c99
4 changed files with 33 additions and 32 deletions

View File

@@ -535,28 +535,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
});
}
final int[] i = {0};
lineRequests.each(req -> {
if(!(req.block instanceof PowerNode)) return;
if(i[0]++ == 0 || i[0] == lineRequests.size){
// beginning & end should always be placed
}else{
// check with how many powernodes the *next* tile will overlap
int overlaps = 0;
for(int j = 0; j < i[0]; j++){
if (((PowerNode) req.block).overlaps(lineRequests.get(i[0]).tile(), lineRequests.get(j).tile()) && lineRequests.get(j).block instanceof PowerNode){
overlaps++;
}
}
// if its more than two it can bridge the gap
if(overlaps > 1){
req.block = Blocks.air;
}
}
});
}
protected void updateLine(int x1, int y1){
@@ -830,21 +808,46 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Array<Point2> points;
boolean diagonal = Core.input.keyDown(Binding.diagonal_placement);
// place powernodes diagonally by default
if((block != null && block.powernodePlacement)){
diagonal = !diagonal;
}
if(Core.settings.getBool("swapdiagonal") && mobile){
diagonal = !diagonal;
}
if(diagonal){
points = Placement.pathfindLine(block != null && block.conveyorPlacement, block != null && block.powernodePlacement, startX, startY, endX, endY);
points = Placement.pathfindLine(block != null && block.conveyorPlacement, startX, startY, endX, endY);
}else{
points = Placement.normalizeLine(startX, startY, endX, endY);
}
Array<Point2> skip = new Array<>();
if(block instanceof PowerNode){
final int[] i = {0};
points.each(req -> {
if(i[0]++ == 0 || i[0] == points.size){
// beginning & end should always be placed
}else{
// check with how many powernodes the *next* tile will overlap
int overlaps = 0;
for(int j = 0; j < i[0]; j++){
// skip powernodes we have already crossed off as air
if(skip.contains(points.get(j))) continue;
Tile next = world.ltile(points.get(i[0]).x, points.get(i[0]).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[0]-1));
}
}
});
}
points.removeAll(skip);
float angle = Angles.angle(startX, startY, endX, endY);
int baseRotation = rotation;
if(!overrideLineRotation || diagonal){

View File

@@ -22,7 +22,7 @@ public class Placement{
private static IntSet closed = new IntSet();
/** Normalize a diagonal line into points. */
public static Array<Point2> pathfindLine(boolean conveyors, boolean powernodes, int startX, int startY, int endX, int endY){
public static Array<Point2> pathfindLine(boolean conveyors, int startX, int startY, int endX, int endY){
Pools.freeAll(points);
points.clear();

View File

@@ -93,8 +93,6 @@ public class Block extends BlockStorage{
public boolean posConfig;
/** Whether this block uses conveyor-type placement mode.*/
public boolean conveyorPlacement;
/** Whether this block uses powernode-type placement mode.*/
public boolean powernodePlacement;
/**
* The color of this block when displayed on the minimap or map preview.
* Do not set manually! This is overriden when loading for most blocks.

View File

@@ -32,7 +32,7 @@ public class PowerNode extends PowerBlock{
configurable = true;
consumesPower = false;
outputsPower = false;
powernodePlacement = true;
conveyorPlacement = true;
}
@Override