Re-added xRand

This commit is contained in:
Anuken
2022-05-16 13:50:40 -04:00
parent 2641404f46
commit 13e57ba89e
3 changed files with 10 additions and 5 deletions

View File

@@ -279,7 +279,6 @@ public class ContentParser{
readFields(obj, data);
return obj;
});
put(Ability.class, (type, data) -> {
Class<? extends Ability> oc = resolve(data.getString("type", ""));
data.remove("type");

View File

@@ -75,6 +75,8 @@ public class Weapon implements Cloneable{
public float shootX = 0f, shootY = 3f;
/** offsets of weapon position on unit */
public float x = 5f, y = 0f;
/** Random spread on the X axis. */
public float xRand = 0f;
/** pattern used for bullets */
public ShootPattern shoot = new ShootPattern();
/** radius of shadow drawn under the weapon; <0 to disable */
@@ -398,11 +400,12 @@ public class Weapon implements Cloneable{
if(!unit.isAdded()) return;
float
xSpread = Mathf.range(xRand),
weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : baseRotation),
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 + xOffset, this.shootY + yOffset),
bulletY = mountY + Angles.trnsy(weaponRotation, this.shootX + xOffset, this.shootY + yOffset),
bulletX = mountX + Angles.trnsx(weaponRotation, this.shootX + xOffset + xSpread, this.shootY + yOffset),
bulletY = mountY + Angles.trnsy(weaponRotation, this.shootX + xOffset + xSpread, this.shootY + yOffset),
shootAngle = bulletRotation(unit, mount, bulletX, bulletY) + angleOffset,
lifeScl = bullet.scaleLife ? Mathf.clamp(Mathf.dst(bulletX, bulletY, mount.aimX, mount.aimY) / bullet.range) : 1f,
angle = angleOffset + shootAngle + Mathf.range(inaccuracy);

View File

@@ -56,6 +56,8 @@ public class Turret extends ReloadTurret{
public float shootCone = 8f;
/** Turret shoot point. */
public float shootX = 0f, shootY = Float.NEGATIVE_INFINITY;
/** Random spread on the X axis. */
public float xRand = 0f;
/** Minimum bullet range. Used for artillery only. */
public float minRange = 0f;
/** Minimum warmup needed to fire. */
@@ -533,8 +535,9 @@ public class Turret extends ReloadTurret{
if(dead || (!consumeAmmoOnce && !hasAmmo())) return;
float
bulletX = x + Angles.trnsx(rotation - 90, shootX + xOffset, shootY + yOffset),
bulletY = y + Angles.trnsy(rotation - 90, shootX + xOffset, shootY + yOffset),
xSpread = Mathf.range(xRand),
bulletX = x + Angles.trnsx(rotation - 90, shootX + xOffset + xSpread, shootY + yOffset),
bulletY = y + Angles.trnsy(rotation - 90, shootX + xOffset + xSpread, shootY + yOffset),
shootAngle = rotation + angleOffset + Mathf.range(inaccuracy);
float lifeScl = type.scaleLife ? Mathf.clamp(Mathf.dst(bulletX, bulletY, targetPos.x, targetPos.y) / type.range, minRange / type.range, range() / type.range) : 1f;