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 ... 652 653 [654] 655 656 ... 706

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

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9795 on: April 18, 2023, 05:32:12 PM »

I'm trying to build a Beam with a sound windup during delay, firing loop, and final sound. What, exactly, do fireSoundOne, fireSoundTwo and fireSoundThree do, when a Beam is firing? I originally set it up like the Tachyon Lance... which just defines fireSoundTwo. I want all three sounds to be unique.

I've seen that one of the "new" weapons uses fireSoundThree, but not the other two. What are these doing? There isn't any definition in beam_weapon.sample.

[EDIT]
OK, so 2 is always looping. 1 never appears to play. I'll try defining all three and see what I get.

Tachyon Lance, on the other hand, does not loop and has three sounds. Whaaaa?

[EDIT2]
OK... if all three are defined, you get fireSoundOne, then fireSoundTwo loops until the Beam is finished, but fireSoundThree doesn't play. Weird, lol.
« Last Edit: April 18, 2023, 05:43:31 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9796 on: April 18, 2023, 05:47:05 PM »

fireSoundOne plays once when the beam is fired
fireSoundTwo is the beam loop

fireSoundThree, is, as far as I can tell, not a string that is found anywhere in the codebase, including weapon definition files.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9797 on: April 18, 2023, 05:52:54 PM »

It's in Cryoflux.wpn:

"fireSoundThree":"cryoflamer_loop",

