Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 641 642 [643] 644 645 ... 710

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

Ontheheavens

  • Commander
  • ***
  • Posts: 137
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9630 on: February 22, 2023, 09:55:29 AM »

Having some issues with my mod and thought it might be of some interest.
Spoiler
70396 [Thread-3] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.ClassCastException: com.fs.starfarer.campaign.BaseLocation$LocationToken cannot be cast to com.fs.starfarer.campaign.BaseCampaignEntity
java.lang.ClassCastException: com.fs.starfarer.campaign.BaseLocation$LocationToken cannot be cast to com.fs.starfarer.campaign.BaseCampaignEntity
   at com.fs.starfarer.campaign.BaseLocation.getEntityById(Unknown Source)
   at fleetjour.scripts.panel.Common.findTargetEntity(Common.kt:85)
[close]

What basically happens is that I fetch SectorEntityToken ID of the system's center through getCenter(); store this ID in field of my class, and then fetch SectorEntityToken by this ID through public SectorEntityToken getEntityById(String var1).

BUT. If the star system in question is a nebula, it has LocationToken as its center, while getEntityById method has this code:

Code
        if (this.idToEntity.containsKey(var1)) {
            BaseCampaignEntity var2 = (BaseCampaignEntity)this.idToEntity.get(var1);
            if (var2.getContainingLocation() != null && var2.getContainingLocation().getAllEntities().contains(var2)) {
                return var2;
            }
        }

And that is the source of my crash right there, since LocationToken doesn't cast to BaseCampaignEntity. The question is: is this a vanilla implementation shortcoming or am I simply doing it wrong? I'm able to get rid of the crash by retrieving star of the system instead of its center, so it's nothing major - just putting this out there.
Logged
   

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9631 on: February 22, 2023, 12:44:09 PM »


What is the correct usage of CombatEngineAPI.spawnProjectile(ShipAPI ship, WeaponAPI weapon, String weaponId, String projSpecId, Vector2f point, float angle, Vector2f shipVelocity);?

Every time I have tried to use it, it crashes with a nullpointerexception in the constructor of either MovingRay or BallisticProjectile. For example calling this method with non-null variables, and with the strings "lightdualac" and "lightdualac_shot" will cause a crash. This makes it impossible to spawn projectiles that are indirectly spawned via MIRV missiles, e.g. the "sabot_warhead2" projectile. Can this be clarified please?

Hmm - it's used a bunch of times in the API for things like mines, some Omega weapons, etc. Also, data.scripts.plugins.TestCombatPlugin calls this to spray a bunch of lightmg shots, and I recall this working.

Yeah the problem is that there are two spawnProjectile methods defined, and TestCombatPlugin only uses the one that takes a weaponID (which works flawlessly). The problem is that the second overload that takes a weaponID and a projectileID is always crashing whenever i try to use it, and I can't get it to not crash with a lot of different input combinations.

Ah, thank you for clarifying! ... it looks like this method is fundamentally broken. It may have worked at some point in the past, but basically: the projectile spec is cloned and has some values set for it when it is modified to apply to a specific weapon. Different weapons can use the same projectile spec and have different stats such as max range, though this is mostly only done with missiles. So the spec this method tries to use is the "base" spec unmodified by any specific weapon's stats. Among the other things it's missing, it doesn't have a damage component specified, which causes the NPE.

I'm going to deprecate the method and add a note in the javadoc. As the code is right now, using a projecile spec not associated with a specific weapon doesn't make conceptual sense, it needs a weapon to draw a bunch of its stats from.

is it possible to change the time for how long the hit glow stays on the beam end point after beam is no longer hitting anything ?

is it possible to change how long the takeoff/landing animation plays for a given fighter, or all fighters in wing? and get the current progress of said animation?

I don't think so, on any of the counts - sorry! You could perhaps try using ship.getAlphaMult() as a rough proxy for the progress of the landing animation.


Can I get a FleetEncounterContextPlugin with populated DataForEncounterSide? Currently it seems that only CampaignEventListener#reportEncounterLootGenerated provides such a structure to mod-reachable code, but that one always has empty #disabledInLastEngagement, #destroyedInLastEngagement members, even if spawned from an ending battle where I observed ships being disabled/destroyed.

