Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 596 597 [598] 599 600 ... 710

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

Wispborne

  • Captain
  • ****
  • Posts: 408
  • Discord: wispborne
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8955 on: July 20, 2022, 11:48:29 AM »

- More importantly : how do i compile the code so it applies in game ? I don't think the "starsector.api.zip" will do anything to my game. So where is the proper file i need to tamper in order to change in game stuff ?

There are a few IDE setup guides.

This is the one I think is simplest, although it doesn't have a nice wiki page yet and isn't completely noob-proof. Still, the readme should hit all the major steps needed to complete setup.
https://github.com/davidwhitman/Starsector-IntelliJ-Template
It's also quite new and the wiki doesn't link to it yet.

This is an overview of mod programming, with a few IDEs compared and guides linked. It contains stuff about what the different files are, too (.java, .class, .jar) and why you shouldn't use Janino.
https://starsector.fandom.com/wiki/Getting_started_with_mod_programming

And finally, this is another IntelliJ setup guide: https://starsector.fandom.com/wiki/IntelliJ_IDEA_Setup.
This one has you compile Magellan, as opposed to just a barebones template like the first link.
Logged
Mod: Persean Chronicles | Mod Manager: SMOL | Tool: VRAM Estimator | Tool: Forum+Discord Mod Database | If I'm inactive for 3 months, anyone can use any of my work for anything (except selling it or its derivatives).

Liral

  • Admiral
  • *****
  • Posts: 718
  • Realistic Combat Mod Author
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8956 on: July 20, 2022, 05:24:25 PM »

How can I detect each tick of a beam that has hit a CombatEntityAPI, or at least a ShipAPI and its shield?  DamageDealtModifier and DamageTakenModifier detect only the first tick of damage.

Edit: Sweet Ludd.  I had to resort to redundant iteration and spaghetti code to find the beam ticks.  I really hope it's my fault because this is just ugly.  If it's not... please make them detect subsequent ticks?  :'(

Code
    private static void diffractBeam(BeamAPI beam) {
        if (!(beam.getDamageTarget() instanceof ShipAPI)) beam.getDamage().setDamage(
                Penetration.getPenetration(beam));
        else if (beam.getDamageTarget().getShield() == null
                 || !beam.getDamageTarget().getShield().isWithinArc(beam.getTo()))
        {
            final ShipAPI target = (ShipAPI) beam.getDamageTarget();
            final HashMap<String, Float> damage = Damage.getCompartmentAndHullDamage(target, beam);
            final float time = Global.getCombatEngine().getElapsedInLastFrame();
            if (damage.get("compartment") > 0)
                DamageTakenModifier.applyDamage(
                        target,
                        beam.getRayEndPrevFrame(),
                        time * damage.get("hull"),
                        time * damage.get("compartment"),
                        beam.getSource()
                );
            beam.getDamage().setDamage(0);
        }
    }

    private static void diffractAllBeams(ShipAPI ship) {
        for (WeaponAPI weapon : ship.getUsableWeapons())
            if (weapon.isBeam() && weapon.isFiring())
                for (BeamAPI beam : weapon.getBeams())
                    if (beam.getDamageTarget() != null && beam.getBrightness() >= 1)
                        try { diffractBeam(beam); } catch (Throwable ignored) {}
    }

Also, EnergyWeaponRangeBonus seems to affect Beam weapons too.  Can I affect energy projectile but not energy beam range?
« Last Edit: July 21, 2022, 01:59:36 AM by Liral »
Logged

PasDeBras

  • Ensign
  • *
  • Posts: 23
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8957 on: July 21, 2022, 01:29:22 AM »

Hello! I'm looking for a way to make a hullmod give a set number of OP (the simpler the better) like a mod i found years ago but lost, in exchange of malfunctions, but modding HM seems way harder that just adding a ship to the game, any pointers?
Thank you precious people..

