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 0000000000..0098e0cbcd Binary files /dev/null and b/core/assets-raw/sprites/blocks/environment/lead1.png differ diff --git a/core/assets-raw/sprites/blocks/environment/lead2.png b/core/assets-raw/sprites/blocks/environment/lead2.png new file mode 100644 index 0000000000..e41fd23c79 Binary files /dev/null and b/core/assets-raw/sprites/blocks/environment/lead2.png differ 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 0000000000..061eb04e00 Binary files /dev/null and b/core/assets-raw/sprites/blocks/environment/lead3.png differ diff --git a/core/assets-raw/sprites/blocks/production/leaddrill.png b/core/assets-raw/sprites/blocks/production/leaddrill.png new file mode 100644 index 0000000000..3b1a608077 Binary files /dev/null and b/core/assets-raw/sprites/blocks/production/leaddrill.png differ 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 0000000000..5d0ce18461 Binary files /dev/null and b/core/assets-raw/sprites/blocks/tech/powernode.png differ 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 0000000000..d678fb0a81 Binary files /dev/null and b/core/assets-raw/sprites/effects/laser-end.png differ 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 0000000000..e0bb050697 Binary files /dev/null and b/core/assets-raw/sprites/items/item-lead.png differ diff --git a/core/assets/version.properties b/core/assets/version.properties index 65ceb224c5..081e2158aa 100644 --- a/core/assets/version.properties +++ b/core/assets/version.properties @@ -1,7 +1,7 @@ #Autogenerated file. Do not modify. -#Fri Mar 23 20:15:39 EDT 2018 +#Fri Mar 23 22:35:52 EDT 2018 version=release -androidBuildCode=621 +androidBuildCode=623 name=Mindustry code=3.4 build=custom build diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 6a9cb3b196..af710cb783 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -109,12 +109,6 @@ public class Control extends Module{ DefaultKeybinds.load(); - for(int i = 0; i < saveSlots; i ++){ - Settings.defaults("save-" + i + "-autosave", !gwt); - Settings.defaults("save-" + i + "-name", "untitled"); - Settings.defaults("save-" + i + "-data", "empty"); - } - Settings.defaultList( "ip", "localhost", "port", port+"", @@ -172,7 +166,7 @@ public class Control extends Module{ Events.on(WaveEvent.class, () -> { 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