I kind of expect to get one from CampaignEventListener#reportBattleFinished but cannot find a way.

... Going to put that into the API requests thread, if not, but wanted to ask here first in case I am just blind.

The vanilla implementation of this - FleetEncounterContext - gets this data populated, let me see. Ah - this happens in FleetInteractionDialogPluginImpl.backFromEngagement(). That plugin calls:
context.processEngagementResults(result);

With "result" being the data passed in to backFromEngagement() which has this info.


What basically happens is that I fetch SectorEntityToken ID of the system's center through getCenter(); store this ID in field of my class, and then fetch SectorEntityToken by this ID through public SectorEntityToken getEntityById(String var1).

BUT. If the star system in question is a nebula, it has LocationToken as its center, while getEntityById method has this code:

Code
        if (this.idToEntity.containsKey(var1)) {
            BaseCampaignEntity var2 = (BaseCampaignEntity)this.idToEntity.get(var1);
            if (var2.getContainingLocation() != null && var2.getContainingLocation().getAllEntities().contains(var2)) {
                return var2;
            }
        }

And that is the source of my crash right there, since LocationToken doesn't cast to BaseCampaignEntity. The question is: is this a vanilla implementation shortcoming or am I simply doing it wrong? I'm able to get rid of the crash by retrieving star of the system instead of its center, so it's nothing major - just putting this out there.

Thank you! This is a vanilla issue; fixed this up.
Logged

Zsar

  • Captain
  • ****
  • Posts: 279
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9632 on: February 22, 2023, 03:02:47 PM »

Can I get a FleetEncounterContextPlugin with populated DataForEncounterSide? Currently it seems that only CampaignEventListener#reportEncounterLootGenerated provides such a structure to mod-reachable code, but that one always has empty #disabledInLastEngagement, #destroyedInLastEngagement members, even if spawned from an ending battle where I observed ships being disabled/destroyed.

I kind of expect to get one from CampaignEventListener#reportBattleFinished but cannot find a way.

... Going to put that into the API requests thread, if not, but wanted to ask here first in case I am just blind.

The vanilla implementation of this - FleetEncounterContext - gets this data populated, let me see. Ah - this happens in FleetInteractionDialogPluginImpl.backFromEngagement(). That plugin calls:
context.processEngagementResults(result);

With "result" being the data passed in to backFromEngagement() which has this info.
Sorry, I formulated badly. This EngagementResultAPI is produced by #getResult of a specific instance of BattleAutoresolverPluginImpl only created in and for case AUTORESOLVE_PURSUE of method FleetInteractionDialogPluginImpl#optionSelected . It cannot possibly contain the results of other kinds of battle, even if the player is involved in them.

There is also no listener that will provide the moment in time, when it is save to read the resulting context, e.g. via reflection access to FleetInteractionDialogPluginImpl#context . Nor is it possible to extend FleetInteractionDialogPluginImpl, as its constructor is called explicitly instead of Factory or Singleton access. All callers are themselves plugins and it might be possible to replace some of them, but e.g. CoreCampaignPluginImpl probably can't be (or at least I find no methods that would allow doing that).

