Starsector API
Loading...
Searching...
No Matches
PlanetaryShieldBarEvent.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.bar.events;
2
3import java.util.LinkedHashSet;
4import java.util.Map;
5import java.util.Set;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CargoAPI;
9import com.fs.starfarer.api.campaign.InteractionDialogAPI;
10import com.fs.starfarer.api.campaign.OptionPanelAPI;
11import com.fs.starfarer.api.campaign.PlanetAPI;
12import com.fs.starfarer.api.campaign.TextPanelAPI;
13import com.fs.starfarer.api.campaign.econ.MarketAPI;
14import com.fs.starfarer.api.campaign.rules.MemoryAPI;
15import com.fs.starfarer.api.characters.FullName.Gender;
16import com.fs.starfarer.api.characters.PersonAPI;
17import com.fs.starfarer.api.impl.campaign.DebugFlags;
18import com.fs.starfarer.api.impl.campaign.ids.Factions;
19import com.fs.starfarer.api.impl.campaign.ids.Ranks;
20import com.fs.starfarer.api.impl.campaign.ids.Tags;
21import com.fs.starfarer.api.impl.campaign.procgen.themes.MiscellaneousThemeGenerator;
22import com.fs.starfarer.api.util.Misc;
23import com.fs.starfarer.api.util.WeightedRandomPicker;
24
26
27 public static enum OptionId {
28 INIT,
29 APOLOGIZE,
30 CONTINUE_1,
31 CONTINUE_2,
32 WHERE_WAS_SYSTEM,
33 CONTINUE_3,
34 LEAVE,
35
36 }
37
38 public static PlanetAPI getTargetPlanet() {
39 return (PlanetAPI) Global.getSector().getMemoryWithoutUpdate().get(MiscellaneousThemeGenerator.PLANETARY_SHIELD_PLANET_KEY);
40 }
41
42
44 super();
45 }
46
47 public boolean shouldShowAtMarket(MarketAPI market) {
48 if (!super.shouldShowAtMarket(market)) return false;
49
50
51 if (market.getFactionId().equals(Factions.LUDDIC_CHURCH) ||
52 market.getFactionId().equals(Factions.LUDDIC_PATH)) {
53 return false;
54 }
55
56 if (getTargetPlanet() == null) return false;
57
58 if (Global.getSector().getIntelManager().hasIntelOfClass(PlanetaryShieldIntel.class)) {
59 return false;
60 }
61
62 if (Global.getSector().getPlayerStats().getLevel() < 10 && !DebugFlags.BAR_DEBUG) return false;
63
64 return true;
65 }
66
67 protected PersonAPI pilot;
68 protected MarketAPI pilotMarket = null;
69 @Override
70 protected void regen(MarketAPI market) {
71 if (this.market == market) return;
72 super.regen(market);
73
74 if (person.getGender() == Gender.MALE) {
75 person.setPortraitSprite(Global.getSettings().getSpriteName("intel", "old_spacer_male"));
76 } else {
77 person.setPortraitSprite(Global.getSettings().getSpriteName("intel", "old_spacer_female"));
78 }
79
80 pilot = Global.getSector().getFaction(Factions.INDEPENDENT).createRandomPerson(random);
81 pilot.setRankId(Ranks.PILOT);
82 pilot.setPostId(Ranks.POST_CITIZEN);
83
84 WeightedRandomPicker<MarketAPI> picker = new WeightedRandomPicker<MarketAPI>(random);
85 for (MarketAPI curr : Global.getSector().getEconomy().getMarketsInGroup(null)) {
86 if (curr == market) continue;
87 if (curr.isPlayerOwned()) continue;
88 if (curr.isHidden()) continue;
89 if (curr.isInvalidMissionTarget()) continue;
90 if (curr.getStabilityValue() <= 0) continue;
91
92 float w = curr.getSize();
93 if (curr.isFreePort()) w += 10f;
94 picker.add(curr, w);
95 }
96
97 if (picker.isEmpty()) picker.add(market, 1f);
98
99 pilotMarket = picker.pick();
100 }
101
102 @Override
103 public void addPromptAndOption(InteractionDialogAPI dialog, Map<String, MemoryAPI> memoryMap) {
104 super.addPromptAndOption(dialog, memoryMap);
105
106 regen(dialog.getInteractionTarget().getMarket());
107
108 TextPanelAPI text = dialog.getTextPanel();
109 text.addPara("A rough-looking veteran spacer with cybernetic eyes seems to be staring intently at you; " +
110 "it's a little unnerving.");
111
112// Color c = Misc.getHighlightColor();
113// c = Misc.getHighlightedOptionColor();
114
115 dialog.getOptionPanel().addOption("Ask the veteran spacer what " + getHeOrShe() + "'s looking at", this,
116 null);
117 }
118
119
120 @Override
121 public void init(InteractionDialogAPI dialog, Map<String, MemoryAPI> memoryMap) {
122 super.init(dialog, memoryMap);
123
124 done = false;
125
126 dialog.getVisualPanel().showPersonInfo(person, true);
127
128 optionSelected(null, OptionId.INIT);
129 }
130
131 @Override
132 public void optionSelected(String optionText, Object optionData) {
133 if (!(optionData instanceof OptionId)) {
134 return;
135 }
136 OptionId option = (OptionId) optionData;
137
138 OptionPanelAPI options = dialog.getOptionPanel();
139 TextPanelAPI text = dialog.getTextPanel();
140 options.clearOptions();
141
142// continue
143// > Offer to apologize for the misunderstanding by buying $himOrHer a drink.
144//
145// exit
146// > Suggest that they read the manual then leave.
147
148 switch (option) {
149 case INIT:
150 text.addPara("\"Ain't nothing, I'm just reading my mail,\" " + getHeOrShe() +
151 " growls back. Then laughs, and taps " + getHisOrHer() + " temple. " +
152 "\"Swear I'll never get proper used to these things.\"");
153 options.addOption("Offer to apologize for the misunderstanding by buying " + getHimOrHer() + " a drink", OptionId.APOLOGIZE);
154 options.addOption("Suggest that " + getHeOrShe() + " read the manual then leave", OptionId.LEAVE);
155 break;
156 case APOLOGIZE:
157 text.addPara("The old space-hand opens up as one drink turns to two or three. " +
158 Misc.ucFirst(getHeOrShe()) + " tells stories of old injuries earned, including that of " +
159 getHisOrHer() + " lost eyes.\n\n\"Was just two survivors from that mission, me and the pilot. " +
160 "Lucky bastards, we two.\" It all began when " + getHeOrShe() + " was hired on to " +
161 "a salvage fleet trawling decivilized systems outside the Core Worlds. " +
162 "The loot was good, and any brigand they couldn't fight, they could flee." +
163 "\n\nThen the officers found something new in a data-cache. " +
164 "Rumours flew among the crew, who were told nothing, as the fleet suddenly left a rich " +
165 "asteroid belt to make for the outer system jump-point. " +
166 "They fared two hyperspace storms before arriving at a distant star system.");
167
168 options.addOption("Continue", OptionId.CONTINUE_1);
169 break;
170 case CONTINUE_1:
171 text.addPara("There they found a planet all shining and red. \"It weren't anything natural. " +
172 "It was all... shapes, angles, glowing like plasma. That's truth,\" " + getHeOrShe() +
173 " says quietly, \"I've seen Gates, sure, and orbital works big as you like. Ain't " +
174 "never seen anything Domain-made glow like that across a whole planet's face. " +
175 "Not anything that weren't a weapon, I mean.\"");
176
177 options.addOption("Continue", OptionId.CONTINUE_2);
178 break;
179 case CONTINUE_2:
180 text.addPara("\"While we were gawkin', the prox alarm goes and it's battle stations\", " + getHeOrShe() +
181 " continues. Hostile ships came fast upon the salvage fleet, flitting with agility " +
182 "belying advanced tech. They had equally advanced weapons, too, and with those they " +
183 "attacked with no mercy. \"It weren't pirates, nor military,\" here the spacer loses " +
184 getHisOrHer() + " cheer at a good story. \"Ludd's hells, I swear to you it weren't anything human.\"");
185
186 text.addPara("The spacer explains that just " + getHeOrShe() + " and the pilot got away in an " +
187 "escape pod which was only \"mostly\" malfunctioning. \"The miracle wasn't that I " +
188 "fixed it, it's that they could thaw enough of me out at the end of it for me to keep " +
189 "livin', if you call this livin'.\"");
190
191 options.addOption("\"Where was this system with the red planet?\"", OptionId.WHERE_WAS_SYSTEM);
192 break;
193 case WHERE_WAS_SYSTEM:
194 text.addPara("You emphasize your interest in the subject by having the spacer's drink refreshed. " +
195 Misc.ucFirst(getHeOrShe()) + " shakes " + getHisOrHer() + " head, \"Captain, " +
196 "I wouldn't wish my fate on you or anyone. Besides, I have no idea.\" A pause, then, " +
197 "\"" + pilot.getNameString() + " would - that's the pilot,\" " + getHeOrShe() + " finally admits.");
198
199 text.addPara("The old spacer tells you that " + pilot.getName().getFirst() + " did not live the experience in such " +
200 "stride as " + getHimOrHerself() + ", and has taken to drinking themselves senseless " +
201 "in semi-retirement " + pilotMarket.getOnOrAt() + " " + pilotMarket.getName() + ". " +
202 "\"Some folks, I don't think they react well " +
203 "to the emergency cryo-pods. Like a bit o' their brain is still froze up and not coming back.\"");
204
205 String icon = Global.getSettings().getSpriteName("intel", "red_planet");
206 Set<String> tags = new LinkedHashSet<String>();
207 tags.add(Tags.INTEL_MISSIONS);
208
209 dialog.getVisualPanel().showMapMarker(pilotMarket.getPrimaryEntity(),
210 "Destination: " + pilotMarket.getName(), pilotMarket.getFaction().getBaseUIColor(),
211 true, icon, null, tags);
212
213 options.addOption("Continue", OptionId.CONTINUE_3);
214 break;
215 case CONTINUE_3:
216 text.addPara("You consider a trip to " + pilotMarket.getName() + " to see if you can get the exact location of " +
217 "this mysterious planet with its unknown technology. You also realize that the old spacer " +
218 "has fallen asleep in " + getHisOrHer() + " seat, cybernetic eyes blanked out in standby mode.");
219
221 addIntel();
222
223 options.addOption("Leave the old spacer to " + getHisOrHer() + " rest", OptionId.LEAVE);
224 break;
225 case LEAVE:
226 noContinue = true;
227 done = true;
228 break;
229 }
230 }
231
232
233 protected void addIntel() {
234 CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo();
235 TextPanelAPI text = dialog.getTextPanel();
236
237 PlanetAPI planet = getTargetPlanet();
238 boolean success = false;
239 if (planet != null) {
240 PlanetaryShieldIntel intel = new PlanetaryShieldIntel(planet, this);
241 if (!intel.isDone()) {
242 Global.getSector().getIntelManager().addIntel(intel, false, text);
243 success = true;
244 }
245 }
246
247 if (!success) {
248 text.addPara("For a minute there, you were caught by the story, but you now see that following up " +
249 "on it would be a fool's errand.");
250 }
251 }
252
253 @Override
254 protected String getPersonFaction() {
255 return Factions.INDEPENDENT;
256 }
257
258 @Override
259 protected String getPersonRank() {
260 return Ranks.SPACE_SAILOR;
261 }
262
263 @Override
264 protected String getPersonPost() {
265 return Ranks.CITIZEN;
266 }
267
268 @Override
269 protected String getPersonPortrait() {
270 return null;
271 }
272
273 @Override
274 protected Gender getPersonGender() {
275 return Gender.ANY;
276 }
277
278 public PersonAPI getPilot() {
279 return pilot;
280 }
281
282 public MarketAPI getPilotMarket() {
283 return pilotMarket;
284 }
285
286}
287
288
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
void addPromptAndOption(InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap)
void init(InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap)
String getSpriteName(String category, String id)