Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: spawnProjectile bug  (Read 1376 times)

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
spawnProjectile bug
« on: December 14, 2013, 05:26:34 PM »

Spoiler
missiles spawned with spawnProjectile do not get their AI consistently

to be specific it seems to have problems about 90% of the time

Code
            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
Code: java
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);    }
    }
}

[close]

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
[close]
fixed/bugfound, getSource does not work properly on spawnProjectile objects: using launchingship seems to be more much more consistent
« Last Edit: December 15, 2013, 05:02:11 AM by dmaiski »
Logged
BISO
(WIP) lots of shiny new weapons ( :-[ i have more weapons then sprites :-[ )

i got a cat pad
its like a mouse pad but better!

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: spawnProjectile bug
« Reply #1 on: December 14, 2013, 09:08:41 PM »

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 :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: spawnProjectile bug
« Reply #2 on: December 15, 2013, 03:20:57 AM »

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 :P
Logged
BISO
(WIP) lots of shiny new weapons ( :-[ i have more weapons then sprites :-[ )

i got a cat pad
its like a mouse pad but better!