Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.9.1a is out! (05/10/19); Updated the Forum Rules and Guidelines (02/29/20); Blog post: GIF Roundup (04/11/20)

Pages: 1 [2] 3 4 ... 9

Author Topic: The Radioactive Code Dump  (Read 64376 times)

Sproginator

  • Admiral
  • *****
  • Posts: 3592
  • Forum Ancient
    • View Profile
Re: The Radioactive Code Dump
« Reply #15 on: September 01, 2013, 05:47:32 AM »

Very interesting stockpile you all have here. I'll be keeping an eye on this for when .6 comes out :)
Logged
A person who's never made a mistake, never tried anything new
- Albert Einstein

As long as we don't quit, we haven't failed
- Jamie Fristrom (Programmer for Spiderman2 & Lead Developer for Energy Hook)

Gotcha!

  • Admiral
  • *****
  • Posts: 1109
    • View Profile
    • Welcome to New Hiigara
Re: The Radioactive Code Dump
« Reply #16 on: September 18, 2013, 03:55:04 PM »

Would anyone know how to properly implement the Heat Special Projectile?
Spoiler
I've added this line to one of my projectiles:
Code
"onHitEffect":"data.scripts.plugins.HiiHeatCannonEffect",

But regardless of adding that line I get the following error:

Code
29903 [Thread-6] ERROR com.fs.starfarer.combat.D  - java.lang.RuntimeException: Error compiling [data.scripts.plugins.HiiHeatCannonEffect]
java.lang.RuntimeException: Error compiling [data.scripts.plugins.HiiHeatCannonEffect]
at com.fs.starfarer.loading.scripts.ScriptStore$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: Parsing compilation unit "[email protected]"
at org.codehaus.janino.JavaSourceIClassLoader.findIClass(JavaSourceIClassLoader.java:180)
at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:158)
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:199)
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:164)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 2 more
Caused by: org.codehaus.commons.compiler.CompileException: Source file "data/scripts/plugins/HiiHeatCannonEffect.java" does not declare class "data.scripts.plugins.HiiHeatCannonEffect"
at org.codehaus.janino.JavaSourceIClassLoader.findIClass(JavaSourceIClassLoader.java:165)
... 7 more

The contents of HiiHeatCannonEffect.java:

Code
package data.scripts;

import java.awt.Color;

import org.lwjgl.util.vector.Vector2f;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.combat.DamageType;
import com.fs.starfarer.api.combat.DamagingProjectileAPI;
import com.fs.starfarer.api.combat.OnHitEffectPlugin;
import com.fs.starfarer.api.combat.ShipAPI;

import org.lazywizard.lazylib.CollisionUtils;
import org.lazywizard.lazylib.MathUtils;

public class HiiHeatCannonEffect implements OnHitEffectPlugin {

public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target,
 Vector2f point, boolean shieldHit, CombatEngineAPI engine) {
if (target instanceof ShipAPI) {
float emp = projectile.getEmpAmount() * 0.1f;
float dam = projectile.getDamageAmount() * 0.1f;
WeaponAPI weapon = projectile.getWeapon();
DamageType damType = weapon.getDamageType();
int heatMe = (int) Math.max(6f,dam / 150f);

Vector2f targLoc = target.getLocation();
for(int i = 0; i < heatMe; i++)
{
//Gets a point far, far away and uses it as our ray-test point.  Long distances work better than shorter ones.
Vector2f cloneLoc = MathUtils.getRandomPointOnCircumference(targLoc, 1000000f);

//Try to get a valid collision point between our explosion's point source and the Entity.
Vector2f colPoint = CollisionUtils.getCollisionPoint(cloneLoc, targLoc, target);
//If we can't get a good collision point, use the center of the target Entity.  This is potentially a balance issue (hits all going to one armor cell are pretty OP lol), but this case mainly covers little teeny drones and suchlike that should be registering hits from giant explosions nearby, but often don't, for whatever reason.  Bigger things rarely fail, so it usually works out.
if(colPoint == null) colPoint = targLoc;
if(colPoint != null)//Must check this, getCollisionPoint returns null fairly frequently and that's a wrap
{
engine.applyDamage(
target, //enemy Entity
colPoint, //Our 2D vector to the exact world-position of the collision
dam, //DPS modified by the damage multiplier
damType, //Using the damage type here, so that Kinetic / Explosive / Fragmentation AOE works.
emp, //EMP (if any)
false, //Does not bypass shields.
false, //Does not do Soft Flux damage (unless you want it to for some strange reason)
projectile.getSource()  //Who owns this projectile?
);
}
}  
}
}
}
[close]

(Solved)
« Last Edit: September 18, 2013, 04:29:03 PM by Gotcha! »
Logged
  

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1292
    • View Profile
    • GitHub Profile
Re: The Radioactive Code Dump
« Reply #17 on: September 18, 2013, 04:24:29 PM »

Would anyone know how to properly implement the Heat Special Projectile?

You need to change
Code
package data.scripts;
to
Code
package data.scripts.plugins;
in your java file.
Logged

Gotcha!

  • Admiral
  • *****
  • Posts: 1109
    • View Profile
    • Welcome to New Hiigara
Re: The Radioactive Code Dump
« Reply #18 on: September 18, 2013, 04:28:43 PM »

That's.... not the first time I made that mistake. I hope it'll be the last. -_-'

Thanks again! <3

Nearing completion.
Logged
  

Uomoz

  • Admiral
  • *****
  • Posts: 2663
  • 'womo'dz
    • View Profile
    • Email
Re: The Radioactive Code Dump
« Reply #19 on: September 30, 2013, 05:52:11 AM »

Tried implementing the crit plugin in UsS, null pointer!

