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: Codex Overhaul (05/11/24)

Pages: 1 ... 551 552 [553] 554 555 ... 717

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

SafariJohn

  • Admiral
  • *****
  • Posts: 3033
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8280 on: December 21, 2021, 08:30:10 PM »

I am creating tokens and adding them to systems for fleets to travel to. Am I using them right? Do they automatically get cleaned up? Is this a memory leak?

The createToken() comment:
// Not actually added to the location, and doesn't need to be. Can be added via addEntity if it needs to have an orbit.

So if you're actually adding them to the system, you do need to also remove them, otherwise it would be (a quite minor) savefile/memory leak. But if you just want the fleet to go to a specific coordinate, you can create the token, NOT add it to the system, and just pass it in to the fleet's assignment - and when that's finished, all references to the token will be gone and it will get cleaned up.

Ah, right. I do need orbits, so I will have to handle cleanup. Didn't think about it because all my other usages are in system gen classes where there is no risk of memory leaks.
Logged

itBeABruhMoment

  • Commander
  • ***
  • Posts: 166
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8281 on: December 21, 2021, 09:36:31 PM »

I'm trying to make a console command that duplicates ships, and what I currently have is correctly copying everything except Smods. I've already tried simply cloning the variant and setting the boolean field of addPermaMod to false (which seemed to make it behave the exact same as it did as when it was set to true). Any idea what is wrong?

-snipped code-

There's an overload of createFleetMember that takes a ShipVariantAPI instead of a variantID string, and I'm wondering what's wrong with just using that? For example, this two liner worked to clone a ship for me, S-mods and all:

Code
FleetMemberAPI dup = Global.getFactory().createFleetMember(FleetMemberType.SHIP, fleetMember.getVariant().clone());
Global.getSector().getPlayerFleet().getFleetData().addFleetMember(dup);
Iirc some ships have temporary variant ids (notably the ships you start with), so it's a bit tricker to spawn ships using variant id strings, since you have to walk through the hull id to variant list map and actually find one that corresponds to the variant's hull id, but I've not encountered a situation where the actual ship's getVariant is temporary or otherwise unusable.

Edit: good call on the cloning, added that in.

Thanks, I've figured it out. Why I couldn't get this to work for fleet members created by createFleetMember(FleetMemberType.SHIP, hull_id) is beyond me. Here is the code for anyone's future reference
Code
final FleetDataAPI fleet = Global.getSector().getPlayerFleet().getFleetData();
clonedShip = Global.getFactory().createFleetMember(FleetMemberType.SHIP, cloneCandidate.getVariant().clone());
FleetEncounterContext.prepareShipForRecovery(clonedShip, true, true, true,1f, 1f, MathUtils.getRandom());
for(String smod : cloneCandidate.getVariant().getSMods())
{
    clonedShip.getVariant().addPermaMod(smod, true);
}
clonedShip.updateStats(); //seems to work fine without this function, but I saw this used in some code to add smods
fleet.addFleetMember(clonedShip);
note that this uses functions from LazyLib
>finished code
>decides to update to rc-6 because code was done
>use command when trying the new falcon
>copies nothing correctly but the smods
code bricks in rc-6, back to the drawing board
Logged

float

  • Captain
  • ****
  • Posts: 275
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8282 on: December 21, 2021, 09:44:32 PM »

>finished code
>decides to update to rc-6 because code was done
>use command when trying the new falcon
>copies nothing correctly but the smods
code bricks in rc-6, back to the drawing board

I tested those two lines on RC6 and they work fine. BTW, cloneCandidate.getVariant() already stores information about its own S-mods, so there isn't any need to transfer them onto clonedShip's variant. It's different if you use variant ids from the global list map, since I think those are just the stock variants that don't have any custom hull mods on them at all. Do you have a stack trace?
Logged

itBeABruhMoment

  • Commander
  • ***
  • Posts: 166
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8283 on: December 21, 2021, 09:47:42 PM »

My bad I got my jars mixed up. NVM
Logged

SikeSky

  • Ensign
  • *
  • Posts: 3
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8284 on: December 22, 2021, 03:46:28 AM »

Hi, I'm trying to get some custom shields working. I'll try to be as clear as possible, but be warned that I am fairly wet-behind-the-ears when it comes to Java.

My goal is to have multiple small shields rotating around the ship with stats and behavior separate from the default shield. They will power up whenever the main shield is activated and power down when it's turned off. I want a lot on every ship I'm adding, so I'd prefer not to use modules to jury rig it.

Since ShieldAPI is an abstract class it's impossible to instantiate any new ShieldAPIs, so instead I started to implement it as a new class. Somebody quickly pointed out that since I had no idea how ShieldAPI was implemented in vanilla I would likely not be able to create a new, working implementation. Unfortunately neither of us could find where ShieldAPI was implemented in the game files - they searched through the obf.jar file which I was unfamiliar with but turned up nothing.

