Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: [SOLVED] Problem while trying to make hullmod that makes ships auto retreat++  (Read 1216 times)

creature

  • Captain
  • ****
  • Posts: 400
    • View Profile

As the title says, I'm trying to make a hullmod that forces ships that have it to auto retreat when CR reaches < 30%.

To force the retreat, I was pointed to this code:

Code: java
            boolean retreatDirectly = true;
            ship.setRetreating(true, retreatDirectly);

However, the code below, inside a hullmod class, doesn't seem to make any ship retreat (100% sure all ships that should retreat have the mod).

As you can see, it also does something else apart from forcing a retreat - the code also sets CR to the percentage of HP, down to a minimum of 30% (at which time the ship should forcibly retreat).

Code: java
    @Override
    public void advanceInCombat(ShipAPI ship, float amount) {

    CombatEngineAPI engine = Global.getCombatEngine();
    float potentialMaxCR = ship.getHitpoints()/ship.getMaxHitpoints();
   
    if(ship.getCurrentCR() > potentialMaxCR) {
    if(potentialMaxCR >= 0.30) {
        ship.setCurrentCR(potentialMaxCR);
    }else {
    boolean retreatDirectly = true;
          ship.setRetreating(true, retreatDirectly);
    }
    }]
« Last Edit: November 10, 2019, 06:06:37 PM by creature »
Logged

Alex

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

Just super quick, see:
CombatTaskManagerAPI.orderRetreat()

Would have to dig around the javadoc to figure out how to get at it/what parameters to pass in; I'll see if I have a chance to elaborate a bit later!
Logged

creature

  • Captain
  • ****
  • Posts: 400
    • View Profile

Just super quick, see:
CombatTaskManagerAPI.orderRetreat()

Would have to dig around the javadoc to figure out how to get at it/what parameters to pass in; I'll see if I have a chance to elaborate a bit later!
Thanks for the quick reply Alex! I actually tried this one before the one above, but with similar results... I'll try them both at the same time next.

-> I also tried them both, but still to no effect. I wonder though, should the command only be executed once to work? Because the code runs every frame at the moment...
Logged

Sinosauropteryx

  • Captain
  • ****
  • Posts: 262
    • View Profile

Try this, it worked for me.

Code
if (!ship.isRetreating())
Global.getCombatEngine().getFleetManager(ship.getOwner()).getTaskManager(false).orderRetreat(Global.getCombatEngine().getFleetManager(ship.getOwner()).getDeployedFleetMember(ship), true, true);

I wonder though, should the command only be executed once to work? Because the code runs every frame at the moment...
Yes, running it every frame seems to mess with it.
Logged

I_is_nublet

  • Lieutenant
  • **
  • Posts: 51
    • View Profile

You could probably ask Phoenix how he did #2 in this mod.

https://fractalsoftworks.com/forum/index.php?topic=17173.0

Since it relies on the hullmod getting down to 20% before it allows the ship to use zero-flux speeds. He might be using something other than a continuous check, but again. Talk to him and ask him.
Logged

creature

  • Captain
  • ****
  • Posts: 400
    • View Profile

Try this, it worked for me.

Code
if (!ship.isRetreating())
Global.getCombatEngine().getFleetManager(ship.getOwner()).getTaskManager(false).orderRetreat(Global.getCombatEngine().getFleetManager(ship.getOwner()).getDeployedFleetMember(ship), true, true);

This one worked! Thank you very much!

I wonder which part of the chain my code got wrong though... it seems you got the task manager via

Code
ship.getOwner()).getTaskManager(false)


instead of

       
Code
CombatFleetManagerAPI fleetManager = engine.getFleetManager(FleetSide.PLAYER);
    CombatTaskManagerAPI taskManager = fleetManager.getTaskManager(true);

So maybe that's where the problem was?
Logged

Sinosauropteryx

  • Captain
  • ****
  • Posts: 262
    • View Profile

I think the only real difference is I put getTaskManager(false) instead of (true). Glad it's working :)
Logged

creature

  • Captain
  • ****
  • Posts: 400
    • View Profile

Hmm, the parameter said
Code
 boolean ally
, so I gave it a true, but I guess it should have been false? A bit confusing.  ???
Logged

Sinosauropteryx

  • Captain
  • ****
  • Posts: 262
    • View Profile

If I recall, "ally' usually means those allied ships with yellow stat bars, not your own fleet's ships.
Logged

creature

  • Captain
  • ****
  • Posts: 400
    • View Profile

Ah, I right! I don't usually see them so I forgot they even exist.  ;D
Logged