Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Making a ship system that scales with flux level - [ NOW SOLVED! :D ]  (Read 4368 times)

AxleMC131

  • Admiral
  • *****
  • Posts: 1722
  • Amateur World-Builder
    • View Profile

I'm currently trying to set up a (number of) custom ship system(s) with one or two buffs that scale with the ship's current flux level, ie. The higher the ship's flux when the system is activated, the more potent the effects of the buff are.

Problem is, I'm not sure in the file how to grab current stats on the ship. I know about the MutableShipStats and I've got that bit under control for modifying combat stats, but I'm stuck with retrieving existing numbers - MutableShipStats doesn't appear to have a "current flux level" or similar. Can anyone give me a pointer as to what part of the API I should be looking at in the system stats file, and how I can retrieve the ship's current flux level into a variable?
« Last Edit: March 08, 2017, 02:49:32 AM by AxleMC131 »
Logged

Orikson

  • Captain
  • ****
  • Posts: 280
  • Always Seen on Discord
    • View Profile
Re: Making a ship system that scales with flux level - Need advice!
« Reply #1 on: March 07, 2017, 06:56:51 PM »

I'm not sure if this will help, but try looking at the Excelsior-class frigate from Ships & Weapons Pack mod.

It doesn't have a flux buff system, but it's built-in weapons (Flux Shunt cannons) gets stronger the higher the flux levels of the ship.
Logged
"A story teller and a trader. Tell me your tales and I'll tell you no lies."

Come join the Starsector Fan Chat! It's decently active.

Link: https://discord.gg/eb5UC

AxleMC131

  • Admiral
  • *****
  • Posts: 1722
  • Amateur World-Builder
    • View Profile
Re: Making a ship system that scales with flux level - Need advice!
« Reply #2 on: March 07, 2017, 09:11:36 PM »

Thanks for the advice. :D I went through the files relating to the Excelsior's abilities (my word are there a lot!) and found that there's a "fluxTracker()" utility in the ShipAPI. This has allowed me to put together my own system to the plans I was working on.

I've got some math going on now in the system file, and when the system is activated, both passive flux dissipation and ballistic rate-of-fire are buffed, scaling with the current flux level (up to 250% of normal at 100% flux capacity). Sadly, and I'm not sure if this is because of how I've got things setup, I can't call the variables I have set to display in the status data on the side of the screen.

This is what currently makes up the ship system file:

Spoiler

- - - - -
package data.shipsystems.scripts;

import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.impl.combat.BaseShipSystemScript;

public class FluxPurgeAmmoStats extends BaseShipSystemScript {


   public static final float VENT_BONUS = 200f;
   public static final float MAX_PERCENT = 150f;
   

   public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel) {

      ShipAPI ship;
      ship = (ShipAPI) stats.getEntity();
      float FLUX_CURRENT = ship.getFluxTracker().getCurrFlux();   # Get the ship's current flux value
      float FLUX_TOTAL = stats.getFluxCapacity().getBaseValue();   # Get the ship's total flux capacity
      
      float FLUX_LEVEL = FLUX_CURRENT / FLUX_TOTAL;         # Get the ratio of current flux to maximum flux as a float between 0 and 1

      float ROF_BONUS = FLUX_LEVEL * MAX_PERCENT;         # Multiply that by the modifier - in this case 150

      stats.getBallisticRoFMult().modifyPercent(id, ROF_BONUS);
      stats.getFluxDissipation().modifyPercent(id, ROF_BONUS);
      //stats.getFluxDissipation().modifyPercent(id, VENT_BONUS);
   }


   public void unapply(MutableShipStatsAPI stats, String id) {
      stats.getBallisticRoFMult().unmodify(id);
      stats.getFluxDissipation().unmodify(id);
   }


   
   public StatusData getStatusData(int index, State state, float effectLevel) {

      if (index == 0) {
         return new StatusData("dissipation scaling with flux level", false);
         //return new StatusData("flux dissipation at " + (int) (VENT_BONUS + 100f) + "%", false);
         //return new StatusData("current flux level" + (int) FLUX_CURRENT, false);
      }
      if (index == 1) {
         return new StatusData("ballistic rof scaling with flux level", false);
      }
      return null;
   }
}
- - - - -

