1package com.fs.starfarer.api.impl.campaign.procgen.themes;
5import org.lwjgl.util.vector.Vector2f;
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.Script;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.FleetAssignment;
11import com.fs.starfarer.api.campaign.LocationAPI;
12import com.fs.starfarer.api.campaign.SectorEntityToken;
13import com.fs.starfarer.api.campaign.StarSystemAPI;
14import com.fs.starfarer.api.impl.campaign.fleets.RouteLocationCalculator;
15import com.fs.starfarer.api.impl.campaign.fleets.RouteManager.RouteData;
16import com.fs.starfarer.api.impl.campaign.fleets.RouteManager.RouteSegment;
17import com.fs.starfarer.api.util.Misc;
21 public static enum TravelState {
47 if (segment.isInSystem()) {
48 return TravelState.IN_SYSTEM;
51 if (segment.hasLeaveSystemPhase() && segment.getLeaveProgress() < 1f) {
52 return TravelState.LEAVING_SYSTEM;
54 if (segment.hasEnterSystemPhase() && segment.getEnterProgress() > 0f) {
55 return TravelState.ENTERING_SYSTEM;
58 return TravelState.IN_HYPER_TRANSIT;
63 case ENTERING_SYSTEM: {
64 if (segment.to !=
null) {
65 return segment.to.getContainingLocation();
67 return segment.from.getContainingLocation();
70 case IN_SYSTEM:
return segment.from.getContainingLocation();
71 case LEAVING_SYSTEM:
return segment.from.getContainingLocation();
80 if (
fleet.getContainingLocation() !=
null) {
81 fleet.getContainingLocation().removeEntity(
fleet);
83 conLoc.addEntity(
fleet);
87 fleet.setFacing((
float) Math.random() * 360f);
97 protected void advance(
float amount,
boolean withReturnAssignments) {
99 RouteSegment current =
route.getCurrent();
100 if (current !=
null && current.from !=
null &&
101 Misc.getDistance(
fleet.getLocation(), current.from.getLocation()) < 1000f) {
102 fleet.clearAssignments();
103 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, current.from, 1000f,
104 "returning to " + current.from.getName());
106 Misc.giveStandardReturnToSourceAssignments(
fleet);
111 super.advance(amount);
123 if (segment.from ==
route.getMarket().getPrimaryEntity()) {
124 return "orbiting " +
route.getMarket().getName();
130 SectorEntityToken to = segment.to;
131 if (to ==
null) to = segment.from;
132 if (to ==
null) to =
route.getMarket().getPrimaryEntity();
133 return "returning to " + to.getName();
143 RouteSegment current =
route.getCurrent();
144 if (current ==
null)
return;
146 List<RouteSegment> segments =
route.getSegments();
147 int index =
route.getSegments().indexOf(
route.getCurrent());
150 if (index == 0 &&
route.getMarket() !=
null && !current.isTravel()) {
151 if (current.getFrom() !=
null && (current.getFrom().isSystemCenter() || current.getFrom().getMarket() !=
route.getMarket())) {
159 if (index == segments.size() - 1 &&
route.getMarket() !=
null && !current.isTravel()
160 && (current.elapsed >= current.daysMax || current.getFrom() ==
route.getMarket().getPrimaryEntity())) {
166 if (current.isTravel()) {
167 if (index == segments.size() - 1 &&
168 fleet.getContainingLocation() == current.to.getContainingLocation() &&
169 current.elapsed >= current.daysMax) {
178 if (!current.isTravel()) {
184 SectorEntityToken from = current.getFrom();
185 if (from ==
null) from =
route.getMarket().getPrimaryEntity();
188 float progress = current.getProgress();
189 RouteLocationCalculator.setLocation(
fleet, progress, from, from);
191 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, from,
199 route.goToAtLeastNext(current);
206 float progress = current.getProgress();
207 RouteLocationCalculator.setLocation(
fleet, progress,
208 current.getDestination(), current.getDestination());
218 SectorEntityToken to = current.to;
219 if (to ==
null) to = current.from;
220 if (to ==
null) to =
route.getMarket().getPrimaryEntity();
222 if (to ==
null || !to.isAlive()) {
223 Vector2f loc = Misc.getPointAtRadius(
fleet.getLocationInHyperspace(), 5000);
224 SectorEntityToken token =
Global.
getSector().getHyperspace().createToken(loc);
225 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, token, 1000f);
230 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, to, 1000f,
231 "returning to " + to.getName());
232 if (current.daysMax > current.elapsed) {
233 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, to,
237 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, to,
244 float progress = current.getProgress();
245 RouteLocationCalculator.setLocation(
fleet, progress,
246 current.from, current.getDestination());
248 if (current.from !=
null && current.to ==
null && !current.isFromSystemCenter()) {
253 fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, current.from,
264 SectorEntityToken target =
null;
265 if (current.from.getContainingLocation() instanceof StarSystemAPI) {
266 target = ((StarSystemAPI)current.from.getContainingLocation()).getCenter();
268 target =
Global.
getSector().getHyperspace().createToken(current.from.getLocation().x, current.from.getLocation().y);
271 fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, target,
278 if (state == TravelState.LEAVING_SYSTEM) {
279 float p = current.getLeaveProgress();
280 SectorEntityToken jp = RouteLocationCalculator.findJumpPointToUse(
fleet, current.from);
281 if (jp ==
null) jp = current.from;
282 RouteLocationCalculator.setLocation(
fleet, p,
296 else if (state == TravelState.ENTERING_SYSTEM) {
297 float p = current.getEnterProgress();
298 SectorEntityToken jp = RouteLocationCalculator.findJumpPointToUse(
fleet, current.to);
299 if (jp ==
null) jp = current.to;
300 RouteLocationCalculator.setLocation(
fleet, p,
314 else if (state == TravelState.IN_SYSTEM) {
315 float p = current.getTransitProgress();
316 RouteLocationCalculator.setLocation(
fleet, p,
317 current.from, current.to);
324 else if (state == TravelState.IN_HYPER_TRANSIT) {
325 float p = current.getTransitProgress();
327 current.from.getLocationInHyperspace().x,
328 current.from.getLocationInHyperspace().y);
330 current.to.getLocationInHyperspace().x,
331 current.to.getLocationInHyperspace().y);
332 RouteLocationCalculator.setLocation(
fleet, p, t1, t2);
static SectorAPI getSector()
FleetActionDelegate delegate
RouteFleetAssignmentAI(CampaignFleetAPI fleet, RouteData route, FleetActionDelegate delegate)
LocationAPI getLocationForState(RouteSegment segment, TravelState state)
String getStartingActionText(RouteSegment segment)
Boolean gaveReturnAssignments
String getTravelActionText(RouteSegment segment)
Script goNextScript(final RouteSegment current)
void addTravelAssignment(final RouteSegment current, boolean justSpawned)
void giveInitialAssignments()
void addEndingAssignment(final RouteSegment current, boolean justSpawned)
String getEndingActionText(RouteSegment segment)
void pickNext(boolean justSpawned)
void addLocalAssignment(final RouteSegment current, boolean justSpawned)
void addStartingAssignment(final RouteSegment current, boolean justSpawned)
String getInSystemActionText(RouteSegment segment)
void advance(float amount)
void advance(float amount, boolean withReturnAssignments)
TravelState getTravelState(RouteSegment segment)
RouteFleetAssignmentAI(CampaignFleetAPI fleet, RouteData route)