Starsector API
Loading...
Searching...
No Matches
SurveyDataSpecial.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special;
2
3import java.util.List;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.InteractionDialogAPI;
7import com.fs.starfarer.api.campaign.PlanetAPI;
8import com.fs.starfarer.api.campaign.SectorEntityToken;
9import com.fs.starfarer.api.campaign.StarSystemAPI;
10import com.fs.starfarer.api.campaign.econ.MarketAPI.SurveyLevel;
11import com.fs.starfarer.api.characters.MarketConditionSpecAPI;
12import com.fs.starfarer.api.impl.campaign.ids.Conditions;
13import com.fs.starfarer.api.impl.campaign.ids.Entities;
14import com.fs.starfarer.api.impl.campaign.intel.misc.BreadcrumbIntel;
15import com.fs.starfarer.api.impl.campaign.procgen.themes.DerelictThemeGenerator;
16import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageSpecialInteraction.SalvageSpecialData;
17import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageSpecialInteraction.SalvageSpecialPlugin;
18import com.fs.starfarer.api.plugins.SurveyPlugin;
19import com.fs.starfarer.api.util.Highlights;
20import com.fs.starfarer.api.util.Misc;
21import com.fs.starfarer.api.util.WeightedRandomPicker;
22
24
25 public static float MAX_RANGE = 16000f;
26
27 public static enum SurveyDataSpecialType {
28 SCRAMBLED, // used when the planet is already surveyed or doesn't exist anymore or nothing is found etc
29 PLANET_INTERESTING_PROPERTY,
30 PLANET_SURVEY_DATA,
31 SYSTEM_PRELIMINARY_SURVEY,
32 AUTO_PICK, // generate one of the above automatically, for a nearby planet or system
33 AUTO_PICK_NOT_SYSTEM, // pick either property or data, but not full system
34 }
35
36
37 public static class SurveyDataSpecialData implements SalvageSpecialData {
38 public SurveyDataSpecialType type = null;
39 public String entityId = null;
40 public String secondaryId = null;
41 public boolean includeRuins = true;
42 public SurveyDataSpecialData(SurveyDataSpecialType type) {
43 this.type = type;
44 }
45
46 public SalvageSpecialPlugin createSpecialPlugin() {
47 return new SurveyDataSpecial();
48 }
49 }
50
51 private SurveyDataSpecialData data;
52
54 }
55
56 @Override
57 public void init(InteractionDialogAPI dialog, Object specialData) {
58 super.init(dialog, specialData);
59
60 data = (SurveyDataSpecialData) specialData;
61
62 //random = new Random();
63
64 if (data.type == SurveyDataSpecialType.AUTO_PICK ||
65 data.type == SurveyDataSpecialType.AUTO_PICK_NOT_SYSTEM) {
66 WeightedRandomPicker<SurveyDataSpecialType> picker = new WeightedRandomPicker<SurveyDataSpecialType>(random);
67 picker.add(SurveyDataSpecialType.PLANET_INTERESTING_PROPERTY, 50f);
68 picker.add(SurveyDataSpecialType.PLANET_SURVEY_DATA, 20f);
69
70 if (data.type == SurveyDataSpecialType.AUTO_PICK) {
71 picker.add(SurveyDataSpecialType.SYSTEM_PRELIMINARY_SURVEY, 5f);
72 }
73
74 data.type = picker.pick();
75 data.entityId = null;
76
77 if (data.type == SurveyDataSpecialType.PLANET_INTERESTING_PROPERTY) {
78 List<StarSystemAPI> systems = Misc.getSystemsInRange(entity, null, true, MAX_RANGE);
79 PlanetAPI planet = DerelictThemeGenerator.findInterestingPlanet(systems, null, false, data.includeRuins, random);
80 String conditionId = DerelictThemeGenerator.getInterestingCondition(planet, data.includeRuins);
81 if (planet != null && conditionId != null) {
82 data.entityId = planet.getId();
83 data.secondaryId = conditionId;
84 }
85 } else if (data.type == SurveyDataSpecialType.PLANET_SURVEY_DATA) {
86 List<StarSystemAPI> systems = Misc.getSystemsInRange(entity, null, true, MAX_RANGE);
87 PlanetAPI planet = DerelictThemeGenerator.findInterestingPlanet(systems, null, false, data.includeRuins, random);
88 if (planet != null) {
89 data.entityId = planet.getId();
90 }
91 } else if (data.type == SurveyDataSpecialType.SYSTEM_PRELIMINARY_SURVEY) {
92 StarSystemAPI system = DerelictThemeGenerator.findNearbySystem(entity, null, random, MAX_RANGE);
93 if (system != null) {
94 data.entityId = system.getId();
95 }
96 }
97 }
98
99
100 if (data.entityId != null) {
101 SectorEntityToken entity = Global.getSector().getEntityById(data.entityId);
102 StarSystemAPI system = Global.getSector().getStarSystem(data.entityId);
103 if (entity == null && system == null) {
104 data.entityId = null;
105 data.type = SurveyDataSpecialType.SCRAMBLED;
106 }
107 } else {
108 data.type = SurveyDataSpecialType.SCRAMBLED;
109 }
110
111
112 switch (data.type) {
113 case SCRAMBLED:
114 initNothing();
115 break;
116 case PLANET_INTERESTING_PROPERTY:
118 break;
119 case PLANET_SURVEY_DATA:
121 break;
122 case SYSTEM_PRELIMINARY_SURVEY:
124 break;
125 }
126
127 }
128
129 public void initNothing() {
130 addText("The $shortName's memory banks have been scrubbed clean by hard radiation, and the systems are largely inert and non-functional.");
131 setDone(true);
132 }
133
134
135 protected void initInterestingProperty() {
136 if (data.entityId == null || data.secondaryId == null) {
137 initNothing();
138 return;
139 }
140
141 PlanetAPI planet = (PlanetAPI) Global.getSector().getEntityById(data.entityId);
142 if (planet.getMarket() != null && planet.getMarket().getSurveyLevel() == SurveyLevel.FULL) {
143 initNothing();
144 return;
145 }
146
147 String text1 = getString("The $shortName's memory banks are partially accessible, and the data therein ");
148 boolean debris = Entities.DEBRIS_FIELD_SHARED.equals(entity.getCustomEntityType());
149 if (debris) {
150 text1 = "Your salvage crews find a memory bank in the debris. The data therein ";
151 }
152
153 String desc = "";
154 String world = planet.getSpec().getAOrAn() + " " + planet.getTypeNameWithWorld().toLowerCase();
155
156 String loc = BreadcrumbSpecial.getLocatedString(planet, true);
157 loc = loc.replaceFirst("located ", "");
158
159 String subject = "";
160 MarketConditionSpecAPI spec = Global.getSettings().getMarketConditionSpec(data.secondaryId);
161 if (spec.getId().equals(Conditions.HABITABLE)) {
162 subject = "Habitable World";
163 desc = "points to the existence of " + world + " with a low hazard rating " + loc;
164
165 } else {
166 subject = Misc.ucFirst(spec.getName()) + " Location";
167 desc = "contained information about " + spec.getName().toLowerCase() + " on " + world + " " + loc;
168 }
169
170 desc += ".";
171
172 addText(text1 + desc);
173
174
175 String text1ForIntel = "While exploring $aOrAn $nameInText, your crews found " +
176 "partially accessible memory banks that ";
177
178 BreadcrumbIntel intel = new BreadcrumbIntel(entity, planet);
179 intel.setTitle(getString(subject));
180 intel.setText(getString(text1ForIntel + desc));
181 Global.getSector().getIntelManager().addIntel(intel, false, text);
182
183// CommMessageAPI message = FleetLog.beginEntry(subject, planet);
184// message.getSection1().addPara(getString(text1 + desc));
185// FleetLog.addToLog(message, text);
186
187 setDone(true);
188 }
189
190
191 protected void initPlanetSurveyData() {
192 if (data.entityId == null) {
193 initNothing();
194 return;
195 }
196
197 PlanetAPI planet = (PlanetAPI) Global.getSector().getEntityById(data.entityId);
198 if (planet.getMarket() != null && planet.getMarket().getSurveyLevel() == SurveyLevel.FULL) {
199 initNothing();
200 return;
201 }
202
203
204 String name = planet.getName();
205 String world = planet.getSpec().getAOrAn() + " " + planet.getTypeNameWithWorld().toLowerCase();
206 //String loc = getLocationName(planet);
207 String loc = BreadcrumbSpecial.getLocatedString(planet, true);
208 loc = loc.replaceFirst("located ", "");
209
210 String text1 = "The $shortName's memory banks are partially accessible, " +
211 "and contain full survey data for " + name + ", " + world + " located " + loc + ".";
212
213 String text1ForIntel = "While exploring $aOrAn $nameInText, your crews found " +
214 "partially accessible memory banks that contain full survey data for " +
215 name + ", " + world + " located " + loc + ".";
216
217 boolean debris = Entities.DEBRIS_FIELD_SHARED.equals(entity.getCustomEntityType());
218 if (debris) {
219 text1 = "Your salvage crews find a functional memory bank in the debris. " +
220 "It contains full survey data for " + name + ", " + world + " located " + loc + ".";
221 }
222
223 String conditionId = DerelictThemeGenerator.getInterestingCondition(planet, data.includeRuins);
224 if (conditionId != null) {
225 MarketConditionSpecAPI spec = Global.getSettings().getMarketConditionSpec(conditionId);
226 if (spec != null) {
227 text1 += " The world is notable for ";
228 text1ForIntel += " The world is notable for ";
229 if (conditionId.equals(Conditions.HABITABLE)) {
230 text1 += "being habitable.";
231 text1ForIntel += "being habitable.";
232 } else {
233 text1 += "having " + spec.getName().toLowerCase() + ".";
234 text1ForIntel += "having " + spec.getName().toLowerCase() + ".";
235 }
236 }
237 }
238
239
240 //planet.getMarket().setSurveyLevel(SurveyLevel.PRELIMINARY);
241
242 String subject = "Survey Data for " + name;
243
244 addText(text1);
245 Misc.setFullySurveyed(planet.getMarket(), null, false);
246 Misc.addSurveyDataFor(planet, text);
247// text.setFontSmallInsignia();
248// text.addParagraph("Acquired full survey data for " + name + ", " + planet.getTypeNameWithWorld().toLowerCase(),
249// planet.getSpec().getIconColor());
250// text.setFontInsignia();
251
252 SurveyPlugin plugin = (SurveyPlugin) Global.getSettings().getNewPluginInstance("surveyPlugin");
253 plugin.init(Global.getSector().getPlayerFleet(), planet);
254 long xp = plugin.getXP();
255 if (xp > 0) {
256 Global.getSector().getPlayerPerson().getStats().addXP(xp, text);
257 }
258
259
260 BreadcrumbIntel intel = new BreadcrumbIntel(entity, planet);
261 intel.setTitle(getString(subject));
262 intel.setText(getString(text1ForIntel));
263 intel.setShowSpecificEntity(true);
264 Global.getSector().getIntelManager().addIntel(intel, false, text);
265
266// CommMessageAPI message = FleetLog.beginEntry(subject, planet);
267// message.getSection1().addPara(getString(text1));
268// FleetLog.addToLog(message, text);
269
270 //unsetData();
271 setDone(true);
272 }
273
274
276 if (data.entityId == null) {
277 initNothing();
278 return;
279 }
280
281 StarSystemAPI system = Global.getSector().getStarSystem(data.entityId);
282 if (system == null) {
283 initNothing();
284 return;
285 }
286
287 String name = system.getNameWithLowercaseType();
288 String text1 = "The $shortName's memory banks are partially accessible, " +
289 "and contain complete preliminary survey data for the " + name + ".";
290
291 String text1ForIntel = "While exploring $aOrAn $nameInText, your crews found " +
292 "partially accessible memory banks that contain complete preliminary survey data for the " + name + ".";
293
294
295 boolean debris = Entities.DEBRIS_FIELD_SHARED.equals(entity.getCustomEntityType());
296 if (debris) {
297 text1 = "Your salvage crews find a functional memory bank in the debris. " +
298 "It contains complete preliminary survey data for the " + name + ".";
299 }
300
301
302 String subject = "Preliminary Survey of the " + system.getName();
303
304 addText(text1);
305
306 String data = "";
307 Highlights h = new Highlights();
308 for (PlanetAPI planet : system.getPlanets()) {
309 if (planet.isStar()) continue;
310 if (planet.getMarket() == null) continue;
311 if (!planet.getMarket().isPlanetConditionMarketOnly()) continue;
312 if (planet.getMarket().getSurveyLevel().ordinal() > SurveyLevel.PRELIMINARY.ordinal()) continue;
313
314 String curr = planet.getName() + ", " + planet.getTypeNameWithWorld().toLowerCase();
315 data += " " + curr + "\n";
316 h.append(curr, planet.getSpec().getIconColor());
317
318// text.addParagraph(" " + planet.getName() + ", " + planet.getTypeNameWithWorld().toLowerCase(),
319// planet.getSpec().getIconColor());
320 planet.getMarket().setSurveyLevel(SurveyLevel.PRELIMINARY);
321
322 //Misc.setPreliminarySurveyed(planet.getMarket(), text, true);
323 }
324
325 //data = "";
326
327 if (!data.isEmpty()) {
328 text.setFontSmallInsignia();
329 text.addParagraph("Preliminary survey data for:", Misc.getTooltipTitleAndLightHighlightColor());
330 //data = data.substring(0, data.length() - 2);
331 data = " " + data.trim();
332 text.addParagraph(data);
333 text.setHighlightsInLastPara(h);
334 text.setFontInsignia();
335
336// CommMessageAPI message = FleetLog.beginEntry(subject, system.getCenter());
337// message.getSection1().addPara(getString(text1));
338// FleetLog.addToLog(message, text);
339
340
341 BreadcrumbIntel intel = new BreadcrumbIntel(entity, system.getCenter());
342 intel.setTitle(getString(subject));
343 intel.setText(getString(text1ForIntel));
344 Global.getSector().getIntelManager().addIntel(intel, false, text);
345
346 } else {
347 text.addParagraph("However, you've already acquired this data through other means.");
348 }
349
350 //unsetData();
351 setDone(true);
352 }
353
354
355 @Override
356 public void optionSelected(String optionText, Object optionData) {
357 super.optionSelected(optionText, optionData);
358 }
359
360
361
362}
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
MarketConditionSpecAPI getMarketConditionSpec(String conditionId)
Object getNewPluginInstance(String id)