From 6fa14accfec9bdd35d461e8e00561f6fb6b04911 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 7 Dec 2018 15:19:14 -0500 Subject: [PATCH 1/2] Added proper core blocks / Murdered snek --- .../io/anuke/mindustry/content/Recipes.java | 24 +-- .../content/blocks/StorageBlocks.java | 5 +- .../world/blocks/storage/CoreBlock.java | 8 +- .../world/blocks/storage/SortedUnloader.java | 18 ++- .../world/blocks/storage/StorageBlock.java | 103 ++---------- .../world/blocks/storage/StorageGraph.java | 151 ------------------ .../world/blocks/storage/Unloader.java | 26 --- .../mindustry/world/blocks/storage/Vault.java | 1 - 8 files changed, 48 insertions(+), 288 deletions(-) delete mode 100644 core/src/io/anuke/mindustry/world/blocks/storage/StorageGraph.java delete mode 100644 core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index f236469ff9..7bca788480 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -42,17 +42,23 @@ public class Recipes implements ContentList{ new Recipe(defense, DefenseBlocks.surgeWall, new ItemStack(Items.surgealloy, 12)); new Recipe(defense, DefenseBlocks.surgeWallLarge, new ItemStack(Items.surgealloy, 12 * 4)); + new Recipe(effect, StorageBlocks.container, new ItemStack(Items.densealloy, 200)); + new Recipe(effect, StorageBlocks.vault, new ItemStack(Items.densealloy, 500), new ItemStack(Items.thorium, 250)); + + //core disabled due to being broken + new Recipe(effect, StorageBlocks.core, + new ItemStack(Items.copper, 2000), new ItemStack(Items.densealloy, 1500), + new ItemStack(Items.silicon, 1500), new ItemStack(Items.thorium, 500), + new ItemStack(Items.surgealloy, 500), new ItemStack(Items.phasefabric, 750) + ); + //projectors new Recipe(effect, DefenseBlocks.mendProjector, new ItemStack(Items.lead, 200), new ItemStack(Items.densealloy, 150), new ItemStack(Items.titanium, 50), new ItemStack(Items.silicon, 180)); new Recipe(effect, DefenseBlocks.overdriveProjector, new ItemStack(Items.lead, 200), new ItemStack(Items.densealloy, 150), new ItemStack(Items.titanium, 150), new ItemStack(Items.silicon, 250)); new Recipe(effect, DefenseBlocks.forceProjector, new ItemStack(Items.lead, 200), new ItemStack(Items.densealloy, 150), new ItemStack(Items.titanium, 150), new ItemStack(Items.silicon, 250)); - new Recipe(effect, StorageBlocks.unloader, new ItemStack(Items.densealloy, 50), new ItemStack(Items.silicon, 60)); - new Recipe(effect, StorageBlocks.container, new ItemStack(Items.densealloy, 200)); - new Recipe(effect, StorageBlocks.vault, new ItemStack(Items.densealloy, 500), new ItemStack(Items.thorium, 250)); - new Recipe(effect, DefenseBlocks.shockMine, new ItemStack(Items.lead, 50), new ItemStack(Items.silicon, 25)) - .setDependencies(Items.blastCompound); + .setDependencies(Items.blastCompound); //TURRETS new Recipe(turret, TurretBlocks.duo, new ItemStack(Items.copper, 40)).setAlwaysUnlocked(true); @@ -82,6 +88,7 @@ public class Recipes implements ContentList{ new Recipe(distribution, DistributionBlocks.sorter, new ItemStack(Items.densealloy, 4), new ItemStack(Items.copper, 4)); new Recipe(distribution, DistributionBlocks.overflowGate, new ItemStack(Items.densealloy, 4), new ItemStack(Items.copper, 8)); new Recipe(distribution, DistributionBlocks.itemBridge, new ItemStack(Items.densealloy, 8), new ItemStack(Items.copper, 8)); + new Recipe(distribution, StorageBlocks.unloader, new ItemStack(Items.densealloy, 50), new ItemStack(Items.silicon, 60)); new Recipe(distribution, DistributionBlocks.massDriver, new ItemStack(Items.densealloy, 250), new ItemStack(Items.silicon, 150), new ItemStack(Items.lead, 250), new ItemStack(Items.thorium, 100)); //CRAFTING @@ -134,13 +141,6 @@ public class Recipes implements ContentList{ new Recipe(power, PowerBlocks.thoriumReactor, new ItemStack(Items.lead, 600), new ItemStack(Items.silicon, 400), new ItemStack(Items.densealloy, 300), new ItemStack(Items.thorium, 300)); new Recipe(power, PowerBlocks.rtgGenerator, new ItemStack(Items.lead, 200), new ItemStack(Items.silicon, 150), new ItemStack(Items.phasefabric, 50), new ItemStack(Items.plastanium, 150), new ItemStack(Items.thorium, 100)); - //core disabled due to being broken - /*new Recipe(distribution, StorageBlocks.core, - new ItemStack(Items.copper, 2000), new ItemStack(Items.densealloy, 1500), - new ItemStack(Items.silicon, 1500), new ItemStack(Items.thorium, 500), - new ItemStack(Items.surgealloy, 500), new ItemStack(Items.phasefabric, 750) - );*/ - //DRILLS, PRODUCERS new Recipe(production, ProductionBlocks.mechanicalDrill, new ItemStack(Items.copper, 45)).setAlwaysUnlocked(true); new Recipe(production, ProductionBlocks.pneumaticDrill, new ItemStack(Items.copper, 60), new ItemStack(Items.densealloy, 50)); diff --git a/core/src/io/anuke/mindustry/content/blocks/StorageBlocks.java b/core/src/io/anuke/mindustry/content/blocks/StorageBlocks.java index 460a79da77..a4519d04cb 100644 --- a/core/src/io/anuke/mindustry/content/blocks/StorageBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/StorageBlocks.java @@ -13,16 +13,17 @@ public class StorageBlocks extends BlockList implements ContentList{ public void load(){ core = new CoreBlock("core"){{ health = 1100; + itemCapacity = 3000; }}; vault = new Vault("vault"){{ size = 3; - itemCapacity = 900; + itemCapacity = 1000; }}; container = new Vault("container"){{ size = 2; - itemCapacity = 200; + itemCapacity = 300; }}; unloader = new SortedUnloader("unloader"){{ diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index 591344afdb..3c6abdf84f 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -51,7 +51,6 @@ public class CoreBlock extends StorageBlock{ update = true; size = 3; hasItems = true; - itemCapacity = 2000; viewRange = 200f; flags = EnumSet.of(BlockFlag.resupplyPoint, BlockFlag.target); } @@ -85,6 +84,11 @@ public class CoreBlock extends StorageBlock{ @Override public void onProximityUpdate(Tile tile) { + for(Tile other : state.teams.get(tile.getTeam()).cores){ + if(other != tile){ + tile.entity.items = other.entity.items; + } + } state.teams.get(tile.getTeam()).cores.add(tile); } @@ -222,7 +226,7 @@ public class CoreBlock extends StorageBlock{ return new CoreEntity(); } - public class CoreEntity extends StorageEntity implements SpawnerTrait{ + public class CoreEntity extends TileEntity implements SpawnerTrait{ public Unit currentUnit; int droneID = -1; boolean solid = true; diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java b/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java index a0e1545255..7db33b0cac 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java @@ -7,6 +7,7 @@ import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.type.Item; +import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.SelectionTrait; import io.anuke.ucore.graphics.Draw; @@ -19,15 +20,30 @@ import java.io.IOException; import static io.anuke.mindustry.Vars.content; import static io.anuke.mindustry.Vars.threads; -public class SortedUnloader extends Unloader implements SelectionTrait{ +public class SortedUnloader extends Block implements SelectionTrait{ protected float speed = 1f; + protected final int timerUnload = timers++; + private static Item lastItem; public SortedUnloader(String name){ super(name); + update = true; + solid = true; + health = 70; + hasItems = true; configurable = true; } + @Override + public boolean canDump(Tile tile, Tile to, Item item){ + Block block = to.target().block(); + return !(block instanceof StorageBlock); + } + + @Override + public void setBars(){} + @Override public void playerPlaced(Tile tile){ threads.runDelay(() -> Call.setSortedUnloaderItem(null, tile, lastItem)); diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/StorageBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/StorageBlock.java index b6d2c738a9..530e49171c 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/StorageBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/StorageBlock.java @@ -1,20 +1,10 @@ package io.anuke.mindustry.world.blocks.storage; -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.entities.TileEntity; -import io.anuke.mindustry.entities.Unit; -import io.anuke.mindustry.graphics.Palette; -import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.world.BarType; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; -import io.anuke.ucore.core.Graphics; -import io.anuke.ucore.graphics.Draw; -import io.anuke.ucore.graphics.Fill; - -import static io.anuke.mindustry.Vars.tilesize; public abstract class StorageBlock extends Block{ @@ -23,6 +13,16 @@ public abstract class StorageBlock extends Block{ hasItems = true; } + @Override + public boolean acceptItem(Item item, Tile tile, Tile source){ + return tile.entity.items.get(item) < itemCapacity; + } + + @Override + public int getMaximumAccepted(Tile tile, Item item){ + return itemCapacity; + } + @Override public void setBars(){ super.setBars(); @@ -34,85 +34,6 @@ public abstract class StorageBlock extends Block{ return false; } - @Override - public void onProximityAdded(Tile tile){ - StorageEntity entity = tile.entity(); - entity.graph.set(tile); - - for(Tile prox : tile.entity.proximity()){ - if(prox.block() instanceof StorageBlock){ - StorageEntity other = prox.entity(); - entity.graph.merge(other.graph); - } - } - } - - @Override - public void onProximityRemoved(Tile tile){ - StorageEntity entity = tile.entity(); - entity.graph.remove(tile); - } - - @Override - public void drawSelect(Tile tile){ - - StorageEntity entity = tile.entity(); - - if(entity.graph.getTiles().size > 1){ - - Shaders.outline.color.set(Palette.accent); - Graphics.beginShaders(Shaders.outline); - - for(Tile other : entity.graph.getTiles()){ - Fill.square(other.drawx(), other.drawy(), other.block().size * tilesize); - } - - Draw.color(Color.CLEAR); - Graphics.endShaders(); - Draw.color(); - } - } - - @Override - public boolean acceptItem(Item item, Tile tile, Tile source){ - StorageEntity entity = tile.entity(); - return entity.graph.accept(item); - } - - @Override - public int acceptStack(Item item, int amount, Tile tile, Unit source){ - StorageEntity entity = tile.entity(); - if(acceptItem(item, tile, tile) && hasItems && (source == null || source.getTeam() == tile.getTeam())){ - return Math.min(entity.graph.accept(item, amount), amount); - }else{ - return 0; - } - } - - @Override - public float inventoryScaling(Tile tile){ - StorageEntity entity = tile.entity(); - return 1f / entity.graph.getTiles().size; - } - - @Override - public TileEntity newEntity(){ - return new StorageEntity(); - } - - @Override - public Array getDebugInfo(Tile tile){ - Array arr = super.getDebugInfo(tile); - - StorageEntity entity = tile.entity(); - arr.addAll("storage graph", entity.graph.getID(), - "graph capacity", entity.graph.getCapacity(), - "graph tiles", entity.graph.getTiles().size, - "graph item ID", entity.graph.items().getID()); - - return arr; - } - /** * Removes an item and returns it. If item is not null, it should return the item. * Returns null if no items are there. @@ -144,8 +65,4 @@ public abstract class StorageBlock extends Block{ return entity.items.has(item); } } - - public class StorageEntity extends TileEntity{ - public StorageGraph graph = new StorageGraph(); - } } diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/StorageGraph.java b/core/src/io/anuke/mindustry/world/blocks/storage/StorageGraph.java deleted file mode 100644 index fd8edb912b..0000000000 --- a/core/src/io/anuke/mindustry/world/blocks/storage/StorageGraph.java +++ /dev/null @@ -1,151 +0,0 @@ -package io.anuke.mindustry.world.blocks.storage; - -import com.badlogic.gdx.utils.IntSet; -import com.badlogic.gdx.utils.ObjectSet; -import com.badlogic.gdx.utils.Queue; -import io.anuke.mindustry.type.Item; -import io.anuke.mindustry.world.Tile; -import io.anuke.mindustry.world.blocks.storage.StorageBlock.StorageEntity; -import io.anuke.mindustry.world.modules.ItemModule; - -public class StorageGraph{ - private static IntSet closedSet = new IntSet(); - private static Queue queue = new Queue<>(); - private static ObjectSet itemSet = new ObjectSet<>(); - private static int lastID; - - private final int id = lastID++; - private ObjectSet tiles = new ObjectSet<>(); - private ItemModule items = new ItemModule(); - private int capacity; - - public void set(Tile tile){ - items.addAll(tile.entity.items); - items.setID(tile.entity.items.getID()); - - add(tile); - } - - public void add(Tile tile){ - - if(!tiles.add(tile)) return; - - StorageEntity e = tile.entity(); - e.graph = this; - - capacity += tile.block().itemCapacity; - - if(tile.entity.items != null && tile.entity.items.getID() != items.getID()){ - items.addAll(tile.entity.items); - } - - tile.entity.items = items; - } - - public void remove(Tile tile){ - if(!tiles.contains(tile)) return; - - for(Tile other : tiles){ - if(other == tile) continue; - - StorageEntity entity = other.entity(); - entity.graph = null; - entity.items = new ItemModule(); - - float fraction = (float)other.block().itemCapacity / capacity; - items.forEach((item, amount) -> { - int added = (int)(fraction * amount); - entity.items.add(item, added); - items.remove(item, added); - }); - } - - //handle remaining items that didn't get added - Item taken; - while((taken = items.take()) != null){ - for(Tile other : tiles){ - if(other == tile) continue; - - //insert item into first found block - if(other.entity.items.get(taken) < other.block().itemCapacity){ - other.entity.items.add(taken, 1); - break; - } - } - } - - items.clear(); - capacity = 0; - - for(Tile other : tile.entity.proximity()){ - if(other.block() instanceof StorageBlock && other.entity().graph == null){ - StorageGraph graph = new StorageGraph(); - other.entity().graph = graph; - graph.reflow(tile, other); - } - } - } - - public void reflow(Tile base, Tile tile){ - queue.clear(); - queue.addLast(tile); - closedSet.clear(); - itemSet.clear(); - - while(queue.size > 0){ - Tile child = queue.removeFirst(); - StorageEntity entity = child.entity(); - entity.graph = this; - - if(!itemSet.add(child.entity.items)) child.entity.items = null; - add(child); - - for(Tile next : child.entity.proximity()){ - if(next != base && next.block() instanceof StorageBlock && next.entity().graph == null && !closedSet.contains(next.pos())){ - queue.addLast(next); - closedSet.add(next.pos()); - } - } - } - } - - public void merge(StorageGraph other){ - if(this == other || other == null) return; - - itemSet.clear(); - for(Tile tile : other.tiles){ - if(!itemSet.add(tile.entity.items)){ - tile.entity.items = null; - } - } - - for(Tile tile : other.tiles){ - add(tile); - } - } - - public boolean accept(Item item){ - return accept(item, 1) == 1; - } - - public int accept(Item item, int amount){ - return Math.min(capacity - items.get(item), amount); - } - - public ObjectSet getTiles(){ - return tiles; - } - - public int getID(){ - return id; - } - - public int getCapacity(){ - return capacity; - } - - public ItemModule items(){ - return items; - } - -} diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java b/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java deleted file mode 100644 index c42c272985..0000000000 --- a/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.anuke.mindustry.world.blocks.storage; - -import io.anuke.mindustry.type.Item; -import io.anuke.mindustry.world.Block; -import io.anuke.mindustry.world.Tile; - -public abstract class Unloader extends Block{ - protected final int timerUnload = timers++; - - public Unloader(String name){ - super(name); - update = true; - solid = true; - health = 70; - hasItems = true; - } - - @Override - public boolean canDump(Tile tile, Tile to, Item item){ - Block block = to.target().block(); - return !(block instanceof StorageBlock); - } - - @Override - public void setBars(){} -} diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/Vault.java b/core/src/io/anuke/mindustry/world/blocks/storage/Vault.java index 28beaad8f2..4ee9cf97b7 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/Vault.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/Vault.java @@ -7,7 +7,6 @@ public class Vault extends StorageBlock{ solid = true; update = false; destructible = true; - itemCapacity = 1000; } } From b427185fac832b68895f2ae1ad397507edd7baa6 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 7 Dec 2018 19:32:44 -0500 Subject: [PATCH 2/2] 'Added' attack mode / Core inventory sharing --- core/src/io/anuke/mindustry/game/GameMode.java | 1 - core/src/io/anuke/mindustry/input/MobileInput.java | 10 +++++----- .../mindustry/world/blocks/storage/CoreBlock.java | 10 ++++++++++ .../mindustry/world/blocks/storage/StorageBlock.java | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/src/io/anuke/mindustry/game/GameMode.java b/core/src/io/anuke/mindustry/game/GameMode.java index 0e7de8475f..cd4057012a 100644 --- a/core/src/io/anuke/mindustry/game/GameMode.java +++ b/core/src/io/anuke/mindustry/game/GameMode.java @@ -13,7 +13,6 @@ public enum GameMode{ }}, attack{{ disableWaves = true; - hidden = true; enemyCheat = true; }}, victory{{ diff --git a/core/src/io/anuke/mindustry/input/MobileInput.java b/core/src/io/anuke/mindustry/input/MobileInput.java index 314d20819e..9379b8c917 100644 --- a/core/src/io/anuke/mindustry/input/MobileInput.java +++ b/core/src/io/anuke/mindustry/input/MobileInput.java @@ -221,11 +221,6 @@ public class MobileInput extends InputHandler implements GestureListener{ } }).update(l -> l.setChecked(mode == breaking)); - //rotate button - table.addImageButton("icon-arrow", "clear-partial", 16 * 2f, () -> rotation = Mathf.mod(rotation + 1, 4)) - .update(i -> i.getImage().setRotationOrigin(rotation * 90, Align.center)) - .visible(() -> recipe != null && recipe.result.rotate); - //cancel button table.addImageButton("icon-cancel", "clear-partial", 16 * 2f, () -> { player.clearBuilding(); @@ -233,6 +228,11 @@ public class MobileInput extends InputHandler implements GestureListener{ recipe = null; }).visible(() -> player.isBuilding() || recipe != null || mode == breaking); + //rotate button + table.addImageButton("icon-arrow", "clear-partial", 16 * 2f, () -> rotation = Mathf.mod(rotation + 1, 4)) + .update(i -> i.getImage().setRotationOrigin(rotation * 90, Align.center)) + .visible(() -> recipe != null && recipe.result.rotate); + //confirm button table.addImageButton("icon-check", "clear-partial", 16 * 2f, () -> { for(PlaceRequest request : selection){ diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index 3c6abdf84f..33f98fd2ce 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -82,6 +82,11 @@ public class CoreBlock extends StorageBlock{ if(entity != null) entity.solid = solid; } + @Override + public int getMaximumAccepted(Tile tile, Item item){ + return itemCapacity * state.teams.get(tile.getTeam()).cores.size; + } + @Override public void onProximityUpdate(Tile tile) { for(Tile other : state.teams.get(tile.getTeam()).cores){ @@ -100,6 +105,11 @@ public class CoreBlock extends StorageBlock{ @Override public void removed(Tile tile){ state.teams.get(tile.getTeam()).cores.remove(tile); + + int max = itemCapacity * state.teams.get(tile.getTeam()).cores.size; + for(Item item : content.items()){ + tile.entity.items.set(item, Math.min(tile.entity.items.get(item), max)); + } } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/StorageBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/StorageBlock.java index 530e49171c..324c86008a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/StorageBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/StorageBlock.java @@ -15,7 +15,7 @@ public abstract class StorageBlock extends Block{ @Override public boolean acceptItem(Item item, Tile tile, Tile source){ - return tile.entity.items.get(item) < itemCapacity; + return tile.entity.items.get(item) < getMaximumAccepted(tile, item); } @Override