diff --git a/core/src/io/anuke/mindustry/editor/MapEditor.java b/core/src/io/anuke/mindustry/editor/MapEditor.java index e5f7a9bc69..bf557eb640 100644 --- a/core/src/io/anuke/mindustry/editor/MapEditor.java +++ b/core/src/io/anuke/mindustry/editor/MapEditor.java @@ -175,7 +175,6 @@ public class MapEditor{ world.setBlock(tile(x, y), drawBlock, drawTeam); }else{ - boolean isFloor = drawBlock.isFloor() && drawBlock != Blocks.air; Consumer drawer = tile -> { 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 fca63f70a1..2bcbd7e03d 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.*; @@ -266,7 +268,27 @@ 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); + } + } + + if(outputsPower && !consumesPower){ + PowerNode.lastPlaced = tile.pos(); + } } 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..94284f983c 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -25,7 +25,7 @@ import static io.anuke.mindustry.Vars.world; public class PowerNode extends PowerBlock{ //last distribution block placed - private static int lastPlaced = -1; + public static int lastPlaced = -1; protected Vector2 t1 = new Vector2(), t2 = new Vector2(); protected TextureRegion laser, laserEnd; @@ -106,17 +106,13 @@ public class PowerNode extends PowerBlock{ @Override public void playerPlaced(Tile tile){ Tile before = world.tile(lastPlaced); - if(linkValid(tile, before) && before.block() instanceof PowerNode){ - for(Tile near : before.entity.proximity()){ - if(near == tile){ - lastPlaced = tile.pos(); - return; - } - } + + if(linkValid(tile, before) && !before.entity.proximity().contains(tile)){ Call.linkPowerNodes(null, tile, before); } lastPlaced = tile.pos(); + super.playerPlaced(tile); } @Override @@ -170,7 +166,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 +197,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 +221,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))){ diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java index 089eb784c7..e28ca954b2 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java @@ -211,8 +211,10 @@ public class Drill extends Block{ } itemArray.sort((item1, item2) -> { - int type = Boolean.compare(item1.type == ItemType.material, item2.type == ItemType.material); + int type = Boolean.compare(item1 != Items.sand, item2 != Items.sand); if(type != 0) return type; + int amounts = Integer.compare(oreCount.get(item1, 0), oreCount.get(item2, 0)); + if(amounts != 0) return amounts; return Integer.compare(item1.id, item2.id); }); diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index f081b7c98c..efee63dbb8 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -15,14 +15,14 @@ import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.graphics.Pal; import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.net.Net; -import io.anuke.mindustry.type.Item; -import io.anuke.mindustry.type.ItemType; +import io.anuke.mindustry.type.*; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.meta.BlockFlag; import static io.anuke.mindustry.Vars.*; public class CoreBlock extends StorageBlock{ + protected Mech mech = Mechs.starter; public CoreBlock(String name){ super(name); @@ -40,10 +40,10 @@ public class CoreBlock extends StorageBlock{ CoreEntity entity = tile.entity(); Effects.effect(Fx.spawn, entity); entity.progress = 0; - entity.currentUnit = player; - entity.currentUnit.onRespawn(tile); - entity.currentUnit.applyImpulse(0, 8f); - entity.currentUnit = null; + entity.spawnPlayer = player; + entity.spawnPlayer.onRespawn(tile); + entity.spawnPlayer.applyImpulse(0, 8f); + entity.spawnPlayer = null; } @Override @@ -94,8 +94,8 @@ public class CoreBlock extends StorageBlock{ Draw.reset(); } - if(entity.currentUnit != null){ - Unit player = entity.currentUnit; + if(entity.spawnPlayer != null){ + Unit player = entity.spawnPlayer; TextureRegion region = player.getIconRegion(); @@ -129,19 +129,19 @@ public class CoreBlock extends StorageBlock{ public void update(Tile tile){ CoreEntity entity = tile.entity(); - if(entity.currentUnit != null){ - if(!entity.currentUnit.isDead() || !entity.currentUnit.isAdded()){ - entity.currentUnit = null; + if(entity.spawnPlayer != null){ + if(!entity.spawnPlayer.isDead() || !entity.spawnPlayer.isAdded()){ + entity.spawnPlayer = null; return; } - entity.currentUnit.set(tile.drawx(), tile.drawy()); + entity.spawnPlayer.set(tile.drawx(), tile.drawy()); entity.heat = Mathf.lerpDelta(entity.heat, 1f, 0.1f); entity.time += entity.delta(); entity.progress += 1f / state.rules.respawnTime * entity.delta(); if(entity.progress >= 1f){ - Call.onUnitRespawn(tile, entity.currentUnit); + Call.onUnitRespawn(tile, entity.spawnPlayer); } }else{ entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.1f); @@ -154,17 +154,17 @@ public class CoreBlock extends StorageBlock{ } public class CoreEntity extends TileEntity implements SpawnerTrait{ - public Player currentUnit; + public Player spawnPlayer; float progress; float time; float heat; @Override public void updateSpawning(Player player){ - if(!netServer.isWaitingForPlayers() && currentUnit == null){ - currentUnit = player; + if(!netServer.isWaitingForPlayers() && spawnPlayer == null){ + spawnPlayer = player; progress = 0f; - player.mech = Mechs.starter; + player.mech = mech; player.beginRespawning(this); } }