1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-10 15:05:23 +03:00

Merge branch 'master' of https://github.com/Anuken/Mindustry into baltitenger

This commit is contained in:
Timmeey86 2018-12-08 20:07:45 +01:00
commit 41c6887f33
10 changed files with 63 additions and 294 deletions

View File

@ -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));

View File

@ -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"){{

View File

@ -13,7 +13,6 @@ public enum GameMode{
}},
attack{{
disableWaves = true;
hidden = true;
enemyCheat = true;
}},
victory{{

View File

@ -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){

View File

@ -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);
}
@ -83,8 +82,18 @@ 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){
if(other != tile){
tile.entity.items = other.entity.items;
}
}
state.teams.get(tile.getTeam()).cores.add(tile);
}
@ -96,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
@ -222,7 +236,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;

View File

@ -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));

View File

@ -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) < getMaximumAccepted(tile, item);
}
@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<Object> getDebugInfo(Tile tile){
Array<Object> 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();
}
}

View File

@ -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<Tile> queue = new Queue<>();
private static ObjectSet<ItemModule> itemSet = new ObjectSet<>();
private static int lastID;
private final int id = lastID++;
private ObjectSet<Tile> 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.<StorageEntity>entity().graph == null){
StorageGraph graph = new StorageGraph();
other.<StorageEntity>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.<StorageEntity>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<Tile> getTiles(){
return tiles;
}
public int getID(){
return id;
}
public int getCapacity(){
return capacity;
}
public ItemModule items(){
return items;
}
}

View File

@ -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(){}
}

View File

@ -7,7 +7,6 @@ public class Vault extends StorageBlock{
solid = true;
update = false;
destructible = true;
itemCapacity = 1000;
}
}