diff --git a/core/assets-raw/sprites/blocks/power/beam-link-glow.png b/core/assets-raw/sprites/blocks/power/beam-link-glow.png new file mode 100644 index 0000000000..6777c9a222 Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/beam-link-glow.png differ diff --git a/core/assets-raw/sprites/blocks/power/beam-link.png b/core/assets-raw/sprites/blocks/power/beam-link.png new file mode 100644 index 0000000000..7311804768 Binary files /dev/null and b/core/assets-raw/sprites/blocks/power/beam-link.png differ diff --git a/core/assets/icons/icons.properties b/core/assets/icons/icons.properties index 9a502464fd..612d00e5bc 100755 --- a/core/assets/icons/icons.properties +++ b/core/assets/icons/icons.properties @@ -527,3 +527,4 @@ 63176=red-stone-vent|block-red-stone-vent-ui 63175=carbon-vent|block-carbon-vent-ui 63174=shield-projector|block-shield-projector-ui +63173=beam-link|block-beam-link-ui diff --git a/core/assets/logicids.dat b/core/assets/logicids.dat index 11dead3947..1c6082c1b8 100644 Binary files a/core/assets/logicids.dat and b/core/assets/logicids.dat differ diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 3b451bd039..def46136c6 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -112,7 +112,7 @@ public class Blocks{ //power - erekir //TODO rename chemicalCombustionChamber turbineCondenser, ventCondenser, chemicalCombustionChamber, pyrolysisGenerator, - beamNode, beamTower, + beamNode, beamTower, beamLink, //production mechanicalDrill, pneumaticDrill, laserDrill, blastDrill, waterExtractor, oilExtractor, cultivator, @@ -1731,8 +1731,7 @@ public class Blocks{ //TODO 5x5?? shieldProjector = new BaseShield("shield-projector"){{ - category = Category.effect; - buildVisibility = BuildVisibility.editorOnly; + requirements(Category.effect, BuildVisibility.editorOnly, with()); size = 3; @@ -2125,6 +2124,16 @@ public class Blocks{ range = 23; }}; + beamLink = new LongPowerNode("beam-link"){{ + requirements(Category.power, BuildVisibility.editorOnly, with()); + size = 3; + maxNodes = 1; + laserRange = 1000f; + autolink = false; + laserColor2 = Color.valueOf("ffd9c2"); + laserScale = 0.65f; + }}; + combustionGenerator = new BurnerGenerator("combustion-generator"){{ requirements(Category.power, with(Items.copper, 25, Items.lead, 15)); powerProduction = 1f; diff --git a/core/src/mindustry/world/blocks/power/LongPowerNode.java b/core/src/mindustry/world/blocks/power/LongPowerNode.java new file mode 100644 index 0000000000..ac2e00b84c --- /dev/null +++ b/core/src/mindustry/world/blocks/power/LongPowerNode.java @@ -0,0 +1,48 @@ +package mindustry.world.blocks.power; + +import arc.*; +import arc.graphics.*; +import arc.graphics.g2d.*; +import arc.math.*; +import arc.util.*; +import mindustry.annotations.Annotations.*; +import mindustry.graphics.*; + +public class LongPowerNode extends PowerNode{ + public @Load("@-glow") TextureRegion glow; + public Color glowColor = Color.valueOf("cbfd81").a(0.6f); + public float glowScl = 16f, glowMag = 0.6f; + + public LongPowerNode(String name){ + super(name); + drawRange = false; + } + + @Override + public void load(){ + super.load(); + + laser = Core.atlas.find("power-beam"); + laserEnd = Core.atlas.find("power-beam-end"); + } + + public class LongPowerNodeBuild extends PowerNodeBuild{ + public float warmup = 0f; + + @Override + public void updateTile(){ + super.updateTile(); + + warmup = Mathf.lerpDelta(warmup, power.links.size > 0 ? 1f : 0f, 0.05f); + } + + @Override + public void draw(){ + super.draw(); + + if(warmup > 0.001f){ + Drawf.additive(glow, Tmp.c1.set(glowColor).mula(warmup).mula(1f - glowMag + Mathf.absin(glowScl, glowMag)), x, y); + } + } + } +} diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index f91301c198..2f61d24d96 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -31,6 +31,8 @@ public class PowerNode extends PowerBlock{ public @Load("laser-end") TextureRegion laserEnd; public float laserRange = 6; public int maxNodes = 3; + public boolean autolink = true, drawRange = true; + public float laserScale = 0.25f; public Color laserColor1 = Color.white; public Color laserColor2 = Pal.powerLight; @@ -145,7 +147,7 @@ public class PowerNode extends PowerBlock{ public void drawPlace(int x, int y, int rotation, boolean valid){ Tile tile = world.tile(x, y); - if(tile == null) return; + if(tile == null || !autolink) return; Lines.stroke(1f); Draw.color(Pal.placing); @@ -176,7 +178,7 @@ public class PowerNode extends PowerBlock{ vx = Mathf.cosDeg(angle1), vy = Mathf.sinDeg(angle1), len1 = size1 * tilesize / 2f - 1.5f, len2 = size2 * tilesize / 2f - 1.5f; - Drawf.laser(team, laser, laserEnd, x1 + vx*len1, y1 + vy*len1, x2 - vx*len2, y2 - vy*len2, 0.25f); + Drawf.laser(team, laser, laserEnd, x1 + vx*len1, y1 + vy*len1, x2 - vx*len2, y2 - vy*len2, laserScale); } protected boolean overlaps(float srcx, float srcy, Tile other, Block otherBlock, float range){ @@ -202,6 +204,8 @@ public class PowerNode extends PowerBlock{ } protected void getPotentialLinks(Tile tile, Team team, Cons others){ + if(!autolink) return; + Boolf valid = other -> other != null && other.tile() != tile && other.power != null && (other.block.outputsPower || other.block.consumesPower || other.block instanceof PowerNode) && overlaps(tile.x * tilesize + offset, tile.y * tilesize + offset, other.tile(), laserRange * tilesize) && other.team == team && @@ -255,6 +259,7 @@ public class PowerNode extends PowerBlock{ /** Iterates through linked nodes of a block at a tile. All returned buildings are power nodes. */ public static void getNodeLinks(Tile tile, Block block, Team team, Cons others){ Boolf valid = other -> other != null && other.tile() != tile && other.block instanceof PowerNode node && + node.autolink && other.power.links.size < node.maxNodes && node.overlaps(other.x, other.y, tile, block, node.laserRange * tilesize) && other.team == team && !graphs.contains(other.power.graph) && @@ -410,6 +415,8 @@ public class PowerNode extends PowerBlock{ public void drawSelect(){ super.drawSelect(); + if(!drawRange) return; + Lines.stroke(1f); Draw.color(Pal.accent); @@ -421,23 +428,33 @@ public class PowerNode extends PowerBlock{ public void drawConfigure(){ Drawf.circles(x, y, tile.block().size * tilesize / 2f + 1f + Mathf.absin(Time.time, 4f, 1f)); - Drawf.circles(x, y, laserRange * tilesize); - for(int x = (int)(tile.x - laserRange - 2); x <= tile.x + laserRange + 2; x++){ - for(int y = (int)(tile.y - laserRange - 2); y <= tile.y + laserRange + 2; y++){ - Building link = world.build(x, y); + if(drawRange){ + Drawf.circles(x, y, laserRange * tilesize); - if(link != this && linkValid(this, link, false)){ - boolean linked = linked(link); + for(int x = (int)(tile.x - laserRange - 2); x <= tile.x + laserRange + 2; x++){ + for(int y = (int)(tile.y - laserRange - 2); y <= tile.y + laserRange + 2; y++){ + Building link = world.build(x, y); - if(linked){ - Drawf.square(link.x, link.y, link.block.size * tilesize / 2f + 1f, Pal.place); + if(link != this && linkValid(this, link, false)){ + boolean linked = linked(link); + + if(linked){ + Drawf.square(link.x, link.y, link.block.size * tilesize / 2f + 1f, Pal.place); + } } } } - } - Draw.reset(); + Draw.reset(); + }else{ + power.links.each(i -> { + var link = world.build(i); + if(link != null && linkValid(this, link, false)){ + Drawf.square(link.x, link.y, link.block.size * tilesize / 2f + 1f, Pal.place); + } + }); + } } @Override diff --git a/core/src/mindustry/world/meta/BuildVisibility.java b/core/src/mindustry/world/meta/BuildVisibility.java index b9558fc1a5..1bbd3fa0a7 100644 --- a/core/src/mindustry/world/meta/BuildVisibility.java +++ b/core/src/mindustry/world/meta/BuildVisibility.java @@ -8,7 +8,7 @@ public enum BuildVisibility{ hidden(() -> false), shown(() -> true), debugOnly(() -> false), - editorOnly(() -> false), + editorOnly(() -> Vars.state.rules.editor), sandboxOnly(() -> Vars.state == null || Vars.state.rules.infiniteResources), campaignOnly(() -> Vars.state == null || Vars.state.isCampaign()), lightingOnly(() -> Vars.state == null || Vars.state.rules.lighting || Vars.state.isCampaign()),