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] 2

Author Topic: Modding ShieldAPI  (Read 1953 times)

direfungasaur

  • Ensign
  • *
  • Posts: 4
    • View Profile
Modding ShieldAPI
« on: August 20, 2019, 06:55:23 PM »

Greetings all,

I really enjoy the game, but one thing that's really bothering me is how quickly the AI can bring up and tear down their shields in the face of incoming fire. This seems to greatly weaken shield-breaker builds and gives the AI an edge humans can't match, so I want to have a crack at modding it out. I've setup my IntelliJ project and have poked around the source code of some of the bigger mods, as well as the Javadocs.

While looking through there, I came across ShieldAPI, which has some methods I could presumably wrap and implement the logic I want. However, I can't seem to find where that's exposed. Global doesn't seem to expose it, nor CombatEngineAPI or ShipAPI. Does anybody know where I could get a list of ShieldAPIs for all active ships in a battle from? I would appreciate any pointers.

Cheers!
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Modding ShieldAPI
« Reply #1 on: August 20, 2019, 08:13:13 PM »

I think this will force all ships to always keep their shields up, but it's sure to be buggy:
Code
public class MyCombatPlugin implements EveryFrameCombatPlugin {
    @Override
    public void advance(float amount, List<InputEventAPI> events) {
            for(ShipAPI ship : Global.getCombatEngine().getShips()) {
                ship.getShield().toggleOn();
                ship.getShield().setActiveArc(ship.getShield().getArc());
            }
    }
}
Note that that's horrible code that's guaranteed to throw NPEs frequently (like when any ship doesn't have a shield).
Also, a better approach might be to modify AI, but that can be notoriously difficulty to do in some cases.

But... are you sure you want to do this?
  • Tricking the AI into dropping their shields when they shouldn't or keeping them up too long is a big part of combat, and a lot of weapons are balanced around the reflexes of the vanilla AI.
  • Good shield management is one of the few areas where the AI usually has an advantage over the player.
  • I expect something like this might take a lot of work to get right.
Not trying to discourage you, just want to make sure you've considered everything.

direfungasaur

  • Ensign
  • *
  • Posts: 4
    • View Profile
Re: Modding ShieldAPI
« Reply #2 on: August 21, 2019, 05:25:41 AM »

Thanks for the alternative, though unfortunately that's not quite what I'm looking for. I don't want to force the shield to be on all the time. What I want is that the shield has to be fully extended before it can be switched off. That's why I'm hoping to wrap the ShieldAPI and delay the off/toggleOff calls until the shield has fully extended. This is a simple decorator if I can just find how to pull the ShieldAPI instances from active combatants.

Right now there's an extend delay, but no corresponding drop delay, which lets the AI extend the shield exactly at the point of impact and quickly switch it back off again after the projectile has been consumed. They are smart enough to let shield-breaker rounds through to hit the armor when they have low flux, and not get into an override state. I don't see how I can do the same as a player, even with excellent reflexes, due to input and perception lag.

I see two main possibilities to solve this - 1) implement the lag mechanics I'm wanting to do or 2) give the player the same advantage by letting their shield by controlled by the AI. I think that 1) is more mechanically interesting, because it gives you the possibility to overload units more. Once the AI commits to using their shield, they have to deal with it being up for 1-3s which is closer to a player's response time. The second approach just makes the player's flux management easier, but doesn't seem as interesting from a gameplay mechanic.

I suppose worst case I could rewrite ShipAI, but that seems like a daunting affair I was hoping to avoid for now.

Thanks for the help, hopefully someone knows how to pull the ShipAIs out of the code. The Javadoc is extensive but has very little descriptive documentation explaining it's purpose. I'm finding it hard to understand the interconnections of systems. I've been a bit too spoiled by the power Harmony patches provides to Unity modders...
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Modding ShieldAPI
« Reply #3 on: August 21, 2019, 08:36:53 AM »

Thanks for the alternative, though unfortunately that's not quite what I'm looking for.
[snip]
...if I can just find how to pull the ShieldAPI instances from active combatants.
The code snippet I gave you wasn't meant to be a copy and paste alternative; it was meant to demonstrate how to access the ShieldAPI of each active combatant. The return value of ship.getShield() is a ShieldAPI instance.

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Modding ShieldAPI
« Reply #4 on: August 21, 2019, 09:08:18 AM »

As, well, the only person who ever built a general-purpose AI replacement for this game, I'd like to address a few things:

