Conveyor upgrade system (#3912)
* conveyor/conduit upgrading system * style
This commit is contained in:
@@ -32,6 +32,7 @@ import mindustry.ui.fragments.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.ConstructBlock.*;
|
||||
import mindustry.world.blocks.distribution.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.blocks.power.*;
|
||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||
@@ -1161,7 +1162,15 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
|
||||
if(diagonal){
|
||||
points = Placement.pathfindLine(block != null && block.conveyorPlacement, startX, startY, endX, endY);
|
||||
Tile start = world.tile(startX, startY);
|
||||
Tile end = world.tile(endX, endY);
|
||||
if(block != null && block instanceof Autotiler
|
||||
&& start.build instanceof ChainedBuilding && end.build instanceof ChainedBuilding
|
||||
&& block.canReplace(end.build.block) && block.canReplace(start.build.block)){
|
||||
points = Placement.upgradeLine(startX, startY, endX, endY);
|
||||
}else{
|
||||
points = Placement.pathfindLine(block != null && block.conveyorPlacement, startX, startY, endX, endY);
|
||||
}
|
||||
}else{
|
||||
points = Placement.normalizeLine(startX, startY, endX, endY);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.pooling.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.distribution.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -23,7 +25,6 @@ public class Placement{
|
||||
/** Normalize a diagonal line into points. */
|
||||
public static Seq<Point2> pathfindLine(boolean conveyors, int startX, int startY, int endX, int endY){
|
||||
Pools.freeAll(points);
|
||||
|
||||
points.clear();
|
||||
if(conveyors && Core.settings.getBool("conveyorpathfinding")){
|
||||
if(astar(startX, startY, endX, endY)){
|
||||
@@ -54,6 +55,20 @@ public class Placement{
|
||||
return points;
|
||||
}
|
||||
|
||||
public static Seq<Point2> upgradeLine(int startX, int startY, int endX, int endY){
|
||||
Pools.freeAll(points);
|
||||
points.clear();
|
||||
Building building = world.tile(startX, startY).build;
|
||||
points.add(Pools.obtain(Point2.class, Point2::new).set(startX, startY));
|
||||
while(building.tile.x != endX || building.tile.y != endY){
|
||||
ChainedBuilding chained = (ChainedBuilding)building;
|
||||
if(chained.next() == null) return pathfindLine(true, startX, startY, endX, endY);
|
||||
building = chained.next();
|
||||
points.add(Pools.obtain(Point2.class, Point2::new).set(building.tile.x, building.tile.y));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
private static float tileHeuristic(Tile tile, Tile other){
|
||||
Block block = control.input.block;
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import mindustry.gen.*;
|
||||
|
||||
public interface ChainedBuilding{
|
||||
Building next();
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
Mathf.mod(req.tile().build.rotation - req.rotation, 2) == 1 ? Blocks.junction : this;
|
||||
}
|
||||
|
||||
public class ConveyorBuild extends Building{
|
||||
public class ConveyorBuild extends Building implements ChainedBuilding{
|
||||
//parallel array data
|
||||
public Item[] ids = new Item[capacity];
|
||||
public float[] xs = new float[capacity];
|
||||
@@ -391,5 +391,11 @@ public class Conveyor extends Block implements Autotiler{
|
||||
|
||||
len--;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Building next(){
|
||||
return nextc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.distribution.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -73,7 +74,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
return new TextureRegion[]{Core.atlas.find("conduit-bottom"), topRegions[0]};
|
||||
}
|
||||
|
||||
public class ConduitBuild extends LiquidBuild{
|
||||
public class ConduitBuild extends LiquidBuild implements ChainedBuilding{
|
||||
public float smoothLiquid;
|
||||
public int blendbits, xscl, yscl, blending;
|
||||
|
||||
@@ -137,5 +138,15 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
sleep();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Building next(){
|
||||
Tile next = tile.nearby(rotation);
|
||||
if(next != null && next.build instanceof ConduitBuild){
|
||||
return next.build;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user