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: Toggleable shipsystems not calling apply() during chargedown and AI control  (Read 1713 times)

Nicke535

  • Commander
  • ***
  • Posts: 240
  • Degenerate Core
    • View Profile

Hello. I may have stumbled upon an issue I don't know is an actual bug or simply intended but strange behaviour, but I figured I should make a thread about it just in case (if this does in fact not belong in this subforum, I would be grateful if it is moved to the correct subforum).

Due to the nature of the problem, screenshots are hard, but I'll try: essentially, the left image is me deactivating a toggleable system (normal systems do not exhibit this behaviour) which simply displays the current effectLevel of the shipsystem via Global.getCombatEngine().addFloatingText(). The right image is the exact same thing, but now deactivated by the AI (the venting happened afterwards due to flux, the shipsystem prevents venting [i turned this off afterwards, the behaviour remains the same]).



For some inexplicable reason, it appears as though an AI-controlled ship does not run apply() at all during the charge-down phase of a toggleable shipsystem. After running some additional tests, this seems to hold true. I cannot fathom a reason for this to be the intended behaviour, so I am submitting it as a bug.

POSTSCRIPT: After writing all this, I found out an equally worrying fact: unapply() is called in the charge-down phase for AI-controlled ships, but not for player-controlled ones. This further cements my suspicion that this is, in fact, a bug.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile

Hmm. Some quick testing with Fortress Shield seems to run counter to your results. Adding this in the apply() method:

System.out.println("level: " + effectLevel);

The level gets printed both going up and down when under AI control. Also, there's no apparent reason for why a system would function differently based on whether the player or an AI is controlling the ship. Not to say it's impossible, but it seems very unlikely since the AI generally controls ships the same way the player does.

It's possible that a particular system AI - especially a custom one - could control a ship system in ways that run counter to that (i.e. calling unapply() manually, hard-toggling the system off, etc), but then that'd be specific to that AI, not system code.

(Let me move this to modding; probably a better place for it.)

Edit: it's of course possible that I changed something and we're not looking at the same code. But - it seems like a few systems (in vanilla, most notably fortress shield?) would be highly broken if what you're observing was indeed consistently the case, right?
« Last Edit: July 01, 2018, 12:32:37 PM by Alex »
Logged

Nicke535

  • Commander
  • ***
  • Posts: 240
  • Degenerate Core
    • View Profile

Yeah, that's why I was confused; so many things should break if this was the case. I'll try finding any weird factors that may be in play (it is running a custom AI, but it doesn't call unapply() manually).

Oh, and sorry about misplacing the thread: now that you mention it, Modding is a better place for it.

EDIT: I may have found the issue, but am unsure: would calling system.deactivate() while in charge-down directly move it to unapply()? If so, that explains the behaviour, as I forgot to check if the system is already deactivating before calling deactivate().
« Last Edit: July 02, 2018, 02:58:13 AM by Nicke535 »
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile

Ah, yeah, you generally want to call LazyWizard's AIUtils.canUseSystemThisFrame(shipAPI ship) which checks all statuses.

Straightforward control loop:

Code
        tracker.advance(amount);
        if (tracker.intervalElapsed())
        {
            boolean otherControlBooleanState = false;
            //---> control the state of otherControlBooleanState here
            
            //If the above is true and canUseSystemThisFrame is true, then proceed.
            // If system is inactive and should be active, enable it.
            if(otherControlBooleanState && AIUtils.canUseSystemThisFrame(ship))
            {
                ship.useSystem();
            }
        }
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile

Oh, and sorry about misplacing the thread: now that you mention it, Modding is a better place for it.

No worries! Generally if you're *sure* it's a bug, then bug reports is the place, but if not quite sure, then modding is probably better, possibly combined with a prod-via-PM if I don't happen to spot it within a day or so.

EDIT: I may have found the issue, but am unsure: would calling system.deactivate() while in charge-down directly move it to unapply()? If so, that explains the behaviour, as I forgot to check if the system is already deactivating before calling deactivate().

Yeah, I think that'd cause unapply() on the same/next frame. Generally if you want to turn a system off "normally" you'd give a USE_SYSTEM command to the ship. deactivate() just shuts it down (near)instantly.
Logged