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

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 199 B

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

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

+2 -2
View File
@@ -1,7 +1,7 @@
#Autogenerated file. Do not modify. #Autogenerated file. Do not modify.
#Sun Mar 11 10:06:17 EDT 2018 #Mon Mar 12 16:07:14 EDT 2018
version=release version=release
androidBuildCode=441 androidBuildCode=461
name=Mindustry name=Mindustry
code=3.4 code=3.4
build=custom build build=custom build
@@ -91,6 +91,7 @@ public class Recipes {
new Recipe(liquid, DistributionBlocks.conduit, stack(Item.steel, 1)), 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.pulseconduit, stack(Item.titanium, 1), stack(Item.steel, 1)),
new Recipe(liquid, DistributionBlocks.liquidrouter, stack(Item.steel, 2)), 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.liquidjunction, stack(Item.steel, 2)),
new Recipe(liquid, DistributionBlocks.conduittunnel, stack(Item.titanium, 2), stack(Item.steel, 2)), new Recipe(liquid, DistributionBlocks.conduittunnel, stack(Item.titanium, 2), stack(Item.steel, 2)),
@@ -117,7 +117,7 @@ public class BlocksFragment implements Fragment{
for (Recipe r : recipes) { for (Recipe r : recipes) {
ImageButton image = new ImageButton(new TextureRegion(), "select"); ImageButton image = new ImageButton(new TextureRegion(), "select");
TextureRegion[] regions = r.result.getIcon(true); TextureRegion[] regions = r.result.getCompactIcon();
Stack istack = new Stack(); Stack istack = new Stack();
for(TextureRegion region : regions){ for(TextureRegion region : regions){
istack.add(new Image(region)); istack.add(new Image(region));
@@ -259,7 +259,7 @@ public class BlocksFragment implements Fragment{
desctable.row(); desctable.row();
TextureRegion[] regions = recipe.result.getIcon(true); TextureRegion[] regions = recipe.result.getCompactIcon();
Stack istack = new Stack(); Stack istack = new Stack();
+13 -5
View File
@@ -177,16 +177,24 @@ public class Block extends BaseBlock {
Effects.sound(explosionSound, x, y); Effects.sound(explosionSound, x, y);
} }
public TextureRegion[] getIcon(boolean compact){ public TextureRegion[] getIcon(){
if(Draw.hasRegion(name + "-icon")){ if(Draw.hasRegion(name + "-icon")){
return new TextureRegion[]{Draw.region(name + "-icon")}; return new TextureRegion[]{Draw.region(name + "-icon")};
}else{ }else{
return new TextureRegion[]{compact ? iconRegion(name) : Draw.region(name)}; return new TextureRegion[]{Draw.region(name)};
} }
} }
protected TextureRegion iconRegion(String name){ public TextureRegion[] getCompactIcon(){
TextureRegion region = new TextureRegion(Draw.region(name)); 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.setRegionWidth(8);
region.setRegionHeight(8); region.setRegionHeight(8);
return region; return region;
@@ -252,7 +260,7 @@ public class Block extends BaseBlock {
"entity.x", tile.entity.x, "entity.x", tile.entity.x,
"entity.y", tile.entity.y, "entity.y", tile.entity.y,
"entity.id", tile.entity.id, "entity.id", tile.entity.id,
"entity.items.total", tile.entity.inventory.totalItems() "entity.items.total", hasInventory ? tile.entity.inventory.totalItems() : null
); );
} }
+1 -1
View File
@@ -14,7 +14,7 @@ public class Edges {
static{ static{
for(int i = 0; i < maxSize; i ++){ 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; int top = (int)(i/2f+0.5f) + 1;
edges[i] = new GridPoint2[(i + 1) * 4]; edges[i] = new GridPoint2[(i + 1) * 4];
@@ -6,7 +6,6 @@ import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Edges; import io.anuke.mindustry.world.Edges;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf;
public abstract class BaseBlock { public abstract class BaseBlock {
public boolean hasInventory = true; public boolean hasInventory = true;
@@ -28,7 +27,7 @@ public abstract class BaseBlock {
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return tile.entity.liquid.amount + amount < liquidCapacity 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){ public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
@@ -49,9 +48,35 @@ public abstract class BaseBlock {
} }
public void tryDumpLiquid(Tile tile){ public void tryDumpLiquid(Tile tile){
if(tile.entity.liquid.amount > 0.01f){ int size = tile.block().size;
tryMoveLiquid(tile, tile.getNearby(tile.getDump()));
tile.setDump((byte) Mathf.mod(tile.getDump() + 1, 4)); 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(); 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)); 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; if(flow <= 0f || tile.entity.liquid.amount < flow) return;
@@ -22,7 +22,14 @@ public class DistributionBlocks{
}}, }},
liquidrouter = new LiquidRouter("liquidrouter"){{ liquidrouter = new LiquidRouter("liquidrouter"){{
liquidCapacity = 30f;
liquidRegion = "liquidrouter-liquid";
}},
liquidsilo = new LiquidRouter("liquidsilo"){{
size = 3;
liquidRegion = "liquidsilo-liquid";
liquidCapacity = 1300f;
}}, }},
conveyor = new Conveyor("conveyor"){{ conveyor = new Conveyor("conveyor"){{
@@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types; 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.Block;
import io.anuke.mindustry.world.BlockGroup; import io.anuke.mindustry.world.BlockGroup;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
@@ -8,29 +9,38 @@ import io.anuke.ucore.graphics.Draw;
public class LiquidBlock extends Block{ public class LiquidBlock extends Block{
protected final int timerFlow = timers++; protected final int timerFlow = timers++;
protected String liquidRegion = "conduitliquid";
public LiquidBlock(String name) { public LiquidBlock(String name) {
super(name); super(name);
rotate = true; rotate = true;
update = true; update = true;
hasLiquids = true; hasLiquids = true;
hasInventory = false;
group = BlockGroup.liquids; group = BlockGroup.liquids;
} }
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name() + "-bottom"), Draw.region(name() + "-top")};
}
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
LiquidModule mod = tile.entity.liquid; 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){ if(mod.amount > 0.01f){
Draw.color(mod.liquid.color); Draw.color(mod.liquid.color);
Draw.alpha(mod.amount / liquidCapacity); 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.color();
} }
Draw.rect(name() + "top", tile.worldx(), tile.worldy(), tile.getRotation() * 90); Draw.rect(name() + "-top", tile.worldx(), tile.worldy(), rotation);
} }
@Override @Override
@@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types.distribution; 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.resource.Liquid;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.LiquidBlock; import io.anuke.mindustry.world.blocks.types.LiquidBlock;
@@ -19,7 +20,12 @@ public class LiquidJunction extends LiquidBlock{
public void draw(Tile tile){ public void draw(Tile tile){
Draw.rect(name(), tile.worldx(), tile.worldy()); Draw.rect(name(), tile.worldx(), tile.worldy());
} }
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name)};
}
@Override @Override
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){ public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
int dir = source.relativeTo(tile.x, tile.y); int dir = source.relativeTo(tile.x, tile.y);
@@ -1,9 +1,7 @@
package io.anuke.mindustry.world.blocks.types.distribution; 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.Tile;
import io.anuke.mindustry.world.blocks.types.LiquidBlock; import io.anuke.mindustry.world.blocks.types.LiquidBlock;
import io.anuke.ucore.graphics.Draw;
public class LiquidRouter extends LiquidBlock{ public class LiquidRouter extends LiquidBlock{
@@ -19,28 +17,8 @@ public class LiquidRouter extends LiquidBlock{
public void update(Tile tile){ public void update(Tile tile){
if(tile.entity.liquid.amount > 0){ if(tile.entity.liquid.amount > 0){
if(tile.getExtra() != tile.getRotation()){ tryDumpLiquid(tile);
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()));
}
tile.setRotation((byte)((tile.getRotation() + 1) % 4));
} }
} }
@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();
}
} }
@@ -21,10 +21,9 @@ public class PowerLaser extends Generator{
} }
@Override @Override
public TextureRegion[] getIcon(boolean compact){ public TextureRegion[] getIcon(){
String bname = base == null ? "laser-base" : base; String bname = base == null ? "laser-base" : base;
return new TextureRegion[]{compact ? iconRegion(bname) : Draw.region(bname), return new TextureRegion[]{Draw.region(bname), Draw.region(name)};
compact ? iconRegion(name) : Draw.region(name)};
} }
@Override @Override
@@ -11,6 +11,8 @@ public class Splitter extends Block{
super(name); super(name);
solid = true; solid = true;
instantTransfer = true; instantTransfer = true;
destructible = true;
hasInventory = false;
} }
@Override @Override
@@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types.distribution; 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.resource.Liquid;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.LiquidBlock; import io.anuke.mindustry.world.blocks.types.LiquidBlock;
@@ -17,6 +18,11 @@ public class TunnelConduit extends LiquidBlock {
instantTransfer = true; instantTransfer = true;
} }
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name)};
}
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
Draw.rect(name, tile.drawx(), tile.drawy(), tile.getRotation() * 90); Draw.rect(name, tile.drawx(), tile.drawy(), tile.getRotation() * 90);
@@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types.production; 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.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.Item;
@@ -23,7 +24,6 @@ public class LiquidCrafter extends LiquidBlock{
public Liquid inputLiquid = null; public Liquid inputLiquid = null;
public float liquidAmount = 20f; public float liquidAmount = 20f;
public Item output = null; public Item output = null;
public int itemCapacity = 90;
public int purifyTime = 80; public int purifyTime = 80;
public Effect craftEffect = Fx.purify; public Effect craftEffect = Fx.purify;
@@ -33,6 +33,8 @@ public class LiquidCrafter extends LiquidBlock{
rotate = false; rotate = false;
solid = true; solid = true;
health = 60; health = 60;
hasInventory = true;
itemCapacity = 90;
liquidCapacity = 21f; liquidCapacity = 21f;
} }
@@ -66,6 +68,11 @@ public class LiquidCrafter extends LiquidBlock{
Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2); Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2);
Draw.color(); Draw.color();
} }
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name)};
}
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
@@ -1,5 +1,6 @@
package io.anuke.mindustry.world.blocks.types.production; 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.resource.Liquid;
import io.anuke.mindustry.world.BlockGroup; import io.anuke.mindustry.world.BlockGroup;
import io.anuke.mindustry.world.Layer; import io.anuke.mindustry.world.Layer;
@@ -11,9 +12,6 @@ import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Strings;
public class Pump extends LiquidBlock{ public class Pump extends LiquidBlock{
protected final int timerPump = timers++;
protected final int timerDump = timers++;
protected float pumpAmount = 2f; protected float pumpAmount = 2f;
public Pump(String name) { public Pump(String name) {
@@ -46,6 +44,11 @@ public class Pump extends LiquidBlock{
Draw.color(); Draw.color();
} }
@Override
public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name)};
}
@Override @Override
public boolean isLayer(Tile tile) { public boolean isLayer(Tile tile) {
return tile.floor().liquidDrop == null; return tile.floor().liquidDrop == null;
@@ -66,10 +69,8 @@ public class Pump extends LiquidBlock{
tile.entity.liquid.liquid = tile.floor().liquidDrop; tile.entity.liquid.liquid = tile.floor().liquidDrop;
tile.entity.liquid.amount += maxPump; tile.entity.liquid.amount += maxPump;
} }
if(tile.entity.timer.get(timerDump, 1)){ tryDumpLiquid(tile);
tryDumpLiquid(tile);
}
} }
} }