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); Blog post: Skills and Story Points (07/08/19)

Author Topic: Anamorphic Flares!  (Read 10567 times)

Dark.Revenant

  • Admiral
  • *****
  • Posts: 2537
    • View Profile
    • Sc2Mafia
    • Email
Anamorphic Flares!
« on: March 28, 2014, 12:43:19 AM »

Requesting that this gets moved to Modding Resources.

ANAMORPHIC FLARES!



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.
« Last Edit: March 28, 2014, 02:11:37 AM by Dark.Revenant »
Logged

MesoTroniK

  • Admiral
  • *****
  • Posts: 1386
  • I am going to destroy your ships
    • View Profile
Re: Anamorphic Flares!
« Reply #1 on: March 28, 2014, 01:27:15 AM »

Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: Anamorphic Flares!
« Reply #2 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.
Logged

Okim

  • Admiral
  • *****
  • Posts: 2145
    • View Profile
    • Okim`s Modelling stuff
Re: Anamorphic Flares!
« Reply #3 on: March 28, 2014, 01:54:56 AM »

Care to share your lighning gun code? The one that creates a lightning.

Dark.Revenant

  • Admiral
  • *****
  • Posts: 2537
    • View Profile
    • Sc2Mafia
    • Email
Re: Anamorphic Flares!
« Reply #4 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.
Logged

Okim

  • Admiral
  • *****
  • Posts: 2145
    • View Profile
    • Okim`s Modelling stuff
Re: Anamorphic Flares!
« Reply #5 on: March 28, 2014, 03:09:13 AM »

Thanks, i`ll have a look at it.

Cycerin

  • Admiral
  • *****
  • Posts: 1646
  • beyond the infinite void
    • View Profile
Logged

mendonca

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1119
    • View Profile
Re: Anamorphic Flares!
« Reply #7 on: March 28, 2014, 05:25:41 AM »

That is really cool!  :D
Logged


"I'm doing it, I'm making them purple! No one can stop me!"

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: Anamorphic Flares!
« Reply #8 on: March 28, 2014, 03:06:13 PM »

:D NGE exlosions!! I demand NGE exlosions
Spoiler
[close]
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!

MesoTroniK

  • Admiral
  • *****
  • Posts: 1386
  • I am going to destroy your ships
    • View Profile
Re: Anamorphic Flares!
« Reply #9 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
Logged