Fractal Softworks Forum

Starsector => Mods => Modding => Topic started by: Dark.Revenant on March 28, 2014, 12:43:19 AM

Title: Anamorphic Flares!
Post by: Dark.Revenant on March 28, 2014, 12:43:19 AM
Requesting that this gets moved to Modding Resources.

ANAMORPHIC FLARES!

(http://www.sc2mafia.com/Starsector/Flare.png)

Code:
Spoiler
Code: java
package data.scripts.util;

import java.awt.Color;

import org.lwjgl.util.vector.Vector2f;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.DamageType;
import com.fs.starfarer.api.combat.ShipAPI;
import org.lazywizard.lazylib.combat.entities.SimpleEntity;
import org.lazywizard.lazylib.FastTrig;

public class AnamorphicFlare {

    /**
     * Anamorphic Flare Generator. This creates a lot of EMP flares in a tight
     * group, exploiting a bug in the game to create an effect similar to an
     * anamorphic flare. To create the effect you want, you may need to do a lot
     * of tweaking. Keep in mind that the effect has a higher resolution and a
     * greater computational cost with smaller thicknesses; extreme values (0.01
     * and smaller) can result in odd behavior. This can cause bugs if used in
     * some particular cases, such as on a weapon that spawns free-floating EMP
     * arcs.
     *
     * @param origin Put any ship in here. Really, any ship. This CANNOT be
     * null.
     * @param point Location of the anamorphic flare.
     * @param engine The base combat engine object.
     * @param brightness The visual brightness of the anamorphic flare. This can
     * also be used to attenuate its size, due to how it is shaped. Biased such
     * that 1 equals maximum brightness, but it is possible to go above maximum
     * brightness, especially on lower thicknesses, due to how the anamorphic
     * flare works.
     * @param thickness Thickness ratio of the anamorphic flare. A bit of a
     * misnomer; it won't actually get thinner, just longer, if you make this
     * smaller. Do not use a value above 0.5 because otherwise the flare won't
     * look like anything. The resolution of the flare and the precision of the
     * flare thickness and the computational complexity of the flare all
     * increase when the thickness is decreased. Values below 0.01 can have a
     * huge performance hit.
     * @param angle The angle the flare points toward, in degrees.
     * @param spread Controls how misshapen the flare will be, in degrees. Use
     * only for low thickness values (0.2 and below).
     * @param fringeGain Multiplies the alpha of the outside color of the
     * anamorphic flare, in case it wasn't colorful enough for you. Not sure if
     * this actually works... Default is 1.
     * @param fringeColor The outside color of the anamorphic flare. Alpha is
     * not used.
     * @param coreColor The core color of the anamorphic flare. Alpha is not
     * used.
     */
    public static void createFlare(ShipAPI origin, Vector2f point, CombatEngineAPI engine, float brightness, float thickness, float angle, float spread, float fringeGain, Color fringeColor, Color coreColor) {
        int magnitude = (int) (1f / thickness);
        int alpha = Math.min((int) (255f * brightness * thickness), 255);
        int alphaf = Math.min((int) (255f * brightness * thickness * fringeGain), 255);

        for (int i = 0; i < magnitude; i++) {
            float angleP = angle + (float) Math.random() * 2f * spread - spread;
            if (angleP >= 360f) {
                angleP -= 360f;
            } else if (angleP < 0f) {
                angleP += 360f;
            }

            Vector2f location = point;
            location.x += FastTrig.cos(angleP * Math.PI / 180f);
            location.y += FastTrig.sin(angleP * Math.PI / 180f);

            Color fringeColorP = new Color(fringeColor.getRed(), fringeColor.getGreen(), fringeColor.getBlue(), alphaf);
            Color coreColorP = new Color(coreColor.getRed(), coreColor.getGreen(), coreColor.getBlue(), alpha);

            engine.spawnEmpArc(origin, location, null, new SimpleEntity(point),
                    DamageType.ENERGY,
                    0.0f,
                    0.0f, // emp
                    100000f, // max range
                    null,
                    25f, // thickness
                    fringeColorP,
                    coreColorP
            );
        }
    }

    private AnamorphicFlare() {

    }
}

[close]

Requires LazyLib 1.8c.  Don't have too much fun.
Title: Re: Anamorphic Flares!
Post by: MesoTroniK on March 28, 2014, 01:27:15 AM
This is amazing looking. (https://www.youtube.com/watch?v=lWYcHznPB-A&feature=youtu.be)
Title: Re: Anamorphic Flares!
Post by: Debido on March 28, 2014, 01:30:52 AM
Alex needs to include this in Starsector. This is 100% in alignment with the presentation and style of the game.
Title: Re: Anamorphic Flares!
Post by: Okim on March 28, 2014, 01:54:56 AM
Care to share your lighning gun code? The one that creates a lightning.
Title: Re: Anamorphic Flares!
Post by: Dark.Revenant on March 28, 2014, 01:57:48 AM
Care to share your lighning gun code? The one that creates a lightning.
It's in the /jars/src/ folder of Starsector+ (see sig).

It also involves weapon and projectile data, so you should look at those too.
Title: Re: Anamorphic Flares!
Post by: Okim on March 28, 2014, 03:09:13 AM
Thanks, i`ll have a look at it.
Title: Re: Anamorphic Flares!
Post by: Cycerin on March 28, 2014, 05:04:44 AM
This is amazing looking. (https://www.youtube.com/watch?v=lWYcHznPB-A&feature=youtu.be)

Goddamn.
Title: Re: Anamorphic Flares!
Post by: mendonca on March 28, 2014, 05:25:41 AM
That is really cool!  :D
Title: Re: Anamorphic Flares!
Post by: dmaiski on March 28, 2014, 03:06:13 PM
:D NGE exlosions!! I demand NGE exlosions
Spoiler
(http://img2.wikia.nocookie.net/__cb20120312001614/evangelion/images/3/3a/7th_Angel_Cross_Explosion.png)
[close]
Title: Re: Anamorphic Flares!
Post by: MesoTroniK on March 28, 2014, 09:21:28 PM
dmaiski, oh you.

I have some other ideas on how to use this code also, something about crazy AOE weapons, and maybe a Casaba Howitzer or two :o