WIP pressure turbine

This commit is contained in:
Anuken
2021-10-27 18:25:58 -04:00
parent 7843785182
commit 3ee7ee7e79
10 changed files with 85 additions and 19 deletions

View File

@@ -30,8 +30,6 @@ public interface Autotiler{
}
/**
* Slices a texture region depending on the SliceMode paramater
*
* @param input The TextureRegion to be sliced
* @param mode The SliceMode to be applied
* @return The sliced texture
@@ -40,12 +38,7 @@ public interface Autotiler{
return mode == SliceMode.none ? input : mode == SliceMode.bottom ? botHalf(input) : topHalf(input);
}
/**
* Get the top half of a texture
*
* @param input The TextureRegion to slice
* @return The top half of the texture
*/
/** @return The top half of the input */
default TextureRegion topHalf(TextureRegion input){
TextureRegion region = Tmp.tr1;
region.set(input);
@@ -53,12 +46,7 @@ public interface Autotiler{
return region;
}
/**
* Get the buttom half of a texture
*
* @param input The TextureRegion to slice
* @return The buttom half of the texture
*/
/** @return The bottom half of the input */
default TextureRegion botHalf(TextureRegion input){
TextureRegion region = Tmp.tr1;
region.set(input);

View File

@@ -2,25 +2,42 @@ package mindustry.world.blocks.power;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.game.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.meta.*;
public class ThermalGenerator extends PowerGenerator{
public Effect generateEffect = Fx.none;
public float effectChance = 0.05f;
public float minEfficiency = 0f;
public float spinSpeed = 1f;
public float displayEfficiencyScale = 1f;
public boolean spinners = false;
public boolean displayEfficiency = true;
public @Nullable LiquidStack liquidOutput;
public Attribute attribute = Attribute.heat;
public @Load("@-rotator") TextureRegion rotatorRegion;
public @Load("@-rotator-blur") TextureRegion blurRegion;
public ThermalGenerator(String name){
super(name);
}
@Override
public void init(){
if(liquidOutput != null){
outputsLiquid = true;
hasLiquids = true;
}
super.init();
//proper light clipping
clipSize = Math.max(clipSize, 45f * size * 2f * 2f);
@@ -30,24 +47,32 @@ public class ThermalGenerator extends PowerGenerator{
public void setStats(){
super.setStats();
stats.add(Stat.tiles, attribute, floating, size * size, false);
stats.add(Stat.tiles, attribute, floating, size * size * displayEfficiencyScale, !displayEfficiency);
}
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
super.drawPlace(x, y, rotation, valid);
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", sumAttribute(attribute, x, y) * 100, 1), x, y, valid);
if(displayEfficiency){
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", sumAttribute(attribute, x, y) * 100, 1), x, y, valid);
}
}
@Override
public boolean canPlaceOn(Tile tile, Team team, int rotation){
//make sure there's heat at this location
return tile.getLinkedTilesAs(this, tempTiles).sumf(other -> other.floor().attributes.get(attribute)) > 0.01f;
return tile.getLinkedTilesAs(this, tempTiles).sumf(other -> other.floor().attributes.get(attribute)) > minEfficiency;
}
@Override
public TextureRegion[] icons(){
return spinners ? new TextureRegion[]{region, rotatorRegion} : super.makeIconRegions();
}
public class ThermalGeneratorBuild extends GeneratorBuild{
public float sum;
public float spinRotation;
@Override
public void updateTile(){
@@ -56,6 +81,23 @@ public class ThermalGenerator extends PowerGenerator{
if(productionEfficiency > 0.1f && Mathf.chanceDelta(effectChance)){
generateEffect.at(x + Mathf.range(3f), y + Mathf.range(3f));
}
spinRotation += productionEfficiency * spinSpeed;
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 void draw(){
super.draw();
if(spinners){
Drawf.spinSprite(blurRegion.found() ? blurRegion : rotatorRegion, x, y, spinRotation);
}
}
@Override