Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Shield Passive Hard Flux  (Read 5025 times)

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Shield Passive Hard Flux
« on: November 23, 2013, 05:11:49 PM »

Is it possible to make shields passively generate hard flux, instead of soft flux while on?

There is no intrinsic method to do so, but I read something about being able to look at a ship in battle, determining if it was venting, and canceling it. If that is possible, then it may be possible to check shield state, and then manually change the flux generation type.
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: Shield Passive Hard Flux
« Reply #1 on: November 23, 2013, 08:28:36 PM »

it is posible, but you will need an evry frame script, and some kind of getter for the shields paive flux rate
(i dont think there is a pre made one for that stat)
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!

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Shield Passive Hard Flux
« Reply #2 on: November 24, 2013, 09:45:52 AM »

Alright.

I cannot currently locate any information or examples on how a every frame script is created. (perhaps named differently? Continous script might be technically accurate)

I looked at the fortress shield, as it continuously creates hard flux. However, neither the script nor the system file gives any information on how that was done. It appears to only reduce damage taken and remove all shield upkeep.

Presumably there is another part to it, but I cannot locate it.
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

Okim

  • Admiral
  • *****
  • Posts: 2161
    • View Profile
    • Okim`s Modelling stuff
Re: Shield Passive Hard Flux
« Reply #3 on: November 24, 2013, 10:01:27 AM »

package data.scripts.plugins;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
import com.fs.starfarer.api.combat.ShipAPI;


public class YourShieldScript implements EveryFrameCombatPlugin
{
    private CombatEngineAPI engine;

    @Override
    public void init(CombatEngineAPI engine)
    {
        this.engine = engine;
    }
    
    @Override
    public void advance(float amount, List events)
    {
        if (engine.isPaused()) return;
        
        ListIterator allships = engine.getShips().listIterator();

        if(allships.hasNext())
        {
             while(allships.hasNext())
             {              
                 ShipAPI ship = (ShipAPI) allships.next();
                 <<put your code here>>
             }
        }
    }
}

That should be put into scripts/plugins folder to make it automatically run each frame. File should be named exactly as you name your class. Note that you might need to add extra scripts to be included to this script.

Put whatever you need in this code. All required methods and classes can be found in javadoc: http://fractalsoftworks.com/starfarer.api/index.html?overview-summary.html

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Shield Passive Hard Flux
« Reply #4 on: November 24, 2013, 12:27:55 PM »

Ah, Nice. Thanks.

The other thing I need to do is make beam weapons apply hard flux.

That may be innately possible however, haven't checked yet.
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

Okim

  • Admiral
  • *****
  • Posts: 2161
    • View Profile
    • Okim`s Modelling stuff
Re: Shield Passive Hard Flux
« Reply #5 on: November 24, 2013, 01:08:14 PM »

You should be able to do that either through the same very script by using some checks if the ship is receiving damage from a beam weapon. OR you can make a specific on hit effect for all beams that transforms damage from soft to hard.

The later will allow you to pick specific beams to have that effect.

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Shield Passive Hard Flux
« Reply #6 on: November 24, 2013, 01:38:31 PM »

Will not run. Appears to require java.util.List
Also, then requires something, can't figure out what, for ListIterator

Spoiler
Quote
package data.scripts.plugins;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
import com.fs.starfarer.api.combat.ShipAPI;

import java.util.List;  

public class HardShield implements EveryFrameCombatPlugin
{
    private CombatEngineAPI engine;

    @Override
    public void init(CombatEngineAPI engine)
    {
        this.engine = engine;
    }
    
    @Override
    public void advance(float amount, List events)
    {
        if (engine.isPaused()) return;
        
        ListIterator allships = engine.getShips().listIterator();

        if(allships.hasNext()) // is this actually nessesary? A while loop terminates instantly if it fails the first check, unlike a do-while loop.
        {
             while(allships.hasNext())
             {              
                 ShipAPI ship = (ShipAPI) allships.next();
             /*ShieldAPI shield = ship.getShield();
             FluxTrackerAPI flux = ship.getFluxTracker();
             float currentFlux = flux.getCurrentFlux();
             float hardFlux = flux.getHardFlux();
             float fluxRate = 5.;
             if (shield != null)
             {
               if (shield.isOn())
               {
                  if (currentFlux > hardFlux)
                  {
                     if (hardFlux + fluxRate > currentFlux)
                     {
                        
                     }
                     else
                     {
                        flux.decreaseFlux(fluxRate);
                     }
                  }
                  flux.increaseFlux(fluxRate,true);
               }
             }*/
             }
        }
    }
}
[close]

