1package com.fs.starfarer.api.impl.campaign;
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.HashMap;
11import org.lwjgl.input.Keyboard;
13import com.fs.starfarer.api.Global;
14import com.fs.starfarer.api.campaign.CampaignFleetAPI;
15import com.fs.starfarer.api.campaign.FactionAPI;
16import com.fs.starfarer.api.campaign.InteractionDialogAPI;
17import com.fs.starfarer.api.campaign.InteractionDialogPlugin;
18import com.fs.starfarer.api.campaign.JumpPointAPI;
19import com.fs.starfarer.api.campaign.JumpPointAPI.JumpDestination;
20import com.fs.starfarer.api.campaign.OptionPanelAPI;
21import com.fs.starfarer.api.campaign.SectorEntityToken;
22import com.fs.starfarer.api.campaign.TextPanelAPI;
23import com.fs.starfarer.api.campaign.VisualPanelAPI;
24import com.fs.starfarer.api.campaign.econ.MarketAPI;
25import com.fs.starfarer.api.campaign.impl.items.WormholeScannerPlugin;
26import com.fs.starfarer.api.campaign.rules.MemKeys;
27import com.fs.starfarer.api.campaign.rules.MemoryAPI;
28import com.fs.starfarer.api.characters.AbilityPlugin;
29import com.fs.starfarer.api.combat.EngagementResultAPI;
30import com.fs.starfarer.api.impl.campaign.abilities.TransponderAbility;
31import com.fs.starfarer.api.impl.campaign.ids.Abilities;
32import com.fs.starfarer.api.impl.campaign.ids.Factions;
33import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
34import com.fs.starfarer.api.impl.campaign.rulecmd.DumpMemory;
35import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MiscCMD;
36import com.fs.starfarer.api.impl.campaign.shared.WormholeManager;
37import com.fs.starfarer.api.impl.campaign.tutorial.TutorialMissionIntel;
38import com.fs.starfarer.api.loading.Description;
39import com.fs.starfarer.api.loading.Description.Type;
40import com.fs.starfarer.api.ui.LabelAPI;
41import com.fs.starfarer.api.util.Misc;
50 private static enum OptionId {
61 JUMP_CONFIRM_TURN_TRANSPONDER_ON,
65 RETRIEVE_ANCHOR_CONFIRM,
82 private List<OptionId> jumpOptions = Arrays.asList(
108 float rounded = Math.round(
fuelCost);
109 if (
fuelCost > 0 && rounded <= 0) rounded = 1;
125 visual.
showImagePortion(
"illustrations",
"jump_point_wormhole", 640, 400, 0, 0, 480, 300);
128 visual.
showImagePortion(
"illustrations",
"jump_point_hyper", 640, 400, 0, 0, 480, 300);
130 visual.
showImagePortion(
"illustrations",
"jump_point_normal", 640, 400, 0, 0, 480, 300);
153 if (optionData ==
null)
return;
156 Map<String, MemoryAPI> memoryMap =
new HashMap<String, MemoryAPI>();
178 OptionId option = (OptionId) optionData;
223 addText(
"Your fleet approaches the wormhole.");
225 addText(getString(
"approach"));
229 if (desc !=
null && desc.
hasText3()) {
233 String noun =
"jump-point";
241 String durStr =
"" + (int) dur;
242 String days =
"days";
251 textPanel.
addPara(
"This wormhole is stabilizing and will become usable "
256 if (time.contains(
"many")) {
258 "This wormhole is gradually stabilizing, but will not be usable for " + time +
".");
261 "This wormhole is stabilizing, and should be usable within " + time +
".");
269 if (stabilizing && !canTransverseJump) {
270 if (tutorialInProgress) {
271 addText(
"This jump-point is stabilizing and should be usable within a day at the most.");
273 addText(
"This jump-point is stabilizing but will not be usable for some time.");
276 addText(
"This jump-point is unstable and can not be used.");
279 if (canTransverseJump && !tutorialInProgress ) {
280 addText(
"Until it restabilizes, hyperspace is only accessible via Transverse Jump.");
288 addText(
"The nav computer pings the wormhole terminus, establishing a data connection through drive-field fluctuations. "
289 +
"In under a minute, and only a moment of unease as the agrav self-correction settles, the process is complete. "
290 +
"Your primary interface unveils a list of possible destinations.");
293 textPanel.
addParagraph(
"Activating this " + noun +
" to let your fleet pass through will cost " + (
int)
fuelCost +
" fuel.");
298 textPanel.
addParagraph(
"Activating this " + noun +
" to let your fleet pass through will cost " + (
int)
fuelCost +
" fuel. You have no fuel.");
300 textPanel.
addParagraph(
"Activating this " + noun +
" to let your fleet pass through will cost " + (
int)
fuelCost +
" fuel. You only have " + fuel +
" fuel.");
315 createInitialOptions();
322 addText(
"You load the stabilization algorithm into your jump program and the drive field goes through a series " +
323 "of esoteric fluctuations, their resonance gradually cancelling out the instability in this jump-point.");
325 addText(
"The jump-point should be stable enough to use within a day or so.");
327 createInitialOptions();
329 case JUMP_CONFIRM_TURN_TRANSPONDER_ON:
339 case RETRIEVE_ANCHOR_CONFIRM:
341 "You give the order. Before long, your ops chief confirms that the wormhole anchor has been stowed in a secure hold on your flagship.");
344 options.
addOption(
"Leave", OptionId.LEAVE,
null);
345 options.
setShortcut(OptionId.LEAVE, Keyboard.KEY_ESCAPE,
false,
false,
false,
true);
347 case RETRIEVE_ANCHOR:
349 "This will shut down the wormhole and free up the stable point for other uses.");
351 options.
addOption(
"Confirm your orders", OptionId.RETRIEVE_ANCHOR_CONFIRM,
null);
353 options.
addOption(
"Abort the operation", OptionId.LEAVE,
null);
354 options.
setShortcut(OptionId.LEAVE, Keyboard.KEY_ESCAPE,
false,
false,
false,
true);
363 if (jumpOptions.contains(option)) {
364 JumpDestination dest = destinationMap.get(option);
373 boolean wouldMindTOff =
false;
374 boolean isPopulated =
false;
376 if (market.isHidden())
continue;
377 if (market.getFaction().isPlayerFaction())
continue;
381 !market.isFreePort() &&
383 wouldMindTOff =
true;
389 textPanel.
addPara(
"Your transponder is off, and patrols " +
392 " are likely to give you trouble over the fact, if you're spotted.");
394 textPanel.
addPara(
"Your transponder is off, but any patrols in the " +
396 " are unlikely to raise the issue.");
399 if (!wouldBecomeHostile.isEmpty()) {
400 String str =
"Turning the transponder on now would reveal your hostile actions to";
401 boolean first =
true;
402 boolean last =
false;
403 for (
FactionAPI faction : wouldBecomeHostile) {
404 last = wouldBecomeHostile.indexOf(faction) == wouldBecomeHostile.size() - 1;
405 if (first || !last) {
406 str +=
" " + faction.getDisplayNameWithArticle() +
",";
408 str +=
" and " + faction.getDisplayNameWithArticle() +
",";
411 str = str.substring(0, str.length() - 1) +
".";
417 options.
addOption(
"Turn the transponder on and then jump", OptionId.JUMP_CONFIRM_TURN_TRANSPONDER_ON,
null);
418 options.
addOption(
"Jump, keeping the transponder off", OptionId.JUMP_CONFIRM,
null);
421 options.
addOption(
"Abort the jump", OptionId.LEAVE,
null);
422 options.
setShortcut(OptionId.LEAVE, Keyboard.KEY_ESCAPE,
false,
false,
false,
true);
470 List<CampaignFleetAPI> fleets =
new ArrayList<CampaignFleetAPI>();
471 boolean hostile =
false;
472 float minDist = Float.MAX_VALUE;
478 if (other.getAI() !=
null) {
489 if (dist < minDist) minDist = dist;
494 if (maxDanger >= 2) {
495 String noun =
"jump-point";
500 String where =
"a short distance away from the exit";
503 where =
"extremely close to the exit";
506 text.
addPara(
"The jump-point exhibits fluctuations " +
507 "characteristic of drive field activity " + where +
".",
510 text.
addPara(
"A disposable probe sends back a microburst of information: forces " +
511 "near the exit are assesed likely hostile and a possible threat to your fleet.",
516 private Map<OptionId, JumpDestination> destinationMap =
new HashMap<OptionId, JumpDestination>();
517 private void createInitialOptions() {
523 boolean okToUseIfAnchor = isStarAnchor && navigation >= 7;
525 okToUseIfAnchor =
true;
526 if (isStarAnchor && !okToUseIfAnchor && dev) {
527 addText(
"(Can always be used in dev mode)");
529 okToUseIfAnchor |= dev;
531 String noun =
"jump-point";
539 options.
addOption(
"Stabilize the jump-point", OptionId.STABILIZE,
null);
544 addText(
"This wormhole is not connected to any other termini and is effectively unusable.");
546 addText(getString(
"noExits"));
550 }
else if (isStarAnchor && !okToUseIfAnchor) {
551 addText(getString(
"starAnchorUnusable"));
555 if (index >= jumpOptions.size())
break;
556 OptionId option = jumpOptions.get(index);
560 options.
addOption(
"Initiate a transit to " + dest.getLabelInInteractionDialog(), option,
null);
562 boolean canUse = WormholeScannerPlugin.canPlayerUseWormholes();
565 options.
setTooltip(option,
"Using a wormhole requires a wormhole scanner.");
569 options.
addOption(
"Order a jump to " + dest.getLabelInInteractionDialog(), option,
null);
571 destinationMap.put(option, dest);
577 options.
addOption(
"Shut down the wormhole and retrieve the anchor", OptionId.RETRIEVE_ANCHOR,
null);
580 options.
addOption(
"Leave", OptionId.LEAVE,
null);
581 options.
setShortcut(OptionId.LEAVE, Keyboard.KEY_ESCAPE,
false,
false,
false,
true);
583 if (Global.getSettings().getBoolean(
"oneClickJumpPoints")) {
591 if (Global.getSettings().isDevMode()) {
592 DevMenuOptions.addOptions(dialog);
608 private void addText(String text) {
612 private void appendText(String text) {
616 private String getString(String
id) {
619 String fleetOrShip =
"fleet";
621 fleetOrShip =
"ship";
623 fleetOrShip =
"fighter wing";
626 str = str.replaceAll(
"\\$fleetOrShip", fleetOrShip);
static SettingsAPI getSettings()
static SoundPlayerAPI getSoundPlayer()
static FactoryAPI getFactory()
static SectorAPI getSector()
static final String LOCAL
static final String FACTION
static final String MARKET
static final String GLOBAL
static final String PLAYER
static final String CAN_STABILIZE
static float WORMHOLE_FUEL_USE_MULT
Map< String, MemoryAPI > getMemoryMap()
void backFromEngagement(EngagementResultAPI result)
void advance(float amount)
static final String UNSTABLE_KEY
void optionSelected(String text, Object optionData)
void init(InteractionDialogAPI dialog)
OptionId lastOptionMousedOver
void optionMousedOver(String optionText, Object optionData)
void showWarningIfNeeded()
List< FactionAPI > getFactionsThatWouldBecomeHostile()
static final String TRANSPONDER
static final String TRANSVERSE_JUMP
static final String CUSTOM_ALLOWS_TRANSPONDER_OFF_TRADE
static final String PLAYER
static final String MEMORY_KEY_PIRATE
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
static final String OPTION_ID
static void addWormholeIntelIfNeeded(SectorEntityToken entity, TextPanelAPI textPanel, boolean deployed)
void removeWormhole(JumpPointAPI jp, InteractionDialogAPI dialog)
static WormholeManager get()
static boolean isTutorialInProgress()
static int getDangerLevel(CampaignFleetAPI fleet)
static Color getNegativeHighlightColor()
static String getStringForDays(int days)
static float getDistance(SectorEntityToken from, SectorEntityToken to)
static Color getHighlightColor()
Description getDescription(String id, Type type)
String getString(String category, String id)
Color getColor(String id)
SoundAPI playUISound(String id, float pitch, float volume)
LocationAPI getContainingLocation()
FleetDataAPI getFleetData()
FleetLogisticsAPI getLogistics()
MutableCharacterStatsAPI getCommanderStats()
void setFollowingDirectCommand(boolean followingDirectCommand)
void removeFuel(float quantity)
List< FleetMemberAPI > getMembersListCopy()
void setBackgroundDimAmount(float backgroundDimAmount)
TextPanelAPI getTextPanel()
VisualPanelAPI getVisualPanel()
void setOpacity(float opacity)
SectorEntityToken getInteractionTarget()
void addOptionSelectedText(Object optionId)
void setOptionOnEscape(String text, Object optionId)
OptionPanelAPI getOptionPanel()
List< JumpDestination > getDestinations()
String getNameWithLowercaseType()
List< CampaignFleetAPI > getFleets()
void setTooltip(Object data, String tooltipText)
void addOption(String text, Object data)
void setEnabled(Object data, boolean enabled)
void setShortcut(Object data, int code, boolean ctrl, boolean alt, boolean shift, boolean putLast)
SectorEntityToken getCourseTarget()
CampaignFleetAPI getPlayerFleet()
void doHyperspaceTransition(CampaignFleetAPI fleet, SectorEntityToken jumpLocation, JumpDestination dest)
void setPaused(boolean paused)
PersistentUIDataAPI getUIData()
CampaignUIAPI getCampaignUI()
CharacterDataAPI getCharacterData()
LocationAPI getContainingLocation()
boolean hasAbility(String id)
String getCustomDescriptionId()
MemoryAPI getMemoryWithoutUpdate()
AbilityPlugin getAbility(String id)
boolean isTransponderOn()
InteractionDialogImageVisual getCustomInteractionDialogImageVisual()
LabelAPI addPara(String text)
LabelAPI addParagraph(String text)
void appendToLastParagraph(String text)
void highlightInLastPara(Color color, String ...strings)
void setVisualFade(float in, float out)
void showImagePortion(String category, String id, float x, float y, float w, float h, float xOffset, float yOffset, float displayWidth, float displayHeight)
void showImageVisual(InteractionDialogImageVisual visual)
List< MarketAPI > getMarkets(LocationAPI loc)
float getExpire(String key)
void expire(String key, float days)
boolean getBoolean(String key)
float getSkillLevel(String id)
float getFuelCostPerLightYear()
void setHighlight(int start, int end)
void setHighlightColor(Color color)