Campaign balance / Smarter power node placement

This commit is contained in:
Anuken
2020-11-24 16:33:36 -05:00
parent 6fd36d97f0
commit bcaf5e4c3d
8 changed files with 44 additions and 46 deletions

View File

@@ -47,6 +47,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
/** Maximum line length. */
final static int maxLength = 100;
final static Rect r1 = new Rect(), r2 = new Rect();
final static Seq<Point2> tmpPoints = new Seq<>(), tmpPoints2 = new Seq<>();
public final OverlayFragment frag = new OverlayFragment();
@@ -1164,27 +1165,39 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
points = Placement.normalizeLine(startX, startY, endX, endY);
}
if(block instanceof PowerNode){
Seq<Point2> skip = new Seq<>();
if(block instanceof PowerNode node){
var base = tmpPoints2;
var result = tmpPoints.clear();
for(int i = 1; i < points.size; i++){
int overlaps = 0;
Point2 point = points.get(i);
base.selectFrom(points, p -> p == points.first() || p == points.peek() || Build.validPlace(block, player.team(), p.x, p.y, rotation, false));
boolean addedLast = false;
//check with how many powernodes the *next* tile will overlap
for(int j = 0; j < i; j++){
if(!skip.contains(points.get(j)) && ((PowerNode)block).overlaps(world.tile(point.x, point.y), world.tile(points.get(j).x, points.get(j).y))){
overlaps++;
outer:
for(int i = 0; i < base.size;){
var point = base.get(i);
result.add(point);
if(i == base.size - 1) addedLast = true;
//find the furthest node that overlaps this one
for(int j = base.size - 1; j > i; j--){
var other = base.get(j);
boolean over = node.overlaps(world.tile(point.x, point.y), world.tile(other.x, other.y));
if(over){
//add node to list and start searching for node that overlaps the next one
i = j;
continue outer;
}
}
//if it's more than one, it can bridge the gap
if(overlaps > 1){
skip.add(points.get(i-1));
}
//if it got here, that means nothing was found. try to proceed to the next node anyway
i ++;
}
//remove skipped points
points.removeAll(skip);
if(!addedLast) result.add(base.peek());
points.clear();
points.addAll(result);
}
float angle = Angles.angle(startX, startY, endX, endY);

View File

@@ -241,35 +241,10 @@ public class Placement{
}
public static class NormalizeDrawResult{
float x, y, x2, y2;
public float x, y, x2, y2;
}
public static class NormalizeResult{
public int x, y, x2, y2, rotation;
boolean isX(){
return Math.abs(x2 - x) > Math.abs(y2 - y);
}
/**
* Returns length of greater edge of the selection.
*/
int getLength(){
return Math.max(x2 - x, y2 - y);
}
/**
* Returns the X position of a specific index along this area as a line.
*/
int getScaledX(int i){
return x + (x2 - x > y2 - y ? i : 0);
}
/**
* Returns the Y position of a specific index along this area as a line.
*/
int getScaledY(int i){
return y + (x2 - x > y2 - y ? 0 : i);
}
}
}