Spoiler
Quote
26829 [Thread-6] ERROR com.fs.starfarer.combat.String  - java.lang.RuntimeException: Error compiling [data.scripts.plugins.HardShield]
java.lang.RuntimeException: Error compiling [data.scripts.plugins.HardShield]
   at com.fs.starfarer.loading.scripts.ScriptStore$1.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: Compiling unit "data/scripts/plugins/HardShield.java"
   at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:212)
   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: File data/scripts/plugins/HardShield.java, Line 24, Column 30: Cannot determine simple type name "ListIterator"
   at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:9403)
   at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:4897)
   at org.codehaus.janino.UnitCompiler.access$108(UnitCompiler.java:4764)
   at org.codehaus.janino.UnitCompiler$17.visitReferenceType(UnitCompiler.java:4704)
   at org.codehaus.janino.Java$ReferenceType.accept(Java.java:2026)
   at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:4743)
   at org.codehaus.janino.UnitCompiler.getLocalVariable(UnitCompiler.java:1680)
   at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2310)
   at org.codehaus.janino.UnitCompiler.access$37(UnitCompiler.java:2302)
   at org.codehaus.janino.UnitCompiler$7.visitLocalVariableDeclarationStatement(UnitCompiler.java:2225)
   at org.codehaus.janino.Java$LocalVariableDeclarationStatement.accept(Java.java:1767)
   at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2228)
   at org.codehaus.janino.UnitCompiler.buildLocalVariableMap(UnitCompiler.java:2189)
   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:2039)
   at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:851)
   at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:832)
   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:528)
   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:421)
   at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:376)
   at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:765)
   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:383)
   at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:352)
   at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:210)
   ... 5 more
[close]

Unsure how exactly flux data is stored.
Is hard and soft seperate, or is hard on top of soft?
Actually, it looks like you have total and hard, with soft being the difference. I cannot be certain yet however.

Also, I cannot determine how to access shield passive flux increase. (only the multiplier)

Unsure how many ticks per second, and, if i were to get shield passive flux increase, whether or not it was already in "Per tick" units.

Haven't gotten to messing with beams yet. May not even be needed, depending. After all, shields should now have legitimate upkeep costs, so blocking beam damage wont be free anymore regardless.
« Last Edit: November 24, 2013, 02:09:15 PM by Ranakastrasz »
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: Shield Passive Hard Flux
« Reply #7 on: November 24, 2013, 03:17:26 PM »

to make a beam weapon apply hard flux, you need an everyframeweaponplugin script, its not optional, using combatplugin will eat your cpu in seconds, because you need to make a list of ships, store curent flux, weapon list, weapon active state, and lots more values... too much to be efficient since it will have to refresh evry frame.

simple how to:
get weapon firing state
get fluxtracker
if state.isfiring && notoverloaded
reduce flux by weapon flux use rate
increase flux by weapon flux use rate with boolean hardflux=true

done you are
you can use the same idea for your shield script, but you will need a decorative weapon on the ship to implement the script with the ships that you want it on (this is also more efficient then evry frame combat plugins)

sample:
Spoiler
Code: java
public class somescript implements EveryFrameWeaponEffectPlugin
{
    //external values //use to store information between frames, cant be done if they are inside advance()
    private float hit1=0;
    private float hit2=0;
    private boolean wasActive=false;
    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon)
    {
        if (engine.isPaused())    //paused nesesary so it dose not run while game is paused
        {
            return;
        }

        ShipAPI ship;
        ship=weapon.getShip();


        //do stuff if condition met...
        if(ship.getSomething.isOn)
        {
              //your something
              float totalarmor = getTotalArmor(ship) //how you use your own getter in script
        }
    }

    //gets total armor of a ship  //just an example of a getter
    public static float getTotalArmor(ShipAPI ship)
    {
        ArmorGridAPI armorgrid = ship.getArmorGrid();
        float sum=0;
        int maxX = armorgrid.getLeftOf()+armorgrid.getRightOf();
        int maxY = armorgrid.getAbove()+armorgrid.getBelow();

        for (int X=0; X<maxX; X++)
        {
            for (int Y=0; Y<maxY; Y++)
            {
                sum += armorgrid.getArmorValue(X, Y);
            }
        }
        return sum;
    }
}
[close]

also if you are planing to do any serious scripting, get an ide, idea is good
how to set up idea for starsector:
http://fractalsoftworks.com/forum/index.php?topic=6809.msg111278;topicseen#msg111278
(realy that thread(or a thread holding directions to all the IDE setup threads) should be stickied on the moding forum...)
dont worry about jars, you wont be using them for this so its not important, the ide itself is pretymuch mandatory though unless you want to suffer due to some masochistic urges hidden in your soul
« Last Edit: November 24, 2013, 03:37:46 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!

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Shield Passive Hard Flux
« Reply #8 on: December 01, 2013, 07:53:08 AM »

Ok, drop the beam weapon part for now, as I probably don't need that. After all, if your shields already generate hard flux when active, then if beam weapons require active shields to block them, you are getting hard flux anyway.

At this time, I need to figure out how to access the flux-generation rate of shields for a given instance of a ship in combat.

