Added liquid silos, general liquid cleanup

This commit is contained in:
Anuken
2018-03-12 16:09:14 -04:00
parent 9674ca5e87
commit e67ddf9430
32 changed files with 487 additions and 405 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 313 B

View File

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 199 B

View File

Before

Width:  |  Height:  |  Size: 191 B

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 B

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

View File

Before

Width:  |  Height:  |  Size: 219 B

After

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

@ -1,7 +1,7 @@
#Autogenerated file. Do not modify.
#Sun Mar 11 10:06:17 EDT 2018
#Mon Mar 12 16:07:14 EDT 2018
version=release
androidBuildCode=441
androidBuildCode=461
name=Mindustry
code=3.4
build=custom build

View File

@ -91,6 +91,7 @@ public class Recipes {
new Recipe(liquid, DistributionBlocks.conduit, stack(Item.steel, 1)),
new Recipe(liquid, DistributionBlocks.pulseconduit, stack(Item.titanium, 1), stack(Item.steel, 1)),
new Recipe(liquid, DistributionBlocks.liquidrouter, stack(Item.steel, 2)),
new Recipe(liquid, DistributionBlocks.liquidsilo, stack(Item.steel, 2)),
new Recipe(liquid, DistributionBlocks.liquidjunction, stack(Item.steel, 2)),
new Recipe(liquid, DistributionBlocks.conduittunnel, stack(Item.titanium, 2), stack(Item.steel, 2)),

View File

@ -117,7 +117,7 @@ public class BlocksFragment implements Fragment{
for (Recipe r : recipes) {
ImageButton image = new ImageButton(new TextureRegion(), "select");
TextureRegion[] regions = r.result.getIcon(true);
TextureRegion[] regions = r.result.getCompactIcon();
Stack istack = new Stack();
for(TextureRegion region : regions){
istack.add(new Image(region));
@ -259,7 +259,7 @@ public class BlocksFragment implements Fragment{
desctable.row();
TextureRegion[] regions = recipe.result.getIcon(true);
TextureRegion[] regions = recipe.result.getCompactIcon();
Stack istack = new Stack();

View File

@ -177,16 +177,24 @@ public class Block extends BaseBlock {
Effects.sound(explosionSound, x, y);
}
public TextureRegion[] getIcon(boolean compact){
public TextureRegion[] getIcon(){
if(Draw.hasRegion(name + "-icon")){
return new TextureRegion[]{Draw.region(name + "-icon")};
}else{
return new TextureRegion[]{compact ? iconRegion(name) : Draw.region(name)};
return new TextureRegion[]{Draw.region(name)};
}
}
protected TextureRegion iconRegion(String name){
TextureRegion region = new TextureRegion(Draw.region(name));
public TextureRegion[] getCompactIcon(){
TextureRegion[] out = getIcon();
for(int i = 0; i < out.length; i ++){
out[i] = iconRegion(out[i]);
}
return out;
}
protected TextureRegion iconRegion(TextureRegion src){
TextureRegion region = new TextureRegion(src);
region.setRegionWidth(8);
region.setRegionHeight(8);
return region;
@ -252,7 +260,7 @@ public class Block extends BaseBlock {
"entity.x", tile.entity.x,
"entity.y", tile.entity.y,
"entity.id", tile.entity.id,
"entity.items.total", tile.entity.inventory.totalItems()
"entity.items.total", hasInventory ? tile.entity.inventory.totalItems() : null
);
}

View File

@ -14,7 +14,7 @@ public class Edges {
static{
for(int i = 0; i < maxSize; i ++){
int bot = -(int)(i/2f-0.5f) - 1;
int bot = -(int)(i/2f) - 1;
int top = (int)(i/2f+0.5f) + 1;
edges[i] = new GridPoint2[(i + 1) * 4];

View File

@ -6,7 +6,6 @@ import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Edges;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf;
public abstract class BaseBlock {
public boolean hasInventory = true;
@ -28,7 +27,7 @@ public abstract class BaseBlock {
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return tile.entity.liquid.amount + amount < liquidCapacity
&& (tile.entity.liquid.liquid == liquid || tile.entity.liquid.amount <= 0.01f);
&& (tile.entity.liquid.liquid == liquid || tile.entity.liquid.amount <= 0.001f);
}
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
@ -49,9 +48,35 @@ public abstract class BaseBlock {
}
public void tryDumpLiquid(Tile tile){
if(tile.entity.liquid.amount > 0.01f){
tryMoveLiquid(tile, tile.getNearby(tile.getDump()));
tile.setDump((byte) Mathf.mod(tile.getDump() + 1, 4));
int size = tile.block().size;
GridPoint2[] nearby = Edges.getEdges(size);
byte i = tile.getDump();
for (int j = 0; j < nearby.length; j ++) {
Tile other = tile.getNearby(nearby[i]);
Tile in = tile.getNearby(Edges.getInsideEdges(size)[i]);
if(other != null) other = other.target();
if (other != null && other.block().hasLiquids) {
float ofract = other.entity.liquid.amount / other.block().liquidCapacity;
float fract = tile.entity.liquid.amount / liquidCapacity;
if(ofract < fract) tryMoveLiquid(tile, in, other, (fract - ofract) * liquidCapacity / 2f);
}
i = (byte) ((i + 1) % nearby.length);
}
}
public void tryMoveLiquid(Tile tile, Tile tileSource, Tile next, float amount){
float flow = Math.min(next.block().liquidCapacity - next.entity.liquid.amount, amount);
if(next.block().acceptLiquid(next, tileSource, tile.entity.liquid.liquid, flow)){
next.block().handleLiquid(next, tileSource, tile.entity.liquid.liquid, flow);
tile.entity.liquid.amount -= flow;
}
}
@ -60,9 +85,13 @@ public abstract class BaseBlock {
next = next.target();
if(next.block().hasLiquids && tile.entity.liquid.amount > 0.01f){
if(next.block().hasLiquids && tile.entity.liquid.amount > 0f){
float ofract = next.entity.liquid.amount / next.block().liquidCapacity;
float fract = tile.entity.liquid.amount / liquidCapacity;
float flow = Math.min(next.block().liquidCapacity - next.entity.liquid.amount - 0.001f,
if(ofract > fract) return;
float flow = Math.min((fract - ofract) * liquidCapacity/2f,
Math.min(tile.entity.liquid.amount/liquidFlowFactor * Math.max(Timers.delta(), 1f), tile.entity.liquid.amount));
if(flow <= 0f || tile.entity.liquid.amount < flow) return;

View File

@ -22,7 +22,14 @@ public class DistributionBlocks{
}},
liquidrouter = new LiquidRouter("liquidrouter"){{
liquidCapacity = 30f;
liquidRegion = "liquidrouter-liquid";
}},
liquidsilo = new LiquidRouter("liquidsilo"){{
size = 3;
liquidRegion = "liquidsilo-liquid";
liquidCapacity = 1300f;
}},
conveyor = new Conveyor("conveyor"){{

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.BlockGroup;
import io.anuke.mindustry.world.Tile;
@ -8,29 +9,38 @@ import io.anuke.ucore.graphics.Draw;
public class LiquidBlock extends Block{
protected final int timerFlow = timers++;
protected String liquidRegion = "conduitliquid";
public LiquidBlock(String name) {
super(name);
rotate = true;
update = true;
hasLiquids = true;
hasInventory = false;
group = BlockGroup.liquids;
}
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name() + "-bottom"), Draw.region(name() + "-top")};
}
@Override
public void draw(Tile tile){
LiquidModule mod = tile.entity.liquid;
int rotation = rotate ? tile.getRotation() * 90 : 0;
Draw.rect(name() + "bottom", tile.worldx(), tile.worldy(), tile.getRotation() * 90);
Draw.rect(name() + "-bottom", tile.worldx(), tile.worldy(), rotation);
if(mod.amount > 0.01f){
Draw.color(mod.liquid.color);
Draw.alpha(mod.amount / liquidCapacity);
Draw.rect("conduitliquid", tile.worldx(), tile.worldy(), tile.getRotation() * 90);
Draw.rect(liquidRegion, tile.worldx(), tile.worldy(), rotation);
Draw.color();
}
Draw.rect(name() + "top", tile.worldx(), tile.worldy(), tile.getRotation() * 90);
Draw.rect(name() + "-top", tile.worldx(), tile.worldy(), rotation);
}
@Override

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types.distribution;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
@ -19,7 +20,12 @@ public class LiquidJunction extends LiquidBlock{
public void draw(Tile tile){
Draw.rect(name(), tile.worldx(), tile.worldy());
}
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name)};
}
@Override
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
int dir = source.relativeTo(tile.x, tile.y);

View File

@ -1,9 +1,7 @@
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.LiquidBlock;
import io.anuke.ucore.graphics.Draw;
public class LiquidRouter extends LiquidBlock{
@ -19,28 +17,8 @@ public class LiquidRouter extends LiquidBlock{
public void update(Tile tile){
if(tile.entity.liquid.amount > 0){
if(tile.getExtra() != tile.getRotation()){
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()));
}
tile.setRotation((byte)((tile.getRotation() + 1) % 4));
tryDumpLiquid(tile);
}
}
@Override
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
super.handleLiquid(tile, source, liquid, amount);
tile.setExtra(tile.relativeTo(source.x, source.y));
}
@Override
public void draw(Tile tile){
Draw.rect(name(), tile.worldx(), tile.worldy());
Draw.color(tile.entity.liquid.liquid.color);
Draw.alpha(tile.entity.liquid.amount / liquidCapacity);
Draw.rect("blank", tile.worldx(), tile.worldy(), 2, 2);
Draw.color();
}
}

View File

@ -21,10 +21,9 @@ public class PowerLaser extends Generator{
}
@Override
public TextureRegion[] getIcon(boolean compact){
public TextureRegion[] getIcon(){
String bname = base == null ? "laser-base" : base;
return new TextureRegion[]{compact ? iconRegion(bname) : Draw.region(bname),
compact ? iconRegion(name) : Draw.region(name)};
return new TextureRegion[]{Draw.region(bname), Draw.region(name)};
}
@Override

View File

@ -11,6 +11,8 @@ public class Splitter extends Block{
super(name);
solid = true;
instantTransfer = true;
destructible = true;
hasInventory = false;
}
@Override

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types.distribution;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
@ -17,6 +18,11 @@ public class TunnelConduit extends LiquidBlock {
instantTransfer = true;
}
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name)};
}
@Override
public void draw(Tile tile){
Draw.rect(name, tile.drawx(), tile.drawy(), tile.getRotation() * 90);

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.resource.Item;
@ -23,7 +24,6 @@ public class LiquidCrafter extends LiquidBlock{
public Liquid inputLiquid = null;
public float liquidAmount = 20f;
public Item output = null;
public int itemCapacity = 90;
public int purifyTime = 80;
public Effect craftEffect = Fx.purify;
@ -33,6 +33,8 @@ public class LiquidCrafter extends LiquidBlock{
rotate = false;
solid = true;
health = 60;
hasInventory = true;
itemCapacity = 90;
liquidCapacity = 21f;
}
@ -66,6 +68,11 @@ public class LiquidCrafter extends LiquidBlock{
Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2);
Draw.color();
}
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name)};
}
@Override
public void update(Tile tile){

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.BlockGroup;
import io.anuke.mindustry.world.Layer;
@ -11,9 +12,6 @@ import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
public class Pump extends LiquidBlock{
protected final int timerPump = timers++;
protected final int timerDump = timers++;
protected float pumpAmount = 2f;
public Pump(String name) {
@ -46,6 +44,11 @@ public class Pump extends LiquidBlock{
Draw.color();
}
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name)};
}
@Override
public boolean isLayer(Tile tile) {
return tile.floor().liquidDrop == null;
@ -66,10 +69,8 @@ public class Pump extends LiquidBlock{
tile.entity.liquid.liquid = tile.floor().liquidDrop;
tile.entity.liquid.amount += maxPump;
}
if(tile.entity.timer.get(timerDump, 1)){
tryDumpLiquid(tile);
}
tryDumpLiquid(tile);
}
}