So I guess my question(s) are first, where can I find that implementation for reference, and second, is there anything else I should know/consider when it comes to creating custom shields?
Logged

float

  • Captain
  • ****
  • Posts: 275
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8285 on: December 22, 2021, 03:03:47 PM »

Hi, I'm trying to get some custom shields working. I'll try to be as clear as possible, but be warned that I am fairly wet-behind-the-ears when it comes to Java.

My goal is to have multiple small shields rotating around the ship with stats and behavior separate from the default shield. They will power up whenever the main shield is activated and power down when it's turned off. I want a lot on every ship I'm adding, so I'd prefer not to use modules to jury rig it.

Since ShieldAPI is an abstract class it's impossible to instantiate any new ShieldAPIs, so instead I started to implement it as a new class. Somebody quickly pointed out that since I had no idea how ShieldAPI was implemented in vanilla I would likely not be able to create a new, working implementation. Unfortunately neither of us could find where ShieldAPI was implemented in the game files - they searched through the obf.jar file which I was unfamiliar with but turned up nothing.

So I guess my question(s) are first, where can I find that implementation for reference, and second, is there anything else I should know/consider when it comes to creating custom shields?

Keep in mind that even if you were able to create your own implementation of ShieldAPI, there isn't really any way to attach it to your ship. See ShipAPI for example -- the setShield method doesn't allow you to pass in an arbitrary ShieldAPI; it instead tells you to pass in the shield type, upkeep, efficiency, and arc, and it's very likely that the game is generating its own implementation behind the scenes.

Off the top of my head I can think of two examples that sort of do the functionality you're asking for. The first is the Exemplar-class from Vayra's ship pack (I think), which has a ship system that spawns six drones, each with its own shield, and the drones rotate around the ship. The second is to use modules with their own shield to simulate the ship having multiple shields, but I'm not sure how you'd get them to rotate around the ship. never mind, you've already thought of this
« Last Edit: December 22, 2021, 03:05:29 PM by this_is_a_username »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24326
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8286 on: December 22, 2021, 04:55:54 PM »

Yeah, a custom implementation of ShieldAPI is extremely unlikely to work - under the hood, the game is likely to be assuming it's the actual vanilla implementing class in any number of places. Generally in Starsector code, if something ends in "API", it means its exposing some functionality from core code, but not something that can be replaced, while if something ends in "Plugin", then that *is* meant to be replaceable by an alternate implementation.

I think extra modules is the only real viable way I see here for what you want.
Logged

SikeSky

  • Ensign
  • *
  • Posts: 3
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8287 on: December 22, 2021, 05:29:06 PM »

Yeah, a custom implementation of ShieldAPI is extremely unlikely to work - under the hood, the game is likely to be assuming it's the actual vanilla implementing class in any number of places. Generally in Starsector code, if something ends in "API", it means its exposing some functionality from core code, but not something that can be replaced, while if something ends in "Plugin", then that *is* meant to be replaceable by an alternate implementation.

I think extra modules is the only real viable way I see here for what you want.

I see, thank you. I'm not sure how hard it would be to open that up to custom implementation, but I think being able to create custom shields and shield geometry etc. would open up all kinds of interesting possibilities for modders. It sounds like it's a little more in-depth than a simple API addition, but would the API request thread be an appropriate place to make the suggestion, if at all?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24326
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8288 on: December 22, 2021, 05:42:47 PM »

The API requests thread is mainly for "this is present in core code but there's no way to get to it", with a little leeway.

What you're talking about here is a major re-engineering effort :) So perhaps that wouldn't be the place for it, but, I mean, consider the suggestion made! Odds of it actually being implemented are extremely not good, though, due to the sheer amount of work (and time) it would require. Never mind that something this complicated without a vanilla use case would also be near-impossible to adequately test and not break going forward.

Sorry to shoot the idea down! It's just, well, not very practical on the backend.
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 #8289 on: December 23, 2021, 06:37:48 AM »

So while troubleshooting this thread to ensure I am not also doing something to cause this crash (since my mod was present on the list of a few of these reports) I get to this line in BattleAutoresolverPluginImpl.java:

Code
490			member.getStatus().applyHullFractionDamage(damage, i);

This relies upon dealing damage to individual fighters in a wing according to the comments? Even though its looking for modules in this case? So, if I am understanding this correctly (though I doubt I am considering how obscure the code is in this particular section is and I suspect its been reused from its original use case) something is going on with:

