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: Painting the Stars (02/07/20)

Pages: 1 ... 5 6 [7] 8 9

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

Sundog

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1021
    • View Profile
    • Email
Re: The Radioactive Code Dump
« Reply #90 on: April 29, 2014, 10:21:21 AM »

Originally I decided to use a hullmod to make it easy to specify which ships are stationary and which ones aren't, but since a function call is necessary in the mission definition anyway, I guess it would make more sense to use an EveryFrameCombatPlugin.

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: The Radioactive Code Dump
« Reply #91 on: May 19, 2014, 02:00:44 AM »

Hard flux generation for beam weapons

Code: java

package data.scripts.weapons;

import com.fs.starfarer.api.combat.BeamAPI;
import com.fs.starfarer.api.combat.BeamEffectPlugin;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.util.IntervalUtil;

/**
 *
 * @author Debido
 * fragments derived from Xenoargh's MegaBeamDamageEffect plugin
 *
 * This script is intended to allow the given Beam weapon using this script to apply hard flux damage to the enemy ship if the beam hits their shield
 * This is probably OP, so be careful with game balancing!
 */

public class BeamFullFlux implements BeamEffectPlugin {

    private final IntervalUtil fireInterval = new IntervalUtil(0.1f, 0.1f); //interval between applying flux
    private final float fluxMultiplier = 10.0f; //determines how much hard flux is generated in the enemy ship. 1.0f would be 100% of weapon DPS, 0.1f would be 10%, and 10f would be 1000%

    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam) {

        if (engine.isPaused()) {
            return;
        }

        fireInterval.advance(amount);

        CombatEntityAPI target = beam.getDamageTarget();
        //If we have a target, target is a Ship, and shields are being hit.
        if (target != null && target instanceof ShipAPI && target.getShield() != null && target.getShield().isWithinArc(beam.getTo())) {
            if (fireInterval.intervalElapsed()) {
                if (beam.getBrightness() >= 1f) {
                    ShipAPI ship = (ShipAPI) target; //cast as ship
                    ship.getFluxTracker().increaseFlux(fluxMultiplier * beam.getWeapon().getDerivedStats().getDps() / 10f, true); //apply flux
                }

            }

        }
    }
}
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 4854
  • naively breaking things!
    • View Profile
Re: The Radioactive Code Dump
« Reply #92 on: May 19, 2014, 12:53:35 PM »

There's actually a much more reliable / accurate method in the newer Vacuum builds:

Spoiler
Code: java
package data.scripts.weapons;

import com.fs.starfarer.api.combat.BeamAPI;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.combat.WeaponAPI.DerivedWeaponStatsAPI;
import com.fs.starfarer.api.combat.BeamEffectPlugin;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.DamageType;
import com.fs.starfarer.api.combat.ShipAPI;

public class BeamDamageEffect implements BeamEffectPlugin {
    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam) {
        if (engine.isPaused()) return;
        if(beam.getBrightness() < 0.99f) return;
        float frameTime = engine.getElapsedInLastFrame();
       
        //Get the beam's target
        CombatEntityAPI target = beam.getDamageTarget();

        //If we have a target, target is a Ship, and shields are being hit.   
        if (target != null && target instanceof ShipAPI && target.getShield() != null && target.getShield().isWithinArc(beam.getTo())) {
            //Now that we have the target, get the weapon ID and get the DPS
            WeaponAPI weapon = beam.getWeapon();
            DamageType damType = weapon.getDamageType();
            DerivedWeaponStatsAPI stats = weapon.getDerivedStats();

            engine.applyDamage(
                target, //enemy Ship
                beam.getTo(), //Our 2D vector to the exact world-position
                dps * frameTime, //We're dividing the DPS by the time that's passed here.
                damType, //Using the damage type here.
                0f, //No EMP, as EMP already has specific rules.  However EMP could go through shields this way if we wanted it to.
                false, //Does not bypass shields.
                false, //Does not do Soft Flux damage (would kind've defeat the whole point, eh?
                beam.getSource()  //Who owns this beam?
             );
        }
    }
}
[close]
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 4854
  • naively breaking things!
    • View Profile
