Starsector API
Loading...
Searching...
No Matches
GenerateSlipsurgeAbility.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.abilities;
2
3import java.awt.Color;
4import java.util.LinkedHashMap;
5import java.util.Map;
6import java.util.Random;
7
8import org.lwjgl.util.vector.Vector2f;
9
10import com.fs.starfarer.api.EveryFrameScript;
11import com.fs.starfarer.api.Global;
12import com.fs.starfarer.api.campaign.CampaignFleetAPI;
13import com.fs.starfarer.api.campaign.CampaignTerrainAPI;
14import com.fs.starfarer.api.campaign.FactionAPI;
15import com.fs.starfarer.api.campaign.JumpPointAPI;
16import com.fs.starfarer.api.campaign.PlanetAPI;
17import com.fs.starfarer.api.campaign.PlanetSpecAPI;
18import com.fs.starfarer.api.campaign.SectorEntityToken;
19import com.fs.starfarer.api.characters.AbilityPlugin;
20import com.fs.starfarer.api.fleet.FleetMemberViewAPI;
21import com.fs.starfarer.api.impl.campaign.ids.Abilities;
22import com.fs.starfarer.api.impl.campaign.ids.Factions;
23import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
24import com.fs.starfarer.api.impl.campaign.ids.Pings;
25import com.fs.starfarer.api.impl.campaign.ids.StarTypes;
26import com.fs.starfarer.api.impl.campaign.ids.Tags;
27import com.fs.starfarer.api.impl.campaign.ids.Terrain;
28import com.fs.starfarer.api.impl.campaign.terrain.HyperspaceTerrainPlugin;
29import com.fs.starfarer.api.impl.campaign.velfield.SlipstreamTerrainPlugin2;
30import com.fs.starfarer.api.impl.campaign.velfield.SlipstreamTerrainPlugin2.SlipstreamParams2;
31import com.fs.starfarer.api.impl.campaign.velfield.SlipstreamTerrainPlugin2.SlipstreamSegment;
32import com.fs.starfarer.api.ui.Alignment;
33import com.fs.starfarer.api.ui.TooltipMakerAPI;
34import com.fs.starfarer.api.util.Misc;
35import com.fs.starfarer.api.util.Misc.FleetMemberDamageLevel;
36
38
39 public static boolean REQUIRE_GIANT_STARS_OR_STRONGER = true;
40
41 public static Map<String, Float> SLIPSURGE_STRENGTH = new LinkedHashMap<String, Float>();
42 static {
43 // I'm aware that these mappings do not reflect actual star mass, which varies
44 // wildly in any case please don't @ me thank you -am
45
46 SLIPSURGE_STRENGTH.put(StarTypes.BLACK_HOLE, 1f);
47 SLIPSURGE_STRENGTH.put(StarTypes.NEUTRON_STAR, 0.9f);
48
49 SLIPSURGE_STRENGTH.put(StarTypes.BLUE_SUPERGIANT, 0.8f);
50 SLIPSURGE_STRENGTH.put(StarTypes.RED_SUPERGIANT, 0.8f);
51
52 SLIPSURGE_STRENGTH.put(StarTypes.RED_GIANT, 0.6f);
53 SLIPSURGE_STRENGTH.put(StarTypes.BLUE_GIANT, 0.6f);
54 SLIPSURGE_STRENGTH.put(StarTypes.ORANGE_GIANT, 0.6f);
55
56 SLIPSURGE_STRENGTH.put(StarTypes.ORANGE, 0.4f);
57 SLIPSURGE_STRENGTH.put(StarTypes.YELLOW, 0.4f);
58
59 SLIPSURGE_STRENGTH.put(StarTypes.WHITE_DWARF, 0.25f);
60 SLIPSURGE_STRENGTH.put(StarTypes.RED_DWARF, 0.2f);
61
62 SLIPSURGE_STRENGTH.put(StarTypes.BROWN_DWARF, 0.1f);
63
64 SLIPSURGE_STRENGTH.put(StarTypes.GAS_GIANT, 0f);
65 SLIPSURGE_STRENGTH.put(StarTypes.ICE_GIANT, 0f);
66 }
67
68 public static float SLIPSURGE_STRENGTH_MULT = 1.3f;
69
70 public static float TRANSIT_MUSIC_SUPPRESSION = 1f;
71 public static String TRANSIT_SOUND_LOOP = "ui_slipsurge_travel_loop";
72
73 public static float FUEL_COST_MULT = 5f;
74 public static float CR_COST_MULT = 0.25f;
75 public static float SENSOR_RANGE_MULT = 0.1f;
76
77 public static String SENSOR_MOD_ID = "slipsurge_sensor_penalty";
78
79 public static class SlipsurgeFadeInScript implements EveryFrameScript {
80 protected SlipstreamTerrainPlugin2 plugin;
81 protected boolean done = false;
82 protected int index = 0;
83 protected float elapsed = 0f;
84 protected float maxElapsed = 0f;
85 public SlipsurgeFadeInScript(SlipstreamTerrainPlugin2 plugin) {
86 this.plugin = plugin;
87
88 float fadeInLength = 300f;
89 float lengthSoFar = 0f;
90 float durIn = 0.2f;
91 maxElapsed = durIn * plugin.getSegments().size() * 0.34f + 3f;
92 for (SlipstreamSegment seg : plugin.getSegments()) {
93 seg.fader.setDurationIn(durIn);
94 seg.fader.forceOut();
95
96 seg.bMult = Math.min(1f, lengthSoFar / fadeInLength);
97 lengthSoFar += seg.lengthToNext;
98 }
99 }
100 public void advance(float amount) {
101 if (done) return;
102
103 // amount == 1 when not current location
104 // which isn't fine-grained enough to fade the segments in
105 // one at a time since each takes <1s
106 if (!plugin.getEntity().isInCurrentLocation()) {
107 for (SlipstreamSegment curr : plugin.getSegments()) {
108 curr.fader.fadeIn();
109 }
110 done = true;
111 return;
112 }
113
114
115 elapsed += amount;
116 if (index >= plugin.getSegments().size() || elapsed > maxElapsed) {
117 done = true;
118 return;
119 }
120 SlipstreamSegment curr = plugin.getSegments().get(index);
121 if (curr.fader.isFadedIn()) {
122 index++;
123 return;
124 }
125 curr.fader.fadeIn();
126 if (curr.fader.getBrightness() > 0.33f && index < plugin.getSegments().size() - 1) {
127 plugin.getSegments().get(index + 1).fader.fadeIn();
128 }
129 if (curr.fader.getBrightness() > 0.67f && index < plugin.getSegments().size() - 2) {
130 plugin.getSegments().get(index + 2).fader.fadeIn();
131 }
132 }
133
134 public boolean isDone() {
135 return done;
136 }
137 public boolean runWhilePaused() {
138 return false;
139 }
140 }
141
142 public static class ExpandStormRadiusScript implements EveryFrameScript {
143 protected float elapsed = 0f;
144 protected float extraRadius;
145 public ExpandStormRadiusScript(float extraRadius) {
146 this.extraRadius = extraRadius;
147 }
148 public void advance(float amount) {
149 elapsed += amount;
150
151 CampaignTerrainAPI terrain = Misc.getHyperspaceTerrain();
152 if (terrain != null) {
153 HyperspaceTerrainPlugin htp = (HyperspaceTerrainPlugin) terrain.getPlugin();
154 htp.setExtraDistanceAroundPlayerToAdvanceStormCells(extraRadius);
155 htp.setStormCellTimeMultOutsideBaseArea(5f);
156 }
157 }
158
159 public boolean isDone() {
160 return elapsed >= 10f;
161 }
162 public boolean runWhilePaused() {
163 return false;
164 }
165 }
166
167 public static class SlipsurgeEffectScript implements EveryFrameScript {
168 protected CampaignFleetAPI fleet;
169 protected boolean triggered = false;
170 protected boolean done = false;
171 protected boolean didTempCleanup = false;
172 protected float elapsed = 0f;
173 protected SlipstreamTerrainPlugin2 plugin;
174 public SlipsurgeEffectScript(CampaignFleetAPI fleet, SlipstreamTerrainPlugin2 plugin) {
175 this.fleet = fleet;
176 this.plugin = plugin;
177 }
178
179 public void abort() {
180 done = true;
181 didTempCleanup = true;
182 fleet.fadeInIndicator();
183 fleet.setNoEngaging(0f);
184 fleet.getStats().getSensorRangeMod().unmodifyMult(SENSOR_MOD_ID);
185 for (FleetMemberViewAPI view : fleet.getViews()) {
186 view.endJitter();
187 }
188 if (fleet.isPlayerFleet()) {
189 Global.getSector().getCampaignUI().setFollowingDirectCommand(false);
190 }
191 //fleet.setMoveDestination(dest.x, dest.y)
192 }
193
194 public void advance(float amount) {
195 if (done) return;
196
197 if (fleet.isInHyperspaceTransition() ||
198 plugin.getEntity().getContainingLocation() != fleet.getContainingLocation()) {
199 if (!didTempCleanup) {
200 abort();
201 }
202 // fleet could conceivably come back, set done back to false so the script keeps running
203 done = false;
204 return;
205 }
206
207 elapsed += amount;
208 if (!triggered) {
209 if (elapsed >= 30f ||
210 !plugin.getEntity().isAlive()) {
211 done = true;
212 return;
213 }
214 }
215
216 float burn = Misc.getBurnLevelForSpeed(fleet.getVelocity().length());
217 if (burn > 50 && plugin.containsEntity(fleet)) {
218 triggered = true;
219 }
220
221 if (triggered) {
222 if (burn < 50) {
223 plugin.despawn(0, 0.2f, new Random());
224 abort();
225 return;
226 }
227
228 AbilityPlugin gs = fleet.getAbility(Abilities.GENERATE_SLIPSURGE);
229 if (gs instanceof BaseAbilityPlugin) {
230 BaseAbilityPlugin base = (BaseAbilityPlugin) gs;
231 for (AbilityPlugin curr : fleet.getAbilities().values()) {
232 if (curr == this) continue;
233 if (!base.isCompatible(curr)) {
234 if (curr.isActiveOrInProgress()) {
235 curr.deactivate();
236 }
237 curr.forceDisable();
238 }
239 }
240 }
241
242 float decelMult = Misc.getAbyssalDepth(fleet) * 1f;
243 if (fleet.getGoSlowOneFrame()) decelMult = 1f;
244 //if (fleet.getGoSlowOneFrame() && !plugin.containsEntity(fleet)) {
245 if (decelMult > 0f && !plugin.containsEntity(fleet)) {
246 float angle = Misc.getAngleInDegrees(fleet.getVelocity());
247 Vector2f decelDir = Misc.getUnitVectorAtDegreeAngle(angle + 180f);
248
249 float targetDecelSeconds = 0.5f;
250 float speed = fleet.getVelocity().length();
251 float decelAmount = amount * speed / targetDecelSeconds;
252 decelDir.scale(decelAmount * decelMult);
253
254 Vector2f vel = fleet.getVelocity();
255 fleet.setVelocity(vel.x + decelDir.x, vel.y + decelDir.y);
256 }
257
258
259 fleet.fadeOutIndicator();
260 fleet.setNoEngaging(0.1f);
261 fleet.setInteractionTarget(null);
262 if (fleet.isPlayerFleet()) {
263 Global.getSector().getCampaignUI().setFollowingDirectCommand(true);
264 }
265 fleet.getMemoryWithoutUpdate().set(MemFlags.NO_HIGH_BURN_TOPOGRAPHY_READINGS, true, 0.1f);
266 fleet.getStats().getSensorRangeMod().modifyMult(SENSOR_MOD_ID, SENSOR_RANGE_MULT, "Extreme burn level");
267 didTempCleanup = false;
268
269 float angle = Misc.getAngleInDegrees(fleet.getVelocity());
270 Vector2f jitterDir = Misc.getUnitVectorAtDegreeAngle(angle + 180f);
271 Vector2f windDir = Misc.getUnitVectorAtDegreeAngle(angle);
272 float windIntensity = (burn - 50f) / 250f;
273 if (windIntensity < 0) windIntensity = 0;
274 //if (windIntensity > 1f) windIntensity = 1f;
275
276 float b = (burn - 50f) / 450f;
277 if (b < 0) b = 0;
278 if (b > 1f) b = 1f;
279 if (b > 0) {
280
281 if (fleet.isPlayerFleet()) {
282 float volume = b;
283 Global.getSector().getCampaignUI().suppressMusic(TRANSIT_MUSIC_SUPPRESSION * volume);
284 Global.getSoundPlayer().setNextLoopFadeInAndOut(0.05f, 0.5f);
285 Global.getSoundPlayer().playLoop(TRANSIT_SOUND_LOOP, fleet,
286 1f, volume,
287 fleet.getLocation(), fleet.getVelocity());
288 }
289
290
291 //String modId = "SlipsurgeEffectScript_" + fleet.getId();
292 for (FleetMemberViewAPI view : fleet.getViews()) {
293 Color c = view.getMember().getHullSpec().getHyperspaceJitterColor();
294// view.setJitter(1f, 1f, c, 7, 10f);
295// view.setJitterBrightness(b);
296// //view.setJitter(0.25f, 1f, c, 10 + Math.round(40f * b), 20f);
297// view.setUseCircularJitter(true);
298
299 c = Misc.setAlpha(c, 60);
300 view.setJitter(0.1f, 1f, c, 10 + Math.round(40f * b), 20f);
301 view.setUseCircularJitter(true);
302 view.setJitterDirection(jitterDir);
303 view.setJitterLength(30f * b);
304 view.setJitterBrightness(b);
305
306 }
307 } else {
308 for (FleetMemberViewAPI view : fleet.getViews()) {
309 view.endJitter();
310 }
311 }
312 }
313
314 }
315
316 public boolean isDone() {
317 return done;
318 }
319 public boolean runWhilePaused() {
320 return false;
321 }
322 }
323
324 protected Boolean primed = null;
325 protected Vector2f startLoc = null;
326 protected JumpPointAPI well = null;
327
328
329 public float getFuelCostMult() {
330 return FUEL_COST_MULT;
331 }
332 public float getCRCostMult() {
333 return CR_COST_MULT;
334 }
335 public FleetMemberDamageLevel getActivationDamageLevel() {
336 return FleetMemberDamageLevel.MEDIUM;
337 }
338 public boolean canRecoverCRWhileActive() {
339 return true;
340 }
341
342
343 @Override
344 protected void activateImpl() {
345 CampaignFleetAPI fleet = getFleet();
346 if (fleet == null) return;
347
348 primed = true;
350 if (well == null) return;
351
352 //startLoc = new Vector2f(fleet.getLocation());
353 float angle = Misc.getAngleInDegrees(well.getLocation(), fleet.getLocation());
354 float offset = 100f;
355 Vector2f from = Misc.getUnitVectorAtDegreeAngle(angle);
356 from.scale(offset + fleet.getRadius());
357 Vector2f.add(from, fleet.getLocation(), from);
358 startLoc = from;
359
360
361 SectorEntityToken token = fleet.getContainingLocation().createToken(startLoc);
362 //Global.getSector().addPing(fleet, Pings.SLIPSURGE);
363 Global.getSector().addPing(token, Pings.SLIPSURGE);
364
365 well.getContainingLocation().addScript(new ExpandStormRadiusScript(16000f));
366
367 deductCost();
368 }
369
370 @Override
371 protected void applyStatsEffect(float amount, float level) {
372 CampaignFleetAPI fleet = getFleet();
373 if (fleet == null) return;
374
375 if (level > 0 && level < 1 && amount > 0) {
376 fleet.goSlowOneFrame();
377 return;
378 }
379
380 if (level == 1 && primed != null) {
382 primed = null;
383 startLoc = null;
384 well = null;
385 }
386
387 }
388
389
390 protected void generateSlipstream() {
391 CampaignFleetAPI fleet = getFleet();
392 if (fleet == null) return;
393
394 //JumpPointAPI jp = findGravityWell();
395 JumpPointAPI jp = well;
396 if (jp == null) return;
397
398 float strength = getStrengthForGravityWell(jp);
399 strength *= SLIPSURGE_STRENGTH_MULT;
400
401 float angle = Misc.getAngleInDegrees(jp.getLocation(), startLoc);
402 float offset = 100f;
403// Vector2f from = Misc.getUnitVectorAtDegreeAngle(angle);
404// from.scale(offset + fleet.getRadius());
405// Vector2f.add(from, startLoc, from);
406 Vector2f from = startLoc;
407
408 SlipstreamParams2 params = new SlipstreamParams2();
409
410 params.enteringSlipstreamTextOverride = "Entering slipsurge";
411 params.enteringSlipstreamTextDurationOverride = 0.1f;
412 params.forceNoWindVisualEffectOnFleets = true;
413
414 float width = 600f;
415 float length = 1000f;
416
417 length += strength * 500f;
418 params.burnLevel = Math.round(400f + strength * strength * 500f);
419 params.accelerationMult = 20f + strength * strength * 280f;
420
421 //params.accelerationMult = 500f;
422
423 params.baseWidth = width;
424 params.widthForMaxSpeed = 400f;
425 params.widthForMaxSpeedMinMult = 0.34f;
426 //params.widthForMaxSpeed = 300f;
427 params.slowDownInWiderSections = true;
428 //params.edgeWidth = 100f;
429 //params.accelerationMult = 100f;
430
431
432 params.minSpeed = Misc.getSpeedForBurnLevel(params.burnLevel - params.burnLevel/8);
433 params.maxSpeed = Misc.getSpeedForBurnLevel(params.burnLevel + params.burnLevel/8);
434 //params.lineLengthFractionOfSpeed = 0.25f * Math.max(0.25f, Math.min(1f, 30f / (float) params.burnLevel));
435 params.lineLengthFractionOfSpeed = 2000f / ((params.maxSpeed + params.minSpeed) * 0.5f);
436
437 float lineFactor = 0.1f;
438 params.minSpeed *= lineFactor;
439 params.maxSpeed *= lineFactor;
440 //params.lineLengthFractionOfSpeed *= 0.25f;
441 //params.lineLengthFractionOfSpeed *= 1f;
442 params.maxBurnLevelForTextureScroll = (int) (params.burnLevel * 0.1f);
443
444 params.particleFadeInTime = 0.01f;
445 params.areaPerParticle = 1000f;
446
447 Vector2f to = Misc.getUnitVectorAtDegreeAngle(angle);
448 to.scale(offset + fleet.getRadius() + length);
449 Vector2f.add(to, startLoc, to);
450
451 CampaignTerrainAPI slipstream = (CampaignTerrainAPI) well.getContainingLocation().addTerrain(Terrain.SLIPSTREAM, params);
452 slipstream.addTag(Tags.SLIPSTREAM_VISIBLE_IN_ABYSS);
453 slipstream.setLocation(from.x, from.y);
454
455 SlipstreamTerrainPlugin2 plugin = (SlipstreamTerrainPlugin2) slipstream.getPlugin();
456
457 float spacing = 100f;
458 float incr = spacing / length;
459
460 Vector2f diff = Vector2f.sub(to, from, new Vector2f());
461 for (float f = 0; f <= 1f; f += incr) {
462 Vector2f curr = new Vector2f(diff);
463 curr.scale(f);
464 Vector2f.add(curr, from, curr);
465 plugin.addSegment(curr, width - Math.min(300f, 300f * (float)Math.sqrt(f)));
466 //plugin.addSegment(curr, width);
467 }
468
469 plugin.recomputeIfNeeded();
470
471 plugin.despawn(1.5f, 0.2f, new Random());
472
473 slipstream.addScript(new SlipsurgeFadeInScript(plugin));
474 fleet.addScript(new SlipsurgeEffectScript(fleet, plugin));
475
476 }
477
478 @Override
479 protected void unapplyStatsEffect() {
480 CampaignFleetAPI fleet = getFleet();
481 if (fleet == null) return;
482
483 primed = null;
484 startLoc = null;
485 well = null;
486 }
487
488
489 @Override
490 public boolean isUsable() {
491 if (!super.isUsable()) return false;
492 return super.isUsable() &&
493 getFleet() != null &&
494 getFleet().isInHyperspace() &&
495 findGravityWell() != null;
496 //findGravityWell() != null || Misc.isInsideSlipstream(getFleet()));
497 //(getFleet().isAIMode() || computeFuelCost(Misc.isInsideSlipstream(getFleet())) <= getFleet().getCargo().getFuel());
498 }
499
500
501 @Override
502 public void addInitialDescription(TooltipMakerAPI tooltip, boolean expanded) {
503 CampaignFleetAPI fleet = getFleet();
504 if (fleet == null) return;
505
506 Color text = Misc.getTextColor();
507 Color gray = Misc.getGrayColor();
508 Color highlight = Misc.getHighlightColor();
509 Color bad = Misc.getNegativeHighlightColor();
510
511 float pad = 10f;
512
513
514 String extra = "";
516 extra = "and availability ";
517 }
518
519
520 // some of the other factors: it has "dwarf" or "giant" in the name
521 tooltip.addPara("Overload and modulate the fleet's drive field "
522 + "to induce an extremely powerful, "
523 + "short-duration slipstream flowing away from the nearest gravity well, its strength " + extra
524 + "based on the stellar object's mass, density, and some other poorly-understood factors. "
525 + "Largely ineffective inside abyssal hyperspace.", pad);
526
527// tooltip.addPara("A stronger surge can allow the fleet to rapidly travel up to %s light-years. "
528// + "Attempting to move slowly "
529// + "during the transit will decelerate the fleet quickly.", pad, highlight,
530// "10", "move slowly");
531
532 FactionAPI player = Global.getSector().getFaction(Factions.PLAYER);
533 Color starColor = Misc.getBasePlayerColor();
534 tooltip.beginTable(player, 20f, "Stellar object type", getTooltipWidth() - 150f, "Surge strength", 150f);
536 tooltip.addRow(Alignment.LMID, starColor, "Black holes, neutron stars",
537 Alignment.MID, highlight, "Extreme");
538 tooltip.addRow(Alignment.LMID, starColor, "Supergiant stars",
539 Alignment.MID, highlight, "High");
540 tooltip.addRow(Alignment.LMID, starColor, "Giant stars",
541 Alignment.MID, highlight, "Average");
542 tooltip.addRow(Alignment.LMID, starColor, "Smaller stars / stellar objects",
543 Alignment.MID, highlight, "---");
544 } else {
545 tooltip.addRow(Alignment.LMID, starColor, "Black holes, neutron stars",
546 Alignment.MID, highlight, "Extreme");
547 tooltip.addRow(Alignment.LMID, starColor, "Supergiant stars",
548 Alignment.MID, highlight, "Very high");
549 tooltip.addRow(Alignment.LMID, starColor, "Giant stars",
550 Alignment.MID, highlight, "High");
551 tooltip.addRow(Alignment.LMID, starColor, "Sol-like stars",
552 Alignment.MID, highlight, "Average");
553 tooltip.addRow(Alignment.LMID, starColor, "Dwarf stars",
554 Alignment.MID, highlight, "Low");
555 tooltip.addRow(Alignment.LMID, starColor, "Gas giants",
556 Alignment.MID, highlight, "Very low");
557 }
558
559 tooltip.addTable("", 0, pad);
560 tooltip.addSpacer(5f);
561
562 tooltip.addPara("A stronger surge can allow the fleet to rapidly travel up to %s light-years. "
563 + "Attempting to %s "
564 + "during the transit will decelerate the fleet quickly. Fleet sensor range is "
565 + "reduced by %s during the transit.", pad, highlight,
566 "15", "move slowly",
567 "" + (int)Math.round((1f - SENSOR_RANGE_MULT) * 100f) + "%");
568
569 }
570
571 @Override
572 public boolean addNotUsableReasonBeforeFuelCost(TooltipMakerAPI tooltip, boolean expanded) {
573 CampaignFleetAPI fleet = getFleet();
574 if (fleet == null) return false;
575
576 Color bad = Misc.getNegativeHighlightColor();
577
578 float pad = 10f;
579
580 if (!fleet.isInHyperspace()) {
581 tooltip.addPara("Can only be used in hyperspace.", bad, pad);
582 return true;
583 //} else if (findGravityWell() == null && !Misc.isInsideSlipstream(getFleet())) {
584 } else if (findGravityWell() == null) {
585 //tooltip.addPara("Must be near a gravity well or inside a slipstream.", bad, pad);
587 tooltip.addPara("Must be near a powerful gravity well.", bad, pad);
588 } else {
589 tooltip.addPara("Must be near a gravity well.", bad, pad);
590 }
591 return true;
592 }
593
594 return false;
595 }
596
597
598 public JumpPointAPI findGravityWell() {
599 CampaignFleetAPI fleet = getFleet();
600 if (fleet == null) return null;
601
602 JumpPointAPI closest = null;
603 float minDist = Float.MAX_VALUE;
604 for (SectorEntityToken curr : fleet.getContainingLocation().getJumpPoints()) {
605 JumpPointAPI jp = (JumpPointAPI) curr;
606 if (!jp.isStarAnchor() && !jp.isGasGiantAnchor()) continue;
607 if (jp.getDestinationVisualEntity() == null) continue;
608
610 float str = getStrengthForGravityWell(jp);
611 float min = SLIPSURGE_STRENGTH.get(StarTypes.YELLOW);
612 if (str <= min) continue;
613 }
614
615 float dist = Misc.getDistance(fleet, jp) - jp.getRadius();
616 if (dist > jp.getRadius() + 150f) continue;
617 if (dist < minDist) {
618 closest = jp;
619 minDist = dist;
620 }
621 }
622 return closest;
623 }
624
625 public float getStrengthForGravityWell(JumpPointAPI jp) {
626 return getStrengthForStellarObject(jp.getDestinationVisualEntity());
627 }
628
629 public float getStrengthForStellarObject(SectorEntityToken object) {
630 if (!(object instanceof PlanetAPI)) return 0f;
631 PlanetAPI star = (PlanetAPI) object;
632 PlanetSpecAPI spec = star.getSpec();
633 Float val = SLIPSURGE_STRENGTH.get(spec.getPlanetType());
634 if (val != null) return val;
635
636 if (spec.isGasGiant()) return 0f;
637
638 // probably a mod-added star of some sort
639 // time to make some guesses based on the "poorly understood factors"
640
641 String key = StarTypes.YELLOW;
642
643 String name = spec.getName().toLowerCase();
644 if (name.contains("neutron") || spec.isPulsar()) {
645 key = StarTypes.NEUTRON_STAR;
646 } else if (name.contains("dwarf")) {
647 key = StarTypes.WHITE_DWARF;
648 } else if (name.contains("giant")) {
649 key = StarTypes.BLUE_GIANT;
650 } else if (name.contains("supergiant")) {
651 key = StarTypes.BLUE_SUPERGIANT;
652 } else if (name.contains(" hole")) {
653 key = StarTypes.BLACK_HOLE;
654 } else if (name.contains("brown")) {
655 key = StarTypes.BROWN_DWARF;
656 }
657
658 val = SLIPSURGE_STRENGTH.get(key);
659 if (val != null) return val;
660 return 0.4f;
661 }
662
663
664}
665
666
667
668
669
static SectorAPI getSector()
Definition Global.java:59
boolean addNotUsableReasonBeforeFuelCost(TooltipMakerAPI tooltip, boolean expanded)