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 ... 279 280 [281] 282 283 ... 706

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

MajorTheRed

  • Captain
  • ****
  • Posts: 288
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4200 on: January 12, 2019, 03:16:09 PM »

It's was indeed a barrel location problem... I would never have been able to figure it out. Thank you for your help and your quick answer (especially during week end!)
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3784
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4201 on: January 13, 2019, 08:50:25 AM »

So, I've been working on a minimod that changes what the Planetary Shield does.

My first implementation, I made a new data.scripts.PlanetaryShield, and changed industries.csv to refer to the new class.

This... technically worked, but ran into some problems, because it turns out that the save file, in several places, refers to industries by their class name rather than their id.  Specifically, any planetary shield generators that were built or under construction when you enabled the mod would retain the old behavior, and, if you wanted to disable the mod, you had to scrap all of the new shield generators... and then wait two months or the save would crash on load because their class was being stored in the monthly planetary expenses report.

This seems like it's a bug, but it's a fairly esoteric one, and who knows, maybe there's some actual reason why it's important to store the class name.

So, try number two: see if I could overwrite com.fs.starfarer.api.impl.campaign.econ.impl.PlanetaryShield - even using a built jar file, this doesn't work; starsector continues to use its own copy of the PlanetaryShield class rather than the new one.

Before I move on to try number three, where I build code that will, on mod-add, iterate through every market to remove and re-create any existing planetary shields, I have to ask: Can anyone come up with a better way of doing this?  Because that won't solve the on-mod-remove issues, and I'd really like for this to be a straightforward add mod, get new behavior, remove mod, get old behavior, sort of thing, without any gotchas going in either direction.
« Last Edit: January 13, 2019, 08:56:04 AM by Wyvern »
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4202 on: January 13, 2019, 10:48:06 AM »

It's not so much that it's referring to it by class name, but that it needs to store data for each industry (construction state, AI cores, etc), which means the object for each industry gets written out to the savefile. The data an object has is class-dependent, hence the class being specified there.

Getting a mod that changes industry classes to be save-compatible in both directions is going to be a lot of trouble. I'm not sure it's possible, actually. Depending on what you want to do, it *may* be possible to add a transient script instead that implements EconomyUpdateListener and do your work in economyUpdated(), basically overriding whatever the default PlanetaryShield class does.

This wouldn't work if it changed supply/demand (since that would happen too late to be considered by the economy), but should for example work if you were changing something like the shield visuals or defensive stats.

So, try number two: see if I could overwrite com.fs.starfarer.api.impl.campaign.econ.impl.PlanetaryShield - even using a built jar file, this doesn't work; starsector continues to use its own copy of the PlanetaryShield class rather than the new one.

Right, yeah - classes with the same package plus name generally isn't a good idea, since it depends on the order of the jar files in the classpath, and I'm not sure how it interacts with the custom classloader used for scripts. Even if it worked, it'd be the sort of thing you really wouldn't want to rely on as it might be inconsistent.
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3784
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4203 on: January 13, 2019, 11:21:19 AM »

Getting a mod that changes industry classes to be save-compatible in both directions is going to be a lot of trouble. I'm not sure it's possible, actually. Depending on what you want to do, it *may* be possible to add a transient script instead that implements EconomyUpdateListener and do your work in economyUpdated(), basically overriding whatever the default PlanetaryShield class does.

This wouldn't work if it changed supply/demand (since that would happen too late to be considered by the economy), but should for example work if you were changing something like the shield visuals or defensive stats.
While I'm not directly changing the supply/demand of the shield generator, I am adding a population growth penalty, accessibility penalty, and pather interest changes, so this doesn't sound like it'd work for me.

So, try number two: see if I could overwrite com.fs.starfarer.api.impl.campaign.econ.impl.PlanetaryShield - even using a built jar file, this doesn't work; starsector continues to use its own copy of the PlanetaryShield class rather than the new one.

Right, yeah - classes with the same package plus name generally isn't a good idea, since it depends on the order of the jar files in the classpath, and I'm not sure how it interacts with the custom classloader used for scripts. Even if it worked, it'd be the sort of thing you really wouldn't want to rely on as it might be inconsistent.
I was hoping that Starsector's classloader would have a set order & put mods first.  It seemed worth trying.

Sounds like providing special code for on-mod-install is the best option, then.  Unless... hm... maybe I can do something with beforeGameSave and afterGameSave?  Swapping things around every save would be -ridiculous-, but it might also work.  Maybe.  If I can get at the internals of those monthly reports.
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4204 on: January 13, 2019, 02:17:35 PM »

While I'm not directly changing the supply/demand of the shield generator, I am adding a population growth penalty, accessibility penalty, and pather interest changes, so this doesn't sound like it'd work for me.

For accessibility, you could use a hidden market condition, since that'd apply at the right time. For population growth, you could do market.addTransientImmigrationModifier(MarketImmigrationModifier mod) - that doesn't have to come from an industry, it could just be a separate class.

For Pather interest, you'd be sol - that does have to come from industry.

Sounds like providing special code for on-mod-install is the best option, then.  Unless... hm... maybe I can do something with beforeGameSave and afterGameSave?  Swapping things around every save would be -ridiculous-, but it might also work.  Maybe.  If I can get at the internals of those monthly reports.

For adding it, sure, yeah.