So, yes, technically I can obtain some populated DataForEncounterSide, but even for the player fleet I will only ever get it from a delegated pursuit, not from any other battle. AI vs AI battles are right out (surprisingly - I'd kind of expect the BattleAutoresolverPluginImpl to handle them as well... - so maybe/hopefully I am mistaken).

I should have asked whether I can get it reliably, without concern about the specific kind of engagement, commander of fleets involved or other "magic" environmental variables. Getting one only for player-delegated pursuits technically is "getting", yes - but also pretty useless.
Logged

bananana

  • Commander
  • ***
  • Posts: 228
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9633 on: February 22, 2023, 03:31:16 PM »

not sure if that's intended behavior or not
but does _under sprite of the weapon not respect render order?
i have a gun that only has an _under sprite specified for it
it goes into small built-in slot
changing renderOrderMod of that slot seems to have no effect whatsoever, it still renders below the deco weapon in the large slot
Logged
Any and ALL sprites i ever posted on this forum are FREE to use. even if i'm using them myself. Don't ever, EVER ask for permission, or i will come to your home and EAT YOUR DOG!!!
i do NOT want to see my name appear in the credits section of any published mod and will consider it a personal insult.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9634 on: February 22, 2023, 04:15:39 PM »

Sorry, I formulated badly. This EngagementResultAPI is produced by #getResult of a specific instance of BattleAutoresolverPluginImpl only created in and for case AUTORESOLVE_PURSUE of method FleetInteractionDialogPluginImpl#optionSelected . It cannot possibly contain the results of other kinds of battle, even if the player is involved in them.

There is also no listener that will provide the moment in time, when it is save to read the resulting context, e.g. via reflection access to FleetInteractionDialogPluginImpl#context . Nor is it possible to extend FleetInteractionDialogPluginImpl, as its constructor is called explicitly instead of Factory or Singleton access. All callers are themselves plugins and it might be possible to replace some of them, but e.g. CoreCampaignPluginImpl probably can't be (or at least I find no methods that would allow doing that).

So, yes, technically I can obtain some populated DataForEncounterSide, but even for the player fleet I will only ever get it from a delegated pursuit, not from any other battle. AI vs AI battles are right out (surprisingly - I'd kind of expect the BattleAutoresolverPluginImpl to handle them as well... - so maybe/hopefully I am mistaken).

I should have asked whether I can get it reliably, without concern about the specific kind of engagement, commander of fleets involved or other "magic" environmental variables. Getting one only for player-delegated pursuits technically is "getting", yes - but also pretty useless.

Ah, yeah, I see. There's no listener at that point so you're probably out of luck. And what the default BattleAutoresolverPluginImpl does as far as tracking this sort of info is also an implementation detail that you probably couldn't rely on too much, anyway.

It *is* possible to replace CoreCampaignPluginImpl - you'd need to SectorAPI.unregisterPlugin() and then provide your own implementation. More to the point, though, you don't *have* to do that, you can provide your own implementation that returns a different interaction dialog plugin with a higher priority. So e.g.

CoreCampaignPluginImpl has:
return new PluginPick<InteractionDialogPlugin>(new FleetInteractionDialogPluginImpl(), PickPriority.CORE_GENERAL);

And your plugin might have:
return new PluginPick<InteractionDialogPlugin>(new YourFleetInteractionDialogPluginImpl(), PickPriority.MOD_GENERAL);

Note that this is likely to be a bad idea since multiple mods doing this could be, and likely would be, incompatible with each other.

not sure if that's intended behavior or not
but does _under sprite of the weapon not respect render order?
i have a gun that only has an _under sprite specified for it
it goes into small built-in slot
changing renderOrderMod of that slot seems to have no effect whatsoever, it still renders below the deco weapon in the large slot

Intended behavior; it renders right over the ship sprite (well, and right over the d-hull overlay, if any). Your best would probably be to have an _under sprite for the deco weapon and finagle the slot order so it comes out right. ... this does point to a broader issue of weapons with _under sprites not working well with ships that have decorative weapons, though, doesn't it, hmm. I'll keep it in mind.
Logged

bananana

  • Commander
  • ***
  • Posts: 228
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9635 on: February 22, 2023, 04:42:50 PM »

not sure if that's intended behavior or not
but does _under sprite of the weapon not respect render order?
i have a gun that only has an _under sprite specified for it
it goes into small built-in slot
changing renderOrderMod of that slot seems to have no effect whatsoever, it still renders below the deco weapon in the large slot

Intended behavior; it renders right over the ship sprite (well, and right over the d-hull overlay, if any). Your best would probably be to have an _under sprite for the deco weapon and finagle the slot order so it comes out right. ... this does point to a broader issue of weapons with _under sprites not working well with ships that have decorative weapons, though, doesn't it, hmm. I'll keep it in mind.

maybe also consider adding RENDER_UNDER_ABOVE render hint, similar to RENDER_BARREL_BELOW, to force the _under sprite to render on top of everything else. this can have oh so many possibilities, pillbox-like weapons, just to name a few...
or an option to suspend base/barrel rotation?

speaking of sprites actually, can frame animation be applied to the  barrel sprite at all? or even, to the base and barrel sprite, as two different animations?
« Last Edit: February 22, 2023, 04:46:28 PM by bananana »
Logged
Any and ALL sprites i ever posted on this forum are FREE to use. even if i'm using them myself. Don't ever, EVER ask for permission, or i will come to your home and EAT YOUR DOG!!!
i do NOT want to see my name appear in the credits section of any published mod and will consider it a personal insult.

rogerbacon

  • Commander
  • ***
  • Posts: 151
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9636 on: February 24, 2023, 05:19:19 PM »

I want to make a shipSystem that has an active duration in seconds equal to the fleet points value of the ship it's installed on. How would I do that? Also, is each shipSystem a singleton that is shared by all ships that have that system?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9637 on: February 25, 2023, 10:40:05 AM »

speaking of sprites actually, can frame animation be applied to the  barrel sprite at all? or even, to the base and barrel sprite, as two different animations?

Hmm, I don't think so. It's assumed that the base animation handles an animated barrel, if that's a thing for the weapon.


I want to make a shipSystem that has an active duration in seconds equal to the fleet points value of the ship it's installed on. How would I do that?

You'd probably need to handle this in the system script, using ShipSystemAPI.deactivate() when appropriate.


Also, is each shipSystem a singleton that is shared by all ships that have that system?

You can check this by having a system script with a constructor, logging some stuff there (or putting a breakpoint there) and seeing when that's called.

(It's not a singleton, a new copy is instantiated for each ship.)
Logged

rogerbacon

  • Commander
  • ***
  • Posts: 151
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9638 on: February 26, 2023, 02:00:35 PM »

I made a ship that carries a firgate. It deploys thefrigate at thestart of combat with spawnShipOrWing(). I'm using a mod that tracks kills and ship experience and I wanted to give the launching ship credit for anything the dynamically-spawned frigate kills. I successfully did this by calling pf.setParentStation(ship);, where pf is the frigate.

The only problem I'm having is that if the frigate gets too far from the parent ship the frigate stops firing all of its weapons. Once the parent ship gets back within about 1500 to 2000 of the frigate it starts firing again. Any idea what could be causing this behavior?
« Last Edit: February 27, 2023, 05:20:23 AM by rogerbacon »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9639 on: February 27, 2023, 05:57:16 PM »

... no idea, honestly - nothing comes to mind as a possible cause. I'm very surprised that calling setParentStation() on the ship doesn't break things horribly, though, wow.

Ok, well, maybe one idea - could it be a fog of war issue, perhaps? A quick way to check would be to turn the fog of war off in dev mode (by pressing Ctrl-F).
Logged

bananana

  • Commander
  • ***
  • Posts: 228
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9640 on: February 28, 2023, 12:21:00 AM »

is it possible to change this text for one specific ability?
the "press F1 for more info"
Logged
Any and ALL sprites i ever posted on this forum are FREE to use. even if i'm using them myself. Don't ever, EVER ask for permission, or i will come to your home and EAT YOUR DOG!!!
i do NOT want to see my name appear in the credits section of any published mod and will consider it a personal insult.

Ontheheavens

  • Commander
  • ***
  • Posts: 137
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9641 on: February 28, 2023, 01:12:25 AM »

is it possible to change this text for one specific ability?
the "press F1 for more info"
Spoiler
[close]

Yes, but only on runtime with use of some serious reflection, and the underlying frame graphics is not going to accomodate those changes, said frame being un-modifiable due to method names being obfuscated too. In other words: no, not realistically possible.
Logged
   

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9642 on: February 28, 2023, 02:00:11 PM »

It is, however, possibly to *remove* this text - along with the ability to expand the tooltip - by having AbilityPlugin.isTooltipExpandable() return false.
Logged

bananana

  • Commander
  • ***
  • Posts: 228
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9643 on: March 01, 2023, 04:33:10 AM »

what would be the safest way to detect the event of missile being killed by PD fire?
to make stuff happen
Logged
Any and ALL sprites i ever posted on this forum are FREE to use. even if i'm using them myself. Don't ever, EVER ask for permission, or i will come to your home and EAT YOUR DOG!!!
i do NOT want to see my name appear in the credits section of any published mod and will consider it a personal insult.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24125
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9644 on: March 01, 2023, 05:59:04 PM »

Hmm, probably with a DamageTakenModifier added to the Global.getCombatEngine().getListenerManager().
Logged
Pages: 1 ... 641 642 [643] 644 645 ... 710