WIP flux reactor
This commit is contained in:
@@ -134,13 +134,13 @@ public class StackConveyor extends Block implements Autotiler{
|
||||
for(int i = 0; i < 4; i++){
|
||||
int dir = rotation - i;
|
||||
var near = nearby(dir);
|
||||
if((blendprox & (1 << i)) != 0 && i != 0 && near != null && !near.block.fillsTile){
|
||||
if((blendprox & (1 << i)) != 0 && i != 0 && near != null && !near.block.squareSprite){
|
||||
Draw.rect(sliced(regions[0], SliceMode.bottom), x + Geometry.d4x(dir) * tilesize*0.75f, y + Geometry.d4y(dir) * tilesize*0.75f, (float)(dir*90));
|
||||
}
|
||||
}
|
||||
}else if(state == stateUnload){ //front unload
|
||||
//TOOD hacky front check
|
||||
if((blendprox & (1)) != 0 && !front().block.fillsTile){
|
||||
if((blendprox & (1)) != 0 && !front().block.squareSprite){
|
||||
Draw.rect(sliced(regions[0], SliceMode.top), x + Geometry.d4x(rotation) * tilesize*0.75f, y + Geometry.d4y(rotation) * tilesize*0.75f, rotation * 90f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import arc.audio.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
@@ -25,8 +24,6 @@ import static mindustry.Vars.*;
|
||||
public class NuclearReactor extends PowerGenerator{
|
||||
public final int timerFuel = timers++;
|
||||
|
||||
public final Vec2 tr = new Vec2();
|
||||
|
||||
public Color lightColor = Color.valueOf("7f19ea");
|
||||
public Color coolColor = new Color(1, 1, 1, 0f);
|
||||
public Color hotColor = Color.valueOf("ff9575a3");
|
||||
|
||||
@@ -1,24 +1,151 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import arc.*;
|
||||
import arc.audio.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.effect.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.heat.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class VariableReactor extends PowerGenerator{
|
||||
//TODO
|
||||
public float maxEfficiency = 1f;
|
||||
//TODO
|
||||
public float maxHeat = 100f;
|
||||
/** How quickly instability moves towards 1, per frame. */
|
||||
public float unstableSpeed = 1f / 60f / 3f;
|
||||
public float warmupSpeed = 0.1f;
|
||||
public Effect effect = Fx.fluxVapor;
|
||||
public float effectChance = 0.05f;
|
||||
public Color effectColor = Color.valueOf("ffdf9d");
|
||||
|
||||
public float flashThreshold = 0.01f, flashAlpha = 0.4f, flashSpeed = 7f;
|
||||
public Color flashColor1 = Color.red, flashColor2 = Color.valueOf("89e8b6");
|
||||
|
||||
public int explosionRadius = 12;
|
||||
public int explosionDamage = 1000;
|
||||
public Effect explodeEffect = new MultiEffect(Fx.bigShockwave, new WrapEffect(Fx.titanSmoke, Color.valueOf("e3ae6f")));
|
||||
public Sound explodeSound = Sounds.explosionbig;
|
||||
|
||||
public int puddles = 70;
|
||||
public float puddleRange = tilesize * 6f;
|
||||
public Liquid puddleLiquid = Liquids.slag;
|
||||
public float puddleAmount = 100f;
|
||||
|
||||
public @Load("@-lights") TextureRegion lightsRegion;
|
||||
|
||||
public VariableReactor(String name){
|
||||
super(name);
|
||||
powerProduction = 20f;
|
||||
rebuildable = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
addBar("instability", (VariableReactorBuild entity) -> new Bar("bar.instability", Pal.sap, () -> entity.instability));
|
||||
|
||||
addBar("heat", (VariableReactorBuild entity) ->
|
||||
new Bar(() ->
|
||||
Core.bundle.format("bar.heatpercent", (int)entity.heat, (int)(Mathf.clamp(entity.heat / maxHeat) * 100)),
|
||||
() -> Pal.lightOrange,
|
||||
() -> entity.heat / maxHeat));
|
||||
}
|
||||
|
||||
//TODO: draw warmup fraction on block?
|
||||
public class VariableReactorBuild extends GeneratorBuild implements HeatConsumer{
|
||||
public float[] sideHeat = new float[4];
|
||||
public float heat = 0f;
|
||||
public float heat = 0f, instability, totalProgress, warmup, flash;
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
heat = calculateHeat(sideHeat);
|
||||
|
||||
productionEfficiency = Mathf.clamp(heat / maxHeat);
|
||||
warmup = Mathf.lerpDelta(warmup, productionEfficiency > 0 ? 1f : 0f, warmupSpeed);
|
||||
|
||||
if(instability >= 1f){
|
||||
kill();
|
||||
}
|
||||
|
||||
totalProgress += productionEfficiency * Time.delta;
|
||||
|
||||
if(Mathf.chanceDelta(effectChance * warmup)){
|
||||
effect.at(x, y, effectColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyed(){
|
||||
super.onDestroyed();
|
||||
|
||||
if(!state.rules.reactorExplosions) return;
|
||||
|
||||
Damage.damage(x, y, explosionRadius * tilesize, explosionDamage);
|
||||
|
||||
explodeEffect.at(this);
|
||||
explodeSound.at(this);
|
||||
|
||||
for(int i = 0; i < puddles; i++){
|
||||
Tmp.v1.trns(Mathf.random(360f), Mathf.random(puddleRange));
|
||||
Tile tile = world.tileWorld(x + Tmp.v1.x, y + Tmp.v1.y);
|
||||
Puddles.deposit(tile, puddleLiquid, puddleAmount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
if(instability > flashThreshold){
|
||||
if(!state.isPaused()) flash += (1f + ((instability - flashThreshold) / (1f - flashThreshold)) * flashSpeed) * Time.delta;
|
||||
Draw.z(Layer.blockAdditive);
|
||||
Draw.blend(Blending.additive);
|
||||
Draw.color(flashColor1, flashColor2, Mathf.absin(flash, 8f, 1f));
|
||||
Draw.alpha(flashAlpha * Mathf.clamp((instability - flashThreshold) / (1f - flashThreshold) * 4f));
|
||||
Draw.rect(lightsRegion, x, y);
|
||||
Draw.blend();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float totalProgress(){
|
||||
return totalProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float warmup(){
|
||||
return warmup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEfficiencyMultiplier(){
|
||||
//at this stage efficiency = how much coolant is provided
|
||||
|
||||
//target efficiency value
|
||||
float target = Mathf.clamp(heat / maxHeat);
|
||||
|
||||
//fraction of coolant provided (from what is needed)
|
||||
float efficiencyMet = Mathf.clamp(Mathf.zero(target) ? 1f : efficiency / target);
|
||||
boolean met = efficiencyMet >= 0.99999f;
|
||||
|
||||
//if all requirements are met, instability moves toward 0 at 50% of speed
|
||||
//if requirements are not meant, instability approaches 1 at a speed scaled by how much efficiency is *not* met
|
||||
instability = Mathf.approachDelta(instability, met ? 0f : 1f, met ? 0.5f : unstableSpeed * (1f - efficiencyMet));
|
||||
|
||||
//now scale efficiency by target, so it consumes less depending on heat
|
||||
efficiency *= target;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,8 +155,25 @@ public class VariableReactor extends PowerGenerator{
|
||||
|
||||
@Override
|
||||
public float heatRequirement(){
|
||||
//TODO
|
||||
return maxHeat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
|
||||
write.f(heat);
|
||||
write.f(instability);
|
||||
write.f(warmup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
|
||||
heat = read.f();
|
||||
instability = read.f();
|
||||
warmup = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user