Edit : Message is unclear, but i want to know what to call for malfunctions...
« Last Edit: July 21, 2022, 05:44:44 AM by PasDeBras »
Logged

JAL28

  • Commander
  • ***
  • Posts: 217
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8958 on: July 21, 2022, 11:33:28 PM »

Is there a way to make a missile not disappear when hitting shields/fighters? Also optionally how to make a missile bypass shields entirely?

For example, the missile moves to fighter 1 and hits it, but it’s still alive and can move on to target fighter 2.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24111
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8959 on: July 22, 2022, 12:28:17 PM »

How can I detect each tick of a beam that has hit a CombatEntityAPI, or at least a ShipAPI and its shield?  DamageDealtModifier and DamageTakenModifier detect only the first tick of damage.

Some quick testing shows that modifyDamageDealt() is called for every damage tick. Which is not the same as every frame btw.

Code
try { diffractBeam(beam); } catch (Throwable ignored) {}

(I really wouldn't do this sort of stuff if I were you - in the long run, you're likely hiding some major bugs from *yourself*.


Also, EnergyWeaponRangeBonus seems to affect Beam weapons too.  Can I affect energy projectile but not energy beam range?

You can modify beam range by the inverse.


Hello! I'm looking for a way to make a hullmod give a set number of OP (the simpler the better) like a mod i found years ago but lost, in exchange of malfunctions, but modding HM seems way harder that just adding a ship to the game, any pointers?
Thank you precious people..

Edit : Message is unclear, but i want to know what to call for malfunctions...

IIRC the way to give OP is to give the hullmod a negative cost. For malfunctions, take a look at data.hullmods.IllAdvised.


Is there a way to make a missile not disappear when hitting shields/fighters? Also optionally how to make a missile bypass shields entirely?

For example, the missile moves to fighter 1 and hits it, but it’s still alive and can move on to target fighter 2.

Offhand, I don't think so. You might be able to do something fancier like replacing the missile with a copy and making it non-collideable until it leaves the bounds of the targets, or some such. You might also possibly experiment with setting it to be not "armed" (so that it bounces off on impact) and scripting the damage it does instead. Not 100% sure how well any of that would pan out; too many variables.
Logged

Liral

  • Admiral
  • *****
  • Posts: 718
  • Realistic Combat Mod Author
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8960 on: July 22, 2022, 02:09:14 PM »

Some quick testing shows that modifyDamageDealt() is called for every damage tick. Which is not the same as every frame btw.

Wow, you tested it for me?  Gee, Alex... you didn't have to!  Thank you so much!  :)  Why mine doesn't work like yours I have no idea.  I'll try to test it myself some more and see.

Quote from: Alex
Code
try { diffractBeam(beam); } catch (Throwable ignored) {}

(I really wouldn't do this sort of stuff if I were you - in the long run, you're likely hiding some major bugs from *yourself*.

Oh... what should I do instead?  :o I've wrapped the inner workings of the many public, and even a few private, methods of my mod inside one if not several such try-catch blocks because I had thought that guaranteeing that no bug will ever crash the code or generate a nasty error report to be good software engineering practice--and had felt rather proud of myself until just now.  *gulp*  :-[

My best guess is to keep the try-catch blocks but put breakpoints and error dumps inside the catch sections.

Quote from: Alex
You can modify beam range by the inverse.

Thank you!  What a relief.  I can fix a longstanding bug now.  I hope that there will be a method to do so directly someday!

SafariJohn

  • Admiral
  • *****
  • Posts: 3020
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8961 on: July 22, 2022, 06:39:02 PM »

Oh... what should I do instead?  :o I've wrapped the inner workings of the many public, and even a few private, methods of my mod inside one if not several such try-catch blocks because I had thought that guaranteeing that no bug will ever crash the code or generate a nasty error report to be good software engineering practice--and had felt rather proud of myself until just now.  *gulp*  :-[

My best guess is to keep the try-catch blocks but put breakpoints and error dumps inside the catch sections.

Buy the book "Code Complete" by Steve McConnell and read it. Page 198-203 of my 2nd edition specifically talks about exceptions.

What you are doing is covering up exceptions you don't know what to do with, which means your code is either raising an exception for no reason, or as Alex said you are hiding problems from yourself.

What you should do is let the null pointers and other exceptions blow out, find where they are coming from, and either avoid or fix those problems.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4681
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8962 on: July 22, 2022, 07:48:04 PM »

Kicking the player to desktop is unpleasant, so in cases where the error will be visible without such extreme methods and/or is non-fatal (in my case, this is UI elements in an intel display), I've used a catch-all-exceptions block.
But log the error at least so if it's noticed you know what's going on.

Actually now what I'd like is a standardised API for error reporting dialogs (and do this automatically for uncaught exceptions), like the one AI War 2 uses:

Spoiler
[close]
- Big annoying popup is big, annoying and full of scary code, but it also immediately lets them know something has gone wrong without the abrupt transition of a CTD, or losing their progress
- When player shows a screenshot of this to someone, the stacktrace is immediately visible without having to tell them where/how to look for starsector.log
- If the error isn't fatal they can resume playing, at least they can make a save copy and try to continue, and even if things are in an invalid state now they can sometimes be left alone till the relevant battle/campaign event ends, or fixed with a console runcode
Logged

Liral

  • Admiral
  • *****
  • Posts: 718
  • Realistic Combat Mod Author
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8963 on: July 23, 2022, 02:16:07 AM »

Buy the book "Code Complete" by Steve McConnell and read it. Page 198-203 of my 2nd edition specifically talks about exceptions.

What you are doing is covering up exceptions you don't know what to do with, which means your code is either raising an exception for no reason, or as Alex said you are hiding problems from yourself.

What you should do is let the null pointers and other exceptions blow out, find where they are coming from, and either avoid or fix those problems.

Thanks for replying!  Why should I let the null pointers and other exceptions blow out if, instead, I could have a breakpoint and error-logger inside every try-catch block?  When I would run the code with a debugger attached, any use of the try-catch block would 'crash' the game to the debugger, saving the trouble of reloading while exposing what went wrong.  When the user would run the code, the try-catch block would execute silently, letting them enjoy the game without worrying about crashes, which I worry about because my mod interacts with every other mod in the game and the entire combat system without many of the guarantees of the API; e.g., I have to cover not only projectiles, missiles, and beams but also asteroids, ships, debris, and anything else that any modder has decided to toss in.  If my mod crashed to the desktop or even displayed an error dialogue for every exception, users could never rest easy and would probably uninstall it.  :(

(see below as well)

Kicking the player to desktop is unpleasant, so in cases where the error will be visible without such extreme methods and/or is non-fatal (in my case, this is UI elements in an intel display), I've used a catch-all-exceptions block.
But log the error at least so if it's noticed you know what's going on.

What do you mean by non-fatal?  I expect nullPointerExceptions, weird numerical errors, etc. especially once huge lists of other mods and their interactions become involved because my mod works with dark DIY API magic, implements a whole new damage model, and has many EveryFrameCombatScripts, some of which do things I know to be unstable but haven't seen an alternative to.  I'm afraid that I am attempting to do stuff so inherently unstable and repetitive that if Realistic Combat so much as threw pop-ups, the user might know no peace.  For example, I received a bug report that the entire combat UI was smeared around the screen, implying that Realistic Combat had 'shrugged and chugged' despite a glaring problem with a perhaps gnarly or obscure cause--just as I had hoped because I haven't received another such report before or since.

Writing all this, I have a bad feeling, but I don't know why.  I think I need another try-catch block.  ???

Quote
Actually now what I'd like is a standardised API for error reporting dialogs (and do this automatically for uncaught exceptions), like the one AI War 2 uses:

Spoiler
[close]
- Big annoying popup is big, annoying and full of scary code, but it also immediately lets them know something has gone wrong without the abrupt transition of a CTD, or losing their progress
- When player shows a screenshot of this to someone, the stacktrace is immediately visible without having to tell them where/how to look for starsector.log
- If the error isn't fatal they can resume playing, at least they can make a save copy and try to continue, and even if things are in an invalid state now they can sometimes be left alone till the relevant battle/campaign event ends, or fixed with a console runcode

That's easier than it might seem.  I believe you can use LazyLib to directly draw a big, scary blue block on the screen and print white text on it: "ERROR: [report] PRESS SPACE TO CONTINUE"

presidentmattdamon

  • Commander
  • ***
  • Posts: 249
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8964 on: July 23, 2022, 03:48:42 PM »

For example, I received a bug report that the entire combat UI was smeared around the screen, implying that Realistic Combat had 'shrugged and chugged' despite a glaring problem with a perhaps gnarly or obscure cause--just as I had hoped because I haven't received another such report before or since.

you have an issue in one of your UI draw events that caused this, which happened after pushing onto the openGL stack and before popping it.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4681
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8965 on: July 24, 2022, 08:43:41 PM »

What do you mean by non-fatal?  I expect nullPointerExceptions, weird numerical errors, etc. especially once huge lists of other mods and their interactions become involved because my mod works with dark DIY API magic, implements a whole new damage model, and has many EveryFrameCombatScripts, some of which do things I know to be unstable but haven't seen an alternative to.  I'm afraid that I am attempting to do stuff so inherently unstable and repetitive that if Realistic Combat so much as threw pop-ups, the user might know no peace.  For example, I received a bug report that the entire combat UI was smeared around the screen, implying that Realistic Combat had 'shrugged and chugged' despite a glaring problem with a perhaps gnarly or obscure cause--just as I had hoped because I haven't received another such report before or since.

Writing all this, I have a bad feeling, but I don't know why.  I think I need another try-catch block.  ???
By non-fatal I mean anything that won't permanently (within or beyond the current play session).
  • If the entire Combat Chatter mod were to stop working in the middle of a battle: annoying but whatever, finish the battle, save and restart the game, assuming you even noticed it stopped working.
  • AI breaks and all the NPC ships stop moving: this is serious, but I think the player should be the one to decide whether they want to close the game now, or just use console (if available) to end it and then save.
  • TBH to justify a CTD you'd probably need a bug that outright corrupts campaign data in an irrecoverable way

Regarding the rest:
If your mod is generating errors that need covering up, this often ("know no peace") you need to fix them, not merely sweep them under the rug.
You don't have to make it interfere with the player's UX, maybe write something in the post-combat dialog or campaign message field "X errors in Realistic Combat encountered in last battle, please send me your starsector.log". But the key point remains: If the mod suppresses a hundred distinct bug notifications, that's a hundred bugs in the mod, and hiding them doesn't make them stop being bugs. If the user is experiencing so many hidden errors, they're not receiving the intended experience — but neither you nor they know they're not getting the intended experience!
Relying on your own debugger runs isn't adequate; many errors aren't picked up by the mod dev, but by a player.
Logged

Liral

  • Admiral
  • *****
  • Posts: 718
  • Realistic Combat Mod Author
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8966 on: July 25, 2022, 02:59:36 AM »

By non-fatal I mean anything that won't permanently (within or beyond the current play session).
  • If the entire Combat Chatter mod were to stop working in the middle of a battle: annoying but whatever, finish the battle, save and restart the game, assuming you even noticed it stopped working.
  • AI breaks and all the NPC ships stop moving: this is serious, but I think the player should be the one to decide whether they want to close the game now, or just use console (if available) to end it and then save.
  • TBH to justify a CTD you'd probably need a bug that outright corrupts campaign data in an irrecoverable way

Ok, so anything short of the equivalent to SEGMENTATION FAULT: CORE DUMPED is non-fatal.

Quote
Regarding the rest:
If your mod is generating errors that need covering up, this often ("know no peace") you need to fix them, not merely sweep them under the rug.

I have no idea how often my mod generates errors because I have built try-catch blocks into it from the beginning--and it has no logs to record the errors--but I have nothing against fixing them in principle.  In practice I suspect from what I have seen of the errors that have leaked through the try-catch blocks that ones not caused by my own typos or forgetfulness are obscure, gnarly, and peculiar to whatever long content mod list each reporting player pushes through my ship and weapon stat modifications or damage model.  For example, one user has recently complained about a music file not loading even though Realistic Combat never even touches music files.  :o  I have no idea how to fix any of these errors, either.

Maybe this is all so much whining.  :-\

Quote
You don't have to make it interfere with the player's UX, maybe write something in the post-combat dialog or campaign message field "X errors in Realistic Combat encountered in last battle, please send me your starsector.log". But the key point remains: If the mod suppresses a hundred distinct bug notifications, that's a hundred bugs in the mod, and hiding them doesn't make them stop being bugs. If the user is experiencing so many hidden errors, they're not receiving the intended experience —

Ooooh, OK, that could work.  Please tell me more about this because I have no idea how to make it happen.

Quote
but neither you nor they know they're not getting the intended experience!

All according to plan!  ;D

Quote
Relying on your own debugger runs isn't adequate; many errors aren't picked up by the mod dev, but by a player.

Aww...

Ruddygreat

  • Admiral
  • *****
  • Posts: 524
  • Seals :^)
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8967 on: July 25, 2022, 01:00:28 PM »

would it be possible to force a ship's fighters to always land at one bay and launch from another?

i.e, if I had a ship with a bay going "through" the hull and always wanted the fighters to land on one end then launch from the other, that kinda thing.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24111
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8968 on: July 25, 2022, 06:32:57 PM »

Actually now what I'd like is a standardised API for error reporting dialogs (and do this automatically for uncaught exceptions), like the one AI War 2 uses:

Spoiler
[close]
- Big annoying popup is big, annoying and full of scary code, but it also immediately lets them know something has gone wrong without the abrupt transition of a CTD, or losing their progress
- When player shows a screenshot of this to someone, the stacktrace is immediately visible without having to tell them where/how to look for starsector.log
- If the error isn't fatal they can resume playing, at least they can make a save copy and try to continue, and even if things are in an invalid state now they can sometimes be left alone till the relevant battle/campaign event ends, or fixed with a console runcode

Hmm, interesting! The bad case here seems like it'd be the error popping up, putting some mission chain in a "permanently broken" state because something critical to it failed, and then the mission becomes incompletable a few play sessions later. And *then* the player reports a bug with that mission being in a broken state - without mentioning that, oh yeah, there was this error like a week ago. I don't know - I get the appeal, but I feel like this also destroys something very foundational about being able to look at a bug report and know certain things about what led to it. If you can no longer assume that X is true because it would've crashed earlier otherwise, that's real, real bad.

(I suppose one could store these errors in the savefile, but, that really gets to be a rabbit hole...)


would it be possible to force a ship's fighters to always land at one bay and launch from another?

i.e, if I had a ship with a bay going "through" the hull and always wanted the fighters to land on one end then launch from the other, that kinda thing.

I don't *think* so.
« Last Edit: July 25, 2022, 07:02:05 PM by Alex »
Logged

SafariJohn

  • Admiral
  • *****
  • Posts: 3020
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #8969 on: July 25, 2022, 06:59:04 PM »

would it be possible to force a ship's fighters to always land at one bay and launch from another?

i.e, if I had a ship with a bay going "through" the hull and always wanted the fighters to land on one end then launch from the other, that kinda thing.

I don't *think* so.

A script for the ship that messes with the fighters? Put all the deck points at the landing end and then teleport any launching fighters to the launch end, maybe.
Logged
Pages: 1 ... 596 597 [598] 599 600 ... 710