diff --git a/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java b/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java new file mode 100644 index 0000000000..2f98a84448 --- /dev/null +++ b/core/src/mindustry/world/blocks/defense/turrets/ContinuousTurret.java @@ -0,0 +1,109 @@ +package mindustry.world.blocks.defense.turrets; + +import arc.math.*; +import arc.struct.*; +import mindustry.entities.bullet.*; +import mindustry.gen.*; +import mindustry.logic.*; +import mindustry.world.meta.*; + +/** A turret that fires a continuous beam bullet with no reload or coolant necessary. The bullet only disappears when the turret stops shooting. */ +public class ContinuousTurret extends Turret{ + public BulletType shootType; + + public ContinuousTurret(String name){ + super(name); + + coolantMultiplier = 1f; + envEnabled |= Env.space; + acceptCoolant = false; + } + + @Override + public void setStats(){ + super.setStats(); + + stats.add(Stat.ammo, StatValues.ammo(ObjectMap.of(this, shootType))); + } + + public class ContinuousTurretBuild extends TurretBuild{ + public Bullet bullet; + + @Override + protected void updateCooling(){ + //TODO how does coolant work here, if at all? + } + + @Override + public BulletType useAmmo(){ + //nothing used directly + return shootType; + } + + @Override + public boolean hasAmmo(){ + return consValid(); + } + + @Override + public BulletType peekAmmo(){ + return shootType; + } + + @Override + public void updateTile(){ + 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()){ + bullet = null; + } + } + } + + @Override + public double sense(LAccess sensor){ + //no concept of reload here + if(sensor == LAccess.progress) return bullet == null ? 0f : 1f; + return super.sense(sensor); + } + + @Override + protected void updateShooting(){ + if(bullet != null){ + return; + } + + if(reload <= 0 && (consValid() || cheating()) && !charging){ + BulletType type = peekAmmo(); + shoot(type); + } + } + + @Override + protected void turnToTarget(float targetRot){ + rotation = Angles.moveToward(rotation, targetRot, efficiency() * rotateSpeed * delta()); + } + + @Override + protected void bullet(BulletType type, float angle){ + bullet = type.create(this, team, x + bulletOffset.x, y + bulletOffset.y, angle); + } + + @Override + public boolean shouldActiveSound(){ + return bullet != null; + } + } +} diff --git a/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java b/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java index 888a7d06be..6fa20f60d1 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java @@ -11,6 +11,7 @@ import mindustry.world.meta.*; import static mindustry.Vars.*; +/** A turret that fires a continuous beam with a delay between shots. Liquid coolant is required. */ public class LaserTurret extends PowerTurret{ public float firingMoveFract = 0.25f; public float shootDuration = 100f; @@ -24,7 +25,7 @@ public class LaserTurret extends PowerTurret{ @Override public void init(){ - consumes.powerCond(powerUse, (LaserTurretBuild entity) -> entity.bullet != null || entity.target != null); + consumes.power(powerUse); super.init(); } @@ -45,6 +46,12 @@ public class LaserTurret extends PowerTurret{ //do nothing, cooling is irrelevant here } + @Override + public boolean shouldConsume(){ + //still consumes power when bullet is around + return bullet != null || isActive(); + } + @Override public void updateTile(){ super.updateTile(); diff --git a/core/src/mindustry/world/blocks/defense/turrets/PowerTurret.java b/core/src/mindustry/world/blocks/defense/turrets/PowerTurret.java index 4b19d33284..e3956cf2fc 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/PowerTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/PowerTurret.java @@ -23,7 +23,7 @@ public class PowerTurret extends Turret{ @Override public void init(){ - consumes.powerCond(powerUse, TurretBuild::isActive); + consumes.power(powerUse); super.init(); } diff --git a/core/src/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/mindustry/world/blocks/defense/turrets/Turret.java index fc574f7e03..10bf0ef956 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/Turret.java @@ -177,6 +177,11 @@ public class Turret extends ReloadTurret{ return rotation - 90; } + @Override + public boolean shouldConsume(){ + return isActive(); + } + @Override public boolean canControl(){ return playerControllable;