From ccdd94a0908b9cc648ddf65361c5a1a764a96653 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 25 Sep 2020 20:15:00 -0400 Subject: [PATCH] Build check cleanup --- core/src/mindustry/content/Blocks.java | 1 + core/src/mindustry/world/Block.java | 1 + core/src/mindustry/world/Build.java | 91 ++++++------------- .../mindustry/world/blocks/defense/Wall.java | 3 +- 4 files changed, 34 insertions(+), 62 deletions(-) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 6d4dc05687..41090e1de3 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1753,6 +1753,7 @@ public class Blocks implements ContentList{ }; size = 3; consumes.power(1.2f); + floating = true; }}; additiveReconstructor = new Reconstructor("additive-reconstructor"){{ diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 94fc221305..a8d32bcc19 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -369,6 +369,7 @@ public class Block extends UnlockableContent{ } public boolean canReplace(Block other){ + if(other.alwaysReplace) return true; return (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && size == other.size; } diff --git a/core/src/mindustry/world/Build.java b/core/src/mindustry/world/Build.java index 97666142e0..d0729f380f 100644 --- a/core/src/mindustry/world/Build.java +++ b/core/src/mindustry/world/Build.java @@ -90,68 +90,37 @@ public class Build{ return false; } - if(type.isMultiblock()){ - if(((type.canReplace(tile.block()) || tile.block.alwaysReplace) || (tile.block instanceof ConstructBlock && tile.bc().cblock == type)) && - type.canPlaceOn(tile, team) && tile.interactable(team)){ - - //if the block can be replaced but the sizes differ, check all the spaces around the block to make sure it can fit - if(type.size != tile.block().size){ - int offsetx = -(type.size - 1) / 2; - int offsety = -(type.size - 1) / 2; - - //this does not check *all* the conditions for placeability yet - for(int dx = 0; dx < type.size; dx++){ - for(int dy = 0; dy < type.size; dy++){ - int wx = dx + offsetx + x, wy = dy + offsety + y; - - Tile check = world.tile(wx, wy); - if(check == null || - (check.floor().isDeep() && !type.floating && !type.requiresWater && !type.placeableLiquid) || - !check.interactable(team) || - (!check.block.alwaysReplace && check.block != tile.block && !(check.block.size == 1 && type.canReplace(check.block)))) return false; - } - } - } - - //make sure that the new block can fit the old one - return type.bounds(x, y, Tmp.r1).grow(0.01f).contains(tile.block.bounds(tile.centerX(), tile.centerY(), Tmp.r2)); - } - - if(!type.requiresWater && !contactsShallows(tile.x, tile.y, type) && !type.placeableLiquid){ - return false; - } - - if(!type.canPlaceOn(tile, team)){ - return false; - } - - int offsetx = -(type.size - 1) / 2; - int offsety = -(type.size - 1) / 2; - for(int dx = 0; dx < type.size; dx++){ - for(int dy = 0; dy < type.size; dy++){ - Tile other = world.tile(x + dx + offsetx, y + dy + offsety); - if( - other == null || - !other.block().alwaysReplace || - !other.floor().placeableOn || - (other.floor().isDeep() && !type.floating && !type.requiresWater && !type.placeableLiquid) || - (type.requiresWater && tile.floor().liquidDrop != Liquids.water) - ){ - return false; - } - } - } - return true; - }else{ - return tile.interactable(team) - && (contactsShallows(tile.x, tile.y, type) || type.requiresWater || type.placeableLiquid) - && (!tile.floor().isDeep() || type.floating || type.requiresWater || type.placeableLiquid) - && tile.floor().placeableOn - && (!type.requiresWater || tile.floor().liquidDrop == Liquids.water) - && (((type.canReplace(tile.block()) || (tile.block instanceof ConstructBlock && tile.bc().cblock == type)) - && !(type == tile.block() && (tile.build != null && rotation == tile.build.rotation) && type.rotate)) || tile.block().alwaysReplace || tile.block() == Blocks.air) - && tile.block().isMultiblock() == type.isMultiblock() && type.canPlaceOn(tile, team); + if(!type.requiresWater && !contactsShallows(tile.x, tile.y, type) && !type.placeableLiquid){ + return false; } + + if(!type.canPlaceOn(tile, team)){ + return false; + } + + int offsetx = -(type.size - 1) / 2; + int offsety = -(type.size - 1) / 2; + + for(int dx = 0; dx < type.size; dx++){ + for(int dy = 0; dy < type.size; dy++){ + int wx = dx + offsetx + tile.x, wy = dy + offsety + tile.y; + + Tile check = world.tile(wx, wy); + if( + check == null || //nothing there + (check.floor().isDeep() && !type.floating && !type.requiresWater && !type.placeableLiquid) || //deep water + (type == check.block() && check.build != null && rotation == check.build.rotation && type.rotate) || //same block, same rotation + !check.interactable(team) || //cannot interact + !check.floor().placeableOn || //solid wall + !((type.canReplace(check.block()) || //can replace type + (check.block instanceof ConstructBlock && check.bc().cblock == type && check.centerX() == tile.x && check.centerY() == tile.y)) && //same type in construction + type.bounds(tile.x, tile.y, Tmp.r1).grow(0.01f).contains(check.block.bounds(check.centerX(), check.centerY(), Tmp.r2))) || //no replacement + (type.requiresWater && check.floor().liquidDrop != Liquids.water) //requires water but none found + ) return false; + } + } + + return true; } public static boolean contactsGround(int x, int y, Block block){ diff --git a/core/src/mindustry/world/blocks/defense/Wall.java b/core/src/mindustry/world/blocks/defense/Wall.java index 9e58db933c..1c1c522692 100644 --- a/core/src/mindustry/world/blocks/defense/Wall.java +++ b/core/src/mindustry/world/blocks/defense/Wall.java @@ -58,7 +58,8 @@ public class Wall extends Block{ @Override public boolean canReplace(Block other){ - return (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && health > other.health && size >= other.size; + if(other.alwaysReplace) return true; + return (other != this || rotate) && this.group != BlockGroup.none && other.group == this.group && other != this && size >= other.size; } public class WallBuild extends Building{