24312 [Thread-6] ERROR com.fs.starfarer.combat.D  - java.lang.NullPointerException
java.lang.NullPointerException
   at data.scripts.plugins.Crit.critSucessfull(Crit.java:191)
   at data.scripts.plugins.Crit.advance(Crit.java:172)
   at com.fs.starfarer.title.Object.K$Oo.o00000(Unknown Source)
   at com.fs.starfarer.combat.super.new.o00000(Unknown Source)
   at com.fs.starfarer.combat.CombatEngine.advance(Unknown Source)
   at com.fs.starfarer.title.B.super(Unknown Source)
   at com.fs.starfarer.new.øÒÒ000(Unknown Source)
   at com.fs.oOOO.super.new(Unknown Source)
   at com.fs.starfarer.combat.D.o00000(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)
Logged

silentstormpt

  • Admiral
  • *****
  • Posts: 1058
    • View Profile
Re: The Radioactive Code Dump
« Reply #20 on: September 30, 2013, 07:37:04 AM »

Dont forget the new version of Lazylib decrypted some methods used on that crit System, ill need to check what needs to be changed.

EDIT: Added a null check on the projectile, its not really a "fix" but more of a bandage, i need to upgrade the script anyway and remove/add other options besides a normal crit.
EDIT2: Might change the script to be used as a OnHit so its not so heavy in resources on huge fights, this means it needs to be added to every weapon tho.
« Last Edit: September 30, 2013, 07:52:25 AM by silentstormpt »
Logged

Gotcha!

  • Admiral
  • *****
  • Posts: 1109
    • View Profile
    • Welcome to New Hiigara
Re: The Radioactive Code Dump
« Reply #21 on: September 30, 2013, 09:51:58 AM »

Dont forget the new version of Lazylib decrypted some methods used on that crit System, ill need to check what needs to be changed.

Might change the script to be used as a OnHit so its not so heavy in resources on huge fights, this means it needs to be added to every weapon tho.

Please do!
Spoiler
[close]
Logged
  

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: The Radioactive Code Dump
« Reply #22 on: October 17, 2013, 07:00:50 AM »

i never thought id be here dumping nuclear waste...

a hemogeny inventor named alex once made an ion cannon, this cannon through unknown means fell into the vile tentacles of the BISO reaserch department... bad things happened to that poor ion cannon, unspeakable things! it is now fitted onto many BISO warships as standard for getting rid of pesky hemogeny ships

i present the BISO lightningstorm OnHitEffect script
made it more random, previous was only making a diagonal slash
made it confine itself to the area of the shield it hit (looks epic)
some more minor tweaks to make it work beter(i hope), and more balanced vs shields
final version with annotations to explain what is going on
Spoiler
Code: java
package data.scripts.onhiteffects;

import java.awt.Color;
import java.util.Random;

import com.fs.starfarer.api.combat.*;
import org.lwjgl.util.vector.Vector2f;

public class Lightningstorm implements OnHitEffectPlugin {


    public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target,
                      Vector2f point, boolean shieldHit, CombatEngineAPI engine) {

        if (target instanceof ShipAPI && !shieldHit) {   //only if hits hull
            do {
                double rnd1 = .5 - Math.random();      //see below for details
                float rn1 = (float)rnd1;
                double rnd2 = .5 - Math.random();
                float rn2 = (float)rnd2;    // +(float)rnd*2 to create a ring outside of ship
                float px = target.getLocation().getX();   //get center of cloud
                float py = target.getLocation().getY();   //get center of cloud
                float sr = target.getCollisionRadius();   //replace to change to manual area or effect
                Vector2f pa = new Vector2f(px + sr*rn1, py + sr*rn2);   //replace "sr" to change to manual area or effect
                float emp = projectile.getEmpAmount();
                float dam = projectile.getDamageAmount();
                engine.spawnEmpArc(projectile.getSource(), pa, target, target,
                    DamageType.ENERGY,
                    dam,
                    emp, // emp
                    sr, // max range prevent bolds hitting wrong side of the ship
                    "tachyon_lance_emp_impact",
                    20f, // thickness
                    new Color(255,10,15,255),
                    new Color(255,255,255,255)
                );
            }while ((float) Math.random() > 0.6f && target instanceof ShipAPI); //duration
        }
        else if (target instanceof ShipAPI && shieldHit) {     //only if hits shield
            do {
                double rnd1 = .5 - Math.random(); //generate a random double with -vs component, range -.5 to +.5
                float rn1 = (float)rnd1;          // convert to float
                double rnd2 = .5 - Math.random();
                float rn2 = (float)rnd2;    // +(float)rnd*2 to create a ring (implemented later in a better way)
                float px = target.getLocation().getX();   //get center of cloud
                float py = target.getLocation().getY();
                float hx = point.getX();   //get center of cloud
                float hy = point.getY();   //get center of cloud
                float sr = target.getCollisionRadius();   //replace to change to manual area or effect
                Vector2f pa = new Vector2f(hx + 1/2*(hx-px) + sr*rn1, hy + 1/2*(hy-py) + sr*rn2);   //cause bolt spawn center to be just outside of ship radius,
                //at the point where it was hit, within a radius bounded by max range(5/3*sr) and (1/2*sr) around point
                float emp = projectile.getEmpAmount();
                float dam = projectile.getDamageAmount();
                engine.spawnEmpArc(projectile.getSource(), pa, target, target,
                        DamageType.ENERGY,
                        2/4*dam, //make it less shield destroying
                        emp, // emp
                        5/3*sr, // max range make bolts hit hull closest
                        "tachyon_lance_emp_impact",
                        20f, // thickness
                        new Color(255,10,15,255),
                        new Color(255,255,255,255)
                );
                if ((float) Math.random() > 0.85f) { //generate additional bolts around ship 15% chance per loop
                    double rnd1b = .25 - .5*Math.random();
                    float rn1b = (float)rnd1b+(float)rnd1b*5;
                    double rnd2b = .25 - .5*Math.random();
                    float rn2b = (float)rnd2b+(float)rnd2b*5;    // +(float)rnd*2 to create a ring outside of ship
                    float pxb = target.getLocation().getX();   //get center of cloud
                    float pyb = target.getLocation().getY();   //get center of cloud
                    Vector2f pab = new Vector2f(pxb + sr*rn1b, pyb + sr*rn2b);   //replace "sr" to change to manual area or effect
                    engine.spawnEmpArc(projectile.getSource(), pab, target, target,
                            DamageType.ENERGY,
                            dam,
                            emp, // emp
                            10000f, // max range
                            "tachyon_lance_emp_impact",
                            20f, // thickness
                            new Color(255,10,15,255),
                            new Color(255,255,255,255)
                    );
                }

            }while ((float) Math.random() > 0.6f && target instanceof ShipAPI); //duration
        }

    }
}
//less scarry math
//Vector2f pa = new Vector2f(px + sr*rn1, py + sr*rn2);   //replace "sr" to change to manual area or effect
//creates a sphere of lightning around target ship

