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)

Pages: 1 ... 419 420 [421] 422 423 ... 706

Author Topic: Misc modding questions that are too minor to warrant their own thread  (Read 1700035 times)

SafariJohn

  • Admiral
  • *****
  • Posts: 3010
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6300 on: April 15, 2020, 07:59:40 PM »

I want to iterate through every loaded mod and load a text file from each mod, but I don't know which mods have it and which don't. SettingsAPI.loadText()'s method contract implies I can handle FileNotFound exceptions, but it catches them itself and crashes the game instead. Is there any way for me to check if the file exists before I pass the path to loadText()?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6301 on: April 15, 2020, 09:20:09 PM »

I tried some personal edit in a mod by starting from someone else. I got an error message. It seems to tell me the field id is missing from a file, however how can I know which file?

I cant seem to be able to paste my log here, it always crash my post

That's due to the log containing a special character of some sort. But, yeah, need more to go on. The file is probably mentioned in one of the lines before the error, though.

Each mod_info of a mod point to a single mod plugin. Could a single mod define multiple plugin? Could a single mod have multiple mod info?

It's just one mod_info and one plugin per mod.


What does MarketAPI.reapplyIndustries() do? Is it necessary when changing industries through a script or, maybe, does it read and reapply what is contained in the economy json files?

It refreshes admin stats, and then calls unapply()/apply() on all industries in order. I don't think it's necessary in the normal course of things - this will happen during normal economy ticks, anyway. However, if you're relying on market data to be accurate vis a vis an industry change you just made, then this might be necessary. But that could get a little dodgy, anyway, as it might take an economy tick for all the impacts of an industry change to propagate.

If you make a change in response to a UI interaction, it's probably better to call Global.getSector().getEconomy().tripleStep(). You *do not* want to call this from a general script that's just running on a timer/interval/whatever, though, as it might be enough to drop a frame or two. But in response to UI interactions, it's fine.


I want to iterate through every loaded mod and load a text file from each mod, but I don't know which mods have it and which don't. SettingsAPI.loadText()'s method contract implies I can handle FileNotFound exceptions, but it catches them itself and crashes the game instead. Is there any way for me to check if the file exists before I pass the path to loadText()?

I think if you just catch RuntimeException there - instead of IOException - you should be fine.
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6302 on: April 16, 2020, 12:53:26 AM »

It refreshes admin stats, and then calls unapply()/apply() on all industries in order. I don't think it's necessary in the normal course of things - this will happen during normal economy ticks, anyway. However, if you're relying on market data to be accurate vis a vis an industry change you just made, then this might be necessary. But that could get a little dodgy, anyway, as it might take an economy tick for all the impacts of an industry change to propagate.

If you make a change in response to a UI interaction, it's probably better to call Global.getSector().getEconomy().tripleStep(). You *do not* want to call this from a general script that's just running on a timer/interval/whatever, though, as it might be enough to drop a frame or two. But in response to UI interactions, it's fine.

Thanks!
Logged

SafariJohn

  • Admiral
  • *****
  • Posts: 3010
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6303 on: April 16, 2020, 05:38:31 AM »

I want to iterate through every loaded mod and load a text file from each mod, but I don't know which mods have it and which don't. SettingsAPI.loadText()'s method contract implies I can handle FileNotFound exceptions, but it catches them itself and crashes the game instead. Is there any way for me to check if the file exists before I pass the path to loadText()?

I think if you just catch RuntimeException there - instead of IOException - you should be fine.

Agh, dang, that works. Obvious in retrospect. Thanks.
Logged

Hydra7-1

  • Ensign
  • *
  • Posts: 22
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6304 on: April 16, 2020, 01:01:11 PM »

Which would be easier? adding a post combat dialogue option, or making a unique item drop for a bounty?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6305 on: April 16, 2020, 01:12:34 PM »

The latter, I would say. I think using the fleet.addDrop* methods would work. As - I think - should using the BaseSalvageSpecial.addExtraSalvage() method. Adding a post-combat dialog option is way more complicated, and would involve overriding the combat dialog, which wouldn't play nice with other mods.
Logged

Hydra7-1

  • Ensign
  • *
  • Posts: 22
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6306 on: April 16, 2020, 04:30:45 PM »

So I would have the fleet drop a unique item, which could then be turned in as a quest item that can turned in for the bounty target as an officer. That would most likely be the most mod friendly way to recruit HVB/IBB yes?
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6307 on: April 16, 2020, 06:40:21 PM »

If I add a condition to a market such as:

Code
derinkyu.getMarket().addCondition(Conditions.ORE_MODERATE);

and then add the Mining Industry- during a script called during onNewGameAfterEconomyLoad()-

- the market does not actually produce the Ore commodity in the economy. Can I not do that there or am I doing something wrong?
Logged

SafariJohn

  • Admiral
  • *****
  • Posts: 3010
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6308 on: April 16, 2020, 07:10:28 PM »

Try calling MarketAPI.reapplyConditions()
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6309 on: April 16, 2020, 07:28:26 PM »

Mark the condition as surveyed.
Code: java
	MarketAPI tigraCity = getMarket("tigra_city");
tigraCity.addCondition(Conditions.ORE_MODERATE);
tigraCity.getCondition(Conditions.ORE_MODERATE).setSurveyed(true);
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6310 on: April 16, 2020, 07:34:54 PM »