I believe this requires me to find a way to access a ship's blueprint, but I cannot be certain.

Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: Shield Passive Hard Flux
« Reply #9 on: December 01, 2013, 08:16:56 AM »

MutableShipStatsAPI getShieldUpkeepMult() may be what you are looking for, test it out
if its not you can allways set the mult to 0 and then implement your own custom shield upkeep cost (its probably faster this way imo)
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!

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Shield Passive Hard Flux
« Reply #10 on: December 01, 2013, 08:22:29 AM »

Well, I need to look at the actual value. However, I thought a Mult was a multiplier, meaning it was applied to the pre-existing value, and not the value itself. However, I might be mistaken, and will look at it.

Edit: It is in fact a multiplier, usually with a value of 1.

I still need to access the shield upkeep rate. If possible, I need to suppress shield upkeep, but only if I can get the value independent of this, including any modifications made by ship mods.
« Last Edit: December 01, 2013, 08:55:47 AM by Ranakastrasz »
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: Shield Passive Hard Flux
« Reply #11 on: December 01, 2013, 09:13:22 AM »

since it is a mult do:

Code: java
//outside of public void advance()
private IntervalUtil STimer = new IntervalUtil(.05f, .0f);
////////////////////////////////////////////////////
public void advance(amount)
{      
        timer.advance(amount);
        //whatever for() search function you want to use
        if (ship.getShield().isOn()){
            ship.getMutableStats().getShieldUpkeepMult().modifyMult(ship.getFleetMemberId(),0f);
            if (timer.intervalElapsed()){
                FluxTrackerAPI tracker = ship.getFluxTracker();
                tracker.increaseFlux(0.001f*tracker.getMaxFlux(),true);
            }
        }
}

that should do what you want, 0.001f is the amount shield costs to upkeep depending on the ships flux reserve (wich is how shield upkeep is calculated in any case...)
« Last Edit: December 01, 2013, 09:18:45 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!

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Shield Passive Hard Flux
« Reply #12 on: December 01, 2013, 10:20:41 AM »

Cannot figure out how that works. Timer probably is self explanitory. Timer goes off 20 times a second, due to it advancing with the combat simulation, and manages overflow of duration. Hence, this should run 20 times a second. I cannot figure out how to implemented it. It would be benfitial however, considering it should reduce how often calculations are made.

However, I don't see what setting the Mult to zero every time is for, unless it resets, or only effects a copy for this particular gameloop.

As for 0.001f, being 1/1000th in float format. Well, unless getMaxFlux works very differently from how I think it does, or other factors are involved (that ship spreadsheet that has multipliers), then that is clearly wrong.

The Hammerhead has an upkeep of 100 for 4200 flux, while the shuttle has an upkeep of 75 for 1600 flux. This makes it pretty obvious that it is not simply a fraction of the total.

Hammerhead, 4200 * 0.001 = 42; 42/100 = .42
Shuttle       , 1600 * 0.001 = 16; 16/  75 = .21_6_

I would expect to get very nearly the same value there.

The spreadsheet gives a 0.5 modifier for the shuttle, and 0.4 for the hammerhead, which is nowhere near enough to make up the difference.

Presumably I missed something somewhere.
« Last Edit: December 01, 2013, 10:51:51 AM by Ranakastrasz »
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: Shield Passive Hard Flux
« Reply #13 on: December 01, 2013, 11:39:21 AM »

i didnt bother putting in a check for the mult cause it would take more calculations then just setting mult every time
the 0.001 is just a number i pulled from my head it can e anything you want

1600*.04=64
4200*.04=168
thats roughly how the mult works
(the actual math for the shield cost calculation is backwards, ask alex if there is logic behind it(i cant see any))

0.001f*tracker.getMaxFlux() is just a function i made as a rough aproximation, you can set it up however you want as long as it gives a float value...
« Last Edit: December 01, 2013, 11:46:30 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!

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Shield Passive Hard Flux
« Reply #14 on: December 01, 2013, 12:41:14 PM »

Alright. That makes more sense.

It is actually working now, largely.

However, I need to allow the shield efficiency modifier to work.

I would prefer using the exact equation, so it matches the internal data shown for shield rate.

I would like to be able to store some information for later. However, I cannot determine how to do that.
~A container indexed via ship.getFleetMemberId(), with floats for the efficiency modifier. The question is where to put the calculation.
Does init for EveryFrameCombatPlugin run when created, and each battle, it is created? Need to run again for each new ship introduced.

Also, will you end up with a 10000000 long stack of 0 multipliers, which may overflow and waste massive amounts of memory, or does that work differently?

Documentation for the starfarer API is not particularly comprehensive yet.


Wait a second. Does that work with multiple ships? Why did it work before without a check for the shield existing?
« Last Edit: December 01, 2013, 02:14:35 PM by Ranakastrasz »
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire