Drill cleanup / Added liquid boosting / Liquid hierarchy cleanup
This commit is contained in:
@@ -4,7 +4,10 @@ import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.content.Liquids;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.production.*;
|
||||
import io.anuke.mindustry.world.blocks.types.production.Cultivator;
|
||||
import io.anuke.mindustry.world.blocks.types.production.Drill;
|
||||
import io.anuke.mindustry.world.blocks.types.production.Fracker;
|
||||
import io.anuke.mindustry.world.blocks.types.production.SolidPump;
|
||||
|
||||
public class ProductionBlocks {
|
||||
public static final Block
|
||||
@@ -29,27 +32,37 @@ public class ProductionBlocks {
|
||||
drillTime = 280;
|
||||
}},
|
||||
|
||||
laserdrill = new GenericDrill("laserdrill") {{
|
||||
laserdrill = new Drill("laserdrill") {{
|
||||
drillTime = 220;
|
||||
size = 2;
|
||||
powerUse = 0.2f;
|
||||
hasPower = true;
|
||||
tier = 5;
|
||||
updateEffect = Fx.pulverizeMedium;
|
||||
drillEffect = Fx.mineBig;
|
||||
}},
|
||||
|
||||
nucleardrill = new GenericDrill("nucleardrill") {{
|
||||
nucleardrill = new Drill("nucleardrill") {{
|
||||
drillTime = 170;
|
||||
size = 3;
|
||||
powerUse = 0.32f;
|
||||
hasPower = true;
|
||||
tier = 5;
|
||||
updateEffect = Fx.pulverizeMedium;
|
||||
drillEffect = Fx.mineBig;
|
||||
}},
|
||||
|
||||
plasmadrill = new GenericDrill("plasmadrill") {{
|
||||
plasmadrill = new Drill("plasmadrill") {{
|
||||
inputLiquid = Liquids.plasma;
|
||||
liquidRequired = true;
|
||||
drillTime = 110;
|
||||
size = 4;
|
||||
powerUse = 0.16f;
|
||||
hasLiquids = true;
|
||||
hasPower = true;
|
||||
tier = 5;
|
||||
updateEffect = Fx.pulverizeMedium;
|
||||
drillEffect = Fx.mineBig;
|
||||
}},
|
||||
|
||||
waterextractor = new SolidPump("waterextractor") {{
|
||||
|
||||
@@ -376,6 +376,14 @@ public class Fx{
|
||||
});
|
||||
}),
|
||||
|
||||
mineBig = new Effect(30, e -> {
|
||||
Angles.randLenVectors(e.id, 6, 4f + e.ifract()*8f, (x, y)->{
|
||||
Draw.color(e.color, Color.LIGHT_GRAY, e.ifract());
|
||||
Fill.poly(e.x + x, e.y + y, 4, e.fract() * 2f + 0.2f, 45);
|
||||
Draw.reset();
|
||||
});
|
||||
}),
|
||||
|
||||
sparkbig = new Effect(11, e -> {
|
||||
Lines.stroke(1f);
|
||||
Draw.color(lightRed, Color.GRAY, e.ifract());
|
||||
|
||||
@@ -12,8 +12,8 @@ public class LiquidBlock extends Block{
|
||||
|
||||
public LiquidBlock(String name) {
|
||||
super(name);
|
||||
rotate = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
hasLiquids = true;
|
||||
hasInventory = false;
|
||||
group = BlockGroup.liquids;
|
||||
|
||||
@@ -12,6 +12,8 @@ public class Conduit extends LiquidBlock {
|
||||
public Conduit(String name) {
|
||||
super(name);
|
||||
liquidRegion = "conduit-liquid";
|
||||
rotate = true;
|
||||
solid = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Conveyor extends Block{
|
||||
private static ItemPos drawpos = new ItemPos();
|
||||
private static ItemPos pos1 = new ItemPos();
|
||||
private static ItemPos pos2 = new ItemPos();
|
||||
private static final float itemSpace = 0.135f * 2f;
|
||||
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);
|
||||
|
||||
@@ -11,9 +11,6 @@ public class LiquidJunction extends LiquidBlock{
|
||||
|
||||
public LiquidJunction(String name) {
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
rotate = false;
|
||||
hasLiquids = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,6 @@ public class LiquidRouter extends LiquidBlock{
|
||||
|
||||
public LiquidRouter(String name) {
|
||||
super(name);
|
||||
rotate = false;
|
||||
solid = true;
|
||||
liquidFlowFactor = 2f;
|
||||
hasInventory = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ 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.BarType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@@ -18,6 +19,12 @@ public class TunnelConduit extends LiquidBlock {
|
||||
instantTransfer = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars() {
|
||||
super.setBars();
|
||||
bars.remove(BarType.liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] getIcon(){
|
||||
return new TextureRegion[]{Draw.region(name)};
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Cultivator extends GenericDrill {
|
||||
public class Cultivator extends Drill {
|
||||
protected Color plantColor = Color.valueOf("648b55");
|
||||
protected Color plantColorLight = Color.valueOf("73a75f");
|
||||
protected Color bottomColor = Color.valueOf("474747");
|
||||
|
||||
@@ -2,10 +2,12 @@ package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.Liquids;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.graphics.Layer;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -17,20 +19,35 @@ import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
public class Drill extends Block{
|
||||
protected final static float hardnessDrillMultiplier = 40f;
|
||||
protected final int timerDrill = timers++;
|
||||
protected final static float hardnessDrillMultiplier = 50f;
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected final Array<Tile> drawTiles = new Array<>();
|
||||
|
||||
protected int tier;
|
||||
protected float drillTime = 300;
|
||||
protected Effect drillEffect = Fx.mine;
|
||||
protected float rotateSpeed = 2f;
|
||||
protected Effect updateEffect = Fx.pulverizeSmall;
|
||||
protected float updateEffectChance = 0.02f;
|
||||
protected final Array<Item> toAdd = new Array<>();
|
||||
|
||||
protected Array<Item> toAdd = new Array<>();
|
||||
/**Maximum tier of blocks this drill can mine.*/
|
||||
protected int tier;
|
||||
/**Base time to drill one ore, in frames.*/
|
||||
protected float drillTime = 300;
|
||||
/**power use per frame.*/
|
||||
public float powerUse = 0.08f;
|
||||
/**liquid use per frame.*/
|
||||
protected float liquidUse = 0.05f;
|
||||
/**Input liquid. Set hasLiquids to true so this is used.*/
|
||||
protected Liquid inputLiquid = Liquids.water;
|
||||
/**Whether the liquid is required to drill. If false, then it will be used as a speed booster.*/
|
||||
protected boolean liquidRequired = false;
|
||||
/**How many times faster the drill will progress when booster by liquid.*/
|
||||
protected float liquidBoostIntensity = 1.3f;
|
||||
|
||||
/**Effect played when an item is produced. This is colored.*/
|
||||
protected Effect drillEffect = Fx.mine;
|
||||
/**Speed the drill bit rotates at.*/
|
||||
protected float rotateSpeed = 2f;
|
||||
/**Effect randomly played while drilling.*/
|
||||
protected Effect updateEffect = Fx.pulverizeSmall;
|
||||
/**Chance the update effect will appear.*/
|
||||
protected float updateEffectChance = 0.02f;
|
||||
|
||||
public Drill(String name) {
|
||||
super(name);
|
||||
@@ -39,14 +56,16 @@ public class Drill extends Block{
|
||||
layer = Layer.overlay;
|
||||
itemCapacity = 5;
|
||||
group = BlockGroup.drills;
|
||||
hasLiquids = true;
|
||||
liquidCapacity = 5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile) {
|
||||
boolean valid = isMultiblock() || isValid(tile);
|
||||
DrillEntity entity = tile.entity();
|
||||
|
||||
Draw.rect(name, tile.drawx(), tile.drawy());
|
||||
Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), valid ? Timers.time() * rotateSpeed : 0f);
|
||||
Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.drillTime * rotateSpeed);
|
||||
Draw.rect(name + "-top", tile.drawx(), tile.drawy());
|
||||
|
||||
if(!isMultiblock() && isValid(tile)) {
|
||||
@@ -64,6 +83,7 @@ public class Drill extends Block{
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
//TODO this is misleading, change it
|
||||
stats.add("secondsitem", Strings.toFixed(drillTime/60, 1));
|
||||
}
|
||||
|
||||
@@ -71,7 +91,7 @@ public class Drill extends Block{
|
||||
public void update(Tile tile){
|
||||
toAdd.clear();
|
||||
|
||||
TileEntity entity = tile.entity;
|
||||
DrillEntity entity = tile.entity();
|
||||
|
||||
float multiplier = 0f;
|
||||
float totalHardness = 0f;
|
||||
@@ -84,23 +104,49 @@ public class Drill extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
if(toAdd.size > 0 && tile.entity.inventory.totalItems() < itemCapacity){
|
||||
if(entity.timer.get(timerDump, 15)){
|
||||
tryDump(tile);
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDrill, drillTime/multiplier + totalHardness*hardnessDrillMultiplier)) {
|
||||
int extra = tile.getExtra() % toAdd.size;
|
||||
entity.drillTime += entity.warmup * Timers.delta();
|
||||
|
||||
offloadNear(tile, toAdd.get(extra));
|
||||
float powerUsed = Math.min(powerCapacity, powerUse * Timers.delta());
|
||||
float liquidUsed = Math.min(liquidCapacity, liquidUse * Timers.delta());
|
||||
|
||||
tile.setExtra((byte)((extra + 1) % toAdd.size));
|
||||
Effects.effect(drillEffect, toAdd.get(extra).color, tile.drawx(), tile.drawy());
|
||||
if(entity.inventory.totalItems() < itemCapacity &&
|
||||
(!hasPower || entity.power.amount >= powerUsed) &&
|
||||
(!liquidRequired || entity.liquid.amount >= liquidUsed)){
|
||||
|
||||
if(hasPower) entity.power.amount -= powerUsed;
|
||||
if(liquidRequired) entity.liquid.amount -= liquidUsed;
|
||||
|
||||
float speed = 1f;
|
||||
|
||||
if(entity.liquid.amount >= liquidUsed && !liquidRequired){
|
||||
entity.liquid.amount -= liquidUsed;
|
||||
speed = liquidBoostIntensity;
|
||||
}
|
||||
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, speed, 0.02f);
|
||||
entity.progress += Timers.delta() * multiplier * speed;
|
||||
|
||||
if(Mathf.chance(Timers.delta() * updateEffectChance))
|
||||
Effects.effect(updateEffect, entity.x + Mathf.range(size*2f), entity.y + Mathf.range(size*2f));
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f);
|
||||
return;
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDump, 15)){
|
||||
tryDump(tile);
|
||||
if(toAdd.size > 0 && entity.progress >= drillTime + hardnessDrillMultiplier*totalHardness
|
||||
&& tile.entity.inventory.totalItems() < itemCapacity){
|
||||
|
||||
int index = entity.index % toAdd.size;
|
||||
offloadNear(tile, toAdd.get(index));
|
||||
|
||||
entity.index ++;
|
||||
entity.progress = 0f;
|
||||
|
||||
Effects.effect(drillEffect, toAdd.get(index).color, tile.drawx(), tile.drawy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +171,23 @@ public class Drill extends Block{
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
|
||||
return super.acceptLiquid(tile, source, liquid, amount) && liquid == inputLiquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new DrillEntity();
|
||||
}
|
||||
|
||||
public static class DrillEntity extends TileEntity{
|
||||
public float progress;
|
||||
public int index;
|
||||
public float warmup;
|
||||
public float drillTime;
|
||||
}
|
||||
|
||||
protected boolean isValid(Tile tile){
|
||||
return tile.floor().drops != null && tile.floor().drops.item.hardness <= tier;
|
||||
}
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.content.Liquids;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
/**Generic drill, can use both power and liquids. Set 'resource' to null to make it drill any block with drops.*/
|
||||
public class GenericDrill extends Drill{
|
||||
/**power use per frame.*/
|
||||
public float powerUse = 0.08f;
|
||||
/**liquid use per frame.*/
|
||||
protected float liquidUse = 0.1f;
|
||||
protected Liquid inputLiquid = Liquids.water;
|
||||
|
||||
protected float rotateSpeed = 1.5f;
|
||||
|
||||
public GenericDrill(String name){
|
||||
super(name);
|
||||
updateEffect = Fx.pulverizeMedium;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile) {
|
||||
DrillEntity entity = tile.entity();
|
||||
|
||||
Draw.rect(name, tile.drawx(), tile.drawy());
|
||||
Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.drillTime * rotateSpeed);
|
||||
Draw.rect(name + "-top", tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] getIcon() {
|
||||
return new TextureRegion[]{Draw.region(name), Draw.region(name + "-rotator"), Draw.region(name + "-top")};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
toAdd.clear();
|
||||
|
||||
DrillEntity entity = tile.entity();
|
||||
|
||||
float multiplier = 0f;
|
||||
float totalHardness = 0f;
|
||||
|
||||
for(Tile other : tile.getLinkedTiles(tempTiles)){
|
||||
if(isValid(other)){
|
||||
toAdd.add(other.floor().drops.item);
|
||||
totalHardness += other.floor().drops.item.hardness;
|
||||
multiplier += 1f;
|
||||
}
|
||||
}
|
||||
|
||||
entity.drillTime += entity.warmup * Timers.delta();
|
||||
|
||||
float powerUsed = Math.min(powerCapacity, powerUse * Timers.delta());
|
||||
float liquidUsed = Math.min(liquidCapacity, liquidUse * Timers.delta());
|
||||
|
||||
//TODO slow down when no space.
|
||||
if((!hasPower || entity.power.amount >= powerUsed)
|
||||
&& (!hasLiquids || entity.liquid.amount >= liquidUsed)){
|
||||
if(hasPower) entity.power.amount -= powerUsed;
|
||||
if(hasLiquids) entity.liquid.amount -= liquidUsed;
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
entity.progress += Timers.delta() * multiplier;
|
||||
|
||||
if(Mathf.chance(Timers.delta() * updateEffectChance))
|
||||
Effects.effect(updateEffect, entity.x + Mathf.range(size*2f), entity.y + Mathf.range(size*2f));
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f);
|
||||
return;
|
||||
}
|
||||
|
||||
if(toAdd.size > 0 && entity.progress >= drillTime + hardnessDrillMultiplier*totalHardness
|
||||
&& tile.entity.inventory.totalItems() < itemCapacity){
|
||||
|
||||
int index = entity.index % toAdd.size;
|
||||
offloadNear(tile, toAdd.get(index));
|
||||
|
||||
entity.index ++;
|
||||
entity.progress = 0f;
|
||||
|
||||
Effects.effect(drillEffect, toAdd.get(index).color, tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDump, 15)){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
|
||||
return super.acceptLiquid(tile, source, liquid, amount) && liquid == inputLiquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new DrillEntity();
|
||||
}
|
||||
|
||||
public static class DrillEntity extends TileEntity{
|
||||
public float progress;
|
||||
public int index;
|
||||
public float warmup;
|
||||
public float drillTime;
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,6 @@ public class Pump extends LiquidBlock{
|
||||
|
||||
public Pump(String name) {
|
||||
super(name);
|
||||
rotate = false;
|
||||
solid = true;
|
||||
layer = Layer.overlay;
|
||||
liquidFlowFactor = 3f;
|
||||
group = BlockGroup.liquids;
|
||||
|
||||
Reference in New Issue
Block a user