Re: The Radioactive Code Dump
« Reply #93 on: June 05, 2014, 08:55:36 PM »

So... are Decorative weapons showing up on your ships after you set them up in Trylobot's otherwise-wonderful editor? 

Do you have other, ah, weird cases, where you definitely want a weapon to not show up in weapon slots, whether players put them there or not, and the engine limitations on Decorative / System / whatever won't quite do it for ya?  Use this snippet :)

Run in an EveryFrameWeaponEffectPlugin script, using a one-time boolean in Advance():

Spoiler
Code: java
        if(runOnce){
            String weaponSlot = weapon.getSlot().getId();
            List<WeaponGroupSpec> weaponGroups = weapon.getShip().getVariant().getWeaponGroups();
            for(WeaponGroupSpec group : weaponGroups){
                List<String> slots = group.getSlots();
                String slotID = new String();
                for(String slot : slots){
                    if(slot.equalsIgnoreCase(weaponSlot)){
                        slotID = slot.toString();
                    }
                }
                if(slotID.equalsIgnoreCase(weaponSlot)) group.removeSlot(slotID);
            }     
            runOnce = false;
        }
[close]



Logged
Please check out my SS projects :)
Xeno's Mod Pack

ValkyriaL

  • Admiral
  • *****
  • Posts: 2145
  • The Guru of Capital Ships.
    • View Profile
Re: The Radioactive Code Dump
« Reply #94 on: June 06, 2014, 03:50:55 AM »

This is very easily fixed with trylobot tho, if you save a variant with decorative weapons, then they are added, if you only save the hull file with the decoratives, then the variant won't have them, but they will still be there, alternatively you can open the variant file and delete the decorative weapons and they are gone from the variant.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 4854
  • naively breaking things!
    • View Profile
Re: The Radioactive Code Dump
« Reply #95 on: June 06, 2014, 12:34:33 PM »

Every time you modify a variant in SFEd you have to do that, and sometimes I do stuff where I have to modify every single ship (like when I added the "vernier thrusters" feature- I think I only had 185 ships then, but meh) and I change variants quite often to rebal.  It all added up to quite a bit of extra work due to one smallish issue with SFEd.  Alex's answer gave me the clue I needed to remove it automatically.

There are probably some other uses for something like this, too :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Thaago

  • Global Moderator
  • Admiral
  • *****
  • Posts: 4381
  • Quantum Mechanic
    • View Profile
    • Email
Re: The Radioactive Code Dump
« Reply #96 on: June 09, 2014, 01:01:57 PM »

Big thanks to everyone who has posted in this thread - I'm making a slew of missile AI's for a TC and this has probably saved me 10 hours of work. :D You all get a beer.
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: The Radioactive Code Dump
« Reply #97 on: August 09, 2014, 04:19:57 AM »

This bomber code was considered too powerful for general use



Code: java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package uaf.data.scripts.weapons;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.DamageType;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.WeaponAPI;
import java.awt.Color;
import java.util.List;
import org.lazywizard.lazylib.CollisionUtils;
import org.lazywizard.lazylib.MathUtils;
import org.lazywizard.lazylib.combat.CombatUtils;
import org.lwjgl.util.vector.Vector2f;

/**
 *
 * @author Debido
 */
public class SPSBomber implements EveryFrameWeaponEffectPlugin {
    
