Starsector API
Loading...
Searching...
No Matches
HegemonyHostileActivityFactor.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.events;
2
3import java.awt.Color;
4import java.util.Random;
5
6import org.lwjgl.util.vector.Vector2f;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.StarSystemAPI;
11import com.fs.starfarer.api.campaign.comm.CommMessageAPI.MessageClickAction;
12import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin.ListInfoMode;
13import com.fs.starfarer.api.campaign.econ.Industry;
14import com.fs.starfarer.api.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.impl.campaign.NPCHassler;
16import com.fs.starfarer.api.impl.campaign.ids.Factions;
17import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
18import com.fs.starfarer.api.impl.campaign.ids.Industries;
19import com.fs.starfarer.api.impl.campaign.ids.Sounds;
20import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
21import com.fs.starfarer.api.impl.campaign.intel.MessageIntel;
22import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel.EventStageData;
23import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.HAERandomEventData;
24import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.Stage;
25import com.fs.starfarer.api.impl.campaign.intel.inspection.HegemonyInspectionIntel;
26import com.fs.starfarer.api.impl.campaign.intel.inspection.HegemonyInspectionIntel.HegemonyInspectionOutcome;
27import com.fs.starfarer.api.impl.campaign.intel.inspection.HegemonyInspectionIntel.InspectionEndedListener;
28import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
29import com.fs.starfarer.api.ui.LabelAPI;
30import com.fs.starfarer.api.ui.TooltipMakerAPI;
31import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
32import com.fs.starfarer.api.util.DelayedActionScript;
33import com.fs.starfarer.api.util.Misc;
34import com.fs.starfarer.api.util.WeightedRandomPicker;
35
36public class HegemonyHostileActivityFactor extends BaseHostileActivityFactor implements InspectionEndedListener {
37
38 public static final String HASSLE_REASON = "hegemonyInvestigator";
39
40 public static String DEFEATED_HEGEMONY = "$defeatedHegemony";
41
42 public static String INSPECTION_ATTEMPTS = "$hegemonyInspectionAttempts";
43 public static String INSPECTIONS_DEFEATED = "$hegemonyInspectionsDefeated";
44
45 public static int INSPECTIONS_TO_DEFEAT = 3;
46
47 public static float INSPECTION_STRENGTH_FIRST = 150;
48 public static float INSPECTION_STRENGTH_SECOND = 600;
49 public static float INSPECTION_STRENGTH_FINAL = 1400;
50
51 public static boolean isPlayerDefeatedHegemony() {
52 return Global.getSector().getPlayerMemoryWithoutUpdate().getBoolean(DEFEATED_HEGEMONY);
53 }
54 public static void setPlayerDefeatedHegemony() {
55 Global.getSector().getPlayerMemoryWithoutUpdate().set(DEFEATED_HEGEMONY, true);
56 }
57
58 public static int getInspectionAttempts() {
59 return Global.getSector().getPlayerMemoryWithoutUpdate().getInt(INSPECTION_ATTEMPTS);
60 }
61 public static void incrInspectionAttempts() {
62 Global.getSector().getPlayerMemoryWithoutUpdate().set(INSPECTION_ATTEMPTS, getInspectionAttempts() + 1);
63 }
64
65 public static int getInspectionsDefeated() {
66 return Global.getSector().getPlayerMemoryWithoutUpdate().getInt(INSPECTIONS_DEFEATED);
67 }
68 public static void incrInspectionsDefeated() {
69 Global.getSector().getPlayerMemoryWithoutUpdate().set(INSPECTIONS_DEFEATED, getInspectionsDefeated() + 1);
70 }
71
72
74 super(intel);
75
76 //Global.getSector().getListenerManager().addListener(this);
77 }
78
80 return "";
81 }
82
83 @Override
85 if (!checkFactionExists(Factions.HEGEMONY, true)) {
86 return 0;
87 }
88 return super.getProgress(intel);
89 }
90
91 public String getDesc(BaseEventIntel intel) {
92 return "Hegemony";
93 }
94
95 public String getNameForThreatList(boolean first) {
96 return "Hegemony";
97 }
98
99
101 if (getProgress(intel) <= 0) {
102 return Misc.getGrayColor();
103 }
104 return Global.getSector().getFaction(Factions.HEGEMONY).getBaseUIColor();
105 }
106
107 public TooltipCreator getMainRowTooltip(BaseEventIntel intel) {
108 return new BaseFactorTooltip() {
109 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
110 float opad = 10f;
111
112 tooltip.addPara("The Hegemony considers the use of AI cores illegal and will not tolerate it "
113 + "even outside the volume of the core worlds.", 0f);
114 tooltip.addPara("Fleets investigating your AI core use can sometimes be found in your space, not overtly "
115 + "hostile, but harassing your shipping and generally acting in a high-handed way.", opad);
116 }
117 };
118 }
119
121 boolean shouldShowDueToCause = false;
122 for (HostileActivityCause2 cause : getCauses()) {
123 shouldShowDueToCause |= cause.shouldShow();
124 }
125 return getProgress(intel) > 0 || shouldShowDueToCause;
126 }
127
128
129
130 @Override
131 public int getMaxNumFleets(StarSystemAPI system) {
132 return Global.getSettings().getInt("hegemonyMaxFleets");
133 }
134
135 public CampaignFleetAPI createFleet(StarSystemAPI system, Random random) {
136
137 float f = 0f;
138 //f += getEffectMagnitude(system);
139 f += intel.getMarketPresenceFactor(system);
140
141 if (f > 1f) f = 1f;
142
143// float fInvestigators = Global.getSettings().getFloat("hegemonyInvestigatorsFreq");
144// float fRecon = Global.getSettings().getFloat("hegemonyReconFreq");
145//
146// WeightedRandomPicker<Integer> picker = new WeightedRandomPicker<Integer>(random);
147// picker.add(1, fInvestigators);
148// picker.add(2, fRecon);
149//
150// int pick = picker.pick();
151// boolean recon = pick == 2;
152 boolean recon = false;
153
154 int difficulty = 0;
155
156 if (recon) {
157 difficulty = 1 + random.nextInt(2);
158 } else {
159 difficulty = 3;
160 difficulty += (int) Math.round(f * 5f);
161 difficulty += random.nextInt(4);
162 }
163
164
165 FleetCreatorMission m = new FleetCreatorMission(random);
166 m.beginFleet();
167
168 Vector2f loc = system.getLocation();
169 String factionId = Factions.HEGEMONY;
170
171 if (recon) {
172 m.createStandardFleet(difficulty, factionId, loc);
173 } else {
174 m.createStandardFleet(difficulty, factionId, loc);
175 }
176
177 m.triggerSetFleetType(FleetTypes.INVESTIGATORS);
178 m.triggerSetPatrol();
179
180 if (!recon) {
181 m.triggerSetFleetHasslePlayer(HASSLE_REASON);
182 m.triggerSetFleetFlag("$hegemonyInvestigator");
183 m.triggerFleetAllowLongPursuit();
184 }
185
186 m.triggerMakeLowRepImpact();
187
188 CampaignFleetAPI fleet = m.createFleet();
189
190 if (fleet != null && !recon) {
191 fleet.addScript(new NPCHassler(fleet, system));
192 }
193
194 return fleet;
195 }
196
197
198 @Override
199 public void notifyFactorRemoved() {
200 //Global.getSector().getListenerManager().removeListener(this);
201 }
202
203 public void notifyEventEnding() {
205 }
206
207
208 public void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
209 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
210
211 if (!(stage.rollData instanceof HAERandomEventData)) return;
212 HAERandomEventData data = (HAERandomEventData) stage.rollData;
213 MarketAPI target = (MarketAPI) data.custom;
214
215 //MarketAPI target = pickTargetMarket();
216 if (target == null) return;
217
218 MarketAPI from = pickSourceMarket();
219 if (from == null) return;
220
221 Color c = Global.getSector().getFaction(Factions.HEGEMONY).getBaseUIColor();
222
223 LabelAPI label = info.addPara("Upcoming Hegemony AI inspection targeting %s",
224 initPad, tc, tc, target.getName());
225 label.setHighlight("Hegemony", target.getName());
226 label.setHighlightColors(c, Misc.getBasePlayerColor());
227 }
228
229 public void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
230 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
231 info.addPara("Hegemony AI inspection averted", tc, initPad);
232 }
233
234 public void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info) {
235 if (!(stage.rollData instanceof HAERandomEventData)) return;
236 HAERandomEventData data = (HAERandomEventData) stage.rollData;
237 MarketAPI target = (MarketAPI) data.custom;
238
239 //MarketAPI target = pickTargetMarket();
240 if (target == null) return;
241
242 MarketAPI from = pickSourceMarket();
243 if (from == null) return;
244
245 Color c = Global.getSector().getFaction(Factions.HEGEMONY).getBaseUIColor();
246
247 float small = 0f;
248 float opad = 10f;
249
250 small = 8f;
251
252 LabelAPI label = info.addPara("You've received intel that the Hegemony is planning "
253 + "an AI insprection targeting %s. If the inspection arrives at your colony, "
254 + "your options would include open hostilities with the Hegemony, or the loss of "
255 + "at least some of your AI cores.",
256 small, c, target.getName());
257 label.setHighlight(target.getName(), "open hostilities", "loss of at least some of your AI cores");
258 label.setHighlightColors(Misc.getBasePlayerColor(), Misc.getNegativeHighlightColor(), Misc.getNegativeHighlightColor());
259
260 int defeated = getInspectionsDefeated();
261 if (defeated < INSPECTIONS_TO_DEFEAT) {
262 label = info.addPara("If this inspection is defeated by military means, the Hegemony is likely to "
263 + "escalate the conflict, although only up to a point.",
264 opad, Misc.getNegativeHighlightColor(), "escalate the conflict");
265 label.setHighlight("escalate the conflict", "up to a point");
266 label.setHighlightColors(Misc.getNegativeHighlightColor(), Misc.getPositiveHighlightColor());
267 } else {
268 info.addPara("If this massive inspection force - a declaration of war in all but name - is defeated,"
269 + " the Hegemony is likely to reconsider the viability of their approach.",
270 opad, Misc.getPositiveHighlightColor(), "reconsider");
271 }
272
273
274 stage.beginResetReqList(info, true, "crisis", opad);
275 info.addPara("The %s has no functional military bases", 0f, c, "Hegemony");
276 stage.endResetReqList(info, false, "crisis", -1, -1);
277
278 addBorder(info, Global.getSector().getFaction(Factions.HEGEMONY).getBaseUIColor());
279 }
280
281
282 public String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage) {
283 return Global.getSector().getFaction(Factions.HEGEMONY).getCrest();
284 }
285
286 public TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage) {
287 if (stage.id == Stage.HA_EVENT) {
288 return getDefaultEventTooltip("Hegemony AI inspection", intel, stage);
289 }
290 return null;
291 }
292
293
294 public float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage) {
295 if (stage.id == Stage.HA_EVENT) {
296 if (pickTargetMarket() != null && pickSourceMarket() != null) {
297 return 10f;
298 }
299 }
300 return 0;
301 }
302
303 public MarketAPI pickTargetMarket() {
304 WeightedRandomPicker<MarketAPI> picker = new WeightedRandomPicker<MarketAPI>(getRandomizedStageRandom());
305
306 float alpha = Global.getSettings().getFloat("hegemonyPointsAlpha");
307 float beta = Global.getSettings().getFloat("hegemonyPointsBeta");
308 float gamma = Global.getSettings().getFloat("hegemonyPointsGamma");
309
310 float threshold = alpha + beta + gamma;
311 for (MarketAPI market : Misc.getPlayerMarkets(false)) {
312 // to put a damper on shenanigans with establishing and abandoning a colony
313 // with an Alpha Core admin to bait an attack
314 if (market.getDaysInExistence() < 180f && !Global.getSettings().isDevMode()) continue;
315
317 if (w <= threshold) continue;
318 picker.add(market, w * w);
319 }
320 return picker.pick();
321 }
322
323 public MarketAPI pickSourceMarket() {
324 WeightedRandomPicker<MarketAPI> picker = new WeightedRandomPicker<MarketAPI>(getRandomizedStageRandom(7));
325 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
326 if (market.getFactionId().equals(Factions.HEGEMONY)) {
327 Industry b = market.getIndustry(Industries.MILITARYBASE);
328 if (b == null) b = market.getIndustry(Industries.HIGHCOMMAND);
329 if (b == null || b.isDisrupted() || !b.isFunctional()) {
330 continue;
331 }
332 picker.add(market, market.getSize());
333 }
334 }
335 MarketAPI from = picker.pick();
336 return from;
337 }
338
339
340 public void rollEvent(HostileActivityEventIntel intel, EventStageData stage) {
341// if (true) return;
342
343 if (isPlayerDefeatedHegemony()) return;
344
345 MarketAPI market = pickTargetMarket();
346 if (market == null) return;
347
348 MarketAPI from = pickSourceMarket();
349 if (from == null) return;
350
351 HAERandomEventData data = new HAERandomEventData(this, stage);
352 data.custom = market;
353 stage.rollData = data;
355 }
356
357 public boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage) {
358 //if (true) return false;
359
360 if (isPlayerDefeatedHegemony()) return false;
361
362 //MarketAPI market = pickTargetMarket();
363 if (!(stage.rollData instanceof HAERandomEventData)) return false;
364 HAERandomEventData data = (HAERandomEventData) stage.rollData;
365 MarketAPI market = (MarketAPI) data.custom;
366
367 if (market == null) return false;
368 if (!market.isInEconomy()) return false;
369
370 MarketAPI from = pickSourceMarket();
371 if (from == null) return false;
372
373 StarSystemAPI system = market.getStarSystem();
374 if (system == null) return false;
375
376 return createInspection(market, null);
377 }
378
379
380 public boolean createInspection(MarketAPI target, Integer fpOverride) {
381
382// MarketAPI target = pickTargetMarket();
383// if (target == null) return false;
384
385 MarketAPI from = pickSourceMarket();
386 if (from == null) return false;
387
388
389 float fp;
390 int defeated = getInspectionsDefeated();
391 //defeated = 2;
392
393 if (defeated <= 0) {
395 } else if (defeated == 1) {
397 } else {
399 }
400
401 //fp = 500;
402 if (fpOverride != null) {
403 fp = fpOverride;
404 }
405 HegemonyInspectionIntel inspection = new HegemonyInspectionIntel(from, target, fp);
406 if (inspection.isDone()) {
407 inspection = null;
408 return false;
409 }
410
411 inspection.setListener(this);
412
414
415 return true;
416 }
417
418
419 @Override
420 public void advance(float amount) {
421 super.advance(amount);
422
423 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
424 if (stage != null && stage.rollData instanceof HAERandomEventData &&
425 ((HAERandomEventData)stage.rollData).factor == this) {
426 if (pickSourceMarket() == null) {
428 }
429 }
430 }
431
432 public static void avertInspectionIfNotInProgress() {
434 if (intel == null) return;
435
436 HAERandomEventData data = intel.getRollDataForEvent();
437 if (data != null && data.factor instanceof HegemonyHostileActivityFactor) {
439 }
440 }
441
442
443 public void notifyInspectionEnded(HegemonyInspectionOutcome outcome) {
444 // also called when aborted from military base being destroyed, with same outcome enum
445 if (outcome == HegemonyInspectionOutcome.TASK_FORCE_DESTROYED) {
447 int defeated = getInspectionsDefeated();
448 if (defeated >= INSPECTIONS_TO_DEFEAT) {
450
451 Global.getSector().addScript(new DelayedActionScript(0.1f) {
452 @Override
453 public void doAction() {
454 MessageIntel msg = new MessageIntel();
455 msg.addLine("Major Hegemony defeat!", Misc.getBasePlayerColor());
457 "You may be able to discuss the situation with the High Hegemon on Chicomoztoc");
458 msg.setIcon(Global.getSector().getFaction(Factions.HEGEMONY).getCrest());
459 msg.setSound(Sounds.REP_GAIN);
460 Global.getSector().getCampaignUI().addMessage(msg, MessageClickAction.NOTHING);
461 }
462 });
463 }
464 }
465 }
466
467}
468
469
470
471
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
static boolean checkFactionExists(String factionId, boolean requireMilitary)
TooltipCreator getDefaultEventTooltip(final String title, final HostileActivityEventIntel intel, final EventStageData stage)
TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage)
void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage)
void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info)
String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage)