WIP electrolyzer + liquid fixes

This commit is contained in:
Anuken 2021-11-15 14:31:20 -05:00
parent 7103de8454
commit 9663d1153f
30 changed files with 364 additions and 23 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 332 B

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 322 B

After

Width:  |  Height:  |  Size: 323 B

View File

@ -441,3 +441,5 @@
63265=oxide|item-oxide-ui
63264=oxygen|liquid-oxygen-ui
63263=hydrogen|liquid-hydrogen-ui
63262=electrolyzer|block-electrolyzer-ui
63261=ozone|liquid-ozone-ui

Binary file not shown.

View File

@ -60,7 +60,7 @@ public class Blocks implements ContentList{
//crafting
siliconSmelter, siliconCrucible, siliconArcFurnace, kiln, graphitePress, plastaniumCompressor, multiPress, phaseWeaver, surgeSmelter, pyratiteMixer, blastMixer, cryofluidMixer,
melter, separator, disassembler, sporePress, pulverizer, incinerator, coalCentrifuge,
oxidizer, heatReactor, carbideCrucible,
electrolyzer, oxidizer, heatReactor, carbideCrucible,
cellSynthesisChamber,
//sandbox
@ -935,6 +935,7 @@ public class Blocks implements ContentList{
craftTime = 30f;
size = 2;
hasPower = hasItems = hasLiquids = true;
rotatePlan = false;
consumes.liquid(Liquids.oil, 0.1f);
consumes.power(0.7f);
@ -946,10 +947,46 @@ public class Blocks implements ContentList{
consumes.power(0.50f);
}};
//TODO better name
electrolyzer = new GenericCrafter("electrolyzer"){{
requirements(Category.crafting, with(Items.tungsten, 60, Items.graphite, 30));
size = 3;
craftTime = 10f;
rotate = true;
liquidCapacity = 100f;
consumes.liquid(Liquids.water, 1f);
consumes.power(2f);
drawer = new DrawMulti(
new DrawRegion("-bottom"),
new DrawLiquidRegion(Liquids.water),
new DrawBubbles(Color.valueOf("7693e3")){{
sides = 10;
recurrence = 3f;
spread = 6;
radius = 1.5f;
amount = 20;
}},
new DrawRegion(),
new DrawLiquidOutputs(),
new DrawRegion("-top"),
new DrawGlowRegion(){{
alpha = 0.5f;
color = new Color(1f, 0.22f, 0.22f);
}}
);
iconOverride = new String[]{"-bottom", "", "-top"};
outputLiquids = LiquidStack.with(Liquids.ozone, 0.5f, Liquids.hydrogen, 0.5f);
liquidOutputDirections = new int[]{1, 3};
}};
oxidizer = new HeatProducer("oxidizer"){{
requirements(Category.crafting, with(Items.tungsten, 60, Items.graphite, 30));
//TODO bigger?
size = 2;
size = 3;
//TODO multi liquid output
//converts oxygen (?) + beryllium into heat + oxide

View File

@ -58,17 +58,18 @@ public class Liquids implements ContentList{
}};
//TODO reactivity, etc
ozone = new Liquid("ozone", Color.valueOf("bdd7ff")){{
ozone = new Liquid("ozone", Color.valueOf("f099da")){{
gas = true;
barColor = Color.valueOf("97bdf7");
barColor = Color.valueOf("d699f0");
explosiveness = 1f;
flammability = 1f;
}};
//TODO combustion
hydrogen = new Liquid("hydrogen", Color.valueOf("e8d1ff")){{
hydrogen = new Liquid("hydrogen", Color.valueOf("97a5f7")){{
gas = true;
barColor = Color.valueOf("c599f0");
barColor = Color.valueOf("7d8be0");
flammability = 1f;
}};
//TODO dicyanoacetylene

View File

@ -567,6 +567,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
liquids.add(liquid, amount);
}
//TODO entire liquid system is awful
public void dumpLiquid(Liquid liquid){
dumpLiquid(liquid, 2f);
}
@ -585,9 +586,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
for(int i = 0; i < proximity.size; i++){
incrementDump(proximity.size);
Building other = proximity.get((i + dump) % proximity.size);
if(outputDir != -1 && (relativeTo(other) + rotation) % 4 != outputDir) return;
Building other = proximity.get((i + dump) % proximity.size);
if(outputDir != -1 && (outputDir + rotation) % 4 != relativeTo(other)) continue;
other = other.getLiquidDestination(self(), liquid);

View File

@ -1,6 +1,5 @@
package mindustry.type;
import arc.math.*;
import arc.struct.*;
import mindustry.content.*;
@ -38,7 +37,7 @@ public class LiquidStack implements Comparable<LiquidStack>{
public static LiquidStack[] mult(LiquidStack[] stacks, float amount){
LiquidStack[] copy = new LiquidStack[stacks.length];
for(int i = 0; i < copy.length; i++){
copy[i] = new LiquidStack(stacks[i].liquid, Mathf.round(stacks[i].amount * amount));
copy[i] = new LiquidStack(stacks[i].liquid, stacks[i].amount * amount);
}
return copy;
}
@ -46,7 +45,7 @@ public class LiquidStack implements Comparable<LiquidStack>{
public static LiquidStack[] with(Object... items){
LiquidStack[] stacks = new LiquidStack[items.length / 2];
for(int i = 0; i < items.length; i += 2){
stacks[i / 2] = new LiquidStack((Liquid)items[i], ((Number)items[i + 1]).intValue());
stacks[i / 2] = new LiquidStack((Liquid)items[i], ((Number)items[i + 1]).floatValue());
}
return stacks;
}
@ -54,7 +53,7 @@ public class LiquidStack implements Comparable<LiquidStack>{
public static Seq<LiquidStack> list(Object... items){
Seq<LiquidStack> stacks = new Seq<>(items.length / 2);
for(int i = 0; i < items.length; i += 2){
stacks.add(new LiquidStack((Liquid)items[i], ((Number)items[i + 1]).intValue()));
stacks.add(new LiquidStack((Liquid)items[i], ((Number)items[i + 1]).floatValue()));
}
return stacks;
}

View File

@ -90,6 +90,8 @@ public class Block extends UnlockableContent{
public boolean solidifes;
/** whether this is rotatable */
public boolean rotate;
/** if set to plan, the plan region won't rotate when drawing */
public boolean rotatePlan = true;
/** number of different variant regions to use */
public int variants = 0;
/** whether to draw a rotation arrow - this does not apply to lines of blocks */
@ -544,7 +546,7 @@ public class Block extends UnlockableContent{
public void drawRequestRegion(BuildPlan plan, Eachable<BuildPlan> list){
TextureRegion reg = getRequestRegion(plan, list);
Draw.rect(reg, plan.drawx(), plan.drawy(), !rotate ? 0 : plan.rotation * 90);
Draw.rect(reg, plan.drawx(), plan.drawy(), !rotate || !rotatePlan ? 0 : plan.rotation * 90);
if(plan.worldContext && player != null && teamRegion != null && teamRegion.found()){
if(teamRegions[player.team().id] == teamRegion) Draw.color(player.team().color);

View File

@ -201,8 +201,13 @@ public interface Autotiler{
/** @return whether this tile is looking at the other tile, or the other tile is looking at this one.
* If the other tile does not rotate, it is always considered to be facing this one. */
default boolean lookingAtEither(Tile tile, int rotation, int otherx, int othery, int otherrot, Block otherblock){
return (Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery)
|| (!otherblock.rotatedOutput(otherx, othery) || Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y)));
return
//block is facing the other
Point2.equals(tile.x + Geometry.d4(rotation).x, tile.y + Geometry.d4(rotation).y, otherx, othery) ||
//does not output to rotated direction
!otherblock.rotatedOutput(otherx, othery) ||
//other block is facing this one
Point2.equals(otherx + Geometry.d4(otherrot).x, othery + Geometry.d4(otherrot).y, tile.x, tile.y);
}
/**

View File

@ -1,5 +1,6 @@
package mindustry.world.blocks.production;
import arc.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.struct.*;
@ -13,6 +14,7 @@ import mindustry.logic.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.consumers.*;
import mindustry.world.draw.*;
import mindustry.world.meta.*;
@ -38,6 +40,8 @@ public class GenericCrafter extends Block{
public boolean legacyReadWarmup = false;
public DrawBlock drawer = new DrawBlock();
/** If set, the icon is overridden to be these strings, in order. Each string is a suffix. */
public String[] iconOverride = null;
public GenericCrafter(String name){
super(name);
@ -48,6 +52,7 @@ public class GenericCrafter extends Block{
sync = true;
ambientSoundVolume = 0.03f;
flags = EnumSet.of(BlockFlag.factory);
drawArrow = false;
}
@Override
@ -69,13 +74,37 @@ public class GenericCrafter extends Block{
public void setBars(){
super.setBars();
//set up liquid bars for multiple liquid outputs; TODO multiple inputs not yet supported due to inherent complexity
//TODO this will currently screw up input display if input liquids are available - no good way to fix that yet
if(outputLiquids != null && outputLiquids.length > 1){
//set up liquid bars for multiple liquid outputs
//TODO this will currently screw up input display if input liquids are filters - no good way to fix that yet
if(outputLiquids != null && outputLiquids.length > 0){
bars.remove("liquid");
Seq<Liquid> consumed = new Seq<>();
//find list of liquids consumed
if(consumes.has(ConsumeType.liquid)){
var consl = consumes.get(ConsumeType.liquid);
if(consl instanceof ConsumeLiquid liq){
consumed.add(liq.liquid);
}else if(consl instanceof ConsumeLiquids multi){
for(var stack : multi.liquids){
consumed.add(stack.liquid);
}
}
}
//display consumed first
for(var liq : consumed){
bars.add("liquid-consume-" + liq.name, entity -> new Bar(
() -> liq.localizedName,
liq::barColor,
() -> entity.liquids.get(liq) / liquidCapacity)
);
}
//then display output buffer
for(var stack : outputLiquids){
bars.add("liquid-" + stack.liquid.name, entity -> new Bar(
bars.add("liquid-output-" + stack.liquid.name, entity -> new Bar(
() -> stack.liquid.localizedName,
() -> stack.liquid.barColor(),
() -> entity.liquids.get(stack.liquid) / liquidCapacity)
@ -84,6 +113,11 @@ public class GenericCrafter extends Block{
}
}
@Override
public boolean rotatedOutput(int x, int y){
return false;
}
@Override
public void load(){
super.load();
@ -93,13 +127,13 @@ public class GenericCrafter extends Block{
@Override
public void init(){
outputsLiquid = outputLiquid != null;
if(outputItems == null && outputItem != null){
outputItems = new ItemStack[]{outputItem};
}
if(outputLiquids == null && outputLiquid != null){
outputLiquids = new LiquidStack[]{outputLiquid};
}
outputsLiquid = outputLiquids != null;
super.init();
}
@ -114,6 +148,13 @@ public class GenericCrafter extends Block{
@Override
public TextureRegion[] icons(){
if(iconOverride != null){
var out = new TextureRegion[iconOverride.length];
for(int i = 0; i < out.length; i++){
out[i] = Core.atlas.find(name + iconOverride[i]);
}
return out;
}
return drawer.icons(this);
}

View File

@ -9,6 +9,7 @@ import mindustry.world.meta.*;
import static mindustry.Vars.*;
//TODO replace with ConsumeLiquids
public class ConsumeLiquid extends ConsumeLiquidBase{
public final Liquid liquid;

View File

@ -2,6 +2,7 @@ package mindustry.world.consumers;
import arc.scene.ui.layout.*;
import arc.struct.*;
import mindustry.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.ui.*;
@ -38,7 +39,7 @@ public class ConsumeLiquids extends Consume{
int i = 0;
for(var stack : liquids){
c.add(new ReqImage(stack.liquid.uiIcon,
() -> build.liquids != null && build.liquids.get(stack.liquid) >= stack.amount * build.delta())).padRight(8);
() -> build.liquids.get(stack.liquid) >= stack.amount * build.delta())).size(Vars.iconMed).padRight(8);
if(++i % 4 == 0) c.row();
}
}).left();
@ -63,6 +64,7 @@ public class ConsumeLiquids extends Consume{
@Override
public void display(Stats stats){
//TODO display is wrong
stats.add(booster ? Stat.booster : Stat.input, StatValues.liquids(stats.timePeriod, stats.timePeriod >= 0, liquids));
}

View File

@ -0,0 +1,47 @@
package mindustry.world.draw;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawBubbles extends DrawBlock{
public Color color = Color.valueOf("7457ce");
public int amount = 12, sides = 8;
public float strokeMin = 0.2f, spread = 3f, timeScl = 30f;
public float recurrence = 6f, radius = 3f;
public DrawBubbles(Color color){
this.color = color;
}
public DrawBubbles(){
}
@Override
public void drawPlan(GenericCrafter crafter, BuildPlan plan, Eachable<BuildPlan> list){}
@Override
public void draw(GenericCrafterBuild build){
if(build.warmup <= 0.001f) return;
Draw.color(color);
Draw.alpha(build.warmup);
rand.setSeed(build.id);
for(int i = 0; i < amount; i++){
float x = rand.range(spread), y = rand.range(spread);
float life = 1f - ((Time.time / timeScl + rand.random(recurrence)) % recurrence);
if(life > 0){
Lines.stroke(build.warmup * (life + strokeMin));
Lines.poly(build.x + x, build.y + y, sides, (1f - life) * radius);
}
}
Draw.color();
}
}

View File

@ -7,6 +7,7 @@ import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawGlow extends DrawBlock{
public String suffix = "-top";
public float glowAmount = 0.9f, glowScale = 3f;
public TextureRegion top;
@ -20,6 +21,6 @@ public class DrawGlow extends DrawBlock{
@Override
public void load(Block block){
top = Core.atlas.find(block.name + "-top");
top = Core.atlas.find(block.name + suffix);
}
}

View File

@ -0,0 +1,45 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.production.GenericCrafter.*;
/** Not standalone. */
public class DrawGlowRegion extends DrawBlock{
public Blending blending = Blending.additive;
public String suffix = "-glow";
public float alpha = 0.9f, glowScale = 3f;
public float layer = Layer.blockAdditive;
public Color color = Color.red.cpy();
public TextureRegion top;
@Override
public void draw(GenericCrafterBuild build){
if(build.warmup <= 0.001f) return;
float z = Draw.z();
Draw.z(layer);
Draw.blend(blending);
Draw.color(color);
Draw.alpha(Mathf.absin(build.totalProgress, glowScale, alpha) * build.warmup);
Draw.rect(top, build.x, build.y);
Draw.reset();
Draw.blend();
Draw.z(z);
}
@Override
public void load(Block block){
top = Core.atlas.find(block.name + suffix);
}
@Override
public void drawPlan(GenericCrafter crafter, BuildPlan plan, Eachable<BuildPlan> list){}
}

View File

@ -0,0 +1,61 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.world.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.production.GenericCrafter.*;
/** This must be used in conjunction with another DrawBlock; it only draws outputs. */
public class DrawLiquidOutputs extends DrawBlock{
public TextureRegion[][] liquidOutputRegions;
@Override
public void draw(GenericCrafterBuild build){
GenericCrafter crafter = (GenericCrafter)build.block;
if(crafter.outputLiquids == null) return;
for(int i = 0; i < crafter.outputLiquids.length; i++){
int side = i < crafter.liquidOutputDirections.length ? crafter.liquidOutputDirections[i] : -1;
if(side != -1){
int realRot = (side + build.rotation) % 4;
Draw.rect(liquidOutputRegions[realRot > 1 ? 1 : 0][i], build.x, build.y, realRot * 90);
}
}
}
@Override
public void drawPlan(GenericCrafter crafter, BuildPlan plan, Eachable<BuildPlan> list){
if(crafter.outputLiquids == null) return;
for(int i = 0; i < crafter.outputLiquids.length; i++){
int side = i < crafter.liquidOutputDirections.length ? crafter.liquidOutputDirections[i] : -1;
if(side != -1){
int realRot = (side + plan.rotation) % 4;
Draw.rect(liquidOutputRegions[realRot > 1 ? 1 : 0][i], plan.drawx(), plan.drawy(), realRot * 90);
}
}
}
@Override
public void load(Block block){
GenericCrafter crafter = (GenericCrafter)block;
if(crafter.outputLiquids == null) return;
liquidOutputRegions = new TextureRegion[2][crafter.outputLiquids.length];
for(int i = 0; i < crafter.outputLiquids.length; i++){
for(int j = 1; j <= 2; j++){
liquidOutputRegions[j - 1][i] = Core.atlas.find(block.name + "-" + crafter.outputLiquids[i].liquid.name + "-output" + j);
}
}
}
//TODO
@Override
public TextureRegion[] icons(Block block){
return super.icons(block);
}
}

View File

@ -0,0 +1,44 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.production.GenericCrafter.*;
/** Not standalone. */
public class DrawLiquidRegion extends DrawBlock{
public Liquid drawLiquid;
public TextureRegion liquid;
public String suffix = "-liquid";
public DrawLiquidRegion(Liquid drawLiquid){
this.drawLiquid = drawLiquid;
}
public DrawLiquidRegion(){
}
@Override
public void drawPlan(GenericCrafter crafter, BuildPlan plan, Eachable<BuildPlan> list){}
@Override
public void draw(GenericCrafterBuild build){
if(drawLiquid != null){
Drawf.liquid(liquid, build.x, build.y,
build.liquids.get(drawLiquid) / build.block.liquidCapacity,
drawLiquid.color
);
}
}
@Override
public void load(Block block){
liquid = Core.atlas.find(block.name + suffix);
}
}

View File

@ -1,7 +1,10 @@
package mindustry.world.draw;
import arc.graphics.g2d.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.world.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.production.GenericCrafter.*;
/** combined several DrawBlocks into one */
@ -24,6 +27,13 @@ public class DrawMulti extends DrawBlock{
}
}
@Override
public void drawPlan(GenericCrafter crafter, BuildPlan plan, Eachable<BuildPlan> list){
for(var draw : drawers){
draw.drawPlan(crafter, plan, list);
}
}
@Override
public void drawLight(GenericCrafterBuild build){
for(var draw : drawers){

View File

@ -0,0 +1,42 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.world.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.production.GenericCrafter.*;
/** Not standalone. */
public class DrawRegion extends DrawBlock{
public TextureRegion region;
public String suffix = "";
/** Any number <=0 disables layer changes. */
public float layer = -1;
public DrawRegion(String suffix){
this.suffix = suffix;
}
public DrawRegion(){
}
@Override
public void draw(GenericCrafterBuild build){
float z = Draw.z();
if(layer > 0) Draw.z(layer);
Draw.rect(region, build.x, build.y);
Draw.z(z);
}
@Override
public void drawPlan(GenericCrafter crafter, BuildPlan plan, Eachable<BuildPlan> list){
Draw.rect(region, plan.drawx(), plan.drawy());
}
@Override
public void load(Block block){
region = Core.atlas.find(block.name + suffix);
}
}