Try calling MarketAPI.reapplyConditions()

I tried this. No luck.

Mark the condition as surveyed.
Code: java
	MarketAPI tigraCity = getMarket("tigra_city");
tigraCity.addCondition(Conditions.ORE_MODERATE);
tigraCity.getCondition(Conditions.ORE_MODERATE).setSurveyed(true);

Didn't try this. Trying it now. Probably combined with the above advice just to be sure.

Thanks for the help both of you!

*EDIT* It works, thanks!
« Last Edit: April 17, 2020, 02:49:07 AM by Morrokain »
Logged

pignaut

  • Ensign
  • *
  • Posts: 1
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6311 on: April 17, 2020, 06:34:48 AM »

Hello all.
I'm having some trouble getting my mod to work/compile properly.

I've followed this tutorial ( https://fractalsoftworks.com/forum/index.php?topic=10057.0 ), and used Sundog's Fuel Siphoning mod ( https://fractalsoftworks.com/forum/index.php?topic=15272.0 ) as a reference.

Whenever I try and play Starsector, with my mod loaded, it crashes when the loading bar reaches its end.

I'm using intelliJ IDEA 15.0.6, my JDK is "jdk1.7.0_80".

Under File->Settings<Build, Execution, Deployment->Compiler->Java Compiler, the Project Bytecode is set to 1.7.

Under File->Project Structure->Project, the Project SDK is set to 1.7.

When attempting to make my Jar file*, I am unable to select my class as the Main Class
(Selecting it and clicking OK pops us a message saying "*class-name* is not acceptable")

To get around that, I left the Main Class field of the Create JAR from Modules window empty. From that I do get a JAR file (which contains my actual JAR file, and the Starsector api files). What I've been doing is extracting this with 7zip, then using the JAR file in that.

When I launch Starsector, I am able to see my mod in the mod-list and can enable it.

The error message that appear is:
Quote
Fatal: Error compiling
[supplies_from_planets.campaign.abilities.SuppliesFromPlanets]
cause: supplies_from_planets.campaign.abilities.SuppliesFromPlanets
Chack starsector.log for more info

And the log file has this:
Quote
4086 [Thread-4] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.RuntimeException: Error compiling [supplies_from_planets.campaign.abilities.SuppliesFromPlanets]
java.lang.RuntimeException: Error compiling [supplies_from_planets.campaign.abilities.SuppliesFromPlanets]
   at com.fs.starfarer.loading.scripts.ScriptStore$3.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: supplies_from_planets.campaign.abilities.SuppliesFromPlanets
   at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:179)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)


I don't know what I'm doing wrong, but I'm guessing I've set up my IDE wrong? Or I've forgotten to do something? I don't know.


*File->Project Structure->Artifacts->+->Create JAR from Modules
Logged

tomatopaste

  • Captain
  • ****
  • Posts: 306
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6312 on: April 17, 2020, 08:49:05 PM »

Hello, a follow-up to the hyperspace system hiding:
The script
Code
    
@Override
    public void onNewGameAfterProcGen() {
        for (SectorEntityToken token : Global.getSector().getHyperspace().getAllEntities()) {
            token.setDiscoverable(true);
            token.setSensorProfile(2000f);
        }
    }
successfully hides all systems as can be seen in this screenshot.

Spoiler
[close]

The only problem is, when coming across a system in hyperspace, it returns null for the discovery process, and is only visible on map when the player is within sensor range, and disappears otherwise. How would I go about permanently having systems appear on map?

Spoiler
[close]

Thanks!
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6313 on: April 17, 2020, 09:04:35 PM »

Hmm. I suspect CoreDiscoverEntityPlugin isn't handling a JumpPointAPI being "discovered" well. Although, hm, looking at the code for that, I'm not sure why it wouldn't stay discovered - it should setDiscoverable(null) and setSensorProfile(null) in all cases.

The solution for the "Discovered: null" thing would be to provide your own implementation of this, though - basically copy CoreDiscoverEntityPlugin, register your implementation via something like:
if (!plugins.hasPlugin(YourDiscoverEntityPlugin.class)) {
   plugins.addPlugin(new YourDiscoverEntityPlugin(), true);
}

In an appropriate ModPlugin method.

And make sure its getHandlingPriority() method returns... probably GenericPluginManagerAPI.MOD_SPECIFIC, if the parameter is a hyperspace anchor.

Not sure about it not staying discovered, though, that doesn't make sense to me.

Edit: ah, it looks like only nascent jump-points (which your code is also making discoverable) are being "discovered", the jump-points aren't. Aha... hmm. Some old code in play here, I don't want to wantonly tweak it, but basically jump-points can't be discoverable like that. So I'd say the best solution would be a custom script that mimics what CoreDiscoverEntityPlugin does but just checks when the player is near-enough an undiscovered star to "discover" it.
« Last Edit: April 17, 2020, 09:13:13 PM by Alex »
Logged

tomatopaste

  • Captain
  • ****
  • Posts: 306
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #6314 on: April 18, 2020, 03:05:10 AM »

Read and weep fellas 8) 8) 8)

Spoiler
[close]

Cheers Alex, your advice works perfectly  ;D. Mod idea and TC conversion validated!
Logged
Pages: 1 ... 419 420 [421] 422 423 ... 706