    private static final Color BOOM_COLOR = new Color(255, 165, 50, 245);
    private static final Vector2f ZERO_VECTOR = new Vector2f(0f,0f);

    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {

        ShipAPI ship = weapon.getShip();

        if (ship == null || !engine.isEntityInPlay(ship) || weapon.getAmmo() == 0) {
            return;
        }
        

        List<ShipAPI> ships = CombatUtils.getShipsWithinRange(ship.getLocation(), 100f);

        for (ShipAPI s : ships){
            if (s.isAlive() && s.getOwner() != ship.getOwner()){
                if (CollisionUtils.isPointWithinBounds(ship.getLocation(), s)){
                    
                    weapon.setAmmo(0);
                    engine.applyDamage(s, ship.getLocation(), weapon.getDerivedStats().getDamagePerShot(), DamageType.HIGH_EXPLOSIVE, 0f, false, false, ship);
                    engine.spawnExplosion(ship.getLocation(), ZERO_VECTOR, BOOM_COLOR, 500f, 1f);
                    engine.addSmokeParticle(ship.getLocation(), ZERO_VECTOR, 600f, 0.9f, 5f, Color.DARK_GRAY);
                    for (int i = 0; i < 10; i++){
                        Vector2f radialVector = MathUtils.getRandomPointOnCircumference(ship.getLocation(), 500f);
                        engine.addHitParticle(ship.getLocation(), radialVector , 10f, 255, 2f, BOOM_COLOR);
                    }
                }
                
            }
        }

    }

}

« Last Edit: August 09, 2014, 04:22:41 AM by Debido »
Logged

ValkyriaL

  • Admiral
  • *****
  • Posts: 2145
  • The Guru of Capital Ships.
    • View Profile
Re: The Radioactive Code Dump
« Reply #98 on: August 09, 2014, 05:39:10 AM »

Now THAT is cool, id love that from my heavy bombers, the bomber itself also seems incredibly valkyrian themed, kitbash maybe? :D
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: The Radioactive Code Dump
« Reply #99 on: August 09, 2014, 06:05:04 AM »

It was pretty cool, however consultation from resident senior modder Mesotronik advised me it's somewhat OP - Oh and it bypasses his beloved Exigency repulsor like it was never there.

Anyway I now have some slower bombers in the UAF arsenal that aren't anywhere near as effective, that way it's a bit more like the dagger wing, and less like a cool bunker buster. Oh well. Unless there is a way to balance such an awesome force, I don't think it will make the final cut.
Logged

Foxer360

  • Admiral
  • *****
  • Posts: 637
  • Recursion; See Recursion (n)
    • View Profile
    • Email
Re: The Radioactive Code Dump
« Reply #100 on: August 09, 2014, 09:15:20 AM »

If there was some way to make it an EMP bomb... that'd be more balanced perhaps.
Logged

Dark.Revenant

  • Admiral
  • *****
  • Posts: 2551
    • View Profile
    • Sc2Mafia
    • Email
Re: The Radioactive Code Dump
« Reply #101 on: August 09, 2014, 12:43:41 PM »

The difficulty of balance comes with the difficulty of trying to deal with that bomber.  When Piranhas attack, you can see them coming and swivel your shields, get out of the way, hit them with mass flak, etc.  When Daggers attack, you can intercept them, shoot capital-class weapons at the reapers, get out of the way, soak them on your shield, etc.  Tridents go much the same way.

Bombers are designed, in this game, to be things that can be defeated with perception, appropriate tactics, and planning.  Your bomber, on the other hand, has no adequate countermeasures.  It's too fast to dodge or shoot down, the bomb can't be shot down, etc.  The only option is to soak it on shields, and if the ship doesn't have shields it's just ***.
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: The Radioactive Code Dump
« Reply #102 on: August 09, 2014, 07:15:40 PM »

Actually it could still be shot down by energy/laser weapons fairly frequently, and with tweaking the bomber pretty much took 5000su to turn around. It was designed to be fairly ineffective in turning and as such often it would simply fly straight past targets as big as a cruiser if it moved out of the way. Frigates or destroyers could side step fairly easy with enough time. Dunno, might make it a capture only enemy only ship. That is it cannot be captured, or if it is I replace it with the watered down version.

It's fairly trivial to make it an EMP only type damage, that's just modifying line 46 to have EMP damage (engine.applyDamage).
Logged

Tartiflette

  • Admiral
  • *****
  • Posts: 2835
  • Kickstarter is NOT a magic spring of free money!
    • View Profile