1.  To the best of my knowledge, the base AI doesn't actively "know" the state of the shield's arc.
2.  The AI controls the shields, just like a player does.
3.  In theory, you could "countermand" the AI's orders to close the shield by sending contradicting orders, but it largely wouldn't work well.

The right answer is to write a general-purpose AI to deal with this issue.  That... is a big job.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Modding ShieldAPI
« Reply #5 on: August 21, 2019, 09:36:13 AM »

What you'd probably want to do is call ship.blockCommandForOneFrame(ShipCommand.TOGGLE_SHIELD_OR_PHASE_CLOAK) while the shields are up but not fully extended. But, yeah, per Sundog's post, there are a lot of issues with this.

The AI's reflexes with shields are also intentionally slowed down, btw, to a point where it gets overloaded occasionally but not so frequently as to trivialize it. I think if you did do this, you'd probably find that the AI is very ineffective and shields are more of a liability than a bonus.

1.  To the best of my knowledge, the base AI doesn't actively "know" the state of the shield's arc.

(This is not true, the AI knows what the current shield coverage is and makes active use of this information.)
Logged

direfungasaur

  • Ensign
  • *
  • Posts: 4
    • View Profile
Re: Modding ShieldAPI
« Reply #6 on: August 21, 2019, 03:15:14 PM »

The code snippet I gave you wasn't meant to be a copy and paste alternative; it was meant to demonstrate how to access the ShieldAPI of each active combatant. The return value of ship.getShield() is a ShieldAPI instance.

Sundog,

First off, apologies if my reply came off as rude or unappreciative. I was posting when I was far too tired, and I'm afraid it was more rant than constructive rely. Sorry for the tone and I'll try to be better.

Thanks for the reference. I had stumbled across ship.getShield(), but I didn't see a way to wrap the instance and supply the wrapped version to the ShipAPI instance. I could only find the Ship.setShield(...) method, which takes a ShieldType instead. I'm assuming the types are hard-coded and not components, so I was struggling to figure out how to get the actual ShieldAPI implementation. I can always go the reflection route if absolutely necessary, I suppose. I was thinking it's better to wrap the instance than try to iterate over every combatant on each frame, since the latter is at least O(n^2). I will continue to poke around.

re: Xenoargh - I would really like to avoid a general purpose AI at this point. That's more investment than I wanted to commit to. I was hoping for a surgical fix because beyond this I'm generally very happy with StarSector!

re: Alex - thanks for the advice. It's a touch disappointing to hear more experienced folks indicating that the AI wouldn't support this kind of change well. It's such a point of frustration for me that I find it difficult to enjoy combat since I've noticed it. I'll try to brainstorm other solutions to the problem, it just seems like shield-breaking / overload is something that penalizes the player only and that rubs me the wrong way. I suppose I could grant the player ship the same level of 'instant shield' knowledge but that wasn't what I was really going for. Oh well, let's try something and see how it goes.

Thanks to everybody for the responses. I appreciate all the discussion!



Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: Modding ShieldAPI
« Reply #7 on: August 21, 2019, 03:34:57 PM »

From what you've described, I think you might find it more feasible to, instead of changing the AI, change the penalty for overloading?  Maybe boost the benefit of level 3 Damage Control to -50% overload duration (or more)?

Personally, the only part of this that really bothers me is with phase ships.  An AI phase ship will never overload - it's able to perfectly judge "do I have enough flux free to phase out?" or "Do I need to un-phase now to avoid fluxing out?", which makes the mechanics entirely player-facing, even more so than shields.  Making phase ships just fall out of phase (or not enter phase) if they don't have the flux to support it would be a much better option, imo.
Logged
Wyvern is 100% correct about the math.

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Modding ShieldAPI
« Reply #8 on: August 21, 2019, 03:53:12 PM »

Sundog,

First off, apologies if my reply came off as rude or unappreciative. I was posting when I was far too tired, and I'm afraid it was more rant than constructive rely. Sorry for the tone and I'll try to be better.
No worries! I don't think you came off as rude in any way.

By the way, welcome to the forum! I didn't notice your post count at first.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Modding ShieldAPI
« Reply #9 on: August 21, 2019, 04:13:15 PM »

It's a touch disappointing to hear more experienced folks indicating that the AI wouldn't support this kind of change well. It's such a point of frustration for me that I find it difficult to enjoy combat since I've noticed it. I'll try to brainstorm other solutions to the problem, it just seems like shield-breaking / overload is something that penalizes the player only and that rubs me the wrong way.

