Turret accurateDelay parameter
This commit is contained in:
@@ -9,8 +9,8 @@ import mindustry.gen.*;
|
||||
* Class for predicting shoot angles based on velocities of targets.
|
||||
*/
|
||||
public class Predict{
|
||||
private static Vec2 vec = new Vec2();
|
||||
private static Vec2 vresult = new Vec2();
|
||||
private static final Vec2 vec = new Vec2();
|
||||
private static final Vec2 vresult = new Vec2();
|
||||
|
||||
/**
|
||||
* Calculates of intercept of a stationary and moving target. Do not call from multiple threads!
|
||||
@@ -52,6 +52,10 @@ public class Predict{
|
||||
}
|
||||
|
||||
public static Vec2 intercept(Position src, Position dst, float v){
|
||||
return intercept(src, dst, 0, 0, v);
|
||||
}
|
||||
|
||||
public static Vec2 intercept(Position src, Position dst, float offsetx, float offsety, float v){
|
||||
float ddx = 0, ddy = 0;
|
||||
if(dst instanceof Hitboxc h){
|
||||
ddx += h.deltaX();
|
||||
@@ -61,7 +65,7 @@ public class Predict{
|
||||
ddx -= h.deltaX();
|
||||
ddy -= h.deltaY();
|
||||
}
|
||||
return intercept(src.getX(), src.getY(), dst.getX(), dst.getY(), ddx, ddy, v);
|
||||
return intercept(src.getX(), src.getY(), dst.getX() + offsetx, dst.getY() + offsety, ddx, ddy, v);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,6 +60,8 @@ public class Turret extends ReloadTurret{
|
||||
public float minRange = 0f;
|
||||
public float burstSpacing = 0;
|
||||
public boolean alternate = false;
|
||||
/** If true, this turret will accurately target moving targets with respect to charge time. */
|
||||
public boolean accurateDelay = false;
|
||||
public boolean targetAir = true;
|
||||
public boolean targetGround = true;
|
||||
|
||||
@@ -216,11 +218,16 @@ public class Turret extends ReloadTurret{
|
||||
public void targetPosition(Posc pos){
|
||||
if(!hasAmmo() || pos == null) return;
|
||||
BulletType bullet = peekAmmo();
|
||||
float speed = bullet.speed;
|
||||
//slow bullets never intersect
|
||||
if(speed < 0.1f) speed = 9999999f;
|
||||
|
||||
targetPos.set(Predict.intercept(this, pos, speed));
|
||||
var offset = Tmp.v1.setZero();
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
targetPos.set(Predict.intercept(this, pos, offset.x, offset.y, bullet.speed <= 0.01f ? 99999999f : bullet.speed));
|
||||
|
||||
if(targetPos.isZero()){
|
||||
targetPos.set(pos);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user