From 7a1b9e76c98d50c7a664c80ddc6c34218499dd2f Mon Sep 17 00:00:00 2001 From: Patrick 'Quezler' Mounier Date: Mon, 4 Nov 2019 17:50:50 +0100 Subject: [PATCH] Stash initial prototype --- .../io/anuke/mindustry/content/Blocks.java | 6 ++++ .../anuke/mindustry/input/InputHandler.java | 33 ++++++++++++++++++- .../io/anuke/mindustry/input/Placement.java | 2 +- core/src/io/anuke/mindustry/world/Block.java | 2 ++ .../world/blocks/power/PowerNode.java | 5 +++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/Blocks.java b/core/src/io/anuke/mindustry/content/Blocks.java index fc713253ff..c4ae43a5c6 100644 --- a/core/src/io/anuke/mindustry/content/Blocks.java +++ b/core/src/io/anuke/mindustry/content/Blocks.java @@ -10,6 +10,7 @@ import io.anuke.mindustry.*; import io.anuke.mindustry.ctype.ContentList; import io.anuke.mindustry.entities.*; import io.anuke.mindustry.entities.bullet.*; +import io.anuke.mindustry.entities.traits.BuilderTrait; import io.anuke.mindustry.entities.type.*; import io.anuke.mindustry.gen.*; import io.anuke.mindustry.graphics.*; @@ -104,6 +105,11 @@ public class Blocks implements ContentList{ } return variantRegions; } + + @Override + public void drawRequestRegion(BuilderTrait.BuildRequest req, Eachable list) { + // + } }; //create special blockpart variants diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 16ecdb2e47..8c332547a2 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -32,6 +32,7 @@ import io.anuke.mindustry.ui.fragments.*; import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.blocks.*; import io.anuke.mindustry.world.blocks.BuildBlock.*; +import io.anuke.mindustry.world.blocks.power.PowerNode; import java.util.*; @@ -534,6 +535,30 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ } }); } + + final int[] i = {0}; + final Array chain = new Array(); + lineRequests.each(req -> { + if(!(req.block instanceof PowerNode)) return; + + if(i[0]++ == 0 || i[0] == lineRequests.size){ + // beginning & end should always be placed + }else{ + final boolean[] overlaps = {false}; + chain.each(tile -> { + if(((PowerNode) req.block).overlaps(req.tile(), tile)){ + overlaps[0] = true; + }; + }); + + if(overlaps[0]){ + req.block = Blocks.air; + return; + } + } + + chain.add(req.tile()); + }); } protected void updateLine(int x1, int y1){ @@ -806,12 +831,18 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ void iterateLine(int startX, int startY, int endX, int endY, Cons cons){ Array points; boolean diagonal = Core.input.keyDown(Binding.diagonal_placement); + + // place powernodes diagonally by default + if((block != null && block.powernodePlacement)){ + diagonal = !diagonal; + } + if(Core.settings.getBool("swapdiagonal") && mobile){ diagonal = !diagonal; } if(diagonal){ - points = Placement.pathfindLine(block != null && block.conveyorPlacement, startX, startY, endX, endY); + points = Placement.pathfindLine(block != null && block.conveyorPlacement, block != null && block.powernodePlacement, startX, startY, endX, endY); }else{ points = Placement.normalizeLine(startX, startY, endX, endY); } diff --git a/core/src/io/anuke/mindustry/input/Placement.java b/core/src/io/anuke/mindustry/input/Placement.java index 14d1b8b230..6aac3c26aa 100644 --- a/core/src/io/anuke/mindustry/input/Placement.java +++ b/core/src/io/anuke/mindustry/input/Placement.java @@ -22,7 +22,7 @@ public class Placement{ private static IntSet closed = new IntSet(); /** Normalize a diagonal line into points. */ - public static Array pathfindLine(boolean conveyors, int startX, int startY, int endX, int endY){ + public static Array pathfindLine(boolean conveyors, boolean powernodes, int startX, int startY, int endX, int endY){ Pools.freeAll(points); points.clear(); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 9710e1b8de..37d62e8a9c 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -93,6 +93,8 @@ public class Block extends BlockStorage{ public boolean posConfig; /** Whether this block uses conveyor-type placement mode.*/ public boolean conveyorPlacement; + /** Whether this block uses powernode-type placement mode.*/ + public boolean powernodePlacement; /** * The color of this block when displayed on the minimap or map preview. * Do not set manually! This is overriden when loading for most blocks. diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java index e9d922ba1d..87f2ee68cb 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -32,6 +32,7 @@ public class PowerNode extends PowerBlock{ configurable = true; consumesPower = false; outputsPower = false; + powernodePlacement = true; } @Override @@ -302,6 +303,10 @@ public class PowerNode extends PowerBlock{ return overlaps(src.drawx(), src.drawy(), other, range); } + public boolean overlaps(Tile src, Tile other){ + return overlaps(src.drawx(), src.drawy(), other, laserRange * tilesize); + } + protected void drawLaser(Tile tile, Tile target){ int opacityPercentage = Core.settings.getInt("lasersopacity"); if(opacityPercentage == 0) return;