Sweeping rework
This commit is contained in:
@@ -372,6 +372,7 @@ blocks.basepowergeneration = Base Power Generation
|
|||||||
blocks.powertransferspeed = Power Transfer
|
blocks.powertransferspeed = Power Transfer
|
||||||
blocks.productiontime = Production Time
|
blocks.productiontime = Production Time
|
||||||
blocks.repairtime = Block Full Repair Time
|
blocks.repairtime = Block Full Repair Time
|
||||||
|
blocks.speedincrease = Speed Increase
|
||||||
blocks.range = Range
|
blocks.range = Range
|
||||||
blocks.inputliquid = Input Liquid
|
blocks.inputliquid = Input Liquid
|
||||||
blocks.inputliquidaux = Aux Liquid
|
blocks.inputliquidaux = Aux Liquid
|
||||||
@@ -380,6 +381,7 @@ blocks.inputitems = Input Items
|
|||||||
blocks.outputitem = Output Item
|
blocks.outputitem = Output Item
|
||||||
blocks.drilltier = Drillables
|
blocks.drilltier = Drillables
|
||||||
blocks.drillspeed = Base Drill Speed
|
blocks.drillspeed = Base Drill Speed
|
||||||
|
blocks.boosteffect = Boost Effect
|
||||||
blocks.maxunits = Max Active Units
|
blocks.maxunits = Max Active Units
|
||||||
blocks.liquidoutput = Liquid Output
|
blocks.liquidoutput = Liquid Output
|
||||||
blocks.liquidoutputspeed = Liquid Output Speed
|
blocks.liquidoutputspeed = Liquid Output Speed
|
||||||
@@ -426,6 +428,10 @@ unit.liquidunits = liquid units
|
|||||||
unit.powerunits = power units
|
unit.powerunits = power units
|
||||||
unit.degrees = degrees
|
unit.degrees = degrees
|
||||||
unit.seconds = seconds
|
unit.seconds = seconds
|
||||||
|
unit.persecond = /sec
|
||||||
|
unit.timesspeed = x speed
|
||||||
|
unit.timesRadius = x radius
|
||||||
|
unit.percent = %
|
||||||
unit.items = items
|
unit.items = items
|
||||||
category.general = General
|
category.general = General
|
||||||
category.power = Power
|
category.power = Power
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import io.anuke.mindustry.world.blocks.storage.Vault;
|
|||||||
import io.anuke.mindustry.world.blocks.units.MechPad;
|
import io.anuke.mindustry.world.blocks.units.MechPad;
|
||||||
import io.anuke.mindustry.world.blocks.units.RepairPoint;
|
import io.anuke.mindustry.world.blocks.units.RepairPoint;
|
||||||
import io.anuke.mindustry.world.blocks.units.UnitFactory;
|
import io.anuke.mindustry.world.blocks.units.UnitFactory;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
|
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||||
import io.anuke.mindustry.world.meta.Attribute;
|
import io.anuke.mindustry.world.meta.Attribute;
|
||||||
import io.anuke.mindustry.world.modules.LiquidModule;
|
import io.anuke.mindustry.world.modules.LiquidModule;
|
||||||
@@ -521,7 +520,6 @@ public class Blocks implements ContentList{
|
|||||||
hasItems = true;
|
hasItems = true;
|
||||||
rotate = false;
|
rotate = false;
|
||||||
solid = true;
|
solid = true;
|
||||||
singleLiquid = false;
|
|
||||||
outputsLiquid = true;
|
outputsLiquid = true;
|
||||||
|
|
||||||
consumes.power(1f);
|
consumes.power(1f);
|
||||||
@@ -594,7 +592,7 @@ public class Blocks implements ContentList{
|
|||||||
Items.titanium, 2
|
Items.titanium, 2
|
||||||
);
|
);
|
||||||
hasPower = true;
|
hasPower = true;
|
||||||
filterTime = 35f;
|
craftTime = 35f;
|
||||||
spinnerLength = 1.5f;
|
spinnerLength = 1.5f;
|
||||||
spinnerRadius = 3.5f;
|
spinnerRadius = 3.5f;
|
||||||
spinnerThickness = 1.5f;
|
spinnerThickness = 1.5f;
|
||||||
@@ -829,13 +827,13 @@ public class Blocks implements ContentList{
|
|||||||
requirements(Category.effect, ItemStack.with(Items.lead, 200, Items.titanium, 150, Items.silicon, 150, Items.plastanium, 60));
|
requirements(Category.effect, ItemStack.with(Items.lead, 200, Items.titanium, 150, Items.silicon, 150, Items.plastanium, 60));
|
||||||
consumes.power(3.50f);
|
consumes.power(3.50f);
|
||||||
size = 2;
|
size = 2;
|
||||||
consumes.item(Items.phasefabric).optional(true).boost(true);
|
consumes.item(Items.phasefabric).optional(true);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
forceProjector = new ForceProjector("force-projector"){{
|
forceProjector = new ForceProjector("force-projector"){{
|
||||||
requirements(Category.effect, ItemStack.with(Items.lead, 200, Items.titanium, 150, Items.silicon, 250));
|
requirements(Category.effect, ItemStack.with(Items.lead, 200, Items.titanium, 150, Items.silicon, 250));
|
||||||
size = 3;
|
size = 3;
|
||||||
consumes.item(Items.phasefabric).optional(true).boost(true);
|
consumes.item(Items.phasefabric).optional(true);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
shockMine = new ShockMine("shock-mine"){{
|
shockMine = new ShockMine("shock-mine"){{
|
||||||
@@ -1024,7 +1022,7 @@ public class Blocks implements ContentList{
|
|||||||
size = 2;
|
size = 2;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
turbineGenerator = new TurbineGenerator("turbine-generator"){{
|
turbineGenerator = new BurnerGenerator("turbine-generator"){{
|
||||||
requirements(Category.power, ItemStack.with(Items.copper, 70, Items.graphite, 50, Items.lead, 80, Items.silicon, 60));
|
requirements(Category.power, ItemStack.with(Items.copper, 70, Items.graphite, 50, Items.lead, 80, Items.silicon, 60));
|
||||||
powerProduction = 6f;
|
powerProduction = 6f;
|
||||||
itemDuration = 30f;
|
itemDuration = 30f;
|
||||||
@@ -1033,15 +1031,15 @@ public class Blocks implements ContentList{
|
|||||||
size = 2;
|
size = 2;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
differentialGenerator = new DifferentialGenerator("differential-generator"){{
|
differentialGenerator = new ItemLiquidGenerator(true, true, "differential-generator"){{
|
||||||
requirements(Category.power, ItemStack.with(Items.copper, 140, Items.titanium, 100, Items.lead, 200, Items.silicon, 130, Items.metaglass, 100));
|
requirements(Category.power, ItemStack.with(Items.copper, 140, Items.titanium, 100, Items.lead, 200, Items.silicon, 130, Items.metaglass, 100));
|
||||||
powerProduction = 13f;
|
powerProduction = 13f;
|
||||||
itemDuration = 50f;
|
itemDuration = 50f;
|
||||||
consumes.remove(ConsumeItemFilter.class);
|
hasLiquids = true;
|
||||||
consumes.remove(ConsumeLiquidFilter.class);
|
size = 3;
|
||||||
|
|
||||||
consumes.item(Items.pyratite);
|
consumes.item(Items.pyratite);
|
||||||
consumes.liquid(Liquids.cryofluid, 0.2f);
|
consumes.liquid(Liquids.cryofluid, 0.2f);
|
||||||
size = 3;
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
rtgGenerator = new DecayGenerator("rtg-generator"){{
|
rtgGenerator = new DecayGenerator("rtg-generator"){{
|
||||||
@@ -1076,7 +1074,7 @@ public class Blocks implements ContentList{
|
|||||||
size = 4;
|
size = 4;
|
||||||
health = 900;
|
health = 900;
|
||||||
powerProduction = 80f;
|
powerProduction = 80f;
|
||||||
useTime = 40f;
|
itemDuration = 40f;
|
||||||
consumes.power(23f);
|
consumes.power(23f);
|
||||||
consumes.item(Items.blastCompound);
|
consumes.item(Items.blastCompound);
|
||||||
consumes.liquid(Liquids.cryofluid, 0.8f);
|
consumes.liquid(Liquids.cryofluid, 0.8f);
|
||||||
@@ -1091,6 +1089,7 @@ public class Blocks implements ContentList{
|
|||||||
drillTime = 600;
|
drillTime = 600;
|
||||||
size = 2;
|
size = 2;
|
||||||
drawMineItem = true;
|
drawMineItem = true;
|
||||||
|
consumes.liquid(Liquids.water, 0.05f).optional(true);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
pneumaticDrill = new Drill("pneumatic-drill"){{
|
pneumaticDrill = new Drill("pneumatic-drill"){{
|
||||||
@@ -1470,7 +1469,6 @@ public class Blocks implements ContentList{
|
|||||||
);
|
);
|
||||||
reload = 6f;
|
reload = 6f;
|
||||||
coolantMultiplier = 0.5f;
|
coolantMultiplier = 0.5f;
|
||||||
maxCoolantUsed = 1.5f;
|
|
||||||
restitution = 0.1f;
|
restitution = 0.1f;
|
||||||
ammoUseEffect = Fx.shellEjectBig;
|
ammoUseEffect = Fx.shellEjectBig;
|
||||||
range = 200f;
|
range = 200f;
|
||||||
@@ -1484,6 +1482,7 @@ public class Blocks implements ContentList{
|
|||||||
shootCone = 24f;
|
shootCone = 24f;
|
||||||
|
|
||||||
health = 155 * size * size;
|
health = 155 * size * size;
|
||||||
|
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 2f)).update(false).optional(true);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
meltdown = new LaserTurret("meltdown"){{
|
meltdown = new LaserTurret("meltdown"){{
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class Items implements ContentList{
|
|||||||
|
|
||||||
plastanium = new Item("plastanium", Color.valueOf("cbd97f")){{
|
plastanium = new Item("plastanium", Color.valueOf("cbd97f")){{
|
||||||
type = ItemType.material;
|
type = ItemType.material;
|
||||||
flammability = 0.2f;
|
flammability = 0.1f;
|
||||||
explosiveness = 0.2f;
|
explosiveness = 0.2f;
|
||||||
cost = 1.6f;
|
cost = 1.6f;
|
||||||
}};
|
}};
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
public static int sleepingEntities = 0;
|
public static int sleepingEntities = 0;
|
||||||
|
|
||||||
public Tile tile;
|
public Tile tile;
|
||||||
|
public Block block;
|
||||||
public Interval timer;
|
public Interval timer;
|
||||||
public float health;
|
public float health;
|
||||||
public float timeScale = 1f, timeScaleDuration;
|
public float timeScale = 1f, timeScaleDuration;
|
||||||
@@ -76,10 +77,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
x = tile.drawx();
|
x = tile.drawx();
|
||||||
y = tile.drawy();
|
y = tile.drawy();
|
||||||
|
block = tile.block();
|
||||||
|
|
||||||
health = tile.block().health;
|
health = block.health;
|
||||||
|
timer = new Interval(block.timers);
|
||||||
timer = new Interval(tile.block().timers);
|
|
||||||
|
|
||||||
if(shouldAdd){
|
if(shouldAdd){
|
||||||
add();
|
add();
|
||||||
@@ -134,7 +135,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void collision(Bullet other){
|
public void collision(Bullet other){
|
||||||
tile.block().handleBulletHit(this, other);
|
block.handleBulletHit(this, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(){
|
public void kill(){
|
||||||
@@ -146,7 +147,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
|
|
||||||
float preHealth = health;
|
float preHealth = health;
|
||||||
|
|
||||||
Call.onTileDamage(tile, health - tile.block().handleDamage(tile, damage));
|
Call.onTileDamage(tile, health - block.handleDamage(tile, damage));
|
||||||
|
|
||||||
if(health <= 0){
|
if(health <= 0){
|
||||||
Call.onTileDestroyed(tile);
|
Call.onTileDestroyed(tile);
|
||||||
@@ -164,9 +165,9 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeFromProximity(){
|
public void removeFromProximity(){
|
||||||
tile.block().onProximityRemoved(tile);
|
block.onProximityRemoved(tile);
|
||||||
|
|
||||||
Point2[] nearby = Edges.getEdges(tile.block().size);
|
Point2[] nearby = Edges.getEdges(block.size);
|
||||||
for(Point2 point : nearby){
|
for(Point2 point : nearby){
|
||||||
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
||||||
//remove this tile from all nearby tile's proximities
|
//remove this tile from all nearby tile's proximities
|
||||||
@@ -184,7 +185,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
tmpTiles.clear();
|
tmpTiles.clear();
|
||||||
proximity.clear();
|
proximity.clear();
|
||||||
|
|
||||||
Point2[] nearby = Edges.getEdges(tile.block().size);
|
Point2[] nearby = Edges.getEdges(block.size);
|
||||||
for(Point2 point : nearby){
|
for(Point2 point : nearby){
|
||||||
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
||||||
|
|
||||||
@@ -207,8 +208,8 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
proximity.add(tile);
|
proximity.add(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
tile.block().onProximityAdded(tile);
|
block.onProximityAdded(tile);
|
||||||
tile.block().onProximityUpdate(tile);
|
block.onProximityUpdate(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array<Tile> proximity(){
|
public Array<Tile> proximity(){
|
||||||
@@ -227,7 +228,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float maxHealth(){
|
public float maxHealth(){
|
||||||
return tile.block().health;
|
return block.health;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -239,7 +240,6 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
public void onDeath(){
|
public void onDeath(){
|
||||||
if(!dead){
|
if(!dead){
|
||||||
dead = true;
|
dead = true;
|
||||||
Block block = tile.block();
|
|
||||||
|
|
||||||
Events.fire(new BlockDestroyEvent(tile));
|
Events.fire(new BlockDestroyEvent(tile));
|
||||||
block.onDestroyed(tile);
|
block.onDestroyed(tile);
|
||||||
@@ -262,22 +262,22 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
//TODO better smoke effect, this one is awful
|
//TODO better smoke effect, this one is awful
|
||||||
if(health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
|
if(health != 0 && health < block.health && !(block instanceof Wall) &&
|
||||||
Mathf.chance(0.009f * Time.delta() * (1f - health / tile.block().health))){
|
Mathf.chance(0.009f * Time.delta() * (1f - health / block.health))){
|
||||||
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
|
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
timeScaleDuration -= Time.delta();
|
timeScaleDuration -= Time.delta();
|
||||||
if(timeScaleDuration <= 0f || !tile.block().canOverdrive){
|
if(timeScaleDuration <= 0f || !block.canOverdrive){
|
||||||
timeScale = 1f;
|
timeScale = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(health <= 0){
|
if(health <= 0){
|
||||||
onDeath();
|
onDeath();
|
||||||
}
|
}
|
||||||
Block previous = tile.block();
|
Block previous = block;
|
||||||
tile.block().update(tile);
|
block.update(tile);
|
||||||
if(tile.block() == previous && cons != null){
|
if(block == previous && cons != null){
|
||||||
cons.update();
|
cons.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,31 @@
|
|||||||
package io.anuke.mindustry.ui;
|
package io.anuke.mindustry.ui;
|
||||||
|
|
||||||
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.scene.ui.Image;
|
import io.anuke.arc.scene.ui.Image;
|
||||||
import io.anuke.arc.scene.ui.layout.Stack;
|
import io.anuke.arc.scene.ui.layout.Stack;
|
||||||
import io.anuke.arc.scene.ui.layout.Table;
|
import io.anuke.arc.scene.ui.layout.Table;
|
||||||
import io.anuke.arc.util.Strings;
|
import io.anuke.arc.util.Strings;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
/**An ItemDisplay, but for liquids.*/
|
/**An ItemDisplay, but for liquids.*/
|
||||||
public class LiquidDisplay extends Table{
|
public class LiquidDisplay extends Table{
|
||||||
|
|
||||||
public LiquidDisplay(Liquid liquid){
|
public LiquidDisplay(Liquid liquid, float amount, boolean perSecond){
|
||||||
add(new Image(liquid.getContentIcon())).size(8*4);
|
|
||||||
add(liquid.localizedName()).padLeft(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiquidDisplay(Liquid liquid, float amount){
|
|
||||||
add(new Stack(){{
|
add(new Stack(){{
|
||||||
add(new Image(liquid.getContentIcon()));
|
add(new Image(liquid.getContentIcon()));
|
||||||
|
|
||||||
if(amount != 0){
|
if(amount != 0){
|
||||||
Table t = new Table().left().bottom();
|
Table t = new Table().left().bottom();
|
||||||
t.add(Strings.autoFixed(amount));
|
t.add(Strings.autoFixed(amount, 1));
|
||||||
add(t);
|
add(t);
|
||||||
}
|
}
|
||||||
}}).size(8*4);
|
}}).size(8*4).padRight(3);
|
||||||
add(liquid.localizedName()).padLeft(3);
|
|
||||||
|
if(perSecond){
|
||||||
|
add(StatUnit.perSecond.localized()).padLeft(2).padRight(5).color(Color.LIGHT_GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
add(liquid.localizedName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import io.anuke.mindustry.ui.Bar;
|
|||||||
import io.anuke.mindustry.ui.ContentDisplay;
|
import io.anuke.mindustry.ui.ContentDisplay;
|
||||||
import io.anuke.mindustry.world.consumers.Consume;
|
import io.anuke.mindustry.world.consumers.Consume;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
import io.anuke.mindustry.world.meta.*;
|
import io.anuke.mindustry.world.meta.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -321,7 +321,7 @@ public class Block extends BlockStorage{
|
|||||||
setStats();
|
setStats();
|
||||||
setBars();
|
setBars();
|
||||||
|
|
||||||
consumes.checkRequired(this);
|
consumes.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -407,8 +407,8 @@ public class Block extends BlockStorage{
|
|||||||
|
|
||||||
if(hasLiquids){
|
if(hasLiquids){
|
||||||
Function<TileEntity, Liquid> current;
|
Function<TileEntity, Liquid> current;
|
||||||
if(consumes.has(ConsumeLiquid.class)){
|
if(consumes.has(ConsumeType.liquid) && consumes.get(ConsumeType.liquid) instanceof ConsumeLiquid){
|
||||||
Liquid liquid = consumes.liquid();
|
Liquid liquid = consumes.<ConsumeLiquid>get(ConsumeType.liquid).liquid;
|
||||||
current = entity -> liquid;
|
current = entity -> liquid;
|
||||||
}else{
|
}else{
|
||||||
current = entity -> entity.liquids.current();
|
current = entity -> entity.liquids.current();
|
||||||
@@ -416,9 +416,9 @@ public class Block extends BlockStorage{
|
|||||||
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("blocks.liquid") : current.get(entity).localizedName(), () -> current.get(entity).color, () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
|
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("blocks.liquid") : current.get(entity).localizedName(), () -> current.get(entity).color, () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasPower && consumes.has(ConsumePower.class)){
|
if(hasPower && consumes.hasPower()){
|
||||||
boolean buffered = consumes.get(ConsumePower.class).isBuffered;
|
boolean buffered = consumes.getPower().isBuffered;
|
||||||
float capacity = consumes.get(ConsumePower.class).powerCapacity;
|
float capacity = consumes.getPower().powerCapacity;
|
||||||
|
|
||||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("blocks.powerbalance", Float.isNaN(entity.power.satisfaction * capacity) ? "<ERROR>" : (int)(entity.power.satisfaction * capacity)) :
|
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("blocks.powerbalance", Float.isNaN(entity.power.satisfaction * capacity) ? "<ERROR>" : (int)(entity.power.satisfaction * capacity)) :
|
||||||
Core.bundle.get("blocks.power"), () -> Pal.powerBar, () -> entity.power.satisfaction));
|
Core.bundle.get("blocks.power"), () -> Pal.powerBar, () -> entity.power.satisfaction));
|
||||||
@@ -477,8 +477,8 @@ public class Block extends BlockStorage{
|
|||||||
explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 2f);
|
explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(consumes.has(ConsumePower.class) && consumes.get(ConsumePower.class).isBuffered){
|
if(consumes.hasPower() && consumes.getPower().isBuffered){
|
||||||
power += tile.entity.power.satisfaction * consumes.get(ConsumePower.class).powerCapacity;
|
power += tile.entity.power.satisfaction * consumes.getPower().powerCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasLiquids){
|
if(hasLiquids){
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
public final BlockStats stats = new BlockStats();
|
public final BlockStats stats = new BlockStats();
|
||||||
public final BlockBars bars = new BlockBars();
|
public final BlockBars bars = new BlockBars();
|
||||||
public final Consumers consumes = new Consumers();
|
public final Consumers consumes = new Consumers();
|
||||||
//public final Producers produces = new Producers();
|
|
||||||
|
|
||||||
public BlockStorage(String name){
|
public BlockStorage(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -112,7 +111,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
Tile other = proximity.get((i + dump) % proximity.size);
|
Tile other = proximity.get((i + dump) % proximity.size);
|
||||||
Tile in = Edges.getFacingEdge(tile, other);
|
Tile in = Edges.getFacingEdge(tile, other);
|
||||||
|
|
||||||
if(other.getTeamID() == tile.getTeamID() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid)){
|
if(other.getTeam() == tile.getTeam() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid)){
|
||||||
float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity;
|
float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity;
|
||||||
float fract = tile.entity.liquids.get(liquid) / liquidCapacity;
|
float fract = tile.entity.liquids.get(liquid) / liquidCapacity;
|
||||||
|
|
||||||
@@ -140,7 +139,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
|
|
||||||
next = next.target();
|
next = next.target();
|
||||||
|
|
||||||
if(next.getTeamID() == tile.getTeamID() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
|
if(next.getTeam() == tile.getTeam() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
|
||||||
|
|
||||||
if(next.block().acceptLiquid(next, tile, liquid, 0f)){
|
if(next.block().acceptLiquid(next, tile, liquid, 0f)){
|
||||||
float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity;
|
float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity;
|
||||||
@@ -190,7 +189,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
incrementDump(tile, proximity.size);
|
incrementDump(tile, proximity.size);
|
||||||
Tile other = proximity.get((i + dump) % proximity.size);
|
Tile other = proximity.get((i + dump) % proximity.size);
|
||||||
Tile in = Edges.getFacingEdge(tile, other);
|
Tile in = Edges.getFacingEdge(tile, other);
|
||||||
if(other.getTeamID() == tile.getTeamID() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||||
other.block().handleItem(item, other, in);
|
other.block().handleItem(item, other, in);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -199,9 +198,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
handleItem(item, tile, tile);
|
handleItem(item, tile, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**Try dumping any item near the tile.*/
|
||||||
* Try dumping any item near the tile.
|
|
||||||
*/
|
|
||||||
public boolean tryDump(Tile tile){
|
public boolean tryDump(Tile tile){
|
||||||
return tryDump(tile, null);
|
return tryDump(tile, null);
|
||||||
}
|
}
|
||||||
@@ -230,7 +227,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
for(int ii = 0; ii < Vars.content.items().size; ii++){
|
for(int ii = 0; ii < Vars.content.items().size; ii++){
|
||||||
Item item = Vars.content.item(ii);
|
Item item = Vars.content.item(ii);
|
||||||
|
|
||||||
if(other.getTeamID() == tile.getTeamID() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
if(other.getTeam() == tile.getTeam() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||||
other.block().handleItem(item, other, in);
|
other.block().handleItem(item, other, in);
|
||||||
tile.entity.items.remove(item, 1);
|
tile.entity.items.remove(item, 1);
|
||||||
incrementDump(tile, proximity.size);
|
incrementDump(tile, proximity.size);
|
||||||
@@ -239,7 +236,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
if(other.getTeamID() == tile.getTeamID() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||||
other.block().handleItem(todump, other, in);
|
other.block().handleItem(todump, other, in);
|
||||||
tile.entity.items.remove(todump, 1);
|
tile.entity.items.remove(todump, 1);
|
||||||
incrementDump(tile, proximity.size);
|
incrementDump(tile, proximity.size);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import io.anuke.mindustry.world.Block;
|
|||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class ForceProjector extends Block {
|
|||||||
canOverdrive = false;
|
canOverdrive = false;
|
||||||
hasLiquids = true;
|
hasLiquids = true;
|
||||||
hasItems = true;
|
hasItems = true;
|
||||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.1f)).optional(true).boost(true).update(false);
|
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.1f)).optional(true).update(false);
|
||||||
consumePower = new ConsumeForceProjectorPower(60f, 60f);
|
consumePower = new ConsumeForceProjectorPower(60f, 60f);
|
||||||
consumes.add(consumePower);
|
consumes.add(consumePower);
|
||||||
}
|
}
|
||||||
@@ -71,6 +72,8 @@ public class ForceProjector extends Block {
|
|||||||
|
|
||||||
stats.add(BlockStat.powerUse, basePowerDraw * 60f, StatUnit.powerSecond);
|
stats.add(BlockStat.powerUse, basePowerDraw * 60f, StatUnit.powerSecond);
|
||||||
stats.add(BlockStat.powerDamage, powerDamage, StatUnit.powerUnits);
|
stats.add(BlockStat.powerDamage, powerDamage, StatUnit.powerUnits);
|
||||||
|
|
||||||
|
stats.add(BlockStat.boostEffect, phaseRadiusBoost/tilesize, StatUnit.blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,10 +86,10 @@ public class ForceProjector extends Block {
|
|||||||
entity.shield.add();
|
entity.shield.add();
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||||
|
|
||||||
if(entity.cons.valid() && !entity.broken && entity.timer.get(timerUse, phaseUseTime) && entity.items.total() > 0){
|
if(entity.cons.optionalValid() && !entity.broken && entity.timer.get(timerUse, phaseUseTime)){
|
||||||
entity.items.remove(consumes.item(), 1);
|
entity.cons.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.radscl = Mathf.lerpDelta(entity.radscl, entity.broken ? 0f : 1f, 0.05f);
|
entity.radscl = Mathf.lerpDelta(entity.radscl, entity.broken ? 0f : 1f, 0.05f);
|
||||||
@@ -95,7 +98,7 @@ public class ForceProjector extends Block {
|
|||||||
Effects.effect(Fx.reactorsmoke, tile.drawx() + Mathf.range(tilesize/2f), tile.drawy() + Mathf.range(tilesize/2f));
|
Effects.effect(Fx.reactorsmoke, tile.drawx() + Mathf.range(tilesize/2f), tile.drawy() + Mathf.range(tilesize/2f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use Cases:
|
//use cases:
|
||||||
// - There is enough power in the buffer, and there are no shots fired => Draw base power and keep shield up
|
// - There is enough power in the buffer, and there are no shots fired => Draw base power and keep shield up
|
||||||
// - There is enough power in the buffer, but not enough power to cope for shots being fired => Draw all power and break shield
|
// - There is enough power in the buffer, but not enough power to cope for shots being fired => Draw all power and break shield
|
||||||
// - There is enough power in the buffer and enough power to cope for shots being fired => Draw base power + additional power based on shots absorbed
|
// - There is enough power in the buffer and enough power to cope for shots being fired => Draw base power + additional power based on shots absorbed
|
||||||
@@ -120,8 +123,9 @@ public class ForceProjector extends Block {
|
|||||||
|
|
||||||
if(entity.buildup > 0){
|
if(entity.buildup > 0){
|
||||||
float scale = !entity.broken ? cooldownNormal : cooldownBrokenBase;
|
float scale = !entity.broken ? cooldownNormal : cooldownBrokenBase;
|
||||||
if(consumes.get(ConsumeLiquidFilter.class).valid(this, entity)){
|
ConsumeLiquidFilter cons = consumes.get(ConsumeType.liquid);
|
||||||
consumes.get(ConsumeLiquidFilter.class).update(this, entity);
|
if(cons.valid(entity)){
|
||||||
|
cons.update(entity);
|
||||||
scale *= (cooldownLiquid * (1f+(entity.liquids.current().heatCapacity-0.4f)*0.9f));
|
scale *= (cooldownLiquid * (1f+(entity.liquids.current().heatCapacity-0.4f)*0.9f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,8 +272,8 @@ public class ForceProjector extends Block {
|
|||||||
super(powerCapacity / ticksToFill, powerCapacity, true);
|
super(powerCapacity / ticksToFill, powerCapacity, true);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean valid(Block block, TileEntity entity){
|
public boolean valid(TileEntity entity){
|
||||||
return entity.power.satisfaction >= basePowerDraw / powerCapacity && super.valid(block, entity);
|
return entity.power.satisfaction >= basePowerDraw / powerCapacity && super.valid(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ public class MendProjector extends Block{
|
|||||||
|
|
||||||
stats.add(BlockStat.repairTime, (int)(100f / healPercent * reload / 60f), StatUnit.seconds);
|
stats.add(BlockStat.repairTime, (int)(100f / healPercent * reload / 60f), StatUnit.seconds);
|
||||||
stats.add(BlockStat.range, range / tilesize, StatUnit.blocks);
|
stats.add(BlockStat.range, range / tilesize, StatUnit.blocks);
|
||||||
|
|
||||||
|
stats.add(BlockStat.boostEffect, phaseRangeBoost/tilesize, StatUnit.blocks);
|
||||||
|
stats.add(BlockStat.boostEffect, (phaseBoost + healPercent) / healPercent, StatUnit.timesSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,10 +71,10 @@ public class MendProjector extends Block{
|
|||||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f);
|
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f);
|
||||||
entity.charge += entity.heat * entity.delta();
|
entity.charge += entity.heat * entity.delta();
|
||||||
|
|
||||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||||
|
|
||||||
if(entity.cons.valid() && entity.timer.get(timerUse, useTime) && entity.items.total() > 0){
|
if(entity.cons.optionalValid() && entity.timer.get(timerUse, useTime)){
|
||||||
entity.items.remove(consumes.item(), 1);
|
entity.cons.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entity.charge >= reload){
|
if(entity.charge >= reload){
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import io.anuke.arc.util.Time;
|
|||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
@@ -50,16 +52,27 @@ public class OverdriveProjector extends Block{
|
|||||||
topRegion = Core.atlas.find(name + "-top");
|
topRegion = Core.atlas.find(name + "-top");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStats(){
|
||||||
|
super.setStats();
|
||||||
|
|
||||||
|
stats.add(BlockStat.speedIncrease, (int)(100f * speedBoost), StatUnit.percent);
|
||||||
|
stats.add(BlockStat.range, range / tilesize, StatUnit.blocks);
|
||||||
|
|
||||||
|
stats.add(BlockStat.boostEffect, phaseRangeBoost/tilesize, StatUnit.blocks);
|
||||||
|
stats.add(BlockStat.boostEffect, (int)((speedBoost + speedBoostPhase) * 100f), StatUnit.percent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
OverdriveEntity entity = tile.entity();
|
OverdriveEntity entity = tile.entity();
|
||||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() ? 1f : 0f, 0.08f);
|
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() ? 1f : 0f, 0.08f);
|
||||||
entity.charge += entity.heat * Time.delta();
|
entity.charge += entity.heat * Time.delta();
|
||||||
|
|
||||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||||
|
|
||||||
if(entity.timer.get(timerUse, useTime) && entity.items.total() > 0){
|
if(entity.timer.get(timerUse, useTime)){
|
||||||
entity.items.remove(consumes.item(), 1);
|
entity.cons.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entity.charge >= reload){
|
if(entity.charge >= reload){
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
package io.anuke.mindustry.world.blocks.defense.turrets;
|
package io.anuke.mindustry.world.blocks.defense.turrets;
|
||||||
|
|
||||||
|
import io.anuke.arc.math.Mathf;
|
||||||
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
|
||||||
import io.anuke.mindustry.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.mindustry.entities.Effects.Effect;
|
import io.anuke.mindustry.entities.Effects.Effect;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
public class CooledTurret extends Turret{
|
public class CooledTurret extends Turret{
|
||||||
/**How much reload is lowered by for each unit of liquid of heat capacity 1.*/
|
/**How much reload is lowered by for each unit of liquid of heat capacity.*/
|
||||||
protected float coolantMultiplier = 1f;
|
protected float coolantMultiplier = 2f;
|
||||||
/**Max coolant used per tick.*/
|
|
||||||
protected float maxCoolantUsed = 1f;
|
|
||||||
protected Effect coolEffect = Fx.fuelburn;
|
protected Effect coolEffect = Fx.fuelburn;
|
||||||
|
|
||||||
public CooledTurret(String name){
|
public CooledTurret(String name){
|
||||||
@@ -23,17 +25,28 @@ public class CooledTurret extends Turret{
|
|||||||
hasLiquids = true;
|
hasLiquids = true;
|
||||||
liquidCapacity = 20f;
|
liquidCapacity = 20f;
|
||||||
|
|
||||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.01f)).update(false).optional(true);
|
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.5f)).update(false).optional(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStats(){
|
||||||
|
super.setStats();
|
||||||
|
|
||||||
|
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||||
|
|
||||||
|
stats.add(BlockStat.boostEffect, 1f + maxUsed * coolantMultiplier, StatUnit.timesSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateShooting(Tile tile){
|
protected void updateShooting(Tile tile){
|
||||||
super.updateShooting(tile);
|
super.updateShooting(tile);
|
||||||
|
|
||||||
|
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||||
|
|
||||||
TurretEntity entity = tile.entity();
|
TurretEntity entity = tile.entity();
|
||||||
Liquid liquid = entity.liquids.current();
|
Liquid liquid = entity.liquids.current();
|
||||||
|
|
||||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxCoolantUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||||
entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
|
entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
|
||||||
entity.liquids.remove(liquid, used);
|
entity.liquids.remove(liquid, used);
|
||||||
|
|
||||||
@@ -41,9 +54,4 @@ public class CooledTurret extends Turret{
|
|||||||
Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));
|
Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
|
||||||
return super.acceptLiquid(tile, source, liquid, amount) && liquid.temperature <= 0.5f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
package io.anuke.mindustry.world.blocks.defense.turrets;
|
package io.anuke.mindustry.world.blocks.defense.turrets;
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.Effects;
|
|
||||||
import io.anuke.arc.math.Angles;
|
import io.anuke.arc.math.Angles;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||||
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
@@ -60,8 +62,9 @@ public class LaserTurret extends PowerTurret{
|
|||||||
entity.reload = 0f;
|
entity.reload = 0f;
|
||||||
}else{
|
}else{
|
||||||
Liquid liquid = entity.liquids.current();
|
Liquid liquid = entity.liquids.current();
|
||||||
|
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||||
|
|
||||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxCoolantUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||||
entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
|
entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
|
||||||
entity.liquids.remove(liquid, used);
|
entity.liquids.remove(liquid, used);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.defense.turrets;
|
|||||||
|
|
||||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ public abstract class PowerTurret extends CooledTurret{
|
|||||||
public void setStats(){
|
public void setStats(){
|
||||||
super.setStats();
|
super.setStats();
|
||||||
|
|
||||||
stats.add(BlockStat.powerShot, powerUsed * consumes.get(ConsumePower.class).powerCapacity, StatUnit.powerUnits);
|
stats.add(BlockStat.powerShot, powerUsed * consumes.getPower().powerCapacity, StatUnit.powerUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class MassDriver extends Block{
|
|||||||
public void setStats(){
|
public void setStats(){
|
||||||
super.setStats();
|
super.setStats();
|
||||||
|
|
||||||
stats.add(BlockStat.powerShot, consumes.get(ConsumePower.class).powerCapacity * powerPercentageUsed, StatUnit.powerUnits);
|
stats.add(BlockStat.powerShot, consumes.getPower().powerCapacity * powerPercentageUsed, StatUnit.powerUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package io.anuke.mindustry.world.blocks.power;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.type.Item;
|
|
||||||
import io.anuke.mindustry.type.Liquid;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
|
||||||
|
|
||||||
public class DifferentialGenerator extends TurbineGenerator{
|
|
||||||
|
|
||||||
public DifferentialGenerator(String name){
|
|
||||||
super(name);
|
|
||||||
|
|
||||||
hasLiquids = true;
|
|
||||||
consumes.require(ConsumeItem.class);
|
|
||||||
consumes.require(ConsumeLiquid.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
|
||||||
return hasItems && consumes.item() == item && tile.entity.items.total() < itemCapacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
|
||||||
return hasLiquids && consumes.liquid() == liquid && tile.entity.liquids.get(liquid) < liquidCapacity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,8 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
|||||||
import io.anuke.mindustry.graphics.Pal;
|
import io.anuke.mindustry.graphics.Pal;
|
||||||
import io.anuke.mindustry.ui.Bar;
|
import io.anuke.mindustry.ui.Bar;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
@@ -29,7 +30,7 @@ public class ImpactReactor extends PowerGenerator{
|
|||||||
|
|
||||||
protected int plasmas = 4;
|
protected int plasmas = 4;
|
||||||
protected float warmupSpeed = 0.001f;
|
protected float warmupSpeed = 0.001f;
|
||||||
protected float useTime = 60f;
|
protected float itemDuration = 60f;
|
||||||
protected int explosionRadius = 30;
|
protected int explosionRadius = 30;
|
||||||
protected int explosionDamage = 180;
|
protected int explosionDamage = 180;
|
||||||
|
|
||||||
@@ -52,11 +53,20 @@ public class ImpactReactor extends PowerGenerator{
|
|||||||
|
|
||||||
bars.add("poweroutput", entity -> new Bar(() ->
|
bars.add("poweroutput", entity -> new Bar(() ->
|
||||||
Core.bundle.format("blocks.poweroutput",
|
Core.bundle.format("blocks.poweroutput",
|
||||||
Strings.fixed(Math.max(entity.tile.block().getPowerProduction(entity.tile) - consumes.get(ConsumePower.class).powerPerTick, 0)*60 * entity.delta(), 1)),
|
Strings.fixed(Math.max(entity.tile.block().getPowerProduction(entity.tile) - consumes.getPower().powerPerTick, 0)*60 * entity.delta(), 1)),
|
||||||
() -> Pal.powerBar,
|
() -> Pal.powerBar,
|
||||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStats(){
|
||||||
|
super.setStats();
|
||||||
|
|
||||||
|
if(hasItems){
|
||||||
|
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
FusionReactorEntity entity = tile.entity();
|
FusionReactorEntity entity = tile.entity();
|
||||||
@@ -64,8 +74,8 @@ public class ImpactReactor extends PowerGenerator{
|
|||||||
if(entity.cons.valid()){
|
if(entity.cons.valid()){
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||||
|
|
||||||
if(entity.timer.get(timerUse, useTime)){
|
if(entity.timer.get(timerUse, itemDuration)){
|
||||||
entity.items.remove(consumes.item(), consumes.itemAmount());
|
entity.cons.trigger();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
package io.anuke.mindustry.world.blocks.power;
|
package io.anuke.mindustry.world.blocks.power;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.mindustry.entities.Effects;
|
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
|
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||||
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.content;
|
import static io.anuke.mindustry.Vars.content;
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
@@ -44,11 +46,11 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
|||||||
this.hasLiquids = hasLiquids;
|
this.hasLiquids = hasLiquids;
|
||||||
|
|
||||||
if(hasItems){
|
if(hasItems){
|
||||||
consumes.add(new ConsumeItemFilter(item -> getItemEfficiency(item) >= minItemEfficiency)).update(false).optional(true);
|
consumes.add(new ConsumeItemFilter(item -> getItemEfficiency(item) >= minItemEfficiency)).update(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasLiquids){
|
if(hasLiquids){
|
||||||
consumes.add(new ConsumeLiquidFilter(liquid -> getLiquidEfficiency(liquid) >= minLiquidEfficiency, maxLiquidGenerate)).update(false).optional(true);
|
consumes.add(new ConsumeLiquidFilter(liquid -> getLiquidEfficiency(liquid) >= minLiquidEfficiency, maxLiquidGenerate)).update(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +62,15 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStats(){
|
||||||
|
super.setStats();
|
||||||
|
|
||||||
|
if(hasItems){
|
||||||
|
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
ItemLiquidGeneratorEntity entity = tile.entity();
|
ItemLiquidGeneratorEntity entity = tile.entity();
|
||||||
|
|||||||
@@ -12,9 +12,15 @@ import io.anuke.mindustry.entities.Damage;
|
|||||||
import io.anuke.mindustry.entities.Effects;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.graphics.Pal;
|
import io.anuke.mindustry.graphics.Pal;
|
||||||
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.ui.Bar;
|
import io.anuke.mindustry.ui.Bar;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
@@ -29,7 +35,7 @@ public class NuclearReactor extends PowerGenerator{
|
|||||||
|
|
||||||
protected Color coolColor = new Color(1, 1, 1, 0f);
|
protected Color coolColor = new Color(1, 1, 1, 0f);
|
||||||
protected Color hotColor = Color.valueOf("ff9575a3");
|
protected Color hotColor = Color.valueOf("ff9575a3");
|
||||||
protected int fuelUseTime = 120; //time to consume 1 fuel
|
protected int itemDuration = 120; //time to consume 1 fuel
|
||||||
protected float heating = 0.01f; //heating per frame * fullness
|
protected float heating = 0.01f; //heating per frame * fullness
|
||||||
protected float smokeThreshold = 0.3f; //threshold at which block starts smoking
|
protected float smokeThreshold = 0.3f; //threshold at which block starts smoking
|
||||||
protected int explosionRadius = 19;
|
protected int explosionRadius = 19;
|
||||||
@@ -47,6 +53,15 @@ public class NuclearReactor extends PowerGenerator{
|
|||||||
hasLiquids = true;
|
hasLiquids = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStats(){
|
||||||
|
super.setStats();
|
||||||
|
|
||||||
|
if(hasItems){
|
||||||
|
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
super.load();
|
super.load();
|
||||||
@@ -65,20 +80,23 @@ public class NuclearReactor extends PowerGenerator{
|
|||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
NuclearReactorEntity entity = tile.entity();
|
NuclearReactorEntity entity = tile.entity();
|
||||||
|
|
||||||
int fuel = entity.items.get(consumes.item());
|
ConsumeLiquid cliquid = consumes.get(ConsumeType.liquid);
|
||||||
|
Item item = consumes.<ConsumeItems>get(ConsumeType.item).items[0].item;
|
||||||
|
|
||||||
|
int fuel = entity.items.get(item);
|
||||||
float fullness = (float) fuel / itemCapacity;
|
float fullness = (float) fuel / itemCapacity;
|
||||||
entity.productionEfficiency = fullness;
|
entity.productionEfficiency = fullness;
|
||||||
|
|
||||||
if(fuel > 0){
|
if(fuel > 0){
|
||||||
entity.heat += fullness * heating * Math.min(entity.delta(), 4f);
|
entity.heat += fullness * heating * Math.min(entity.delta(), 4f);
|
||||||
|
|
||||||
if(entity.timer.get(timerFuel, fuelUseTime)){
|
if(entity.timer.get(timerFuel, itemDuration)){
|
||||||
entity.cons.trigger();
|
entity.cons.trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Liquid liquid = consumes.liquid();
|
Liquid liquid = cliquid.liquid;
|
||||||
float liquidAmount = consumes.liquidAmount();
|
float liquidAmount = cliquid.amount;
|
||||||
|
|
||||||
if(entity.heat > 0){
|
if(entity.heat > 0){
|
||||||
float maxUsed = Math.min(Math.min(entity.liquids.get(liquid), entity.heat / coolantPower), liquidAmount * entity.delta());
|
float maxUsed = Math.min(Math.min(entity.liquids.get(liquid), entity.heat / coolantPower), liquidAmount * entity.delta());
|
||||||
@@ -109,7 +127,7 @@ public class NuclearReactor extends PowerGenerator{
|
|||||||
|
|
||||||
NuclearReactorEntity entity = tile.entity();
|
NuclearReactorEntity entity = tile.entity();
|
||||||
|
|
||||||
int fuel = entity.items.get(consumes.item());
|
int fuel = entity.items.get(consumes.<ConsumeItems>get(ConsumeType.item).items[0].item);
|
||||||
|
|
||||||
if(fuel < 5 && entity.heat < 0.5f) return;
|
if(fuel < 5 && entity.heat < 0.5f) return;
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class PowerGenerator extends PowerDistributor{
|
|||||||
public void setBars(){
|
public void setBars(){
|
||||||
super.setBars();
|
super.setBars();
|
||||||
|
|
||||||
if(hasPower && outputsPower && !consumes.has(ConsumePower.class)){
|
if(hasPower && outputsPower && !consumes.hasPower()){
|
||||||
bars.add("power", entity -> new Bar(() ->
|
bars.add("power", entity -> new Bar(() ->
|
||||||
Core.bundle.format("blocks.poweroutput",
|
Core.bundle.format("blocks.poweroutput",
|
||||||
Strings.fixed(entity.tile.block().getPowerProduction(entity.tile)*60 * entity.timeScale, 1)),
|
Strings.fixed(entity.tile.block().getPowerProduction(entity.tile)*60 * entity.timeScale, 1)),
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ public class PowerGraph{
|
|||||||
float powerNeeded = 0f;
|
float powerNeeded = 0f;
|
||||||
for(Tile consumer : consumers){
|
for(Tile consumer : consumers){
|
||||||
Consumers consumes = consumer.block().consumes;
|
Consumers consumes = consumer.block().consumes;
|
||||||
if(consumes.has(ConsumePower.class)){
|
if(consumes.hasPower()){
|
||||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
ConsumePower consumePower = consumes.getPower();
|
||||||
if(otherConsumersAreValid(consumer, consumePower)){
|
if(otherConsumersAreValid(consumer, consumePower)){
|
||||||
powerNeeded += consumePower.requestedPower(consumer.block(), consumer.entity) * consumer.entity.delta();
|
powerNeeded += consumePower.requestedPower(consumer.block(), consumer.entity) * consumer.entity.delta();
|
||||||
}
|
}
|
||||||
@@ -68,8 +68,8 @@ public class PowerGraph{
|
|||||||
float totalAccumulator = 0f;
|
float totalAccumulator = 0f;
|
||||||
for(Tile battery : batteries){
|
for(Tile battery : batteries){
|
||||||
Consumers consumes = battery.block().consumes;
|
Consumers consumes = battery.block().consumes;
|
||||||
if(consumes.has(ConsumePower.class)){
|
if(consumes.hasPower()){
|
||||||
totalAccumulator += battery.entity.power.satisfaction * consumes.get(ConsumePower.class).powerCapacity;
|
totalAccumulator += battery.entity.power.satisfaction * consumes.getPower().powerCapacity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return totalAccumulator;
|
return totalAccumulator;
|
||||||
@@ -79,8 +79,8 @@ public class PowerGraph{
|
|||||||
float totalCapacity = 0f;
|
float totalCapacity = 0f;
|
||||||
for(Tile battery : batteries){
|
for(Tile battery : batteries){
|
||||||
Consumers consumes = battery.block().consumes;
|
Consumers consumes = battery.block().consumes;
|
||||||
if(consumes.has(ConsumePower.class)){
|
if(consumes.hasPower()){
|
||||||
totalCapacity += consumes.get(ConsumePower.class).requestedPower(battery.block(), battery.entity) * battery.entity.delta();
|
totalCapacity += consumes.getPower().requestedPower(battery.block(), battery.entity) * battery.entity.delta();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return totalCapacity;
|
return totalCapacity;
|
||||||
@@ -94,8 +94,8 @@ public class PowerGraph{
|
|||||||
float consumedPowerPercentage = Math.min(1.0f, needed / stored);
|
float consumedPowerPercentage = Math.min(1.0f, needed / stored);
|
||||||
for(Tile battery : batteries){
|
for(Tile battery : batteries){
|
||||||
Consumers consumes = battery.block().consumes;
|
Consumers consumes = battery.block().consumes;
|
||||||
if(consumes.has(ConsumePower.class)){
|
if(consumes.hasPower()){
|
||||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
ConsumePower consumePower = consumes.getPower();
|
||||||
if(consumePower.powerCapacity > 0f){
|
if(consumePower.powerCapacity > 0f){
|
||||||
battery.entity.power.satisfaction = Math.max(0.0f, battery.entity.power.satisfaction - consumedPowerPercentage);
|
battery.entity.power.satisfaction = Math.max(0.0f, battery.entity.power.satisfaction - consumedPowerPercentage);
|
||||||
}
|
}
|
||||||
@@ -110,8 +110,8 @@ public class PowerGraph{
|
|||||||
|
|
||||||
for(Tile battery : batteries){
|
for(Tile battery : batteries){
|
||||||
Consumers consumes = battery.block().consumes;
|
Consumers consumes = battery.block().consumes;
|
||||||
if(consumes.has(ConsumePower.class)){
|
if(consumes.hasPower()){
|
||||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
ConsumePower consumePower = consumes.getPower();
|
||||||
if(consumePower.powerCapacity > 0f){
|
if(consumePower.powerCapacity > 0f){
|
||||||
float additionalPowerPercentage = Math.min(1.0f, excess / consumePower.powerCapacity);
|
float additionalPowerPercentage = Math.min(1.0f, excess / consumePower.powerCapacity);
|
||||||
battery.entity.power.satisfaction = Math.min(1.0f, battery.entity.power.satisfaction + additionalPowerPercentage);
|
battery.entity.power.satisfaction = Math.min(1.0f, battery.entity.power.satisfaction + additionalPowerPercentage);
|
||||||
@@ -126,8 +126,8 @@ public class PowerGraph{
|
|||||||
float coverage = Mathf.isZero(needed) ? 1f : Math.min(1, produced / needed);
|
float coverage = Mathf.isZero(needed) ? 1f : Math.min(1, produced / needed);
|
||||||
for(Tile consumer : consumers){
|
for(Tile consumer : consumers){
|
||||||
Consumers consumes = consumer.block().consumes;
|
Consumers consumes = consumer.block().consumes;
|
||||||
if(consumes.has(ConsumePower.class)){
|
if(consumes.hasPower()){
|
||||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
ConsumePower consumePower = consumes.getPower();
|
||||||
//currently satisfies power even if it's not required yet
|
//currently satisfies power even if it's not required yet
|
||||||
if(consumePower.isBuffered){
|
if(consumePower.isBuffered){
|
||||||
if(!Mathf.isZero(consumePower.powerCapacity)){
|
if(!Mathf.isZero(consumePower.powerCapacity)){
|
||||||
@@ -176,7 +176,7 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(Tile tile){
|
public void add(Tile tile){
|
||||||
if(tile.block().consumes.has(ConsumePower.class) && !tile.block().consumes.get(ConsumePower.class).isBuffered){
|
if(tile.block().consumes.hasPower() && !tile.block().consumes.getPower().isBuffered){
|
||||||
//reset satisfaction to zero in case of direct consumer. There is no reason to clear power from buffered consumers.
|
//reset satisfaction to zero in case of direct consumer. There is no reason to clear power from buffered consumers.
|
||||||
tile.entity.power.satisfaction = 0.0f;
|
tile.entity.power.satisfaction = 0.0f;
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ public class PowerGraph{
|
|||||||
tile.entity.power.graph = this;
|
tile.entity.power.graph = this;
|
||||||
all.add(tile);
|
all.add(tile);
|
||||||
|
|
||||||
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.get(ConsumePower.class).isBuffered){
|
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.getPower().isBuffered){
|
||||||
producers.add(tile);
|
producers.add(tile);
|
||||||
consumers.add(tile);
|
consumers.add(tile);
|
||||||
}else if(tile.block().outputsPower && tile.block().consumesPower){
|
}else if(tile.block().outputsPower && tile.block().consumesPower){
|
||||||
@@ -259,7 +259,7 @@ public class PowerGraph{
|
|||||||
|
|
||||||
private boolean otherConsumersAreValid(Tile tile, Consume consumePower){
|
private boolean otherConsumersAreValid(Tile tile, Consume consumePower){
|
||||||
for(Consume cons : tile.block().consumes.all()){
|
for(Consume cons : tile.block().consumes.all()){
|
||||||
if(cons != consumePower && !cons.isOptional() && !cons.valid(tile.block(), tile.entity())){
|
if(cons != consumePower && !cons.isOptional() && !cons.valid(tile.entity())){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package io.anuke.mindustry.world.blocks.power;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.type.Liquid;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
|
||||||
|
|
||||||
public class TurbineGenerator extends BurnerGenerator{
|
|
||||||
|
|
||||||
public TurbineGenerator(String name){
|
|
||||||
super(name);
|
|
||||||
singleLiquid = false;
|
|
||||||
|
|
||||||
consumes.require(ConsumeLiquid.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
|
||||||
return (liquid == consumes.liquid() && tile.entity.liquids.get(consumes.liquid()) < liquidCapacity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,17 +3,16 @@ package io.anuke.mindustry.world.blocks.production;
|
|||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.ObjectIntMap;
|
import io.anuke.arc.collection.ObjectIntMap;
|
||||||
import io.anuke.arc.util.Strings;
|
|
||||||
import io.anuke.mindustry.entities.Effects;
|
|
||||||
import io.anuke.mindustry.entities.Effects.Effect;
|
|
||||||
import io.anuke.arc.graphics.Blending;
|
import io.anuke.arc.graphics.Blending;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
|
import io.anuke.arc.util.Strings;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
import io.anuke.mindustry.content.Liquids;
|
import io.anuke.mindustry.entities.Effects;
|
||||||
|
import io.anuke.mindustry.entities.Effects.Effect;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.graphics.Layer;
|
import io.anuke.mindustry.graphics.Layer;
|
||||||
import io.anuke.mindustry.graphics.Pal;
|
import io.anuke.mindustry.graphics.Pal;
|
||||||
@@ -22,7 +21,6 @@ import io.anuke.mindustry.type.ItemType;
|
|||||||
import io.anuke.mindustry.ui.Bar;
|
import io.anuke.mindustry.ui.Bar;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
|
||||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
@@ -40,8 +38,6 @@ public class Drill extends Block{
|
|||||||
protected int tier;
|
protected int tier;
|
||||||
/**Base time to drill one ore, in frames.*/
|
/**Base time to drill one ore, in frames.*/
|
||||||
protected float drillTime = 300;
|
protected float drillTime = 300;
|
||||||
/**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 boosted by liquid.*/
|
/**How many times faster the drill will progress when boosted by liquid.*/
|
||||||
protected float liquidBoostIntensity = 1.6f;
|
protected float liquidBoostIntensity = 1.6f;
|
||||||
/**Speed at which the drill speeds up.*/
|
/**Speed at which the drill speeds up.*/
|
||||||
@@ -74,8 +70,6 @@ public class Drill extends Block{
|
|||||||
hasLiquids = true;
|
hasLiquids = true;
|
||||||
liquidCapacity = 5f;
|
liquidCapacity = 5f;
|
||||||
hasItems = true;
|
hasItems = true;
|
||||||
|
|
||||||
consumes.liquid(Liquids.water, 0.05f).optional(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -161,6 +155,7 @@ public class Drill extends Block{
|
|||||||
});
|
});
|
||||||
|
|
||||||
stats.add(BlockStat.drillSpeed, 60f / drillTime * size * size, StatUnit.itemsSecond);
|
stats.add(BlockStat.drillSpeed, 60f / drillTime * size * size, StatUnit.itemsSecond);
|
||||||
|
stats.add(BlockStat.boostEffect, liquidBoostIntensity, StatUnit.timesSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -204,9 +199,10 @@ public class Drill extends Block{
|
|||||||
|
|
||||||
float speed = 1f;
|
float speed = 1f;
|
||||||
|
|
||||||
if(entity.consumed(ConsumeLiquid.class) && !liquidRequired){
|
if(entity.cons.optionalValid()){
|
||||||
speed = liquidBoostIntensity;
|
speed = liquidBoostIntensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasPower){
|
if(hasPower){
|
||||||
speed *= entity.power.satisfaction; // Drill slower when not at full power
|
speed *= entity.power.satisfaction; // Drill slower when not at full power
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package io.anuke.mindustry.world.blocks.production;
|
package io.anuke.mindustry.world.blocks.production;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.type.Item;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
public class Fracker extends SolidPump{
|
public class Fracker extends SolidPump{
|
||||||
protected final float itemUseTime = 100f;
|
protected final float itemUseTime = 100f;
|
||||||
@@ -17,9 +18,13 @@ public class Fracker extends SolidPump{
|
|||||||
public Fracker(String name){
|
public Fracker(String name){
|
||||||
super(name);
|
super(name);
|
||||||
hasItems = true;
|
hasItems = true;
|
||||||
singleLiquid = false;
|
}
|
||||||
|
|
||||||
consumes.require(ConsumeItem.class);
|
@Override
|
||||||
|
public void setStats(){
|
||||||
|
super.setStats();
|
||||||
|
|
||||||
|
stats.add(BlockStat.productionTime, itemUseTime / 60f, StatUnit.seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -54,14 +59,13 @@ public class Fracker extends SolidPump{
|
|||||||
@Override
|
@Override
|
||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
FrackerEntity entity = tile.entity();
|
FrackerEntity entity = tile.entity();
|
||||||
Item item = consumes.item();
|
|
||||||
|
|
||||||
while(entity.accumulator >= itemUseTime && entity.items.has(item, 1)){
|
|
||||||
entity.items.remove(item, 1);
|
|
||||||
entity.accumulator -= itemUseTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entity.cons.valid() && entity.accumulator < itemUseTime){
|
if(entity.cons.valid() && entity.accumulator < itemUseTime){
|
||||||
|
if(entity.accumulator >= itemUseTime){
|
||||||
|
entity.cons.trigger();
|
||||||
|
entity.accumulator -= itemUseTime;
|
||||||
|
}
|
||||||
|
|
||||||
super.update(tile);
|
super.update(tile);
|
||||||
entity.accumulator += entity.delta() * entity.power.satisfaction;
|
entity.accumulator += entity.delta() * entity.power.satisfaction;
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.anuke.mindustry.type.ItemStack;
|
|||||||
import io.anuke.mindustry.type.LiquidStack;
|
import io.anuke.mindustry.type.LiquidStack;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
@@ -45,20 +46,20 @@ public class GenericCrafter extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStats(){
|
public void setStats(){
|
||||||
|
if(consumes.has(ConsumeType.liquid)){
|
||||||
|
ConsumeLiquidBase cons = consumes.get(ConsumeType.liquid);
|
||||||
|
cons.timePeriod = craftTime;
|
||||||
|
}
|
||||||
|
|
||||||
super.setStats();
|
super.setStats();
|
||||||
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
|
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
|
||||||
|
|
||||||
if(consumes.has(ConsumeType.liquid)){
|
|
||||||
//TODO replace with per second instead of
|
|
||||||
//stats.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(outputItem != null){
|
if(outputItem != null){
|
||||||
stats.add(BlockStat.output, outputItem);
|
stats.add(BlockStat.output, outputItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(outputLiquid != null){
|
if(outputLiquid != null){
|
||||||
stats.add(BlockStat.output, outputLiquid);
|
stats.add(BlockStat.output, outputLiquid.liquid, outputLiquid.amount, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
package io.anuke.mindustry.world.blocks.production;
|
package io.anuke.mindustry.world.blocks.production;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
|
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.mindustry.graphics.Layer;
|
import io.anuke.mindustry.graphics.Layer;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.LiquidBlock;
|
import io.anuke.mindustry.world.blocks.LiquidBlock;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
|
||||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
|
||||||
|
|
||||||
public class Pump extends LiquidBlock{
|
public class Pump extends LiquidBlock{
|
||||||
protected final Array<Tile> drawTiles = new Array<>();
|
protected final Array<Tile> drawTiles = new Array<>();
|
||||||
@@ -107,11 +106,6 @@ public class Pump extends LiquidBlock{
|
|||||||
tryDumpLiquid(tile, tile.entity.liquids.current());
|
tryDumpLiquid(tile, tile.entity.liquids.current());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
|
||||||
return consumes.has(ConsumeLiquid.class) && consumes.liquid() == liquid && super.acceptLiquid(tile, source, liquid, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isValid(Tile tile){
|
protected boolean isValid(Tile tile){
|
||||||
return tile != null && tile.floor().liquidDrop != null;
|
return tile != null && tile.floor().liquidDrop != null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import io.anuke.mindustry.type.ItemStack;
|
|||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +23,7 @@ public class Separator extends Block{
|
|||||||
protected final int timerDump = timers++;
|
protected final int timerDump = timers++;
|
||||||
|
|
||||||
protected ItemStack[] results;
|
protected ItemStack[] results;
|
||||||
protected float filterTime;
|
protected float craftTime;
|
||||||
protected float spinnerRadius = 2.5f;
|
protected float spinnerRadius = 2.5f;
|
||||||
protected float spinnerLength = 1f;
|
protected float spinnerLength = 1f;
|
||||||
protected float spinnerThickness = 1f;
|
protected float spinnerThickness = 1f;
|
||||||
@@ -41,6 +44,11 @@ public class Separator extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStats(){
|
public void setStats(){
|
||||||
|
if(consumes.has(ConsumeType.liquid)){
|
||||||
|
ConsumeLiquidBase cons = consumes.get(ConsumeType.liquid);
|
||||||
|
cons.timePeriod = craftTime;
|
||||||
|
}
|
||||||
|
|
||||||
super.setStats();
|
super.setStats();
|
||||||
|
|
||||||
stats.add(BlockStat.output, new ItemFilterValue(item -> {
|
stats.add(BlockStat.output, new ItemFilterValue(item -> {
|
||||||
@@ -49,6 +57,9 @@ public class Separator extends Block{
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,7 +85,7 @@ public class Separator extends Block{
|
|||||||
entity.totalProgress += entity.warmup * entity.delta();
|
entity.totalProgress += entity.warmup * entity.delta();
|
||||||
|
|
||||||
if(entity.cons.valid()){
|
if(entity.cons.valid()){
|
||||||
entity.progress += getProgressIncrease(entity, filterTime);
|
entity.progress += getProgressIncrease(entity, craftTime);
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||||
}else{
|
}else{
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f);
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ public class SolidPump extends Pump{
|
|||||||
public void setStats(){
|
public void setStats(){
|
||||||
super.setStats();
|
super.setStats();
|
||||||
|
|
||||||
stats.add(BlockStat.output, result);
|
stats.remove(BlockStat.output);
|
||||||
|
stats.add(BlockStat.output, result, 60f * pumpAmount, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import io.anuke.mindustry.graphics.Shaders;
|
|||||||
import io.anuke.mindustry.type.Mech;
|
import io.anuke.mindustry.type.Mech;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
@@ -45,6 +47,13 @@ public class MechPad extends Block{
|
|||||||
hasPower = true;
|
hasPower = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStats(){
|
||||||
|
super.setStats();
|
||||||
|
|
||||||
|
stats.add(BlockStat.productionTime, buildTime/60f, StatUnit.seconds);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
super.init();
|
super.init();
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ import io.anuke.mindustry.ui.Bar;
|
|||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
import io.anuke.mindustry.world.modules.ItemModule;
|
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
@@ -45,6 +45,7 @@ public class UnitFactory extends Block{
|
|||||||
protected float launchVelocity = 0f;
|
protected float launchVelocity = 0f;
|
||||||
protected TextureRegion topRegion;
|
protected TextureRegion topRegion;
|
||||||
protected int maxSpawn = 2;
|
protected int maxSpawn = 2;
|
||||||
|
protected int[] capacities;
|
||||||
|
|
||||||
public UnitFactory(String name){
|
public UnitFactory(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -53,8 +54,6 @@ public class UnitFactory extends Block{
|
|||||||
hasItems = true;
|
hasItems = true;
|
||||||
solid = false;
|
solid = false;
|
||||||
flags = EnumSet.of(BlockFlag.producer);
|
flags = EnumSet.of(BlockFlag.producer);
|
||||||
|
|
||||||
consumes.require(ConsumeItems.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(called = Loc.server)
|
@Remote(called = Loc.server)
|
||||||
@@ -79,6 +78,19 @@ public class UnitFactory extends Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(){
|
||||||
|
super.init();
|
||||||
|
|
||||||
|
capacities = new int[Vars.content.items().size];
|
||||||
|
if(consumes.has(ConsumeType.item)){
|
||||||
|
ConsumeItems cons = consumes.get(ConsumeType.item);
|
||||||
|
for(ItemStack stack : cons.items){
|
||||||
|
capacities[stack.item.id] = stack.amount*2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(){
|
public void load(){
|
||||||
super.load();
|
super.load();
|
||||||
@@ -102,6 +114,7 @@ public class UnitFactory extends Block{
|
|||||||
public void setStats(){
|
public void setStats(){
|
||||||
super.setStats();
|
super.setStats();
|
||||||
|
|
||||||
|
stats.remove(BlockStat.itemCapacity);
|
||||||
stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds);
|
stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds);
|
||||||
stats.add(BlockStat.maxUnits, maxSpawn, StatUnit.none);
|
stats.add(BlockStat.maxUnits, maxSpawn, StatUnit.none);
|
||||||
}
|
}
|
||||||
@@ -190,24 +203,9 @@ public class UnitFactory extends Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
|
||||||
for(ItemStack stack : consumes.items()){
|
|
||||||
if(item == stack.item && tile.entity.items.get(item) < stack.amount * 2){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaximumAccepted(Tile tile, Item item){
|
public int getMaximumAccepted(Tile tile, Item item){
|
||||||
for(ItemStack stack : consumes.items()){
|
return capacities[item.id];
|
||||||
if(item == stack.item){
|
|
||||||
return stack.amount * 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -222,11 +220,11 @@ public class UnitFactory extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class UnitFactoryEntity extends TileEntity{
|
public static class UnitFactoryEntity extends TileEntity{
|
||||||
public float buildTime;
|
float buildTime;
|
||||||
public float time;
|
float time;
|
||||||
public float speedScl;
|
float speedScl;
|
||||||
public float warmup; //only for enemy spawners
|
float warmup; //only for enemy spawners
|
||||||
public int spawned;
|
int spawned;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(DataOutput stream) throws IOException{
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ package io.anuke.mindustry.world.consumers;
|
|||||||
|
|
||||||
import io.anuke.arc.scene.ui.layout.Table;
|
import io.anuke.arc.scene.ui.layout.Table;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.world.Block;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.meta.BlockStats;
|
import io.anuke.mindustry.world.meta.BlockStats;
|
||||||
|
|
||||||
/**An abstract class that defines a type of resource that a block can consume.*/
|
/**An abstract class that defines a type of resource that a block can consume.*/
|
||||||
public abstract class Consume{
|
public abstract class Consume{
|
||||||
protected boolean optional;
|
protected boolean optional;
|
||||||
protected boolean update = true, boost = false;
|
protected boolean update = true;
|
||||||
|
|
||||||
/**Apply a filter to items accepted.
|
/**Apply a filter to items accepted.
|
||||||
* This should set all item IDs that are present in the filter to true.*/
|
* This should set all item IDs that are present in the filter to true.*/
|
||||||
@@ -33,11 +32,6 @@ public abstract class Consume{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Consume boost(boolean boost){
|
|
||||||
this.boost = boost;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOptional(){
|
public boolean isOptional(){
|
||||||
return optional;
|
return optional;
|
||||||
}
|
}
|
||||||
@@ -51,15 +45,15 @@ public abstract class Consume{
|
|||||||
public abstract void build(Tile tile, Table table);
|
public abstract void build(Tile tile, Table table);
|
||||||
|
|
||||||
/**Called when a consumption is triggered manually.*/
|
/**Called when a consumption is triggered manually.*/
|
||||||
public void trigger(Block block, TileEntity entity){
|
public void trigger(TileEntity entity){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getIcon();
|
public abstract String getIcon();
|
||||||
|
|
||||||
public abstract void update(Block block, TileEntity entity);
|
public abstract void update(TileEntity entity);
|
||||||
|
|
||||||
public abstract boolean valid(Block block, TileEntity entity);
|
public abstract boolean valid(TileEntity entity);
|
||||||
|
|
||||||
public abstract void display(BlockStats stats);
|
public abstract void display(BlockStats stats);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import io.anuke.mindustry.type.Item.Icon;
|
|||||||
import io.anuke.mindustry.ui.ItemImage;
|
import io.anuke.mindustry.ui.ItemImage;
|
||||||
import io.anuke.mindustry.ui.MultiReqImage;
|
import io.anuke.mindustry.ui.MultiReqImage;
|
||||||
import io.anuke.mindustry.ui.ReqImage;
|
import io.anuke.mindustry.ui.ReqImage;
|
||||||
import io.anuke.mindustry.world.Block;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
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;
|
||||||
@@ -18,7 +17,7 @@ import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
|||||||
import static io.anuke.mindustry.Vars.content;
|
import static io.anuke.mindustry.Vars.content;
|
||||||
|
|
||||||
public class ConsumeItemFilter extends Consume{
|
public class ConsumeItemFilter extends Consume{
|
||||||
private final Predicate<Item> filter;
|
public final Predicate<Item> filter;
|
||||||
|
|
||||||
public ConsumeItemFilter(Predicate<Item> item){
|
public ConsumeItemFilter(Predicate<Item> item){
|
||||||
this.filter = item;
|
this.filter = item;
|
||||||
@@ -49,12 +48,12 @@ public class ConsumeItemFilter extends Consume{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Block block, TileEntity entity){
|
public void update(TileEntity entity){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void trigger(Block block, TileEntity entity){
|
public void trigger(TileEntity entity){
|
||||||
for(int i = 0; i < content.items().size; i++){
|
for(int i = 0; i < content.items().size; i++){
|
||||||
Item item = content.item(i);
|
Item item = content.item(i);
|
||||||
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
||||||
@@ -65,7 +64,7 @@ public class ConsumeItemFilter extends Consume{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean valid(Block block, TileEntity entity){
|
public boolean valid(TileEntity entity){
|
||||||
for(int i = 0; i < content.items().size; i++){
|
for(int i = 0; i < content.items().size; i++){
|
||||||
Item item = content.item(i);
|
Item item = content.item(i);
|
||||||
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
||||||
@@ -77,6 +76,6 @@ public class ConsumeItemFilter extends Consume{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(BlockStats stats){
|
public void display(BlockStats stats){
|
||||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new ItemFilterValue(filter));
|
stats.add(optional ? BlockStat.booster : BlockStat.input, new ItemFilterValue(filter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,23 +6,18 @@ import io.anuke.mindustry.type.Item.Icon;
|
|||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.ui.ItemImage;
|
import io.anuke.mindustry.ui.ItemImage;
|
||||||
import io.anuke.mindustry.ui.ReqImage;
|
import io.anuke.mindustry.ui.ReqImage;
|
||||||
import io.anuke.mindustry.world.Block;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
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.values.ItemListValue;
|
import io.anuke.mindustry.world.meta.values.ItemListValue;
|
||||||
|
|
||||||
public class ConsumeItems extends Consume{
|
public class ConsumeItems extends Consume{
|
||||||
private final ItemStack[] items;
|
public final ItemStack[] items;
|
||||||
|
|
||||||
public ConsumeItems(ItemStack[] items){
|
public ConsumeItems(ItemStack[] items){
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getItems(){
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyItemFilter(boolean[] filter){
|
public void applyItemFilter(boolean[] filter){
|
||||||
for(ItemStack stack : items){
|
for(ItemStack stack : items){
|
||||||
@@ -48,24 +43,24 @@ public class ConsumeItems extends Consume{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Block block, TileEntity entity){
|
public void update(TileEntity entity){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void trigger(Block block, TileEntity entity){
|
public void trigger(TileEntity entity){
|
||||||
for(ItemStack stack : items){
|
for(ItemStack stack : items){
|
||||||
entity.items.remove(stack);
|
entity.items.remove(stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean valid(Block block, TileEntity entity){
|
public boolean valid(TileEntity entity){
|
||||||
return entity.items != null && entity.items.has(items);
|
return entity.items != null && entity.items.has(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(BlockStats stats){
|
public void display(BlockStats stats){
|
||||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new ItemListValue(items));
|
stats.add(optional ? BlockStat.booster : BlockStat.input, new ItemListValue(items));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,17 @@ package io.anuke.mindustry.world.consumers;
|
|||||||
import io.anuke.arc.scene.ui.layout.Table;
|
import io.anuke.arc.scene.ui.layout.Table;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.type.LiquidStack;
|
|
||||||
import io.anuke.mindustry.ui.ReqImage;
|
import io.anuke.mindustry.ui.ReqImage;
|
||||||
import io.anuke.mindustry.world.Block;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
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;
|
||||||
|
|
||||||
public class ConsumeLiquid extends Consume{
|
public class ConsumeLiquid extends ConsumeLiquidBase{
|
||||||
protected final float use;
|
public final Liquid liquid;
|
||||||
protected final Liquid liquid;
|
|
||||||
|
|
||||||
public ConsumeLiquid(Liquid liquid, float use){
|
public ConsumeLiquid(Liquid liquid, float amount){
|
||||||
|
super(amount);
|
||||||
this.liquid = liquid;
|
this.liquid = liquid;
|
||||||
this.use = use;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -24,22 +21,9 @@ public class ConsumeLiquid extends Consume{
|
|||||||
filter[liquid.id] = true;
|
filter[liquid.id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float used(){
|
|
||||||
return use;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Liquid get(){
|
|
||||||
return liquid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConsumeType type(){
|
|
||||||
return ConsumeType.liquid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Tile tile, Table table){
|
public void build(Tile tile, Table table){
|
||||||
table.add(new ReqImage(liquid.getContentIcon(), () -> valid(tile.block(), tile.entity))).size(8*4);
|
table.add(new ReqImage(liquid.getContentIcon(), () -> valid(tile.entity))).size(8*4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,22 +32,17 @@ public class ConsumeLiquid extends Consume{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Block block, TileEntity entity){
|
public void update(TileEntity entity){
|
||||||
entity.liquids.remove(liquid, Math.min(use(block, entity), entity.liquids.get(liquid)));
|
entity.liquids.remove(liquid, Math.min(use(entity), entity.liquids.get(liquid)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean valid(Block block, TileEntity entity){
|
public boolean valid(TileEntity entity){
|
||||||
return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(block, entity);
|
return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(BlockStats stats){
|
public void display(BlockStats stats){
|
||||||
//stats.add(BlockStat.liquidUse, use * 60f, StatUnit.liquidSecond);
|
stats.add(optional ? BlockStat.booster : BlockStat.input, liquid, amount * timePeriod, timePeriod == 60);
|
||||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new LiquidStack(liquid, use * 60f));
|
|
||||||
}
|
|
||||||
|
|
||||||
float use(Block block, TileEntity entity){
|
|
||||||
return Math.min(use * entity.delta(), block.liquidCapacity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package io.anuke.mindustry.world.consumers;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
|
|
||||||
|
public abstract class ConsumeLiquidBase extends Consume{
|
||||||
|
/**amount used per frame*/
|
||||||
|
public final float amount;
|
||||||
|
/**How much time is taken to use this liquid, in ticks. Used only for visual purposes.
|
||||||
|
* Example: a normal ConsumeLiquid with 10/s and a 10 second timePeriod would display as "100 seconds".
|
||||||
|
* Without a time override, it would display as "10 liquid/second".
|
||||||
|
* This is used for generic crafters.*/
|
||||||
|
public float timePeriod = 60;
|
||||||
|
|
||||||
|
public ConsumeLiquidBase(float amount){
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsumeType type(){
|
||||||
|
return ConsumeType.liquid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float use(TileEntity entity){
|
||||||
|
return Math.min(amount * entity.delta(), entity.block.liquidCapacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
|||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.ui.MultiReqImage;
|
import io.anuke.mindustry.ui.MultiReqImage;
|
||||||
import io.anuke.mindustry.ui.ReqImage;
|
import io.anuke.mindustry.ui.ReqImage;
|
||||||
import io.anuke.mindustry.world.Block;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
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;
|
||||||
@@ -15,13 +14,12 @@ import io.anuke.mindustry.world.meta.values.LiquidFilterValue;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.content;
|
import static io.anuke.mindustry.Vars.content;
|
||||||
|
|
||||||
public class ConsumeLiquidFilter extends Consume{
|
public class ConsumeLiquidFilter extends ConsumeLiquidBase{
|
||||||
private final Predicate<Liquid> filter;
|
public final Predicate<Liquid> filter;
|
||||||
private final float use;
|
|
||||||
|
|
||||||
public ConsumeLiquidFilter(Predicate<Liquid> liquid, float amount){
|
public ConsumeLiquidFilter(Predicate<Liquid> liquid, float amount){
|
||||||
|
super(amount);
|
||||||
this.filter = liquid;
|
this.filter = liquid;
|
||||||
this.use = amount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -29,16 +27,11 @@ public class ConsumeLiquidFilter extends Consume{
|
|||||||
content.liquids().each(filter, item -> arr[item.id] = true);
|
content.liquids().each(filter, item -> arr[item.id] = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConsumeType type(){
|
|
||||||
return ConsumeType.liquid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Tile tile, Table table){
|
public void build(Tile tile, Table table){
|
||||||
Array<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.test(l));
|
Array<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.test(l));
|
||||||
MultiReqImage image = new MultiReqImage();
|
MultiReqImage image = new MultiReqImage();
|
||||||
list.each(liquid -> image.add(new ReqImage(liquid.getContentIcon(), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.block(), tile.entity))));
|
list.each(liquid -> image.add(new ReqImage(liquid.getContentIcon(), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.entity))));
|
||||||
|
|
||||||
table.add(image).size(8*4);
|
table.add(image).size(8*4);
|
||||||
}
|
}
|
||||||
@@ -49,21 +42,17 @@ public class ConsumeLiquidFilter extends Consume{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Block block, TileEntity entity){
|
public void update(TileEntity entity){
|
||||||
entity.liquids.remove(entity.liquids.current(), use(block, entity));
|
entity.liquids.remove(entity.liquids.current(), use(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean valid(Block block, TileEntity entity){
|
public boolean valid(TileEntity entity){
|
||||||
return entity != null && entity.liquids != null && filter.test(entity.liquids.current()) && entity.liquids.currentAmount() >= use(block, entity);
|
return entity != null && entity.liquids != null && filter.test(entity.liquids.current()) && entity.liquids.currentAmount() >= use(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(BlockStats stats){
|
public void display(BlockStats stats){
|
||||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new LiquidFilterValue(filter, use * 60f));
|
stats.add(optional ? BlockStat.booster : BlockStat.input, new LiquidFilterValue(filter, amount * timePeriod, timePeriod == 60f));
|
||||||
}
|
|
||||||
|
|
||||||
float use(Block block, TileEntity entity){
|
|
||||||
return Math.min(use * entity.delta(), block.liquidCapacity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ public class ConsumePower extends Consume{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Block block, TileEntity entity){
|
public void update(TileEntity entity){
|
||||||
// Nothing to do since PowerGraph directly updates entity.power.satisfaction
|
// Nothing to do since PowerGraph directly updates entity.power.satisfaction
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean valid(Block block, TileEntity entity){
|
public boolean valid(TileEntity entity){
|
||||||
if(isBuffered){
|
if(isBuffered){
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -1,49 +1,37 @@
|
|||||||
package io.anuke.mindustry.world.consumers;
|
package io.anuke.mindustry.world.consumers;
|
||||||
|
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.util.Structs;
|
||||||
import io.anuke.arc.collection.ObjectSet;
|
|
||||||
import io.anuke.arc.util.Log;
|
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.world.Block;
|
|
||||||
import io.anuke.mindustry.world.meta.BlockStats;
|
import io.anuke.mindustry.world.meta.BlockStats;
|
||||||
|
|
||||||
public class Consumers{
|
public class Consumers{
|
||||||
private Consume[] map = new Consume[ConsumeType.values().length];
|
private Consume[] map = new Consume[ConsumeType.values().length];
|
||||||
private ObjectSet<ConsumeType> required = new ObjectSet<>();
|
private Consume[] results, optionalResults;
|
||||||
private Consume[] results;
|
|
||||||
|
|
||||||
public final boolean[] itemFilters = new boolean[Vars.content.items().size];
|
public final boolean[] itemFilters = new boolean[Vars.content.items().size];
|
||||||
public final boolean[] liquidfilters = new boolean[Vars.content.liquids().size];
|
public final boolean[] liquidfilters = new boolean[Vars.content.liquids().size];
|
||||||
|
|
||||||
public void require(ConsumeType type){
|
public void init(){
|
||||||
required.add(type);
|
results = Structs.filter(Consume.class, map, m -> m != null);
|
||||||
}
|
optionalResults = Structs.filter(Consume.class, map, m -> m != null && m.isOptional());
|
||||||
|
|
||||||
public void checkRequired(Block block){
|
for(Consume cons : results){
|
||||||
for(ConsumeType c : required){
|
|
||||||
if(!has(c)){
|
|
||||||
throw new RuntimeException("Missing required consumer of type \"" + c + "\" in block \"" + block.name + "\"!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Array<Consume> array = new Array<>(Consume.class);
|
|
||||||
for(Consume cons : map){
|
|
||||||
if(cons != null){
|
|
||||||
array.add(cons);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
results = array.toArray();
|
|
||||||
|
|
||||||
for(Consume cons : all()){
|
|
||||||
cons.applyItemFilter(itemFilters);
|
cons.applyItemFilter(itemFilters);
|
||||||
cons.applyLiquidFilter(liquidfilters);
|
cons.applyLiquidFilter(liquidfilters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConsumePower getPower(){
|
||||||
|
return get(ConsumeType.power);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPower(){
|
||||||
|
return has(ConsumeType.power);
|
||||||
|
}
|
||||||
|
|
||||||
public ConsumeLiquid liquid(Liquid liquid, float amount){
|
public ConsumeLiquid liquid(Liquid liquid, float amount){
|
||||||
return add(new ConsumeLiquid(liquid, amount));
|
return add(new ConsumeLiquid(liquid, amount));
|
||||||
}
|
}
|
||||||
@@ -88,10 +76,6 @@ public class Consumers{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Consume> T add(T consume){
|
public <T extends Consume> T add(T consume){
|
||||||
if(map[consume.type().ordinal()] != null){
|
|
||||||
Log.warn("[WARN] Conflict: Replacing {0} with {1}", consume, map[consume.type().ordinal()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
map[consume.type().ordinal()] = consume;
|
map[consume.type().ordinal()] = consume;
|
||||||
return consume;
|
return consume;
|
||||||
}
|
}
|
||||||
@@ -116,6 +100,10 @@ public class Consumers{
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Consume[] optionals(){
|
||||||
|
return optionalResults;
|
||||||
|
}
|
||||||
|
|
||||||
public void display(BlockStats stats){
|
public void display(BlockStats stats){
|
||||||
for(Consume c : map){
|
for(Consume c : map){
|
||||||
if(c != null){
|
if(c != null){
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ public enum BlockStat{
|
|||||||
launchTime(StatCategory.items),
|
launchTime(StatCategory.items),
|
||||||
|
|
||||||
liquidCapacity(StatCategory.liquids),
|
liquidCapacity(StatCategory.liquids),
|
||||||
coolant(StatCategory.liquids),
|
|
||||||
coolantUse(StatCategory.liquids),
|
|
||||||
|
|
||||||
powerCapacity(StatCategory.power),
|
powerCapacity(StatCategory.power),
|
||||||
powerUse(StatCategory.power),
|
powerUse(StatCategory.power),
|
||||||
@@ -31,6 +29,7 @@ public enum BlockStat{
|
|||||||
drillSpeed(StatCategory.crafting),
|
drillSpeed(StatCategory.crafting),
|
||||||
maxUnits(StatCategory.crafting),
|
maxUnits(StatCategory.crafting),
|
||||||
|
|
||||||
|
speedIncrease(StatCategory.shooting),
|
||||||
repairTime(StatCategory.shooting),
|
repairTime(StatCategory.shooting),
|
||||||
range(StatCategory.shooting),
|
range(StatCategory.shooting),
|
||||||
shootRange(StatCategory.shooting),
|
shootRange(StatCategory.shooting),
|
||||||
@@ -43,7 +42,7 @@ public enum BlockStat{
|
|||||||
ammo(StatCategory.shooting),
|
ammo(StatCategory.shooting),
|
||||||
|
|
||||||
booster(StatCategory.optional),
|
booster(StatCategory.optional),
|
||||||
|
boostEffect(StatCategory.optional)
|
||||||
;
|
;
|
||||||
|
|
||||||
public final StatCategory category;
|
public final StatCategory category;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import io.anuke.arc.collection.OrderedMap;
|
|||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.type.LiquidStack;
|
|
||||||
import io.anuke.mindustry.world.meta.values.*;
|
import io.anuke.mindustry.world.meta.values.*;
|
||||||
|
|
||||||
/**Hold and organizes a list of block stats.*/
|
/**Hold and organizes a list of block stats.*/
|
||||||
@@ -29,19 +28,14 @@ public class BlockStats{
|
|||||||
add(stat, new ItemListValue(new ItemStack(item, 1)));
|
add(stat, new ItemListValue(new ItemStack(item, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Adds a liquid value.*/
|
|
||||||
public void add(BlockStat stat, Liquid liquid){
|
|
||||||
add(stat, new LiquidValue(liquid));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Adds an item value.*/
|
/**Adds an item value.*/
|
||||||
public void add(BlockStat stat, ItemStack item){
|
public void add(BlockStat stat, ItemStack item){
|
||||||
add(stat, new ItemListValue(item));
|
add(stat, new ItemListValue(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Adds an item value.*/
|
/**Adds an item value.*/
|
||||||
public void add(BlockStat stat, LiquidStack stack){
|
public void add(BlockStat stat, Liquid liquid, float amount, boolean perSecond){
|
||||||
add(stat, new LiquidValue(stack.liquid, stack.amount));
|
add(stat, new LiquidValue(liquid, amount, perSecond));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Adds a single string value with this stat.*/
|
/**Adds a single string value with this stat.*/
|
||||||
|
|||||||
@@ -16,9 +16,23 @@ public enum StatUnit{
|
|||||||
powerUnits,
|
powerUnits,
|
||||||
degrees,
|
degrees,
|
||||||
seconds,
|
seconds,
|
||||||
|
perSecond,
|
||||||
|
timesSpeed(false),
|
||||||
|
timesRadius(false),
|
||||||
|
percent(false),
|
||||||
none,
|
none,
|
||||||
items;
|
items;
|
||||||
|
|
||||||
|
public final boolean space;
|
||||||
|
|
||||||
|
StatUnit(boolean space){
|
||||||
|
this.space = space;
|
||||||
|
}
|
||||||
|
|
||||||
|
StatUnit(){
|
||||||
|
this(true);
|
||||||
|
}
|
||||||
|
|
||||||
public String localized(){
|
public String localized(){
|
||||||
if(this == none) return "";
|
if(this == none) return "";
|
||||||
return Core.bundle.get("unit." + name().toLowerCase(Locale.ROOT));
|
return Core.bundle.get("unit." + name().toLowerCase(Locale.ROOT));
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ import static io.anuke.mindustry.Vars.content;
|
|||||||
public class LiquidFilterValue implements StatValue{
|
public class LiquidFilterValue implements StatValue{
|
||||||
private final Predicate<Liquid> filter;
|
private final Predicate<Liquid> filter;
|
||||||
private final float amount;
|
private final float amount;
|
||||||
|
private final boolean perSecond;
|
||||||
|
|
||||||
public LiquidFilterValue(Predicate<Liquid> filter, float amount){
|
public LiquidFilterValue(Predicate<Liquid> filter, float amount, boolean perSecond){
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
|
this.perSecond = perSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,7 +29,7 @@ public class LiquidFilterValue implements StatValue{
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < list.size; i++){
|
for(int i = 0; i < list.size; i++){
|
||||||
table.add(new LiquidDisplay(list.get(i), amount)).padRight(5);
|
table.add(new LiquidDisplay(list.get(i), amount, perSecond)).padRight(5);
|
||||||
|
|
||||||
if(i != list.size - 1){
|
if(i != list.size - 1){
|
||||||
table.add("/");
|
table.add("/");
|
||||||
|
|||||||
@@ -8,18 +8,16 @@ import io.anuke.mindustry.world.meta.StatValue;
|
|||||||
public class LiquidValue implements StatValue{
|
public class LiquidValue implements StatValue{
|
||||||
private final Liquid liquid;
|
private final Liquid liquid;
|
||||||
private final float amount;
|
private final float amount;
|
||||||
|
private final boolean perSecond;
|
||||||
|
|
||||||
public LiquidValue(Liquid liquid, float amount){
|
public LiquidValue(Liquid liquid, float amount, boolean perSecond){
|
||||||
this.liquid = liquid;
|
this.liquid = liquid;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
this.perSecond = perSecond;
|
||||||
|
|
||||||
public LiquidValue(Liquid liquid){
|
|
||||||
this(liquid, 0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(Table table){
|
public void display(Table table){
|
||||||
table.add(new LiquidDisplay(liquid, amount));
|
table.add(new LiquidDisplay(liquid, amount, perSecond));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,6 @@ public class NumberValue implements StatValue{
|
|||||||
int precision = Math.abs((int) value - value) <= 0.001f ? 0 : Math.abs((int) (value * 10) - value * 10) <= 0.001f ? 1 : 2;
|
int precision = Math.abs((int) value - value) <= 0.001f ? 0 : Math.abs((int) (value * 10) - value * 10) <= 0.001f ? 1 : 2;
|
||||||
|
|
||||||
table.add(Strings.fixed(value, precision));
|
table.add(Strings.fixed(value, precision));
|
||||||
table.add(" " + unit.localized());
|
table.add((unit.space ? " " : "") + unit.localized());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.io.DataOutput;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class ConsumeModule extends BlockModule{
|
public class ConsumeModule extends BlockModule{
|
||||||
private boolean valid;
|
private boolean valid, optionalValid;
|
||||||
private final TileEntity entity;
|
private final TileEntity entity;
|
||||||
|
|
||||||
public ConsumeModule(TileEntity entity){
|
public ConsumeModule(TileEntity entity){
|
||||||
@@ -18,22 +18,31 @@ public class ConsumeModule extends BlockModule{
|
|||||||
public void update(){
|
public void update(){
|
||||||
boolean prevValid = valid();
|
boolean prevValid = valid();
|
||||||
valid = true;
|
valid = true;
|
||||||
|
optionalValid = true;
|
||||||
boolean docons = entity.tile.block().shouldConsume(entity.tile);
|
boolean docons = entity.tile.block().shouldConsume(entity.tile);
|
||||||
|
|
||||||
for(Consume cons : entity.tile.block().consumes.all()){
|
for(Consume cons : entity.tile.block().consumes.all()){
|
||||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity.getTile().block(), entity)){
|
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||||
cons.update(entity.getTile().block(), entity);
|
cons.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!cons.isOptional()){
|
if(!cons.isOptional()){
|
||||||
valid &= cons.valid(entity.getTile().block(), entity);
|
valid &= cons.valid(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(Consume cons : entity.tile.block().consumes.optionals()){
|
||||||
|
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||||
|
cons.update(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
optionalValid &= cons.valid(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trigger(){
|
public void trigger(){
|
||||||
for(Consume cons : entity.tile.block().consumes.all()){
|
for(Consume cons : entity.tile.block().consumes.all()){
|
||||||
cons.trigger(entity.tile.block(), entity);
|
cons.trigger(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +50,10 @@ public class ConsumeModule extends BlockModule{
|
|||||||
return valid && entity.tile.block().canProduce(entity.tile);
|
return valid && entity.tile.block().canProduce(entity.tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean optionalValid(){
|
||||||
|
return valid() && optionalValid;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(DataOutput stream) throws IOException{
|
||||||
stream.writeBoolean(valid);
|
stream.writeBoolean(valid);
|
||||||
|
|||||||
@@ -176,9 +176,9 @@ public class PowerTests extends PowerTestFixture{
|
|||||||
powerGraph.update();
|
powerGraph.update();
|
||||||
|
|
||||||
assertEquals(0.0f, consumerTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR);
|
assertEquals(0.0f, consumerTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR);
|
||||||
if(consumerTile.block().consumes.has(ConsumePower.class)){
|
if(consumerTile.block().consumes.hasPower()){
|
||||||
ConsumePower consumePower = consumerTile.block().consumes.get(ConsumePower.class);
|
ConsumePower consumePower = consumerTile.block().consumes.getPower();
|
||||||
assertFalse(consumePower.valid(consumerTile.block(), consumerTile.entity()));
|
assertFalse(consumePower.valid(consumerTile.entity()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user