1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-11 03:31:19 +03:00

Generic node/bridge placement system

This commit is contained in:
Anuken 2020-12-18 12:41:13 -05:00
parent d80678dfeb
commit bd25294096
7 changed files with 56 additions and 35 deletions

View File

@ -989,9 +989,9 @@ public class Blocks implements ContentList{
}};
itemBridge = new BufferedItemBridge("bridge-conveyor"){{
requirements(Category.distribution, with(Items.lead, 4, Items.copper, 4));
requirements(Category.distribution, with(Items.lead, 6, Items.copper, 6));
range = 4;
speed = 70f;
speed = 74f;
bufferCapacity = 14;
}};

View File

@ -1,6 +1,7 @@
package mindustry.input;
import arc.*;
import arc.func.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
@ -11,6 +12,7 @@ import mindustry.world.blocks.distribution.*;
import static mindustry.Vars.*;
public class Placement{
private final static Seq<Point2> tmpPoints = new Seq<>(), tmpPoints2 = new Seq<>();
private static final NormalizeResult result = new NormalizeResult();
private static final NormalizeDrawResult drawResult = new NormalizeDrawResult();
private static Bresenham2 bres = new Bresenham2();
@ -68,6 +70,42 @@ public class Placement{
return points;
}
/** Calculates optimal node placement for nodes with spacing. Used for bridges and power nodes. */
public static void calculateNodes(Seq<Point2> points, Block block, int rotation, Boolf2<Point2, Point2> overlapper){
var base = tmpPoints2;
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));
boolean addedLast = false;
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 = overlapper.get(point, other);
if(over){
//add node to list and start searching for node that overlaps the next one
i = j;
continue outer;
}
}
//if it got here, that means nothing was found. try to proceed to the next node anyway
i ++;
}
if(!addedLast) result.add(base.peek());
points.clear();
points.addAll(result);
}
private static float tileHeuristic(Tile tile, Tile other){
Block block = control.input.block;

View File

@ -62,7 +62,7 @@ public class PointDefenseTurret extends ReloadTurret{
//retarget
if(timer(timerTarget, retargetTime)){
target = Groups.bullet.intersect(x - range, y - range, range*2, range*2).min(b -> b.team == team || !b.type().hittable ? Float.MAX_VALUE : b.dst2(this));
target = Groups.bullet.intersect(x - range, y - range, range*2, range*2).min(b -> b.team != team && b.type().hittable, b -> b.dst2(this));
}
//pooled bullets

View File

@ -13,6 +13,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.input.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.meta.*;
@ -152,6 +153,11 @@ public class ItemBridge extends Block{
lastPlan = plan;
}
@Override
public void changePlacementPath(Seq<Point2> points, int rotation){
Placement.calculateNodes(points, this, rotation, (point, other) -> Math.max(Math.abs(point.x - other.x), Math.abs(point.y - other.y)) <= range);
}
public class ItemBridgeBuild extends Building{
public int link = -1;
public IntSet incoming = new IntSet();

View File

@ -14,6 +14,7 @@ import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.input.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.meta.*;
@ -153,38 +154,7 @@ public class PowerNode extends PowerBlock{
@Override
public void changePlacementPath(Seq<Point2> points, int rotation){
var base = tmpPoints2;
var result = tmpPoints.clear();
base.selectFrom(points, p -> p == points.first() || p == points.peek() || Build.validPlace(this, player.team(), p.x, p.y, rotation, false));
boolean addedLast = false;
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 = 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 got here, that means nothing was found. try to proceed to the next node anyway
i ++;
}
if(!addedLast) result.add(base.peek());
points.clear();
points.addAll(result);
Placement.calculateNodes(points, this, rotation, (point, other) -> overlaps(world.tile(point.x, point.y), world.tile(other.x, other.y)));
}
protected void setupColor(float satisfaction){

View File

@ -386,6 +386,13 @@ public class CoreBlock extends StorageBlock{
}else{
super.handleItem(source, item);
}
}else if(incinerate()){
if(items.get(item) >= storageCapacity){
//create item incineration effect at random intervals
if(!noEffect){
incinerateEffect(this, source);
}
}
}
}
}