Re: The Radioactive Code Dump
« Reply #103 on: August 29, 2014, 04:49:28 AM »

My own small contribution to this "dump":
Slashing beam:
Spoiler
[close]
Works in two modes depending of the arc available, and two speeds in each.

Code: Java
//by Tartiflette, this script allow for a beam weapon to slash during the main firing sequence
//feel free to use it, credit is appreciated but not mandatory
package data.scripts.weapons;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
import com.fs.starfarer.api.combat.WeaponAPI;

public class SCY_slasherBeamEffect implements EveryFrameWeaponEffectPlugin {

private boolean isFiring = false;
private float aim = 0.0f;
private float count = 0.0f;
private final float offset = 0.5f;
private boolean hasFired = false;
private boolean RUN_ONCE = false;
private float multiplier = 1;
private boolean turretMode = true;
private float arc = 0.0f;
private float arcFacing = 0.0f;

    
    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
        // Don't bother with any checks if the game is paused
        if (engine.isPaused()) {
            return;
        }
        
        //run only once to check the available arc, double the slashing width if arc > 90 degrees, hardpoint mode if arc < 20 degrees
        
        if (!RUN_ONCE) {
            if (weapon.getArc() >= 90f) {
                multiplier = 2;
            }
            if (weapon.getArc() <= 10f) {
                multiplier = 0.5f;
            }
            if (weapon.getArc() <= 20f) {
                turretMode = false;
                arc = weapon.getArc();
                arcFacing = weapon.getArcFacing();
                aim = 0.5f;
            }
            RUN_ONCE = true;
        }
        
        
        if (!turretMode) {
            //HARPOINT MODE: goes back and forth in the arc for the duration
            
            if (weapon.isFiring()) {
                
                //initialize the first offset to start on the same direction the weapon is facing
                if (!hasFired) {
                    count = weapon.getCurrAngle() - arcFacing - weapon.getShip().getFacing();
                    hasFired = true;
                }
                
                //if the weapon hit an arc limit, change the rotation direction
                if (count >= ( arc * 0.5f )) {
                    aim = -0.5f*multiplier;                    
                }
                
                if (count <= -( arc * 0.5f )) {
                    aim = 0.5f*multiplier;                    
                }
              
                //slashing in the arc
                weapon.setCurrAngle( weapon.getShip().getFacing() + arcFacing + count );
                count = count + aim;
            }
            //reset the variables when the weapon is cooling down
            if (!weapon.isFiring() && hasFired) {
                hasFired = false;
                aim = 0.5f;
                count = 0f;
            }
            
        } else {
            //TURRET MODE: one large slash
            //charging: the gun turn left in preparation of the slashing
            if (weapon.isFiring() && weapon.getChargeLevel() < 1.0f && !hasFired) {

                //the gun orientation is stored before being altered
                if (weapon.isFiring() && isFiring == false) {
                    aim = weapon.getCurrAngle();
                }

                isFiring = true;
                count++;
                weapon.setCurrAngle(aim + (count * offset * multiplier));
            }

            //firing: the gun slash to the right
            if (weapon.isFiring() && weapon.getChargeLevel() == 1.0f) {
                hasFired = true;
                count = count - 0.5f;
                weapon.setCurrAngle(aim + (count * offset * multiplier));
            }

            //cooldown: the weapon is released and the variables reseted
            if (!weapon.isFiring() && hasFired) {
                isFiring = false;
                hasFired = false;
                aim = 0.0f;
                count = 0f;
            }
        }
    }
}

Vibrating beam:
Spoiler
[close]
Randomly reorient the weapon every few moments.
Code: Java
//by Tartiflette, this script allow for a beam weapon to vibrate at a predetermined frequency during the main firing sequence
//feel free to use it, credit is appreciated but not mandatory
package data.scripts.weapons;


import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import org.lazywizard.lazylib.MathUtils;

