Added generic drill class, cleanup of other subclasses

This commit is contained in:
Anuken
2018-03-09 20:57:12 -05:00
parent c46f1ec590
commit 89ca9ad213
9 changed files with 114 additions and 176 deletions

View File

@ -552,7 +552,7 @@ blocks/extra/cross-1
index: -1 index: -1
blocks/extra/cross-2 blocks/extra/cross-2
rotate: false rotate: false
xy: 468, 113 xy: 213, 90
size: 16, 16 size: 16, 16
orig: 16, 16 orig: 16, 16
offset: 0, 0 offset: 0, 0
@ -585,13 +585,6 @@ blocks/production/alloysmelter
orig: 8, 8 orig: 8, 8
offset: 0, 0 offset: 0, 0
index: -1 index: -1
blocks/production/biomatterextractor
rotate: false
xy: 763, 426
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
blocks/production/coaldrill blocks/production/coaldrill
rotate: false rotate: false
xy: 590, 155 xy: 590, 155
@ -627,6 +620,13 @@ blocks/production/combustiongenerator
orig: 8, 8 orig: 8, 8
offset: 0, 0 offset: 0, 0
index: -1 index: -1
blocks/production/cultivator
rotate: false
xy: 468, 113
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
blocks/production/fluxpump blocks/production/fluxpump
rotate: false rotate: false
xy: 847, 431 xy: 847, 431
@ -1063,7 +1063,7 @@ blocks/turrets/block-1
index: -1 index: -1
blocks/turrets/block-2 blocks/turrets/block-2
rotate: false rotate: false
xy: 727, 365 xy: 763, 426
size: 16, 16 size: 16, 16
orig: 16, 16 orig: 16, 16
offset: 0, 0 offset: 0, 0
@ -1077,7 +1077,7 @@ blocks/turrets/block-3
index: -1 index: -1
blocks/turrets/chainturret blocks/turrets/chainturret
rotate: false rotate: false
xy: 637, 292 xy: 727, 365
size: 16, 16 size: 16, 16
orig: 16, 16 orig: 16, 16
offset: 0, 0 offset: 0, 0
@ -1869,7 +1869,7 @@ ui/cursor
index: -1 index: -1
ui/icons/controller-cursor ui/icons/controller-cursor
rotate: false rotate: false
xy: 213, 90 xy: 637, 292
size: 16, 16 size: 16, 16
orig: 16, 16 orig: 16, 16
offset: 0, 0 offset: 0, 0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

View File

@ -1,7 +1,7 @@
#Autogenerated file. Do not modify. #Autogenerated file. Do not modify.
#Thu Mar 08 23:00:40 EST 2018 #Fri Mar 09 20:56:36 EST 2018
version=release version=release
androidBuildCode=412 androidBuildCode=417
name=Mindustry name=Mindustry
code=3.4 code=3.4
build=custom build build=custom build

View File

