autolink
This commit is contained in:
@@ -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;
|
||||
}};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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.<PowerNode>cblock().laserRange * tilesize))){
|
||||
|
||||
Reference in New Issue
Block a user