Added allowRectanglePlacement for 1x1 blocks
This commit is contained in:
@@ -1973,11 +1973,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
var end = world.build(endX, endY);
|
var end = world.build(endX, endY);
|
||||||
if(diagonal && (block == null || block.allowDiagonal)){
|
if(diagonal && (block == null || block.allowDiagonal)){
|
||||||
if(block != null && start instanceof ChainedBuilding && end instanceof ChainedBuilding
|
if(block != null && start instanceof ChainedBuilding && end instanceof ChainedBuilding
|
||||||
&& block.canReplace(end.block) && block.canReplace(start.block)){
|
&& block.canReplace(end.block) && block.canReplace(start.block)){
|
||||||
points = Placement.upgradeLine(startX, startY, endX, endY);
|
points = Placement.upgradeLine(startX, startY, endX, endY);
|
||||||
}else{
|
}else{
|
||||||
points = Placement.pathfindLine(block != null && block.conveyorPlacement, startX, startY, endX, endY);
|
points = Placement.pathfindLine(block != null && block.conveyorPlacement, startX, startY, endX, endY);
|
||||||
}
|
}
|
||||||
|
}else if(block != null && block.size == 1 && block.allowRectanglePlacement){
|
||||||
|
points = Placement.normalizeRectangle(startX, startY, endX, endY, block.size);
|
||||||
}else{
|
}else{
|
||||||
points = Placement.normalizeLine(startX, startY, endX, endY);
|
points = Placement.normalizeLine(startX, startY, endX, endY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,22 @@ public class Placement{
|
|||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Normalize two points into a rectangle. */
|
||||||
|
public static Seq<Point2> normalizeRectangle(int startX, int startY, int endX, int endY, int blockSize){
|
||||||
|
Pools.freeAll(points);
|
||||||
|
points.clear();
|
||||||
|
|
||||||
|
int minX = Math.min(startX, endX), minY = Math.min(startY, endY), maxX = Math.max(startX, endX), maxY = Math.max(startY, endY);
|
||||||
|
|
||||||
|
for(int y = minY; y <= maxY; y += blockSize){
|
||||||
|
for(int x = minX; x <= maxX; x += blockSize){
|
||||||
|
points.add(Pools.obtain(Point2.class, Point2::new).set(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
public static Seq<Point2> upgradeLine(int startX, int startY, int endX, int endY){
|
public static Seq<Point2> upgradeLine(int startX, int startY, int endX, int endY){
|
||||||
closed.clear();
|
closed.clear();
|
||||||
Pools.freeAll(points);
|
Pools.freeAll(points);
|
||||||
|
|||||||
@@ -245,6 +245,8 @@ public class Block extends UnlockableContent implements Senseable{
|
|||||||
public boolean allowDiagonal = true;
|
public boolean allowDiagonal = true;
|
||||||
/** Whether to swap the diagonal placement modes. */
|
/** Whether to swap the diagonal placement modes. */
|
||||||
public boolean swapDiagonalPlacement;
|
public boolean swapDiagonalPlacement;
|
||||||
|
/** Whether to allow rectangular placement, as opposed to a line. Only supported for 1x1 blocks currently! */
|
||||||
|
public boolean allowRectanglePlacement = false;
|
||||||
/** Build queue priority in schematics. */
|
/** Build queue priority in schematics. */
|
||||||
public int schematicPriority = 0;
|
public int schematicPriority = 0;
|
||||||
/**
|
/**
|
||||||
@@ -322,6 +324,8 @@ public class Block extends UnlockableContent implements Senseable{
|
|||||||
public float deconstructThreshold = 0f;
|
public float deconstructThreshold = 0f;
|
||||||
/** If true, this block deconstructs immediately. Instant deconstruction implies no resource refund. */
|
/** If true, this block deconstructs immediately. Instant deconstruction implies no resource refund. */
|
||||||
public boolean instantDeconstruct = false;
|
public boolean instantDeconstruct = false;
|
||||||
|
/** If true, this block constructs immediately. This implies no resource requirement, and ignores configs - do not use, this is for performance only! */
|
||||||
|
public boolean instantBuild = false;
|
||||||
/** Effect for placing the block. Passes size as rotation. */
|
/** Effect for placing the block. Passes size as rotation. */
|
||||||
public Effect placeEffect = Fx.placeBlock;
|
public Effect placeEffect = Fx.placeBlock;
|
||||||
/** Effect for breaking the block. Passes size as rotation. */
|
/** Effect for breaking the block. Passes size as rotation. */
|
||||||
|
|||||||
@@ -122,6 +122,14 @@ public class Build{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//complete it immediately
|
||||||
|
if(result.instantBuild){
|
||||||
|
Events.fire(new BlockBuildBeginEvent(tile, team, unit, false));
|
||||||
|
result.placeBegan(tile, tile.block, unit);
|
||||||
|
ConstructBlock.constructFinish(tile, result, unit, (byte)rotation, team, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Block previous = tile.block();
|
Block previous = tile.block();
|
||||||
Block sub = ConstructBlock.get(result.size);
|
Block sub = ConstructBlock.get(result.size);
|
||||||
var prevBuild = new Seq<Building>(9);
|
var prevBuild = new Seq<Building>(9);
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class ConstructBlock extends Block{
|
|||||||
tile.setBlock(block, team, rotation);
|
tile.setBlock(block, team, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tile.build != null){
|
if(tile.build != null && tile.build.block == block){
|
||||||
tile.build.health = block.health * healthf;
|
tile.build.health = block.health * healthf;
|
||||||
|
|
||||||
if(config != null){
|
if(config != null){
|
||||||
@@ -100,11 +100,11 @@ public class ConstructBlock extends Block{
|
|||||||
|
|
||||||
//make sure block indexer knows it's damaged
|
//make sure block indexer knows it's damaged
|
||||||
indexer.notifyHealthChanged(tile.build);
|
indexer.notifyHealthChanged(tile.build);
|
||||||
}
|
|
||||||
|
|
||||||
//last builder was this local client player, call placed()
|
//last builder was this local client player, call placed()
|
||||||
if(tile.build != null && !headless && builder == player.unit()){
|
if(!headless && builder == player.unit()){
|
||||||
tile.build.playerPlaced(config);
|
tile.build.playerPlaced(config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fogControl.isVisibleTile(team, tile.x, tile.y)){
|
if(fogControl.isVisibleTile(team, tile.x, tile.y)){
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ public class Floor extends Block{
|
|||||||
super(name);
|
super(name);
|
||||||
this.variants = variants;
|
this.variants = variants;
|
||||||
placeableLiquid = true;
|
placeableLiquid = true;
|
||||||
|
allowRectanglePlacement = true;
|
||||||
|
instantBuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public class StaticWall extends Prop{
|
|||||||
solid = true;
|
solid = true;
|
||||||
variants = 2;
|
variants = 2;
|
||||||
cacheLayer = CacheLayer.walls;
|
cacheLayer = CacheLayer.walls;
|
||||||
|
allowRectanglePlacement = true;
|
||||||
|
instantBuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user