Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: [1] 2

Author Topic: Why aren't my fleets engaging?  (Read 4895 times)

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Why aren't my fleets engaging?
« on: June 10, 2014, 08:15:10 PM »

I've hit a weird issue with the CampaignFleetAPI addAssignment() stuff again.

If I set it to the Player Fleet, the fleets aren't going and attacking the Player Fleet; they're going near to it, then running away, every time.

Needless to say, this isn't much fun, as I want them to attack the player's fleet when <condition> and not run away, even if that's "stupid".

What triggers this behavior from fleets?  How are they judging whether to attack or run away?
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #1 on: June 12, 2014, 10:12:17 AM »

Sooo... took a look at this, and it's weird.

I set all of the Captain / Admiral personalities to "fearless", and that changed nothing.  An Assault Fleet will attack a fleet consisting of a Destroyer, Frigate and a Civilian Cruiser, but nothing smaller than that.

So I armed all of my fake-fleet ships, just to see how that went; giving them all built-in MegaBeams didn't do any good.  I'll try setting it as non built-in next.  They already have shields and ridiculous stats.  What's the trigger here? 
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #2 on: June 12, 2014, 11:48:38 AM »

OK, I flipped all the fleet compositions back to "natural' fleets generated from the base templates, rather than my fake fleets. 

Result:  engagements improve a little, but only when the AI fleet has an overwhelming advantage in numbers. 

The AI fleets are scared to death of a few ships. 

I guess I need to write a custom fleet AI, lol; but I can't even guarantee that they'll engage even if I force them to get to the target.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #3 on: June 12, 2014, 11:52:34 AM »

For a fleet to actively want to engage another, its strength needs to be ~25% higher. The strength calculation is based on the fleet point cost and factors in the ordnance point fraction spent, the current CR, and whether the ship is flagged as civilian.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #4 on: June 12, 2014, 12:22:37 PM »

Hmm.  So if they've spent all their OPs (or more) and their CR is maxed and they aren't Civvie, they get a bonus to aggro? 

OK, let's see if I can get this sucker straightened out...

BTW, I tried out setMoveDestinationOverride(), and, er, it appears that fleets don't make engagement happen until they have point-point equivalance, rather than circle-circle.  That, and it doesn't appear to be able to force an engagement.

Hmm.  Another thought on this; I could simply raise the distance at which engagements can happen by starting up a fleet dialog if players are within <some number>; that'd really confuse newbies to the mod, though.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #5 on: June 12, 2014, 12:34:49 PM »

It's circle-circle, but you also need to fleet.setInteractionTarget(playerFleet). That's what'll trigger the dialog.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #6 on: June 12, 2014, 12:42:25 PM »

I've got to get them to quit running away, first.

Hrmm.  Boosted CR to 2 when the fleets spawn; they have a 30:1 ratio of OPs vs. weapons (put a 30-point weapon on them with one OP).  They still aren't acting very aggro.  If I raise the FPs, that'll probably work, but then I'll lose the circle-size adjustments, though.

Let's see what happens when I force them and give them their interaction target...
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #7 on: June 12, 2014, 04:38:07 PM »

Well, if they're forced and they have an interaction target, they're finally engaging, but not consistently enough; even if the player's fleet is the target and it's sitting still, it takes them forever to engage.  It really appears that setMoveDestinationOverride() doesn't override their "fear factor":

Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #8 on: June 12, 2014, 04:47:34 PM »

Code I'm using to implement forced stuff- really basic but it should work:

Spoiler
Code: java
package data.scripts;

import java.util.List;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.*;

import com.fs.starfarer.api.EveryFrameScript;
import java.util.Collections;
import org.lazywizard.lazylib.CollectionUtils;
import org.lazywizard.lazylib.campaign.FleetUtils;

@SuppressWarnings("unchecked")
public class FleetAIScript implements EveryFrameScript {

    //EveryFrameScripts must implement these
    @Override
    public boolean isDone()
    {
        return false;
    }

    @Override
    public boolean runWhilePaused()
    {
        return false;
    }

    @Override
    public void advance(float amount)
    {
       
        List<CampaignFleetAPI> fleets = Global.getSector().getCurrentLocation().getFleets();
       
        for(CampaignFleetAPI fleet : fleets){
            if(fleet.getName().equalsIgnoreCase("raiding party")){
                fleet.clearAssignments();
                List<CampaignFleetAPI> enemyFleets = FleetUtils.getEnemyFleetsInSystem(fleet);
                Collections.sort(enemyFleets,new CollectionUtils.SortTokensByDistance(fleet.getLocation()));
                for(CampaignFleetAPI enemyFleet : enemyFleets){
                    if(enemyFleet.getName().equalsIgnoreCase("raiding party")
                        || enemyFleet.getName().equalsIgnoreCase("system police")
                        || (enemyFleet.isPlayerFleet() && Global.getSector().getPlayerFleet().getCommanderStats().getLevel() < 10)){
                        fleet.setMoveDestinationOverride(enemyFleet.getLocation().x,enemyFleet.getLocation().y);
                        fleet.setInteractionTarget(enemyFleet);
                    }
                }
            }
        }
    }
}
[close]
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #9 on: June 12, 2014, 06:00:44 PM »

Looked into this:

It'll say "running from your fleet" if it's weaker, but they should still move to pursue the player's fleet.

Code: java
CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
for (CampaignFleetAPI fleet : Global.getSector().getCurrentLocation().getFleets()) {
if (fleet.getName().toLowerCase().contains("scout")) {
fleet.setMoveDestinationOverride(playerFleet.getLocation().x, playerFleet.getLocation().y);
}
}

