Spoiler
missiles spawned with spawnProjectile do not get their AI consistently
to be specific it seems to have problems about 90% of the time
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); }
}
}
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
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
im not actualy sure what is going on with this case, but something is broken (error seems to be related to spwanProjectile but im not sure what is cause)
postid this thread in sugestions by accident