// +(float)rnd*2 to create a ring (implemented later in a better way):
//double rndx1 = rnd1/Math.abs(rnd1)*sr; //to generate exclusion zone of size sr


//projectile.getWeapon().getLocation()
// for arc from gun
//projectile.getDamageTarget().getLocation()
//long form for "point" Vector2f
[close]

Spoiler
[close]

it is complete!

old
Spoiler
[close]

things to do(ye gads, the workaround fairy came):
make it spawn purely visual bolts back to impact point when hitting shield
« Last Edit: October 22, 2013, 05:34:00 PM 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!

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: The Radioactive Code Dump
« Reply #23 on: October 18, 2013, 03:23:25 PM »

the BISO reaserch head presents, new MIRV code (with more variables, and it can do more stuff)

my curent working code(its beutifull):
Spoiler
Code: java
if (MathUtils.getDistance(
                add(target.getLocation(), target.getVelocity(), null),              //blow up the enemy ship
                add(missile.getLocation(), multV2f(missile.getVelocity(),3), null))
                < 200
                && MathUtils.getDistance(
                missile.getLocation(),                     //don't blow up your own ship
                missile.getSource().getLocation())
                >missile.getSource().getCollisionRadius()+5)
        {
            CombatEngine engine = CombatEngine.getInstance();          //engine

            String MBRC_p = "MBRC2";      //dummy weapon

            {
                    {
                        int counts = 1;
                        do {
                            float angRAND= (float) ((25*(.5-Math.random())));     //angle of spread
                            float velRAND= (float) (1+.5*(.5-Math.random()));      //variance of projectile speeds
                            float splashVEL = 255f*velRAND;    //speed of bullets launched
                            float misFFACE = missile.getFacing()-angRAND;
                            float x = (float) (splashVEL*Math.cos(Math.toRadians(misFFACE)));
                            float y = (float) (splashVEL*Math.sin(Math.toRadians(misFFACE)));
                            Vector2f vecFIRE = new Vector2f(x,y);
                            engine.spawnProjectile(null, null,MBRC_p,
                                    missile.getLocation(),          //Vector2f firing point
                                    misFFACE,            //float   angle of spread
                                    add(missile.getVelocity(), vecFIRE, null)

                                   //multV2f(multV2f(missile.getVelocity(),1),velRAND)           //Vector2f  aditional velocity
                                    //add(multV2f(missile.getVelocity(), 1), multRanV2f(missile.getVelocity(),1,.5f),null)
                            );
                            counts++;
                        }while (counts<30);         //30x pew pew

                        //engine.removeEntity(missile); //make missile go poof
                    }
                //lightning
                   // float emp = missile.getEmpAmount();
                    //float dam = missile.getDamageAmount();

                    //engine.spawnEmpArc(missile.getSource(), missile.getLocation(), target, target,
                           // DamageType.ENERGY,dam/4, emp/4,
                            //10000f, "tachyon_lance_emp_impact",20f, new Color(255,10,15,255),new Color(255,100,100,255));
                }
            //to stop missile shooting again
            //engine.removeEntity(missile);   //make missile go poof
            missile.flameOut();               //make missile flame out
            return;

        }

you also need these:
Code: java
// Will be in next LazyLib version
    public static float getAngleDifference(float angle1, float angle2)
    {
        float distance = (angle2 - angle1) + 180f;
        distance = (distance / 360.0f);
        distance = ((distance - (float) Math.floor(distance)) * 360f) - 180f;
        return distance;
    }
    //multiply vectors //own code
    public static Vector2f multV2f(Vector2f Vector1, float Multiplier)
    {
        float v1x = Vector1.getX()*Multiplier;
        float v1y = Vector1.getY()*Multiplier;
        Vector2f v1end = new Vector2f(v1x, v1y);
        return v1end;
    }
    //more code
    public static Vector2f multRanV2f(Vector2f Vector1, float Multiplier, float Random)
    {
        double rxd = .5 - Math.random(); //generate a random double with -vs component, range -.5 to +.5
        float rx = (float)rxd*2*Random;          // convert to float
        double ryd = .5 - Math.random();
        float ry = (float)ryd*2*Random;
        float v1x = Vector1.getX()*Multiplier*rx;
        float v1y = Vector1.getY()*Multiplier*ry;
        Vector2f v1end = new Vector2f(v1x, v1y);
        return v1end;
    }
}
[close]




