Turret requirement cleanup / WIP ContinuousTurret type

This commit is contained in:
Anuken
2021-11-22 13:59:09 -05:00
parent f7cf35369b
commit d218480f6f
4 changed files with 123 additions and 2 deletions

View File

@@ -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;
}
}
}

View File

@@ -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();

View File

@@ -23,7 +23,7 @@ public class PowerTurret extends Turret{
@Override
public void init(){
consumes.powerCond(powerUse, TurretBuild::isActive);
consumes.power(powerUse);
super.init();
}

View File

@@ -177,6 +177,11 @@ public class Turret extends ReloadTurret{
return rotation - 90;
}
@Override
public boolean shouldConsume(){
return isActive();
}
@Override
public boolean canControl(){
return playerControllable;