Fixed puddles not appearing / Overdrive tweaks
- Bridges, routers and junctions can (probably) be overdrived now, untested
This commit is contained in:
@@ -6,19 +6,15 @@ import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class DirectionalItemBuffer{
|
||||
public final long[][] buffers;
|
||||
public final int[] indexes;
|
||||
private final float speed;
|
||||
|
||||
public DirectionalItemBuffer(int capacity, float speed){
|
||||
public DirectionalItemBuffer(int capacity){
|
||||
this.buffers = new long[4][capacity];
|
||||
this.indexes = new int[5];
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public boolean accepts(int buffer){
|
||||
@@ -30,7 +26,7 @@ public class DirectionalItemBuffer{
|
||||
buffers[buffer][indexes[buffer]++] = BufferItem.get((byte)item.id, Time.time());
|
||||
}
|
||||
|
||||
public Item poll(int buffer){
|
||||
public Item poll(int buffer, float speed){
|
||||
if(indexes[buffer] > 0){
|
||||
long l = buffers[buffer][0];
|
||||
float time = BufferItem.time(l);
|
||||
|
||||
@@ -7,14 +7,11 @@ import mindustry.type.*;
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class ItemBuffer{
|
||||
private final float speed;
|
||||
|
||||
private long[] buffer;
|
||||
private int index;
|
||||
|
||||
public ItemBuffer(int capacity, float speed){
|
||||
public ItemBuffer(int capacity){
|
||||
this.buffer = new long[capacity];
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public boolean accepts(){
|
||||
@@ -30,7 +27,7 @@ public class ItemBuffer{
|
||||
accept(item, (short)-1);
|
||||
}
|
||||
|
||||
public Item poll(){
|
||||
public Item poll(float speed){
|
||||
if(index > 0){
|
||||
long l = buffer[0];
|
||||
float time = Float.intBitsToFloat(Pack.leftInt(l));
|
||||
@@ -42,18 +39,6 @@ public class ItemBuffer{
|
||||
return null;
|
||||
}
|
||||
|
||||
public short pollData(){
|
||||
if(index > 0){
|
||||
long l = buffer[0];
|
||||
float time = Float.intBitsToFloat(Pack.leftInt(l));
|
||||
|
||||
if(Time.time() >= time + speed || Time.time() < time){
|
||||
return Pack.rightShort(Pack.rightInt(l));
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
System.arraycopy(buffer, 1, buffer, 0, index - 1);
|
||||
index--;
|
||||
|
||||
@@ -16,10 +16,11 @@ public class BufferedItemBridge extends ExtendingItemBridge{
|
||||
super(name);
|
||||
hasPower = false;
|
||||
hasItems = true;
|
||||
canOverdrive = true;
|
||||
}
|
||||
|
||||
public class BufferedItemBridgeEntity extends ExtendingItemBridgeEntity{
|
||||
ItemBuffer buffer = new ItemBuffer(bufferCapacity, speed);
|
||||
ItemBuffer buffer = new ItemBuffer(bufferCapacity);
|
||||
|
||||
@Override
|
||||
public void updateTransport(Tilec other){
|
||||
@@ -27,7 +28,7 @@ public class BufferedItemBridge extends ExtendingItemBridge{
|
||||
buffer.accept(items.take());
|
||||
}
|
||||
|
||||
Item item = buffer.poll();
|
||||
Item item = buffer.poll(speed / timeScale);
|
||||
if(timer(timerAccept, 4) && item != null && other.acceptItem(this, item)){
|
||||
cycleSpeed = Mathf.lerpDelta(cycleSpeed, 4f, 0.05f);
|
||||
other.handleItem(this, item);
|
||||
|
||||
@@ -41,6 +41,8 @@ public class ItemBridge extends Block{
|
||||
hasItems = true;
|
||||
unloadable = false;
|
||||
group = BlockGroup.transportation;
|
||||
canOverdrive = false;
|
||||
|
||||
//point2 config is relative
|
||||
config(Point2.class, (tile, i) -> ((ItemBridgeEntity)tile).link = Point2.pack(i.x + tile.tileX(), i.y + tile.tileY()));
|
||||
//integer is not
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Junction extends Block{
|
||||
}
|
||||
|
||||
public class JunctionEntity extends TileEntity{
|
||||
DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity, speed);
|
||||
DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity);
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Teamc source){
|
||||
@@ -43,7 +43,7 @@ public class Junction extends Block{
|
||||
long l = buffer.buffers[i][0];
|
||||
float time = BufferItem.time(l);
|
||||
|
||||
if(Time.time() >= time + speed || Time.time() < time){
|
||||
if(Time.time() >= time + speed / timeScale || Time.time() < time){
|
||||
|
||||
Item item = content.item(BufferItem.item(l));
|
||||
Tilec dest = nearby(i);
|
||||
|
||||
@@ -22,6 +22,7 @@ public class OverflowGate extends Block{
|
||||
update = true;
|
||||
group = BlockGroup.transportation;
|
||||
unloadable = false;
|
||||
canOverdrive = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,7 +137,7 @@ public class OverflowGate extends Block{
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
if(revision == 1){
|
||||
new DirectionalItemBuffer(25, 50f).read(read);
|
||||
new DirectionalItemBuffer(25).read(read);
|
||||
}else if(revision == 3){
|
||||
lastInput = world.tile(read.i());
|
||||
lastItem = items.first();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
@@ -27,12 +26,12 @@ public class Router extends Block{
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(lastItem == null && items.total() > 0){
|
||||
if(lastItem == null && items.any()){
|
||||
items.clear();
|
||||
}
|
||||
|
||||
if(lastItem != null){
|
||||
time += 1f / speed * Time.delta();
|
||||
time += 1f / speed * delta();
|
||||
Tilec target = getTileTarget(lastItem, lastInput, false);
|
||||
|
||||
if(target != null && (time >= 1f || !(target.block() instanceof Router))){
|
||||
|
||||
@@ -170,7 +170,7 @@ public class Sorter extends Block{
|
||||
sortItem = content.item(read.s());
|
||||
|
||||
if(revision == 1){
|
||||
new DirectionalItemBuffer(20, 45f).read(read);
|
||||
new DirectionalItemBuffer(20).read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
smoothLiquid = Mathf.lerpDelta(smoothLiquid, liquids.currentAmount() / liquidCapacity, 0.05f);
|
||||
|
||||
if(liquids.total() > 0.001f && timer(timerFlow, 1)){
|
||||
moveLiquid(tile.getNearbyEntity(rotation()), leakResistance, liquids.current());
|
||||
moveLiquidForward(leakResistance, liquids.current());
|
||||
noSleep();
|
||||
}else{
|
||||
sleep();
|
||||
|
||||
@@ -44,7 +44,7 @@ public class LiquidBridge extends ItemBridge{
|
||||
|
||||
if(uptime >= 0.5f){
|
||||
|
||||
if(moveLiquid(other, false, liquids.current()) > 0.1f){
|
||||
if(moveLiquid(other, liquids.current()) > 0.1f){
|
||||
cycleSpeed = Mathf.lerpDelta(cycleSpeed, 4f, 0.05f);
|
||||
}else{
|
||||
cycleSpeed = Mathf.lerpDelta(cycleSpeed, 1f, 0.01f);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class LiquidExtendingBridge extends ExtendingItemBridge{
|
||||
}
|
||||
|
||||
if(uptime >= 0.5f){
|
||||
if(moveLiquid(other, false, liquids.current()) > 0.1f){
|
||||
if(moveLiquid(other, liquids.current()) > 0.1f){
|
||||
cycleSpeed = Mathf.lerpDelta(cycleSpeed, 4f, 0.05f);
|
||||
}else{
|
||||
cycleSpeed = Mathf.lerpDelta(cycleSpeed, 1f, 0.01f);
|
||||
|
||||
@@ -24,6 +24,8 @@ public class LiquidSource extends Block{
|
||||
liquidCapacity = 100f;
|
||||
configurable = true;
|
||||
outputsLiquid = true;
|
||||
saveConfig = true;
|
||||
|
||||
config(Liquid.class, (tile, l) -> ((LiquidSourceEntity)tile).source = l);
|
||||
configClear(tile -> ((LiquidSourceEntity)tile).source = null);
|
||||
}
|
||||
|
||||
@@ -23,36 +23,6 @@ public abstract class StorageBlock extends Block{
|
||||
public class StorageBlockEntity extends TileEntity{
|
||||
protected @Nullable Tilec linkedCore;
|
||||
|
||||
/**
|
||||
* Removes an item and returns it. If item is not null, it should return the item.
|
||||
* Returns null if no items are there.
|
||||
*/
|
||||
@Nullable
|
||||
public Item removeItem(@Nullable Item item){
|
||||
if(item == null){
|
||||
return items.take();
|
||||
}else{
|
||||
if(items.has(item)){
|
||||
items.remove(item, 1);
|
||||
return item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this storage block has the specified item.
|
||||
* If the item is null, it should return whether it has ANY items.
|
||||
*/
|
||||
public boolean hasItem(@Nullable Item item){
|
||||
if(item == null){
|
||||
return items.total() > 0;
|
||||
}else{
|
||||
return items.has(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Tilec source, Item item){
|
||||
return linkedCore != null ? linkedCore.acceptItem(source, item) : items.get(item) < getMaximumAccepted(item);
|
||||
|
||||
@@ -137,6 +137,10 @@ public class ItemModule extends BlockModule{
|
||||
return total;
|
||||
}
|
||||
|
||||
public boolean any(){
|
||||
return total > 0;
|
||||
}
|
||||
|
||||
public Item first(){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
|
||||
Reference in New Issue
Block a user