From 76735b01f77c47697f1f7785d84c55364b35dfa1 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 22 Jun 2022 03:25:35 -0400 Subject: [PATCH] Somewhat more dangerous neoplasm --- core/src/mindustry/content/Liquids.java | 3 +- core/src/mindustry/entities/Puddles.java | 2 +- core/src/mindustry/logic/LExecutor.java | 12 +++-- core/src/mindustry/type/CellLiquid.java | 58 +++++++++++++++++++++++- core/src/mindustry/type/Liquid.java | 6 +++ 5 files changed, 72 insertions(+), 9 deletions(-) diff --git a/core/src/mindustry/content/Liquids.java b/core/src/mindustry/content/Liquids.java index 8de5f16bc9..de478269af 100644 --- a/core/src/mindustry/content/Liquids.java +++ b/core/src/mindustry/content/Liquids.java @@ -48,9 +48,10 @@ public class Liquids{ heatCapacity = 0.4f; temperature = 0.54f; viscosity = 0.85f; - flammability = 0.1f; + flammability = 0f; capPuddles = false; hidden = true; + spreadTarget = Liquids.water; colorFrom = Color.valueOf("f98f4a"); colorTo = Color.valueOf("9e172c"); diff --git a/core/src/mindustry/entities/Puddles.java b/core/src/mindustry/entities/Puddles.java index 4b0b66f001..20e8264ecb 100644 --- a/core/src/mindustry/entities/Puddles.java +++ b/core/src/mindustry/entities/Puddles.java @@ -124,7 +124,7 @@ public class Puddles{ } return -0.4f * amount; } - return 0f; + return dest.react(liquid, amount, tile, x, y); } /** diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 8853361aaa..e347be85b7 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -1289,14 +1289,16 @@ public class LExecutor{ if(b instanceof OverlayFloor o && tile.overlay() != o) tile.setOverlayNet(o); } case floor -> { - if(b instanceof Floor f && tile.floor() != f) tile.setFloorNet(f); + if(b instanceof Floor f && tile.floor() != f && !f.isOverlay()) tile.setFloorNet(f); } case block -> { - Team t = exec.team(team); - if(t == null) t = Team.derelict; + if(!b.isFloor()){ + Team t = exec.team(team); + if(t == null) t = Team.derelict; - if(tile.block() != b || tile.team() != t){ - tile.setNet(b, t, Mathf.clamp(exec.numi(rotation), 0, 3)); + if(tile.block() != b || tile.team() != t){ + tile.setNet(b, t, Mathf.clamp(exec.numi(rotation), 0, 3)); + } } } //building case not allowed diff --git a/core/src/mindustry/type/CellLiquid.java b/core/src/mindustry/type/CellLiquid.java index c9d276059d..220953c3c0 100644 --- a/core/src/mindustry/type/CellLiquid.java +++ b/core/src/mindustry/type/CellLiquid.java @@ -3,16 +3,23 @@ package mindustry.type; import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; +import arc.math.geom.*; import arc.util.*; +import mindustry.entities.*; import mindustry.gen.*; import mindustry.graphics.*; +import mindustry.world.*; import static mindustry.entities.Puddles.*; +/** Liquid that draws cells in its puddle. */ public class CellLiquid extends Liquid{ public Color colorFrom = Color.white.cpy(), colorTo = Color.white.cpy(); public int cells = 8; + public @Nullable Liquid spreadTarget; + public float maxSpread = 0.5f, spreadConversion = 0.5f, spreadDamage = 0.1f; + public CellLiquid(String name, Color color){ super(name, color); } @@ -21,11 +28,58 @@ public class CellLiquid extends Liquid{ super(name); } + @Override + public void update(Puddle puddle){ + if(spreadTarget != null){ + float scaling = Mathf.pow(Mathf.clamp(puddle.amount / maxLiquid), 2f); + + for(var point : Geometry.d4c){ + Tile tile = puddle.tile.nearby(point); + if(tile != null && tile.build != null && tile.build.liquids != null && tile.build.liquids.get(spreadTarget) > 0){ + float amount = Math.min(tile.build.liquids.get(spreadTarget), maxSpread * Time.delta * scaling); + tile.build.liquids.remove(spreadTarget, amount); + Puddles.deposit(tile, this, amount * spreadConversion); + } + } + + //damage thing it is on + if(spreadDamage > 0 && puddle.tile.build != null && puddle.tile.build.liquids != null && puddle.tile.build.liquids.get(spreadTarget) > 0){ + puddle.tile.build.damage(spreadDamage * Time.delta * scaling); + } + + //spread to nearby puddles + for(var point : Geometry.d4){ + Tile tile = puddle.tile.nearby(point); + if(tile != null){ + var other = Puddles.get(tile); + if(other != null && other.liquid == spreadTarget){ + //TODO looks somewhat buggy when outputs are occurring + float amount = Math.min(other.amount, Math.max(maxSpread * Time.delta * scaling, other.amount * 0.25f * scaling)); + other.amount -= amount; + puddle.amount += amount; + if(other.amount <= maxLiquid / 3f){ + other.remove(); + Puddles.deposit(tile, puddle.tile, this, Math.max(amount, maxLiquid / 3f)); + } + } + } + } + } + } + + @Override + public float react(Liquid other, float amount, Tile tile, float x, float y){ + if(other == spreadTarget){ + return amount; + } + return 0f; + } + @Override public void drawPuddle(Puddle puddle){ super.drawPuddle(puddle); - Draw.z(Layer.debris - 0.5f); + float baseLayer = puddle.tile != null && puddle.tile.build != null ? Layer.blockOver : Layer.debris - 0.5f; int id = puddle.id; float amount = puddle.amount, x = puddle.x, y = puddle.y; @@ -35,7 +89,7 @@ public class CellLiquid extends Liquid{ rand.setSeed(id); for(int i = 0; i < cells; i++){ - Draw.z(Layer.debris - 0.5f + i/1000f + (id % 100) / 10000f); + Draw.z(baseLayer + i/1000f + (id % 100) / 10000f); Tmp.v1.trns(rand.random(360f), rand.random(length)); float vx = x + Tmp.v1.x, vy = y + Tmp.v1.y; diff --git a/core/src/mindustry/type/Liquid.java b/core/src/mindustry/type/Liquid.java index 7a45caee2a..306f663420 100644 --- a/core/src/mindustry/type/Liquid.java +++ b/core/src/mindustry/type/Liquid.java @@ -10,6 +10,7 @@ import mindustry.entities.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.logic.*; +import mindustry.world.*; import mindustry.world.meta.*; import static mindustry.entities.Puddles.*; @@ -145,6 +146,11 @@ public class Liquid extends UnlockableContent implements Senseable{ } + //TODO proper API for this (do not use yet!) + public float react(Liquid other, float amount, Tile tile, float x, float y){ + return 0f; + } + @Override public void setStats(){ stats.addPercent(Stat.explosiveness, explosiveness);