From bd252940960e0d814651d5474445c99f9f414fac Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 18 Dec 2020 12:41:13 -0500 Subject: [PATCH] Generic node/bridge placement system --- core/assets/baseparts/1603222912251.msch | Bin 302 -> 325 bytes core/src/mindustry/content/Blocks.java | 4 +- core/src/mindustry/input/Placement.java | 38 ++++++++++++++++++ .../defense/turrets/PointDefenseTurret.java | 2 +- .../world/blocks/distribution/ItemBridge.java | 6 +++ .../world/blocks/power/PowerNode.java | 34 +--------------- .../world/blocks/storage/CoreBlock.java | 7 ++++ 7 files changed, 56 insertions(+), 35 deletions(-) diff --git a/core/assets/baseparts/1603222912251.msch b/core/assets/baseparts/1603222912251.msch index 6b33abac342876064e00a1fd3a43a40abb40c0c4..f9c5e5f55dd648d3556ca1aaaa26ed333b096149 100644 GIT binary patch literal 325 zcmV-L0lNNeb7N=$c$_Vf?QVl06oy~H53Fs|UB!NRQOpu!VzEKo)+=weZe{P$#o)s^ zJRA-IC!7>=Z!Zqb)do9`_A|sD&DqUe7_M=cJg`SKyZ+*QL^Cg;cWsX1nqV>aaX}ih4yBlR~Lx*y-zLP?4HqyKOZ)-+7v(PyV z7vf5yv)mn&A!AO*K72QZ*6>2C= z>`j>-={G%jq)K1^{fHoYjo9KA64eqJ?D!sxb`sU{HpnEE^Yn_P_c+S(f%=NwhGxTF XnmF)d;>g}ILA7DM!%>t!fjC>lH^ic8 literal 302 zcmV+}0nz?#b7N=$c$_Vd>u!TE3`W0@a)+vWiT&fDG8!SIG@y`f>yuBrm3?jof@3=e z+u(##hJ!a3i*_}^IA`8NoY0=_HimhP^WuRP@@4~is>5Wx4JIxD zr&X$hU(R-Lh8l{nTqDJ&I7j2>>tz@h|7vfPwFx5%XZ$FQUQDES`~R$UW@Dpsn4ROq zh1Fp--Z}u!e4wEeQCCnIGDevoht@=0Rlxqkl-K@&X1_y|JVw5M@Av&nA8?S tmpPoints = new Seq<>(), tmpPoints2 = new Seq<>(); private static final NormalizeResult result = new NormalizeResult(); private static final NormalizeDrawResult drawResult = new NormalizeDrawResult(); private static Bresenham2 bres = new Bresenham2(); @@ -68,6 +70,42 @@ public class Placement{ return points; } + /** Calculates optimal node placement for nodes with spacing. Used for bridges and power nodes. */ + public static void calculateNodes(Seq points, Block block, int rotation, Boolf2 overlapper){ + var base = tmpPoints2; + var result = tmpPoints.clear(); + + base.selectFrom(points, p -> p == points.first() || p == points.peek() || Build.validPlace(block, player.team(), p.x, p.y, rotation, false)); + boolean addedLast = false; + + outer: + for(int i = 0; i < base.size;){ + var point = base.get(i); + result.add(point); + if(i == base.size - 1) addedLast = true; + + //find the furthest node that overlaps this one + for(int j = base.size - 1; j > i; j--){ + var other = base.get(j); + boolean over = overlapper.get(point, other); + + if(over){ + //add node to list and start searching for node that overlaps the next one + i = j; + continue outer; + } + } + + //if it got here, that means nothing was found. try to proceed to the next node anyway + i ++; + } + + if(!addedLast) result.add(base.peek()); + + points.clear(); + points.addAll(result); + } + private static float tileHeuristic(Tile tile, Tile other){ Block block = control.input.block; diff --git a/core/src/mindustry/world/blocks/defense/turrets/PointDefenseTurret.java b/core/src/mindustry/world/blocks/defense/turrets/PointDefenseTurret.java index 2c9ef9c134..9c0259c8b2 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/PointDefenseTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/PointDefenseTurret.java @@ -62,7 +62,7 @@ public class PointDefenseTurret extends ReloadTurret{ //retarget if(timer(timerTarget, retargetTime)){ - target = Groups.bullet.intersect(x - range, y - range, range*2, range*2).min(b -> b.team == team || !b.type().hittable ? Float.MAX_VALUE : b.dst2(this)); + target = Groups.bullet.intersect(x - range, y - range, range*2, range*2).min(b -> b.team != team && b.type().hittable, b -> b.dst2(this)); } //pooled bullets diff --git a/core/src/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/mindustry/world/blocks/distribution/ItemBridge.java index cfcc488881..604cefce4a 100644 --- a/core/src/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ItemBridge.java @@ -13,6 +13,7 @@ import mindustry.annotations.Annotations.*; import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.graphics.*; +import mindustry.input.*; import mindustry.type.*; import mindustry.world.*; import mindustry.world.meta.*; @@ -152,6 +153,11 @@ public class ItemBridge extends Block{ lastPlan = plan; } + @Override + public void changePlacementPath(Seq points, int rotation){ + Placement.calculateNodes(points, this, rotation, (point, other) -> Math.max(Math.abs(point.x - other.x), Math.abs(point.y - other.y)) <= range); + } + public class ItemBridgeBuild extends Building{ public int link = -1; public IntSet incoming = new IntSet(); diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index ab265dbf09..2f100e7476 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -14,6 +14,7 @@ import mindustry.entities.units.*; import mindustry.game.*; import mindustry.gen.*; import mindustry.graphics.*; +import mindustry.input.*; import mindustry.ui.*; import mindustry.world.*; import mindustry.world.meta.*; @@ -153,38 +154,7 @@ public class PowerNode extends PowerBlock{ @Override public void changePlacementPath(Seq points, int rotation){ - var base = tmpPoints2; - var result = tmpPoints.clear(); - - base.selectFrom(points, p -> p == points.first() || p == points.peek() || Build.validPlace(this, player.team(), p.x, p.y, rotation, false)); - boolean addedLast = false; - - outer: - for(int i = 0; i < base.size;){ - var point = base.get(i); - result.add(point); - if(i == base.size - 1) addedLast = true; - - //find the furthest node that overlaps this one - for(int j = base.size - 1; j > i; j--){ - var other = base.get(j); - boolean over = overlaps(world.tile(point.x, point.y), world.tile(other.x, other.y)); - - if(over){ - //add node to list and start searching for node that overlaps the next one - i = j; - continue outer; - } - } - - //if it got here, that means nothing was found. try to proceed to the next node anyway - i ++; - } - - if(!addedLast) result.add(base.peek()); - - points.clear(); - points.addAll(result); + Placement.calculateNodes(points, this, rotation, (point, other) -> overlaps(world.tile(point.x, point.y), world.tile(other.x, other.y))); } protected void setupColor(float satisfaction){ diff --git a/core/src/mindustry/world/blocks/storage/CoreBlock.java b/core/src/mindustry/world/blocks/storage/CoreBlock.java index 6d77239f50..18299cd02a 100644 --- a/core/src/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/mindustry/world/blocks/storage/CoreBlock.java @@ -386,6 +386,13 @@ public class CoreBlock extends StorageBlock{ }else{ super.handleItem(source, item); } + }else if(incinerate()){ + if(items.get(item) >= storageCapacity){ + //create item incineration effect at random intervals + if(!noEffect){ + incinerateEffect(this, source); + } + } } } }