Sublimate visuals, damage/length still broken

This commit is contained in:
Anuken
2021-11-24 12:30:01 -05:00
parent ba14151a01
commit 211c0b2e71
32 changed files with 177 additions and 72 deletions
@@ -55,19 +55,19 @@ public class ContinuousTurret extends Turret{
super.updateTile();
if(bullet != null){
wasShooting = true;
bullet.rotation(rotation);
bullet.set(x + bulletOffset.x, y + bulletOffset.y);
heat = 1f;
recoil = recoilAmount;
if(isShooting()){
bullet.time = 0f;
}
//check to see if bullet despawned
if(bullet.owner != this || !bullet.isAdded()){
if(bullet.owner != this || !bullet.isAdded() || bullet.type == null){
bullet = null;
}else{
wasShooting = true;
bullet.rotation(rotation);
bullet.set(x + bulletOffset.x, y + bulletOffset.y);
heat = 1f;
recoil = recoilAmount;
if(isShooting()){
bullet.time = bullet.lifetime * bullet.type.optimalLifeFract * shootWarmup;
}
}
}
}
@@ -4,14 +4,13 @@ import arc.math.*;
import arc.util.*;
import mindustry.entities.bullet.*;
import mindustry.gen.*;
import mindustry.logic.*;
import mindustry.type.*;
import mindustry.world.consumers.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
/** A turret that fires a continuous beam with a delay between shots. Liquid coolant is required. */
/** A turret that fires a continuous beam with a delay between shots. Liquid coolant is required. Yes, this class name is awful. */
public class LaserTurret extends PowerTurret{
public float firingMoveFract = 0.25f;
public float shootDuration = 100f;
@@ -56,11 +55,15 @@ public class LaserTurret extends PowerTurret{
public void updateTile(){
super.updateTile();
if(!bullet.isAdded() || bullet.type == null){
bullet = null;
}
if(bulletLife > 0 && bullet != null){
wasShooting = true;
bullet.rotation(rotation);
bullet.set(x + bulletOffset.x, y + bulletOffset.y);
bullet.time = 0f;
bullet.time = bullet.type.lifetime * bullet.type.optimalLifeFract;
heat = 1f;
recoil = recoilAmount;
bulletLife -= Time.delta / Math.max(efficiency(), 0.00001f);
@@ -83,10 +86,8 @@ public class LaserTurret extends PowerTurret{
}
@Override
public double sense(LAccess sensor){
//reload reversed for laser turrets
if(sensor == LAccess.progress) return Mathf.clamp(1f - reload / reloadTime);
return super.sense(sensor);
public float progress(){
return 1f - Mathf.clamp(reload / reloadTime);
}
@Override
@@ -48,7 +48,7 @@ public class Turret extends ReloadTurret{
public float ammoEjectBack = 1f;
public float inaccuracy = 0f;
public float velocityInaccuracy = 0f;
public float shootWarmupSpeed = 3f / 60f;
public float shootWarmupSpeed = 0.1f;
public int shots = 1;
public float spread = 4f;
public float recoilAmount = 1f;
@@ -152,7 +152,7 @@ public class Turret extends ReloadTurret{
@Override
public void getRegionsToOutline(Seq<TextureRegion> out){
draw.getRegionsToOutline(out);
draw.getRegionsToOutline(this, out);
}
public static abstract class AmmoEntry{
@@ -233,11 +233,16 @@ public class Turret extends ReloadTurret{
case shootX -> World.conv(targetPos.x);
case shootY -> World.conv(targetPos.y);
case shooting -> isShooting() ? 1 : 0;
case progress -> Mathf.clamp(reload / reloadTime);
case progress -> progress();
default -> super.sense(sensor);
};
}
@Override
public float progress(){
return Mathf.clamp(reload / reloadTime);
}
public boolean isShooting(){
return (isControlled() ? unit.isShooting() : logicControlled() ? logicShooting : target != null);
}
@@ -286,7 +291,7 @@ public class Turret extends ReloadTurret{
if(!validateTarget()) target = null;
//TODO can be lerp instead, that's smoother
shootWarmup = Mathf.approachDelta(shootWarmup, isActive() ? 1f : 0f, shootWarmupSpeed);
shootWarmup = Mathf.lerpDelta(shootWarmup, isShooting() ? 1f : 0f, shootWarmupSpeed);
wasShooting = false;
@@ -140,7 +140,7 @@ public class GenericCrafter extends Block{
@Override
public void getRegionsToOutline(Seq<TextureRegion> out){
drawer.getRegionsToOutline(out);
drawer.getRegionsToOutline(this, out);
}
public class GenericCrafterBuild extends Building{
@@ -254,12 +254,17 @@ public class GenericCrafter extends Block{
@Override
public double sense(LAccess sensor){
if(sensor == LAccess.progress) return Mathf.clamp(progress);
if(sensor == LAccess.progress) return progress();
//attempt to prevent wild total liquid fluctuation, at least for crafters
if(sensor == LAccess.totalLiquids && outputLiquid != null) return liquids.get(outputLiquid.liquid);
return super.sense(sensor);
}
@Override
public float progress(){
return Mathf.clamp(progress);
}
@Override
public int getMaximumAccepted(Item item){
return itemCapacity;
+1 -1
View File
@@ -23,7 +23,7 @@ public class DrawBlock{
@Deprecated
public void drawLight(GenericCrafterBuild build){}
public void getRegionsToOutline(Seq<TextureRegion> out){
public void getRegionsToOutline(Block block, Seq<TextureRegion> out){
}
+2 -2
View File
@@ -25,9 +25,9 @@ public class DrawMulti extends DrawBlock{
}
@Override
public void getRegionsToOutline(Seq<TextureRegion> out){
public void getRegionsToOutline(Block block, Seq<TextureRegion> out){
for(var draw : drawers){
draw.getRegionsToOutline(out);
draw.getRegionsToOutline(block, out);
}
}
+59 -28
View File
@@ -8,6 +8,7 @@ import arc.struct.*;
import arc.util.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.defense.turrets.*;
import mindustry.world.blocks.defense.turrets.Turret.*;
@@ -18,7 +19,9 @@ public class DrawTurret extends DrawBlock{
public Seq<TurretPart> parts = new Seq<>();
public String basePrefix = "";
public TextureRegion base, liquid, top, heat, preview;
/** Overrides the liquid to draw in the liquid region. */
public @Nullable Liquid liquidDraw;
public TextureRegion base, liquid, top, heat, preview, outline;
public DrawTurret(String basePrefix){
this.basePrefix = basePrefix;
@@ -28,10 +31,13 @@ public class DrawTurret extends DrawBlock{
}
@Override
public void getRegionsToOutline(Seq<TextureRegion> out){
public void getRegionsToOutline(Block block, Seq<TextureRegion> out){
for(var part : parts){
part.getOutlines(out);
}
if(preview.found()){
out.add(block.region);
}
}
@Override
@@ -42,14 +48,22 @@ public class DrawTurret extends DrawBlock{
Draw.rect(base, build.x, build.y);
Draw.color();
Draw.z(Layer.turret);
Draw.z(Layer.turret - 0.02f);
Drawf.shadow(build.block.region, build.x + tb.recoilOffset.x - turret.elevation, build.y + tb.recoilOffset.y - turret.elevation, tb.drawrot());
Drawf.shadow(preview, build.x + tb.recoilOffset.x - turret.elevation, build.y + tb.recoilOffset.y - turret.elevation, tb.drawrot());
Draw.z(Layer.turret);
drawTurret(turret, tb);
drawHeat(turret, tb);
if(parts.size > 0){
if(outline.found()){
Draw.z(Layer.turret - 0.01f);
Draw.rect(outline, build.x + tb.recoilOffset.x, build.y + tb.recoilOffset.y, tb.drawrot());
Draw.z(Layer.turret);
}
for(var part : parts){
part.draw(tb);
}
@@ -60,7 +74,8 @@ public class DrawTurret extends DrawBlock{
Draw.rect(block.region, build.x + build.recoilOffset.x, build.y + build.recoilOffset.y, build.drawrot());
if(liquid.found()){
Drawf.liquid(liquid, build.x + build.recoilOffset.x, build.y + build.recoilOffset.y, build.liquids.currentAmount() / block.liquidCapacity, build.liquids.current().color, build.drawrot());
Liquid toDraw = liquidDraw == null ? build.liquids.current() : liquidDraw;
Drawf.liquid(liquid, build.x + build.recoilOffset.x, build.y + build.recoilOffset.y, build.liquids.get(toDraw) / block.liquidCapacity, toDraw.color.write(Tmp.c1).a(1f), build.drawrot());
}
if(top.found()){
@@ -71,11 +86,7 @@ public class DrawTurret extends DrawBlock{
public void drawHeat(Turret block, TurretBuild build){
if(build.heat <= 0.00001f || !heat.found()) return;
Draw.color(block.heatColor, build.heat);
Draw.blend(Blending.additive);
Draw.rect(heat, build.x + build.recoilOffset.x, build.y + build.recoilOffset.y, build.drawrot());
Draw.blend();
Draw.color();
Drawf.additive(heat, block.heatColor.write(Tmp.c1).a(build.heat), build.x + build.recoilOffset.x, build.y + build.recoilOffset.y, build.drawrot(), Layer.turretHeat);
}
/** Load any relevant texture regions. */
@@ -84,6 +95,7 @@ public class DrawTurret extends DrawBlock{
if(!(block instanceof Turret)) throw new ClassCastException("This drawer can only be used on turrets.");
preview = Core.atlas.find(block.name + "-preview", block.region);
outline = Core.atlas.find(block.name + "-outline");
liquid = Core.atlas.find(block.name + "-liquid");
top = Core.atlas.find(block.name + "-top");
heat = Core.atlas.find(block.name + "-heat");
@@ -107,16 +119,25 @@ public class DrawTurret extends DrawBlock{
public static class RegionPart extends TurretPart{
public String suffix = "";
public boolean mirror = true;
public TextureRegion heat;
public TextureRegion[] regions;
public TextureRegion[] outlines;
public boolean outline = false;
/** If true, turret reload is used as the measure of progress. Otherwise, warmup is used. */
public boolean useReload = false;
/** If true, parts are mirrored across the turret. Requires -1 and -2 regions. */
public boolean mirror = true;
/** If true, an outline is drawn under the part. */
public boolean outline = true;
/** If true, the layer is overridden to be under the turret itself. */
public boolean under = false;
public float layer = -1;
public float outlineLayerOffset = -0.01f;
public float rotation, rotMove;
public float originX, originY;
public float offsetX, offsetY, offsetMoveX, offsetMoveY;
public float x, y, moveX, moveY;
public float oscMag = 0f, oscScl = 7f;
public boolean oscAbs = false;
public Color heatColor = Pal.turretHeat.cpy();
public RegionPart(String region){
this.suffix = region;
@@ -133,32 +154,38 @@ public class DrawTurret extends DrawBlock{
}
float prevZ = layer > 0 ? layer : z;
float progress = build.warmup();
float progress = useReload ? build.progress() : build.warmup();
if(oscMag > 0){
progress += oscAbs ? Mathf.absin(oscScl, oscMag) : Mathf.sin(oscScl, oscMag);
}
for(int i = 0; i < regions.length; i++){
var region = regions[i];
float sign = i == 1 ? -1 : 1;
Tmp.v1.set((offsetX + offsetMoveX * progress) * sign, offsetY + offsetMoveY*progress).rotate(build.rotation - 90);
Tmp.v1.set((x + moveX * progress) * sign, y + moveY * progress).rotate((build.rotation - 90));
float
x = build.x + Tmp.v1.x,
y = build.y + Tmp.v1.y,
rot = (i == 0 ? rotation : 180f - rotation) + rotMove * progress * sign + build.rotation,
ox = originX + region.width * Draw.scl/2f, oy = originY + region.height * Draw.scl/2f;
rx = build.x + Tmp.v1.x + build.recoilOffset.x,
ry = build.y + Tmp.v1.y + build.recoilOffset.y,
rot = i * sign + rotMove * progress * sign + build.rotation - 90;
Draw.xscl = i == 0 ? 1 : -1;
if(outline){
Draw.z(prevZ + outlineLayerOffset);
Draw.rect(outlines[i],
x, y, region.width * Draw.scl, region.height * Draw.scl,
ox, oy, rot);
Draw.rect(outlines[i], rx, ry, rot);
Draw.z(prevZ);
}
Draw.rect(region,
x, y, region.width * Draw.scl, region.height * Draw.scl,
ox, oy, rot);
if(region.found()){
Draw.rect(region, rx, ry, rot);
}
if(heat.found()){
Drawf.additive(heat, heatColor.write(Tmp.c1).a(build.heat), rx, ry, rot, Layer.turretHeat);
}
Draw.xscl = 1f;
}
Draw.z(z);
@@ -166,6 +193,8 @@ public class DrawTurret extends DrawBlock{
@Override
public void load(Block block){
if(under) layer = Layer.turret - 0.0001f;
if(mirror){
regions = new TextureRegion[]{
Core.atlas.find(block.name + suffix + "1"),
@@ -180,6 +209,8 @@ public class DrawTurret extends DrawBlock{
regions = new TextureRegion[]{Core.atlas.find(block.name + suffix)};
outlines = new TextureRegion[]{Core.atlas.find(block.name + suffix + "-outline")};
}
heat = Core.atlas.find(block.name + suffix + "-heat");
}
@Override