[close]

Ideally I'd like to refer to the variable "ROF_BONUS" in the StatusData string concatenations, but if I do the game gives me this "ROF_BONUS is not a rvalue" error. I can't say for certain due my limited experience, but I presume that means "I can't give you that number in the Status Data because it's a dynamic value that changes over time". Any suggestions on how I can reconfigure this to make that work?
« Last Edit: March 07, 2017, 09:28:15 PM by AxleMC131 »
Logged

Deathfly

  • Modders' Vanguard
  • Commander
  • ***
  • Posts: 245
  • Murdered by T. H. Morgan
    • View Profile
Re: Making a ship system that scales with flux level - Need advice!
« Reply #3 on: March 08, 2017, 12:01:32 AM »

"ROF_BONUS" is a local field of the method called "apply", not a field for class "FluxPurgeAmmoStats" so you cann't reference it in the method "getStatusData", another method of class "FluxPurgeAmmoStats".

To do so, you should declare the field "ROF_BONUS" in class "FluxPurgeAmmoStats". like what had you done for the "VENT_BONUS" and "MAX_PERCENT.
« Last Edit: March 08, 2017, 12:05:05 AM by Deathfly »
Logged
A not-so-noob functional geneticist
And a free bug hunter
Code and decode almost everythings with a genomics approach.
Served in Neutrino corporation as a long-term services and supports staff.

AxleMC131

  • Admiral
  • *****
  • Posts: 1722
  • Amateur World-Builder
    • View Profile
Re: Making a ship system that scales with flux level - Need advice!
« Reply #4 on: March 08, 2017, 12:18:16 AM »

To do so, you should declare the field "ROF_BONUS" in class "FluxPurgeAmmoStats". like what had you done for the "VENT_BONUS" and "MAX_PERCENT.

I think I've tried this, but the wrong way around. I attempted to achieve this by having the -

"      ShipAPI ship;
      ship = (ShipAPI) stats.getEntity();
      float FLUX_CURRENT = ship.getFluxTracker().getCurrFlux();
      float FLUX_TOTAL = stats.getFluxCapacity().getBaseValue(); "

- bit under the initial Class definition, but because I was calling ship stats outside the MutableShipStats bit it wouldn't parse the file.

Can I achieve this by defining ROF_BONUS as a null variable in the initial Class definition, ie. alongside -

"   public static final float VENT_BONUS = 200f;
   public static final float MAX_PERCENT = 150f; "

- at the start, and then alter that variable with the remaining code as it currently stands?


(... I really hope that made sense.)
Logged

Deathfly

  • Modders' Vanguard
  • Commander
  • ***
  • Posts: 245
  • Murdered by T. H. Morgan
    • View Profile
Re: Making a ship system that scales with flux level - Need advice!
« Reply #5 on: March 08, 2017, 12:37:52 AM »

You should declare and initial the field "ROF_BONUS" in class "FluxPurgeAmmoStats" and reference that field in both "apply" and "getStatusData".

And the code should looks like this.

Spoiler
Code
package data.shipsystems.scripts;

import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.impl.combat.BaseShipSystemScript;

public class FluxPurgeAmmoStats extends BaseShipSystemScript {

//    public static final float VENT_BONUS = 200f;
    public static final float MAX_PERCENT = 150f;
    private float FLUX_LEVEL = 0;
    private float ROF_BONUS = 0;

    @Override
    public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel) {

        if (!(stats.getEntity() instanceof ShipAPI)) {
            return;
        }
        ShipAPI ship = (ShipAPI) stats.getEntity();
        FLUX_LEVEL = ship.getFluxTracker().getFluxLevel();
        ROF_BONUS = FLUX_LEVEL * MAX_PERCENT;
        stats.getBallisticRoFMult().modifyPercent(id, ROF_BONUS);
        stats.getFluxDissipation().modifyPercent(id, ROF_BONUS);
    }

    @Override
    public void unapply(MutableShipStatsAPI stats, String id) {
        stats.getBallisticRoFMult().unmodify(id);
        stats.getFluxDissipation().unmodify(id);
    }

    @Override
    public StatusData getStatusData(int index, State state, float effectLevel) {

        if (index == 0) {
            return new StatusData("flux dissipation increaced by " + (int) (ROF_BONUS) + "%", false);
        }
        if (index == 1) {
            return new StatusData("ballistic rof increaced by "+(int)ROF_BONUS +"%", false);
        }
        return null;
    }
}
[close]
Logged
A not-so-noob functional geneticist
And a free bug hunter
Code and decode almost everythings with a genomics approach.
Served in Neutrino corporation as a long-term services and supports staff.

