Turret pattern rewrite

This commit is contained in:
Anuken 2022-02-24 23:29:36 -05:00
parent c3e9a961c5
commit 45f27eaeec
17 changed files with 239 additions and 240 deletions

View file

@ -8,6 +8,7 @@ import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
import mindustry.entities.part.*;
import mindustry.entities.pattern.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
@ -2725,9 +2726,11 @@ public class Blocks{
Items.silicon, Bullets.standardHoming
);
spread = 4f;
shots = 2;
alternate = true;
shoot = new ShootAlternate(){{
spread = 3.5f;
}};
shootY = 3f;
reloadTime = 20f;
restitution = 0.03f;
range = 110;
@ -2751,10 +2754,11 @@ public class Blocks{
reloadTime = 18f;
range = 220f;
size = 2;
burstSpacing = 5f;
shots = 2;
targetGround = false;
shoot.shotDelay = 5f;
shoot.shots = 2;
recoilAmount = 2f;
rotateSpeed = 15f;
inaccuracy = 17f;
@ -2828,17 +2832,15 @@ public class Blocks{
lancer = new PowerTurret("lancer"){{
requirements(Category.turret, with(Items.copper, 60, Items.lead, 70, Items.silicon, 50));
range = 165f;
chargeTime = 40f;
chargeMaxDelay = 30f;
chargeEffects = 7;
shoot.firstShotDelay = 40f;
recoilAmount = 2f;
reloadTime = 80f;
cooldown = 0.03f;
shootShake = 2f;
shootEffect = Fx.lancerLaserShoot;
smokeEffect = Fx.none;
chargeEffect = Fx.lancerLaserCharge;
chargeBeginEffect = Fx.lancerLaserChargeBegin;
heatColor = Color.red;
size = 2;
scaledHealth = 280;
@ -2850,6 +2852,9 @@ public class Blocks{
shootType = new LaserBulletType(140){{
colors = new Color[]{Pal.lancerLaser.cpy().a(0.4f), Pal.lancerLaser, Color.white};
//TODO merge
chargeEffect = new MultiEffect(Fx.lancerLaserCharge, Fx.lancerLaserChargeBegin);
hitEffect = Fx.hitLancer;
hitSize = 4;
lifetime = 16f;
@ -2905,12 +2910,16 @@ public class Blocks{
Items.pyratite, Bullets.missileIncendiary,
Items.surgeAlloy, Bullets.missileSurge
);
shoot = new ShootAlternate(){{
shots = 4;
spread = 3.5f;
shotDelay = 5f;
}};
reloadTime = 30f;
shots = 4;
burstSpacing = 5;
inaccuracy = 10f;
range = 240f;
xRand = 6f;
size = 2;
scaledHealth = 300;
shootSound = Sounds.missile;
@ -2938,9 +2947,9 @@ public class Blocks{
cooldown = 0.03f;
recoilAmount = 3f;
shootShake = 1f;
burstSpacing = 3f;
spread = 0f;
shots = 4;
shoot.shots = 4;
shoot.shotDelay = 3f;
ammoUseEffect = Fx.casing2;
scaledHealth = 240;
shootSound = Sounds.shootBig;
@ -2973,7 +2982,7 @@ public class Blocks{
);
size = 3;
reloadTime = 3f;
shots = 2;
shoot.shots = 2;
velocityInaccuracy = 0.1f;
inaccuracy = 4f;
recoilAmount = 1f;
@ -2993,8 +3002,12 @@ public class Blocks{
shootShake = 4f;
range = 90f;
recoilAmount = 5f;
shots = 3;
spread = 20f;
shoot = new ShootSpread(){{
shots = 3;
spread = 20f;
}};
restitution = 0.1f;
shootCone = 30;
size = 3;
@ -3036,7 +3049,7 @@ public class Blocks{
targetAir = false;
size = 3;
shots = 4;
shoot.shots = 4;
inaccuracy = 12f;
reloadTime = 60f;
ammoEjectBack = 5f;
@ -3063,7 +3076,14 @@ public class Blocks{
Items.plastanium, Bullets.fragPlastic,
Items.surgeAlloy, Bullets.fragSurge
);
xRand = 4f;
shootY = 8.75f;
shoot = new ShootBarrel(){{
barrels = new float[]{
0f, 1f, 0f,
3f, 0f, 0f,
-3f, 0f, 0f,
};
}};
reloadTime = 8f;
range = 200f;
size = 3;
@ -3107,7 +3127,6 @@ public class Blocks{
restitution = 0.009f;
cooldown = 0.009f;
shootShake = 4f;
shots = 1;
size = 4;
shootCone = 2f;
shootSound = Sounds.railgun;
@ -3135,10 +3154,10 @@ public class Blocks{
range = 260f;
inaccuracy = 3f;
recoilAmount = 3f;
spread = 8f;
alternate = true;
shoot = new ShootAlternate(){{
spread = 8f;
}};
shootShake = 2f;
shots = 2;
size = 4;
shootCone = 24f;
shootSound = Sounds.shootBig;
@ -3165,6 +3184,11 @@ public class Blocks{
loopSoundVolume = 2f;
envEnabled |= Env.space;
shoot = new ShootSpread(){{
shots = 3;
spread = 10f;
}};
shootType = new ContinuousLaserBulletType(78){{
length = 200f;
hitEffect = Fx.hitMeltdown;
@ -3227,7 +3251,7 @@ public class Blocks{
shootShake = 1f;
ammoPerShot = 5;
draw = new DrawTurret("reinforced-");
shootLength = -2;
shootY = -2;
outlineColor = Pal.darkOutline;
size = 3;
envEnabled |= Env.space;
@ -3287,13 +3311,13 @@ public class Blocks{
liquidConsumed = 4f / 60f;
range = 130f;
float r = range = 130f;
//TODO balance, set up, where is liquid/sec displayed? status effects maybe?
ammo(
Liquids.ozone, new ContinuousFlameBulletType(){{
damage = 90f;
length = range;
length = r;
knockback = 1f;
colors = new Color[]{Color.valueOf("eb7abe").a(0.55f), Color.valueOf("e189f5").a(0.7f), Color.valueOf("907ef7").a(0.8f), Color.valueOf("91a4ff"), Color.white};
@ -3301,7 +3325,7 @@ public class Blocks{
Liquids.cyanogen, new ContinuousFlameBulletType(){{
damage = 200f;
rangeChange = 70f;
length = range + rangeChange;
length = r + rangeChange;
knockback = 2f;
colors = new Color[]{Color.valueOf("465ab8").a(0.55f), Color.valueOf("66a6d2").a(0.7f), Color.valueOf("89e8b6").a(0.8f), Color.valueOf("cafcbe"), Color.white};
@ -3312,7 +3336,7 @@ public class Blocks{
);
scaledHealth = 330;
shootLength = 7f;
shootY = 7f;
size = 3;
}};
@ -3359,7 +3383,7 @@ public class Blocks{
shootShake = 4f;
recoilAmount = 1f;
reloadTime = 60f * 2.3f;
shootLength = 7f;
shootY = 7f;
rotateSpeed = 1.4f;
minWarmup = 0.85f;
shootWarmupSpeed = 0.07f;
@ -3432,7 +3456,7 @@ public class Blocks{
reloadTime = 9f;
shootLength = 15f;
shootY = 15f;
rotateSpeed = 5f;
shootCone = 30f;
@ -3469,11 +3493,14 @@ public class Blocks{
}};
unitFilter = u -> !u.spawnedByCore;
shots = 4;
alternate = true;
widthSpread = true;
shoot = new ShootAlternate(){{
spread = 4.7f;
shots = 4;
barrels = 4;
}};
targetGround = false;
spread = 4.7f;
inaccuracy = 8f;
restitution = 0.11f;

View file

@ -1820,7 +1820,7 @@ public class Fx{
lancerLaserCharge = new Effect(38f, e -> {
color(Pal.lancerLaser);
randLenVectors(e.id, 2, 1f + 20f * e.fout(), e.rotation, 120f, (x, y) -> {
randLenVectors(e.id, 14, 1f + 20f * e.fout(), e.rotation, 120f, (x, y) -> {
lineAngle(e.x + x, e.y + y, Mathf.angle(x, y), e.fslope() * 3f + 1f);
});
}),

View file

@ -874,7 +874,7 @@ public class UnitTypes{
shadow = 12f;
recoil = 3f;
shoot = new SpreadPattern(){{
shoot = new ShootSpread(){{
shots = 2;
spread = 17f;
}};
@ -1695,7 +1695,7 @@ public class UnitTypes{
shake = 1f;
shootSound = Sounds.missile;
shoot = new AlternatePattern(){{
shoot = new ShootAlternate(){{
shots = 6;
shotDelay = 1.5f;
spread = 4f;
@ -2406,7 +2406,7 @@ public class UnitTypes{
reload = 15f;
x = 1f;
y = 2f;
shoot = new SpreadPattern(){{
shoot = new ShootSpread(){{
shots = 2;
shotDelay = 3f;
spread = 2f;
@ -2484,8 +2484,8 @@ public class UnitTypes{
weapons.add(new Weapon("locus-weapon"){{
layerOffset = 0.0001f;
reload = 70f;
shootY = 8f;
reload = 30f;
shootY = 9.3f;
recoil = 1f;
rotate = true;
rotateSpeed = 1.4f;
@ -2495,8 +2495,9 @@ public class UnitTypes{
heatColor = Color.valueOf("f9350f");
cooldownTime = 30f;
//TODO alternating double pattern
shoot.shots = 2;
shoot = new ShootAlternate(){{
spread = 3.5f;
}};
bullet = new BasicBulletType(5f, 50){{
sprite = "missile-large";

View file

@ -25,6 +25,7 @@ public class LiquidBulletType extends BulletType{
if(liquid != null){
this.liquid = liquid;
this.status = liquid.effect;
hitColor = liquid.color;
lightColor = liquid.lightColor;
lightOpacity = liquid.lightColor.a;
}

View file

@ -1,6 +1,6 @@
package mindustry.entities.pattern;
public class AlternatePattern extends ShotPattern{
public class ShootAlternate extends ShootPattern{
/** number of barrels used for shooting. */
public int barrels = 2;
/** spread between barrels, in world units - not degrees. */

View file

@ -0,0 +1,16 @@
package mindustry.entities.pattern;
public class ShootBarrel extends ShootPattern{
/** barrels [in x, y, rotation] format. */
public float[] barrels = {0f, 0f, 0f};
/** offset of barrel to start on */
public int barrelOffset = 0;
@Override
public void shoot(int totalShots, BulletHandler handler){
for(int i = 0; i < shots; i++){
int index = ((i + totalShots + barrelOffset) % (barrels.length / 3)) * 3;
handler.shoot(barrels[index], barrels[index + 1], barrels[index + 2], firstShotDelay + shotDelay * i);
}
}
}

View file

@ -1,15 +1,15 @@
package mindustry.entities.pattern;
public class MultiPattern extends ShotPattern{
public ShotPattern source;
public ShotPattern[] dest = {};
public class ShootMulti extends ShootPattern{
public ShootPattern source;
public ShootPattern[] dest = {};
public MultiPattern(ShotPattern source, ShotPattern... dest){
public ShootMulti(ShootPattern source, ShootPattern... dest){
this.source = source;
this.dest = dest;
}
public MultiPattern(){
public ShootMulti(){
}
@Override

View file

@ -1,7 +1,7 @@
package mindustry.entities.pattern;
/** Handles different types of bullet patterns for shooting. */
public class ShotPattern{
public class ShootPattern{
/** amount of shots per "trigger pull" */
public int shots = 1;
/** delay in ticks before first shot */

View file

@ -2,18 +2,18 @@ package mindustry.entities.pattern;
import arc.math.*;
public class SinePattern extends ShotPattern{
public class ShootSine extends ShootPattern{
/** scaling applied to bullet index */
public float scl = 4f;
/** magnitude of sine curve for position displacement */
public float mag = 20f;
public SinePattern(float scl, float mag){
public ShootSine(float scl, float mag){
this.scl = scl;
this.mag = mag;
}
public SinePattern(){
public ShootSine(){
}
@Override

View file

@ -1,6 +1,6 @@
package mindustry.entities.pattern;
public class SpreadPattern extends ShotPattern{
public class ShootSpread extends ShootPattern{
/** spread between bullets, in degrees. */
public float spread = 5f;

View file

@ -64,12 +64,13 @@ public class ClassMap{
classes.put("SeqEffect", mindustry.entities.effect.SeqEffect.class);
classes.put("WaveEffect", mindustry.entities.effect.WaveEffect.class);
classes.put("WrapEffect", mindustry.entities.effect.WrapEffect.class);
classes.put("AlternatePattern", mindustry.entities.pattern.AlternatePattern.class);
classes.put("MultiPattern", mindustry.entities.pattern.MultiPattern.class);
classes.put("ShotPattern", mindustry.entities.pattern.ShotPattern.class);
classes.put("BulletHandler", mindustry.entities.pattern.ShotPattern.BulletHandler.class);
classes.put("SinePattern", mindustry.entities.pattern.SinePattern.class);
classes.put("SpreadPattern", mindustry.entities.pattern.SpreadPattern.class);
classes.put("ShootAlternate", mindustry.entities.pattern.ShootAlternate.class);
classes.put("ShootBarrel", mindustry.entities.pattern.ShootBarrel.class);
classes.put("ShootMulti", mindustry.entities.pattern.ShootMulti.class);
classes.put("ShootPattern", mindustry.entities.pattern.ShootPattern.class);
classes.put("BulletHandler", mindustry.entities.pattern.ShootPattern.BulletHandler.class);
classes.put("ShootSine", mindustry.entities.pattern.ShootSine.class);
classes.put("ShootSpread", mindustry.entities.pattern.ShootSpread.class);
classes.put("Objectives", mindustry.game.Objectives.class);
classes.put("Objective", mindustry.game.Objectives.Objective.class);
classes.put("OnPlanet", mindustry.game.Objectives.OnPlanet.class);
@ -175,6 +176,7 @@ public class ClassMap{
classes.put("TractorBeamBuild", mindustry.world.blocks.defense.turrets.TractorBeamTurret.TractorBeamBuild.class);
classes.put("Turret", mindustry.world.blocks.defense.turrets.Turret.class);
classes.put("AmmoEntry", mindustry.world.blocks.defense.turrets.Turret.AmmoEntry.class);
classes.put("BulletEntry", mindustry.world.blocks.defense.turrets.Turret.BulletEntry.class);
classes.put("TurretBuild", mindustry.world.blocks.defense.turrets.Turret.TurretBuild.class);
classes.put("ArmoredConveyor", mindustry.world.blocks.distribution.ArmoredConveyor.class);
classes.put("ArmoredConveyorBuild", mindustry.world.blocks.distribution.ArmoredConveyor.ArmoredConveyorBuild.class);

View file

@ -137,8 +137,8 @@ public class ContentParser{
readFields(result, data);
return result;
});
put(ShotPattern.class, (type, data) -> {
var bc = resolve(data.getString("type", ""), ShotPattern.class);
put(ShootPattern.class, (type, data) -> {
var bc = resolve(data.getString("type", ""), ShootPattern.class);
data.remove("type");
var result = make(bc);
readFields(result, data);

View file

@ -70,7 +70,7 @@ public class Weapon implements Cloneable{
/** offsets of weapon position on unit */
public float x = 5f, y = 0f;
/** pattern used for bullets */
public ShotPattern shoot = new ShotPattern();
public ShootPattern shoot = new ShootPattern();
/** radius of shadow drawn under the weapon; <0 to disable */
public float shadow = -1f;
/** fraction of velocity that is random */
@ -385,8 +385,8 @@ public class Weapon implements Cloneable{
weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : 0),
mountX = unit.x + Angles.trnsx(unit.rotation - 90, x, y),
mountY = unit.y + Angles.trnsy(unit.rotation - 90, x, y),
bulletX = mountX + Angles.trnsx(weaponRotation, this.shootX, this.shootY) + Angles.trnsx(weaponRotation, xOffset, yOffset),
bulletY = mountY + Angles.trnsy(weaponRotation, this.shootX, this.shootY) + Angles.trnsy(weaponRotation, xOffset, yOffset),
bulletX = mountX + Angles.trnsx(weaponRotation, this.shootX + xOffset, this.shootY + yOffset),
bulletY = mountY + Angles.trnsy(weaponRotation, this.shootX + xOffset, this.shootY + yOffset),
shootAngle = bulletRotation(unit, mount, bulletX, bulletY) + angleOffset,
lifeScl = bullet.scaleVelocity ? Mathf.clamp(Mathf.dst(shootX, shootY, mount.aimX, mount.aimY) / bullet.range) : 1f;

View file

@ -6,7 +6,6 @@ import arc.util.*;
import mindustry.content.*;
import mindustry.entities.bullet.*;
import mindustry.gen.*;
import mindustry.logic.*;
import mindustry.world.consumers.*;
import mindustry.world.meta.*;
@ -31,8 +30,9 @@ public class ContinuousTurret extends Turret{
stats.remove(Stat.inaccuracy);
}
//TODO LaserTurret shared code
public class ContinuousTurretBuild extends TurretBuild{
public @Nullable Bullet bullet;
public Seq<BulletEntry> bullets = new Seq<>();
@Override
protected void updateCooling(){
@ -68,29 +68,27 @@ public class ContinuousTurret extends Turret{
unit.ammo(unit.type().ammoCapacity * ammoFract);
if(bullet != null){
//check to see if bullet despawned
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;
bullets.removeAll(b -> !b.bullet.isAdded() || b.bullet.type == null || b.bullet.owner != this);
if(bullets.any()){
for(var entry : bullets){
float
bulletX = x + Angles.trnsx(rotation - 90, shootX + entry.x, shootY + entry.y),
bulletY = y + Angles.trnsy(rotation - 90, shootX + entry.x, shootY + entry.y),
angle = rotation + entry.rotation;
entry.bullet.rotation(angle);
entry.bullet.set(bulletX, bulletY);
if(isShooting() && hasAmmo()){
bullet.time = bullet.lifetime * bullet.type.optimalLifeFract * shootWarmup;
entry.bullet.time = entry.bullet.lifetime * entry.bullet.type.optimalLifeFract * shootWarmup;
}
}
}
}
@Override
public double sense(LAccess sensor){
//no concept of reload here
if(sensor == LAccess.progress) return bullet == null ? 0f : 1f;
return super.sense(sensor);
wasShooting = true;
heat = 1f;
recoil = recoilAmount;
}
}
@Override
@ -100,11 +98,11 @@ public class ContinuousTurret extends Turret{
@Override
protected void updateShooting(){
if(bullet != null){
if(bullets.any()){
return;
}
if(canConsume() && !charging && shootWarmup >= minWarmup){
if(canConsume() && !charging() && shootWarmup >= minWarmup){
shoot(peekAmmo());
}
}
@ -115,13 +113,15 @@ public class ContinuousTurret extends Turret{
}
@Override
protected void handleBullet(@Nullable Bullet bullet){
this.bullet = bullet;
protected void handleBullet(@Nullable Bullet bullet, float offsetX, float offsetY, float angleOffset){
if(bullet != null){
bullets.add(new BulletEntry(bullet, offsetX, offsetY, angleOffset, 0f));
}
}
@Override
public boolean shouldActiveSound(){
return bullet != null;
return bullets.any();
}
}
}

View file

@ -1,6 +1,7 @@
package mindustry.world.blocks.defense.turrets;
import arc.math.*;
import arc.struct.*;
import arc.util.*;
import mindustry.entities.bullet.*;
import mindustry.gen.*;
@ -29,8 +30,7 @@ public class LaserTurret extends PowerTurret{
}
public class LaserTurretBuild extends PowerTurretBuild{
public @Nullable Bullet bullet;
public float bulletLife;
public Seq<BulletEntry> bullets = new Seq<>();
@Override
protected void updateCooling(){
@ -40,28 +40,32 @@ public class LaserTurret extends PowerTurret{
@Override
public boolean shouldConsume(){
//still consumes power when bullet is around
return bullet != null || isActive();
return bullets.any() || isActive();
}
@Override
public void updateTile(){
super.updateTile();
if(bullet != null && (!bullet.isAdded() || bullet.type == null)){
bullet = null;
}
bullets.removeAll(b -> !b.bullet.isAdded() || b.bullet.type == null || b.life <= 0f || b.bullet.owner != this);
if(bullets.any()){
for(var entry : bullets){
float
bulletX = x + Angles.trnsx(rotation - 90, shootX + entry.x, shootY + entry.y),
bulletY = y + Angles.trnsy(rotation - 90, shootX + entry.x, shootY + entry.y),
angle = rotation + entry.rotation;
entry.bullet.rotation(angle);
entry.bullet.set(bulletX, bulletY);
entry.bullet.time = entry.bullet.type.lifetime * entry.bullet.type.optimalLifeFract;
entry.life -= Time.delta / Math.max(efficiency, 0.00001f);
}
if(bulletLife > 0 && bullet != null){
wasShooting = true;
bullet.rotation(rotation);
bullet.set(x + bulletOffset.x, y + bulletOffset.y);
bullet.time = bullet.type.lifetime * bullet.type.optimalLifeFract;
heat = 1f;
recoil = recoilAmount;
bulletLife -= Time.delta / Math.max(efficiency, 0.00001f);
if(bulletLife <= 0f){
bullet = null;
}
}else if(reload > 0){
wasShooting = true;
//TODO does not handle multi liquid req?
@ -89,11 +93,11 @@ public class LaserTurret extends PowerTurret{
@Override
protected void updateShooting(){
if(bulletLife > 0 && bullet != null){
if(bullets.any()){
return;
}
if(reload <= 0 && efficiency > 0 && !charging && shootWarmup >= minWarmup){
if(reload <= 0 && efficiency > 0 && !charging() && shootWarmup >= minWarmup){
BulletType type = peekAmmo();
shoot(type);
@ -104,18 +108,19 @@ public class LaserTurret extends PowerTurret{
@Override
protected void turnToTarget(float targetRot){
rotation = Angles.moveToward(rotation, targetRot, efficiency * rotateSpeed * delta() * (bulletLife > 0f ? firingMoveFract : 1f));
rotation = Angles.moveToward(rotation, targetRot, efficiency * rotateSpeed * delta() * (bullets.any() ? firingMoveFract : 1f));
}
@Override
protected void handleBullet(@Nullable Bullet bullet){
this.bullet = bullet;
bulletLife = shootDuration;
protected void handleBullet(@Nullable Bullet bullet, float offsetX, float offsetY, float angleOffset){
if(bullet != null){
bullets.add(new BulletEntry(bullet, offsetX, offsetY, angleOffset, shootDuration));
}
}
@Override
public boolean shouldActiveSound(){
return bulletLife > 0 && bullet != null;
return bullets.any();
}
}
}

View file

@ -114,7 +114,6 @@ public class PayloadTurret extends Turret{
@Override
public BulletType useAmmo(){
ejectEffects();
for(var block : ammoKeys){
if(payloads.contains(block)){
payloads.remove(block);

View file

@ -15,6 +15,7 @@ import mindustry.core.*;
import mindustry.entities.*;
import mindustry.entities.Units.*;
import mindustry.entities.bullet.*;
import mindustry.entities.pattern.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
@ -40,10 +41,8 @@ public class Turret extends ReloadTurret{
public Effect smokeEffect = Fx.none;
public Effect ammoUseEffect = Fx.none;
public Sound shootSound = Sounds.shoot;
public Effect chargeEffect = Fx.none;
public Effect chargeBeginEffect = Fx.none;
public Sound chargeSound = Sounds.none;
public float soundPitchMin = 0.9f, soundPitchMax = 1.1f;
//visuals
public float ammoEjectBack = 1f;
@ -60,44 +59,24 @@ public class Turret extends ReloadTurret{
public float heatRequirement = -1f;
public float maxHeatEfficiency = 3f;
//TODO all the fields below should be deprecated and moved into a ShootPattern class or similar
//TODO ...however, it would be nice to unify the weapon and turret systems into one.
//TODO clean all of this up + weapon consistency
// below
/** Bullet angle randomness in degrees. */
public float inaccuracy = 0f;
/** Fraction of bullet velocity that is random. */
public float velocityInaccuracy = 0f;
/** Number of bullets fired per volley. */
public int shots = 1;
/**
* Spread between bullets in degrees.
* For some dumb reason, this is also used for the "alternation width", and it's too late to change anything.
* */
public float spread = 4f;
/** Maximum angle difference in degrees at which turret will still try to shoot. */
public float shootCone = 8f;
/** Length of turret shoot point. */
public float shootLength = Float.NEGATIVE_INFINITY;
/** Random spread of projectile across width. This looks stupid. */
public float xRand = 0f;
/** Turret shoot point. */
public float shootX = 0f, shootY = Float.NEGATIVE_INFINITY;
/** Currently used for artillery only. */
public float minRange = 0f;
/** Minimum warmup needed to fire. */
public float minWarmup = 0f;
/** Ticks between shots if shots > 1. */
public float burstSpacing = 0;
/** An inflexible and terrible idea. */
public boolean alternate = false, widthSpread = false;
/** If true, this turret will accurately target moving targets with respect to charge time. */
public boolean accurateDelay = false;
//charging
public float chargeTime = -1f;
public int chargeEffects = 5;
public float chargeMaxDelay = 10f;
//see above
/** pattern used for bullets */
public ShootPattern shoot = new ShootPattern();
public boolean targetAir = true;
public boolean targetGround = true;
@ -126,7 +105,7 @@ public class Turret extends ReloadTurret{
super.setStats();
stats.add(Stat.inaccuracy, (int)inaccuracy, StatUnit.degrees);
stats.add(Stat.reload, 60f / (reloadTime) * (alternate ? 1 : shots), StatUnit.perSecond);
stats.add(Stat.reload, 60f / (reloadTime) * shoot.shots, StatUnit.perSecond);
stats.add(Stat.targetsAir, targetAir);
stats.add(Stat.targetsGround, targetGround);
if(ammoPerShot != 1) stats.add(Stat.ammoUse, ammoPerShot, StatUnit.perShot);
@ -148,7 +127,7 @@ public class Turret extends ReloadTurret{
@Override
public void init(){
if(shootLength == Float.NEGATIVE_INFINITY) shootLength = size * tilesize / 2f;
if(shootY == Float.NEGATIVE_INFINITY) shootY = size * tilesize / 2f;
if(elevation < 0) elevation = size / 2f;
super.init();
@ -181,26 +160,25 @@ public class Turret extends ReloadTurret{
//TODO storing these as instance variables is horrible design
/** Turret sprite offset, based on recoil. Updated every frame. */
public Vec2 recoilOffset = new Vec2();
/** Turret bullet position offset. Updated every frame. */
public Vec2 bulletOffset = new Vec2();
public Seq<AmmoEntry> ammo = new Seq<>();
public int totalAmmo;
public float recoil, heat, logicControlTime = -1;
public float shootWarmup;
public int shotCounter;
public int totalShots;
public boolean logicShooting = false;
public @Nullable Posc target;
public Vec2 targetPos = new Vec2();
public BlockUnitc unit = (BlockUnitc)UnitTypes.block.create(team);
public boolean wasShooting, charging;
public boolean wasShooting;
public int queuedBullets = 0;
public float heatReq;
public float[] sideHeat = new float[4];
public float estimateDps(){
if(!hasAmmo()) return 0f;
return shots / reloadTime * 60f * peekAmmo().estimateDPS() * efficiency * timeScale;
return shoot.shots / reloadTime * 60f * peekAmmo().estimateDPS() * efficiency * timeScale;
}
@Override
@ -303,7 +281,7 @@ public class Turret extends ReloadTurret{
//when delay is accurate, assume unit has moved by chargeTime already
if(accurateDelay && pos instanceof Hitboxc h){
offset.set(h.deltaX(), h.deltaY()).scl(chargeTime / Time.delta);
offset.set(h.deltaX(), h.deltaY()).scl(shoot.firstShotDelay / Time.delta);
}
targetPos.set(Predict.intercept(this, pos, offset.x, offset.y, bullet.speed <= 0.01f ? 99999999f : bullet.speed));
@ -339,7 +317,6 @@ public class Turret extends ReloadTurret{
unit.rotation(rotation);
unit.team(team);
recoilOffset.trns(rotation, -recoil);
bulletOffset.trns(rotation, shootLength);
if(logicControlTime > 0){
logicControlTime -= Time.delta;
@ -427,7 +404,7 @@ public class Turret extends ReloadTurret{
}
public boolean shouldTurn(){
return !charging;
return !charging();
}
@Override
@ -446,13 +423,12 @@ public class Turret extends ReloadTurret{
if(entry.amount <= 0) ammo.pop();
totalAmmo -= ammoPerShot;
totalAmmo = Math.max(totalAmmo, 0);
ejectEffects();
return entry.type();
}
/** @return the ammo type that will be returned if useAmmo is called. */
public BulletType peekAmmo(){
return ammo.peek().type();
public @Nullable BulletType peekAmmo(){
return ammo.size == 0 ? null : ammo.peek().type();
}
/** @return whether the turret has ammo. */
@ -467,6 +443,10 @@ public class Turret extends ReloadTurret{
return ammo.size > 0 && ammo.peek().amount >= ammoPerShot;
}
public boolean charging(){
return queuedBullets > 0;
}
protected void updateReload(){
float multiplier = hasAmmo() ? peekAmmo().reloadMultiplier : 1f;
reload += delta() * multiplier * baseReloadSpeed();
@ -477,7 +457,7 @@ public class Turret extends ReloadTurret{
protected void updateShooting(){
if(reload >= reloadTime && !charging && shootWarmup >= minWarmup){
if(reload >= reloadTime && !charging() && shootWarmup >= minWarmup){
BulletType type = peekAmmo();
shoot(type);
@ -487,111 +467,66 @@ public class Turret extends ReloadTurret{
}
protected void shoot(BulletType type){
//TODO absolute disaster here, combining shot patterns fails in unpredictable ways and I don't want to touch anything in case it breaks mods
float
bulletX = x + Angles.trnsx(rotation - 90, shootX, shootY),
bulletY = y + Angles.trnsy(rotation - 90, shootX, shootY);
//when charging is enabled, use the charge shoot pattern
if(chargeTime > 0){
useAmmo();
chargeBeginEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
chargeSound.at(x + bulletOffset.x, y + bulletOffset.y, 1);
for(int i = 0; i < chargeEffects; i++){
Time.run(Mathf.random(chargeMaxDelay), () -> {
if(dead) return;
bulletOffset.trns(rotation, shootLength);
chargeEffect.at(x + bulletOffset.x, y + bulletOffset.y, rotation);
});
}
charging = true;
Time.run(chargeTime, () -> {
if(dead) return;
bulletOffset.trns(rotation, shootLength);
recoil = recoilAmount;
heat = 1f;
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy));
charging = false;
});
//when burst spacing is enabled, use the burst pattern
}else if(burstSpacing > 0.0001f){
for(int i = 0; i < shots; i++){
int ii = i;
Time.run(burstSpacing * i, () -> {
if(dead || !hasAmmo()) return;
bulletOffset.trns(rotation, shootLength, Mathf.range(xRand));
bullet(peekAmmo(), rotation + Mathf.range(inaccuracy + peekAmmo().inaccuracy) + (ii - (int)(shots / 2f)) * spread);
useAmmo();
recoil = recoilAmount;
heat = 1f;
});
}
}else{
//otherwise, use the normal shot pattern(s)
if(alternate || widthSpread){
int count = !widthSpread ? 1 : shots;
for(int c = 0; c < count; c++){
float i = (shotCounter % shots) - (shots-1)/2f;
bulletOffset.trns(rotation - 90, (spread) * i + Mathf.range(xRand), shootLength);
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy));
shotCounter ++;
}
}else{
bulletOffset.trns(rotation, shootLength, Mathf.range(xRand));
for(int i = 0; i < shots; i++){
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy) + (i - (int)(shots / 2f)) * spread);
shotCounter ++;
}
}
recoil = recoilAmount;
heat = 1f;
useAmmo();
if(shoot.firstShotDelay > 0){
chargeSound.at(bulletX, bulletY, Mathf.random(soundPitchMin, soundPitchMax));
type.chargeEffect.at(bulletX, bulletY, rotation);
}
shoot.shoot(totalShots, (xOffset, yOffset, angle, delay) -> {
queuedBullets ++;
if(delay > 0f){
Time.run(delay, () -> bullet(type, xOffset, yOffset, angle));
}else{
bullet(type, xOffset, yOffset, angle);
}
totalShots ++;
});
}
protected void bullet(BulletType type, float angle){
float bulletX = x + bulletOffset.x, bulletY = y + bulletOffset.y;
protected void bullet(BulletType type, float xOffset, float yOffset, float angleOffset){
queuedBullets --;
if(dead || !hasAmmo()) return;
float
bulletX = x + Angles.trnsx(rotation - 90, shootX + xOffset, shootY + yOffset),
bulletY = y + Angles.trnsy(rotation - 90, shootX + xOffset, shootY + yOffset),
shootAngle = rotation + angleOffset + Mathf.range(inaccuracy);
float lifeScl = type.scaleVelocity ? Mathf.clamp(Mathf.dst(bulletX, bulletY, targetPos.x, targetPos.y) / type.range, minRange / type.range, range() / type.range) : 1f;
handleBullet(type.create(this, team, bulletX, bulletY, angle, 1f + Mathf.range(velocityInaccuracy), lifeScl));
handleBullet(type.create(this, team, bulletX, bulletY, shootAngle, 1f + Mathf.range(velocityInaccuracy), lifeScl), xOffset, yOffset, angleOffset);
//TODO "shoot" and "smoke" should just be MultiEffects there's no reason to have them separate
Effect fshootEffect = shootEffect == Fx.none ? type.shootEffect : shootEffect;
Effect fsmokeEffect = smokeEffect == Fx.none ? type.smokeEffect : smokeEffect;
fshootEffect.at(bulletX, bulletY, rotation, type.hitColor);
fsmokeEffect.at(bulletX, bulletY, rotation, type.hitColor);
shootSound.at(bulletX, bulletY, Mathf.random(0.9f, 1.1f));
(shootEffect == Fx.none ? type.shootEffect : shootEffect).at(bulletX, bulletY, rotation, type.hitColor);
(smokeEffect == Fx.none ? type.smokeEffect : smokeEffect).at(bulletX, bulletY, rotation, type.hitColor);
shootSound.at(bulletX, bulletY, Mathf.random(soundPitchMin, soundPitchMax));
ammoUseEffect.at(
x - Angles.trnsx(rotation, ammoEjectBack),
y - Angles.trnsy(rotation, ammoEjectBack),
rotation * (shoot.shots == 1 && shoot instanceof ShootAlternate && totalShots % 2 == 1 ? -1f : 1f)
);
if(shootShake > 0){
Effect.shake(shootShake, shootShake, this);
}
recoil = recoilAmount;
heat = 1f;
useAmmo();
}
protected void handleBullet(@Nullable Bullet bullet){
protected void handleBullet(@Nullable Bullet bullet, float offsetX, float offsetY, float angleOffset){
}
protected void ejectEffects(){
if(dead) return;
//alternate sides when using a double turret
float scl = (shots == 2 && alternate && shotCounter % 2 == 1 ? -1f : 1f);
ammoUseEffect.at(x - Angles.trnsx(rotation, ammoEjectBack), y - Angles.trnsy(rotation, ammoEjectBack), rotation * scl);
}
@Override
public void write(Writes write){
super.write(write);
@ -614,4 +549,17 @@ public class Turret extends ReloadTurret{
return 1;
}
}
public static class BulletEntry{
public Bullet bullet;
public float x, y, rotation, life;
public BulletEntry(Bullet bullet, float x, float y, float rotation, float life){
this.bullet = bullet;
this.x = x;
this.y = y;
this.rotation = rotation;
this.life = life;
}
}
}