Code
463				String slotId = member.getVariant().getModuleSlots().get(i - 1);
464 variant = variant.getModuleVariant(slotId);

 - which is causing an array out of bounds when trying to apply the calculate damage based upon the index being passed in. The weird thing is that "i" isn't supposed to be able exceed the number of "statuses" though what this actually means is unclear to me considering the notes seem to indicate it can be the number of wing members in a fighter wing or the number of modules on a ship depending upon a context that isn't really defined:
Code
458		float num = member.getStatus().getNumStatuses();
459 boolean someActiveRemaining = false;
460 for (int i = 0; i < num; i++) {

But! Based upon this line:

Code
455		if (member.isFighterWing()) return;

 - my guess is the context is whether the FleetMemberAPI is a fighter wing or a ship. And in this case its looking for ships only to check for modules.

Histidine thinks this may be due to improperly defined modules in the mod, but I was wondering if there was any additional insight from the backend side of things. Cross referencing vanilla code seems to indicate everything is defined properly - unless I am missing something but it isn't obvious to me anyway.

Thanks for any additional help in advance! Hopefully I can track this thing down as I think it has happened in other mods too and just having the information out there would likely prove useful to modders in general if they are making stations or moduled ships.

I've cross reference over half of my station files and nothing seems out of the ordinary compared to the vanilla implementation.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24326
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8290 on: December 23, 2021, 08:29:45 AM »

Yeah, this isn't used for fighters anymore, that's from way back when they were full-fledged fleet members and not installed on carriers. (Unless a mod somewhere out there still does this? It might work.)

So, it's used for ships with modules and stations. The status with index 0 is the main body; the rest are the modules, in the order they're defined in the variant, iirc. The absolute key thing - and I think possibly where the problem might come from? Is that the number of modules (and perhaps type, not 100% on that offhand) *can not* change from when the fleet member is originally created, since the status array is created then, too. If, for example, you dynamically add an extra module with code, stuff will crash in this way because the new module will push the number of modules higher than the size of the status array.
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 #8291 on: December 23, 2021, 09:13:50 AM »

Yeah, this isn't used for fighters anymore, that's from way back when they were full-fledged fleet members and not installed on carriers. (Unless a mod somewhere out there still does this? It might work.)

So, it's used for ships with modules and stations. The status with index 0 is the main body; the rest are the modules, in the order they're defined in the variant, iirc. The absolute key thing - and I think possibly where the problem might come from? Is that the number of modules (and perhaps type, not 100% on that offhand) *can not* change from when the fleet member is originally created, since the status array is created then, too. If, for example, you dynamically add an extra module with code, stuff will crash in this way because the new module will push the number of modules higher than the size of the status array.

I really appreciate the insight. Nothing I do does this afaik. At least assuming "dynamically" means in the combat layer.

Other than that? I cannot say.

*EDIT* In other words, I don't add any modules dynamically. At least, if I add any additional ones it is through variant files which reference different ship files with updated module slots and so that should be irrelevant, etc. The only thing that might be different in this case is the hullmods which also add fighter bays. I doubt that this is the cause of the error though considering that the use case has changed completely.
« Last Edit: December 23, 2021, 09:22:47 AM by Morrokain »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24326
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8292 on: December 23, 2021, 09:17:48 AM »

By dynamically I mean in the campaign layer. Like, the "bad" sequence of steps would be something like:

1) Add a ship-with-modules/station fleet member to a fleet
2) Use member.getVariant().setModuleVariant() to add a module to it, into a module slot that the original fleet member's variant had empty
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 #8293 on: December 23, 2021, 09:30:49 AM »

By dynamically I mean in the campaign layer. Like, the "bad" sequence of steps would be something like:

1) Add a ship-with-modules/station fleet member to a fleet
2) Use member.getVariant().setModuleVariant() to add a module to it, into a module slot that the original fleet member's variant had empty

Ah ok thanks for clarifying! I don't do this specifically, but it's good to know that it's not a good idea either way. Well, then I can only assume its nothing related to my implementation from what I can gather.

If anyone has additional input let me know, but I am considering this bug "solved" until then.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24326
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8294 on: December 23, 2021, 09:41:03 AM »

Now that I think about it, one time this came up recently, iirc, was when someone had a problem with one of the .variant files... trying to remember what it was (or who it was, so I can look it up) but having a hard time remembering. But it was something like one of the variants having a different number of modules than the rest, though I'm not sure what the additional factor was that made this into a crash instead of being fine.

It could for example be something like: the ship is in a player-faction fleet, and has "goal" variants for autofit. In which case there's a chance that it'll try to fit with that variant as the "target" instead of the original variant of the fleet member. And if there's a mismatch in the number of modules, then that would cause a crash, without any dynamic modification of the variant - but simply because a stock variant, and a player-made goal variant (based on another stock variant) had a different number of modules, if that makes sense.
Logged
Pages: 1 ... 551 552 [553] 554 555 ... 717