1package com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special;
3import org.lwjgl.util.vector.Vector2f;
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.CampaignTerrainAPI;
7import com.fs.starfarer.api.campaign.CustomCampaignEntityAPI;
8import com.fs.starfarer.api.campaign.InteractionDialogAPI;
9import com.fs.starfarer.api.campaign.JumpPointAPI;
10import com.fs.starfarer.api.campaign.LocationAPI;
11import com.fs.starfarer.api.campaign.PlanetAPI;
12import com.fs.starfarer.api.campaign.SectorEntityToken;
13import com.fs.starfarer.api.campaign.StarSystemAPI;
14import com.fs.starfarer.api.combat.ShipAPI.HullSize;
15import com.fs.starfarer.api.combat.ShipVariantAPI;
16import com.fs.starfarer.api.impl.campaign.DerelictShipEntityPlugin;
17import com.fs.starfarer.api.impl.campaign.ids.Entities;
18import com.fs.starfarer.api.impl.campaign.ids.Tags;
19import com.fs.starfarer.api.impl.campaign.ids.Terrain;
20import com.fs.starfarer.api.impl.campaign.intel.misc.BreadcrumbIntel;
21import com.fs.starfarer.api.impl.campaign.procgen.Constellation;
22import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageSpecialInteraction.SalvageSpecialData;
23import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageSpecialInteraction.SalvageSpecialPlugin;
24import com.fs.starfarer.api.util.CountingMap;
25import com.fs.starfarer.api.util.Misc;
30 public static class BreadcrumbSpecialData
implements SalvageSpecialData {
31 public String targetId =
null;
32 public String targetName =
null;
33 public BreadcrumbSpecialData(String targetId) {
34 this.targetId = targetId;
37 public SalvageSpecialPlugin createSpecialPlugin() {
42 private BreadcrumbSpecialData data;
49 public void init(InteractionDialogAPI
dialog, Object specialData) {
50 super.init(
dialog, specialData);
52 data = (BreadcrumbSpecialData) specialData;
57 private void initEntityLocation() {
58 if (data.targetId ==
null) {
63 SectorEntityToken target =
Global.
getSector().getEntityById(data.targetId);
70 if (!target.hasSensorProfile() && !target.isDiscoverable()) {
77 String targetNameUC =
getNameWithAOrAn(target, data.targetName,
false,
true);
81 String nameForTitle = targetNameUC.substring(targetNameUC.indexOf(
" ") + 1);
83 String subject =
getString(
"Location: " + nameForTitle);
86 String text1 =
"The $shortName's memory banks are partially accessible, and ";
87 text1 +=
"contain information indicating that " + targetName +
" is " + located +
".";
89 String text1ForIntel =
"While exploring $aOrAn $nameInText, your crews found a " +
90 "partially accessible memory bank " +
91 "containing information that indicates " + targetName +
" is " + located +
".";
93 boolean debris = Entities.DEBRIS_FIELD_SHARED.equals(
entity.getCustomEntityType());
95 text1 =
"Your salvage crews find a functional memory bank in the debris. It contains information " +
96 "indicating that " + targetName.toLowerCase() +
" is " + located +
".";
100 if (target.getCustomPlugin() instanceof DerelictShipEntityPlugin) {
101 DerelictShipEntityPlugin dsep = (DerelictShipEntityPlugin) target.getCustomPlugin();
102 ShipVariantAPI variant = dsep.getData().ship.variant;
103 if (variant ==
null && dsep.getData().ship.variantId !=
null) {
106 if (variant !=
null) {
108 if (variant.getHullSize() == HullSize.FRIGATE ||
109 variant.getHullSize() == HullSize.DESTROYER) {
110 size =
"Based on the information, it's likely the ship is small, a frigate or a destroyer at the largest.";
112 size =
"The vessel is likely to be at least cruiser-sized.";
116 text1 +=
"\n\n" + size;
117 text1ForIntel +=
"\n\n" + size;
124 BreadcrumbIntel intel =
new BreadcrumbIntel(
entity, target);
127 Global.getSector().getIntelManager().addIntel(intel,
false,
text);
138 public static String
getNameWithAOrAn(SectorEntityToken target, String override,
boolean lowercaseDebris,
boolean forTitle) {
139 String targetAOrAn =
"a";
140 String targetName = override;
141 if (targetName ==
null) {
142 if (target instanceof CustomCampaignEntityAPI) {
143 CustomCampaignEntityAPI custom = (CustomCampaignEntityAPI) target;
144 targetName = custom.getCustomEntitySpec().getNameInText();
145 if (forTitle) targetName = custom.getName();
146 targetAOrAn = custom.getCustomEntitySpec().getAOrAn();
147 }
else if (target instanceof PlanetAPI) {
148 PlanetAPI planet = (PlanetAPI) target;
149 targetName = planet.getTypeNameWithLowerCaseWorld().toLowerCase();
150 if (forTitle) targetName = planet.getTypeNameWithWorld();
151 targetAOrAn = planet.getSpec().getAOrAn();
153 targetName = target.getName();
156 if (lowercaseDebris && target.hasTag(Tags.DEBRIS_FIELD)) {
157 targetName = targetName.toLowerCase();
159 return targetAOrAn +
" " + targetName;
168 String orbiting =
"";
169 boolean useTerrain =
false;
170 if (target.getOrbitFocus() !=
null) {
171 if (target.getOrbitFocus() instanceof PlanetAPI) {
172 PlanetAPI focus = (PlanetAPI) target.getOrbitFocus();
173 boolean isPrimary = target.getContainingLocation() instanceof StarSystemAPI &&
174 focus == ((StarSystemAPI)target.getContainingLocation()).getStar();
175 if (!focus.isStar() || !isPrimary) {
176 orbiting =
"orbiting " + focus.getSpec().getAOrAn() +
" " + focus.getTypeNameWithLowerCaseWorld().toLowerCase() +
" in ";
178 float dist = Misc.getDistance(focus.getLocation(), target.getLocation());
181 orbiting =
"located in the heart of ";
182 }
else if (dist > 12000) {
183 orbiting =
"located in the outer reaches of ";
186 orbiting =
"located some distance away from the center of ";
190 }
else if (target.getOrbitFocus() instanceof CustomCampaignEntityAPI) {
191 CustomCampaignEntityAPI custom = (CustomCampaignEntityAPI) target.getOrbitFocus();
192 orbiting =
"orbiting " + custom.getCustomEntitySpec().getAOrAn() +
" " + custom.getCustomEntitySpec().getNameInText() +
" in ";
193 }
else if (target.getOrbitFocus() instanceof JumpPointAPI) {
194 orbiting =
"orbiting a jump-point in ";
195 }
else if (target.getOrbitFocus() instanceof CampaignTerrainAPI) {
196 CampaignTerrainAPI t = (CampaignTerrainAPI) target.getOrbitFocus();
197 String n = t.getPlugin().getNameForTooltip().toLowerCase();
198 String a = Misc.getAOrAnFor(n);
199 orbiting =
"located inside " + a +
" " + n +
" ";
201 float dist = Misc.getDistance(
new Vector2f(), target.getLocation());
203 orbiting +=
"in the heart of ";
204 }
else if (dist > 12000) {
205 orbiting +=
"in the outer reaches of ";
207 orbiting +=
"some distance away from the center of ";
211 float dist = Misc.getDistance(
new Vector2f(), target.getLocation());
213 orbiting =
"located in the heart of ";
214 }
else if (dist > 12000) {
215 orbiting =
"located in the outer reaches of ";
218 orbiting =
"located some distance away from the center of ";
222 }
else if (target.getContainingLocation() !=
null && target.getContainingLocation().isNebula()) {
223 float dist = Misc.getDistance(
new Vector2f(), target.getLocation());
225 orbiting =
"located in the heart of ";
226 }
else if (dist > 12000) {
227 orbiting =
"located on the outskirts of ";
230 orbiting =
"located some distance away from the center of ";
237 if (terrainString !=
null) {
238 orbiting =
"located in " + terrainString +
" in ";
242 if (orbiting ==
null || orbiting.isEmpty()) orbiting =
"located in ";
243 return orbiting + loc;
247 if (!(
entity.getContainingLocation() instanceof StarSystemAPI))
return null;
249 StarSystemAPI system = (StarSystemAPI)
entity.getContainingLocation();
250 for (CampaignTerrainAPI terrain : system.getTerrainCopy()) {
251 if (!terrain.getPlugin().containsEntity(
entity))
continue;
253 String type = terrain.getType();
255 if (Terrain.ASTEROID_BELT.equals(type))
return "an asteroid belt";
256 if (Terrain.ASTEROID_FIELD.equals(type))
return "an asteroid field";
258 if (terrain.hasTag(Tags.ACCRETION_DISK))
return "an accretion disk";
259 if (Terrain.RING.equals(type))
return "a ring system";
266 LocationAPI loc =
entity.getContainingLocation();
268 return "an unknown location";
270 if (loc.isHyperspace()) {
273 StarSystemAPI system = (StarSystemAPI) loc;
280 if (withSystem ||
entity.getConstellation() ==
null ||
entity.getConstellation().getSystems().size() == 1 ||
281 entity.isInCurrentLocation()) {
282 return "the " + system.getNameWithLowercaseType();
285 Constellation c =
entity.getConstellation();
286 String cText =
"in the " + c.getNameWithLowercaseType();
287 if (c.getSystems().size() == 1) {
288 return "the " + system.getNameWithLowercaseType();
291 if (system.isNebula()) {
292 return "a nebula " + cText;
295 if (system.getTertiary() !=
null) {
296 return "a trinary star system " + cText;
299 if (system.getSecondary() !=
null) {
300 return "a binary star system " + cText;
303 PlanetAPI star = system.getStar();
305 if (star.getSpec().isBlackHole()) {
306 return "a black hole system " + cText;
314 String sysText =
null;
316 int cColor = counts.getCount(color);
317 int cType = counts.getCount(type);
318 if (cColor > 1 && cType > cColor) {
319 sysText =
"a system with " + star.getSpec().getAOrAn() +
" " + color +
" primary star ";
320 }
else if (cType > 0) {
321 sysText =
"a system with " +
"a" +
" " + type +
" primary star ";
322 }
else if (cColor > 0) {
323 sysText =
"a system with " + star.getSpec().getAOrAn() +
" " + color +
" primary star ";
326 if (sysText !=
null) {
327 return sysText + cText;
332 return "the " + system.getNameWithLowercaseType() +
" " + cText;
337 CountingMap<String> map =
new CountingMap<String>();
338 for (StarSystemAPI system : c.getSystems()) {
339 PlanetAPI star = system.getStar();
340 if (system.isNebula())
continue;
341 if (system.getSecondary() !=
null)
continue;
342 if (system.getTertiary() !=
null)
continue;
346 if (type !=
null) map.add(type);
347 if (color !=
null) map.add(color);
353 String name = star.getSpec().getName().toLowerCase();
354 if (name.contains(
" dwarf")) {
356 }
else if (name.contains(
" star")) {
358 }
else if (name.contains(
" giant")) {
360 }
else if (name.contains(
" supergiant")) {
366 String name = star.getSpec().getName().toLowerCase();
367 if (name.contains(
" dwarf")) {
368 name = name.replace(
" dwarf",
"");
369 }
else if (name.contains(
" star")) {
370 name = name.replace(
" star",
"");
371 }
else if (name.contains(
" giant")) {
372 name = name.replace(
" giant",
"");
373 }
else if (name.contains(
" supergiant")) {
374 name = name.replace(
" supergiant",
"");
376 if (!name.equals(star.getSpec().getName().toLowerCase())) {
420 super.optionSelected(optionText, optionData);
static SettingsAPI getSettings()
static SectorAPI getSector()
void setDone(boolean done)
InteractionDialogAPI dialog
void addText(String format)
String getString(String format)
static String getTerrainString(SectorEntityToken entity)
void init(InteractionDialogAPI dialog, Object specialData)
static CountingMap< String > getTypeAndColorCounts(Constellation c)
static String getStarTypeName(PlanetAPI star)
void optionSelected(String optionText, Object optionData)
static String getStarColorName(PlanetAPI star)
static String getLocatedString(SectorEntityToken target, boolean withSystem)
static String getLocationDescription(SectorEntityToken entity, boolean withSystem)
static String getNameWithAOrAn(SectorEntityToken target, String override, boolean lowercaseDebris, boolean forTitle)
static String getLocatedString(SectorEntityToken target)
ShipVariantAPI getVariant(String variantId)