AxleMC131

  • Admiral
  • *****
  • Posts: 1722
  • Amateur World-Builder
    • View Profile
Re: Making a ship system that scales with flux level - Need advice!
« Reply #6 on: March 08, 2017, 12:59:26 AM »

You should declare and initial the field "ROF_BONUS" in class "FluxPurgeAmmoStats" and reference that field in both "apply" and "getStatusData".

And the code should looks like this.

Spoiler
Code
package data.shipsystems.scripts;

import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.impl.combat.BaseShipSystemScript;

public class FluxPurgeAmmoStats extends BaseShipSystemScript {

//    public static final float VENT_BONUS = 200f;
    public static final float MAX_PERCENT = 150f;
    private float FLUX_LEVEL = 0;
    private float ROF_BONUS = 0;

    @Override
    public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel) {

        if (!(stats.getEntity() instanceof ShipAPI)) {
            return;
        }
        ShipAPI ship = (ShipAPI) stats.getEntity();
        FLUX_LEVEL = ship.getFluxTracker().getFluxLevel();
        ROF_BONUS = FLUX_LEVEL * MAX_PERCENT;
        stats.getBallisticRoFMult().modifyPercent(id, ROF_BONUS);
        stats.getFluxDissipation().modifyPercent(id, ROF_BONUS);
    }

    @Override
    public void unapply(MutableShipStatsAPI stats, String id) {
        stats.getBallisticRoFMult().unmodify(id);
        stats.getFluxDissipation().unmodify(id);
    }

    @Override
    public StatusData getStatusData(int index, State state, float effectLevel) {

        if (index == 0) {
            return new StatusData("flux dissipation increaced by " + (int) (ROF_BONUS) + "%", false);
        }
        if (index == 1) {
            return new StatusData("ballistic rof increaced by "+(int)ROF_BONUS +"%", false);
        }
        return null;
    }
}
[close]

Aight, I think I can handle that. What does the "@Override" mean? I've been seeing it a lot in trawling through the game- and mod-code, but never with any explanation of what it does.

Also, I hadn't noticed that you could format code that way in these forum comments, but now I see the button. Thanks. :) (Although it would be nice if it would show it in a slightly larger box... Currently it's showing your code section as one line at a time and a scroll up/down button.)
« Last Edit: March 08, 2017, 01:00:58 AM by AxleMC131 »
Logged

AxleMC131

  • Admiral
  • *****
  • Posts: 1722
  • Amateur World-Builder
    • View Profile
Re: Making a ship system that scales with flux level - Need advice!
« Reply #7 on: March 08, 2017, 01:13:06 AM »

Update: IT WORKS!
Logged

Mini S

  • Ensign
  • *
  • Posts: 47
    • View Profile
Re: Making a ship system that scales with flux level - [ NOW SOLVED! :D ]
« Reply #8 on: March 08, 2017, 04:24:29 AM »

When you do this:

public class FluxPurgeAmmoStats extends BaseShipSystemScript {

You are "importing" all methods and variables of BaseShipSystemScript into FluxPurgeAmmoStats

What the "@Override" mean is that you are changing one of the "imported" methods. if you need the original method you may call it with super.methodName()(recommend to only use it while defining classes and NOT when dealing with objects).
Logged

AxleMC131

  • Admiral
  • *****
  • Posts: 1722
  • Amateur World-Builder
    • View Profile
Re: Making a ship system that scales with flux level - [ NOW SOLVED! :D ]
« Reply #9 on: March 08, 2017, 01:49:00 PM »


What the "@Override" mean is that you are changing one of the "imported" methods. if you need the original method you may call it with super.methodName()(recommend to only use it while defining classes and NOT when dealing with objects).


Ah, so it allows you to make changes to a method you have imported at the top of the file for the sake of the class, in this case the "...MutableShipStatsAPI".
Logged