(note: I'm still a version behind, so maybe that got fixed in the current build)

So, er, how does the Tachyon Lance do the special noise when it resets? Just an EveryFrame script that catches it and checks state?
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9798 on: April 18, 2023, 05:55:56 PM »

Ah, that's not in the code now; not sure when that got cleaned up.

So, er, how does the Tachyon Lance do the special noise when it resets? Just an EveryFrame script that catches it and checks state?

I don't know what you mean. It's only got one sound defined in the .wpn file - fireSoundTwo - and it plays an EMP hit effect with its beamEffect script.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9799 on: April 18, 2023, 06:02:02 PM »

Ah, so what I think is the third sound must just be the Flux meter resetting or something. I always hear a "whoosh" at the end of firing it in tests and presumed that was what the last sound was for, lol- a cue to the player that the weapon has reset and is ready to shoot again. That seems like something that would be super-easy to do; just play a sound at <location> when weapon reaches <recharge level>. I'll look into that; I'm doing some weapons with pretty absurd chargeup / chargedown times and want clear audio cues.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

vicegrip

  • Commander
  • ***
  • Posts: 184
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9800 on: April 18, 2023, 07:48:59 PM »

Is there a way for a hullmod to apply an effect to a weapon being removed from a hull? Alternatively is there a way to have a hullmod lock certain weapons into a ship (modular weapons in modular slots) as long as the hullmod is present?

Context: I have a few hullmods both current and planned that alter weaponSpec modifiers that are permanent (even if the hullmod that changed them is removed) I have the means to restore the previous values if the granting hullmod is removed via a hidden hullmod, but it does noting if you just strip the weapons out that are left with their now altered parameters and no way to tell them apart from "clean" versions of the same weapon.

This isn't a conclusive answer since I'm just an amateur modder myself, but when I attempted to do this, the conclusion I came to was no, it's not really possible. You can do very hacky things with hullmods to simulate item pinning and transformations, such as causing a slot to always have a weapon, or always swap a weapon. You can also do things like look through inventory and delete or swap items as players receive them from unequipping. But what will mess you up is the undo button. Because everything you're trying to do is with hullmods, and hullmods that aren't built in can be removed as well with undo, players hitting undo will cause unintended behavior such as creating duplicates or causing items to disappear, or leaving the wrong type of item in inventory. Also, setting the weapon type to BUILT_IN with a hullmod unfortunately doesn't actually make it built in, and lets players remove a weapon that they now can't re-equip. So far I haven't found a way to have a fire and forget method to change the nature of a weapon and make it unequippable without faking it with inventory swaps behind the scenes, and undo just ruins that on every attempt unless you're doing something very specific such as using an "always on" built-in hullmod to make sure a type of tagged/untagged item never end up in a slot.

One potential workaround I heard but haven't explored is to make a hullmod that describes the weapon changes to players, but doesn't actually make them until combat starts. I have no idea if that'll make a difference, however, even if you could get it to work.

ctuncks

  • Commander
  • ***
  • Posts: 117
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9801 on: April 18, 2023, 07:55:21 PM »

Is it possible to implement a SR NOR Latch into advanceInCombat in order to memorise the state of local booleans?

in short - yes, you can use code to emulate digital logic. (and strictly speaking, an sr latch is just a boolean variable)

though I suspect that this is a useless non-answer for your case, what are you trying to do specifically?

I have some cosmetic hullmods in the works that dynamically changes the base colour of shields in combat as a ships flux level rises (It's really just 1 script, but with different starting colour values). An issue I ran into however is these new values completely overwrite the colour change from fortress shield. I made an IF statement to counteract this, but now have the issue of an instant colour change as opposed to the gradual transition that fortress shield normally has.

The issue I'm having Is I need to use local booleans and/or floats and they need to be initialised, for everything to work properly they need to start off as false/0f, but as soon as the conditions that change these values are missing they default back to false/0f.

What I'm aiming for is:

- Boolean "Start" is by default false.
- As soon as a ship with fortress shield turns on fortress shield I want "Start" to be true and stay true after fortress shield is turned off.
* With "Start" as a local boolean it will default back to false at this point.
- As soon as fortress shield turns off and shields are still on and "Start" is true a timer will start for about 5 seconds (variable) after this is complete or shields are turned off while "Start" is still true, then "Start" will be reset to false.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9802 on: April 18, 2023, 08:30:49 PM »

@ctuncks: Ah, so you want to catch the state of something changing a shield's values in real time, then. So you just check the ship's MutableStats, get the size of bonus for <shield stuff> at the very start when the ship's brand new to the simulation, then check it again during play to see if it's different for <reasons>. If yes, quit running your real-time modification of shield colors, or initiate a fade transition or whatnot.

You could also simply check for the presence of that particular System and check its state, to see if it's on, but that won't be a good generalized solution.

@vicegrip:  The problem here is that hullmods apply their effects in a few specific contexts: before ship creation, when it's just a VariantAPI, or after, and "after" means when it's a full-fledged ShipAPI in the sim or combat.

So you're talking "making them after combat starts" there, but it's easy to implement in the current BaseHullMod system.

So what do you want this to do, exactly, that requires all this? Turn a Decorative into a functional weapon that's effectively like a Built In? If so, doing it in AfterShipCreation() is probably the appropriate time, but there you'll end up with other problems, such as, "what weapon group will this be assigned to", that would require some careful thought.

I've often thought that Hull Mods should have a couple of methods: AfterVariantHasBeenChanged() and AfterHullModHasBeenRemoved() that are specifically triggered by player changes to Variants in the ship editor, to allow for behaviors like this a little more gracefully. The Dock interface is one of the weird places in SS, where it's not quite a ship and it's not quite a Variant, either.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

ctuncks

  • Commander
  • ***
  • Posts: 117
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9803 on: April 19, 2023, 02:12:05 AM »

After studying some of PureTilt's hullmods I believe I've come up with a workable solution to my issue.

Code
public void advanceInCombat(ShipAPI ship, float amount) {

        Map<String, Object> customCombatData = Global.getCombatEngine().getCustomData();

        float shieldTest = 0f;
        if (customCombatData.get("ZDA_Test" + ship.getId()) instanceof Float)
            shieldTest = (float) customCombatData.get("ZDA_Test" + ship.getId());

// How fast shieldTest increases.
        if (ship.getSystem().isOn())
            shieldTest += 0.0175f;

// Upper Limit of shieldTest
        if (shieldTest > 5f)
            shieldTest = 5f;

// How fast shieldTest decerases.
        if (ship.getShield().isOn() && !ship.getSystem().isOn())
            shieldTest -= 0.0175f;

// Lower Limit of shieldTest
        if (shieldTest < 0f)
            shieldTest = 0f;

// Reset of shieldTest when shield is off.
        if (ship.getShield().isOff() && !ship.getSystem().isOn())
            shieldTest = 0f;

        ship.getMutableStats().getBallisticWeaponRangeBonus().modifyFlat("test", shieldTest * 80f);

        customCombatData.put("ZDA_Test" + ship.getId(), shieldTest);

    }

Using custom combat data I can generate a persistent float value that increases/decreases periodically as long as the conditions are true, acting as a pseudo clock, which is good enough for me. While messing about though I did find that custom data doesn't seem to interact well with booleans, even if they're booleans that are derived from the custom data floats.

The above test was just testing the concept and I like to use range for it since it's relatively easy to measure against.
« Last Edit: April 19, 2023, 02:16:05 AM by ctuncks »
Logged

Lukas04

  • Captain
  • ****
  • Posts: 337
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9804 on: April 19, 2023, 10:03:44 AM »

Using custom combat data I can generate a persistent float value that increases/decreases periodically as long as the conditions are true, acting as a pseudo clock, which is good enough for me. While messing about though I did find that custom data doesn't seem to interact well with booleans, even if they're booleans that are derived from the custom data floats.

Custom Data is just a Map attached to a CombatEntity, it shouldnt handle primitive types differently than a normal map, so not quite sure what you mean with the "doesn't seem to interact well with booleans" part.
Logged
My Mods

Ruddygreat

  • Admiral
  • *****
  • Posts: 524
  • Seals :^)
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9805 on: April 19, 2023, 12:19:30 PM »

is there a way to get a ship's center of mass offset from it's sprite (if that makes sense)?
my particular case is renderAtCenter()'ing (well, doing something equivalent) a sprite, if you just do it without an offset then the final sprite will end up misaligned from the ship 99% of the time.

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9806 on: April 19, 2023, 09:13:09 PM »

After studying some of PureTilt's hullmods I believe I've come up with a workable solution to my issue.
That'll work for that specific case, but I'd suggest checking against the values of each shield-related stat's state vs. what it is when the ShipAPI's initialized. Remember, there are other Systems out there that will effect Shields in a different way, but may also be using custom effects. For a general-purpose system, it probably needs a broader approach.

For example, check the value of ship.getMutableStats().getShieldAbsorptionMult().getModifiedValue(). This is pretty cheap (you're fetching an Object's Object reference, then a value from that, then running a very teeny method).

Here's a little cleanup of that code; I hope you find it useful!
Spoiler
public void advanceInCombat(ShipAPI ship, float amount) {
   //If we don't pass Go, then...
   //Note that we're explicitly *not* creating a copy of the custom data here; we're checking it directly. Also, checking for NPE.
   //Populating the custom data should be done in a once-and-done that only applies to ships that need it.
   if (Global.getCombatEngine().getCustomData().get("ZDA_Test" + ship.getId()) != null && Global.getCombatEngine().getCustomData().get("ZDA_Test" + ship.getId())  instanceof Float)
   {
      float shieldTest = 0f;
      shieldTest = (Float) Global.getCombatEngine().getCustomData().get("ZDA_Test" + ship.getId());
      
      //Branch optimizations
      if(ship.getSystem().isActive() || ship.getSystem().isOn() || ship.getSystem().isChargeup()){
         if(ship.getShield() != null && ship.getShield().isOn()){
             shieldTest += 0.0175f;
         }
      } else {
         shieldTest -= 0.0175f;
      }
      //Clean limiter function here
      shieldTest = Math.min(Math.max(shieldTest, 0f), 5f);

      ship.getMutableStats().getBallisticWeaponRangeBonus().modifyFlat("test", shieldTest * 80f);

      Global.getCombatEngine().getCustomData().put("ZDA_Test" + ship.getId(), shieldTest);      
   }
}
[close]

is there a way to get a ship's center of mass offset from it's sprite
Absolutely. Get the ship's hull JSON and read the offsets directly from there.

Here's a working example that gets you most of the way there:

Spoiler
                        //Get all Variants in the game.
         List<ShipHullSpecAPI> theVariants = Global.getSettings().getAllShipHullSpecs();
                        //This uses a Stream... Alex, you've finally updated to Java 7+, right?
         theVariants.forEach(variantID -> {            
            if(variantID != null && variantID.getBaseHull() != null && variantID.getBaseHull().getShipFilePath() != null){
                                        //If nothing borked, we now have something we can go get in the SS filesystem.
               String path = "data/hulls/" + variantID.getBaseHullId() + ".ship";
               //Global.getLogger(YOUR_FANCY_CLASS_NAME_HERE.class).log(Level.ERROR,"Hey, We've Got A Path: " + path);
               
               //Now we look through each mod's sub-directory to find the actual file, essentially.
               for(ModSpecAPI mod : Global.getSettings().getModManager().getAvailableModsCopy()){
                  String modID = mod.getId();               
                  try{
                     JSONObject thisBaseHull = Global.getSettings().loadJSON(path, modID);
                     

                     /*<GET THE OFFSET DATA HERE, STORE SOMEWHERE ELSE>*/

                     //Global.getLogger(YOUR_FANCY_CLASS_NAME_HERE.class).log(Level.ERROR,"Hey, we've found that JSON data you wanted: " + YOUR_DATA_HERE);
                  } catch(Throwable ex) {
                     //Global.getLogger(YOUR_FANCY_CLASS_NAME_HERE.class).log(Level.ERROR,"Oops! We didn't find the JSON at: " + path + " in: " + modID);
                  }
               }
            }
         });
[close]

« Last Edit: April 19, 2023, 09:31:54 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

rogerbacon

  • Commander
  • ***
  • Posts: 142
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9807 on: April 20, 2023, 05:21:32 AM »

Is ther eany way in campaign to tell when a ship was built? I.e. The year, month and day in-game when a ship was created? Is there any interaction between game date and ships that I could see as an example?

A couple of things I'd like to do:
I'd like to prevent certain weapons being added before a certain game year.
Have a ship suffer accelerated CR decline if it's older than X years.
Logged

ctuncks

  • Commander
  • ***
  • Posts: 117
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9808 on: April 20, 2023, 06:01:34 AM »

@ Lukas04

I mucked a little bit more around for whatever reason when I use the custom data floats. they seem to work fine if you just use them as values, but as soon as I use them with an "if" statement (that doesn't alter the float value) whether directly or to set a boolean it seems to lock into the true setting.

@ xenoargh

I copied your example code whole-cloth and it doesn't seem to work the way my previous entry did unfortunately, I have however taken a few pointers from it to pare it down to:
Code
public void advanceInCombat(ShipAPI ship, float amount) {

        Map<String, Object> customCombatData = Global.getCombatEngine().getCustomData();

        float shieldTest = 0f;
        if (customCombatData.get("ZDA_Test" + ship.getId()) instanceof Float)
            shieldTest = (float) customCombatData.get("ZDA_Test" + ship.getId());
       
        if (ship.getSystem().isOn()) {
            shieldTest += 0.0175f;
        } else if ((ship.getShield().isOn() && !ship.getSystem().isOn())) {
            shieldTest -= 0.0175f;
        } else {
            shieldTest = 0f;
        }

        shieldTest = Math.min(Math.max(shieldTest, 0f), 5f);

        customCombatData.put("ZDA_Test" + ship.getId(), shieldTest);

        ship.getMutableStats().getBallisticWeaponRangeBonus().modifyFlat("test", shieldTest * 80f);

    }


Your concerns for other system weirdness is valid, but ultimately I'm only intending to use the code for ships with fortress shield (and it'll be changing colour not ballistic weapon range).

Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #9809 on: April 20, 2023, 10:12:58 AM »

Is ther eany way in campaign to tell when a ship was built? I.e. The year, month and day in-game when a ship was created? Is there any interaction between game date and ships that I could see as an example?

There isn't, no. I think probably the best you could do is track ships present in the player fleet. (You'd probably need to use WeakReference to avoid gradual memory leaks; see SModRecord for an example of that.)
Logged
Pages: 1 ... 652 653 [654] 655 656 ... 706