old code made during a drunken stupor, more versetile, insanely complex
Spoiler
Spoiler
Code: java
//create variables
        //capitalized can be changed

        //insert targeter code here (anything goes, you may need to change it so T gives tx/ty a float value
        //see at bottom for possible code
        CombatEntityAPI T = target;//end point of " " (enemy api/point in space/ect) for targeter
        MissileAPI P = missile;    //start point of " " for weapon
        float px = P.getLocation().getX();   //get location og p (for center of dakakakaka)
        float py = P.getLocation().getY();
        float mvx = missile.getVelocity().getX();
        float mvy = missile.getVelocity().getY();
        float tx = px+mvx;   //get location of t (for center of pew pew)
        float ty = py+mvy;
        double rxd = .5 - Math.random(); //generate a random double with -vs component, range -.5 to +.5
        float rx = (float)rxd*2;          // convert to float
        double ryd = .5 - Math.random();
        float ry = (float)ryd*2;
        double rpd = Math.random(); //+ve random
        float rp = (float)rpd;
        float Tvar = 50f; //radius of t (sets mirv spread (angular))
        float Pvar = 1f;   //variable for vectors can use random float
        double prany = py/Math.abs(py)*Pvar;
        double pranx = px/Math.abs(px)*Pvar;
        float prx = (float)pranx;
        float pry = (float)prany;
        float Rvar = 5f; //how much the velocities of projectiles can vary
        double rvd = .5 - Math.random(); //generate a random double with -vs component, range -.5 to +.5
        float rv = (float)rxd*Rvar;



        //math

        float Fx = (tx * rx * Tvar);  //create randomized point field to shoot at
        float Fy = (ty * ry * Tvar);
        float Vx = (Fx * px * prx);         //create vectors for pewpews to follow
        float Vy = (Fy * py * pry);
        double Smoothv = (Math.sqrt(((tx-px)*(tx-px))+((ty-py)*(ty-py)))/Math.sqrt((Vx*Vx)+(Vy*Vy)))*rv;   //smoothes out ragged shot
        float Sv = (float) Smoothv;
        Vector2f Pjv = new Vector2f(Vx*Sv, Vy*Sv);   //make the actual vector

        //projectile spawn code here

        engine.removeEntity(missile); //make missile go poof
    }


//for canister of flashcetes behaviour
//CombatEntityAPI T = target;//end point of " " (enemy api/point in space/ect) for targeter
//MissileAPI P = missile;    //start point of " " for weapon
//float px = P.getLocation().getX();   //get location og p (for center of dakakakaka)
//float py = P.getLocation().getY();
//float mvx = missile.getVelocity().getX();
//float mvy = missile.getVelocity().getY();
//float tx = px+mvx;   //get location of t (for center of pew pew)
//float ty = py+mvy;
[close]

makes vectors to apply velocities to projectiles, and can pretymuch make any MIRV/mine/anything behaviour you want
Spoiler
Code
{
        //create variables
        //capitalized can be changed

        //insert targeter code here (anything goes, you may need to change it so T gives tx/ty a float value
        //see at bottom for possible code
        CombatEntityAPI T = target;//end point of " " (enemy api/point in space/ect) for targeter
        MissileAPI P = missile;    //start point of " " for weapon
        float px = P.getLocation().getX();   //get location og p (for center of dakakakaka)
        float py = P.getLocation().getY();
        //float mvx = missile.getVelocity().getX();
        //float mvy = missile.getVelocity().getY();
        float tx = T.getLocation().getX();   //get location of t (for center of pew pew)
        float ty = T.getLocation().getY();
        double rxd = .5 - Math.random(); //generate a random double with -vs component, range -.5 to +.5
        float rx = (float)rxd*2;          // convert to float
        double ryd = .5 - Math.random();
        float ry = (float)ryd*2;
        double rpd = Math.random(); //+ve random
        float rp = (float)rpd;
        float Tvar = 50f; //radius of t (sets mirv spread (angular))
        float Pvar = 1f;   //variable for vectors can use random float
        double prany = py/Math.abs(py)*Pvar;
        double pranx = px/Math.abs(px)*Pvar;
        float prx = (float)pranx;
        float pry = (float)prany;
        float Rvar = 5f; //how much the velocities of projectiles can vary
        double rvd = .5 - Math.random(); //generate random velocity multiplier for smooth function (to arr roughness back in
        float rv = (float)rvd*Rvar;



        //math

        float Fx = (tx * rx * Tvar);  //create randomized point field to shoot at
        float Fy = (ty * ry * Tvar);
        float Vx = (Fx * px * prx);         //create vectors for pewpews to follow
        float Vy = (Fy * py * pry);
        double Smoothv = (Math.sqrt(((tx-px)*(tx-px))+((ty-py)*(ty-py)))/Math.sqrt((Vx*Vx)+(Vy*Vy)))*rv;   //smoothes out ragged shot
        float Sv = (float) Smoothv;
        Vector2f Pjv = new Vector2f(Vx*Sv, Vy*Sv);   //make the actual vector

        engine.spawnProjectile(null, null,
               SBKR1,
                missile.getLocation(), 0,Pjv);

        engine.removeEntity(missile); //make missile go poof
    }
[close]
in theory this crates an skbr shell to fly at the enemy ship
[close]

big picture
Spoiler
Spoiler
[close]



sexy fireworks


accidentaly made awsome
[close]
« Last Edit: October 22, 2013, 05:37:36 PM 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!

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: The Radioactive Code Dump
« Reply #24 on: October 22, 2013, 02:18:47 PM »

DRONE missiles
Spoiler

[close]


stays at a set distance and blasts the enemy ships appart
who needs fighters anyways?


