mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-27 06:51:30 -08:00
Fixed puddles not appearing / Overdrive tweaks
- Bridges, routers and junctions can (probably) be overdrived now, untested
This commit is contained in:
parent
bcec6261d1
commit
aab97fefc8
18 changed files with 58 additions and 90 deletions
|
|
@ -63,7 +63,7 @@ public class Puddles{
|
|||
p.lastRipple(Time.time());
|
||||
}
|
||||
}else{
|
||||
p.amount(p.amount() + reactPuddle(p.liquid(), liquid, amount, p.tile(), p.x(), p.y()));
|
||||
p.amount(p.amount() + reactPuddle(p.liquid(), liquid, amount, p.tile(), (p.x() + source.worldx())/2f, (p.y() + source.worldy())/2f));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import static mindustry.entities.Puddles.maxLiquid;
|
|||
|
||||
@EntityDef(value = {Puddlec.class}, pooled = true)
|
||||
@Component
|
||||
abstract class PuddleComp implements Posc, Puddlec{
|
||||
abstract class PuddleComp implements Posc, Puddlec, Drawc{
|
||||
private static final int maxGeneration = 2;
|
||||
private static final Color tmp = new Color();
|
||||
private static final Rect rect = new Rect();
|
||||
|
|
|
|||
|
|
@ -383,11 +383,11 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
}
|
||||
|
||||
public boolean acceptLiquid(Tilec source, Liquid liquid, float amount){
|
||||
return block.hasLiquids && liquids().get(liquid) + amount < block.liquidCapacity && block.consumes.liquidfilters.get(liquid.id);
|
||||
return block.hasLiquids && liquids.get(liquid) + amount < block.liquidCapacity && block.consumes.liquidfilters.get(liquid.id);
|
||||
}
|
||||
|
||||
public void handleLiquid(Tilec source, Liquid liquid, float amount){
|
||||
liquids().add(liquid, amount);
|
||||
liquids.add(liquid, amount);
|
||||
}
|
||||
|
||||
public void dumpLiquid(Liquid liquid){
|
||||
|
|
@ -400,7 +400,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
|
||||
if(other != null && other.team() == team() && other.block().hasLiquids && canDumpLiquid(other, liquid) && other.liquids() != null){
|
||||
float ofract = other.liquids().get(liquid) / other.block().liquidCapacity;
|
||||
float fract = liquids().get(liquid) / block.liquidCapacity;
|
||||
float fract = liquids.get(liquid) / block.liquidCapacity;
|
||||
|
||||
if(ofract < fract) transferLiquid(other, (fract - ofract) * block.liquidCapacity / 2f, liquid);
|
||||
}
|
||||
|
|
@ -417,30 +417,41 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
|
||||
if(next.acceptLiquid(this, liquid, flow)){
|
||||
next.handleLiquid(this, liquid, flow);
|
||||
liquids().remove(liquid, flow);
|
||||
liquids.remove(liquid, flow);
|
||||
}
|
||||
}
|
||||
|
||||
public float moveLiquid(Tilec next, boolean leak, Liquid liquid){
|
||||
return moveLiquid(next, leak ? 1.5f : 100, liquid);
|
||||
public float moveLiquidForward(float leakResistance, Liquid liquid){
|
||||
Tile next = tile.getNearby(rotation());
|
||||
|
||||
if(next == null) return 0;
|
||||
|
||||
if(next.entity != null){
|
||||
return moveLiquid(next.entity, liquid);
|
||||
}else if(leakResistance != 100f && !next.block().solid && !next.block().hasLiquids){
|
||||
float leakAmount = liquids.get(liquid) / leakResistance;
|
||||
Puddles.deposit(next, tile(), liquid, leakAmount);
|
||||
liquids.remove(liquid, leakAmount);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float moveLiquid(Tilec next, float leakResistance, Liquid liquid){
|
||||
public float moveLiquid(Tilec next, Liquid liquid){
|
||||
if(next == null) return 0;
|
||||
|
||||
next = next.getLiquidDestination(this, liquid);
|
||||
|
||||
if(next.team() == team() && next.block().hasLiquids && liquids().get(liquid) > 0f){
|
||||
if(next.team() == team() && next.block().hasLiquids && liquids.get(liquid) > 0f){
|
||||
|
||||
if(next.acceptLiquid(this, liquid, 0f)){
|
||||
float ofract = next.liquids().get(liquid) / next.block().liquidCapacity;
|
||||
float fract = liquids().get(liquid) / block.liquidCapacity * block.liquidPressure;
|
||||
float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (block.liquidCapacity), liquids().get(liquid));
|
||||
float fract = liquids.get(liquid) / block.liquidCapacity * block.liquidPressure;
|
||||
float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (block.liquidCapacity), liquids.get(liquid));
|
||||
flow = Math.min(flow, next.block().liquidCapacity - next.liquids().get(liquid) - 0.001f);
|
||||
|
||||
if(flow > 0f && ofract <= fract && next.acceptLiquid(this, liquid, flow)){
|
||||
next.handleLiquid(this, liquid, flow);
|
||||
liquids().remove(liquid, flow);
|
||||
liquids.remove(liquid, flow);
|
||||
return flow;
|
||||
}else if(ofract > 0.1f && fract > 0.1f){
|
||||
//TODO these are incorrect effect positions
|
||||
|
|
@ -454,17 +465,13 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
Fx.fire.at(fx, fy);
|
||||
}
|
||||
}else if((liquid.temperature > 0.7f && other.temperature < 0.55f) || (other.temperature > 0.7f && liquid.temperature < 0.55f)){
|
||||
liquids().remove(liquid, Math.min(liquids().get(liquid), 0.7f * Time.delta()));
|
||||
liquids.remove(liquid, Math.min(liquids.get(liquid), 0.7f * Time.delta()));
|
||||
if(Mathf.chance(0.2f * Time.delta())){
|
||||
Fx.steam.at(fx, fy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(leakResistance != 100f && !next.block().solid && !next.block().hasLiquids){
|
||||
float leakAmount = liquids().get(liquid) / leakResistance;
|
||||
Puddles.deposit(next.tile(), tile(), liquid, leakAmount);
|
||||
liquids().remove(liquid, leakAmount);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -651,6 +658,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
float brcx = tile.drawx() + (block.size * tilesize / 2f) - (tilesize / 2f);
|
||||
float brcy = tile.drawy() - (block.size * tilesize / 2f) + (tilesize / 2f);
|
||||
|
||||
Draw.z(Layer.blockOver);
|
||||
Draw.color(Pal.gray);
|
||||
Fill.square(brcx, brcy, 2.5f, 45);
|
||||
Draw.color(cons.status().color);
|
||||
|
|
@ -677,8 +685,8 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
}
|
||||
|
||||
public void drawLight(){
|
||||
if(block.hasLiquids && block.drawLiquidLight && liquids().current().lightColor.a > 0.001f){
|
||||
drawLiquidLight(liquids().current(), liquids().smoothAmount());
|
||||
if(block.hasLiquids && block.drawLiquidLight && liquids.current().lightColor.a > 0.001f){
|
||||
drawLiquidLight(liquids.current(), liquids.smoothAmount());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -781,8 +789,8 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
}
|
||||
|
||||
if(block.hasLiquids){
|
||||
flammability += liquids().sum((liquid, amount) -> liquid.explosiveness * amount / 2f);
|
||||
explosiveness += liquids().sum((liquid, amount) -> liquid.flammability * amount / 2f);
|
||||
flammability += liquids.sum((liquid, amount) -> liquid.explosiveness * amount / 2f);
|
||||
explosiveness += liquids.sum((liquid, amount) -> liquid.flammability * amount / 2f);
|
||||
}
|
||||
|
||||
if(block.consumes.hasPower() && block.consumes.getPower().buffered){
|
||||
|
|
@ -791,7 +799,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
|
||||
if(block.hasLiquids){
|
||||
|
||||
liquids().each((liquid, amount) -> {
|
||||
liquids.each((liquid, amount) -> {
|
||||
float splash = Mathf.clamp(amount / 4f, 0f, 10f);
|
||||
|
||||
for(int i = 0; i < Mathf.clamp(amount / 5, 0, 30); i++){
|
||||
|
|
@ -825,7 +833,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
|
|||
float result = items.sum((item, amount) -> item.flammability * amount);
|
||||
|
||||
if(block.hasLiquids){
|
||||
result += liquids().sum((liquid, amount) -> liquid.flammability * amount / 3f);
|
||||
result += liquids.sum((liquid, amount) -> liquid.flammability * amount / 3f);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=84bbb36f336c108fdb85ae1bcb8eeeac42447460
|
||||
archash=96baae84beb618f21b6b01b1da3ce11991df5730
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue