Removed tunnels / Added item bridge

This commit is contained in:
Anuken
2018-04-11 21:14:12 -04:00
parent f8b0819fb3
commit 2c769cad0b
18 changed files with 528 additions and 256 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

After

Width:  |  Height:  |  Size: 235 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 104 KiB

View File

@ -1,7 +1,7 @@
#Autogenerated file. Do not modify.
#Tue Apr 10 22:25:05 EDT 2018
#Wed Apr 11 21:11:23 EDT 2018
version=release
androidBuildCode=897
androidBuildCode=908
name=Mindustry
code=3.5
build=custom build

View File

@ -40,6 +40,7 @@ public class Recipes {
new Recipe(distribution, StorageBlocks.unloader, stack(Items.steel, 5)),
new Recipe(distribution, StorageBlocks.sortedunloader, stack(Items.steel, 5)),
new Recipe(distribution, DistributionBlocks.bridgeconveyor, stack(Items.steel, 5)),
new Recipe(distribution, DistributionBlocks.laserconveyor, stack(Items.steel, 5)),
new Recipe(weapon, WeaponBlocks.doubleturret, stack(Items.iron, 7)),
new Recipe(weapon, WeaponBlocks.gatlingturret, stack(Items.iron, 8)),
@ -71,7 +72,6 @@ public class Recipes {
new Recipe(crafting, CraftingBlocks.incinerator, stack(Items.steel, 60), stack(Items.iron, 60)),
new Recipe(crafting, CraftingBlocks.weaponFactory, stack(Items.steel, 60), stack(Items.iron, 60)).setDesktop(),
//new Recipe(production, ProductionBlocks.stonedrill, stack(Item.stone, 12)),
new Recipe(production, ProductionBlocks.ironDrill, stack(Items.iron, 25)),
new Recipe(production, ProductionBlocks.reinforcedDrill, stack(Items.iron, 25)),
new Recipe(production, ProductionBlocks.steelDrill, stack(Items.iron, 25)),
@ -79,11 +79,6 @@ public class Recipes {
new Recipe(production, ProductionBlocks.laserdrill, stack(Items.titanium, 40), stack(Items.densealloy, 40)),
new Recipe(production, ProductionBlocks.nucleardrill, stack(Items.titanium, 40), stack(Items.densealloy, 40)),
new Recipe(production, ProductionBlocks.plasmadrill, stack(Items.titanium, 40), stack(Items.densealloy, 40)),
//new Recipe(production, ProductionBlocks.leaddrill, stack(Items.iron, 25)),
//new Recipe(production, ProductionBlocks.coaldrill, stack(Items.iron, 25), stack(Items.iron, 40)),
//new Recipe(production, ProductionBlocks.titaniumdrill, stack(Items.iron, 50), stack(Items.steel, 50)),
//new Recipe(production, ProductionBlocks.thoriumdrill, stack(Items.iron, 40), stack(Items.steel, 40)),
//new Recipe(production, ProductionBlocks.quartzextractor, stack(Items.titanium, 40), stack(Items.densealloy, 40)),
new Recipe(production, ProductionBlocks.cultivator, stack(Items.titanium, 40), stack(Items.densealloy, 40)),
new Recipe(production, ProductionBlocks.waterextractor, stack(Items.titanium, 40), stack(Items.densealloy, 40)),
new Recipe(production, ProductionBlocks.oilextractor, stack(Items.titanium, 40), stack(Items.densealloy, 40)),

View File

@ -34,8 +34,9 @@ public class DistributionBlocks{
capacity = 32;
}},
bridgeconveyor = new ItemBridge("bridgeconveyor"){{
range = 2;
bridgeconveyor = new BufferedItemBridge("bridgeconveyor"){{
range = 3;
hasPower = false;
}},
laserconveyor = new ItemBridge("laserconveyor"){{

View File

@ -37,7 +37,7 @@ public class LiquidBlocks {
liquidjunction = new LiquidJunction("liquidjunction"),
bridgeconduit = new LiquidBridge("bridgeconduit"){{
range = 7;
range = 3;
}},
laserconduit = new LiquidBridge("laserconduit"){{

View File

@ -5,12 +5,12 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.content.fx.ExplosionFx;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.graphics.DrawLayer;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.content.fx.ExplosionFx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.ItemStack;

View File

@ -0,0 +1,44 @@
package io.anuke.mindustry.world;
import com.badlogic.gdx.utils.NumberUtils;
import io.anuke.mindustry.resource.Item;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Bits;
public class ItemBuffer {
private final float speed;
private long[] buffer;
private int index;
public ItemBuffer(int capacity, float speed){
this.buffer = new long[capacity];
this.speed = speed;
}
public boolean accepts(){
return index < buffer.length;
}
public void accept(Item item){
//if(!accepts()) return;
buffer[index ++] = Bits.packLong(NumberUtils.floatToIntBits(Timers.time()), item.id);
}
public Item poll(){
if(index > 0){
long l = buffer[0];
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
if(Timers.time() >= time + speed || Timers.time() < time){
return Item.getByID(Bits.getRightInt(l));
}
}
return null;
}
public void remove(){
System.arraycopy(buffer, 1, buffer, 0, index - 1);
index --;
}
}

View File

@ -0,0 +1,108 @@
package io.anuke.mindustry.world.blocks.types.distribution;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.ItemBuffer;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.CapStyle;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class BufferedItemBridge extends ItemBridge {
protected int timerAccept = timers ++;
protected float speed = 40f;
protected int bufferCapacity = 50;
public BufferedItemBridge(String name) {
super(name);
hasPower = false;
}
@Override
public void updateTransport(Tile tile, Tile other){
BufferedItemBridgeEntity entity = tile.entity();
if(entity.buffer.accepts() && entity.inventory.totalItems() > 0){
entity.buffer.accept(entity.inventory.takeItem());
}
Item item = entity.buffer.poll();
if(entity.timer.get(timerAccept, 4) && item != null && other.block().acceptItem(item, other, tile)){
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
other.block().handleItem(item, other, tile);
entity.buffer.remove();
}else{
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 0f, 0.008f);
}
}
@Override
public void drawLayer(Tile tile) {
BufferedItemBridgeEntity entity = tile.entity();
Tile other = world.tile(entity.link);
if(!linkValid(tile, other)) return;
int i = tile.absoluteRelativeTo(other.x, other.y);
float ex = other.worldx() - tile.worldx(),
ey = other.worldy() - tile.worldy();
ex *= entity.uptime;
ey *= entity.uptime;
Lines.stroke(8f);
Lines.line(Draw.region(name + "-bridge"),
tile.worldx(),
tile.worldy(),
tile.worldx() + ex,
tile.worldy() + ey, CapStyle.none, -tilesize/2f);
Draw.rect(name + "-end", tile.drawx(), tile.drawy(), i*90 + 90);
Draw.rect(name + "-end", tile.worldx() + ex, tile.worldy() + ey, i*90 + 270);
int dist = Math.max(Math.abs(other.x - tile.x), Math.abs(other.y - tile.y));
int arrows = (dist)*tilesize/6-1;
Draw.color();
for(int a = 0; a < arrows; a ++){
Draw.alpha(Mathf.absin(a/(float)arrows - entity.time/100f, 0.1f, 1f) * entity.uptime);
Draw.rect(name + "-arrow",
tile.worldx() + Geometry.d4[i].x*(tilesize/2f + a*6f + 2) * entity.uptime,
tile.worldy() + Geometry.d4[i].y*(tilesize/2f + a*6f + 2) * entity.uptime,
i*90f);
}
Draw.reset();
}
@Override
public TileEntity getEntity() {
return new BufferedItemBridgeEntity();
}
class BufferedItemBridgeEntity extends ItemBridgeEntity{
ItemBuffer buffer = new ItemBuffer(bufferCapacity, speed);
@Override
public void write(DataOutputStream stream) throws IOException {
super.write(stream);
}
@Override
public void read(DataInputStream stream) throws IOException {
super.read(stream);
}
}
}

View File

@ -28,9 +28,10 @@ public class Conveyor extends Block{
private static ItemPos pos2 = new ItemPos();
private static final float itemSpace = 0.135f * 2.2f;
private static final float offsetScl = 128f*3f;
private static final float itemSize = 5f;
private static final float minmove = 1f / (Short.MAX_VALUE - 2);
public static final float itemSize = 5f;
private final Translator tr1 = new Translator();
private final Translator tr2 = new Translator();

View File

@ -1,6 +1,9 @@
package io.anuke.mindustry.world.blocks.types.distribution;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.IntSet;
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.resource.Item;
@ -27,6 +30,7 @@ public class ItemBridge extends Block {
protected int range;
protected float powerUse = 0.05f;
protected float transportTime = 2f;
protected IntArray removals = new IntArray();
public ItemBridge(String name) {
super(name);
@ -40,9 +44,12 @@ public class ItemBridge extends Block {
@Override
public void placed(Tile tile) {
if(linkValid(tile, world.tile(lastPlaced))){
ItemBridgeEntity entity = tile.entity();
entity.link = lastPlaced;
Tile last = world.tile(lastPlaced);
if(linkValid(tile, last)){
ItemBridgeEntity entity = last.entity();
if(!linkValid(last, world.tile(entity.link))){
link(last, tile);
}
}
lastPlaced = tile.packedPosition();
}
@ -99,9 +106,9 @@ public class ItemBridge extends Block {
if(linkValid(tile, other)){
if(entity.link == other.packedPosition()){
entity.link = -1;
unlink(tile, other);
}else{
entity.link = other.packedPosition();
link(tile, other);
}
return false;
}
@ -115,9 +122,25 @@ public class ItemBridge extends Block {
entity.time += entity.cycleSpeed*Timers.delta();
entity.time2 += (entity.cycleSpeed-1f)*Timers.delta();
removals.clear();
IntSetIterator it = entity.incoming.iterator();
while(it.hasNext){
int i = it.next();
Tile other = world.tile(i);
if(!linkValid(tile, other, false)){
removals.add(i);
}
}
for(int j = 0; j < removals.size; j ++)
entity.incoming.remove(removals.get(j));
Tile other = world.tile(entity.link);
if(!linkValid(tile, other)){
tryDump(tile);
entity.uptime = 0f;
}else{
float use = Math.min(powerCapacity, powerUse * Timers.delta());
@ -128,6 +151,13 @@ public class ItemBridge extends Block {
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
}
updateTransport(tile, other);
}
}
public void updateTransport(Tile tile, Tile other){
ItemBridgeEntity entity = tile.entity();
if(entity.uptime >= 0.5f && entity.timer.get(timerTransport, transportTime)){
Item item = entity.inventory.takeItem();
if(item != null && other.block().acceptItem(item, other, tile)){
@ -139,7 +169,6 @@ public class ItemBridge extends Block {
}
}
}
}
@Override
public void drawLayer(Tile tile) {
@ -185,26 +214,74 @@ public class ItemBridge extends Block {
return tile.entity.inventory.totalItems() < itemCapacity;
}
@Override
public boolean canDump(Tile tile, Tile to, Item item) {
ItemBridgeEntity entity = tile.entity();
Tile other = world.tile(entity.link);
if(!linkValid(tile, other)){
int i = tile.absoluteRelativeTo(to.x, to.y);
IntSetIterator it = entity.incoming.iterator();
while(it.hasNext){
int v = it.next();
int x = v % world.width();
int y = v / world.width();
if(tile.absoluteRelativeTo(x, y) == i){
return false;
}
}
return true;
}
int rel = tile.absoluteRelativeTo(other.x, other.y);
int rel2 = tile.relativeTo(to.x, to.y);
return rel != rel2;
}
@Override
public TileEntity getEntity() {
return new ItemBridgeEntity();
}
public void link(Tile tile, Tile other){
ItemBridgeEntity entity = tile.entity();
ItemBridgeEntity oe = other.entity();
entity.link = other.packedPosition();
oe.incoming.add(tile.packedPosition());
}
public void unlink(Tile tile, Tile other){
ItemBridgeEntity entity = tile.entity();
entity.link = -1;
if(other != null) {
ItemBridgeEntity oe = other.entity();
oe.incoming.remove(tile.packedPosition());
}
}
public boolean linkValid(Tile tile, Tile other){
return linkValid(tile, other, true);
}
public boolean linkValid(Tile tile, Tile other, boolean checkDouble){
if(other == null) return false;
if(tile.x == other.x){
if(Math.abs(tile.x - other.x) > range) return false;
}else if(tile.y == other.y){
if(Math.abs(tile.y - other.y) > range) return false;
}else if(tile.y == other.y){
if(Math.abs(tile.x - other.x) > range) return false;
}else{
return false;
}
return other.block() == this && other.<ItemBridgeEntity>entity().link != tile.packedPosition();
return other.block() == this && (!checkDouble || other.<ItemBridgeEntity>entity().link != tile.packedPosition());
}
public static class ItemBridgeEntity extends TileEntity{
public int link = -1;
public IntSet incoming = new IntSet();
public float uptime;
public float time;
public float time2;
@ -213,11 +290,24 @@ public class ItemBridge extends Block {
@Override
public void write(DataOutputStream stream) throws IOException {
stream.writeInt(link);
stream.writeFloat(uptime);
stream.writeByte(incoming.size);
IntSetIterator it = incoming.iterator();
while(it.hasNext){
stream.writeInt(it.next());
}
}
@Override
public void read(DataInputStream stream) throws IOException {
link = stream.readInt();
uptime = stream.readFloat();
byte links = stream.readByte();
for(int i = 0; i < links; i ++){
incoming.add(stream.readInt());
}
}
}
}

View File

@ -1,6 +1,5 @@
package io.anuke.mindustry.world.blocks.types.distribution;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.NumberUtils;
import io.anuke.mindustry.entities.TileEntity;
@ -61,11 +60,10 @@ public class TunnelConveyor extends Block{
}
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
public boolean acceptItem(Item item, Tile tile, Tile source) {
TunnelEntity entity = tile.entity();
int rot = source.relativeTo(tile.x, tile.y);
if(rot != (tile.getRotation() + 2)%4) return false;
return entity.index < entity.buffer.length - 1;
return rot == (tile.getRotation() + 2) % 4 && entity.index < entity.buffer.length - 1;
}
@Override