Spoiler
Code: java
int timer = 0;  //needs to be outside of advance() to work as a timer
int timer2 = (int) (600*Math.random());  //random start point for strafing
public void advance(float amount)
        {
        timer++;

        if (MathUtils.getDistance(
                add(target.getLocation(), target.getVelocity(), null),              //blow up the enemy ship
                add(missile.getLocation(), multV2f(missile.getVelocity(),3), null))
                < 600
                && MathUtils.getDistance(
                missile.getLocation(),                     //don't blow up your own ship
                missile.getSource().getLocation())
                >missile.getSource().getCollisionRadius()+5
                && timer==1
                )
        {
            timer++;
                CombatEngine engine = CombatEngine.getInstance();          //engine

                String MBRC_p = "MBRC2";      //dummy weapon

                {

                    {
                        int counts = 1;
                        do {
                            float angRAND= (float) ((25*(.5-Math.random())));     //angle of spread
                            float velRAND= (float) (1+.5*(.5-Math.random()));      //variance of projectile speeds
                            float splashVEL = 255f*velRAND;    //speed of bullets launched
                            float misFFACE = missile.getFacing()-angRAND;
                            float x = (float) (splashVEL*Math.cos(Math.toRadians(misFFACE)));
                            float y = (float) (splashVEL*Math.sin(Math.toRadians(misFFACE)));
                            Vector2f vecFIRE = new Vector2f(x,y);
                            engine.spawnProjectile(null, null,MBRC_p,
                                    missile.getLocation(),          //Vector2f firing point
                                    misFFACE,            //float   angle of spread
                                    add(missile.getVelocity(), vecFIRE, null)

                                    //multV2f(multV2f(missile.getVelocity(),1),velRAND)           //Vector2f  aditional velocity
                                    //add(multV2f(missile.getVelocity(), 1), multRanV2f(missile.getVelocity(),1,.5f),null)
                            );
                            counts++;
                        }while (counts<2);         //2x pew pew


                        //engine.removeEntity(missile); //make missile go poof
                    }
                    //lightning
                    // float emp = missile.getEmpAmount();
                    //float dam = missile.getDamageAmount();

                    //engine.spawnEmpArc(missile.getSource(), missile.getLocation(), target, target,
                    // DamageType.ENERGY,dam/4, emp/4,
                    //10000f, "tachyon_lance_emp_impact",20f, new Color(255,10,15,255),new Color(255,100,100,255));
                }
                //to stop missile shooting again
                //engine.removeEntity(missile);   //make missile go poof

                //missile.flameOut();               //make missile flame out
                return;
        }
        if (timer>40)
        {timer=0;}
        
        //missile pathing code
        if (Math.abs(angularDistance) < 100      //get in close
                && MathUtils.getDistance(missile.getLocation(), target.getLocation())
                >320+100/target.getCollisionRadius()*target.getCollisionRadius())
        {
            missile.giveCommand(ShipCommand.ACCELERATE);
        }
        if (Math.abs(angularDistance) < 100     //keep distance
                && MathUtils.getDistance(missile.getLocation(), target.getLocation())
                <280+100/target.getCollisionRadius()*target.getCollisionRadius())
        {
            missile.giveCommand(ShipCommand.ACCELERATE_BACKWARDS);
        }

        if (Math.abs(angularDistance) < 100   //strafe
                && MathUtils.getDistance(missile.getLocation(), target.getLocation())<400+target.getCollisionRadius())
        {
            missile.giveCommand(timer2 > 300 ? ShipCommand.STRAFE_LEFT : ShipCommand.STRAFE_RIGHT);
        }
        timer2++;
        if (timer2>600)
        {
            timer2=0;
        }
        }
[close]
« Last Edit: October 22, 2013, 05:38:02 PM 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!

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: The Radioactive Code Dump
« Reply #25 on: October 22, 2013, 05:31:06 PM »

BISO fleet have been known to leave quite a mess behind, mainly in the shattered hulls of the enemy, but also through the vast numbers of mines they habitually deploy during battle.

Here, the BISO research department presents their findings on the subject of intelligent munitions, and automated mine dispersal methods:

Spoiler

A1 minelayer deploying minefield


10 seconds later, minefield is forming, Cluster procesing is engaged to produce an even spread


test subject 129331 enters minefield, aproximate range from deployment zone, 3km


o gads the evilbastards!!! they teleported BEHIND my ship and deployed dozens of mines so I cant escape!!!
trully feindish!

btw, for those poor of vision, those pale yelow dots spread evenly across the map, they aren't stars i can tell you that much...
[close]
images, lots of them


beware, long, lots of code:


new "smart" mines that track enemy ships range to mine to maximize damage
also this code is optimized to use as few cpu cycles as posible, otherwhise verry dense minefields can cause crashes
Spoiler
Code: java
package data.scripts.MissileAI;


import com.fs.starfarer.api.combat.*;

import com.fs.starfarer.combat.CombatEngine;
import org.lazywizard.lazylib.MathUtils;
import org.lazywizard.lazylib.combat.AIUtils;
import org.lwjgl.util.vector.Vector2f;
import static org.lwjgl.util.vector.Vector2f.add;




public class CustomMINEMissileAI implements MissileAIPlugin
{
    // Our missile object
    private final MissileAPI missile;

    public CustomMINEMissileAI(MissileAPI missile)
    {
        this.missile = missile;
    }


    float range1 = 0;
    float range2 = 0;
    int trigger = 0;
    int deathcode = 0;
    double minetimer = 0;
    ShipAPI enemy=null;

