Coolant system rework

This commit is contained in:
Anuken
2022-02-15 19:11:49 -05:00
parent 390c76a84f
commit 0102ade759
16 changed files with 86 additions and 71 deletions

View File

@@ -2685,6 +2685,7 @@ public class Blocks{
health = 250;
inaccuracy = 2f;
rotateSpeed = 10f;
coolant = consume(new ConsumeCoolant(0.1f));
limitRange();
}};
@@ -2710,6 +2711,7 @@ public class Blocks{
scaledHealth = 200;
shootSound = Sounds.shootSnap;
coolant = consume(new ConsumeCoolant(0.2f));
limitRange(2);
}};
@@ -2729,6 +2731,7 @@ public class Blocks{
ammoUseEffect = Fx.none;
health = 400;
shootSound = Sounds.flame;
coolant = consume(new ConsumeCoolant(0.1f));
}};
hail = new ItemTurret("hail"){{
@@ -2746,6 +2749,7 @@ public class Blocks{
shootCone = 10f;
health = 260;
shootSound = Sounds.bang;
coolant = consume(new ConsumeCoolant(0.1f));
limitRange(0f);
}};
@@ -2789,6 +2793,7 @@ public class Blocks{
scaledHealth = 280;
targetAir = false;
shootSound = Sounds.laser;
coolant = consume(new ConsumeCoolant(0.2f));
consumePower(6f);
@@ -2815,7 +2820,6 @@ public class Blocks{
reloadTime = 35f;
shootCone = 40f;
rotateSpeed = 8f;
consumePower(3.3f);
targetAir = false;
range = 90f;
shootEffect = Fx.lightningShoot;
@@ -2824,6 +2828,8 @@ public class Blocks{
size = 1;
health = 260;
shootSound = Sounds.spark;
consumePower(3.3f);
coolant = consume(new ConsumeCoolant(0.1f));
}};
parallax = new TractorBeamTurret("parallax"){{
@@ -2838,7 +2844,7 @@ public class Blocks{
scaledHealth = 160;
rotateSpeed = 10;
consumePowerCond(3f, (TractorBeamBuild e) -> e.target != null);
consumePower(3f);
}};
swarmer = new ItemTurret("swarmer"){{
@@ -2860,6 +2866,7 @@ public class Blocks{
envEnabled |= Env.space;
limitRange(5f);
coolant = consume(new ConsumeCoolant(0.3f));
}};
salvo = new ItemTurret("salvo"){{
@@ -2888,6 +2895,7 @@ public class Blocks{
shootSound = Sounds.shootBig;
limitRange();
coolant = consume(new ConsumeCoolant(0.2f));
}};
segment = new PointDefenseTurret("segment"){{
@@ -2896,7 +2904,7 @@ public class Blocks{
scaledHealth = 250;
range = 180f;
hasPower = true;
consumePowerCond(8f, (PointDefenseBuild b) -> b.target != null);
consumePower(8f);
size = 2;
shootLength = 5f;
bulletDamage = 30f;
@@ -2943,6 +2951,7 @@ public class Blocks{
scaledHealth = 220;
shootSound = Sounds.shotgun;
coolant = consume(new ConsumeCoolant(0.3f));
float brange = range + 10f;
@@ -2989,6 +2998,7 @@ public class Blocks{
shootShake = 2f;
range = 290f;
minRange = 50f;
coolant = consume(new ConsumeCoolant(0.3f));
scaledHealth = 130;
shootSound = Sounds.artillery;
@@ -3011,6 +3021,7 @@ public class Blocks{
inaccuracy = 10f;
shootCone = 30f;
shootSound = Sounds.shootSnap;
coolant = consume(new ConsumeCoolant(0.3f));
scaledHealth = 145;
limitRange();
@@ -3053,11 +3064,10 @@ public class Blocks{
envEnabled |= Env.space;
coolantMultiplier = 0.4f;
scaledHealth = 150;
coolantUsage = 1f;
consumePowerCond(10f, TurretBuild::isActive);
coolant = consume(new ConsumeCoolant(1f));
consumePower(10f);
}};
spectre = new ItemTurret("spectre"){{
@@ -3083,7 +3093,7 @@ public class Blocks{
shootSound = Sounds.shootBig;
scaledHealth = 160;
coolantUsage = 1f;
coolant = consume(new ConsumeCoolant(1f));
limitRange();
}};
@@ -3099,7 +3109,6 @@ public class Blocks{
reloadTime = 90f;
firingMoveFract = 0.5f;
shootDuration = 230f;
consumePower(17f);
shootSound = Sounds.laserbig;
loopSound = Sounds.beam;
loopSoundVolume = 2f;
@@ -3119,7 +3128,8 @@ public class Blocks{
}};
scaledHealth = 200;
consume(new ConsumeCoolant(0.5f)).update(false);
coolant = consume(new ConsumeCoolant(0.5f));
consumePower(17f);
}};
breach = new ItemTurret("breach"){{
@@ -3160,8 +3170,6 @@ public class Blocks{
}}
);
coolantUsage = 15f / 60f;
coolantOverride = Liquids.water;
coolantMultiplier = 6f;
unitFilter = u -> !u.spawnedByCore;
@@ -3180,6 +3188,7 @@ public class Blocks{
scaledHealth = 280;
rotateSpeed = 1.6f;
coolant = consume(new ConsumeLiquid(Liquids.water, 15f / 60f));
limitRange();
}};
@@ -3250,7 +3259,6 @@ public class Blocks{
}}
);
acceptCoolant = false;
scaledHealth = 330;
shootLength = 7f;
size = 3;
@@ -3304,8 +3312,7 @@ public class Blocks{
minWarmup = 0.85f;
shootWarmupSpeed = 0.07f;
coolantUsage = 30f / 60f;
coolantOverride = Liquids.water;
coolant = consume(new ConsumeLiquid(Liquids.water, 30f / 60f));
draw = new DrawTurret("reinforced-"){{
parts.addAll(
@@ -3331,7 +3338,6 @@ public class Blocks{
shootWarmupSpeed = 0.08f;
outlineColor = Pal.darkOutline;
acceptCoolant = false;
consumeLiquid(Liquids.hydrogen, 5f / 60f);
@@ -3377,8 +3383,7 @@ public class Blocks{
rotateSpeed = 5f;
shootCone = 30f;
coolantUsage = 30f / 60f;
coolantOverride = Liquids.water;
coolant = consume(new ConsumeLiquid(Liquids.water, 30f / 60f));
draw = new DrawTurret("reinforced-"){{
parts.add(new RegionPart("-side"){{
@@ -3422,7 +3427,6 @@ public class Blocks{
shootWarmupSpeed = 0.08f;
outlineColor = Pal.darkOutline;
acceptCoolant = false;
scaledHealth = 420;
range = 270f;
@@ -3826,7 +3830,7 @@ public class Blocks{
}};
interplanetaryAccelerator = new Accelerator("interplanetary-accelerator"){{
requirements(Category.effect, BuildVisibility.campaignOnly, with(Items.copper, 16000, Items.silicon, 11000, Items.thorium, 13000, Items.titanium, 12000, Items.surgeAlloy, 6000, Items.phaseFabric, 5000));
requirements(Category.effect, BuildVisibility.hidden, with(Items.copper, 16000, Items.silicon, 11000, Items.thorium, 13000, Items.titanium, 12000, Items.surgeAlloy, 6000, Items.phaseFabric, 5000));
researchCostMultiplier = 0.1f;
size = 7;
hasPower = true;

View File

@@ -29,7 +29,7 @@ public class ErekirTechTree{
//TODO gate behind capture
Planets.erekir.techTree = nodeRoot("erekir", coreBastion, true, () -> {
context().researchCostMultipliers = costMultipliers;
//context().researchCostMultipliers = costMultipliers;
node(duct, erekirSector, () -> {
node(ductRouter, () -> {

View File

@@ -49,6 +49,7 @@ public class Planets{
new HexSkyMesh(this, 2, 0.15f, 0.14f, 5, Color.valueOf("eba768").a(0.75f), 2, 0.42f, 1f, 0.43f),
new HexSkyMesh(this, 3, 0.6f, 0.15f, 5, Color.valueOf("eea293").a(0.75f), 2, 0.42f, 1.2f, 0.45f)
);
alwaysUnlocked = true;
landCloudColor = Color.valueOf("ed6542");
atmosphereColor = Color.valueOf("f07218");
defaultEnv = Env.scorching | Env.terrestrial;

View File

@@ -71,6 +71,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
transient boolean wasDamaged; //used only by the indexer
transient float visualLiquid;
transient @Nullable Liquid filterConsLiquid;
transient @Nullable Item filterConsItem;
@Nullable PowerModule power;
@Nullable ItemModule items;
@Nullable LiquidModule liquids;

View File

@@ -7,7 +7,6 @@ import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.consumers.*;
import mindustry.world.meta.*;
@@ -19,17 +18,12 @@ public class BaseTurret extends Block{
public float placeOverlapMargin = 8 * 7f;
public float rotateSpeed = 5;
public float coolantUsage = 0.2f;
//TODO
public boolean acceptCoolant = true;
/** Effect displayed when coolant is used. */
public Effect coolEffect = Fx.fuelburn;
/** How much reload is lowered by for each unit of liquid of heat capacity. */
public float coolantMultiplier = 5f;
/** Liquid that is used by coolant; null to use default. */
public @Nullable Liquid coolantOverride;
protected @Nullable ConsumeLiquidBase coolantConsumer;
/** If not null, this consumer will be used for coolant. */
public @Nullable ConsumeLiquidBase coolant;
public BaseTurret(String name){
super(name);
@@ -44,18 +38,14 @@ public class BaseTurret extends Block{
@Override
public void init(){
//TODO bad
if(acceptCoolant && findConsumer(f -> f instanceof ConsumeLiquidBase) == null){
hasLiquids = true;
consume(coolantOverride != null ? new ConsumeLiquid(coolantOverride, coolantUsage) : new ConsumeCoolant(coolantUsage)).update(false).boost();
//just makes things a little more convenient
if(coolant != null){
coolant.update = false;
coolant.booster = true;
}
placeOverlapRange = Math.max(placeOverlapRange, range + placeOverlapMargin);
super.init();
if(acceptCoolant){
coolantConsumer = findConsumer(c -> c instanceof ConsumeLiquidBase);
}
}
@Override

View File

@@ -14,7 +14,6 @@ public class ContinuousLiquidTurret extends ContinuousTurret{
public ContinuousLiquidTurret(String name){
super(name);
acceptCoolant = false;
hasLiquids = true;
//TODO
loopSound = Sounds.minebeam;

View File

@@ -18,7 +18,6 @@ public class ContinuousTurret extends Turret{
coolantMultiplier = 1f;
envEnabled |= Env.space;
acceptCoolant = false;
displayAmmoMultiplier = false;
}

View File

@@ -26,7 +26,7 @@ public class LaserTurret extends PowerTurret{
super.setStats();
stats.remove(Stat.booster);
stats.add(Stat.input, StatValues.boosters(reloadTime, coolantConsumer.amount, coolantMultiplier, false, this::consumesLiquid));
stats.add(Stat.input, StatValues.boosters(reloadTime, coolant.amount, coolantMultiplier, false, this::consumesLiquid));
}
public class LaserTurretBuild extends PowerTurretBuild{
@@ -65,9 +65,9 @@ public class LaserTurret extends PowerTurret{
}
}else if(reload > 0){
wasShooting = true;
//TODO does not handle multi liquid req?
Liquid liquid = liquids.current();
float maxUsed = coolantConsumer.amount;
float maxUsed = coolant.amount;
float used = (cheating() ? maxUsed : Math.min(liquids.get(liquid), maxUsed)) * delta();
reload -= used * liquid.heatCapacity * coolantMultiplier;
liquids.remove(liquid, used);

View File

@@ -19,7 +19,6 @@ public class LiquidTurret extends Turret{
public LiquidTurret(String name){
super(name);
acceptCoolant = false;
hasLiquids = true;
loopSound = Sounds.spray;
shootSound = Sounds.none;

View File

@@ -38,8 +38,6 @@ public class PointDefenseTurret extends ReloadTurret{
reloadTime = 30f;
coolantMultiplier = 2f;
//disabled due to version mismatch problems
acceptCoolant = false;
}
@Override
@@ -70,7 +68,7 @@ public class PointDefenseTurret extends ReloadTurret{
target = null;
}
if(acceptCoolant){
if(coolant != null){
updateCooling();
}
@@ -99,6 +97,11 @@ public class PointDefenseTurret extends ReloadTurret{
}
}
@Override
public boolean shouldConsume(){
return super.shouldConsume() && target != null;
}
@Override
public void draw(){
Draw.rect(baseRegion, x, y);

View File

@@ -1,8 +1,6 @@
package mindustry.world.blocks.defense.turrets;
import arc.math.*;
import arc.util.*;
import mindustry.type.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
@@ -18,8 +16,8 @@ public class ReloadTurret extends BaseTurret{
public void setStats(){
super.setStats();
if(acceptCoolant && coolantConsumer != null){
stats.add(Stat.booster, StatValues.boosters(reloadTime, coolantConsumer.amount, coolantMultiplier, true, l -> l.coolant && consumesLiquid(l)));
if(coolant != null){
stats.add(Stat.booster, StatValues.boosters(reloadTime, coolant.amount, coolantMultiplier, true, l -> l.coolant && consumesLiquid(l)));
}
}
@@ -34,15 +32,11 @@ public class ReloadTurret extends BaseTurret{
}
protected void updateCooling(){
if(reload < reloadTime && acceptCoolant){
float maxUsed = coolantConsumer.amount;
Liquid liquid = liquids.current();
if(reload < reloadTime && coolant != null && coolant.valid(this)){
coolant.update(this);
reload += coolant.amount * edelta() * (filterConsLiquid == null ? 1f : filterConsLiquid.heatCapacity) * coolantMultiplier;
float used = Math.min(liquids.get(liquid), maxUsed * Time.delta) * baseReloadSpeed();
reload += used * liquid.heatCapacity * coolantMultiplier;
liquids.remove(liquid, used);
if(Mathf.chance(0.06 * used)){
if(Mathf.chance(0.06 * coolant.amount)){
coolEffect.at(x + Mathf.range(size * tilesize / 2f), y + Mathf.range(size * tilesize / 2f));
}
}

View File

@@ -45,9 +45,6 @@ public class TractorBeamTurret extends BaseTurret{
rotateSpeed = 10f;
coolantMultiplier = 1f;
envEnabled |= Env.space;
//disabled due to version mismatch problems
acceptCoolant = false;
}
@Override
@@ -75,7 +72,7 @@ public class TractorBeamTurret extends BaseTurret{
public @Nullable Unit target;
public float lastX, lastY, strength;
public boolean any;
public float coolant = 1f;
public float coolantMultiplier = 1f;
@Override
public void updateTile(){
@@ -86,8 +83,8 @@ public class TractorBeamTurret extends BaseTurret{
}
//consume coolant
if(target != null && acceptCoolant){
float maxUsed = coolantConsumer.amount;
if(target != null && coolant != null){
float maxUsed = coolant.amount;
Liquid liquid = liquids.current();
@@ -99,7 +96,7 @@ public class TractorBeamTurret extends BaseTurret{
coolEffect.at(x + Mathf.range(size * tilesize / 2f), y + Mathf.range(size * tilesize / 2f));
}
coolant = 1f + (used * liquid.heatCapacity * coolantMultiplier);
coolantMultiplier = 1f + (used * liquid.heatCapacity * coolantMultiplier);
}
any = false;
@@ -134,9 +131,14 @@ public class TractorBeamTurret extends BaseTurret{
}
}
@Override
public boolean shouldConsume(){
return super.shouldConsume() && target != null;
}
@Override
public float efficiency(){
return super.efficiency() * coolant;
return super.efficiency() * coolantMultiplier;
}
@Override

View File

@@ -381,14 +381,14 @@ public class Turret extends ReloadTurret{
}
}
if(acceptCoolant){
if(coolant != null){
updateCooling();
}
}
@Override
public void handleLiquid(Building source, Liquid liquid, float amount){
if(acceptCoolant && liquids.currentAmount() <= 0.001f){
if(coolant != null && liquids.currentAmount() <= 0.001f){
Events.fire(Trigger.turretCool);
}

View File

@@ -43,6 +43,7 @@ public class ConsumeItemFilter extends Consume{
Item item = content.item(i);
if(build.items != null && build.items.has(item) && this.filter.get(item)){
build.items.remove(item, 1);
build.filterConsItem = item;
break;
}
}

View File

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

View File

@@ -3,6 +3,7 @@ package mindustry.world.consumers;
import arc.func.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.ui.*;
@@ -34,19 +35,38 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{
Seq<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.get(l));
MultiReqImage image = new MultiReqImage();
list.each(liquid -> image.add(new ReqImage(liquid.uiIcon, () ->
build.liquids != null && build.liquids.current() == liquid && build.liquids.get(liquid) >= Math.max(use(build), amount * build.delta()))));
build.liquids != null && build.liquids.get(liquid) >= Math.max(use(build), amount * build.delta()))));
table.add(image).size(8 * 4);
}
@Override
public void update(Building build){
build.liquids.remove(build.liquids.current(), use(build));
Liquid liq = match(build);
build.liquids.remove(liq, use(build));
build.filterConsLiquid = liq;
}
@Override
public boolean valid(Building build){
return build != null && build.liquids != null && filter.get(build.liquids.current()) && build.liquids.currentAmount() >= use(build);
var liq = match(build);
return liq != null && build.liquids.get(liq) >= use(build);
}
@Nullable Liquid match(Building build){
if(filter.get(build.liquids.current())){
return build.liquids.current();
}
var liqs = content.liquids();
for(int i = 0; i < liqs.size; i++){
var liq = liqs.get(i);
if(filter.get(liq) && build.liquids.get(liq) > 0){
return liq;
}
}
return null;
}
@Override