Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: [0.9.1.a RC8] Can't seem to override "maxIndustries".  (Read 5085 times)

SpaceMonster

  • Ensign
  • *
  • Posts: 13
    • View Profile
[0.9.1.a RC8] Can't seem to override "maxIndustries".
« on: May 27, 2019, 08:06:13 PM »

In my settings file I have this:
"maxIndustries": [1,1,1,2,3,4,5,6,7,8]

But the end result is still '4' on my size 10 colonies in-game. I know the settings file is valid json & it succeeds in changing the values of other things.
If I make the same change in starsector-core/data/config/settings.json the change works in-game.

Bug from merging json appending the values instead of replacing them? Or am I doing something wrong?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #1 on: May 27, 2019, 08:48:44 PM »

Sorry, just have a second, so I have to be quick: yeah, json merges (most) arrays by appending, this is unfortunate here but "how it works".

You could have this work in a mod using code - get the json array using Global.getSettings().getJSONArray(<key>) and then editing that array. You'd want to do this in your ModPlugin's onApplicationLoad() method. IIRC this doesn't require compiling code and the mod plugin could be a loose script, making it easier. But, yeah, in either case more of a pain than a json edit.
Logged

SpaceMonster

  • Ensign
  • *
  • Posts: 13
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #2 on: May 28, 2019, 10:37:12 AM »

Thanks. I got it working from that.
Here's my quick working copy if anyone else needs a base to work with.

Code
public class GMod extends BaseModPlugin {
    @Override
    public void onApplicationLoad() throws Exception {
        JSONArray maxIndustries = Global.getSettings().getJSONArray("maxIndustries");

        // Sets sizes 6-10 to 4-8 respectively.
        for (int i = 5; i < 10; i++) {
            maxIndustries.put(i, i - 1);
        }
    }
}
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #3 on: May 28, 2019, 11:01:53 AM »

Nice! Thank you for sharing the code.
Logged

SpaceMonster

  • Ensign
  • *
  • Posts: 13
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #4 on: May 28, 2019, 11:49:22 AM »

My only final issue is the colony UI won't show any modules past 12. I can build a thirteenth (planetary shield) but I can't access it, cancel it, etc.
Note that I have to have less than 12, then I can tell it to build two more modules leading to a planned total of 13. Once 12 are completed I can't build anything due to "Maximum number of industries reached" despite the planet being 7/8 industries. (And a shield isn't an industry. Err, well, I think it isn't.)
I'll wait but I expect the thirteenth I queued up will get built in time.

Is there some way to expand the UI? I'm not sure where in the code this is.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #5 on: May 28, 2019, 12:00:24 PM »

This is in core code (i.e. not anywhere you might see/tweak), and actually, being able to queue up a 13th industry/structure looks like a bug - let me make a note. There's a hard limit of 12 things total per colony.
Logged

SpaceMonster

  • Ensign
  • *
  • Posts: 13
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #6 on: May 28, 2019, 12:57:29 PM »

I found a bug! Yay!

To elaborate, I can queue up more than 13 but I don't know how far they make it. I know I can see a thirteenth structure in 'Command' -> 'Colonies' -> planet tooltip, "Industries & Structures" section. But I'm not waiting 90+ for each to know if they get built.

Where is best to make a feature request thread for this? I don't expect it to be in the base game, but if modding could get an override-able value somewhere (settings.json) that would be boss.
I imagine it's not a simple change, but I can dream.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #7 on: May 28, 2019, 01:02:56 PM »

(Already fixed this up, btw, in terms of the limit being bypassed.)

Yeah, this came up before, so you don't need to make a request thread :)

Basically it's a UI issue - I'd have to put the industry list inside a scroller to support more than 12 (or rearrange the UI in a big way). Neither seems all that good UI-wise, really, so it's not something I'm keen on doing.

It also wouldn't see much use in vanilla - since design-wise, I think it's better to encourage fewer things being built at a colony; at least in my view, if the 12 building limit is being brushed against, that's indicative of a design problem - and if I did this just for people to be able to use in mods etc, there's a solid chance I'd break it without realizing, and that's its own set of problems.
Logged

eltharion

  • Ensign
  • *
  • Posts: 5
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #8 on: September 22, 2019, 09:06:58 AM »

Thanks. I got it working from that.
Here's my quick working copy if anyone else needs a base to work with.

Code
public class GMod extends BaseModPlugin {
    @Override
    public void onApplicationLoad() throws Exception {
        JSONArray maxIndustries = Global.getSettings().getJSONArray("maxIndustries");

        // Sets sizes 6-10 to 4-8 respectively.
        for (int i = 5; i < 10; i++) {
            maxIndustries.put(i, i - 1);
        }
    }
}

Hi SpaceMonster,
Would it be possible for you to post a file that can be easily integrated into a mod?

Already doubling the industrial structures of a colony would be good,
getting up to being able to build 10, would be perfect.

