Pyrolysis generator + generation tweaks

This commit is contained in:
Anuken
2021-12-02 17:00:49 -05:00
parent fff492d89d
commit 4e181d715f
17 changed files with 183 additions and 31 deletions

View File

@@ -0,0 +1,112 @@
package mindustry.world.blocks.power;
import arc.graphics.*;
import arc.math.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.meta.*;
/**
* A generator that just takes in certain items or liquids. Basically SingleTypeGenerator, but not unreliable garbage.
* TODO at the moment, these generators require at least one item in their inventory to work, meaning they cannot be "kickstarted" with only one item.
*/
public class ConsumeGenerator extends PowerGenerator{
/** The time in number of ticks during which a single item will produce power. */
public float itemDuration = 120f;
public float effectChance = 0.01f;
public Effect generateEffect = Fx.none;
public float generateEffectRange = 3f;
public @Nullable LiquidStack liquidOutput;
public ConsumeGenerator(String name){
super(name);
}
@Override
public void setBars(){
super.setBars();
if(liquidOutput != null){
addLiquidBar(liquidOutput.liquid);
}
}
@Override
public void init(){
if(liquidOutput != null){
outputsLiquid = true;
hasLiquids = true;
}
emitLight = true;
lightRadius = 65f * size;
super.init();
}
@Override
public void setStats(){
super.setStats();
if(hasItems){
stats.add(Stat.productionTime, itemDuration / 60f, StatUnit.seconds);
}
if(liquidOutput != null){
stats.add(Stat.output, StatValues.liquid(liquidOutput.liquid, liquidOutput.amount * 60f, true));
}
}
public class ConsumeGeneratorBuild extends GeneratorBuild{
public float warmup, totalTime;
@Override
public void updateTile(){
boolean valid = consValid();
warmup = Mathf.lerpDelta(warmup, enabled && valid ? 1f : 0f, 0.05f);
productionEfficiency = valid ? 1f : 0f;
totalTime += warmup * Time.delta;
//generation time always goes down
generateTime -= Math.min(1f / itemDuration * delta(), generateTime);
//randomly produce the effect
if(valid && Mathf.chanceDelta(effectChance)){
generateEffect.at(x + Mathf.range(generateEffectRange), y + Mathf.range(generateEffectRange));
}
//take in items periodically
if(hasItems && valid && generateTime <= 0f && items.any()){
cons.trigger();
generateTime = 1f;
}
if(liquidOutput != null){
float added = Math.min(productionEfficiency * delta() * liquidOutput.amount, liquidCapacity - liquids.get(liquidOutput.liquid));
liquids.add(liquidOutput.liquid, added);
dumpLiquid(liquidOutput.liquid);
}
}
@Override
public float warmup(){
return warmup;
}
@Override
public float totalProgress(){
return totalTime;
}
@Override
public void drawLight(){
//TODO
Drawf.light(team, x, y, (60f + Mathf.absin(10f, 5f)) * size, Color.orange, 0.5f * warmup);
}
}
}

View File

@@ -25,6 +25,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
/** 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;
@@ -36,6 +37,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
public boolean defaults = false;
/** @deprecated unused, use a custom drawer instead */
@Deprecated
public Color heatColor = Color.valueOf("ff9b59");
/** @deprecated unused, use a custom drawer instead */
@Deprecated
@@ -129,14 +131,17 @@ public class ItemLiquidGenerator extends PowerGenerator{
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 * power.graph.getUsageFraction());
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;
@@ -152,7 +157,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
}
if(generateTime > 0f){
generateTime -= Math.min(1f / itemDuration * delta() * power.graph.getUsageFraction(), generateTime);
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

View File

@@ -83,7 +83,8 @@ public class PowerGraph{
return Mathf.clamp(lastPowerProduced / lastPowerNeeded);
}
/** @return multiplier of speed at which resources should be consumed for power generation. */
/** @deprecated unused mechanic that always returns 1, I really don't know why you would use this outside of copy-pasted code */
@Deprecated
public float getUsageFraction(){
return 1f;
}

View File

@@ -2,6 +2,8 @@ package mindustry.world.blocks.power;
import mindustry.type.*;
/** @deprecated use ConsumeGenerator instead, this class does not have a sane implementation. */
@Deprecated
public class SingleTypeGenerator extends ItemLiquidGenerator{
public boolean useItems = true;

View File

@@ -3,7 +3,6 @@ package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
@@ -11,7 +10,8 @@ import mindustry.world.*;
public class DrawPistons extends DrawBlock{
public float sinMag = 4f, sinScl = 6f, sinOffset = 50f, sideOffset = 0f, lenOffset = -1f;
public TextureRegion region1, region2;
public int sides = 4;
public TextureRegion region1, region2, regiont;
@Override
public void drawPlan(Block block, BuildPlan plan, Eachable<BuildPlan> list){
@@ -20,9 +20,20 @@ public class DrawPistons extends DrawBlock{
@Override
public void drawBase(Building build){
for(int i = 0; i < 4; i++){
for(int i = 0; i < sides; i++){
float len = Mathf.absin(build.totalProgress() + sinOffset + sideOffset * sinScl * i, sinScl, sinMag) + lenOffset;
Draw.rect(i >= 2 ? region2 : region1, build.x + Geometry.d4[i].x * len, build.y + Geometry.d4[i].y * len, i * 90);
float angle = i * 360f / sides;
TextureRegion reg =
regiont.found() && (Mathf.equal(angle, 315) || Mathf.equal(angle, 135)) ? regiont :
angle >= 135 && angle < 315 ? region2 : region1;
if(Mathf.equal(angle, 315)){
Draw.yscl = -1f;
}
Draw.rect(reg, build.x + Angles.trnsx(angle, len), build.y + Angles.trnsy(angle, len), angle);
Draw.yscl = 1f;
}
}
@@ -30,7 +41,8 @@ public class DrawPistons extends DrawBlock{
public void load(Block block){
super.load(block);
region1 = Core.atlas.find(block.name + "-piston0");
region2 = Core.atlas.find(block.name + "-piston1");
region1 = Core.atlas.find(block.name + "-piston0", block.name + "-piston");
region2 = Core.atlas.find(block.name + "-piston1", block.name + "-piston");
regiont = Core.atlas.find(block.name + "-piston-t");
}
}

View File

@@ -11,6 +11,14 @@ public class DrawRotator extends DrawBlock{
public boolean drawSpinSprite = false;
public float spinSpeed = 2f;
public DrawRotator(boolean drawSpinSprite, float spinSpeed){
this.drawSpinSprite = drawSpinSprite;
this.spinSpeed = spinSpeed;
}
public DrawRotator(){
}
@Override
public void drawBase(Building build){
Draw.rect(build.block.region, build.x, build.y);