Turret requirement cleanup / WIP ContinuousTurret type
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import mindustry.world.meta.*;
|
|||||||
|
|
||||||
import static mindustry.Vars.*;
|
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 class LaserTurret extends PowerTurret{
|
||||||
public float firingMoveFract = 0.25f;
|
public float firingMoveFract = 0.25f;
|
||||||
public float shootDuration = 100f;
|
public float shootDuration = 100f;
|
||||||
@@ -24,7 +25,7 @@ public class LaserTurret extends PowerTurret{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
consumes.powerCond(powerUse, (LaserTurretBuild entity) -> entity.bullet != null || entity.target != null);
|
consumes.power(powerUse);
|
||||||
super.init();
|
super.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +46,12 @@ public class LaserTurret extends PowerTurret{
|
|||||||
//do nothing, cooling is irrelevant here
|
//do nothing, cooling is irrelevant here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldConsume(){
|
||||||
|
//still consumes power when bullet is around
|
||||||
|
return bullet != null || isActive();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTile(){
|
public void updateTile(){
|
||||||
super.updateTile();
|
super.updateTile();
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class PowerTurret extends Turret{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
consumes.powerCond(powerUse, TurretBuild::isActive);
|
consumes.power(powerUse);
|
||||||
super.init();
|
super.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -177,6 +177,11 @@ public class Turret extends ReloadTurret{
|
|||||||
return rotation - 90;
|
return rotation - 90;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldConsume(){
|
||||||
|
return isActive();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canControl(){
|
public boolean canControl(){
|
||||||
return playerControllable;
|
return playerControllable;
|
||||||
|
|||||||
Reference in New Issue
Block a user