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: Anubis-class Cruiser (12/20/24)

Pages: 1 ... 724 725 [726] 727 728 ... 748

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

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24945
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10875 on: July 20, 2024, 12:32:38 PM »

Hmm.

This notionally works, but putting ships in storage changes their ID string

This is definitely not the case, at least in general - I just tested it and the fleet member id stays the same when the ship is put into storage. It's possible some other code might change fleet member id's, but vanilla doesn't, unless I'm really missing something.

- a WeakHashMap<FleetMemberAPI, data_object> stored in sector memory, which didn't work; fleet member objects appear to be created new when the game loads, which breaks the references.

WeakRefernce<FleetMemberAPI> definitely works - the SModRecord class uses it. You're right that new fleet member objects are created when the game is loaded, but if the WeakReference is in the set of objects being instantiated, its FleetMemberAPI will be that same newly-instantiated one, so it's not a problem.

I suspect WeakHashMap works too - the way it works is substantially similar - though I haven't tested it specifically.

So I'm not sure what's going on - clearly it's not working for you - but it may be worth another look since both of those approaches seem like they should/do work.
Logged

theDragn

  • Captain
  • ****
  • Posts: 334
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10876 on: July 23, 2024, 01:04:51 AM »

Hmm.

This notionally works, but putting ships in storage changes their ID string

This is definitely not the case, at least in general - I just tested it and the fleet member id stays the same when the ship is put into storage. It's possible some other code might change fleet member id's, but vanilla doesn't, unless I'm really missing something.


I'll admit I didn't check to see if getID() was returning the same value or not— and of course I'm inclined to believe you over code that I wrote at 3am. I was just mapping ID to a data object, and then before save checking every fleet/storage in the game for ships and only retaining the map entries that had corresponding IDs present. Worked fine for ships in fleets, but not ones in storage. Maybe I was accessing hull storage incorrectly? Definitely didn't double check it.

Quote
WeakRefernce<FleetMemberAPI> definitely works - the SModRecord class uses it. You're right that new fleet member objects are created when the game is loaded, but if the WeakReference is in the set of objects being instantiated, its FleetMemberAPI will be that same newly-instantiated one, so it's not a problem.

I suspect WeakHashMap works too - the way it works is substantially similar - though I haven't tested it specifically.

So I'm not sure what's going on - clearly it's not working for you - but it may be worth another look since both of those approaches seem like they should/do work.

I tested WeakHashMap a little more thoroughly than the ID->data map since it was my first idea and I wanted it to work so much, but I just couldn't get any data in it to persist through loading the save. (I did check that it was serializing out the entries into the save.) I wonder if sector memory gets loaded before fleet members, and that breaks the reference long enough for it to get garbage collected? Also entirely possible I wrote it wrong somehow- difficult to check at this point anyway.

Regardless, I've got a system working at this point- I stringify my data object and store it in the variant tags, and do some screwing around with the variant to ensure it's unique to the ship and that the tag change actually sticks. Not the best system in the world, but if it works for now...

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24945
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10877 on: July 23, 2024, 08:51:02 AM »

Maybe I was accessing hull storage incorrectly? Definitely didn't double check it.

Possibly? I think that's a difficult way to go for this anyway because it's hard (or rather, impossible) to find all possible storage - when one includes the possibility of a mod creating some arbitrary form of it.

I tested WeakHashMap a little more thoroughly than the ID->data map since it was my first idea and I wanted it to work so much, but I just couldn't get any data in it to persist through loading the save. (I did check that it was serializing out the entries into the save.) I wonder if sector memory gets loaded before fleet members, and that breaks the reference long enough for it to get garbage collected? Also entirely possible I wrote it wrong somehow- difficult to check at this point anyway.

Ah, an idea comes to mind - I've seen xstream use the wrong class for a map before if you don't specify the right class in the declaration. For example:
public Map<String,String> map = new LinkedHashMap<>()

If you save and then load, map would end up being a regular HashMap, because there's not enough info in the savefile to tell it was a LinkedHashMap originally. But if you declare it as:
public LinkedHashMap<String,String> map

Then it would deserialize it properly. I wonder if something similar might not be going on for WeakHashMap.

Regardless, I've got a system working at this point- I stringify my data object and store it in the variant tags, and do some screwing around with the variant to ensure it's unique to the ship and that the tag change actually sticks. Not the best system in the world, but if it works for now...

Yeah, in all honesty, that sounds like the best way to go - it's just simpler. I almost did something very similar the other day :)
Logged

