Merged some turret classes
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
package mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import arc.math.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
/**
|
||||
* Artillery turrets have special shooting calculations done to hit targets.
|
||||
*/
|
||||
public class ArtilleryTurret extends ItemTurret{
|
||||
public float velocityInaccuracy = 0f;
|
||||
|
||||
public ArtilleryTurret(String name){
|
||||
super(name);
|
||||
targetAir = false;
|
||||
}
|
||||
|
||||
public class ArtilleryTurretEntity extends ItemTurretEntity{
|
||||
@Override
|
||||
protected void shoot(BulletType ammo){
|
||||
recoil = recoilAmount;
|
||||
heat = 1f;
|
||||
|
||||
BulletType type = peekAmmo();
|
||||
|
||||
tr.trns(rotation, size * tilesize / 2);
|
||||
|
||||
float dst = dst(targetPos.x, targetPos.y);
|
||||
float maxTraveled = type.lifetime * type.speed;
|
||||
|
||||
for(int i = 0; i < shots; i++){
|
||||
ammo.create(tile.entity, team, x + tr.x, y + tr.y,
|
||||
rotation + Mathf.range(inaccuracy + type.inaccuracy), 1f + Mathf.range(velocityInaccuracy), (dst / maxTraveled));
|
||||
}
|
||||
|
||||
effects();
|
||||
useAmmo();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class BurstTurret extends ItemTurret{
|
||||
public float burstSpacing = 5;
|
||||
|
||||
public BurstTurret(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
public class BurstTurretEntity extends ItemTurretEntity{
|
||||
|
||||
@Override
|
||||
protected void shoot(BulletType ammo){
|
||||
heat = 1f;
|
||||
|
||||
for(int i = 0; i < shots; i++){
|
||||
Time.run(burstSpacing * i, () -> {
|
||||
if(!(tile.entity instanceof TurretEntity) || !hasAmmo()) return;
|
||||
|
||||
recoil = recoilAmount;
|
||||
|
||||
tr.trns(rotation, size * tilesize / 2, Mathf.range(xRand));
|
||||
bullet(ammo, rotation + Mathf.range(inaccuracy));
|
||||
effects();
|
||||
useAmmo();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import mindustry.entities.bullet.*;
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class ChargeTurret extends PowerTurret{
|
||||
|
||||
public float chargeTime = 30f;
|
||||
public int chargeEffects = 5;
|
||||
public float chargeMaxDelay = 10f;
|
||||
@@ -27,13 +26,13 @@ public class ChargeTurret extends PowerTurret{
|
||||
public void shoot(BulletType ammo){
|
||||
useAmmo();
|
||||
|
||||
tr.trns(rotation, size * tilesize / 2);
|
||||
tr.trns(rotation, size * tilesize / 2f);
|
||||
chargeBeginEffect.at(x + tr.x, y + tr.y, rotation);
|
||||
|
||||
for(int i = 0; i < chargeEffects; i++){
|
||||
Time.run(Mathf.random(chargeMaxDelay), () -> {
|
||||
if(!isValid()) return;
|
||||
tr.trns(rotation, size * tilesize / 2);
|
||||
tr.trns(rotation, size * tilesize / 2f);
|
||||
chargeEffect.at(x + tr.x, y + tr.y, rotation);
|
||||
});
|
||||
}
|
||||
@@ -42,7 +41,7 @@ public class ChargeTurret extends PowerTurret{
|
||||
|
||||
Time.run(chargeTime, () -> {
|
||||
if(!isValid()) return;
|
||||
tr.trns(rotation, size * tilesize / 2);
|
||||
tr.trns(rotation, size * tilesize / 2f);
|
||||
recoil = recoilAmount;
|
||||
heat = 1f;
|
||||
bullet(ammo, rotation + Mathf.range(inaccuracy));
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import arc.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class CooledTurret extends Turret{
|
||||
/** How much reload is lowered by for each unit of liquid of heat capacity. */
|
||||
public float coolantMultiplier = 5f;
|
||||
public Effect coolEffect = Fx.fuelburn;
|
||||
|
||||
public CooledTurret(String name){
|
||||
super(name);
|
||||
hasLiquids = true;
|
||||
liquidCapacity = 20f;
|
||||
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.2f)).update(false).boost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.booster, new BoosterListValue(reloadTime, consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount, coolantMultiplier, true, l -> consumes.liquidfilters.get(l.id)));
|
||||
}
|
||||
|
||||
public class CooledTurretEntity extends TurretEntity{
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tilec source, Liquid liquid, float amount){
|
||||
if(liquids.currentAmount() <= 0.001f){
|
||||
Events.fire(Trigger.turretCool);
|
||||
}
|
||||
|
||||
super.handleLiquid(source, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateShooting(){
|
||||
super.updateShooting();
|
||||
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
Liquid liquid = liquids.current();
|
||||
|
||||
float used = Math.min(Math.min(liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reloadTime - reload) / coolantMultiplier) / liquid.heatCapacity)) * baseReloadSpeed();
|
||||
reload += used * liquid.heatCapacity * coolantMultiplier;
|
||||
liquids.remove(liquid, used);
|
||||
|
||||
if(Mathf.chance(0.06 * used)){
|
||||
coolEffect.at(x + Mathf.range(size * tilesize / 2f), y + Mathf.range(size * tilesize / 2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import mindustry.world.meta.values.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class ItemTurret extends CooledTurret{
|
||||
public class ItemTurret extends Turret{
|
||||
public int maxAmmo = 30;
|
||||
public ObjectMap<Item, BulletType> ammoTypes = new ObjectMap<>();
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public class LiquidTurret extends Turret{
|
||||
|
||||
public LiquidTurret(String name){
|
||||
super(name);
|
||||
acceptCoolant = false;
|
||||
hasLiquids = true;
|
||||
activeSound = Sounds.spray;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import arc.util.ArcAnnotate.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class PowerTurret extends CooledTurret{
|
||||
public class PowerTurret extends Turret{
|
||||
public @NonNull BulletType shootType;
|
||||
public float powerUse = 1f;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PowerTurret extends CooledTurret{
|
||||
super.init();
|
||||
}
|
||||
|
||||
public class PowerTurretEntity extends CooledTurretEntity{
|
||||
public class PowerTurretEntity extends TurretEntity{
|
||||
|
||||
@Override
|
||||
public BulletType useAmmo(){
|
||||
|
||||
@@ -8,18 +8,22 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
@@ -38,6 +42,7 @@ public abstract class Turret extends Block{
|
||||
public float range = 50f;
|
||||
public float reloadTime = 10f;
|
||||
public float inaccuracy = 0f;
|
||||
public float velocityInaccuracy = 0f;
|
||||
public int shots = 1;
|
||||
public float spread = 4f;
|
||||
public float recoilAmount = 1f;
|
||||
@@ -47,9 +52,15 @@ public abstract class Turret extends Block{
|
||||
public float shootCone = 8f;
|
||||
public float shootShake = 0f;
|
||||
public float xRand = 0f;
|
||||
public float burstSpacing = 0;
|
||||
public boolean alternate = false;
|
||||
public boolean targetAir = true;
|
||||
public boolean targetGround = true;
|
||||
public boolean acceptCoolant = true;
|
||||
/** How much reload is lowered by for each unit of liquid of heat capacity. */
|
||||
public float coolantMultiplier = 5f;
|
||||
/** Effect displayed when coolant is used. */
|
||||
public Effect coolEffect = Fx.fuelburn;
|
||||
|
||||
protected Vec2 tr = new Vec2();
|
||||
protected Vec2 tr2 = new Vec2();
|
||||
@@ -75,6 +86,7 @@ public abstract class Turret extends Block{
|
||||
group = BlockGroup.turrets;
|
||||
flags = EnumSet.of(BlockFlag.turret);
|
||||
outlineIcon = true;
|
||||
liquidCapacity = 20f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,6 +104,20 @@ public abstract class Turret extends Block{
|
||||
stats.add(BlockStat.shots, shots, StatUnit.none);
|
||||
stats.add(BlockStat.targetsAir, targetAir);
|
||||
stats.add(BlockStat.targetsGround, targetGround);
|
||||
|
||||
if(acceptCoolant){
|
||||
stats.add(BlockStat.booster, new BoosterListValue(reloadTime, consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount, coolantMultiplier, true, l -> consumes.liquidfilters.get(l.id)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
if(acceptCoolant && !consumes.has(ConsumeType.liquid)){
|
||||
hasLiquids = true;
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.2f)).update(false).boost();
|
||||
}
|
||||
|
||||
super.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,6 +145,7 @@ public abstract class Turret extends Block{
|
||||
public Vec2 targetPos = new Vec2();
|
||||
public @NonNull BlockUnitc unit = Nulls.blockUnit;
|
||||
|
||||
@Override
|
||||
public void created(){
|
||||
unit = (BlockUnitc)UnitTypes.block.create(team);
|
||||
unit.tile(this);
|
||||
@@ -196,14 +223,40 @@ public abstract class Turret extends Block{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(acceptCoolant){
|
||||
updateCooling();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSelect(){
|
||||
Drawf.dashCircle(x, y, range, team.color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tilec source, Liquid liquid, float amount){
|
||||
if(acceptCoolant && liquids.currentAmount() <= 0.001f){
|
||||
Events.fire(Trigger.turretCool);
|
||||
}
|
||||
|
||||
super.handleLiquid(source, liquid, amount);
|
||||
}
|
||||
|
||||
protected void updateCooling(){
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
Liquid liquid = liquids.current();
|
||||
|
||||
float used = Math.min(Math.min(liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reloadTime - reload) / coolantMultiplier) / liquid.heatCapacity)) * baseReloadSpeed();
|
||||
reload += used * liquid.heatCapacity * coolantMultiplier;
|
||||
liquids.remove(liquid, used);
|
||||
|
||||
if(Mathf.chance(0.06 * used)){
|
||||
coolEffect.at(x + Mathf.range(size * tilesize / 2f), y + Mathf.range(size * tilesize / 2f));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean validateTarget(){
|
||||
return !Units.invalidateTarget(target, team, x, y) || isControlled();
|
||||
}
|
||||
@@ -232,7 +285,7 @@ public abstract class Turret extends Block{
|
||||
entry.amount -= ammoPerShot;
|
||||
if(entry.amount == 0) ammo.pop();
|
||||
totalAmmo -= ammoPerShot;
|
||||
Time.run(reloadTime / 2f, () -> ejectEffects());
|
||||
Time.run(reloadTime / 2f, this::ejectEffects);
|
||||
return entry.type();
|
||||
}
|
||||
|
||||
@@ -266,27 +319,48 @@ public abstract class Turret extends Block{
|
||||
recoil = recoilAmount;
|
||||
heat = 1f;
|
||||
|
||||
if(alternate){
|
||||
float i = (shotCounter % shots) - shots/2f + (((shots+1)%2) / 2f);
|
||||
|
||||
tr.trns(rotation - 90, spread * i + Mathf.range(xRand), size * tilesize / 2);
|
||||
bullet(type, rotation + Mathf.range(inaccuracy));
|
||||
}else{
|
||||
tr.trns(rotation, size * tilesize / 2f, Mathf.range(xRand));
|
||||
|
||||
//when burst spacing is enabled, use the burst pattern
|
||||
if(burstSpacing > 0.0001f){
|
||||
for(int i = 0; i < shots; i++){
|
||||
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy) + (i - shots / 2f) * spread);
|
||||
Time.run(burstSpacing * i, () -> {
|
||||
if(!isValid() || !hasAmmo()) return;
|
||||
|
||||
recoil = recoilAmount;
|
||||
|
||||
tr.trns(rotation, size * tilesize / 2f, Mathf.range(xRand));
|
||||
bullet(type, rotation + Mathf.range(inaccuracy));
|
||||
effects();
|
||||
useAmmo();
|
||||
});
|
||||
}
|
||||
|
||||
}else{
|
||||
//otherwise, use the normal shot pattern(s)
|
||||
|
||||
if(alternate){
|
||||
float i = (shotCounter % shots) - shots/2f + (((shots+1)%2) / 2f);
|
||||
|
||||
tr.trns(rotation - 90, spread * i + Mathf.range(xRand), size * tilesize / 2f);
|
||||
bullet(type, rotation + Mathf.range(inaccuracy));
|
||||
}else{
|
||||
tr.trns(rotation, size * tilesize / 2f, Mathf.range(xRand));
|
||||
|
||||
for(int i = 0; i < shots; i++){
|
||||
bullet(type, rotation + Mathf.range(inaccuracy + type.inaccuracy) + (i - shots / 2f) * spread);
|
||||
}
|
||||
}
|
||||
|
||||
shotCounter++;
|
||||
|
||||
effects();
|
||||
useAmmo();
|
||||
}
|
||||
|
||||
shotCounter++;
|
||||
|
||||
effects();
|
||||
useAmmo();
|
||||
}
|
||||
|
||||
protected void bullet(BulletType type, float angle){
|
||||
type.create(this, team, x + tr.x, y + tr.y, angle);
|
||||
float lifeScl = type.scaleVelocity ? Mathf.clamp(Mathf.dst(x, y, targetPos.x, targetPos.y) / type.range()) : 1f;
|
||||
|
||||
type.create(this, team, x + tr.x, y + tr.y, angle, 1f + Mathf.range(velocityInaccuracy), lifeScl);
|
||||
}
|
||||
|
||||
protected void effects(){
|
||||
|
||||
Reference in New Issue
Block a user