missiles spawned with spawnProjectile do not get their AI consistently
to be specific it seems to have problems about 90% of the time
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()
);
code spawning the missile
same missile sucsessfully runs when launched using normal weapon from ship
code of the AI, its a simple one 92 lines...
Spoiler
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); }
}
}
curently trying to track down what exactly is causing the problem
it seems that very often they fail to get missile.getSource
ok after the first missile is launched(after startup) subsequent missiles become unable to getSource,
spawnProjectile also breaks(this happens on the first run through when the rest of the AI is working corectly, spawnEmpArk works fine in this case)
final test from tonight:
exiting combat(general): causes missileAI to become unable to call missile.getSource or use launchingShip from when the ai is set
spawnProjectile missiles: unable to use spawnProjectile commands on ocasions (related to above issue)
note: this has not caused any null exceptions to date, there is a chance that this happend because the ShipAPI from the previous instance has not been cleared