For removing it, there's no way to really do it safely. The monthly report is just one of many possible places that could be hanging on to an industry reference - it could be a piece of intel, some other script, etc. You'd have to account for every possible piece of code that might do that, both in vanilla and in mods, and - while that's already highly impractical - some might also be impossible to modify on the fly like that.

Removing a piece of content like that is basically a no-go in general, just too many things could be referring to it. Adding one to an existing game is much more doable, though.
Logged

From a Faster Time

  • Commander
  • ***
  • Posts: 146
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4205 on: January 15, 2019, 05:09:47 AM »

I made a music mod for the game. The issue I have is that every time my fleet flys near a system, the in system music starts to play, constantly switching tracks from the hyperspace music.
Is there a way to make it so that in star system music plays only when you are actually inside the star system?
Logged

Originem

  • Purple Principle
  • Captain
  • ****
  • Posts: 430
  • Dancing like a boss.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4206 on: January 15, 2019, 06:50:42 PM »

What's the best method to modify fleet's MutableFleetStatsAPI in a hullmod?
I am thinking about 2 ways:
onFleetSync in HullModFleetEffect
check fleet each frame in EveryFrameEffect
Which is better?
Logged
My mods


Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4207 on: January 15, 2019, 07:29:17 PM »

Is there a way to make it so that in star system music plays only when you are actually inside the star system?

Nothing simple, iirc you'd have to basically take over music playing with custom code entirely.


What's the best method to modify fleet's MutableFleetStatsAPI in a hullmod?
I am thinking about 2 ways:
onFleetSync in HullModFleetEffect
check fleet each frame in EveryFrameEffect
Which is better?

And EveryFrameScript attached to the fleet may be better for performance; you'd just have to be careful how you do it.

Could also do it in HullModEffect.advanceInCampaign() - per the javadoc, it'll be called with amount = 0 when the fleet is being re-synched.

Either way, it's something to be careful with as far as performance.
Logged

Originem

  • Purple Principle
  • Captain
  • ****
  • Posts: 430
  • Dancing like a boss.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4208 on: January 15, 2019, 08:09:46 PM »

Could also do it in HullModEffect.advanceInCampaign() - per the javadoc, it'll be called with amount = 0 when the fleet is being re-synched.
If I remove the hullmod, would advanceInCampaign() be called?
Logged
My mods


Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4209 on: January 15, 2019, 08:25:13 PM »

No, it would not.

There's basically not a great mechanism for doing this in the game. If there's any alternate design approach, I would recommend taking it instead, of perhaps restricting the impact of the hullmod to the player's fleet only, which should make it perform better.

Given when variant generation kicks in for AI fleets (i.e. when the player mouses over their fleet, or interacts with it), it probably doesn't make too much sense for hullmod effects to apply to AI fleets anyway, as it'd be inconsistent. For example, if the goal variant has it, but the autofit variant doesn't, or vice versa, then whether the fleet gets the effect or not would depend on the player mousing over it.
Logged

Originem

  • Purple Principle
  • Captain
  • ****
  • Posts: 430
  • Dancing like a boss.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4210 on: January 15, 2019, 09:57:41 PM »

There's basically not a great mechanism for doing this in the game. If there's any alternate design approach, I would recommend taking it instead, of perhaps restricting the impact of the hullmod to the player's fleet only, which should make it perform better.
well I do want to restrict the impact only to the player's fleet.
So i could do this: in an every frame script, I check the fleet members and their hullmods, if there are some, do something, else unmodify?
Logged
My mods


From a Faster Time

  • Commander
  • ***
  • Posts: 146
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4211 on: January 16, 2019, 06:15:15 AM »

Is there a way to make it so that in star system music plays only when you are actually inside the star system?
Nothing simple, iirc you'd have to basically take over music playing with custom code entirely.
Well fug. That's a bit more than I am willing to do.
Why is the system as it is right now, anyway?
I realize most people don't have custom music mods but it's rather annoying when I am flying by a star system on my way across the galaxy and the music fades away from the hyperspace track that's playing, into a in-star-system track for 3 seconds then fades back into the hyper space one. This happens repeatedly while passing star systems on my way to the destination. As you imagine it's some what annoying.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4212 on: January 16, 2019, 09:41:00 PM »

well I do want to restrict the impact only to the player's fleet.
So i could do this: in an every frame script, I check the fleet members and their hullmods, if there are some, do something, else unmodify?

Yeah, this makes sense.

Why is the system as it is right now, anyway?
I realize most people don't have custom music mods but it's rather annoying when I am flying by a star system on my way across the galaxy and the music fades away from the hyperspace track that's playing, into a in-star-system track for 3 seconds then fades back into the hyper space one. This happens repeatedly while passing star systems on my way to the destination. As you imagine it's some what annoying.

I'll probably take a look at this at some point if there's time; there are reasons but they may or may not hold up. A bit off-topic for this thread, though :)
Logged

Originem

  • Purple Principle
  • Captain
  • ****
  • Posts: 430
  • Dancing like a boss.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4213 on: January 20, 2019, 09:58:08 AM »

How to get damagetype by weaponspec?
Logged
My mods


Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4214 on: January 20, 2019, 10:01:34 AM »

How to get damagetype by weaponspec?

Oh, oops - the method wasn't in the API. Added DamageType getDamageType() to WeaponSpecAPI.
Logged
Pages: 1 ... 279 280 [281] 282 283 ... 706