Does the limit of 12 to which Alex "of the UI" refers, includes orbital structures and defenses?

Thank you ;)
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #9 on: September 22, 2019, 09:38:11 AM »

Yeah, 12 is just "how many fit onto that screen", so it's everything.
Logged

SpaceMonster

  • Ensign
  • *
  • Posts: 13
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #10 on: September 22, 2019, 11:36:40 AM »

Hi SpaceMonster,
Would it be possible for you to post a file that can be easily integrated into a mod?

Attached. I copied out just this part so, in theory it'll work; untested though.
I also renames the files to try to make it clearer. Possible syntax errors as a result.

[attachment deleted by admin]
« Last Edit: September 22, 2019, 11:38:15 AM by SpaceMonster »
Logged

eltharion

  • Ensign
  • *
  • Posts: 5
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #11 on: September 23, 2019, 03:27:19 PM »

Hi SpaceMonster,
Would it be possible for you to post a file that can be easily integrated into a mod?

Attached. I copied out just this part so, in theory it'll work; untested though.
I also renames the files to try to make it clearer. Possible syntax errors as a result.

Thanks SpaceMonster, I will try to test it.
If I can make good use of it in a mod, I'll publish it by adding you in the credits, if you agree.
Thanks.  :D
Logged

SpaceMonster

  • Ensign
  • *
  • Posts: 13
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #12 on: September 24, 2019, 07:32:34 AM »

Thanks SpaceMonster, I will try to test it.
If I can make good use of it in a mod, I'll publish it by adding you in the credits, if you agree.
Thanks.  :D

Do whatever you wish with it. It's basically 2~3 lines of code. The rest is just boilerplate.

For licensings sake, I release this in public domain.
Logged

Yunru

  • Admiral
  • *****
  • Posts: 1560
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #13 on: September 27, 2019, 02:05:16 PM »

Question:
If I wanted to, say, replace Planetary Operations 3's effect with increasing the max number of industries by 1, could I base it off this code, or would it be applied at the wrong time if I did?

And would this code work for that purpose?
(It's frightening how quickly I forgot everything I learned about java.)
Code
for (int i = 0; i < 10; i+){
maxIndustries.put(i, (maxIndustries[i] + 1));
}

SpaceMonster

  • Ensign
  • *
  • Posts: 13
    • View Profile
Re: [0.9.1.a RC8] Can't seem to override "maxIndustries".
« Reply #14 on: September 27, 2019, 04:45:49 PM »

Nah, this just sets the baseline. PO3 adds a bonus separately. To change that bonus, you have to find this file:
Code
data\characters\skills\planetary_operations.skill
Then, copy it into your mod keeping the structure & filename intact. This is the file the game uses to find the right class to use for the handling the bonus.

In that .skill file you will find:
Code
        {
            "name":"Level 3",
            "requiredSkillLevel":3,
            "effectBasedOnLevel":false,
            "effects":[
                {"type":"GOVERNED_OUTPOST", "script":"com.fs.starfarer.api.impl.campaign.skills.PlanetaryOperations$Level3A"},
            ]
        },

What you want to do is change `com.fs.starfarer.api.impl.campaign.skills.PlanetaryOperations$Level3A` to target your own code (class) instead. This means you have to create a .java file that either implements or extends Level3A (or use the copied code as a starting point), save it somewhere with the right package name, and change the script target to your `new.package.ClassName`.

You can find the existing implementation of that still in `starfarer.api.zip` under `com\fs\starfarer\api\impl\campaign\skills\PlanetaryOperations.java`.

In short, copy that file to the same dir as the .skill file, change the package to `package data.characters.skills;`, then edit it as you see fit.
Keep in mind this will only change `Level3A` since that's what the script points to. You'd have to change the other script targets in the .skill file if you want the other levels to be altered too.

If you leave the `Level3A` as a inner class, your new target will be something like `data.characters.skills.PlanetaryOperations$Level3A` (Assuming you put it in {mod}\data\characters\skills). You only need to include inner & outer class names (separated by '$') if you leave the file as is.
If you move Level3A to an outer class, it would just be `data.characters.skills.Level3A` (Or whatever you've named the class.)

Note: Make sure the file name matches the top-level class.

Odds are you'll hit a syntax error or something along the way but those get printed straight to starsector.log so it's easy to check.

PS: You can actually setup a java IDE project and set `starfarer.api.zip` as a dependency to help you make edit the file. If you do, symlink your 'data' folder into the projects 'src' folder. (So it looks like {project root}\src\data\...) This should let you edit the files whilst keeping them where they need to be for the mod.
That will help you with everything you've forgotten about java.

PPS: If you do go the IDE route, make sure the project is set for java 1.7 as that is the IDE that's bundled with the game. (JAVA_VERSION="1.7.0")
« Last Edit: September 27, 2019, 04:48:33 PM by SpaceMonster »
Logged