1package com.fs.starfarer.api.impl.campaign.fleets;
5import org.lwjgl.util.vector.Vector2f;
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CampaignFleetAPI;
9import com.fs.starfarer.api.campaign.FactionAPI;
10import com.fs.starfarer.api.campaign.JumpPointAPI;
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.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.impl.campaign.JumpPointInteractionDialogPluginImpl;
16import com.fs.starfarer.api.impl.campaign.shared.WormholeManager;
17import com.fs.starfarer.api.util.Misc;
22 public static enum IntervalType {
28 public static class TaskInterval {
29 public IntervalType type;
32 public TaskInterval(IntervalType type,
float value) {
37 public TaskInterval(IntervalType type) {
43 public static TaskInterval days(
float days) {
44 return new TaskInterval(IntervalType.DAYS, days);
46 public static TaskInterval travel() {
47 return new TaskInterval(IntervalType.TRAVEL_TIME, 0f);
49 public static TaskInterval remaining(
float fraction) {
50 return new TaskInterval(IntervalType.FRACTION_OF_REMAINING, fraction);
70 float travelTime = dist / 1500f;
75 boolean onlyComputeIntervals,
76 TaskInterval [] intervals,
80 float totalFraction = 0f;
81 for (
int i = 0; i < intervals.length; i++) {
82 TaskInterval t = intervals[i];
83 if (t.type == IntervalType.TRAVEL_TIME) {
91 if (t.type == IntervalType.FRACTION_OF_REMAINING) {
92 totalFraction += t.value;
98 if (totalFraction > 0) {
99 float remaining = maxDays - totalDays;
100 for (TaskInterval t : intervals) {
101 if (t.type == IntervalType.FRACTION_OF_REMAINING) {
102 t.value = Math.max(0.1f, t.value / totalFraction * remaining);
108 for (TaskInterval t : intervals) {
109 totalDays += t.value;
112 if (totalDays > maxDays) {
113 for (TaskInterval t : intervals) {
114 t.value *= maxDays / totalDays;
124 for (
int i = 0; i < intervals.length; i++) {
125 float curr = intervals[i].value;
126 if (curr < 0) curr = 0;
128 if (soFar + curr > daysElapsed && curr > 0) {
129 progress = (daysElapsed - soFar) / curr;
130 if (progress < 0) progress = 0;
131 if (progress > 1) progress = 1;
133 from = sequence[index];
134 to = sequence[index + 1];
135 intervals[i].value *= (1f - progress);
139 intervals[i].value = 0;
143 index = intervals.length - 1;
144 from = sequence[sequence.length - 2];
145 to = sequence[sequence.length - 1];
149 if (onlyComputeIntervals) {
170 float daysElapsed,
float maxDays,
int overflowIndex,
171 boolean onlyAdjustIntervals,
175 for (
float curr : intervals) {
181 if (total != maxDays) {
182 if (overflowIndex >= 0) {
183 float extra = total - maxDays;
184 intervals[overflowIndex] -= extra;
185 if (intervals[overflowIndex] <= 0) {
186 total = maxDays - intervals[overflowIndex];
187 intervals[overflowIndex] = 0;
188 for (
int i = 0; i < intervals.length; i++) {
189 intervals[i] *= maxDays / total;
193 for (
int i = 0; i < intervals.length; i++) {
194 intervals[i] *= maxDays / total;
206 for (
int i = 0; i < intervals.length; i++) {
207 float curr = intervals[i];
208 if (curr < 0) curr = 0;
210 if (soFar + curr > daysElapsed && curr > 0) {
211 progress = (daysElapsed - soFar) / curr;
212 if (progress < 0) progress = 0;
213 if (progress > 1) progress = 1;
215 from = sequence[index];
216 to = sequence[index + 1];
217 intervals[i] *= (1f - progress);
225 index = intervals.length - 1;
226 from = sequence[sequence.length - 2];
227 to = sequence[sequence.length - 1];
232 if (onlyAdjustIntervals) {
254 if (progress < 0) progress = 0;
255 if (progress > 1) progress = 1;
257 if (to ==
null) to = from;
258 if (from ==
null) from = to;
260 if (from ==
null && to ==
null)
return;
269 forSystemCenterCheck = from;
272 if (progress > 0.03f) {
318 if (jp ==
null)
return;
324 float t = d1 / (d1 + d2);
327 forSystemCenterCheck = inSystem;
348 if (jp1 ==
null || jp2 ==
null)
return;
357 float t1 = d1 / (d1 + d2 + d3);
358 float t2 = (d1 + d2) / (d1 + d2 + d3);
362 forSystemCenterCheck = from;
368 }
else if (progress < t2) {
372 (progress - t1) / (t2 - t1));
376 forSystemCenterCheck = to;
380 (progress - t2) / (1f - t2));
387 if (forSystemCenterCheck !=
null && forSystemCenterCheck.
isSystemCenter() &&
397 if (loc ==
null) loc =
new Vector2f(from.
getLocation());
411 float varianceMult = 1f;
413 varianceMult = p / 0.1f;
414 }
else if (p > 0.9f) {
415 varianceMult = (1f - p) / 0.1f;
425 float min = Float.MAX_VALUE;
448 if (dist > fringeMax) {
457 if (useFringeOnly && fringe !=
null) {
470 if (market.getFaction().isHostileTo(faction)) {
471 hostileMax = Math.max(hostileMax, market.getSize());
472 }
else if (market.getFaction() == faction) {
473 ourMax = Math.max(ourMax, market.getSize());
476 boolean inControl = ourMax >= hostileMax;
static SectorAPI getSector()
static final String UNSTABLE_KEY
static boolean isInControlOfSystemOrEven(FactionAPI faction, StarSystemAPI system)
static int setLocation(CampaignFleetAPI fleet, float daysElapsed, float maxDays, int overflowIndex, boolean onlyAdjustIntervals, float[] intervals, SectorEntityToken ... sequence)
static void computeIntervalsAndSetLocation(CampaignFleetAPI fleet, float daysElapsed, float maxDays, boolean onlyComputeIntervals, TaskInterval[] intervals, SectorEntityToken ... sequence)
static JumpPointAPI findJumpPointToUse(CampaignFleetAPI fleet, SectorEntityToken from)
static float getVarianceMult(float p)
static JumpPointAPI findJumpPointToUse(FactionAPI faction, SectorEntityToken from)
static void setLocation(CampaignFleetAPI fleet, float progress, SectorEntityToken from, SectorEntityToken to)
static float getTravelDays(SectorEntityToken from, SectorEntityToken to)
static List< MarketAPI > getMarketsInLocation(LocationAPI location, String factionId)
static Vector2f getSystemJumpPointHyperExitLocation(JumpPointAPI jp)
static float getDistance(SectorEntityToken from, SectorEntityToken to)
static Vector2f getPointAtRadius(Vector2f from, float r)
static Vector2f interpolateVector(Vector2f from, Vector2f to, float progress)
static Vector2f getPointWithinRadius(Vector2f from, float r)
LocationAPI getContainingLocation()
void setLocation(float x, float y)
List getEntities(Class implementedClassOrInterface)
void addEntity(SectorEntityToken entity)
void removeEntity(SectorEntityToken entity)
LocationAPI getHyperspace()
LocationAPI getContainingLocation()
Vector2f getLocationInHyperspace()