From 7f2cc59b3cca0a3d2a87c42c68fe04b2e34a2e6a Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 2 Aug 2019 20:48:26 -0400 Subject: [PATCH] autolink --- .../src/io/anuke/mindustry/content/Blocks.java | 4 ++-- .../src/io/anuke/mindustry/graphics/Drawf.java | 6 +++++- core/src/io/anuke/mindustry/world/Block.java | 18 ++++++++++++++++++ .../world/blocks/power/PowerNode.java | 11 +++++++---- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/Blocks.java b/core/src/io/anuke/mindustry/content/Blocks.java index b80a143631..ed846dae62 100644 --- a/core/src/io/anuke/mindustry/content/Blocks.java +++ b/core/src/io/anuke/mindustry/content/Blocks.java @@ -1024,14 +1024,14 @@ public class Blocks implements ContentList{ powerNode = new PowerNode("power-node"){{ requirements(Category.power, ItemStack.with(Items.copper, 2, Items.lead, 6)); - maxNodes = 4; + maxNodes = 20; laserRange = 6; }}; powerNodeLarge = new PowerNode("power-node-large"){{ requirements(Category.power, ItemStack.with(Items.titanium, 10, Items.lead, 20, Items.silicon, 6)); size = 2; - maxNodes = 6; + maxNodes = 30; laserRange = 9.5f; }}; diff --git a/core/src/io/anuke/mindustry/graphics/Drawf.java b/core/src/io/anuke/mindustry/graphics/Drawf.java index f455660d0f..7327dc5efe 100644 --- a/core/src/io/anuke/mindustry/graphics/Drawf.java +++ b/core/src/io/anuke/mindustry/graphics/Drawf.java @@ -16,8 +16,12 @@ public class Drawf{ Draw.reset(); } + public static void circles(float x, float y, float rad){ + circles(x, y, rad, Pal.accent); + } + public static void circles(float x, float y, float rad, Color color){ - int vertices = 30; + int vertices = (int)(rad * 2); Lines.stroke(3f, Pal.gray); Lines.poly(x, y, vertices, rad); Lines.stroke(1f, color); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 03e7f17b75..736b775107 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -12,6 +12,7 @@ import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.TextureAtlas.*; import io.anuke.arc.math.*; +import io.anuke.arc.math.geom.*; import io.anuke.arc.scene.ui.layout.*; import io.anuke.arc.util.*; import io.anuke.arc.util.pooling.*; @@ -27,6 +28,7 @@ import io.anuke.mindustry.input.InputHandler.*; import io.anuke.mindustry.type.*; import io.anuke.mindustry.ui.*; import io.anuke.mindustry.world.blocks.*; +import io.anuke.mindustry.world.blocks.power.*; import io.anuke.mindustry.world.consumers.*; import io.anuke.mindustry.world.meta.*; @@ -262,7 +264,23 @@ public class Block extends BlockStorage{ } /** Called after the block is placed by this client. */ + @CallSuper public void playerPlaced(Tile tile){ + + if(consumesPower && !outputsPower){ + int range = 10; + tempTiles.clear(); + Geometry.circle(tile.x, tile.y, range, (x, y) -> { + Tile other = world.tile(x, y); + if(other != null && other.block instanceof PowerNode && ((PowerNode)other.block).linkValid(other, tile)){ + tempTiles.add(other); + } + }); + tempTiles.sort(Structs.comparingFloat(t -> t.dst2(tile))); + if(!tempTiles.isEmpty()){ + Call.linkPowerNodes(null, tempTiles.first(), tile); + } + } } public void removed(Tile tile){ 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 1167643ced..0e8d331952 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -105,6 +105,7 @@ public class PowerNode extends PowerBlock{ @Override public void playerPlaced(Tile tile){ + super.playerPlaced(tile); Tile before = world.tile(lastPlaced); if(linkValid(tile, before) && before.block() instanceof PowerNode){ for(Tile near : before.entity.proximity()){ @@ -170,7 +171,9 @@ public class PowerNode extends PowerBlock{ Lines.circle(tile.drawx(), tile.drawy(), tile.block().size * tilesize / 2f + 1f + Mathf.absin(Time.time(), 4f, 1f)); - Lines.poly(tile.drawx(), tile.drawy(), 50, laserRange * tilesize); + Drawf.circles(tile.drawx(), tile.drawy(), laserRange * tilesize); + + Lines.stroke(1.5f); for(int x = (int)(tile.x - laserRange - 1); x <= tile.x + laserRange + 1; x++){ for(int y = (int)(tile.y - laserRange - 1); y <= tile.y + laserRange + 1; y++){ @@ -199,7 +202,7 @@ public class PowerNode extends PowerBlock{ public void drawPlace(int x, int y, int rotation, boolean valid){ Lines.stroke(1f); Draw.color(Pal.placing); - Lines.poly(x * tilesize + offset(), y * tilesize + offset(), 50, laserRange * tilesize); + Drawf.circles(x * tilesize + offset(), y * tilesize + offset(), laserRange * tilesize); Draw.reset(); } @@ -223,11 +226,11 @@ public class PowerNode extends PowerBlock{ return tile.entity.power.links.contains(other.pos()); } - protected boolean linkValid(Tile tile, Tile link){ + public boolean linkValid(Tile tile, Tile link){ return linkValid(tile, link, true); } - protected boolean linkValid(Tile tile, Tile link, boolean checkMaxNodes){ + public boolean linkValid(Tile tile, Tile link, boolean checkMaxNodes){ if(tile == link || link == null || !link.block().hasPower || tile.getTeam() != link.getTeam()) return false; if(overlaps(tile, link, laserRange * tilesize) || (link.block() instanceof PowerNode && overlaps(link, tile, link.cblock().laserRange * tilesize))){