1
Bug Reports & Support / Spawn on asteroid
« on: October 27, 2014, 05:56:27 PM »
Spawn on asteroid battle bug is still a thing, 6000 damage at the start of battle instagibbed my poor wolf...
Starsector 0.97a is out! (02/02/24); New blog post: Planet Search Overhaul (07/13/24)
//find intercept between a missile and a target
//adapted from code by Jens Seiler
//http://jaran.de/goodbits/2011/07/17/calculating-an-intercept-course-to-a-target-with-constant-direction-and-velocity-in-a-2-dimensional-plane/
//have fun if you want to actually understand what going on
//basicaly gets where T will be by the time M gets to it
public static Vector2f LeadVector(Vector2f TLoc, Vector2f TVel, Vector2f MLoc, Vector2f MVel)
{
//get missiles speed
float MSpeed = (float)Math.sqrt(MVel.lengthSquared());
//separate out the vectors
float Tx = TLoc.getX();
float Ty = TLoc.getY();
float Mx = MLoc.getX();
float My = MLoc.getY();
float TVx = TVel.getX();
float TVy = TVel.getY();
//subtract position vectors
float x1 = Tx - Mx;
float y1 = Ty - My;
//quadratic fun
float h1 = TVx*TVx + TVy*TVy - MSpeed*MSpeed;
if (h1==0)
{
h1= (float) .0001;
}
float minusMHalf = -(x1*TVx + y1*TVy)/h1; // h2/h1
float discriminant = minusMHalf * minusMHalf - (x1*x1 + y1*y1)/h1; // (h2/h1)^2-h3/h1 (ie D)
//can they intersect?
if (discriminant < 0)
{
return new Vector2f(0,0);
}
double root = Math.sqrt(discriminant);
double t1 = minusMHalf + root;
double t2 = minusMHalf - root;
double tMin = Math.min(t1, t2);
double tMax = Math.max(t1, t2);
//which of the 2 is smaller
double time = tMin > 0 ? tMin : tMax;
//can return -ve time (this is less then useful)
if (time < 0)
{
return new Vector2f(0,0);
}
//calculate vector
return new Vector2f((float)(time * TVx), (float)(time * TVy));
}
Vector2f QVel = query.getVelocity();
engine.addFloatingText(QLoc, "Av-> "+QVel, 20f, Color.RED, beam.getSource(), 1f, .5f);
//towards line (not used)
Vector2f ToL = V2fPerpendicularDisc(dir, (Sadj < 100 ? Sadj : 100), (DtoL<0? 1:0));
//towards end (just adds 100 velocity each tick, 50 ticks/second)
Vector2f ToE = V2fReSize(dir, (Sadj < 100 ? Sadj : 100));
//adjust the velocity (velocity calculator)
Vector2f Qre = new Vector2f(QVel.getX()+ToE.getX()/*+ToL.getX()*/,
QVel.getY()+ToE.getY()/*+ToL.getY()*/);
//setting the velocity
QVel.set(Qre);
//also tested using
//QVel.set(QVel); //observed same 600 speed cap
package data.scripts.MissileAI;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.combat.*;
import com.fs.starfarer.api.util.IntervalUtil;
import org.lazywizard.lazylib.combat.AIUtils;
import org.lwjgl.util.vector.Vector2f;
import java.awt.*;
import static jar.UtilityKit.getNearestMissileToPoint;
public class BalundirLightningAI implements MissileAIPlugin{
private final MissileAPI missile;
private ShipAPI launchingShip;
private IntervalUtil MainTimer = new IntervalUtil(2f, 0.5f);
private IntervalUtil ShortTimer = new IntervalUtil(.5f, 0.4f);
private IntervalUtil LongTimer = new IntervalUtil(5f, 0.5f);
private static boolean Fire=false;
private static boolean Fire2=false;
public BalundirLightningAI(MissileAPI missile, ShipAPI launchingShip)
{
this.missile = missile;
this.launchingShip = launchingShip;
}
//main missile AI
private Vector2f MouseT=new Vector2f(0,0);
@Override
public void advance(float amount)
{
CombatEngineAPI engine = Global.getCombatEngine();
// pause when you are not needed
if (missile.isFading() || missile.isFizzling() || engine.isPaused())
{
return;
}
if (MouseT.lengthSquared()==0)
{
MouseT = new Vector2f(launchingShip.getMouseTarget());
if (MouseT.lengthSquared()==0)
{
missile.setSource(AIUtils.getNearestAlly(missile));
}
}
ShortTimer.advance(amount);
MainTimer.advance(amount);
LongTimer.advance(amount);
if (MainTimer.intervalElapsed())
{
Fire = true;
}
if (ShortTimer.intervalElapsed()){
Fire2 = true;
}
if (Fire && Fire2) {
Fire2=false;
engine.spawnProjectile(
launchingShip,
null,
"targetdot",
MouseT,
0,
new Vector2f(0,0));
MissileAPI target = getNearestMissileToPoint(MouseT);
engine.spawnEmpArc(
launchingShip,
missile.getLocation(),
target, target,
DamageType.ENERGY,
0f, //real
0, //emp
10000f, // max range
"tachyon_lance_emp_impact",
5f, // thickness
new Color(255,10,15,255),
new Color(31, 214,255,255)
);
}
if (LongTimer.intervalElapsed()) {
engine.removeEntity(missile); }
}
}
no the ai itself activates fine, its just parts of the ai like ShipAPI launchingship that encounter problems that souldnt really happen also i need to move this top bug reports, wrote it at 5am today
So just set the source as the closest friendly ShipAPI?
Also, you can set the AI directly after it's spawned, instead of hoping that it's caught when the MissileAPI is instantiated via the Plugin
engine.spawnProjectile(
weapon.getShip(),
weapon, //who made you
"SM_SCbombard", //spawn the projectile
new Vector2f(WL.getX()+5, WL.getY()+5), //Vector2f firing origin point
weapon.getArcFacing()+weapon.getShip().getFacing(), //float angle of fire
weapon.getShip().getVelocity()
);
package data.scripts.MissileAI;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.combat.*;
import com.fs.starfarer.api.util.IntervalUtil;
import org.lwjgl.util.vector.Vector2f;
import java.awt.*;
import static jar.UtilityKit.getNearestMissileToPoint;
public class BalundirLightningAI implements MissileAIPlugin{
private final MissileAPI missile;
private static CombatEngineAPI engine = Global.getCombatEngine();
private static ShipAPI MSource=null;
private static WeaponAPI MWeapon=null;
private IntervalUtil MainTimer = new IntervalUtil(2f, 0.5f);
private IntervalUtil ShortTimer = new IntervalUtil(.5f, 0.4f);
private IntervalUtil LongTimer = new IntervalUtil(5f, 0.5f);
private static boolean Fire=false;
public BalundirLightningAI(MissileAPI missile)
{
this.missile = missile;
MSource=missile.getSource();
MWeapon=missile.getWeapon();
}
//main missile AI
private Vector2f MouseT=new Vector2f(0,0);
@Override
public void advance(float amount)
{
// pause when you are not needed
if (missile.isFading() || missile.isFizzling() || engine.isPaused())
{
return;
}
if (MouseT.lengthSquared()==0)
{
MouseT = new Vector2f(missile.getSource().getMouseTarget());
}
ShortTimer.advance(amount);
MainTimer.advance(amount);
LongTimer.advance(amount);
if (MainTimer.intervalElapsed())
{
Fire = true;
}
if (Fire && ShortTimer.intervalElapsed()) {
engine.spawnProjectile(
MSource,
MWeapon,
"targetdot",
MouseT,
0,
new Vector2f(0,0));
MissileAPI target = getNearestMissileToPoint(MouseT);
engine.spawnEmpArc(
MSource,
missile.getLocation(),
target, target,
DamageType.ENERGY,
0f, //real
0, //emp
10000f, // max range
"tachyon_lance_emp_impact",
5f, // thickness
new Color(255,10,15,255),
new Color(31, 214,255,255)
);
}
if (LongTimer.intervalElapsed()) {
engine.removeEntity(missile); }
}
}
int maxX = armorgrid.getLeftOf()+armorgrid.getRightOf();
int maxY = armorgrid.getAbove()+armorgrid.getBelow();
int counter = 0;
for (int X=0; X<maxX; X++)
{
for (int Y=0; Y<maxY; Y++)
{
counter++;}}