I've been poking at the fleet assignments, and wanted to confirm my understanding of their behavior. I set up a test using code like this:
public class AssignmentCompletedScript implements Script {
private CampaignFleetAPI fleet;
private String comment;
private Long creationTime;
public AssignmentCompletedScript(CampaignFleetAPI fleet, String comment){
this.fleet = fleet;
this.comment = comment;
this.creationTime = Global.getSector().getClock().getTimestamp();
}
@Override
public void run() {
CampaignFleetAI.FleetAssignmentData currentAssignment = ((CampaignFleet)fleet).getAI().getCurrentAssignment();
Float daysSinceCreation = Global.getSector().getClock().getElapsedDaysSince(creationTime);
System.out.println("Assignment '"+comment+
"' completed after "+daysSinceCreation.toString()+
" days; current assignment"+
" "+currentAssignment.assignment.toString()+
" "+currentAssignment.target.getFullName());
}
}
Somewhere else I do this:
CampaignFleetAPI fleet = sector.createFleet("pirates", "raiders1");
location.spawnFleet(anchor, 1000, 1000, fleet);
fleet.setPreferredResupplyLocation(anchor);
fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, anchor.getOrbit().getFocus(), 3, new AssignmentCompletedScript(fleet, "go to planet"));
fleet.addAssignment(FleetAssignment.DEFEND_LOCATION, anchor, 6, new AssignmentCompletedScript(fleet, "defend station"));
fleet.addAssignment(FleetAssignment.RESUPPLY, anchor, 9, new AssignmentCompletedScript(fleet, "resupply"));
fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, anchor, 12, new AssignmentCompletedScript(fleet, "despawn"));
Here's what I get in the log:
Assignment 'go to planet' completed after 0.77313656 days; current assignment DEFEND_LOCATION Tri-Tachyon Orbital Station
Assignment 'defend station' completed after 6.7509837 days; current assignment RESUPPLY Tri-Tachyon Orbital Station
Assignment 'resupply' completed after 7.0035534 days; current assignment GO_TO_LOCATION_AND_DESPAWN Tri-Tachyon Orbital Station
Assignment 'despawn' completed after 7.0035534 days; current assignment GO_TO_LOCATION_AND_DESPAWN Tri-Tachyon Orbital Station
I've been trying to figure out how the actual timing of the events corresponds to the durations I requested, and I think I understand it:
1. GO_TO_LOCATION completes when the fleet reaches the planet
2. DEFEND_LOCATION starts when GO_TO_LOCATION finishes
3. DEFEND_LOCATION finishes after running for just under 6 days, and RESUPPLY is activated.
4. RESUPPLY completes when the fleet reaches the station, and GO_TO_LOCATION_AND_DESPAWN is activated
5. GO_TO_LOCATION_AND_DESPAWN completes immediately, since the fleet is still at the station (hasn't moved since resupplying)
Based on that, it looks to me like the assignment system is a simple queue, and items are removed either when they've run for their requested duration, or the goal is achieved. It's unclear to me what happens, though, when a goal expires without being achieved - say the location can't be reached in time, or the target can't be attacked because it's too fast or ceased to exist before we could reach it. Other than checking if the fleet is where we expected it to be, or if the target is dead, etc, does the onCompleted callback have any way to tell if the assignment was successful or not?
On a somewhat unrelated note, what happens if we don't call setPreferredResupplyLocation on the fleet? In that case, are we responsible for telling it to resupply on its own (with a RESUPPLY assignment)? I've been trying to figure out how to work around the "resupplying fleets transfer cargo to the station and create new cargo out of thin air" issue, since it's somewhat unbalancing if you're trying to actually control resources.
It'd be nice if we had some sort of API for AI interaction with SectorEntityTokens that was similar to the battle autoresolver API and could handle the various goals (attack, resupply, despawn, transfer cargo x, etc) but absent that, the onCompleted callback gets us part of the way there, since we can just tell the fleet to move somewhere and then do what we really want in the callback. The mouseover tooltip loses some of its usefulness since everything will just say "going to x" but that's why we need a SectorEntityToken mouseover API too