@ -147,7 +147,7 @@ public class ProductionBlocks{
{ {
resource = Blocks.stone; resource = Blocks.stone;
result = Item.stone; result = Item.stone;
time = 4; drillTime = 40;
} }
}, },
@ -155,7 +155,7 @@ public class ProductionBlocks{
{ {
resource = Blocks.iron; resource = Blocks.iron;
result = Item.iron; result = Item.iron;
time = 6; drillTime = 60;
} }
}, },
@ -163,7 +163,7 @@ public class ProductionBlocks{
{ {
resource = Blocks.coal; resource = Blocks.coal;
result = Item.coal; result = Item.coal;
time = 6; drillTime = 60;
} }
}, },
@ -171,7 +171,7 @@ public class ProductionBlocks{
{ {
resource = Blocks.uranium; resource = Blocks.uranium;
result = Item.uranium; result = Item.uranium;
time = 7; drillTime = 70;
} }
}, },
@ -179,29 +179,29 @@ public class ProductionBlocks{
{ {
resource = Blocks.titanium; resource = Blocks.titanium;
result = Item.titanium; result = Item.titanium;
time = 7; drillTime = 70;
} }
}, },
laserdrill = new PowerDrill("laserdrill"){ laserdrill = new GenericDrill("laserdrill"){
{ {
time = 4; drillTime = 40;
size = 2; size = 2;
powerUse = 0.08f; powerUse = 0.08f;
} }
}, },
plasmadrill = new PowerDrill("plasmadrill"){ plasmadrill = new GenericDrill("plasmadrill"){
{ {
time = 4; drillTime = 40;
size = 3; size = 3;
powerUse = 0.16f; powerUse = 0.16f;
} }
}, },
nucleardrill = new PowerDrill("nucleardrill"){ nucleardrill = new GenericDrill("nucleardrill"){
{ {
time = 4; drillTime = 40;
size = 4; size = 4;
powerUse = 0.32f; powerUse = 0.32f;
} }
@ -211,18 +211,18 @@ public class ProductionBlocks{
{ {
resource = Blocks.sand; resource = Blocks.sand;
result = Item.quartz; result = Item.quartz;
time = 5; drillTime = 50;
size = 2; size = 2;
} }
}, },
cultivator = new LiquidDrill("cultivator"){ cultivator = new GenericDrill("cultivator"){
{ {
resource = Blocks.grass; resource = Blocks.grass;
result = Item.biomatter; result = Item.biomatter;
inputLiquid = Liquid.water; inputLiquid = Liquid.water;
inputLiquidAmount = 0.1f; liquidUse = 0.1f;
time = 5; drillTime = 50;
size = 2; size = 2;
} }
}, },

View File

@ -21,7 +21,7 @@ public class Drill extends Block{
protected Block resource; protected Block resource;
protected Item result; protected Item result;
protected float time = 5; protected float drillTime = 5;
protected Effect drillEffect = Fx.spark; protected Effect drillEffect = Fx.spark;
public Drill(String name) { public Drill(String name) {
@ -35,7 +35,7 @@ public class Drill extends Block{
@Override @Override
public void setStats(){ public void setStats(){
super.setStats(); super.setStats();
stats.add("secondsitem", time); stats.add("secondsitem", drillTime);
} }
@Override @Override
@ -54,7 +54,7 @@ public class Drill extends Block{
if(isValid(tile)) mines = 1; if(isValid(tile)) mines = 1;
} }
if(mines > 0 && entity.timer.get(timerDrill, 60 * time) && tile.entity.inventory.getItem(result) < itemCapacity){ if(mines > 0 && entity.timer.get(timerDrill, drillTime) && tile.entity.inventory.getItem(result) < itemCapacity){
for(int i = 0; i < mines; i ++) offloadNear(tile, result); for(int i = 0; i < mines; i ++) offloadNear(tile, result);
Effects.effect(drillEffect, tile.drawx(), tile.drawy()); Effects.effect(drillEffect, tile.drawx(), tile.drawy());
} }

View File

@ -0,0 +1,83 @@
package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
/**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 = Liquid.water;
private Array<Item> toAdd = new Array<>();
public GenericDrill(String name){
super(name);
}
@Override
public void update(Tile tile){
toAdd.clear();
DrillEntity entity = tile.entity();
float powerUsed = Math.min(powerCapacity, powerUse * Timers.delta());
float liquidUsed = Math.min(liquidCapacity, liquidUse * Timers.delta());
if((!hasPower || entity.power.amount >= powerUsed)
&& (!hasLiquids || entity.liquid.amount >= liquidUsed)){
if(hasPower) entity.power.amount -= powerUsed;
if(hasLiquids) entity.liquid.amount -= liquidUsed;
entity.time += Timers.delta();
}else{
return;
}
for(Tile other : tile.getLinkedTiles(tempTiles)){
if(isValid(other)){
toAdd.add(result == null ? other.floor().drops.item : result);
}
}
if(toAdd.size > 0 && entity.power.amount > powerUse && entity.time >= drillTime
&& tile.entity.inventory.totalItems() < itemCapacity){
for(Item item : toAdd) offloadNear(tile, item);
Effects.effect(drillEffect, tile.drawx(), tile.drawy());
entity.time = 0f;
}
if(entity.timer.get(timerDump, 30)){
tryDump(tile);
}
}
@Override
protected boolean isValid(Tile tile){
if(resource == null) {
return tile.floor().drops != null;
}else{
return tile.floor() == resource || (resource.drops != null && resource.drops.equals(tile.floor().drops));
}
}
@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();
}
static class DrillEntity extends TileEntity{
public float time;
}
}

View File

@ -1,32 +0,0 @@
package io.anuke.mindustry.world.blocks.types.production;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
/**A drill that uses liquid as fuel.*/
public class LiquidDrill extends Drill {
protected Liquid inputLiquid = Liquid.water;
protected float inputLiquidAmount = 0.1f; //per frame
public LiquidDrill(String name){
super(name);
hasLiquids = true;
}
@Override
public void update(Tile tile){
float consume = Math.min(liquidCapacity, inputLiquidAmount * Timers.delta());
if(tile.entity.liquid.amount >= consume){
tile.entity.liquid.amount -= consume;
super.update(tile);
}
}
@Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
return super.acceptLiquid(tile, source, liquid, amount) && liquid == inputLiquid;
}
}

View File

@ -1,58 +0,0 @@
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;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.util.Tmp;
public class Omnidrill extends Drill {
public Omnidrill(String name){
super(name);
drillEffect = Fx.sparkbig;
resource = null;
result = null;
}
@Override
public void draw(Tile tile){
super.draw(tile);
if(tile.floor().drops == null) return;
Item item = tile.floor().drops.item;
TextureRegion region = item.region;
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 2f, 2f);
}
@Override
public boolean canReplace(Block other) {
return other instanceof Drill && other != this;
}
@Override
public void update(Tile tile){
TileEntity entity = tile.entity;
if(tile.floor().drops != null && entity.timer.get(timerDrill, 60 * time)){
offloadNear(tile, tile.floor().drops.item);
Effects.effect(drillEffect, tile.worldx(), tile.worldy());
}
if(entity.timer.get(timerDump, 30)){
tryDump(tile);
}
}
@Override
public boolean isLayer(Tile tile){
return tile.floor().drops == null;
}
}

View File

@ -1,55 +0,0 @@
package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerBlock.PowerEntity;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
public class PowerDrill extends Drill{
/**power use per frame.*/
public float powerUse = 0.08f;
private Array<ItemStack> toAdd = new Array<>();
public PowerDrill(String name){
super(name);
hasPower = true;
}
@Override
public void update(Tile tile){
toAdd.clear();
PowerEntity entity = tile.entity();
float used = Math.min(powerUse * Timers.delta(), powerCapacity-0.1f);
if(entity.power.amount >= used){
entity.power.amount -= used;
}
for(Tile other : tile.getLinkedTiles(tempTiles)){
if(isValid(other)){
toAdd.add(other.floor().drops);
}
}
if(toAdd.size > 0 && entity.power.amount > powerUse && entity.timer.get(timerDrill, 60 * time)
&& tile.entity.inventory.totalItems() < itemCapacity){
for(ItemStack stack : toAdd) offloadNear(tile, stack.item);
Effects.effect(drillEffect, tile.drawx(), tile.drawy());
}
if(entity.timer.get(timerDump, 30)){
tryDump(tile);
}
}
@Override
protected boolean isValid(Tile tile){
return tile.floor().drops != null;
}
}