132 if (fleets.isEmpty()) {
140 if (!
interval.intervalElapsed())
return;
146 Set<LocationAPI> locations =
new LinkedHashSet<LocationAPI>();
147 Set<LocationAPI> locationsWithBattles =
new LinkedHashSet<LocationAPI>();
151 for (CampaignFleetAPI fleet : fleets) {
152 LocationAPI conLoc = fleet.getContainingLocation();
153 locations.add(conLoc);
154 if (fleet.getBattle() !=
null) {
155 locationsWithBattles.add(conLoc);
158 if (
to.getContainingLocation() == conLoc) {
160 }
else if (
from.getContainingLocation() == conLoc && !conLoc.isHyperspace()) {
169 for (CampaignFleetAPI fleet : fleets) {
170 if (
doNotGetSidetracked && !locationsWithBattles.contains(fleet.getContainingLocation())) {
171 fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_FLEET_DO_NOT_GET_SIDETRACKED,
true, 0.4f);
175 boolean allInSameLocation = locations.size() == 1;
177 if (allInSameLocation && inTo > 0 &&
to.getContainingLocation() instanceof StarSystemAPI) {
179 StarSystemAPI system = (StarSystemAPI)
to.getContainingLocation();
180 if (
to == system.getCenter()) {
187 if (allInSameLocation) {
188 boolean allNear =
true;
190 Vector2f com =
new Vector2f();
192 String key =
"$FGTravelAction_ignoreFleetForCenterOfMass";
193 for (CampaignFleetAPI fleet : fleets) {
194 boolean near = fleet.getContainingLocation() ==
to.getContainingLocation() &&
195 Misc.getDistance(fleet,
to) <
to.getRadius() + 500f;
198 if (Misc.isSlowMoving(fleet)) {
199 fleet.getMemoryWithoutUpdate().set(key,
true, 2f);
201 if (fleet.getMemoryWithoutUpdate().getBoolean(key)) {
205 float w = fleet.getFleetPoints();
206 Vector2f loc =
new Vector2f(fleet.getLocation());
208 Vector2f.add(com, loc, com);
214 if (!fleets.isEmpty()) {
215 com.set(fleets.get(0).getLocation());
218 com.scale(1f / weight);
220 Vector2f dest =
null;
222 JumpPointAPI jp = RouteLocationCalculator.findJumpPointToUse(fleets.get(0),
from);
223 dest = jp.getLocation();
224 }
else if (inHyper > 0) {
225 JumpPointAPI jp = RouteLocationCalculator.findJumpPointToUse(fleets.get(0),
to);
226 SectorEntityToken jumpExit =
null;
227 for (JumpDestination jd : jp.getDestinations()) {
228 if (jd.getDestination() !=
null && jd.getDestination().isInHyperspace()) {
229 jumpExit = jd.getDestination();
233 if (jumpExit !=
null) {
234 dest = jumpExit.getLocation();
236 dest =
to.getLocationInHyperspace();
239 dest =
to.getLocation();
247 float angle = Misc.getAngleInDegrees(com, dest);
248 float distComToDest = Misc.getDistance(com, dest);
249 float offset = Math.min(distComToDest, 5000f);
251 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(angle);
253 dest =
new Vector2f(dest);
254 Vector2f.add(com, dir, dest);
256 SectorEntityToken movementToken = fleets.get(0).getContainingLocation().createToken(dest);
259 float comLeashRange = 750f;
260 int numFleets = fleets.size();
261 comLeashRange += Math.min(Math.max(numFleets - 5, 0) * 100f, 500f);
263 for (CampaignFleetAPI fleet : fleets) {
264 fleet.clearAssignments();
275 float toCom = Misc.getDistance(fleet.getLocation(), com);
276 float toDest = Misc.getDistance(fleet.getLocation(), dest);
278 if (inTo > 0 && distComToDest < 500f +
to.getRadius() && toCom < 500f) {
280 }
else if (inTo <= 0 && toCom < 1000 && (toDest < 750 || distComToDest < 500f)) {
282 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION,
to, 3f,
travelText);
284 }
else if (toCom > comLeashRange) {
285 angle = Misc.getAngleInDegrees(fleet.getLocation(), com);
286 dir = Misc.getUnitVectorAtDegreeAngle(angle);
289 Vector2f overshootCom = Vector2f.add(com, dir,
new Vector2f());
290 SectorEntityToken comToken = fleets.get(0).getContainingLocation().createToken(overshootCom);
291 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, comToken, 3f,
travelText);
293 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, movementToken, 3f,
travelText);
303 SectorEntityToken rendezvous =
null;
305 JumpPointAPI jp = RouteLocationCalculator.findJumpPointToUse(fleets.get(0),
from);
313 SectorEntityToken jumpExit =
null;
314 for (JumpDestination jd : jp.getDestinations()) {
315 if (jd.getDestination() !=
null && jd.getDestination().isInHyperspace()) {
316 jumpExit = jd.getDestination();
320 if (jumpExit !=
null) {
321 rendezvous = jumpExit;
325 List<SectorEntityToken> potential =
new ArrayList<SectorEntityToken>();
326 for (CampaignFleetAPI fleet : fleets) {
327 if (fleet.getContainingLocation() ==
to.getContainingLocation()) {
328 SectorEntityToken test = Misc.findNearestJumpPointTo(fleet);
336 float bestScore = Float.MAX_VALUE;
337 for (SectorEntityToken curr : potential) {
339 for (CampaignFleetAPI fleet : fleets) {
340 if (fleet.getContainingLocation() ==
to.getContainingLocation()) {
341 float dist = Misc.getDistance(curr, fleet);
342 score += dist * fleet.getFleetPoints();
345 if (score < bestScore) {
352 if (rendezvous ==
null) {
358 for (CampaignFleetAPI fleet : fleets) {
359 fleet.clearAssignments();
361 if (fleet.getContainingLocation() != rendezvous.getContainingLocation()) {
363 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION,
to, 3f,
travelText);
365 float dist = Misc.getDistance(rendezvous, fleet);