Starsector API
Loading...
Searching...
No Matches
MissionFleetAutoDespawn.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.missions.hub;
2
3import com.fs.starfarer.api.EveryFrameScript;
4import com.fs.starfarer.api.Global;
5import com.fs.starfarer.api.campaign.CampaignEventListener.FleetDespawnReason;
6import com.fs.starfarer.api.campaign.CampaignFleetAPI;
7import com.fs.starfarer.api.campaign.FleetAssignment;
8import com.fs.starfarer.api.campaign.ai.FleetAssignmentDataAPI;
9import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
10import com.fs.starfarer.api.impl.campaign.ids.Factions;
11import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
12import com.fs.starfarer.api.impl.campaign.missions.DelayedFleetEncounter;
13import com.fs.starfarer.api.util.Misc;
14
16
17 protected CampaignFleetAPI fleet;
18 protected float elapsedWaitingForDespawn = 0f;
19 protected float elapsed = 0f;
21
22 public MissionFleetAutoDespawn(HubMission mission, CampaignFleetAPI fleet) {
23 this.mission = mission;
24 this.fleet = fleet;
25 }
26
27 protected int framesWithNoAssignment = 0;
28 public void advance(float amount) {
29 elapsed += amount;
30// System.out.println("MFAD: " + fleet.getName());
31// if (fleet.getName().equals("Courier")) {
32// System.out.println("fwefwf23f");
33// }
34// System.out.println(fleet.getName());
35// if (fleet.getName().equals("Mercenary Bounty Hunter")) {
36// System.out.println("efwefweew");
37// }
38 boolean missionImportant = fleet.getMemoryWithoutUpdate().getBoolean(MemFlags.ENTITY_MISSION_IMPORTANT);
39 FleetAssignmentDataAPI ad = fleet.getCurrentAssignment();
40 // make a hopefully reasonable guess that the fleet should stop chasing the player, if that's what it's doing
41 // it it's not "important" (i.e. likely wrong mission stage) and not in the same location and far away
42 if (ad != null &&
43 (ad.getAssignment() == FleetAssignment.INTERCEPT || ad.getAssignment() == FleetAssignment.FOLLOW) &&
44 ad.getTarget() == Global.getSector().getPlayerFleet() &&
45 !missionImportant && elapsed > 10f) {
46 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
47 if (!fleet.isInCurrentLocation()) {
48 float dist = Misc.getDistanceLY(fleet, Global.getSector().getPlayerFleet());
49 if (dist > 4f) {
50 fleet.removeFirstAssignment();
51 if (fleet.getCurrentAssignment() == null) {
52 Misc.giveStandardReturnToSourceAssignments(fleet);
53 }
54 }
55 }
56 else if (fleet.isHostileTo(pf) && fleet.getFaction() != null &&
57 !fleet.getFaction().isHostileTo(Factions.PLAYER) &&
58 !(mission instanceof DelayedFleetEncounter)) {
59 fleet.removeFirstAssignment();
60 if (fleet.getCurrentAssignment() == null) {
61 Misc.giveStandardReturnToSourceAssignments(fleet);
62 }
63 }
64 }
65
66// clean up, figure out details of exactly how to do this
67// - don't want to do it super quick when still during the mission
68// - probably want to give some kind of assignment if there's nothing left after removing the intercept
69// - and also when the mission's ended, give return assignments too? still auto-despawn! just, have it
70// be returning instead of sitting around waiting
71
72 if (isMissionEnded()) {
73 if (fleet.getCurrentAssignment() == null) {
74 Misc.giveStandardReturnToSourceAssignments(fleet);
75 }
76
77 if (!fleet.isInCurrentLocation() && Misc.getDistanceToPlayerLY(fleet) > 3f) {
78 elapsedWaitingForDespawn += Global.getSector().getClock().convertToDays(amount);
79 if (elapsedWaitingForDespawn > 30f && fleet.getBattle() == null) {
80 fleet.despawn(FleetDespawnReason.PLAYER_FAR_AWAY, null);
82 }
83 } else {
85 }
86
87 } else if (fleet.isInCurrentLocation() && fleet.getCurrentAssignment() == null) {
89 if (framesWithNoAssignment >= 10) {
90 Misc.giveStandardReturnToSourceAssignments(fleet);
91 }
92 } else {
94 }
95 }
96
97 public boolean isMissionEnded() {
98 return mission instanceof IntelInfoPlugin && (((IntelInfoPlugin)mission).isEnded() || ((IntelInfoPlugin)mission).isEnding());
99 }
100
101 public boolean isDone() {
102 return false;
103 }
104
105 public boolean runWhilePaused() {
106 return false;
107 }
108
109
110}
111
112
113
114
115
116
117
118
119
120
static SectorAPI getSector()
Definition Global.java:59