Tested using the above code in an EveryFrameScript, it worked, regardless of player fleet strength.

As far as getting the dialog to pop up, looks like setting the interaction target won't work. You'll have to show it yourself when it gets in range.

If you need to make AI vs AI fights happen, you can call the BattleAutoresolverPluginImpl directly. For the player vs AI interaction dialog, you might have to tweak the dialog plugin so that the AI always wants to fight, instead of asking the fleet's AI whether it wants to fight (which it might not). Take a look at the FleetInteractionDialogPluginImpl.otherFleetWantsToFight() to see where that hooks in.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #10 on: June 12, 2014, 06:13:07 PM »

Hrmm.  It's not doing that over here. 

I'll disable all of the other code that can re-direct / give behaviors and see what it does; I must be overriding my code over here somehow by giving Assignments.  But shouldn't clearAssignments() fix that?

As for AI responses to encounters, that's all custom; I don't even refer to the Vanilla structures at all atm, including the CampaignFleetAI.

I can always trigger the Dialog early, for player-AI stuff (which is one of the two goals; I also want certain types of fleets to attack other types more consistently to generate more interesting behavior patterns); I'm just not getting the AI fleets close enough together do any good atm; they're approaching the Player fleet, then running away before they get close enough to engage, which is fixable via fiat, but ideally, I'd like the circles to touch, to preserve that aspect of how Vanilla works :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #11 on: June 12, 2014, 06:24:45 PM »

Hm, you shouldn't even have to call clearAssignments(). As long as you're calling setMoveDestinationOverride() every frame, it'll override whatever move destination the AI is giving the fleet.

I suppose calling setLocation() to move the fleet more directly could be a fallback, but what you're doing should work. I don't understand why it wouldn't, and it seems to work here. I don't think I changed anything pertaining to that recently.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #12 on: June 12, 2014, 06:38:31 PM »

It's probably something silly I'm doing over here anyhow; let me eliminate all of the factors that might be putting a spanner in the works and test it out.  That'll take a minute; juggling stuff from Work tonight :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #13 on: June 12, 2014, 07:49:53 PM »

OK, did a quick test.  All fleet behaviors were turned OFF- no active Assignments.  This worked:

Spoiler
Code: java
package data.scripts;

import java.util.List;

import com.fs.starfarer.api.Global;

import com.fs.starfarer.api.EveryFrameScript;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import java.util.Collections;
import org.lazywizard.lazylib.CollectionUtils;
import org.lazywizard.lazylib.MathUtils;
import org.lazywizard.lazylib.campaign.FleetUtils;

@SuppressWarnings("unchecked")
public class FleetAIScript implements EveryFrameScript {

    //EveryFrameScripts must implement these
    @Override
    public boolean isDone()
    {
        return false;
    }

    @Override
    public boolean runWhilePaused()
    {
        return false;
    }

    @Override
    public void advance(float amount)
    {
       
        List<CampaignFleetAPI> fleets = Global.getSector().getCurrentLocation().getFleets();
       
        for(CampaignFleetAPI fleet : fleets){
            if(fleet.getName().toLowerCase().contains("raiding party")){
                List<CampaignFleetAPI> enemyFleets = FleetUtils.getEnemyFleetsInSystem(fleet);
                for(CampaignFleetAPI enemyFleet : enemyFleets){
                    if(MathUtils.getDistance(fleet,enemyFleet) < 1000f){
                        if(enemyFleet.getName().toLowerCase().contains("raiding party")
                            || enemyFleet.getName().toLowerCase().contains("system police")
                            || (enemyFleet.isPlayerFleet() && Global.getSector().getPlayerFleet().getCommanderStats().getLevel() < 10)){
                            fleet.setMoveDestinationOverride(enemyFleet.getLocation().x,enemyFleet.getLocation().y);
                            fleet.setInteractionTarget(enemyFleet);
                        }
                    }
                }
            }
        }
    }
}
[close]

Fleets with this code will now attack suicidally (which is a good thing, as they were previously rather gun-shy, to the point of not acting like raiders or being at all scary to players) if they're closer than X. 

I haven't tested whether this will override normal behavior properly or not; if yes... tbh, I'm kind of tempted to write a complete Fleet AI (why not, lol), except that then the game's doing double work, since we can't do that via a Plugin :)

I'm kind of scratching my head about why that previous stuff didn't work right.  It looks like some of the issue was the sorting code; I probably need to do some work to ensure good behaviors.  Now I'll test with the core behaviors enabled again and see if it's still kosher; if yes, then I need to think about whether I want to write up a complete Fleet AI system or not. 

Now that I have some ideas about why I'm seeing certain behaviors, it's tempting to just replace it with a fiat AI that does exactly what I want.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: Why aren't my fleets engaging?
« Reply #14 on: June 12, 2014, 07:57:41 PM »

Cool. The sorting code does seem like a likely culprit, the fleet going off after something other than the nearest target might well look like running away.

Yeah, I've got to make fleet AI pluggable at some point. I'll probably do that around the time I end up having to rewrite it. I don't think it's particularly performance intensive, btw, but I guess that depends on how many fleets you've got.

A couple of things to watch out for: hyperspace jumps and no-fuel drifting use the movement override, so your custom AI would have to be careful to detect those conditions and stop calling the override method until they're over. Also, you do want to clearAssignments() - otherwise, the fleet might decided to jump if near enough a jump point and it's what the AI wants to do. It might still jump anyway if it thinks its pursuing something through a jump point, even if it's not. All in all: custom AI via movement override should generally work, but might have a few rough spots.
Logged
Pages: [1] 2