public class SCY_vibratingBeamEffect implements EveryFrameWeaponEffectPlugin
{
    private boolean isFiring = false;
    private float aim = 0.0f;
    private float offset = 0.0f;
    private final IntervalUtil timer = new IntervalUtil(0.05f, 0.05f);
    
    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon)
    {
        // Don't bother with any checks if the game is paused
        if (engine.isPaused()) {
            return;
        }
        
        if (weapon.isFiring())
        {
            //don't vibrate during chargeup
            if (weapon.getChargeLevel() == 1.0f)        
            {

                //store the weapon orientation once it reach full power
                if (weapon.isFiring() && !isFiring) {
                    aim = weapon.getCurrAngle();
                    isFiring = true;
                }

                //change the orientation every few moments
                if(timer.intervalElapsed())
                    {
                    offset = (float)MathUtils.getRandomNumberInRange(-2f, 2f);
                    }
                timer.advance(amount);

                //lock the weapon orientation every frame to avoid trying to aim back to the curser
                weapon.setCurrAngle(aim + offset);
            }
        else
            {
                isFiring = false;
                offset = 0.0f;
                aim = 0.0f;
            }
        }
    }
}
« Last Edit: April 12, 2015, 03:31:58 AM by Tartiflette »
Logged
 

Tartiflette

  • Admiral
  • *****
  • Posts: 2835
  • Kickstarter is NOT a magic spring of free money!
    • View Profile
Re: The Radioactive Code Dump
« Reply #104 on: January 30, 2015, 01:59:51 AM »

Well, I was tempted to try a clip reload mechanic since the patch is still not in sight and here it is. After a set timer since the last shot fired the ammo get reloaded by a set amount, nice and easy. To properly function, the weapon need an ammo regeneration equivalent to the clip reloading (for the weapon tooltip) and a cooldown longer than one frame.

Code: Java
//by Tartiflette, this script allow for a weapon to reload it's ammo after some time since it's last shot
//feel free to use it, credit is appreciated but not mandatory
package data.scripts.weapons;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
import com.fs.starfarer.api.combat.WeaponAPI;

public class SCY_clipEffect implements EveryFrameWeaponEffectPlugin
{
    private boolean runOnce = false;
    private float timer = 0f;
    private int clipSize;
    private int magazine;
    private int clipTimer;
   
    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon)
    {
        // Don't bother with any checks if the game is paused
        if (engine.isPaused()) {
            return;
        }
       
        // store the max reloading ammo amount, the timer between reloads and initialise the current magazine size
        //WARNING to properly function in autoresolve, the weapon need the equivalent of the clip reloading in ammo regen and a cooldown
        if (!runOnce){
            if (weapon.getId().equals("SCY_laserRepeater_mkiii")){
                clipSize=5;
                clipTimer=5;
            } else {
                //default values
                clipSize=weapon.getMaxAmmo();
                clipTimer=5;
            }
            magazine = weapon.getMaxAmmo();
            runOnce=true;
        }
       
        //prevent normal ammo regeneration
        if (weapon.getAmmo()>magazine){
            weapon.setAmmo(magazine);                   
        }
       
        //only run if the ammo isn't full
        if (weapon.getAmmo()<weapon.getMaxAmmo()){
            //lock the weapon if the ammo reach 0
            //necessary because the weapons can fire upon the ammo regeneration before the script kicks in and remove it
            if(weapon.getAmmo()==0){
                weapon.setRemainingCooldownTo(1);
            }
            //interrupt the reloading if the weapon fire
            if(weapon.isFiring()){
                timer = 0;
                magazine = weapon.getAmmo();
            } else {           
                //timer
                timer+=amount;
                //timer elapsed: reload and reset the timer
                if(timer>=clipTimer){
                    //add a clip to the current ammo
                    weapon.setAmmo(Math.min(weapon.getMaxAmmo(),magazine+clipSize));
                    timer = 0;
                    magazine = weapon.getAmmo();
                    //reset the cooldown
                    weapon.setRemainingCooldownTo(0);
                }
            }
        }
    }
}
Logged
 
Pages: 1 ... 5 6 [7] 8 9