Starsector API
Loading...
Searching...
No Matches
BreadcrumbSpecial.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special;
2
3import org.lwjgl.util.vector.Vector2f;
4
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;
26
28
29
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;
35 }
36
37 public SalvageSpecialPlugin createSpecialPlugin() {
38 return new BreadcrumbSpecial();
39 }
40 }
41
42 private BreadcrumbSpecialData data;
43
45 }
46
47
48 @Override
49 public void init(InteractionDialogAPI dialog, Object specialData) {
50 super.init(dialog, specialData);
51
52 data = (BreadcrumbSpecialData) specialData;
53
54 initEntityLocation();
55 }
56
57 private void initEntityLocation() {
58 if (data.targetId == null) {
60 return;
61 }
62
63 SectorEntityToken target = Global.getSector().getEntityById(data.targetId);
64 if (target == null) {
66 return;
67 }
68
69 // already discovered
70 if (!target.hasSensorProfile() && !target.isDiscoverable()) {
72 return;
73 }
74
75
76 String targetName = getNameWithAOrAn(target, data.targetName, true, false);
77 String targetNameUC = getNameWithAOrAn(target, data.targetName, false, true);
78 //String entityName = getNameWithAOrAn(entity, null);
79 String located = getLocatedString(target, true);
80
81 String nameForTitle = targetNameUC.substring(targetNameUC.indexOf(" ") + 1);
82 //if (target.getCu)
83 String subject = getString("Location: " + nameForTitle);
84
85
86 String text1 = "The $shortName's memory banks are partially accessible, and ";
87 text1 += "contain information indicating that " + targetName + " is " + located + ".";
88
89 String text1ForIntel = "While exploring $aOrAn $nameInText, your crews found a " +
90 "partially accessible memory bank " +
91 "containing information that indicates " + targetName + " is " + located + ".";
92
93 boolean debris = Entities.DEBRIS_FIELD_SHARED.equals(entity.getCustomEntityType());
94 if (debris) {
95 text1 = "Your salvage crews find a functional memory bank in the debris. It contains information " +
96 "indicating that " + targetName.toLowerCase() + " is " + located + ".";
97 }
98
99
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) {
104 variant = Global.getSettings().getVariant(dsep.getData().ship.variantId);
105 }
106 if (variant != null) {
107 String size = 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.";
111 } else {
112 size = "The vessel is likely to be at least cruiser-sized.";
113 }
114
115 if (size != null) {
116 text1 += "\n\n" + size;
117 text1ForIntel += "\n\n" + size;
118 }
119 }
120 }
121
122 addText(text1);
123
124 BreadcrumbIntel intel = new BreadcrumbIntel(entity, target);
125 intel.setTitle(getString(subject));
126 intel.setText(getString(text1ForIntel));
127 Global.getSector().getIntelManager().addIntel(intel, false, text);
128
129// CommMessageAPI message = FleetLog.beginEntry(subject, target);
130// message.getSection1().addPara(getString(text1));
131// FleetLog.addToLog(message, text);
132
133 //unsetData();
134 setDone(true);
135 //setShowAgain(true);
136 }
137
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();
152 } else {
153 targetName = target.getName();
154 }
155 }
156 if (lowercaseDebris && target.hasTag(Tags.DEBRIS_FIELD)) {
157 targetName = targetName.toLowerCase();
158 }
159 return targetAOrAn + " " + targetName;
160 }
161
162 public static String getLocatedString(SectorEntityToken target) {
163 return getLocatedString(target, false);
164 }
165 public static String getLocatedString(SectorEntityToken target, boolean withSystem) {
166 String loc = getLocationDescription(target, withSystem);
167
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 ";
177 } else {
178 float dist = Misc.getDistance(focus.getLocation(), target.getLocation());
179 //float dist = Misc.getDistance(new Vector2f(), target.getLocation());
180 if (dist < 3000) {
181 orbiting = "located in the heart of ";
182 } else if (dist > 12000) {
183 orbiting = "located in the outer reaches of ";
184 } else {
185 //orbiting = "located in ";
186 orbiting = "located some distance away from the center of ";
187 }
188 useTerrain = true;
189 }
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 + " ";
200
201 float dist = Misc.getDistance(new Vector2f(), target.getLocation());
202 if (dist < 3000) {
203 orbiting += "in the heart of ";
204 } else if (dist > 12000) {
205 orbiting += "in the outer reaches of ";
206 } else {
207 orbiting += "some distance away from the center of ";
208 }
209 } else { // center of a binary/nebula/etc
210 //float dist = Misc.getDistance(target.getOrbitFocus().getLocation(), target.getLocation());
211 float dist = Misc.getDistance(new Vector2f(), target.getLocation());
212 if (dist < 3000) {
213 orbiting = "located in the heart of ";
214 } else if (dist > 12000) {
215 orbiting = "located in the outer reaches of ";
216 } else {
217 //orbiting = "located in ";
218 orbiting = "located some distance away from the center of ";
219 }
220 useTerrain = true;
221 }
222 } else if (target.getContainingLocation() != null && target.getContainingLocation().isNebula()) {
223 float dist = Misc.getDistance(new Vector2f(), target.getLocation());
224 if (dist < 3000) {
225 orbiting = "located in the heart of ";
226 } else if (dist > 12000) {
227 orbiting = "located on the outskirts of ";
228 } else {
229 //orbiting = "located in ";
230 orbiting = "located some distance away from the center of ";
231 }
232 useTerrain = true;
233 }
234
235 if (useTerrain) {
236 String terrainString = getTerrainString(target);
237 if (terrainString != null) {
238 orbiting = "located in " + terrainString + " in ";
239 }
240 }
241
242 if (orbiting == null || orbiting.isEmpty()) orbiting = "located in ";
243 return orbiting + loc;
244 }
245
246 public static String getTerrainString(SectorEntityToken entity) {
247 if (!(entity.getContainingLocation() instanceof StarSystemAPI)) return null;
248
249 StarSystemAPI system = (StarSystemAPI) entity.getContainingLocation();
250 for (CampaignTerrainAPI terrain : system.getTerrainCopy()) {
251 if (!terrain.getPlugin().containsEntity(entity)) continue;
252
253 String type = terrain.getType();
254
255 if (Terrain.ASTEROID_BELT.equals(type)) return "an asteroid belt";
256 if (Terrain.ASTEROID_FIELD.equals(type)) return "an asteroid field";
257 //if (Terrain.MAGNETIC_FIELD.equals(type)) return "a magnetic field";
258 if (terrain.hasTag(Tags.ACCRETION_DISK)) return "an accretion disk";
259 if (Terrain.RING.equals(type)) return "a ring system";
260 }
261
262 return null;
263 }
264
265 public static String getLocationDescription(SectorEntityToken entity, boolean withSystem) {
266 LocationAPI loc = entity.getContainingLocation();
267 if (loc == null) {
268 return "an unknown location";
269 }
270 if (loc.isHyperspace()) {
271 return "hyperspace";
272 }
273 StarSystemAPI system = (StarSystemAPI) loc;
274
275// if (system == Global.getSector().getCurrentLocation()) {
276// return "the " + system.getNameWithLowercaseType();
277// }
278
279 //if (entity.getConstellation() != null && entity.getConstellation() != Global.getSector().getCurrentLocation().getConstellation()) {
280 if (withSystem || entity.getConstellation() == null || entity.getConstellation().getSystems().size() == 1 ||
281 entity.isInCurrentLocation()) {
282 return "the " + system.getNameWithLowercaseType();
283 }
284
285 Constellation c = entity.getConstellation();
286 String cText = "in the " + c.getNameWithLowercaseType();
287 if (c.getSystems().size() == 1) {
288 return "the " + system.getNameWithLowercaseType();
289 }
290
291 if (system.isNebula()) {
292 return "a nebula " + cText;
293 }
294
295 if (system.getTertiary() != null) {
296 return "a trinary star system " + cText;
297 }
298
299 if (system.getSecondary() != null) {
300 return "a binary star system " + cText;
301 }
302
303 PlanetAPI star = system.getStar();
304 if (star != null) {
305 if (star.getSpec().isBlackHole()) {
306 return "a black hole system " + cText;
307 }
308
309 //String sysText = star.getSpec().getAOrAn() + " " + star.getSpec().getName().toLowerCase() + " system ";
310
311 String type = getStarTypeName(star);
312 String color = getStarColorName(star);
313
314 String sysText = null;
315 CountingMap<String> counts = getTypeAndColorCounts(c);
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 ";
324 }
325
326 if (sysText != null) {
327 return sysText + cText;
328 }
329 }
330
331 //if (system.getType() == StarSystemType.SINGLE) {
332 return "the " + system.getNameWithLowercaseType() + " " + cText;
333 //return "orbit around " + getStarDescription(system.getStar()) + " " + cText;
334 }
335
336 public static CountingMap<String> getTypeAndColorCounts(Constellation c) {
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;
343
344 String type = getStarTypeName(star);
345 String color = getStarColorName(star);
346 if (type != null) map.add(type);
347 if (color != null) map.add(color);
348 }
349 return map;
350 }
351
352 public static String getStarTypeName(PlanetAPI star) {
353 String name = star.getSpec().getName().toLowerCase();
354 if (name.contains(" dwarf")) {
355 return "dwarf";
356 } else if (name.contains(" star")) {
357 return null;
358 } else if (name.contains(" giant")) {
359 return "giant";
360 } else if (name.contains(" supergiant")) {
361 return "supergiant";
362 }
363 return null;
364 }
365 public static String getStarColorName(PlanetAPI star) {
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", "");
375 }
376 if (!name.equals(star.getSpec().getName().toLowerCase())) {
377 return name;
378 }
379 return null;
380 }
381
382 /*
383 public static String getStarDescription(PlanetAPI star) {
384 String type = star.getTypeId();
385
386 if (type.equals(StarTypes.BLACK_HOLE)) return "a black hole";
387 if (type.equals(StarTypes.NEUTRON_STAR)) return "a neutron star";
388
389 if (type.equals(StarTypes.ORANGE) ||
390 type.equals(StarTypes.ORANGE_GIANT)) {
391 return "an orange star";
392 }
393
394 if (type.equals(StarTypes.RED_DWARF) ||
395 type.equals(StarTypes.RED_SUPERGIANT) ||
396 type.equals(StarTypes.RED_GIANT)) {
397 return "a red star";
398 }
399
400 if (type.equals(StarTypes.BLUE_GIANT) ||
401 type.equals(StarTypes.BLUE_SUPERGIANT)) {
402 return "a blue star";
403 }
404
405 if (type.equals(StarTypes.BROWN_DWARF) ||
406 type.equals(StarTypes.WHITE_DWARF)) {
407 return "a dim star";
408 }
409
410 if (type.equals(StarTypes.YELLOW)) {
411 return "a yellow star";
412 }
413
414 return "a star of unknown type";
415 }
416 */
417
418 @Override
419 public void optionSelected(String optionText, Object optionData) {
420 super.optionSelected(optionText, optionData);
421 }
422
423
424}
425
426
427
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
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)
ShipVariantAPI getVariant(String variantId)