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)

Author Topic: Modding Request: Access to ship drawing outside of combat  (Read 2391 times)

Wyvern

  • Admiral
  • *****
  • Posts: 3784
    • View Profile
Modding Request: Access to ship drawing outside of combat
« on: February 21, 2019, 09:10:54 AM »

So, (see posts here and here), I've been experimenting with mirroring asymmetric weapons; this works fine in the outfitting screen and in combat, but not outside of that - i.e. there's no sane way to mirror non-built-in weapons in the fleet screen or the little preview images when you're facing another fleet.

That's not the only reason to support something of this sort, though; another example where it'd be useful to have this kind of control is the modular cargo haulers in Tyrador Safeguard Coalition - they've got some very nice visual changes depending on what they're loaded up with, but they all go back to default empty hold appearance on the fleet screen; it'd be nice to be able to look at an enemy fleet and tell at a glance "Oh, that one's a combat loadout with fighter bays, but those two are tankers and won't be deployed to the main battle."

And, last-but-not-least, there's one more drawing context that would be nice to have a bit more access to, and that's the ship models used for drawing the fleet when you're wandering around on the campaign map.*  Obviously this is a performance-sensitive context, but it'd still be nice to be able to do a few basic things like "use this sprite on the campaign map", or "use these engine trail starting locations" (see, for example, some Shadowyards ships that are supposed to have twin trails on the map, but currently only display one of the pair heading off at an angle), or maybe even "use this class for generating engine trails for this ship".
  * Footnote: Unlike the fleet screens, I haven't personally tried to dig into accessing the campaign display yet, so it's possible that there are more options here already that I'm just not aware of?  But I figure I should mention it while I'm on the topic of 'rendering ships outside of combat'.

I'm aware that Alex has already said that doing this could get "pretty complicated"; obviously, I don't know what that code looks like or why this feature would be troublesome to implement, but I figure it's worth posting an official suggestion thread to say "Hey, this would be a useful feature for modders to have."
« Last Edit: February 21, 2019, 09:12:40 AM by Wyvern »
Logged
Wyvern is 100% correct about the math.

Wyvern

  • Admiral
  • *****
  • Posts: 3784
    • View Profile
Re: Modding Request: Access to ship drawing outside of combat
« Reply #1 on: February 21, 2019, 06:03:52 PM »

I saw you start the other thread - could you clarify exactly what you're doing, there? I'm unclear by what you mean by mirroring, exactly how you're doing the rendering, etc. Still probably no easy way to expose this, but since I don't quite get the situation, I can't say 100%.
A picture is worth a thousand words, they say, and I was going to attach one but I keep getting 'the upload folder is full' despite the picture being below the attach size, and I don't have time right this second to toss it into my own hosting.  ...I'll have to get it up later.  >.<

Here's the code I'm using; for testing purposes I've attached this to the vanilla Hellbore cannon; if you put two on a Dominator, for example, the one on the left is flipped in the refit screen, making the entire ship symmetrical.  But not in the fleet display to the left of the refit screen, or anywhere else outside of combat.
Spoiler
Code: java
public class AutoMirror implements EveryFrameWeaponEffectPlugin {
private boolean runOnce = false;

@Override
public void advance( float amount, CombatEngineAPI engine, WeaponAPI weapon ) {
if( engine.isPaused() ) {
return;
}
if( !runOnce ) {
runOnce = true;
if( isOnLeft( weapon ) ) {
mirror( weapon );
}
}
}

public static boolean isOnLeft( WeaponAPI weapon ) {
WeaponSlotAPI slot = weapon.getSlot();
if( slot != null ) {
return slot.getLocation().getY() > 0f;
}
return false;
}

public static void mirror( WeaponAPI weapon ) {
mirror( weapon.getBarrelSpriteAPI() );
mirror( weapon.getSprite() );
mirror( weapon.getUnderSpriteAPI() );
}

public static void mirror( SpriteAPI s ) {
if( s == null ) return;
s.setWidth( -s.getWidth() );
s.setCenter( -s.getCenterX(), s.getCenterY() );
}
}
[close]

This lack of visual changes is actually more of an annoyance for Tyrador's modular hulls - when looking at the overview of the enemy fleet, you can't at a glance tell which ships are carrier-modified and will turn up in battle and which are cargo or tanker modified and won't.  But I don't have a handy screenshot for that, nor is it my code; it's just something else that'd benefit from being able to do visual modifications to ships outside of combat.
« Last Edit: February 21, 2019, 06:10:41 PM by Alex »
Logged
Wyvern is 100% correct about the math.

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Modding Request: Access to ship drawing outside of combat
« Reply #2 on: February 21, 2019, 06:17:00 PM »

I completely agree that there oughtta be a way to access the Refit Screen state, to do these things.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Wyvern

  • Admiral
  • *****
  • Posts: 3784
    • View Profile
Re: Modding Request: Access to ship drawing outside of combat
« Reply #3 on: February 21, 2019, 06:18:30 PM »

Ah, here we go.
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Modding Request: Access to ship drawing outside of combat
« Reply #4 on: February 21, 2019, 09:23:40 PM »

Ahh, thank you for clarifying! I have to say, the script is really elegant - would've expect this to be much more complicated. *thumbs up*

... let me think about this a bit on the backburner. Nothing comes to mind right now as far as how to possibly do this without it being a bug-prone, complicated mess, and I wouldn't say the odds are good, but, right, I'll give it some thought.


(I cleared out the uploads folder, btw.)
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3784
    • View Profile
Re: Modding Request: Access to ship drawing outside of combat
« Reply #5 on: February 21, 2019, 11:51:01 PM »

Hah, thanks!  My first implementation - based on Tecrys' work here - was much more complicated; this version represents some effort put into refinement.  (And, technically, it actually is more complicated than what I posted; the code I posted doesn't reflect weapon barrel locations and thus only really works right for guns with a single symmetrical firing point.  Like the hellbore.)
Logged
Wyvern is 100% correct about the math.