Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.96a is out! (05/05/23); Blog post: Colony Crises (11/24/23)

Author Topic: Pseudo-ability activation question  (Read 1197 times)

Meridias

  • Ensign
  • *
  • Posts: 9
    • View Profile
Pseudo-ability activation question
« on: March 27, 2021, 07:45:02 PM »

I'm trying to figure out how to get what amounts to an ability to be on all the time while flying around. Something similar to the fuel siphon mod but instead of it being tied to an ability with an icon to turn on/off, I just want the effect of the ability to always be there (ie, the sucking up of material while flying through a nebula). Keep in mind that this is my first attempt at a mod so if you would keep the answers pretty dumbed-down for me please?  :)

I've been trying to work it out taking a look at the siphon source, but since the effect isn't going to be tied to an ability I'm going to assume that BaseAbilityPlugin or BaseToggleAbility aren't what I need to look at.


(quick idea layout to help you figure out what I'm looking towards: start/load game with mod, fly around and do things, if you aren't in a nebula cloud nothings different. if you are, look at fleet fuel status and max, generate fuel if not full). I might have it do other things later on, but to start with, this will be it.
Thanks.

edit: After some looking around, would extending NebulaTerrainPlugin be what I need? Then overriding the applyeffect to add the code for all the fuel stuff?
« Last Edit: March 27, 2021, 10:57:53 PM by Meridias »
Logged

Meridias

  • Ensign
  • *
  • Posts: 9
    • View Profile
Re: Pseudo-ability activation question
« Reply #1 on: March 29, 2021, 12:14:30 AM »

My lack of knowledge about java is really showing. I'm currently trying to work out how to get SS to recognize my custom class with the nebulaterrainplugin overrides. Any suggestions for a specific reference to look at?

(or will this particular way of doing it not work at all for what I'm shooting for?)
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4509
    • View Profile
    • GitHub profile
Re: Pseudo-ability activation question
« Reply #2 on: March 29, 2021, 01:13:48 AM »

Messing with terrain plugins is more invasive than is needed for this.

I'd recommend using an EveryFrameScript. In its advance() method, check if the player fleet is in a nebula and add fuel if so.

Detecting whether the player is in a nebula is a bit complicated, but the Tiandong Heavy Industries mod has you covered:
Pastebin

You can add your script in the mod plugin with Global.getSector().addTransientScript(new MyScript()); in the onGameLoad() method.
« Last Edit: March 29, 2021, 01:34:43 AM by Histidine »
Logged

Meridias

  • Ensign
  • *
  • Posts: 9
    • View Profile
Re: Pseudo-ability activation question
« Reply #3 on: March 29, 2021, 01:33:11 AM »

Cool, thanks. Now I just have to get my brain to parse all that. :)
Logged

Meridias

  • Ensign
  • *
  • Posts: 9
    • View Profile
Re: Pseudo-ability activation question
« Reply #4 on: March 30, 2021, 02:08:06 AM »

Next question. Assume that you're in your fleet and sitting in a nebula sucking up the 'stuff' and making fuel. I have a float value for how many fuel to create per day. If I wanted to have that value spread over 1 day (ie, slowly being created just like supplies are used), what would be a good way of doing that? I'm guessing that I'll be looking at framerate and increment per frame or something like that?

OR
If you could point out to me which source java file actually has that calculation in it for the daily supply use so I can take a look at that for reference, that would work too.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4509
    • View Profile
    • GitHub profile
Re: Pseudo-ability activation question
« Reply #5 on: March 30, 2021, 06:21:53 AM »

Not sure if the daily supply use is actually in the accessible API (as opposed to the obsfucated part of the code). But you'd do something like this:

Code: java
public static final float FUEL_PER_DAY = 10;

@Override
public void advance(float amount)
{
    float days = Global.getSector().getClock().convertToDays(amount);
    Global.getSector().getPlayerFleet().getCargo().addFuel(FUEL_PER_DAY * days);
}
Logged

Meridias

  • Ensign
  • *
  • Posts: 9
    • View Profile
Re: Pseudo-ability activation question
« Reply #6 on: March 30, 2021, 11:22:14 AM »

Yeah, I was hoping it was something easy with the convert calls from the clockAPI but I wasn't sure on how to work it. Didn't know if there was other stuff going on, having to do with the framerate or if the clock took care of that by itself. Thanks again.
Logged

Meridias

  • Ensign
  • *
  • Posts: 9
    • View Profile
Re: Pseudo-ability activation question
« Reply #7 on: March 31, 2021, 01:17:09 AM »

If anyone wants to use this mod, I have it up on nexus. The mod is called Ramscoop.
Logged