From e1ddf115e063329f89cf36980706e9d6d0643769 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 25 Nov 2020 20:41:38 -0500 Subject: [PATCH] Merged turret types --- core/src/mindustry/content/Blocks.java | 2 +- .../blocks/defense/turrets/ChargeTurret.java | 63 ------------------- .../world/blocks/defense/turrets/Turret.java | 51 +++++++++++++-- 3 files changed, 46 insertions(+), 70 deletions(-) delete mode 100644 core/src/mindustry/world/blocks/defense/turrets/ChargeTurret.java diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 2625e478d5..363256dc83 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1513,7 +1513,7 @@ public class Blocks implements ContentList{ flags = EnumSet.of(BlockFlag.turret, BlockFlag.extinguisher); }}; - lancer = new ChargeTurret("lancer"){{ + lancer = new PowerTurret("lancer"){{ requirements(Category.turret, with(Items.copper, 25, Items.lead, 50, Items.silicon, 45)); range = 165f; chargeTime = 40f; diff --git a/core/src/mindustry/world/blocks/defense/turrets/ChargeTurret.java b/core/src/mindustry/world/blocks/defense/turrets/ChargeTurret.java deleted file mode 100644 index 15feaf0379..0000000000 --- a/core/src/mindustry/world/blocks/defense/turrets/ChargeTurret.java +++ /dev/null @@ -1,63 +0,0 @@ -package mindustry.world.blocks.defense.turrets; - -import arc.audio.*; -import arc.math.*; -import arc.util.*; -import mindustry.content.*; -import mindustry.entities.*; -import mindustry.entities.bullet.*; -import mindustry.type.*; -import mindustry.gen.*; - -import static mindustry.Vars.*; - -public class ChargeTurret extends PowerTurret{ - public float chargeTime = 30f; - public int chargeEffects = 5; - public float chargeMaxDelay = 10f; - public Effect chargeEffect = Fx.none; - public Effect chargeBeginEffect = Fx.none; - public Sound chargeSound = Sounds.none; - - public ChargeTurret(String name){ - super(name); - } - - public class ChargeTurretBuild extends PowerTurretBuild{ - public boolean shooting; - - @Override - public void shoot(BulletType ammo){ - useAmmo(); - - tr.trns(rotation, size * tilesize / 2f); - chargeBeginEffect.at(x + tr.x, y + tr.y, rotation); - chargeSound.at(x + tr.x, y + tr.y, 1); - - for(int i = 0; i < chargeEffects; i++){ - Time.run(Mathf.random(chargeMaxDelay), () -> { - if(!isValid()) return; - tr.trns(rotation, size * tilesize / 2f); - chargeEffect.at(x + tr.x, y + tr.y, rotation); - }); - } - - shooting = true; - - Time.run(chargeTime, () -> { - if(!isValid()) return; - tr.trns(rotation, size * tilesize / 2f); - recoil = recoilAmount; - heat = 1f; - bullet(ammo, rotation + Mathf.range(inaccuracy)); - effects(); - shooting = false; - }); - } - - @Override - public boolean shouldTurn(){ - return !shooting; - } - } -} diff --git a/core/src/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/mindustry/world/blocks/defense/turrets/Turret.java index 3d1af1e5ce..9e41023c01 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/Turret.java @@ -40,6 +40,7 @@ public abstract class Turret extends ReloadTurret{ public Effect ammoUseEffect = Fx.none; public Sound shootSound = Sounds.shoot; + //general info public int maxAmmo = 30; public int ammoPerShot = 1; public float ammoEjectBack = 1f; @@ -61,6 +62,14 @@ public abstract class Turret extends ReloadTurret{ public boolean targetAir = true; public boolean targetGround = true; + //charging + public float chargeTime = -1f; + public int chargeEffects = 5; + public float chargeMaxDelay = 10f; + public Effect chargeEffect = Fx.none; + public Effect chargeBeginEffect = Fx.none; + public Sound chargeSound = Sounds.none; + public Sortf unitSort = Unit::dst2; protected Vec2 tr = new Vec2(); @@ -136,7 +145,7 @@ public abstract class Turret extends ReloadTurret{ public @Nullable Posc target; public Vec2 targetPos = new Vec2(); public BlockUnitc unit = Nulls.blockUnit; - public boolean wasShooting; + public boolean wasShooting, charging; @Override public void created(){ @@ -313,7 +322,7 @@ public abstract class Turret extends ReloadTurret{ } public boolean shouldTurn(){ - return true; + return !charging; } /** Consume ammo and return a type. */ @@ -352,11 +361,37 @@ public abstract class Turret extends ReloadTurret{ } protected void shoot(BulletType type){ - recoil = recoilAmount; - heat = 1f; - //when burst spacing is enabled, use the burst pattern - if(burstSpacing > 0.0001f){ + //when charging is enabled, use the charge shoot pattern + if(chargeTime > 0){ + useAmmo(); + + tr.trns(rotation, size * tilesize / 2f); + chargeBeginEffect.at(x + tr.x, y + tr.y, rotation); + chargeSound.at(x + tr.x, y + tr.y, 1); + + for(int i = 0; i < chargeEffects; i++){ + Time.run(Mathf.random(chargeMaxDelay), () -> { + if(!isValid()) return; + tr.trns(rotation, size * tilesize / 2f); + chargeEffect.at(x + tr.x, y + tr.y, rotation); + }); + } + + charging = true; + + Time.run(chargeTime, () -> { + if(!isValid()) return; + tr.trns(rotation, size * tilesize / 2f); + recoil = recoilAmount; + heat = 1f; + bullet(type, rotation + Mathf.range(inaccuracy)); + effects(); + charging = false; + }); + + //when burst spacing is enabled, use the burst pattern + }else if(burstSpacing > 0.0001f){ for(int i = 0; i < shots; i++){ Time.run(burstSpacing * i, () -> { if(!isValid() || !hasAmmo()) return; @@ -367,6 +402,8 @@ public abstract class Turret extends ReloadTurret{ bullet(type, rotation + Mathf.range(inaccuracy)); effects(); useAmmo(); + recoil = recoilAmount; + heat = 1f; }); } @@ -388,6 +425,8 @@ public abstract class Turret extends ReloadTurret{ shotCounter++; + recoil = recoilAmount; + heat = 1f; effects(); useAmmo(); }