WIP Turret field rename / More JSON consume support

This commit is contained in:
Anuken
2022-05-08 23:17:37 -04:00
parent 668b09e955
commit 5a3c8573c3
16 changed files with 120 additions and 76 deletions

View File

@@ -1052,7 +1052,8 @@ public class Blocks{
requirements(Category.crafting, with(Items.copper, 30, Items.lead, 35, Items.graphite, 45));
health = 200;
outputLiquid = new LiquidStack(Liquids.slag, 12f / 60f);
craftTime = 1f;
craftTime = 10f;
hasLiquids = hasPower = true;
drawer = new DrawMulti(new DrawDefault(), new DrawLiquidRegion());
@@ -2877,7 +2878,7 @@ public class Blocks{
shoot.shotDelay = 5f;
shoot.shots = 2;
recoilAmount = 2f;
recoil = 2f;
rotateSpeed = 15f;
inaccuracy = 17f;
shootCone = 35f;
@@ -2920,7 +2921,7 @@ public class Blocks{
hittable = false;
}}
);
recoilAmount = 0f;
recoil = 0f;
reload = 6f;
coolantMultiplier = 1.5f;
range = 60f;
@@ -2974,7 +2975,7 @@ public class Blocks{
);
targetAir = false;
reload = 60f;
recoilAmount = 2f;
recoil = 2f;
range = 235f;
inaccuracy = 1f;
shootCone = 10f;
@@ -3003,7 +3004,7 @@ public class Blocks{
}}
);
size = 2;
recoilAmount = 0f;
recoil = 0f;
reload = 3f;
inaccuracy = 5f;
shootCone = 50f;
@@ -3021,10 +3022,10 @@ public class Blocks{
shoot.firstShotDelay = 40f;
recoilAmount = 2f;
recoil = 2f;
reload = 80f;
cooldown = 0.03f;
shootShake = 2f;
shake = 2f;
shootEffect = Fx.lancerLaserShoot;
smokeEffect = Fx.none;
heatColor = Color.red;
@@ -3085,7 +3086,7 @@ public class Blocks{
range = 90f;
shootEffect = Fx.lightningShoot;
heatColor = Color.red;
recoilAmount = 1f;
recoil = 1f;
size = 1;
health = 260;
shootSound = Sounds.spark;
@@ -3229,8 +3230,8 @@ public class Blocks{
restitution = 0.03f;
ammoEjectBack = 3f;
cooldown = 0.03f;
recoilAmount = 3f;
shootShake = 1f;
recoil = 3f;
shake = 1f;
shoot.shots = 4;
shoot.shotDelay = 3f;
@@ -3309,7 +3310,7 @@ public class Blocks{
shoot.shots = 2;
velocityRnd = 0.1f;
inaccuracy = 4f;
recoilAmount = 1f;
recoil = 1f;
restitution = 0.04f;
shootCone = 45f;
liquidCapacity = 40f;
@@ -3323,9 +3324,9 @@ public class Blocks{
requirements(Category.turret, with(Items.copper, 225, Items.graphite, 225, Items.thorium, 100));
reload = 35f;
shootShake = 4f;
shake = 4f;
range = 90f;
recoilAmount = 5f;
recoil = 5f;
shoot = new ShootSpread(3, 20f);
@@ -3446,8 +3447,8 @@ public class Blocks{
cooldown = 0.03f;
velocityRnd = 0.2f;
restitution = 0.02f;
recoilAmount = 6f;
shootShake = 2f;
recoil = 6f;
shake = 2f;
range = 290f;
minRange = 50f;
coolant = consumeCoolant(0.3f);
@@ -3533,7 +3534,7 @@ public class Blocks{
reload = 8f;
range = 200f;
size = 3;
recoilAmount = 3f;
recoil = 3f;
rotateSpeed = 10f;
inaccuracy = 10f;
shootCone = 30f;
@@ -3569,10 +3570,10 @@ public class Blocks{
rotateSpeed = 2f;
reload = 200f;
ammoUseEffect = Fx.casing3Double;
recoilAmount = 5f;
recoil = 5f;
restitution = 0.009f;
cooldown = 0.009f;
shootShake = 4f;
shake = 4f;
size = 4;
shootCone = 2f;
shootSound = Sounds.railgun;
@@ -3631,11 +3632,11 @@ public class Blocks{
ammoUseEffect = Fx.casing3;
range = 260f;
inaccuracy = 3f;
recoilAmount = 3f;
recoil = 3f;
shoot = new ShootAlternate(){{
spread = 8f;
}};
shootShake = 2f;
shake = 2f;
size = 4;
shootCone = 24f;
shootSound = Sounds.shootBig;
@@ -3650,9 +3651,9 @@ public class Blocks{
requirements(Category.turret, with(Items.copper, 1200, Items.lead, 350, Items.graphite, 300, Items.surgeAlloy, 325, Items.silicon, 325));
shootEffect = Fx.shootBigSmoke2;
shootCone = 40f;
recoilAmount = 4f;
recoil = 4f;
size = 4;
shootShake = 2f;
shake = 2f;
range = 195f;
reload = 90f;
firingMoveFract = 0.5f;
@@ -3726,7 +3727,7 @@ public class Blocks{
coolantMultiplier = 6f;
shootShake = 1f;
shake = 1f;
ammoPerShot = 2;
drawer = new DrawTurret("reinforced-");
shootY = -2;
@@ -3734,7 +3735,7 @@ public class Blocks{
size = 3;
envEnabled |= Env.space;
reload = 40f;
recoilAmount = 2f;
recoil = 2f;
restitution = 0.03f;
range = 190;
shootCone = 3f;
@@ -3773,7 +3774,7 @@ public class Blocks{
inaccuracy = 0.2f;
velocityRnd = 0.17f;
shootShake = 1f;
shake = 1f;
ammoPerShot = 3;
maxAmmo = 30;
consumeAmmoOnce = true;
@@ -3792,7 +3793,7 @@ public class Blocks{
size = 3;
envEnabled |= Env.space;
reload = 30f;
recoilAmount = 2f;
recoil = 2f;
restitution = 0.03f;
range = 125;
shootCone = 40f;
@@ -3920,8 +3921,8 @@ public class Blocks{
ammoPerShot = 4;
maxAmmo = ammoPerShot * 3;
targetAir = false;
shootShake = 4f;
recoilAmount = 1f;
shake = 4f;
recoil = 1f;
reload = 60f * 2.3f;
shootY = 7f;
rotateSpeed = 1.4f;

View File

@@ -395,7 +395,12 @@ public class ContentParser{
for(JsonValue child : value.get("consumes")){
switch(child.name){
case "item" -> block.consumeItem(find(ContentType.item, child.asString()));
case "itemCharged" -> block.consume((Consume)parser.readValue(ConsumeItemCharged.class, child));
case "itemFlammable" -> block.consume((Consume)parser.readValue(ConsumeItemFlammable.class, child));
case "itemRadioactive" -> block.consume((Consume)parser.readValue(ConsumeItemRadioactive.class, child));
case "itemExplosive" -> block.consume((Consume)parser.readValue(ConsumeItemExplosive.class, child));
case "items" -> block.consume((Consume)parser.readValue(ConsumeItems.class, child));
case "liquidFlammable" -> block.consume((Consume)parser.readValue(ConsumeLiquidFlammable.class, child));
case "liquid" -> block.consume((Consume)parser.readValue(ConsumeLiquid.class, child));
case "liquids" -> block.consume((Consume)parser.readValue(ConsumeLiquids.class, child));
case "coolant" -> block.consume((Consume)parser.readValue(ConsumeCoolant.class, child));

View File

@@ -68,6 +68,8 @@ public class Weapon implements Cloneable{
public float recoil = 1.5f;
/** the time it returns back to its original position in ticks. uses reload time by default */
public float recoilTime = -1f;
/** ticks to cool down the heat region */
public float cooldownTime = 20f;
/** projectile/effect offsets from center of weapon */
public float shootX = 0f, shootY = 3f;
/** offsets of weapon position on unit */
@@ -82,8 +84,6 @@ public class Weapon implements Cloneable{
public float shootCone = 5f;
/** Cone in which the weapon can rotate relative to its mount. */
public float rotationLimit = 361f;
/** ticks to cool down the heat region */
public float cooldownTime = 20f;
/** minimum weapon warmup before firing (this is not linear, do NOT use 1!) */
public float minWarmup = 0f;
/** lerp speed for shoot warmup, only used for parts */

View File

@@ -93,7 +93,7 @@ public class ContinuousTurret extends Turret{
wasShooting = true;
heat = 1f;
recoil = recoilAmount;
curRecoil = recoil;
}
}

View File

@@ -76,7 +76,7 @@ public class LaserTurret extends PowerTurret{
wasShooting = true;
heat = 1f;
recoil = recoilAmount;
curRecoil = recoil;
}else if(reloadCounter > 0){
wasShooting = true;

View File

@@ -34,35 +34,20 @@ public class Turret extends ReloadTurret{
public final static float logicControlCooldown = 60 * 2;
public final int timerTarget = timers++;
public int targetInterval = 20;
public Color heatColor = Pal.turretHeat;
public Effect shootEffect = Fx.none;
public Effect smokeEffect = Fx.none;
public Effect ammoUseEffect = Fx.none;
public Sound shootSound = Sounds.shoot;
public Sound chargeSound = Sounds.none;
public float soundPitchMin = 0.9f, soundPitchMax = 1.1f;
//visuals TODO document
public float ammoEjectBack = 1f;
public float shootWarmupSpeed = 0.1f;
public boolean linearWarmup = false;
public float recoilAmount = 1f;
public float restitution = 0.02f;
public float cooldown = 0.02f;
public float elevation = -1f;
public float shootShake = 0f;
/** Ticks between attempt at finding a target. */
public float targetInterval = 20;
/** Maximum ammo units stored. */
public int maxAmmo = 30;
/** Ammo units used per shot. */
public int ammoPerShot = 1;
/** If true, ammo is only consumed once per shot regardless of bullet count. */
public boolean consumeAmmoOnce = false;
/** Minimum input heat required to fire. */
public float heatRequirement = -1f;
/** Maximum efficiency possible, if this turret uses heat. */
public float maxHeatEfficiency = 3f;
//TODO clean all of this up + weapon consistency
/** Bullet angle randomness in degrees. */
public float inaccuracy = 0f;
/** Fraction of bullet velocity that is random. */
@@ -71,7 +56,7 @@ public class Turret extends ReloadTurret{
public float shootCone = 8f;
/** Turret shoot point. */
public float shootX = 0f, shootY = Float.NEGATIVE_INFINITY;
/** Currently used for artillery only. */
/** Minimum bullet range. Used for artillery only. */
public float minRange = 0f;
/** Minimum warmup needed to fire. */
public float minWarmup = 0f;
@@ -82,15 +67,55 @@ public class Turret extends ReloadTurret{
/** pattern used for bullets */
public ShootPattern shoot = new ShootPattern();
/** If true, this block targets air units. */
public boolean targetAir = true;
/** If true, this block targets ground units and structures. */
public boolean targetGround = true;
/** If true, this block targets friend blocks, to heal them. */
public boolean targetHealing = false;
/** If true, this turret can be controlled by players. */
public boolean playerControllable = true;
/** If true, this block will display ammo multipliers in its stats (irrelevant for certain types of turrets). */
public boolean displayAmmoMultiplier = true;
/** Function for choosing which unit to target. */
public Sortf unitSort = UnitSorts.closest;
/** Filter for types of units to attack. */
public Boolf<Unit> unitFilter = u -> true;
/** Filter for types of buildings to attack. */
public Boolf<Building> buildingFilter = b -> !b.block.underBullets;
/** Color of heat region drawn on top (if found) */
public Color heatColor = Pal.turretHeat;
/** Optional override for all shoot effects. */
public @Nullable Effect shootEffect;
/** Optional override for all smoke effects. */
public @Nullable Effect smokeEffect;
/** Optional override for all ammo use effects. */
public @Nullable Effect ammoUseEffect;
/** Sound emitted when a single bullet is shot. */
public Sound shootSound = Sounds.shoot;
/** Sound emitted when shoot.firstShotDelay is >0 and shooting begins. */
public Sound chargeSound = Sounds.none;
/** Range for pitch of shoot sound. */
public float soundPitchMin = 0.9f, soundPitchMax = 1.1f;
/** Backwards Y offset of ammo eject effect. */
public float ammoEjectBack = 1f;
/** Lerp speed of turret warmup. */
public float shootWarmupSpeed = 0.1f;
/** If true, turret warmup is linear instead of a curve. */
public boolean linearWarmup = false;
/** Visual amount by which the turret recoils back per shot. */
public float recoil = 1f;
/** TODO rename */
public float restitution = 0.02f;
/** TODO rename */
public float cooldown = 0.02f;
/** Visual elevation of turret shadow, -1 to use defaults. */
public float elevation = -1f;
/** How much the screen shakes per shot. */
public float shake = 0f;
/** Defines drawing behavior for this turret. */
public DrawBlock drawer = new DrawTurret();
public Turret(String name){
@@ -168,7 +193,7 @@ public class Turret extends ReloadTurret{
public Seq<AmmoEntry> ammo = new Seq<>();
public int totalAmmo;
public float recoil, heat, logicControlTime = -1;
public float curRecoil, heat, logicControlTime = -1;
public float shootWarmup;
public int totalShots;
public boolean logicShooting = false;
@@ -315,13 +340,13 @@ public class Turret extends ReloadTurret{
wasShooting = false;
//TODO do not lerp
recoil = Mathf.lerpDelta(recoil, 0f, restitution);
curRecoil = Mathf.lerpDelta(curRecoil, 0f, restitution);
heat = Mathf.lerpDelta(heat, 0f, cooldown);
unit.tile(this);
unit.rotation(rotation);
unit.team(team);
recoilOffset.trns(rotation, -recoil);
recoilOffset.trns(rotation, -curRecoil);
if(logicControlTime > 0){
logicControlTime -= Time.delta;
@@ -511,8 +536,8 @@ public class Turret extends ReloadTurret{
//TODO aimX / aimY for multi shot turrets?
handleBullet(type.create(this, team, bulletX, bulletY, shootAngle, -1f, (1f - velocityRnd) + Mathf.random(velocityRnd), lifeScl, null, mover, targetPos.x, targetPos.y), xOffset, yOffset, angleOffset);
(shootEffect == Fx.none ? type.shootEffect : shootEffect).at(bulletX, bulletY, rotation + angleOffset, type.hitColor);
(smokeEffect == Fx.none ? type.smokeEffect : smokeEffect).at(bulletX, bulletY, rotation + angleOffset, type.hitColor);
(shootEffect == null ? type.shootEffect : shootEffect).at(bulletX, bulletY, rotation + angleOffset, type.hitColor);
(smokeEffect == null ? type.smokeEffect : smokeEffect).at(bulletX, bulletY, rotation + angleOffset, type.hitColor);
shootSound.at(bulletX, bulletY, Mathf.random(soundPitchMin, soundPitchMax));
ammoUseEffect.at(
@@ -521,11 +546,11 @@ public class Turret extends ReloadTurret{
rotation * Mathf.sign(xOffset)
);
if(shootShake > 0){
Effect.shake(shootShake, shootShake, this);
if(shake > 0){
Effect.shake(shake, shake, this);
}
recoil = recoilAmount;
curRecoil = recoil;
heat = 1f;
if(!consumeAmmoOnce){

View File

@@ -138,7 +138,7 @@ public class Conveyor extends Block implements Autotiler{
@Override
public void draw(){
int frame = enabled && clogHeat <= 0.5f ? (int)(((Time.time * speed * 8f * timeScale)) % 4) : 0;
int frame = enabled && clogHeat <= 0.5f ? (int)(((Time.time * speed * 8f * timeScale * efficiency)) % 4) : 0;
//draw extra conveyors facing this one for non-square tiling purposes
Draw.z(Layer.blockUnder);

View File

@@ -4,9 +4,11 @@ import mindustry.gen.*;
/** For mods. I don't use this (yet). */
public class ConsumeItemCharged extends ConsumeItemFilter{
public float minCharge;
public ConsumeItemCharged(float minCharge){
super(item -> item.charge >= minCharge);
this.minCharge = minCharge;
filter = item -> item.charge >= this.minCharge;
}
public ConsumeItemCharged(){

View File

@@ -3,9 +3,11 @@ package mindustry.world.consumers;
import mindustry.gen.*;
public class ConsumeItemExplosive extends ConsumeItemFilter{
public float minExplosiveness;
public ConsumeItemExplosive(float minExplosiveness){
super(item -> item.explosiveness >= minExplosiveness);
public ConsumeItemExplosive(float minCharge){
this.minExplosiveness = minCharge;
filter = item -> item.explosiveness >= this.minExplosiveness;
}
public ConsumeItemExplosive(){

View File

@@ -12,12 +12,15 @@ import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class ConsumeItemFilter extends Consume{
public final Boolf<Item> filter;
public Boolf<Item> filter = i -> false;
public ConsumeItemFilter(Boolf<Item> item){
this.filter = item;
}
public ConsumeItemFilter(){
}
@Override
public void apply(Block block){
block.hasItems = true;

View File

@@ -3,9 +3,11 @@ package mindustry.world.consumers;
import mindustry.gen.*;
public class ConsumeItemFlammable extends ConsumeItemFilter{
public float minFlammability;
public ConsumeItemFlammable(float minFlammability){
super(item -> item.flammability >= minFlammability);
this.minFlammability = minFlammability;
filter = item -> item.flammability >= this.minFlammability;
}
public ConsumeItemFlammable(){

View File

@@ -3,9 +3,11 @@ package mindustry.world.consumers;
import mindustry.gen.*;
public class ConsumeItemRadioactive extends ConsumeItemFilter{
public float minRadioactivity;
public ConsumeItemRadioactive(float minRadioactivity){
super(item -> item.radioactivity >= minRadioactivity);
this.minRadioactivity = minRadioactivity;
filter = item -> item.radioactivity >= this.minRadioactivity;
}
public ConsumeItemRadioactive(){

View File

@@ -13,7 +13,7 @@ import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class ConsumeLiquidFilter extends ConsumeLiquidBase{
public Boolf<Liquid> filter;
public Boolf<Liquid> filter = l -> false;
public ConsumeLiquidFilter(Boolf<Liquid> liquid, float amount){
super(amount);
@@ -21,7 +21,6 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{
}
public ConsumeLiquidFilter(){
this.filter = l -> false;
}
@Override

View File

@@ -3,13 +3,15 @@ package mindustry.world.consumers;
import mindustry.gen.*;
public class ConsumeLiquidFlammable extends ConsumeLiquidFilter{
public float minFlammability;
public ConsumeLiquidFlammable(float minFlammability, float amount){
super(item -> item.flammability >= minFlammability, amount);
public ConsumeLiquidFlammable(float minFlammability){
this.minFlammability = minFlammability;
filter = liquid -> liquid.flammability >= this.minFlammability;
}
public ConsumeLiquidFlammable(float amount){
this(0.2f, amount);
public ConsumeLiquidFlammable(){
this(0.2f);
}
@Override

View File

@@ -18,6 +18,7 @@ public class DrawTurret extends DrawBlock{
protected static final Rand rand = new Rand();
public Seq<DrawPart> parts = new Seq<>();
/** Prefix to use when loading base region. */
public String basePrefix = "";
/** Overrides the liquid to draw in the liquid region. */
public @Nullable Liquid liquidDraw;