Storage blocks, organized sprites, liquid tunnel implementation
This commit is contained in:
@@ -33,12 +33,10 @@ import java.nio.ByteBuffer;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class NetServer extends Module{
|
||||
private final static float serverSyncTime = 4, itemSyncTime = 10, blockSyncTime = 120;
|
||||
private final static boolean sendBlockSync = false;
|
||||
private final static float serverSyncTime = 4, itemSyncTime = 10;
|
||||
|
||||
private final static int timerEntitySync = 0;
|
||||
private final static int timerStateSync = 1;
|
||||
private final static int timerBlockSync = 2;
|
||||
|
||||
public final Administration admins = new Administration();
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ public class Inventory {
|
||||
addItem(Item.stone, 40);
|
||||
|
||||
if(debug){
|
||||
Arrays.fill(items, 99999);
|
||||
for(Item item : Item.getAllItems()){
|
||||
if(item.material) items[item.id] = 99999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,13 @@ public class Recipes {
|
||||
new Recipe(distribution, DistributionBlocks.steelconveyor, stack(Item.steel, 1)),
|
||||
new Recipe(distribution, DistributionBlocks.pulseconveyor, stack(Item.dirium, 1)),
|
||||
new Recipe(distribution, DistributionBlocks.router, stack(Item.stone, 2)),
|
||||
new Recipe(distribution, DistributionBlocks.vault, stack(Item.iron, 8)),
|
||||
new Recipe(distribution, DistributionBlocks.multiplexer, stack(Item.iron, 8)),
|
||||
new Recipe(distribution, DistributionBlocks.junction, stack(Item.iron, 2)),
|
||||
new Recipe(distribution, DistributionBlocks.tunnel, stack(Item.iron, 2)),
|
||||
new Recipe(distribution, DistributionBlocks.sorter, stack(Item.steel, 2)),
|
||||
new Recipe(distribution, DistributionBlocks.splitter, stack(Item.steel, 1)),
|
||||
new Recipe(distribution, DistributionBlocks.vault, stack(Item.steel, 50)),
|
||||
new Recipe(distribution, DistributionBlocks.unloader, stack(Item.steel, 5)),
|
||||
|
||||
//new Recipe(weapon, WeaponBlocks.turret, stack(Item.stone, 4)),
|
||||
new Recipe(weapon, WeaponBlocks.doubleturret, stack(Item.stone, 7)),
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
@@ -115,9 +114,7 @@ public class BlocksFragment implements Fragment{
|
||||
int i = 0;
|
||||
|
||||
for (Recipe r : recipes) {
|
||||
TextureRegion region = Draw.hasRegion(r.result.name() + "-icon") ?
|
||||
Draw.region(r.result.name() + "-icon") : Draw.region(r.result.name());
|
||||
ImageButton image = new ImageButton(region, "select");
|
||||
ImageButton image = new ImageButton(r.result.getIcon(), "select");
|
||||
|
||||
image.addListener(new ClickListener(){
|
||||
@Override
|
||||
@@ -252,10 +249,7 @@ public class BlocksFragment implements Fragment{
|
||||
|
||||
desctable.row();
|
||||
|
||||
TextureRegion region = Draw.hasRegion(recipe.result.name() + "-icon") ?
|
||||
Draw.region(recipe.result.name() + "-icon") : Draw.region(recipe.result.name());
|
||||
|
||||
header.addImage(region).size(8*5).padTop(4);
|
||||
header.addImage(recipe.result.getIcon()).size(8*5).padTop(4);
|
||||
Label nameLabel = new Label(recipe.result.formalName);
|
||||
nameLabel.setWrap(true);
|
||||
header.add(nameLabel).padLeft(2).width(120f);
|
||||
@@ -357,6 +351,8 @@ public class BlocksFragment implements Fragment{
|
||||
return;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
|
||||
for(int i = 0; i < state.inventory.getItems().length; i ++){
|
||||
int amount = state.inventory.getItems()[i];
|
||||
if(amount == 0) continue;
|
||||
@@ -367,7 +363,7 @@ public class BlocksFragment implements Fragment{
|
||||
label.setFontScale(fontscale*1.5f);
|
||||
itemtable.add(image).size(8*3);
|
||||
itemtable.add(label).expandX().left();
|
||||
if(i % 2 == 1 && i > 0) itemtable.row();
|
||||
if(index++ % 2 == 1 && index > 0) itemtable.row();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,17 @@ public class Block{
|
||||
Effects.effect(explosionEffect, x, y);
|
||||
Effects.sound(explosionSound, x, y);
|
||||
}
|
||||
|
||||
public TextureRegion getIcon(){
|
||||
if(Draw.hasRegion(name + "-icon")){
|
||||
return Draw.region(name + "-icon");
|
||||
}else{
|
||||
TextureRegion region = new TextureRegion(Draw.region(name));
|
||||
region.setRegionWidth(8);
|
||||
region.setRegionHeight(8);
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
public TileEntity getEntity(){
|
||||
return new TileEntity();
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
@@ -227,8 +228,22 @@ public class Tile{
|
||||
}
|
||||
}
|
||||
|
||||
public Tile getNearby(GridPoint2 relative){
|
||||
return world.tile(x + relative.x, y + relative.y);
|
||||
public void allNearby(Consumer<Tile> cons){
|
||||
for(GridPoint2 point : Edges.getEdges(block().width)){
|
||||
Tile tile = world.tile(x + point.x, y + point.y);
|
||||
if(tile != null){
|
||||
cons.accept(tile.target());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void allInside(Consumer<Tile> cons){
|
||||
for(GridPoint2 point : Edges.getInsideEdges(block().width)){
|
||||
Tile tile = world.tile(x + point.x, y + point.y);
|
||||
if(tile != null){
|
||||
cons.accept(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Tile target(){
|
||||
@@ -236,6 +251,10 @@ public class Tile{
|
||||
return link == null ? this : link;
|
||||
}
|
||||
|
||||
public Tile getNearby(GridPoint2 relative){
|
||||
return world.tile(x + relative.x, y + relative.y);
|
||||
}
|
||||
|
||||
public Tile getNearby(int rotation){
|
||||
if(rotation == 0) return world.tile(x + 1, y);
|
||||
if(rotation == 1) return world.tile(x, y + 1);
|
||||
|
||||
@@ -2,6 +2,8 @@ package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.distribution.*;
|
||||
import io.anuke.mindustry.world.blocks.types.storage.Unloader;
|
||||
import io.anuke.mindustry.world.blocks.types.storage.Vault;
|
||||
|
||||
public class DistributionBlocks{
|
||||
|
||||
@@ -38,8 +40,17 @@ public class DistributionBlocks{
|
||||
|
||||
}},
|
||||
|
||||
vault = new Router("vault"){{
|
||||
multiplexer = new Router("multiplexer"){{
|
||||
width = height = 2;
|
||||
capacity = 80;
|
||||
}},
|
||||
|
||||
vault = new Vault("vault"){{
|
||||
width = height = 3;
|
||||
}},
|
||||
|
||||
unloader = new Unloader("unloader"){{
|
||||
|
||||
}},
|
||||
|
||||
junction = new Junction("junction"){{
|
||||
|
||||
@@ -160,7 +160,7 @@ public class WeaponBlocks{
|
||||
shootsound = "bigshot";
|
||||
inaccuracy = 8f;
|
||||
range = 80f;
|
||||
reload = 5f;
|
||||
reload = 8f;
|
||||
bullet = BulletType.chain;
|
||||
ammo = Item.uranium;
|
||||
health = 430;
|
||||
|
||||
@@ -9,9 +9,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class Router extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
int capacity = 20;
|
||||
protected int capacity = 20;
|
||||
|
||||
public Router(String name) {
|
||||
super(name);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidAcceptor;
|
||||
|
||||
public class TunnelConduit extends Conduit {
|
||||
protected int maxdist = 3;
|
||||
protected float speed = 53;
|
||||
|
||||
protected TunnelConduit(String name) {
|
||||
super(name);
|
||||
rotate = true;
|
||||
update = false;
|
||||
solid = true;
|
||||
health = 70;
|
||||
instantTransfer = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
|
||||
Tile tunnel = getDestTunnel(tile, liquid, amount);
|
||||
if (tunnel == null) return;
|
||||
Tile to = tunnel.getNearby(tunnel.getRotation());
|
||||
if (to == null || !(to instanceof LiquidAcceptor)) return;
|
||||
|
||||
LiquidAcceptor a = (LiquidAcceptor) to.block();
|
||||
|
||||
if (a.acceptLiquid(tile, source, liquid, amount)) a.handleLiquid(to, tunnel, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
|
||||
TunnelConveyor.TunnelEntity entity = tile.entity();
|
||||
|
||||
if (entity.index >= entity.buffer.length - 1) return false;
|
||||
|
||||
int rot = source.relativeTo(tile.x, tile.y);
|
||||
if (rot != (tile.getRotation() + 2) % 4) return false;
|
||||
Tile tunnel = getDestTunnel(tile, liquid, amount);
|
||||
|
||||
if (tunnel != null) {
|
||||
Tile to = tunnel.getNearby(tunnel.getRotation());
|
||||
return to != null && (to instanceof LiquidAcceptor) && ((LiquidAcceptor) to.block()).acceptLiquid(to, tunnel, liquid, amount);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Tile getDestTunnel(Tile tile, Liquid liquid, float amount) {
|
||||
Tile dest = tile;
|
||||
int rel = (tile.getRotation() + 2) % 4;
|
||||
for (int i = 0; i < maxdist; i++) {
|
||||
if (dest == null) return null;
|
||||
dest = dest.getNearby(rel);
|
||||
if (dest != null && dest.block() instanceof TunnelConduit && dest.getRotation() == rel
|
||||
&& dest.getNearby(rel) != null
|
||||
&& ((TunnelConduit) dest.getNearby(rel).block()).acceptLiquid(dest.getNearby(rel), dest, liquid, amount)) {
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,13 @@ package io.anuke.mindustry.world.blocks.types.storage;
|
||||
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.debug;
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
|
||||
public class CoreBlock extends Block {
|
||||
public class CoreBlock extends StorageBlock {
|
||||
protected int capacity = 1000;
|
||||
|
||||
public CoreBlock(String name) {
|
||||
super(name);
|
||||
@@ -32,6 +32,6 @@ public class CoreBlock extends Block {
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return item.material;
|
||||
return item.material && tile.entity.getItem(item) < capacity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.anuke.mindustry.world.blocks.types.storage;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
public abstract class StorageBlock extends Block {
|
||||
|
||||
public StorageBlock(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**Removes any one item and returns it. Returns null if no items are there.*/
|
||||
public Item removeItem(Tile tile){
|
||||
TileEntity entity = tile.entity;
|
||||
for(int i = 0; i < entity.items.length; i ++){
|
||||
if(entity.items[i] > 0){
|
||||
entity.items[i] --;
|
||||
return Item.getByID(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.anuke.mindustry.world.blocks.types.storage;
|
||||
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
public class Unloader extends Block {
|
||||
protected final int timerUnload = timers++;
|
||||
|
||||
public Unloader(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
health = 70;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
if(tile.entity.totalItems() == 0 && tile.entity.timer.get(timerUnload, 5)){
|
||||
tile.allNearby(other -> {
|
||||
if(tile.entity.totalItems() == 0 && other.block() instanceof StorageBlock &&
|
||||
other.entity.totalItems() > 0){
|
||||
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(tile.entity.totalItems() > 0){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDump(Tile tile, Tile to, Item item) {
|
||||
Block block = to.target().block();
|
||||
return !(block instanceof StorageBlock);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,12 @@ package io.anuke.mindustry.world.blocks.types.storage;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class Vault extends Block {
|
||||
public int capacity;
|
||||
public class Vault extends StorageBlock {
|
||||
public int capacity = 1000;
|
||||
|
||||
public Vault(String name){
|
||||
super(name);
|
||||
@@ -29,7 +28,7 @@ public class Vault extends Block {
|
||||
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
|
||||
|
||||
for(int i = 0; i < iterations; i ++) {
|
||||
if (tile.entity.totalItems() > 0) { //TODO only output to the right blocks
|
||||
if (tile.entity.totalItems() > 0) {
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +47,6 @@ public class Vault extends Block {
|
||||
|
||||
@Override
|
||||
public boolean canDump(Tile tile, Tile to, Item item){
|
||||
return to != null && (to.block() instanceof Vault || to.block() instanceof CoreBlock);
|
||||
return to.target().block() instanceof StorageBlock;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user