    @Override
    public void advance(float amount)
    {
        CombatEngine engine = CombatEngine.getInstance();          //engine
        // Apparently commands still work while fizzling
        if (missile.isFading() || missile.isFizzling())
        {
            return;
        }


        minetimer++;




        //intelligent mine distribution code
        MissileAPI near = AIUtils.getNearestMissile(missile);

        if (near != null                               //check if there are any nearby mines
                && near.getProjectileSpecId().equals(missile.getProjectileSpecId())
                && MathUtils.getDistance(near, missile) < 400)
        {
            //if there are move away from them
            float angularDistance = getAngleDifference(
                    missile.getFacing(), MathUtils.getAngle(missile.getLocation(),
                    near.getLocation()));
            if (Math.abs(angularDistance) < 175)
            {
                missile.giveCommand(angularDistance < 0f
                        ? ShipCommand.TURN_LEFT : ShipCommand.TURN_RIGHT);
            }
            if (Math.abs(angularDistance) > 135)
            {
                missile.giveCommand(ShipCommand.ACCELERATE);
            }
            if (Math.abs(angularDistance) < 45)
            {
                missile.giveCommand(ShipCommand.ACCELERATE_BACKWARDS);
            }
        }
        else
        {
            missile.giveCommand(ShipCommand.DECELERATE);              //mine dose not move
        }

        //enemy tracking code
        if (Math.tanh(minetimer)>.2) //run once every 3 frames to prevent fun stuff
        {
            if (enemy==null && AIUtils.getNearestEnemy(missile)!=null && AIUtils.getNearestEnemy(missile).isAlive()
                    )
            {
                float targetfinder = MathUtils.getDistance(AIUtils.getNearestEnemy(missile).getLocation(), missile.getLocation())
                        -AIUtils.getNearestEnemy(missile).getCollisionRadius();
                if (targetfinder < 300)
                {
                    enemy=AIUtils.getNearestEnemy(missile);                //remember that enemy
                }
                if (targetfinder > 300)
                {
                    return;
                }

            }


            if (enemy != null)  //check if there is an enemy all these need it
            {
                if (enemy!=AIUtils.getNearestEnemy(missile))
                {
                    deathcode++;      //if a second enemy comes close
                    trigger++;
                }

                if (!enemy.isAlive() |  enemy.isHulk())
                {
                    enemy=null;      //if tracking enemy is dead, don't explode
                }

                if (deathcode==0 && range1==0
                        && MathUtils.getDistance(                               //find out if there are enemy in range
                        enemy.getLocation(),
                        missile.getLocation())-enemy.getCollisionRadius()
                        < 200)
                {
                    range1 = MathUtils.getDistance(                               //find get the range to target
                            enemy.getLocation(),
                            missile.getLocation())-enemy.getCollisionRadius();
                }
            }



            if (deathcode==0 && range1!=0)     //for all grouped in here
            {
                if (range1<100) //when enemy is close enough go boom
                {
                    trigger++;       //make it go boom
                    deathcode++;     //stop tracking
                }


                {
                    range2 = MathUtils.getDistance(enemy.getLocation(),                               //find get the range to target now, 1 tick later
                            missile.getLocation())-enemy.getCollisionRadius();
                }

                if (range1>range2)
                {
                    float range3 = MathUtils.getDistance(                               //find get the range to target now, 1 tick later
                            Vector2f.add(enemy.getLocation(), multV2f(enemy.getVelocity(), .5f), null), //analyze its velocity
                            missile.getLocation())-enemy.getCollisionRadius();
                    if (range1<range3)
                    {
                        trigger++;
                        deathcode++;
                    }
                }

                if (range1>range2)
                {
                    range1=range2;               //store new target range, if it got closer
                }



                if (range1<range2)
                {
                    trigger++;       //make it go boom
                    deathcode++;     //stop tracking
                }

                if (missile.getMaxHitpoints()*0.9>missile.getHitpoints())
                {
                    trigger++;          //if damaged below 90%hp while in range, detonate
                    deathcode++;
                }
            }



            //explosive code
            if (trigger != 0
                    &&MathUtils.getDistance(
                    missile.getLocation(),                     //don't blow up your own ships
                    missile.getSource().getLocation())
                    >AIUtils.getNearestAlly(missile).getCollisionRadius()+210)
            {


                String MBRC_p = "MBRC2";      //dummy weapon

                {
                    {
                        int counts = 1;
                        do {
                            float angRAND= (float) ((360*(.5-Math.random())));     //angle of spread
                            float velRAND= (float) (.6+.5*(.5-Math.random()));      //variance of projectile speeds
                            float splashVEL = 155f*velRAND;    //speed of bullets launched
                            float misFFACE = missile.getFacing()-angRAND;
                            float x = (float) (splashVEL*Math.cos(Math.toRadians(misFFACE)));
                            float y = (float) (splashVEL*Math.sin(Math.toRadians(misFFACE)));
                            Vector2f vecFIRE = new Vector2f(x,y);
                            engine.spawnProjectile(null, null,MBRC_p,
                                    missile.getLocation(),          //Vector2f firing point
                                    misFFACE,            //float   angle of spread
                                    add(missile.getVelocity(), vecFIRE, null)

                                    //multV2f(multV2f(missile.getVelocity(),1),velRAND)           //Vector2f  aditional velocity
                                    //add(multV2f(missile.getVelocity(), 1), multRanV2f(missile.getVelocity(),1,.5f),null)
                            );
                            counts++;
                        }while (counts<100);         //30x pew pew

                        //engine.removeEntity(missile); //make missile go poof
                    }
                    //lightning
                    // float emp = missile.getEmpAmount();
                    //float dam = missile.getDamageAmount();

                    //engine.spawnEmpArc(missile.getSource(), missile.getLocation(), target, target,
                    // DamageType.ENERGY,dam/4, emp/4,
                    //10000f, "tachyon_lance_emp_impact",20f, new Color(255,10,15,255),new Color(255,100,100,255));
                }
                //to stop missile shooting again
                engine.removeEntity(missile);   //make missile go poof
                //missile.flameOut();               //make missile flame out
                return;

            }
        }

    }
    //in next lazylib
    public static float getAngleDifference(float angle1, float angle2)
    {
        float distance = (angle2 - angle1) + 180f;
        distance = (distance / 360.0f);
        distance = ((distance - (float) Math.floor(distance)) * 360f) - 180f;
        return distance;
    }

    //multiply vectors   scale can not be used in static methods...
    public static Vector2f multV2f(Vector2f Vector1, float Multiplier)
    {
        float v1x = Vector1.getX()*Multiplier;
        float v1y = Vector1.getY()*Multiplier;
        Vector2f v1end = new Vector2f(v1x, v1y);
        return v1end;
    }
}
[close]


old "dumb" mines that do not track enemy ships range to mine to maximize damage (they still have dispersal code)
Spoiler
Code: java
package data.scripts.MissileAI;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.combat.*;

import java.util.Iterator;
import java.util.List;

import com.fs.starfarer.combat.CombatEngine;
import org.lazywizard.lazylib.MathUtils;
import org.lazywizard.lazylib.combat.AIUtils;
import org.lazywizard.lazylib.combat.CombatUtils;
import org.lwjgl.util.vector.Vector2f;

import static org.lazywizard.lazylib.combat.CombatUtils.getShipsWithinRange;
import static org.lwjgl.util.vector.Vector2f.add;




public class CustomMINEMissileAI implements MissileAIPlugin
{
    // Our missile object
    private final MissileAPI missile;

    public CustomMINEMissileAI(MissileAPI missile)
    {
        this.missile = missile;
    }

