The on-going consumer disaster
This commit is contained in:
@@ -303,7 +303,7 @@ public class Block extends UnlockableContent implements Senseable{
|
||||
/** Consumption filters. */
|
||||
public boolean[] itemFilter, liquidFilter;
|
||||
/** Array of consumers used by this block. Only populated after init(). */
|
||||
public Consume[] consumers = {}, optionalConsumers = {};
|
||||
public Consume[] consumers = {}, optionalConsumers = {}, nonOptionalConsumers = {};
|
||||
/** Set to true if this block has any consumers in its array. */
|
||||
public boolean hasConsumers;
|
||||
/** The single power consumer, if applicable. */
|
||||
@@ -1090,7 +1090,8 @@ public class Block extends UnlockableContent implements Senseable{
|
||||
buildCost *= buildCostMultiplier;
|
||||
|
||||
consumers = consumeBuilder.toArray(Consume.class);
|
||||
optionalConsumers = consumeBuilder.filter(consume -> consume.optional).toArray(Consume.class);
|
||||
optionalConsumers = consumeBuilder.select(consume -> consume.optional).toArray(Consume.class);
|
||||
nonOptionalConsumers = consumeBuilder.select(consume -> !consume.optional).toArray(Consume.class);
|
||||
hasConsumers = consumers.length > 0;
|
||||
itemFilter = new boolean[content.items().size];
|
||||
liquidFilter = new boolean[content.liquids().size];
|
||||
|
||||
@@ -187,13 +187,13 @@ public class RegenProjector extends Block{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
drawer.drawBase(this);
|
||||
drawer.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLight(){
|
||||
super.drawLight();
|
||||
drawer.drawLights(this);
|
||||
drawer.drawLight(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public class BaseTurret extends Block{
|
||||
public void init(){
|
||||
//just makes things a little more convenient
|
||||
if(coolant != null){
|
||||
//TODO coolant fix
|
||||
coolant.update = false;
|
||||
coolant.booster = true;
|
||||
coolant.optional = true;
|
||||
|
||||
@@ -315,7 +315,7 @@ public class Turret extends ReloadTurret{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
draw.drawBase(this);
|
||||
draw.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,13 +54,13 @@ public class HeatConductor extends Block{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
drawer.drawBase(this);
|
||||
drawer.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLight(){
|
||||
super.drawLight();
|
||||
drawer.drawLights(this);
|
||||
drawer.drawLight(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.draw.*;
|
||||
|
||||
//TODO deprecate this whole class?
|
||||
public class BurnerGenerator extends ItemLiquidGenerator{
|
||||
|
||||
public BurnerGenerator(String name){
|
||||
super(true, false, name);
|
||||
|
||||
drawer = new DrawMulti(new DrawBlock(), new DrawWarmupRegion(), new DrawTurbines());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getLiquidEfficiency(Liquid liquid){
|
||||
return liquid.flammability;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getItemEfficiency(Item item){
|
||||
return item.flammability;
|
||||
}
|
||||
|
||||
public class BurnerGeneratorBuild extends ItemLiquidGeneratorBuild{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,9 @@ public class ConsumeGenerator extends PowerGenerator{
|
||||
|
||||
public @Nullable LiquidStack liquidOutput;
|
||||
|
||||
public @Nullable ConsumeItemFilter filterItem;
|
||||
public @Nullable ConsumeLiquidFilter filterLiquid;
|
||||
|
||||
public ConsumeGenerator(String name){
|
||||
super(name);
|
||||
}
|
||||
@@ -37,10 +41,15 @@ public class ConsumeGenerator extends PowerGenerator{
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
filterItem = findConsumer(c -> c instanceof ConsumeItemFilter);
|
||||
filterLiquid = findConsumer(c -> c instanceof ConsumeLiquidFilter);
|
||||
|
||||
if(liquidOutput != null){
|
||||
outputsLiquid = true;
|
||||
hasLiquids = true;
|
||||
}
|
||||
|
||||
//TODO hardcoded
|
||||
emitLight = true;
|
||||
lightRadius = 65f * size;
|
||||
super.init();
|
||||
@@ -61,6 +70,7 @@ public class ConsumeGenerator extends PowerGenerator{
|
||||
|
||||
public class ConsumeGeneratorBuild extends GeneratorBuild{
|
||||
public float warmup, totalTime;
|
||||
public float itemMultiplier = 1f;
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
@@ -68,7 +78,17 @@ public class ConsumeGenerator extends PowerGenerator{
|
||||
|
||||
warmup = Mathf.lerpDelta(warmup, enabled && valid ? 1f : 0f, 0.05f);
|
||||
|
||||
productionEfficiency = valid ? 1f : 0f;
|
||||
float multiplier = 1f;
|
||||
if(valid){
|
||||
if(filterItem != null && filterItem.getConsumed(this) != null){
|
||||
itemMultiplier = filterItem.getEfficiency(this);
|
||||
}
|
||||
|
||||
//efficiency is added together
|
||||
multiplier *= itemMultiplier + (filterLiquid == null ? 0f : filterLiquid.getEfficiency(this));
|
||||
}
|
||||
|
||||
productionEfficiency = (valid ? 1f : 0f) * multiplier;
|
||||
totalTime += warmup * Time.delta;
|
||||
|
||||
//randomly produce the effect
|
||||
@@ -93,10 +113,6 @@ public class ConsumeGenerator extends PowerGenerator{
|
||||
generateTime -= Math.min(1f / itemDuration * delta(), generateTime);
|
||||
}
|
||||
|
||||
public float getEfficiencyMultiplier(){
|
||||
return 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean consumeTriggerValid(){
|
||||
return generateTime > 0;
|
||||
@@ -114,7 +130,9 @@ public class ConsumeGenerator extends PowerGenerator{
|
||||
|
||||
@Override
|
||||
public void drawLight(){
|
||||
//TODO
|
||||
//???
|
||||
drawer.drawLight(this);
|
||||
//TODO hard coded
|
||||
Drawf.light(team, x, y, (60f + Mathf.absin(10f, 5f)) * size, Color.orange, 0.5f * warmup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class DecayGenerator extends ItemLiquidGenerator{
|
||||
|
||||
public DecayGenerator(String name){
|
||||
super(true, false, name);
|
||||
hasItems = true;
|
||||
hasLiquids = false;
|
||||
envEnabled = Env.any;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getItemEfficiency(Item item){
|
||||
return item.radioactivity;
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.draw.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
/**
|
||||
* Power generation block which can use items, liquids or both as input sources for power production.
|
||||
* Liquids will take priority over items.
|
||||
*/
|
||||
//TODO remove
|
||||
@Deprecated
|
||||
public class ItemLiquidGenerator extends PowerGenerator{
|
||||
public float minItemEfficiency = 0.2f;
|
||||
/** The time in number of ticks during which a single item will produce power. */
|
||||
public float itemDuration = 70f;
|
||||
|
||||
/** Minimum liquid efficiency for a generator to accept it. */
|
||||
public float minLiquidEfficiency = 0.2f;
|
||||
/** Maximum liquid used per frame. */
|
||||
public float maxLiquidGenerate = 0.4f;
|
||||
|
||||
public Effect generateEffect = Fx.generatespark;
|
||||
public float generateEffectRnd = 3f;
|
||||
public Effect explodeEffect = Fx.generatespark;
|
||||
public boolean randomlyExplode = true;
|
||||
public boolean defaults = false;
|
||||
|
||||
public ItemLiquidGenerator(boolean hasItems, boolean hasLiquids, String name){
|
||||
this(name);
|
||||
this.hasItems = hasItems;
|
||||
this.hasLiquids = hasLiquids;
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
public ItemLiquidGenerator(String name){
|
||||
super(name);
|
||||
|
||||
drawer = new DrawMulti(new DrawBlock(), new DrawWarmupRegion());
|
||||
}
|
||||
|
||||
protected void setDefaults(){
|
||||
if(hasItems){
|
||||
consume(new ConsumeItemFilter(item -> getItemEfficiency(item) >= minItemEfficiency)).update(false).optional(true, false);
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
consume(new ConsumeLiquidFilter(liquid -> getLiquidEfficiency(liquid) >= minLiquidEfficiency, maxLiquidGenerate)).update(false).optional(true, false);
|
||||
}
|
||||
|
||||
defaults = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
emitLight = true;
|
||||
lightRadius = 65f * size;
|
||||
if(!defaults){
|
||||
setDefaults();
|
||||
}
|
||||
super.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(hasItems){
|
||||
stats.add(Stat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||
}
|
||||
}
|
||||
|
||||
protected float getItemEfficiency(Item item){
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
protected float getLiquidEfficiency(Liquid liquid){
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public class ItemLiquidGeneratorBuild extends GeneratorBuild{
|
||||
protected Boolf<Liquid> liquidFilter = other -> liquids.get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency;
|
||||
|
||||
public float explosiveness, heat, totalTime;
|
||||
|
||||
@Override
|
||||
public boolean productionValid(){
|
||||
return generateTime > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
//Note: Do not use this delta when calculating the amount of power or the power efficiency, but use it for resource consumption if necessary.
|
||||
//Power amount is delta'd by PowerGraph class already.
|
||||
float calculationDelta = delta();
|
||||
boolean cons = consValid();
|
||||
|
||||
heat = Mathf.lerpDelta(heat, generateTime >= 0.001f && enabled && cons ? 1f : 0f, 0.05f);
|
||||
|
||||
if(!cons){
|
||||
productionEfficiency = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
Liquid liquid = hasLiquids ? content.liquids().find(liquidFilter) : null;
|
||||
totalTime += heat * Time.delta;
|
||||
|
||||
//liquid takes priority over solids
|
||||
//TODO several issues with this! - it does not work correctly, consumption should not be handled here, why am I re-implementing consumes
|
||||
//TODO what an awful class
|
||||
if(hasLiquids && liquid != null && liquids.get(liquid) >= 0.001f){
|
||||
float baseLiquidEfficiency = getLiquidEfficiency(liquid);
|
||||
float maximumPossible = maxLiquidGenerate * calculationDelta;
|
||||
float used = Math.min(liquids.get(liquid) * calculationDelta, maximumPossible);
|
||||
|
||||
liquids.remove(liquid, used);
|
||||
productionEfficiency = baseLiquidEfficiency * used / maximumPossible;
|
||||
|
||||
//TODO this aggressively spams the generate effect why would anyone want this why is this here
|
||||
if(used > 0.001f && (generateTime -= delta()) <= 0f){
|
||||
generateEffect.at(x + Mathf.range(generateEffectRnd), y + Mathf.range(generateEffectRnd));
|
||||
generateTime = 1f;
|
||||
}
|
||||
}else if(hasItems){
|
||||
// No liquids accepted or none supplied, try using items if accepted
|
||||
if(generateTime <= 0f && items.total() > 0){
|
||||
generateEffect.at(x + Mathf.range(generateEffectRnd), y + Mathf.range(generateEffectRnd));
|
||||
Item item = items.take();
|
||||
productionEfficiency = getItemEfficiency(item);
|
||||
explosiveness = item.explosiveness;
|
||||
generateTime = 1f;
|
||||
}
|
||||
|
||||
if(generateTime > 0f){
|
||||
generateTime -= Math.min(1f / itemDuration * delta(), generateTime);
|
||||
|
||||
if(randomlyExplode && state.rules.reactorExplosions && Mathf.chance(delta() * 0.06 * Mathf.clamp(explosiveness - 0.5f))){
|
||||
//this block is run last so that in the event of a block destruction, no code relies on the block type
|
||||
damage(Mathf.random(11f));
|
||||
explodeEffect.at(x + Mathf.range(size * tilesize / 2f), y + Mathf.range(size * tilesize / 2f));
|
||||
}
|
||||
}else{
|
||||
productionEfficiency = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float warmup(){
|
||||
return heat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float totalProgress(){
|
||||
return totalTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLight(){
|
||||
Drawf.light(team, x, y, (60f + Mathf.absin(10f, 5f)) * size, Color.orange, 0.5f * heat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,13 +73,13 @@ public class PowerGenerator extends PowerDistributor{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
drawer.drawBase(this);
|
||||
drawer.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLight(){
|
||||
super.drawLight();
|
||||
drawer.drawLights(this);
|
||||
drawer.drawLight(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,8 +31,8 @@ public class GenericCrafter extends Block{
|
||||
/** if true, crafters with multiple liquid outputs will dump excess when there's still space for at least one liquid type */
|
||||
public boolean dumpExtraLiquid = true;
|
||||
public boolean ignoreLiquidFullness = false;
|
||||
/** if true, liquid will be outputted continuously regardless of craft time */
|
||||
public boolean continuousLiquidOutput = false;
|
||||
|
||||
//TODO should be seconds?
|
||||
public float craftTime = 80;
|
||||
public Effect craftEffect = Fx.none;
|
||||
public Effect updateEffect = Fx.none;
|
||||
@@ -66,7 +66,7 @@ public class GenericCrafter extends Block{
|
||||
}
|
||||
|
||||
if(outputLiquids != null){
|
||||
stats.add(Stat.output, StatValues.liquids(continuousLiquidOutput ? 1f : craftTime, outputLiquids));
|
||||
stats.add(Stat.output, StatValues.liquids(1f, outputLiquids));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,13 +145,13 @@ public class GenericCrafter extends Block{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
drawer.drawBase(this);
|
||||
drawer.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLight(){
|
||||
super.drawLight();
|
||||
drawer.drawLights(this);
|
||||
drawer.drawLight(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,7 +193,7 @@ public class GenericCrafter extends Block{
|
||||
warmup = Mathf.approachDelta(warmup, warmupTarget(), warmupSpeed);
|
||||
|
||||
//continuously output based on efficiency
|
||||
if(outputLiquids != null && continuousLiquidOutput){
|
||||
if(outputLiquids != null){
|
||||
float inc = getProgressIncrease(1f);
|
||||
for(var output : outputLiquids){
|
||||
handleLiquid(this, output.liquid, Math.min(output.amount * inc, liquidCapacity - liquids.get(output.liquid)));
|
||||
@@ -242,12 +242,6 @@ public class GenericCrafter extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
if(outputLiquids != null && !continuousLiquidOutput){
|
||||
for(var output : outputLiquids){
|
||||
handleLiquid(this, output.liquid, output.amount);
|
||||
}
|
||||
}
|
||||
|
||||
craftEffect.at(x, y);
|
||||
progress %= 1f;
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package mindustry.world.blocks.production;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class LiquidConverter extends GenericCrafter{
|
||||
protected @Nullable ConsumeLiquid consumer;
|
||||
|
||||
public LiquidConverter(String name){
|
||||
super(name);
|
||||
hasLiquids = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputsItems(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
consumer = findConsumer(b -> b instanceof ConsumeLiquid);
|
||||
if(consumer == null) throw new RuntimeException("LiquidConverters must have a ConsumeLiquid.");
|
||||
consumer.update = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.remove(Stat.output);
|
||||
stats.add(Stat.output, outputLiquid.liquid, outputLiquid.amount * 60f, true);
|
||||
}
|
||||
|
||||
public class LiquidConverterBuild extends GenericCrafterBuild{
|
||||
@Override
|
||||
public void drawLight(){
|
||||
if(hasLiquids && drawLiquidLight && outputLiquid.liquid.lightColor.a > 0.001f){
|
||||
drawLiquidLight(outputLiquid.liquid, liquids.get(outputLiquid.liquid));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(consValid()){
|
||||
if(Mathf.chanceDelta(updateEffectChance)){
|
||||
updateEffect.at(x + Mathf.range(size * 4f), y + Mathf.range(size * 4));
|
||||
}
|
||||
|
||||
warmup = Mathf.lerpDelta(warmup, 1f, 0.02f);
|
||||
float use = Math.min(consumer.amount * edelta(), liquidCapacity - liquids.get(outputLiquid.liquid));
|
||||
float ratio = outputLiquid.amount / consumer.amount;
|
||||
|
||||
liquids.remove(consumer.liquid, Math.min(use, liquids.get(consumer.liquid)));
|
||||
|
||||
progress += use / consumer.amount;
|
||||
liquids.add(outputLiquid.liquid, use * ratio);
|
||||
if(progress >= craftTime){
|
||||
consume();
|
||||
progress %= craftTime;
|
||||
}
|
||||
}else{
|
||||
//warmup is still 1 even if not consuming
|
||||
warmup = Mathf.lerp(warmup, canConsume() ? 1f : 0f, 0.02f);
|
||||
}
|
||||
|
||||
dumpLiquid(outputLiquid.liquid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,13 +110,13 @@ public class Pump extends LiquidBlock{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
draw.drawBase(this);
|
||||
draw.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLight(){
|
||||
super.drawLight();
|
||||
draw.drawLights(this);
|
||||
draw.drawLight(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,11 +7,14 @@ import mindustry.world.meta.*;
|
||||
|
||||
/** An abstract class that defines a type of resource that a block can consume. */
|
||||
public abstract class Consume{
|
||||
|
||||
//TODO maybe remove these and make it an interface if possible?
|
||||
/** If true, this consumer will not influence consumer validity. */
|
||||
public boolean optional;
|
||||
/** If true, this consumer will be displayed as a boost input. */
|
||||
public boolean booster;
|
||||
//TODO bad. I don't like it.
|
||||
@Deprecated
|
||||
public boolean update = true;
|
||||
|
||||
/**
|
||||
@@ -31,6 +34,7 @@ public abstract class Consume{
|
||||
return optional(true, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Consume update(boolean update){
|
||||
this.update = update;
|
||||
return this;
|
||||
|
||||
21
core/src/mindustry/world/consumers/ConsumeItemCharged.java
Normal file
21
core/src/mindustry/world/consumers/ConsumeItemCharged.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package mindustry.world.consumers;
|
||||
|
||||
import mindustry.gen.*;
|
||||
|
||||
/** For mods. I don't use this (yet). */
|
||||
public class ConsumeItemCharged extends ConsumeItemFilter{
|
||||
|
||||
public ConsumeItemCharged(float minCharge){
|
||||
super(item -> item.charge >= minCharge);
|
||||
}
|
||||
|
||||
public ConsumeItemCharged(){
|
||||
this(0.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEfficiency(Building build){
|
||||
var item = getConsumed(build);
|
||||
return item == null ? 0f : item.charge;
|
||||
}
|
||||
}
|
||||
64
core/src/mindustry/world/consumers/ConsumeItemExplode.java
Normal file
64
core/src/mindustry/world/consumers/ConsumeItemExplode.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package mindustry.world.consumers;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
/** Causes a block to explode when explosive items are moved into it. */
|
||||
public class ConsumeItemExplode extends ConsumeItemFilter{
|
||||
public float damage = 4f;
|
||||
public float threshold, baseChance = 0.06f;
|
||||
public Effect explodeEffect = Fx.generatespark;
|
||||
|
||||
public ConsumeItemExplode(float threshold){
|
||||
super(item -> item.explosiveness >= threshold);
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
public ConsumeItemExplode(){
|
||||
this(0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Building build){
|
||||
var item = getConsumed(build);
|
||||
|
||||
if(item != null){
|
||||
if(Vars.state.rules.reactorExplosions && Mathf.chance(build.delta() * baseChance * Mathf.clamp(item.explosiveness - threshold))){
|
||||
build.damage(damage);
|
||||
explodeEffect.at(build.x + Mathf.range(build.block.size * tilesize / 2f), build.y + Mathf.range(build.block.size * tilesize / 2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//as this consumer doesn't actually consume anything, all methods below are empty
|
||||
|
||||
@Override
|
||||
public void build(Building build, Table table){}
|
||||
|
||||
@Override
|
||||
public void trigger(Building build){}
|
||||
|
||||
@Override
|
||||
public void display(Stats stats){}
|
||||
|
||||
@Override
|
||||
public void apply(Block block){}
|
||||
|
||||
@Override
|
||||
public float getEfficiency(Building build){
|
||||
return 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Building build){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,11 @@ public class ConsumeItemFilter extends Consume{
|
||||
}
|
||||
}
|
||||
|
||||
/** @return efficiency multiplier based on current item to be consumed; overridden in subclasses. Returns 0 if not valid in subclasses. */
|
||||
public float getEfficiency(Building build){
|
||||
return 1f;
|
||||
}
|
||||
|
||||
public @Nullable Item getConsumed(Building build){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
|
||||
20
core/src/mindustry/world/consumers/ConsumeItemFlammable.java
Normal file
20
core/src/mindustry/world/consumers/ConsumeItemFlammable.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package mindustry.world.consumers;
|
||||
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class ConsumeItemFlammable extends ConsumeItemFilter{
|
||||
|
||||
public ConsumeItemFlammable(float minFlammability){
|
||||
super(item -> item.flammability >= minFlammability);
|
||||
}
|
||||
|
||||
public ConsumeItemFlammable(){
|
||||
this(0.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEfficiency(Building build){
|
||||
var item = getConsumed(build);
|
||||
return item == null ? 0f : item.flammability;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package mindustry.world.consumers;
|
||||
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class ConsumeItemRadioactive extends ConsumeItemFilter{
|
||||
|
||||
public ConsumeItemRadioactive(float minRadioactivity){
|
||||
super(item -> item.radioactivity >= minRadioactivity);
|
||||
}
|
||||
|
||||
public ConsumeItemRadioactive(){
|
||||
this(0.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEfficiency(Building build){
|
||||
var item = getConsumed(build);
|
||||
return item == null ? 0f : item.radioactivity;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,11 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{
|
||||
var liq = getConsumed(build);
|
||||
return liq != null && build.liquids.get(liq) >= use(build);
|
||||
}
|
||||
|
||||
/** @return efficiency multiplier based on current item to be consumed; overridden in subclasses. Returns 0 if not valid in subclasses. */
|
||||
public float getEfficiency(Building build){
|
||||
return 1f;
|
||||
}
|
||||
|
||||
public @Nullable Liquid getConsumed(Building build){
|
||||
float u = use(build);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package mindustry.world.consumers;
|
||||
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class ConsumeLiquidFlammable extends ConsumeLiquidFilter{
|
||||
|
||||
public ConsumeLiquidFlammable(float minFlammability, float amount){
|
||||
super(item -> item.flammability >= minFlammability, amount);
|
||||
}
|
||||
|
||||
public ConsumeLiquidFlammable(float amount){
|
||||
this(0.2f, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEfficiency(Building build){
|
||||
var item = getConsumed(build);
|
||||
return item == null ? 0f : item.flammability;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class DrawAnimation extends DrawBlock{
|
||||
public TextureRegion liquid, top;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y);
|
||||
Draw.rect(
|
||||
sine ?
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DrawArcSmelter extends DrawBlock{
|
||||
public Blending blending = Blending.additive;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
if(drawBottom) Draw.rect(bottom, build.x, build.y);
|
||||
|
||||
if(build.warmup() > 0f && flameColor.a > 0.001f){
|
||||
|
||||
@@ -23,12 +23,12 @@ public class DrawBlock{
|
||||
}
|
||||
|
||||
/** Draws the block itself. */
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y, build.drawrot());
|
||||
}
|
||||
|
||||
/** Draws any extra light for the block. */
|
||||
public void drawLights(Building build){
|
||||
public void drawLight(Building build){
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DrawBlurSpin extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Drawf.spinSprite(build.warmup() > blurThresh ? blurRegion : region, build.x + x, build.y + y, build.totalProgress() * rotateSpeed);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class DrawBubbles extends DrawPartial{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
if(build.warmup() <= 0.001f) return;
|
||||
|
||||
Draw.color(color);
|
||||
|
||||
@@ -16,7 +16,7 @@ public class DrawCells extends DrawBlock{
|
||||
public float range = 4f, recurrence = 6f, radius = 3f, lifetime = 60f;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
|
||||
Draw.rect(bottom, build.x, build.y);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DrawCircles extends DrawPartial{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
if(build.warmup() <= 0.001f) return;
|
||||
|
||||
Draw.color(color, build.warmup() * color.a);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class DrawCrucibleFlame extends DrawPartial{
|
||||
public Interp particleInterp = new PowIn(1.5f);
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
|
||||
if(build.warmup() > 0f && flameColor.a > 0.001f){
|
||||
Lines.stroke(circleStroke * build.warmup());
|
||||
|
||||
@@ -21,7 +21,7 @@ public class DrawCultivator extends DrawBlock{
|
||||
public TextureRegion top;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y);
|
||||
|
||||
Drawf.liquid(middle, build.x, build.y, build.warmup(), plantColor);
|
||||
|
||||
@@ -12,7 +12,7 @@ public class DrawGlow extends DrawBlock{
|
||||
public TextureRegion top;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y);
|
||||
Draw.alpha(Mathf.absin(build.totalProgress(), glowScale, glowAmount) * build.warmup());
|
||||
Draw.rect(top, build.x, build.y);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class DrawGlowRegion extends DrawPartial{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
if(build.warmup() <= 0.001f) return;
|
||||
|
||||
float z = Draw.z();
|
||||
|
||||
@@ -31,7 +31,7 @@ public class DrawHeatInput extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
|
||||
Draw.z(Layer.blockAdditive);
|
||||
if(build instanceof HeatConsumer hc){
|
||||
|
||||
@@ -26,7 +26,7 @@ public class DrawHeatOutput extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
if(drawRegion) Draw.rect(build.block.region, build.x, build.y);
|
||||
|
||||
Draw.rect(build.rotation > 1 ? top2 : top1, build.x, build.y, build.rotdeg());
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DrawHeatRegion extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
|
||||
Draw.z(Layer.blockAdditive);
|
||||
if(build instanceof HeatCrafterBuild hc && hc.heat > 0){
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DrawLiquid extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y);
|
||||
GenericCrafter type = (GenericCrafter)build.block;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class DrawLiquidOutputs extends DrawBlock{
|
||||
public TextureRegion[][] liquidOutputRegions;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
GenericCrafter crafter = (GenericCrafter)build.block;
|
||||
if(crafter.outputLiquids == null) return;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DrawLiquidRegion extends DrawPartial{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
if(!build.block.hasLiquids) return;
|
||||
|
||||
Liquid drawn = drawLiquid != null ? drawLiquid : build.liquids.current();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DrawLiquidTile extends DrawPartial{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Liquid drawn = drawLiquid != null ? drawLiquid : build.liquids.current();
|
||||
LiquidBlock.drawTiledFrames(build.block.size, build.x, build.y, padding, drawn, build.liquids.get(drawn) / build.block.liquidCapacity * alpha);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DrawMixer extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
GenericCrafter crafter = (GenericCrafter)build.block;
|
||||
float rotation = build.block.rotate ? build.rotdeg() : 0;
|
||||
Draw.rect(bottom, build.x, build.y, rotation);
|
||||
|
||||
@@ -32,9 +32,9 @@ public class DrawMulti extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
for(var draw : drawers){
|
||||
draw.drawBase(build);
|
||||
draw.draw(build);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ public class DrawMulti extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLights(Building build){
|
||||
public void drawLight(Building build){
|
||||
for(var draw : drawers){
|
||||
draw.drawLights(build);
|
||||
draw.drawLight(build);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class DrawMultiWeave extends DrawBlock{
|
||||
public float pulse = 0.3f, pulseScl = 10f;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(weave, build.x, build.y, build.totalProgress() * rotateSpeed);
|
||||
Draw.rect(weave, build.x, build.y, build.totalProgress() * rotateSpeed * rotateSpeed2);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class DrawParticles extends DrawBlock{
|
||||
public Blending blending = Blending.normal;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
|
||||
if(build.warmup() > 0f){
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DrawPistons extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
for(int i = 0; i < sides; i++){
|
||||
float len = Mathf.absin(build.totalProgress() + sinOffset + sideOffset * sinScl * i, sinScl, sinMag) + lenOffset;
|
||||
float angle = i * 360f / sides;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DrawPulseShape extends DrawPartial{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
float pz = Draw.z();
|
||||
if(layer > 0) Draw.z(layer);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public class DrawPump extends DrawBlock{
|
||||
public TextureRegion liquid;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y);
|
||||
|
||||
if(!(build instanceof PumpBuild pump) || pump.liquidDrop == null) return;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class DrawRegion extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
float z = Draw.z();
|
||||
if(layer > 0) Draw.z(layer);
|
||||
if(spinSprite){
|
||||
|
||||
@@ -20,7 +20,7 @@ public class DrawRotator extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y);
|
||||
if(drawSpinSprite){
|
||||
Drawf.spinSprite(rotator, build.x, build.y, build.totalProgress() * spinSpeed);
|
||||
|
||||
@@ -12,7 +12,7 @@ public class DrawShape extends DrawPartial{
|
||||
public boolean useWarmupRadius = false;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
float pz = Draw.z();
|
||||
if(layer > 0) Draw.z(layer);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DrawSideRegion extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
if(drawRegion) Draw.rect(build.block.region, build.x, build.y);
|
||||
|
||||
Draw.rect(build.rotation > 1 ? top2 : top1, build.x, build.y, build.rotdeg());
|
||||
|
||||
@@ -29,7 +29,7 @@ public class DrawSmelter extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y, build.block.rotate ? build.rotdeg() : 0);
|
||||
|
||||
if(build.warmup() > 0f && flameColor.a > 0.001f){
|
||||
@@ -54,7 +54,7 @@ public class DrawSmelter extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLights(Building build){
|
||||
public void drawLight(Building build){
|
||||
Drawf.light(build.team, build.x, build.y, (lightRadius + Mathf.absin(lightSinScl, lightSinMag)) * build.warmup() * build.block.size, flameColor, lightAlpha);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DrawSpikes extends DrawPartial{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
if(build.warmup() <= 0.001f) return;
|
||||
|
||||
Draw.color(color, build.warmup() * color.a);
|
||||
|
||||
@@ -18,9 +18,7 @@ public class DrawTurbines extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
if(!turbines[0].found()) return;
|
||||
|
||||
public void draw(Building build){
|
||||
float totalTime = build.totalProgress();
|
||||
Draw.rect(turbines[0], build.x, build.y, totalTime * turbineSpeed);
|
||||
Draw.rect(turbines[1], build.x, build.y, -totalTime * turbineSpeed);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class DrawTurret extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Turret turret = (Turret)build.block;
|
||||
TurretBuild tb = (TurretBuild)build;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class DrawWarmupRegion extends DrawBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.color(color);
|
||||
Draw.alpha(build.warmup() * (1f - sinMag) + Mathf.absin(Time.time, sinScl, sinMag) * build.warmup());
|
||||
Draw.rect(region, build.x, build.y);
|
||||
|
||||
@@ -12,7 +12,7 @@ public class DrawWeave extends DrawBlock{
|
||||
public TextureRegion weave, bottom;
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
public void draw(Building build){
|
||||
Draw.rect(bottom, build.x, build.y);
|
||||
Draw.rect(weave, build.x, build.y, build.totalProgress());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user