Princess of Evil

  • Admiral
  • *****
  • Posts: 792
  • Balance is not an endpoint, but a direction.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10878 on: July 23, 2024, 09:10:37 AM »

Janino compiles to like Java 6, yeah. No generics, no -> notation stuff, and a couple other limitations.
Logged
Proof that you don't need to know any languages to translate, you just need to care.

Killer of Fate

  • Admiral
  • *****
  • Posts: 1832
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10879 on: July 24, 2024, 02:32:41 AM »

trying to make it so that high_gravity is a random chance for gas giants... For some reason it worked in the past. But now it doesn't.

Spoiler
[close]

nvm, I should try using "replace" in the mod.json file mechanic... Might fix it.
Nope, still doesn't work.
« Last Edit: July 24, 2024, 02:39:08 AM by Killer of Fate »
Logged

PigeonPun

  • Ensign
  • *
  • Posts: 22
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10880 on: July 24, 2024, 05:05:13 PM »

Currently working on a bionic mod and runs into a issue, the structure it self regenerate the defender fleet on each interaction.

Here is my structure spawning code. The code will run after the save has been loaded in for save compatibility.
Code
SectorEntityToken station = targetLocation.getStarSystem().addCustomEntity(
      "ba_bionic_research_station_",
      "Bionic Research Station", "ba_station_overclock",
      Factions.DERELICT
);
station.setCircularOrbit(selectedPlanet, orbitAngle,  selectedPlanet.getRadius() + 180f, selectedPlanet.getCircularOrbitPeriod());
station.setDiscoverable(true);
station.setSensorProfile(1f);
the structure JSON:
Spoiler
Code
{
"ba_station_overclock":{
"defaultName":"Bionic Research Station", # used if name=null in addCustomEntity()
"defaultRadius":40, # used if radius<0 in addCustomEntity()
"customDescriptionId":"orbital_station_default",
"interactionImage":"graphics/illustrations/orbital.jpg",
"icon":"graphics/icons/station0.png",
"iconWidth":24,
"iconHeight":24,
"sprite":"graphics/stations/ba_overclock_station.png",
"spriteWidth":64,
"spriteHeight":64,
"renderShadow":true,
"useLightColor":true,
"showInCampaign":true,
"showIconOnMap":true,
"showNameOnMap":false,
"scaleNameWithZoom":false,
"scaleIconWithZoom":true,
"tags":["salvageable", "has_interaction_dialog", "neutrino", "ba_overclock_station"],
"layers":[STATIONS], # what layer(s) to render in. See CampaignEngineLayers.java for possible values
}
}
[close]
How i set it up in salvage_entity_gen_data.csv

rules.csv

Here is the gif which display the fleet regenerating happening, extremely weird since i interacted with domain prob on the same save with no problem with any fleet regenerating after each interaction. Tried using console to change FORCE_REGEN_AUTOMATED_DEFENSES memflag to flase but didn't have any effect on the fleet regenerating.
Code
runcode com.fs.starfarer.api.impl.campaign.DebugFlags.FORCE_REGEN_AUTOMATED_DEFENSES = false

Looking at the memory dump on each interaction, the $defenderFleet is different for each interaction.
I honestly have no clue how this is happening since i copied how coronal shunt work in rules.csv
« Last Edit: July 24, 2024, 05:06:51 PM by PigeonPun »
Logged
Working on: Project Solace + Bionic Alteration

NikoTheGuyDude

  • Captain
  • ****
  • Posts: 427
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10881 on: July 24, 2024, 08:04:06 PM »

I want to create a star system that is hidden from the map, but has a star, and thus, a star jump point. This star jump point is not essential if its what it takes.

I want to put this star system in the abyss and force the player to either discover it on their own, via blind navigation, or use a wormhole to get to it/follow a pre-defined questline to find it.

What's the best way to do this? Someone suggested deleting the hyperspace anchor, but that feels like its entering undefined behavior territory.

Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24945
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10882 on: July 25, 2024, 10:04:37 AM »

Currently working on a bionic mod and runs into a issue, the structure it self regenerate the defender fleet on each interaction.

Does your entity have a $salvageSeed set? If not, it might end up generating a random one every time which would explain the defenses not being consistent. They're not actually saved after being generated - unless they have taken damage - they're just regenerated using the same seed.

FORCE_REGEN_AUTOMATED_DEFENSES wouldn't affect this, I don't think - IIRC it forces them to be regenerated if they've taken damage, but in this case - if they haven't - they'd regen anyway.