    //mine
    @Override
    public void advance(float amount)
    {
        CombatEngine engine = CombatEngine.getInstance();          //engine
        // Apparently commands still work while fizzling
        if (missile.isFading() || missile.isFizzling())
        {
            return;
        }

        if (AIUtils.getNearestEnemy(missile) != null                     //check if there is an enemy
                && MathUtils.getDistance(                               //find out if there are enemy in range
                AIUtils.getNearestEnemy(missile).getLocation(),
                missile.getLocation()
                )< 200+AIUtils.getNearestEnemy(missile).getCollisionRadius()
                && MathUtils.getDistance(
                missile.getLocation(),                     //don't blow up your own ship
                missile.getSource().getLocation())
                >missile.getSource().getCollisionRadius()+5)
        {


            String MBRC_p = "MBRC2";      //dummy weapon

            {
                {
                    int counts = 1;
                    do {
                        float angRAND= (float) ((360*(.5-Math.random())));     //angle of spread
                        float velRAND= (float) (.6+.5*(.5-Math.random()));      //variance of projectile speeds
                        float splashVEL = 155f*velRAND;    //speed of bullets launched
                        float misFFACE = missile.getFacing()-angRAND;
                        float x = (float) (splashVEL*Math.cos(Math.toRadians(misFFACE)));
                        float y = (float) (splashVEL*Math.sin(Math.toRadians(misFFACE)));
                        Vector2f vecFIRE = new Vector2f(x,y);
                        engine.spawnProjectile(null, null,MBRC_p,
                                missile.getLocation(),          //Vector2f firing point
                                misFFACE,            //float   angle of spread
                                add(missile.getVelocity(), vecFIRE, null)

                                //multV2f(multV2f(missile.getVelocity(),1),velRAND)           //Vector2f  aditional velocity
                                //add(multV2f(missile.getVelocity(), 1), multRanV2f(missile.getVelocity(),1,.5f),null)
                        );
                        counts++;
                    }while (counts<100);         //30x pew pew

                    //engine.removeEntity(missile); //make missile go poof
                }
                //lightning
                // float emp = missile.getEmpAmount();
                //float dam = missile.getDamageAmount();

                //engine.spawnEmpArc(missile.getSource(), missile.getLocation(), target, target,
                // DamageType.ENERGY,dam/4, emp/4,
                //10000f, "tachyon_lance_emp_impact",20f, new Color(255,10,15,255),new Color(255,100,100,255));
            }
            //to stop missile shooting again
            engine.removeEntity(missile);   //make missile go poof
            //missile.flameOut();               //make missile flame out
            return;

        }
        MissileAPI near = AIUtils.getNearestMissile(missile);

        if (near != null
                && near.getProjectileSpecId().equals(missile.getProjectileSpecId())
                && MathUtils.getDistance(near, missile) < 400)
        {

            float angularDistance = getAngleDifference(
                    missile.getFacing(), MathUtils.getAngle(missile.getLocation(),
                    near.getLocation()));
            if (Math.abs(angularDistance) < 175)
            {
                missile.giveCommand(angularDistance < 0f
                        ? ShipCommand.TURN_LEFT : ShipCommand.TURN_RIGHT);
            }
            if (Math.abs(angularDistance) > 135)
            {
                missile.giveCommand(ShipCommand.ACCELERATE);
            }
            if (Math.abs(angularDistance) < 45)
            {
                missile.giveCommand(ShipCommand.ACCELERATE_BACKWARDS);
            }
        }
        else
        {
            missile.giveCommand(ShipCommand.DECELERATE);              //mine dose not move under its own power
        }

    }
    //in next lazylib
    public static float getAngleDifference(float angle1, float angle2)
    {
        float distance = (angle2 - angle1) + 180f;
        distance = (distance / 360.0f);
        distance = ((distance - (float) Math.floor(distance)) * 360f) - 180f;
        return distance;
    }
}
[close]

all code demonstrated in the aptly named BISO v 0.69 post off topic replies there please, and discuss the actual code here
« Last Edit: October 23, 2013, 09:35:07 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!

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: The Radioactive Code Dump
« Reply #26 on: October 23, 2013, 12:13:12 PM »

SCATTER missileAI

BISO engineers are curently developing an artificialy inteligent missile that automaticaly spaces itself away from neighbors


Spoiler


