From 7b3d60215b60a4623d2d4b59438ad8262544b1c2 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 23 Mar 2018 22:39:42 -0400 Subject: [PATCH] New power system implemented --- build.gradle | 2 +- .../sprites/blocks/environment/lead1.png | Bin 0 -> 240 bytes .../sprites/blocks/environment/lead2.png | Bin 0 -> 256 bytes .../sprites/blocks/environment/lead3.png | Bin 0 -> 241 bytes .../sprites/blocks/production/leaddrill.png | Bin 0 -> 250 bytes .../sprites/blocks/tech/powernode.png | Bin 0 -> 234 bytes core/assets-raw/sprites/effects/laser-end.png | Bin 0 -> 305 bytes core/assets-raw/sprites/items/item-lead.png | Bin 0 -> 274 bytes core/assets/version.properties | 4 +- core/src/io/anuke/mindustry/core/Control.java | 8 +- .../anuke/mindustry/input/DesktopInput.java | 7 +- core/src/io/anuke/mindustry/io/SaveIO.java | 4 +- core/src/io/anuke/mindustry/io/Saves.java | 5 +- .../mindustry/world/blocks/BaseBlock.java | 2 +- .../world/blocks/DistributionBlocks.java | 6 +- .../types/generation/NuclearReactor.java | 1 - .../types/generation/PowerDistributor.java | 93 +++++++++++++++--- .../types/generation/PowerGenerator.java | 33 ++++++- 18 files changed, 128 insertions(+), 37 deletions(-) create mode 100644 core/assets-raw/sprites/blocks/environment/lead1.png create mode 100644 core/assets-raw/sprites/blocks/environment/lead2.png create mode 100644 core/assets-raw/sprites/blocks/environment/lead3.png create mode 100644 core/assets-raw/sprites/blocks/production/leaddrill.png create mode 100644 core/assets-raw/sprites/blocks/tech/powernode.png create mode 100644 core/assets-raw/sprites/effects/laser-end.png create mode 100644 core/assets-raw/sprites/items/item-lead.png diff --git a/build.gradle b/build.gradle index ace1e7730a..8e2949f2c4 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ allprojects { appName = 'Mindustry' gdxVersion = '1.9.8' aiVersion = '1.8.1' - uCoreVersion = '5e6c99a' + uCoreVersion = '64d13cc' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/assets-raw/sprites/blocks/environment/lead1.png b/core/assets-raw/sprites/blocks/environment/lead1.png new file mode 100644 index 0000000000000000000000000000000000000000..0098e0cbcd41cb1a75e8c034dfda0cf49fed4275 GIT binary patch literal 240 zcmeAS@N?(olHy`uVBq!ia0y~yVBi2@4kiW$2Jc+WI}8jAoCO|{#S9GG!XV7ZFl&wk z0|NtliKnkC`y*y?Msdkn8RvZr3=EPbt`Q~9`MJ5Nc_j?aMX8A;sVNHOnI#zt?w-B@ z;f;La3=9leo-U3d9M_X|POO_W`BFkc!j7u<3l=PR@ca9FNeK{`At50lXShy0Z!7l6HFT`dV(2-&hv|12gDf+r#@8qI6PXrQMnBtn=d#~xUKfKmBe`!(UJ%5)F{j=iCx%$jI`QxJ)7#J8lUHx3vIVCg! E01Q-7MgRZ+ literal 0 HcmV?d00001 diff --git a/core/assets-raw/sprites/blocks/environment/lead3.png b/core/assets-raw/sprites/blocks/environment/lead3.png new file mode 100644 index 0000000000000000000000000000000000000000..061eb04e0072cb1bb5a82c9ca22082f5932f4eda GIT binary patch literal 241 zcmeAS@N?(olHy`uVBq!ia0y~yVBi2@4kiW$2Jc+WI}8jAoCO|{#S9GG!XV7ZFl&wk z0|NtliKnkC`y*y?Msd-SRs2&K7#Ji=Tq8=H^K)}k^GX<;i&7IyQd1PlGfOfQ+&z5* z!W;R-85kI{JzX3_IIhR`D)KcL2(V0F#>DbSWZyLR4>R^n(Vt-A7^*NUWbFz?jUyA= zzFkQzd!F~<-r~7ea~0n$Tl{&)i%aZfRYLp>ZZ0A5cdwavgvm0Td_U!q_S~H=O_D9U(j1pE6kM)=t7#Ji=Tq8=H^K)}k^GX<;i&7IyQd1PlGfOfQ+&z5* z!W;R-85kH!JY5_^Brdo18*(ul^0274@76xrcv1cjkNsKwEAlN50%lriHcc%F-2O(V zM=pD9_kP`yc@A#>MaHa1_n=8KbLh*2~7a?;#9%_ literal 0 HcmV?d00001 diff --git a/core/assets-raw/sprites/blocks/tech/powernode.png b/core/assets-raw/sprites/blocks/tech/powernode.png new file mode 100644 index 0000000000000000000000000000000000000000..5d0ce184613301d74e606321ac39fa42b1e2faa6 GIT binary patch literal 234 zcmeAS@N?(olHy`uVBq!ia0y~yVBi2@4mJh`h9ms@x)~T4I14-?iy0WWg+Z8+Vb&Z8 z1_lQ95>H=O_J>?j;vAf3ws^HLFfd4#xJHyX=jZ08=9Mrw7o{eaq^2m8XO?6rxO@5r zgg5euGcYiuc)B=-NL()M-^hDFL4aAmLovosX!DX&Y$iSvEG0T0eT`OeouZ-e@LKxm zdtRE;Rl>T`*bYqmop5E^1eYJPx2k4&J1d;w^prPY(5^i&(fVEAZvN^+(f^(P+cF3q iICJB?#Z>$Ec}o|lc1#Z4FU7#Xz~JfX=d#Wzp$PyVL`!}E literal 0 HcmV?d00001 diff --git a/core/assets-raw/sprites/effects/laser-end.png b/core/assets-raw/sprites/effects/laser-end.png new file mode 100644 index 0000000000000000000000000000000000000000..d678fb0a81ff6149ed5e3cdf253ee70b684cd4d2 GIT binary patch literal 305 zcmeAS@N?(olHy`uVBq!ia0y~yU=RXf4mJh`hOl#e;S3B6oCO|{#S9GG!XV7ZFl&wk z0|NtliKnkC`$H~yCPUS`x2;MT7#J>ix;TbdoZdQRBkv&t0oU__UXEoJv%au&vPLMF zI?s?4FrMIP!!ESUztp-#sduH!o5vgGaO^8-ef#VrAn#}dAZ#Id#)iceZHM`>$gM?*)#n_lVa$0{?*MH}^Y z*RnXeI2_6BJG@DzwP919Ys8CH4L+?KBKw|cNt=92lkDhl@rc~sWq)DS%cKiG>$>%B zPmgaZSQ}J!f9hd=hZk-(Qt#D0gU+3w^{xK?iA()&Sy!@@h9xe0Rm;G@z~JfX=d#Wz Gp$Pz7{dc|q literal 0 HcmV?d00001 diff --git a/core/assets-raw/sprites/items/item-lead.png b/core/assets-raw/sprites/items/item-lead.png new file mode 100644 index 0000000000000000000000000000000000000000..e0bb05069773340246a08ab2b08d49b9adbf0b46 GIT binary patch literal 274 zcmeAS@N?(olHy`uVBq!ia0y~yVBi2@4mJh`h9ms@x)~T4I14-?iy0WWg+Z8+Vb&Z8 z1_lQ95>H=O_D9U(jA9H7Ik)T?7#Ji=Tq8=H^K)}k^GX<;i&7IyQd1PlGfOfQ+&z5* z!W;R-85kIPJY5_^BrYfa`TyUZnVFgS@S>O1|BMX`434DkGB8qLRGabS_V@FW_x9EE zg>x{Uk-z`vpT6d@6CeH_7iVK*V{3bFzt7;#zE8Ux?}w}u%scdR^>4`*R@H~QCio`3 znt$n3#~O}E#XBr1t}m8tG%zqQ2nh)>*znoF;NPD^f8>` { Sounds.play("spawn"); - int last = Settings.getInt("hiscore" + world.getMap().name); + int last = Settings.getInt("hiscore" + world.getMap().name, 0); if(state.wave > last && !state.mode.infiniteResources && !state.mode.disableWaveTimer){ Settings.putInt("hiscore" + world.getMap().name, state.wave); diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index dce98b925a..f370845a3d 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -96,7 +96,7 @@ public class DesktopInput extends InputHandler{ } Tile cursor = world.tile(tilex(), tiley()); - Tile target = cursor == null ? null : cursor.isLinked() ? cursor.getLinked() : cursor; + Tile target = cursor == null ? null : cursor.target(); boolean showCursor = false; if(recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown("block_info") @@ -111,10 +111,11 @@ public class DesktopInput extends InputHandler{ if(target != null && Inputs.keyTap("select") && !ui.hasMouse()){ if(target.block().isConfigurable(target)){ if((!ui.configfrag.isShown() - || ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), target))) + || ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor))) ui.configfrag.showConfig(target); }else if(!ui.configfrag.hasConfigMouse()){ - ui.configfrag.hideConfig(); + if(ui.configfrag.isShown() && ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor)) + ui.configfrag.hideConfig(); } target.block().tapped(target); diff --git a/core/src/io/anuke/mindustry/io/SaveIO.java b/core/src/io/anuke/mindustry/io/SaveIO.java index a8553a302c..ed046b3f1f 100644 --- a/core/src/io/anuke/mindustry/io/SaveIO.java +++ b/core/src/io/anuke/mindustry/io/SaveIO.java @@ -44,7 +44,7 @@ public class SaveIO{ public static void loadFromSlot(int slot){ if(gwt){ - String string = Settings.getString("save-"+slot+"-data"); + String string = Settings.getString("save-"+slot+"-data", ""); ByteArrayInputStream stream = new ByteArrayInputStream(Base64Coder.decode(string)); load(stream); }else{ @@ -54,7 +54,7 @@ public class SaveIO{ public static DataInputStream getSlotStream(int slot){ if(gwt){ - String string = Settings.getString("save-"+slot+"-data"); + String string = Settings.getString("save-"+slot+"-data", ""); byte[] bytes = Base64Coder.decode(string); return new DataInputStream(new ByteArrayInputStream(bytes)); }else{ diff --git a/core/src/io/anuke/mindustry/io/Saves.java b/core/src/io/anuke/mindustry/io/Saves.java index 031f08cae0..73ab98bef8 100644 --- a/core/src/io/anuke/mindustry/io/Saves.java +++ b/core/src/io/anuke/mindustry/io/Saves.java @@ -11,6 +11,7 @@ import io.anuke.ucore.core.Timers; import java.io.IOException; +import static io.anuke.mindustry.Vars.gwt; import static io.anuke.mindustry.Vars.saveSlots; import static io.anuke.mindustry.Vars.state; @@ -127,7 +128,7 @@ public class Saves { } public String getName(){ - return Settings.getString("save-"+index+"-name"); + return Settings.getString("save-"+index+"-name", "untittled"); } public void setName(String name){ @@ -148,7 +149,7 @@ public class Saves { } public boolean isAutosave(){ - return Settings.getBool("save-"+index+"-autosave"); + return Settings.getBool("save-"+index+"-autosave", !gwt); } public void setAutosave(boolean save){ diff --git a/core/src/io/anuke/mindustry/world/blocks/BaseBlock.java b/core/src/io/anuke/mindustry/world/blocks/BaseBlock.java index d9999b12c0..a6b317d7c2 100644 --- a/core/src/io/anuke/mindustry/world/blocks/BaseBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/BaseBlock.java @@ -36,7 +36,7 @@ public abstract class BaseBlock { } public boolean acceptPower(Tile tile, Tile source, float amount){ - return amount + tile.entity.power.amount <= powerCapacity; + return true; } public float addPower(Tile tile, float amount){ diff --git a/core/src/io/anuke/mindustry/world/blocks/DistributionBlocks.java b/core/src/io/anuke/mindustry/world/blocks/DistributionBlocks.java index 96e894662b..b3d5837d23 100644 --- a/core/src/io/anuke/mindustry/world/blocks/DistributionBlocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/DistributionBlocks.java @@ -1,9 +1,9 @@ package io.anuke.mindustry.world.blocks; import io.anuke.mindustry.world.Block; -import io.anuke.mindustry.world.blocks.types.PowerBlock; import io.anuke.mindustry.world.blocks.types.distribution.*; import io.anuke.mindustry.world.blocks.types.generation.PowerDistributor; +import io.anuke.mindustry.world.blocks.types.generation.PowerGenerator; import io.anuke.mindustry.world.blocks.types.storage.SortedUnloader; import io.anuke.mindustry.world.blocks.types.storage.Unloader; import io.anuke.mindustry.world.blocks.types.storage.Vault; @@ -78,10 +78,10 @@ public class DistributionBlocks{ }}, powernode = new PowerDistributor("powernode"){{ }}, - battery = new PowerBlock("battery"){{ + battery = new PowerGenerator("battery"){{ powerCapacity = 320f; }}, - batteryLarge = new PowerBlock("batterylarge"){{ + batteryLarge = new PowerGenerator("batterylarge"){{ size = 3; powerCapacity = 2000f; }}, diff --git a/core/src/io/anuke/mindustry/world/blocks/types/generation/NuclearReactor.java b/core/src/io/anuke/mindustry/world/blocks/types/generation/NuclearReactor.java index 60647980a0..f288d8bb44 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/generation/NuclearReactor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/generation/NuclearReactor.java @@ -47,7 +47,6 @@ public class NuclearReactor extends LiquidPowerGenerator{ liquidCapacity = 50; explosionEffect = Fx.nuclearShockwave; powerCapacity = 80f; - powerSpeed = 0.5f; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/types/generation/PowerDistributor.java b/core/src/io/anuke/mindustry/world/blocks/types/generation/PowerDistributor.java index 1f15c309a1..961783ca81 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/generation/PowerDistributor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/generation/PowerDistributor.java @@ -46,13 +46,17 @@ public class PowerDistributor extends PowerBlock{ expanded = true; layer = Layer.power; hasInventory = false; + powerCapacity = 1f; } + @Override + public void setBars(){} + @Override public void placed(Tile tile) { Tile before = world.tile(lastPlaced); - if(linkValid(tile, before)){ - tile.entity().links.add(before.packedPosition()); + if(linkValid(tile, before) && before.block() instanceof PowerDistributor){ + link(tile, before); } lastPlaced = tile.packedPosition(); @@ -78,13 +82,13 @@ public class PowerDistributor extends PowerBlock{ @Override public boolean onConfigureTileTapped(Tile tile, Tile other){ - DistributorEntity entity = tile.entity(); + other = other.target(); if(linkValid(tile, other)){ - if(entity.links.contains(other.packedPosition())){ - entity.links.removeValue(other.packedPosition()); + if(linked(tile, other)){ + unlink(tile, other); }else{ - entity.links.add(other.packedPosition()); + link(tile, other); } return false; } @@ -105,11 +109,12 @@ public class PowerDistributor extends PowerBlock{ @Override public void drawConfigure(Tile tile){ + Draw.color("accent"); Lines.stroke(1f); Lines.square(tile.drawx(), tile.drawy(), - tile.block().size * tilesize / 2f + 1f); + tile.block().size * tilesize / 2f + 1f + Mathf.absin(Timers.time(), 4f, 1f)); Lines.stroke(1f); @@ -120,9 +125,17 @@ public class PowerDistributor extends PowerBlock{ for(int x = tile.x - laserRange; x <= tile.x + laserRange; x ++){ for(int y = tile.y - laserRange; y <= tile.y + laserRange; y ++){ Tile link = world.tile(x, y); + if(link != null) link = link.target(); + if(link != tile && linkValid(tile, link)){ + if(linked(tile, link)){ + Draw.color("place"); + }else{ + Draw.color(Color.SCARLET); + } + Lines.square(link.drawx(), link.drawy(), - link.block().size * tilesize / 2f + 1f); + link.block().size * tilesize / 2f + 1f + Mathf.absin(Timers.time(), 4f, 1f)); } } } @@ -165,13 +178,67 @@ public class PowerDistributor extends PowerBlock{ protected void distributeLaserPower(Tile tile){ DistributorEntity entity = tile.entity(); - //TODO implement + //validate everything first. + for(int i = 0; i < entity.links.size; i ++){ + Tile target = world.tile(entity.links.get(i)); + if(!linkValid(tile, target)) { + entity.links.removeIndex(i); + i --; + } + } + + float result = Math.min(entity.power.amount / entity.links.size, powerSpeed * Timers.delta()); + + for(int i = 0; i < entity.links.size; i ++){ + Tile target = world.tile(entity.links.get(i)); + float transmit = Math.min(result * Timers.delta(), entity.power.amount); + if(target.block().acceptPower(target, tile, transmit)){ + entity.power.amount -= target.block().addPower(target, transmit); + } + } + } + + protected void link(Tile tile, Tile other){ + DistributorEntity entity = tile.entity(); + + if(!entity.links.contains(other.packedPosition())){ + entity.links.add(other.packedPosition()); + } + + if(other.block() instanceof PowerDistributor){ + DistributorEntity oe = other.entity(); + + if(!oe.links.contains(tile.packedPosition())){ + oe.links.add(tile.packedPosition()); + } + } + } + + protected void unlink(Tile tile, Tile other){ + DistributorEntity entity = tile.entity(); + + entity.links.removeValue(other.packedPosition()); + + if(other.block() instanceof PowerDistributor){ + DistributorEntity oe = other.entity(); + + oe.links.removeValue(tile.packedPosition()); + } + } + + protected boolean linked(Tile tile, Tile other){ + return tile.entity().links.contains(other.packedPosition()); } protected boolean linkValid(Tile tile, Tile link){ - return tile != link && link != null && link.block() instanceof PowerDistributor && - Vector2.dst(tile.worldx(), tile.worldy(), link.worldx(), link.worldy()) < Math.max(laserRange * tilesize, - ((PowerDistributor)link.block()).laserRange * tilesize); + if(!(tile != link && link != null && link.block().hasPower)) return false; + + if(link.block() instanceof PowerDistributor){ + return Vector2.dst(tile.worldx(), tile.worldy(), link.worldx(), link.worldy()) <= Math.max(laserRange * tilesize, + ((PowerDistributor)link.block()).laserRange * tilesize) - tilesize/2f; + }else{ + return Vector2.dst(tile.worldx(), tile.worldy(), link.worldx(), link.worldy()) <= laserRange * tilesize - tilesize/2f; + } } protected void drawLaser(Tile tile, Tile target){ @@ -182,7 +249,7 @@ public class PowerDistributor extends PowerBlock{ float angle2 = angle1 + 180f; t1.trns(angle1, tile.block().size * tilesize/2f + 1f); - t2.trns(angle2,tile.block().size * tilesize/2f + 1f); + t2.trns(angle2, target.block().size * tilesize/2f + 1f); Shapes.laser("laser", "laser-end", x1 + t1.x, y1 + t1.y, x2 + t2.x, y2 + t2.y, thicknessScl); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/generation/PowerGenerator.java b/core/src/io/anuke/mindustry/world/blocks/types/generation/PowerGenerator.java index 5b1c652e6f..d99e67afa6 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/generation/PowerGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/generation/PowerGenerator.java @@ -1,7 +1,9 @@ package io.anuke.mindustry.world.blocks.types.generation; +import com.badlogic.gdx.math.GridPoint2; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.graphics.Fx; +import io.anuke.mindustry.world.Edges; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.types.PowerBlock; import io.anuke.ucore.core.Effects; @@ -9,14 +11,41 @@ import io.anuke.ucore.core.Timers; import io.anuke.ucore.util.Mathf; public class PowerGenerator extends PowerBlock { - protected float powerSpeed = 1f; public PowerGenerator(String name) { super(name); } protected void distributePower(Tile tile){ - //TODO! + TileEntity entity = tile.entity; + int sources = 0; + + for(GridPoint2 point : Edges.getEdges(size)){ + Tile target = tile.getNearby(point); + if(target != null && target.block().hasPower) sources ++; + } + + if(sources == 0) return; + + float result = entity.power.amount / sources; + + for(GridPoint2 point : Edges.getEdges(size)){ + Tile target = tile.getNearby(point); + if(target == null) continue; + target = target.target(); + + if(target.block().hasPower){ + float transmit = Math.min(result * Timers.delta(), entity.power.amount); + if(target.block().acceptPower(target, tile, transmit)){ + entity.power.amount -= target.block().addPower(target, transmit); + } + } + } + } + + @Override + public void update(Tile tile) { + distributePower(tile); } @Override