You want $salvageSeed to be set to a random long value.


I want to create a star system that is hidden from the map, but has a star, and thus, a star jump point. This star jump point is not essential if its what it takes.

I want to put this star system in the abyss and force the player to either discover it on their own, via blind navigation, or use a wormhole to get to it/follow a pre-defined questline to find it.

What's the best way to do this? Someone suggested deleting the hyperspace anchor, but that feels like its entering undefined behavior territory.

Hmm - take a look at AbyssalRogueStellarObjectEPEC. One of the things it generates is a black hole "system" in the abyss, and that seems close to what you're looking for.
Logged

PigeonPun

  • Ensign
  • *
  • Posts: 22
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10883 on: July 25, 2024, 11:53:01 AM »

Currently working on a bionic mod and runs into a issue, the structure it self regenerate the defender fleet on each interaction.

Does your entity have a $salvageSeed set? If not, it might end up generating a random one every time which would explain the defenses not being consistent. They're not actually saved after being generated - unless they have taken damage - they're just regenerated using the same seed.

FORCE_REGEN_AUTOMATED_DEFENSES wouldn't affect this, I don't think - IIRC it forces them to be regenerated if they've taken damage, but in this case - if they haven't - they'd regen anyway.

You want $salvageSeed to be set to a random long value.

Yep, after adding $salvageSeed, it works perfectly now!
Logged
Working on: Project Solace + Bionic Alteration

NikoTheGuyDude

  • Captain
  • ****
  • Posts: 427
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10884 on: July 25, 2024, 12:52:26 PM »


I want to create a star system that is hidden from the map, but has a star, and thus, a star jump point. This star jump point is not essential if its what it takes.

I want to put this star system in the abyss and force the player to either discover it on their own, via blind navigation, or use a wormhole to get to it/follow a pre-defined questline to find it.

What's the best way to do this? Someone suggested deleting the hyperspace anchor, but that feels like its entering undefined behavior territory.

Hmm - take a look at AbyssalRogueStellarObjectEPEC. One of the things it generates is a black hole "system" in the abyss, and that seems close to what you're looking for.

Works perfectly, thanks! For those inclined to follow in my footsteps, the important part seems to be adding STAR_HIDDEN_ON_MAP to the star jumppoint, as well as calling AbyssalRogueStellarObjectEPEC.setAbyssalDetectedRange(jumpPoint, range) on each jumppoint.
Logged

NikoTheGuyDude

  • Captain
  • ****
  • Posts: 427
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10885 on: July 25, 2024, 09:15:00 PM »

Is there any way to prevent a specific ship/fleet from dropping weapons?
Logged

NikoTheGuyDude

  • Captain
  • ****
  • Posts: 427
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10886 on: July 25, 2024, 09:40:12 PM »

Is there any way to prevent a specific ship/fleet from dropping weapons?

Including debris fields generated from a battle. So far, I've found reportEncounterLootGenerated, but that only covers the immediate post-battle salvage.
Logged

NikoTheGuyDude

  • Captain
  • ****
  • Posts: 427
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10887 on: July 25, 2024, 09:51:22 PM »

And on that note, how do you edit what a debris field might contain once salvaged?

EDIT: Figured it out! entity.dropRandom[0]?.custom?.items (kotlin code)
« Last Edit: July 25, 2024, 10:03:26 PM by NikoTheGuyDude »
Logged

theDragn

  • Captain
  • ****
  • Posts: 334
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10888 on: July 25, 2024, 10:47:50 PM »

Is there some way to spawn a duplicate of a projectile with only the projectile spec? Obviously we can use projectile.getWeapon().getId() to grab the weapon ID, and then engine.spawnProjectile(), but this runs into issues with any missile with submunitions, or modded weapons that use projectile swaps (certain shotgun weapons with delayed splits, other heavily-scripted things). In those contexts, there's no way to get the weapon ID that fired the actual sub-projectile, just the WeaponAPI that it belongs to. While there's an overload for spawnProjectile to use a projectile spec ID, it's marked as "doesn't work" in the API, and indeed does not work.

Kaysaar

  • Admiral
  • *****
  • Posts: 536
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #10889 on: July 26, 2024, 01:22:02 AM »

How ordance points for wings is calcualted ?
I tried to retireve ordaance points in such way but it is always 0
Code
        text1 = (int)wing.getVariant().getHullSpec().getOrdnancePoints(null)+"";
Logged
Pages: 1 ... 724 725 [726] 727 728 ... 748