Hmm. I've got to be honest here - and I really don't want to come off as saying "git gud", so please don't take it that way - but I'm not sure I can agree with the premise here. The AI gets overloaded frequently, and in general I wouldn't say it's that much better - if at all better - than a player can be at this. If you're finding yourself overloading way more than the AI does, it's probably due to not paying enough attention.

The AI's not too bad at this; it's probably closer to "good player" with it than it is in some other aspects, so possibly that makes it stand out. A player might be a bit less effective in some flickering-intensive situations (though the AI is far from perfect and has built-in delays in its reactions), but the player will *definitely* be way better in making macro-level decisions such as "I need to tank hits on armor for a bit", so all in all, in terms of flux-related shield management, you can do much better than the AI can.

(I suspect you might be trying stuff like a shield-breaking loadout that doesn't mix in steady high-explosive damage, right? And then the AI lowers shields against it? That sort of thing is pretty easy to counter as the player, too... for shield-breaking to work, it needs to mix a bit of consistent HE to punish armor-tanking. Alternatively, enough sudden burst - say from Sabots - can, somewhat unreliably, overcome the enemy reflexes. That's actually one of the things it's tuned around, so that Sabots can overload AI ships veeeery roughly about half the time.)


An AI phase ship will never overload - it's able to perfectly judge "do I have enough flux free to phase out?" or "Do I need to un-phase now to avoid fluxing out?", which makes the mechanics entirely player-facing, even more so than shields.

I'm pretty positive I've seen phase ships overload when there's enough threat around. And, to be fair, much more so than shields, an overload in a phase ship is definitely a screwup...
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3786
    • View Profile
Re: Modding ShieldAPI
« Reply #10 on: August 21, 2019, 04:29:49 PM »

An AI phase ship will never overload - it's able to perfectly judge "do I have enough flux free to phase out?" or "Do I need to un-phase now to avoid fluxing out?", which makes the mechanics entirely player-facing, even more so than shields.

I'm pretty positive I've seen phase ships overload when there's enough threat around. And, to be fair, much more so than shields, an overload in a phase ship is definitely a screwup...
Hm.  I don't remember seeing an AI phase ship overload, but it's possible that it does happen and I haven't noticed because it's only come up in situations where the ship was dead no matter what it did.

I do know that I have, when up against certain mod-added phase ships with egregious armor values, managed to push them from the middle of the map to the map borders without them overloading, despite their being continuously at effectively max flux, constantly flickering out for just a second at a time, managing to retain just enough mobility to dodge every torpedo I sent its way...
Logged
Wyvern is 100% correct about the math.

direfungasaur

  • Ensign
  • *
  • Posts: 4
    • View Profile
Re: Modding ShieldAPI
« Reply #11 on: August 21, 2019, 05:36:37 PM »

From what you've described, I think you might find it more feasible to, instead of changing the AI, change the penalty for overloading?  Maybe boost the benefit of level 3 Damage Control to -50% overload duration (or more)?

Fair question. I'll have to sit and chew on it some more. I just know overload feels one-sided as a player punishment right now, but that could be my inexperience talking.

Hmm. I've got to be honest here - and I really don't want to come off as saying "git gud", so please don't take it that way - but I'm not sure I can agree with the premise here. The AI gets overloaded frequently, and in general I wouldn't say it's that much better - if at all better - than a player can be at this. If you're finding yourself overloading way more than the AI does, it's probably due to not paying enough attention.

Sure, 'git gud' might be one aspect to it. I've only played 10-15 hours, and I'm still mostly rocking the hammerhead I started with. I recently switched over it's loadout to 2x Heavy Autocannons and 2x Anhillator Rocket Launchers to try to mix anti-shield and anti-armor. I figured I'd bust the shields and rough up the armor, then duck back out and let some of my frigates pound on them while I burned flux. With 8k flux capacity and 420 flex dissipation I figured it might work. But my perception is that the AI is smart enough to let the AC shells through and shield-tank the rockets. The last few times I've tried in sims and against relatively even battles I tend to get overloaded when I dive in, before I can drop back to bleed of flux. At this point in gameplay (still probably early game) it feels like the AI can stun-lock me fairly easily (via overload or by forcing me to vent flux) while it seems nearly impossible for me to the same. I don't expect to punch above my weight class, but an even destroyer-on-destroyer fight I'd think would be a bit more balanced then it feels like it has been.

I'm certainly willing to entertain that my biases are limiting my tactical vision, but when I saw the game had modding support I figured I'd jump in the deep end and see what I could do. I was frustrated enough that I considered shelving the game, but given how enthralling it is in general I thought a shot at tweaking this annoyance was worth it.

By the way, welcome to the forum! I didn't notice your post count at first.

Thank you for the warm welcome!

Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Modding ShieldAPI
« Reply #12 on: August 21, 2019, 06:14:08 PM »

Sure, 'git gud' might be one aspect to it. I've only played 10-15 hours, and I'm still mostly rocking the hammerhead I started with. I recently switched over it's loadout to 2x Heavy Autocannons and 2x Anhillator Rocket Launchers to try to mix anti-shield and anti-armor. I figured I'd bust the shields and rough up the armor, then duck back out and let some of my frigates pound on them while I burned flux. With 8k flux capacity and 420 flex dissipation I figured it might work. But my perception is that the AI is smart enough to let the AC shells through and shield-tank the rockets. The last few times I've tried in sims and against relatively even battles I tend to get overloaded when I dive in, before I can drop back to bleed of flux. At this point in gameplay (still probably early game) it feels like the AI can stun-lock me fairly easily (via overload or by forcing me to vent flux) while it seems nearly impossible for me to the same. I don't expect to punch above my weight class, but an even destroyer-on-destroyer fight I'd think would be a bit more balanced then it feels like it has been.

Gave this kind of loadout a try just now to see how it feels! Fought a simulation Hammerhead and Enforcer (the first one of each). Seems like the AI will shield-tank the Heavy ACs until it's a bit over half flux, at which point it'll generally start armor-tanking. Ideally, it'd really armor-tank the ACs earlier; I'm also not seeing much shield-flickering going on - it pretty much just turns them off, and occasionally toggles them on to block the Annihilators. But, that's exactly what I'd be doing it its shoes; in a fight like that, that's what you want to keep an eye on - blocking bursty HE with your shields.

I'll say, though, this loadout is a bit tricky to fly. You have to engage the ammo feeder at the right time, keep facing the enemy, and then hit a moving target with Annihilators, which is not the easiest thing in the world. Plus, when facing destroyers, it's just *really* lacking in finishing power.

The Annihilators just don't cut it vs armor - I think this may be at the crux of what you're experiencing. This loadout has way better kinetic damage than it does HE, so pretty much no matter what, if it's facing decent armor, it'll end up hitting it a lot with ACs, which is inefficient and will lose you the flux war. The Annihilators are - in addition to being hard to hit with and a bit under-powered as a main source of HE - also bursty, making them easier to block with shields.

What I've observed flying it is I start winning the flux war very handily early on, but just can't capitalize after that. It seems like it could be a good support loadout, but it'd probably be better off mixing in more HE somehow. Either one Heavy Mortar, or two and kinetics in the two small forward-facing turrets, plus Sabots - something like that. Or even some Light Assault Guns in the small turrets, while keeping the Heavy ACs. It's a decent shield-cracker as is, just has no good follow-through.


I'm certainly willing to entertain that my biases are limiting my tactical vision, but when I saw the game had modding support I figured I'd jump in the deep end and see what I could do. I was frustrated enough that I considered shelving the game, but given how enthralling it is in general I thought a shot at tweaking this annoyance was worth it.

Fair enough, and I very much respect the impulse to mod things you don't like!
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Modding ShieldAPI
« Reply #13 on: August 21, 2019, 06:30:40 PM »

@direfungasaur: Everything Alex said about your hammerhead build is good advice. Skill in this game is as much about building ships well as piloting them well.

If you're finding yourself overloading way more than the AI does, it's probably due to not paying enough attention.
While I agree with you on this entirely, I think you could've helped him pay more attention by providing better visual/audio feedback. I often catch myself pausing to check my flux level when I suspect that I might be close to overloading. The post I made a few months ago was all about this sort of thing. Other people have suggested audio feedback as well. A tone that changes in pitch and/or volume between 75% and 95% flux might work well.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Modding ShieldAPI
« Reply #14 on: August 21, 2019, 06:47:45 PM »

Yeah, I did see it back then! Hmm. If anything, I'm more partial to a sound cue, but that could get annoying as well - I know there are times when I'm at maxed flux for a long time - so would have to be careful. Maybe if it only played when your shields are on...
Logged
Pages: [1] 2