reset my fork, started work on using power consumers
This commit is contained in:
@@ -25,13 +25,12 @@ public abstract class BaseBlock extends MappableContent{
|
|||||||
|
|
||||||
public boolean outputsLiquid = false;
|
public boolean outputsLiquid = false;
|
||||||
public boolean singleLiquid = true;
|
public boolean singleLiquid = true;
|
||||||
public boolean consumesPower = true;
|
public boolean consumesPower;
|
||||||
public boolean outputsPower;
|
public boolean outputsPower;
|
||||||
|
|
||||||
public int itemCapacity;
|
public int itemCapacity;
|
||||||
public float liquidCapacity = 10f;
|
public float liquidCapacity = 10f;
|
||||||
public float liquidFlowFactor = 4.9f;
|
public float liquidFlowFactor = 4.9f;
|
||||||
public float powerCapacity = 10f;
|
|
||||||
|
|
||||||
public Consumers consumes = new Consumers();
|
public Consumers consumes = new Consumers();
|
||||||
public Producers produces = new Producers();
|
public Producers produces = new Producers();
|
||||||
@@ -40,6 +39,18 @@ public abstract class BaseBlock extends MappableContent{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getPowerProduction(Tile tile){
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPowerConsumption(Tile tile){
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float usePower(Tile tile){
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
/**Returns the amount of items this block can accept.*/
|
/**Returns the amount of items this block can accept.*/
|
||||||
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
||||||
if(acceptItem(item, tile, tile) && hasItems && (source == null || source.getTeam() == tile.getTeam())){
|
if(acceptItem(item, tile, tile) && hasItems && (source == null || source.getTeam() == tile.getTeam())){
|
||||||
@@ -98,19 +109,6 @@ public abstract class BaseBlock extends MappableContent{
|
|||||||
tile.entity.liquids.add(liquid, amount);
|
tile.entity.liquids.add(liquid, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean acceptPower(Tile tile, Tile source, float amount){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Returns how much power is accepted.*/
|
|
||||||
public float addPower(Tile tile, float amount){
|
|
||||||
float canAccept = Math.min(powerCapacity - tile.entity.power.amount, amount);
|
|
||||||
|
|
||||||
tile.entity.power.amount += canAccept;
|
|
||||||
|
|
||||||
return canAccept;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tryDumpLiquid(Tile tile, Liquid liquid){
|
public void tryDumpLiquid(Tile tile, Liquid liquid){
|
||||||
Array<Tile> proximity = tile.entity.proximity();
|
Array<Tile> proximity = tile.entity.proximity();
|
||||||
int dump = tile.getDump();
|
int dump = tile.getDump();
|
||||||
|
|||||||
@@ -59,22 +59,6 @@ public class BlockPart extends Block{
|
|||||||
block.handleLiquid(tile.getLinked(), source, liquid, amount);
|
block.handleLiquid(tile.getLinked(), source, liquid, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public float addPower(Tile tile, float amount){
|
|
||||||
Block block = linked(tile);
|
|
||||||
if(block.hasPower){
|
|
||||||
return block.addPower(tile.getLinked(), amount);
|
|
||||||
}else{
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean acceptPower(Tile tile, Tile from, float amount){
|
|
||||||
Block block = linked(tile);
|
|
||||||
return block.hasPower && block.acceptPower(tile.getLinked(), from, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Block linked(Tile tile){
|
private Block linked(Tile tile){
|
||||||
return tile.getLinked().block();
|
return tile.getLinked().block();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package io.anuke.mindustry.world.consumers;
|
package io.anuke.mindustry.world.consumers;
|
||||||
|
|
||||||
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.BlockStats;
|
import io.anuke.mindustry.world.meta.BlockStats;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
|
||||||
|
|
||||||
public class ConsumePower extends Consume{
|
public class ConsumePower extends Consume{
|
||||||
protected final float use;
|
protected final float use;
|
||||||
@@ -24,15 +25,9 @@ public class ConsumePower extends Consume{
|
|||||||
return "icon-power";
|
return "icon-power";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(Block block, TileEntity entity){
|
|
||||||
if(entity.power == null) return;
|
|
||||||
entity.power.amount -= Math.min(use(block, entity), entity.power.amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean valid(Block block, TileEntity entity){
|
public boolean valid(Block block, TileEntity entity){
|
||||||
return entity.power != null && entity.power.amount >= use(block, entity);
|
return entity.power.satisfaction >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,7 +35,11 @@ public class ConsumePower extends Consume{
|
|||||||
stats.add(BlockStat.powerUse, use * 60f, StatUnit.powerSecond);
|
stats.add(BlockStat.powerUse, use * 60f, StatUnit.powerSecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float use(Block block, TileEntity entity){
|
public float getUse(Block block, TileEntity entity){
|
||||||
return Math.min(use * entity.delta(), block.powerCapacity);
|
return use * entity.delta();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPower(float amount) {
|
||||||
|
entity.power.satisfaction = amount / getUse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package io.anuke.mindustry.world.consumers;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
|
||||||
import io.anuke.mindustry.world.Block;
|
|
||||||
|
|
||||||
public class ConsumePowerExact extends ConsumePower{
|
|
||||||
|
|
||||||
public ConsumePowerExact(float use){
|
|
||||||
super(use);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected float use(Block block, TileEntity entity){
|
|
||||||
return this.use;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,14 +8,12 @@ import java.io.DataOutput;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class PowerModule extends BlockModule{
|
public class PowerModule extends BlockModule{
|
||||||
public float amount;
|
public float satisfaction;
|
||||||
public PowerGraph graph = new PowerGraph();
|
public PowerGraph graph = new PowerGraph();
|
||||||
public IntArray links = new IntArray();
|
public IntArray links = new IntArray();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(DataOutput stream) throws IOException{
|
||||||
stream.writeFloat(amount);
|
|
||||||
|
|
||||||
stream.writeShort(links.size);
|
stream.writeShort(links.size);
|
||||||
for(int i = 0; i < links.size; i++){
|
for(int i = 0; i < links.size; i++){
|
||||||
stream.writeInt(links.get(i));
|
stream.writeInt(links.get(i));
|
||||||
@@ -24,11 +22,6 @@ public class PowerModule extends BlockModule{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream) throws IOException{
|
public void read(DataInput stream) throws IOException{
|
||||||
amount = stream.readFloat();
|
|
||||||
if(Float.isNaN(amount)){
|
|
||||||
amount = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
short amount = stream.readShort();
|
short amount = stream.readShort();
|
||||||
for(int i = 0; i < amount; i++){
|
for(int i = 0; i < amount; i++){
|
||||||
links.add(stream.readInt());
|
links.add(stream.readInt());
|
||||||
|
|||||||
Reference in New Issue
Block a user