[close]
Spoiler
Code: java
        //spread code
        float timerVariable =                             //timer variable code//how likley is it to run pathAI
                (((MathUtils.getDistance(missile, target.getLocation())                                                      //9
                        /MathUtils.getDistance(missile.getSource(), target))      //d to target/d from target to launch      //10
                        /(MathUtils.getDistance(missile.getSource(), missile)                                                //1
                        +MathUtils.getDistance(missile.getSource(), target)*.1f     //divided by                             //2
                        /MathUtils.getDistance(missile.getSource(), target))))/10;//d to launch ship/d from target to launch //10
        //returns 1 when launched  ~0 when impact                 //((9/10)/((1+1)/10))=4.5 =.45
        spread= 10+(float)(50*Math.sqrt((double)timerVariable));  //adaptive spread
        //when missile closes spread drops to a minimum o 10% of value at 50, max is ~50/1.5





        MissileAPI near = AIUtils.getNearestMissile(missile);

        if (pathAI>10) {pathAI=0;}
        pathAI++;

        if ((near != null                               //check if there are any nearby mines
                && near.getProjectileSpecId().equals(missile.getProjectileSpecId())
                && MathUtils.getDistance(near, missile) > spread))
        {
            pathAI=1;
        }
        if (near==null)
        {
            pathAI=1;
        }
        if (MathUtils.getDistance(missile, target)-target.getCollisionRadius()<500)
        {
            pathAI=1;
        }


        //spread code

        if (near != null)
        {
            //if there are move away from them

            if (pathAI>5.1)
            {
                float angularDistanceS = getAngleDifference(
                        missile.getFacing(), MathUtils.getAngle(missile.getLocation(),
                        (near.getLocation())));
                if (near.getProjectileSpecId().equals(missile.getProjectileSpecId())
                        && MathUtils.getDistance(near, missile) < spread)
                {

                    if (Math.abs(angularDistanceS) < 45)
                    {
                        missile.giveCommand(angularDistanceS < 0f
                                ? ShipCommand.TURN_LEFT : ShipCommand.TURN_RIGHT);
                        missile.giveCommand(angularDistanceS < 0f
                                ? ShipCommand.STRAFE_LEFT : ShipCommand.STRAFE_RIGHT);
                        missile.giveCommand(ShipCommand.DECELERATE);
                    }


                    if (Math.abs(angularDistanceS) > 45 && Math.abs(angularDistanceS) <90)
                    {
                        missile.giveCommand(angularDistanceS < 0f
                                ? ShipCommand.STRAFE_LEFT : ShipCommand.STRAFE_RIGHT);
                        missile.giveCommand(ShipCommand.ACCELERATE);
                    }
                }
            }
        }
        //normal ai

        if (pathAI<5.1)
        {
            float angularDistance = getAngleDifference(
                    missile.getFacing(), MathUtils.getAngle(missile.getLocation(),
                    (add(target.getLocation(),
                            multV2f(target.getVelocity(),
                                    MathUtils.getDistance(target.getLocation(),
                                            missile.getLocation())/missile.getVelocity().lengthSquared()),
                            null))  ));


            if (Math.abs(angularDistance) > 0.2)
            {
                missile.giveCommand(angularDistance > 0
                        ? ShipCommand.TURN_LEFT : ShipCommand.TURN_RIGHT);

            }

            if (Math.abs(angularDistance) < 100
                    && MathUtils.getDistance(missile, target)-target.getCollisionRadius()>290)
            {
                missile.giveCommand(ShipCommand.ACCELERATE);
            }



            if (MathUtils.getDistance(
                    missile.getLocation(),                     //don't blow up your own ship
                    missile.getSource().getLocation())
                    <missile.getSource().getCollisionRadius()*2)
            {
                missile.giveCommand(ShipCommand.ACCELERATE);

            }
            if (MathUtils.getDistance(missile, target)-target.getCollisionRadius()<300
                    && Math.abs(angularDistance) > 1)
            {
                missile.giveCommand(ShipCommand.DECELERATE);
                if (Math.abs(angularDistance) < 10)
                {
                    deathcode=1;
                }
            }


        }
[close]
as usual any unasigned cout++ values go outside of the method
final code, effective enough
« Last Edit: October 23, 2013, 04:09:05 PM 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!

Cosmitz

  • Admiral
  • *****
  • Posts: 753
    • View Profile
Re: The Radioactive Code Dump
« Reply #27 on: October 23, 2013, 12:43:48 PM »

To be fair, most of those yell 'flachettes' and less 'missile'.
Logged

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: The Radioactive Code Dump
« Reply #28 on: October 23, 2013, 12:46:08 PM »

To be fair, most of those yell 'flachettes' and less 'missile'.

to change what the missiles fire, do
Code: java
String MBRC_p = "MBRC2";      //dummy weapon
to:
String MBRC_p = "YourWeaponHere";      //dummy weapon  
missiles and lasers need a difrent code aparently, ill look into implementing them later

Perfect lead calculation
if your missile is fast enough to catch the target, it will hit(unless the target dose insane evasive action, then it may not hit (but probably will)

calculates the exact intercept point+1/2colisionRadious of the target ship and aims there, verry hard to avoid unless you can do on the dime turns

Spoiler
Code: java
        float sx = (float) (target.getCollisionRadius()*.5*Math.cos(Math.toRadians(target.getFacing())));
        float sy = (float) (target.getCollisionRadius()*.5*Math.sin(Math.toRadians(target.getFacing())));
        float angularDistance = getAngleDifference(
                missile.getFacing(), MathUtils.getAngle(missile.getLocation(),
                (add((add(target.getLocation(),
                        multV2f(target.getVelocity(),
                                MathUtils.getDistance(target.getLocation(),
                                        missile.getLocation()) / missile.getVelocity().lengthSquared()),
                        null)),new Vector2f(sx,sy), null))));
[close]
« Last Edit: October 23, 2013, 01:01:39 PM 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!

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: The Radioactive Code Dump
« Reply #29 on: October 24, 2013, 09:46:04 AM »

BISO  engineers were bored, and created:
the orbital missile



append this to any missile pathing logic (that has target!=null)
Spoiler
Code
if (target==null) //orbiting missile system
        {
            float angularDistance = getAngleDifference(
                    missile.getFacing(), MathUtils.getAngle(missile.getLocation(), missile.getSource().getLocation()));
            if (MathUtils.getDistance(missile, missile.getSource())>missile.getSource().getCollisionRadius()*1.4)
            {
                missile.giveCommand(ShipCommand.ACCELERATE_BACKWARDS);
            }
            if (MathUtils.getDistance(missile, missile.getSource())<missile.getSource().getCollisionRadius()*1.2)
            {
                missile.giveCommand(ShipCommand.ACCELERATE);
            }
            if (Math.abs(angularDistance) < 170)
            {
                missile.giveCommand(angularDistance < 0f
                        ? ShipCommand.TURN_LEFT : ShipCommand.TURN_RIGHT);
            }
            if (MathUtils.getDistance(missile, missile.getSource())<missile.getSource().getCollisionRadius()*1.4
                    && MathUtils.getDistance(missile, missile.getSource())>missile.getSource().getCollisionRadius()*1.2)
            {

                if (timer==1)
                {
                    missile.giveCommand(strafeDir>.5 ? ShipCommand.STRAFE_RIGHT : ShipCommand.STRAFE_LEFT);
                }

            }



            timer++;
            if(timer>2){timer=0;}
            return;

        }
[close]
for those familiar with my BISO mod, yes that is the SESPd
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!
Pages: 1 [2] 3 4 ... 9