Starsector API
Loading...
Searching...
No Matches
PerseanLeagueHostileActivityFactor.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.CargoAPI;
11import com.fs.starfarer.api.campaign.FactionAPI;
12import com.fs.starfarer.api.campaign.InteractionDialogAPI;
13import com.fs.starfarer.api.campaign.StarSystemAPI;
14import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin.ListInfoMode;
15import com.fs.starfarer.api.campaign.econ.Industry;
16import com.fs.starfarer.api.campaign.econ.MarketAPI;
17import com.fs.starfarer.api.campaign.listeners.ColonyPlayerHostileActListener;
18import com.fs.starfarer.api.impl.campaign.NPCHassler;
19import com.fs.starfarer.api.impl.campaign.ids.Conditions;
20import com.fs.starfarer.api.impl.campaign.ids.Factions;
21import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
22import com.fs.starfarer.api.impl.campaign.ids.Industries;
23import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
24import com.fs.starfarer.api.impl.campaign.ids.Stats;
25import com.fs.starfarer.api.impl.campaign.intel.PerseanLeagueMembership;
26import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel.EventStageData;
27import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.HAERandomEventData;
28import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.Stage;
29import com.fs.starfarer.api.impl.campaign.intel.group.FGBlockadeAction.FGBlockadeParams;
30import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel;
31import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel.FGIEventListener;
32import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI.GenericRaidParams;
33import com.fs.starfarer.api.impl.campaign.intel.group.PerseanLeagueBlockade;
34import com.fs.starfarer.api.impl.campaign.intel.group.PerseanLeaguePunitiveExpedition;
35import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
36import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission.FleetStyle;
37import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator;
38import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.TempData;
39import com.fs.starfarer.api.ui.LabelAPI;
40import com.fs.starfarer.api.ui.TooltipMakerAPI;
41import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
42import com.fs.starfarer.api.util.Misc;
43
45 FGIEventListener, ColonyPlayerHostileActListener {
46
47 //public static final String DEFEATED_BLOCKADE = "$defeatedLeagueBlockade";
48 public static final String HASSLE_REASON = "leagueEnforcer";
49
50 public static float INDEPENDENT_REP_FOR_DEFEATING = 0.5f;
51 public static float HEGEMONY_REP_FOR_DEFEATING = 0.3f;
52
54 super(intel);
55
56 Global.getSector().getListenerManager().addListener(this);
57 }
58
60 return "";
61 }
62
63 @Override
65 if (!checkFactionExists(Factions.PERSEAN, true)) {
66 return 0;
67 }
68 return super.getProgress(intel);
69 }
70
71 public String getDesc(BaseEventIntel intel) {
72 return "Persean League";
73 }
74
75 public String getNameForThreatList(boolean first) {
76 return "Persean League";
77 }
78
79
81 if (getProgress(intel) <= 0) {
82 return Misc.getGrayColor();
83 }
84 return Global.getSector().getFaction(Factions.PERSEAN).getBaseUIColor();
85 }
86
87 public TooltipCreator getMainRowTooltip(BaseEventIntel intel) {
88 return new BaseFactorTooltip() {
89 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
90 float opad = 10f;
91 tooltip.addPara("A large independent polity is a tantalizing prize for the Persean League, and "
92 + "they will go quite far in exerting pressure for you to join them. League "
93 + "\"enforcer\" fleets prowl your systems, ostensibly to protect the League's "
94 + "interests in \"unclaimed territory\".", 0f);
95
96// tooltip.addPara("Going to Kazeron and negotiating to join the League is likely to get "
97// + "this harassment to stop. A saturation bombardment of a League world would make your "
98// + "joining the league politically impossible, but of course has other ramifications. If "
99// + "left unchecked, the conflict will eventually come to a head and is likely to "
100// + "be resolved one way or another.", opad, Misc.getHighlightColor(),
101// "join the League", "saturation bombardment");
102 }
103 };
104 }
105
107 return getProgress(intel) > 0;
108 }
109
110
111 public Color getNameColor(float mag) {
112 if (mag <= 0f) {
113 return Misc.getGrayColor();
114 }
115 return Global.getSector().getFaction(Factions.PERSEAN).getBaseUIColor();
116 }
117
118
119 @Override
120 public int getMaxNumFleets(StarSystemAPI system) {
121 return Global.getSettings().getInt("perseanLeagueMaxFleets");
122 }
123
124
125 @Override
126 public float getSpawnInHyperProbability(StarSystemAPI system) {
127 return 0f;
128 }
129
130 public CampaignFleetAPI createFleet(StarSystemAPI system, Random random) {
131
132 // minimum is 0.66f for this factor due to it requiring some market presence
133 float f = intel.getMarketPresenceFactor(system);
134
135 int difficulty = 0 + (int) Math.max(1f, Math.round(f * 4f));
136 difficulty += random.nextInt(6);
137
138 FleetCreatorMission m = new FleetCreatorMission(random);
139 m.beginFleet();
140
141 Vector2f loc = system.getLocation();
142 String factionId = Factions.PERSEAN;
143
144 m.createStandardFleet(difficulty, factionId, loc);
145 m.triggerSetFleetType(FleetTypes.LEAGUE_ENFORCER);
146 m.triggerSetPatrol();
147 m.triggerSetFleetHasslePlayer(HASSLE_REASON);
148 m.triggerSetFleetFlag("$leagueEnforcer");
149
150 m.triggerFleetAllowLongPursuit();
151 m.triggerMakeLowRepImpact();
152
153 //m.triggerMakeHostile();
154 //m.triggerMakeHostileWhileTransponderOff();
155
156 CampaignFleetAPI fleet = m.createFleet();
157
158 if (fleet != null) {
159 fleet.addScript(new NPCHassler(fleet, system));
160 }
161
162 return fleet;
163 }
164
165
166
167
168 public void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
169 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
170 //info.addPara("Rumors of Persean League blockade", tc, initPad);
171 Color c = Global.getSector().getFaction(Factions.PERSEAN).getBaseUIColor();
172 info.addPara("Impending Persean League blockade", initPad, tc, c, "Persean League");
173 }
174
175 public void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
176 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
177 info.addPara("Persean League blockade averted", tc, initPad);
178 }
179
180 public void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info) {
181 float small = 0f;
182 float opad = 10f;
183
184 small = 8f;
185
186 info.addPara("You've received intel that the Persean League is planning a lengthy blockade of one of your systems. "
187 + "Colonies in that system will suffer a major accessibility penalty for as long as the blockade lasts.",
188 small, Misc.getNegativeHighlightColor(), "major accessibility penalty");
189
190 LabelAPI label = info.addPara("If the blockading force is defeated, your standing with the Hegemony "
191 + "and the independents will increase substantially, and the Persean League will likely abandon "
192 + "further efforts to strong-arm you and be more open to negotiation.",
193 opad);
194 label.setHighlight("Hegemony", "independents", "increase substantially", "Persean League");
195 label.setHighlightColors(Global.getSector().getFaction(Factions.HEGEMONY).getBaseUIColor(),
196 Global.getSector().getFaction(Factions.INDEPENDENT).getBaseUIColor(),
197 Misc.getPositiveHighlightColor(),
198 Global.getSector().getFaction(Factions.PERSEAN).getBaseUIColor());
199
200 Color c = Global.getSector().getFaction(Factions.PERSEAN).getBaseUIColor();
201 stage.beginResetReqList(info, true, "crisis", opad);
202 info.addPara("You go to %s and make an agreement about joining the League", 0f, c, "Kazeron");
203 info.addPara("%s is tactically bombarded", 0f, c, "Kazeron");
204 //info.addPara("Performing a saturation bombardment of a %s world", 0f, c, "Persean League");
205 stage.endResetReqList(info, false, "crisis", -1, -1);
206
207 addBorder(info, Global.getSector().getFaction(Factions.PERSEAN).getBaseUIColor());
208 }
209
210
211 public String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage) {
212 return Global.getSector().getFaction(Factions.PERSEAN).getCrest();
213 }
214
215 public TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage) {
216 if (stage.id == Stage.HA_EVENT) {
217 return getDefaultEventTooltip("Persean League blockade", intel, stage);
218 }
219 return null;
220 }
221
222
223 public float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage) {
224 if (stage.id == Stage.HA_EVENT) {
225 if (wasPLEverSatBombardedByPlayer() || getKazeron(true) == null) {
226 return 0f;
227 }
228
229 if (PerseanLeagueBlockade.get() != null) {
230 return 0f;
231 }
232 if (PerseanLeaguePunitiveExpedition.get() != null) {
233 return 0f;
234 }
235
236 StarSystemAPI target = findBlockadeTarget(intel, stage);
237 MarketAPI source = getBlockadeSource(intel, stage, target);
238 if (target != null && source != null) {
239 return 10f;
240 }
241 }
242 return 0;
243 }
244
245
246 public void rollEvent(HostileActivityEventIntel intel, EventStageData stage) {
247 HAERandomEventData data = new HAERandomEventData(this, stage);
248 stage.rollData = data;
250 }
251
252 public boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage) {
253 StarSystemAPI target = findBlockadeTarget(intel, stage);
254 MarketAPI source = getBlockadeSource(intel, stage, target);
255 if (source == null || target == null) {
256 return false;
257 }
258
259 stage.rollData = null;
260 return startBlockade(source, target, stage, getRandomizedStageRandom(3));
261 }
262
263
264 public static StarSystemAPI findBlockadeTarget(HostileActivityEventIntel intel, EventStageData stage) {
265 float max = 0f;
266 StarSystemAPI best = null;
267 for (StarSystemAPI system : Misc.getPlayerSystems(false)) {
268 float w = intel.getMarketPresenceFactor(system);
269 if (w > max) {
270 max = w;
271 best = system;
272 }
273 }
274 return best;
275 }
276
277 public MarketAPI getBlockadeSource(HostileActivityEventIntel intel, EventStageData stage, final StarSystemAPI target) {
278 return getKazeron(true);
279 }
280
281 public static MarketAPI getKazeron(boolean requireMilitaryBase) {
282 MarketAPI kazeron = Global.getSector().getEconomy().getMarket("kazeron");
283 if (kazeron == null || kazeron.hasCondition(Conditions.DECIVILIZED)) {
284 return null;
285 }
286 if (requireMilitaryBase) {
287 Industry b = kazeron.getIndustry(Industries.MILITARYBASE);
288 if (b == null) b = kazeron.getIndustry(Industries.HIGHCOMMAND);
289 if (b == null || b.isDisrupted() || !b.isFunctional()) {
290 return null;
291 }
292 }
293 return kazeron;
294 }
295
296 public static boolean wasPLEverSatBombardedByPlayer() {
297 FactionAPI faction = Global.getSector().getFaction(Factions.PERSEAN);
298 if (faction != null) {
299 return faction.getMemoryWithoutUpdate().getInt(MemFlags.FACTION_SATURATION_BOMBARED_BY_PLAYER) > 0;
300 }
301 return false;
302 }
303
304
305 public boolean startBlockade(MarketAPI source, StarSystemAPI target, EventStageData stage, Random random) {
306 GenericRaidParams params = new GenericRaidParams(new Random(random.nextLong()), true);
307 params.factionId = source.getFactionId();
308 params.source = source;
309
310 params.prepDays = 7f + random.nextFloat() * 14f;
311 params.payloadDays = 365f;
312
313 params.makeFleetsHostile = false;
314
315 FGBlockadeParams bParams = new FGBlockadeParams();
316 bParams.where = target;
317 bParams.targetFaction = Factions.PLAYER;
318
319
320 params.style = FleetStyle.STANDARD;
321
322
323 // standard Kazeron fleet size multiplier with no shortages/issues is a bit over 200%
324 float fleetSizeMult = source.getStats().getDynamic().getMod(Stats.COMBAT_FLEET_SIZE_MULT).computeEffective(0f);
325
326 float f = intel.getMarketPresenceFactor(target);
327
328 float totalDifficulty = fleetSizeMult * 50f * (0.5f + 0.5f * f);
329 if (totalDifficulty < 30) {
330 return false;
331 }
332 if (totalDifficulty > 100) {
333 totalDifficulty = 100;
334 }
335
336
337 totalDifficulty -= 10;
338 totalDifficulty -= 5;
339 totalDifficulty -= 4;
340 totalDifficulty -= 1;
341 totalDifficulty -= 1;
342 params.fleetSizes.add(10); // first size 10 pick becomes the Grand Armada
343 params.fleetSizes.add(5);
344 params.fleetSizes.add(4);
345 params.fleetSizes.add(1); // supply fleets #1
346 params.fleetSizes.add(1); // supply fleets #2
347
348 Random r = getRandomizedStageRandom(7);
349
350 // mostly maxed-out fleets, some smaller ones
351 while (totalDifficulty > 0) {
352 float max = 5f;
353 float min = 3f;
354
355 if (r.nextFloat() > 0.3f) {
356 min = (int) Math.min(totalDifficulty, 10f);
357 max = (int) Math.min(totalDifficulty, 10f);
358 }
359
360 int diff = Math.round(StarSystemGenerator.getNormalRandom(r, min, max));
361
362
363 params.fleetSizes.add(diff);
364 totalDifficulty -= diff;
365 }
366
367 PerseanLeagueBlockade blockade = new PerseanLeagueBlockade(params, bParams);
368 blockade.setListener(this);
369 Global.getSector().getIntelManager().addIntel(blockade);
370
371 return true;
372 }
373
374 public void reportFGIAborted(FleetGroupIntel intel) {
376
377 Misc.adjustRep(Factions.HEGEMONY, HEGEMONY_REP_FOR_DEFEATING, null);
378 Misc.adjustRep(Factions.INDEPENDENT, INDEPENDENT_REP_FOR_DEFEATING, null);
379 }
380
381
382
383 @Override
384 public void notifyFactorRemoved() {
385 Global.getSector().getListenerManager().removeListener(this);
386 }
387
388 public void notifyEventEnding() {
390 }
391
392
393 public void reportRaidForValuablesFinishedBeforeCargoShown(InteractionDialogAPI dialog, MarketAPI market,
394 TempData actionData, CargoAPI cargo) {
395
396 }
397
398 public void reportRaidToDisruptFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData, Industry industry) {
399
400 }
401
402 public void reportTacticalBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData) {
403 MarketAPI kazeron = getKazeron(false);
404 if (market != null && market == kazeron) {
405 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
406 if (stage != null) {
407 boolean thisEvent = stage.rollData instanceof HAERandomEventData &&
408 ((HAERandomEventData)stage.rollData).factor == this;
409 // no points if blockade is the event since it'll lead to a reset anyway
410 if (!thisEvent) {
411 int points = Global.getSettings().getInt("HA_tacBombardKazeron");
412 if (points > 0) {
414 }
415 }
416 }
417// intel.resetHA_EVENTIfFromFactor(this);
418// EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
419// if (stage != null && stage.rollData instanceof HAERandomEventData &&
420// ((HAERandomEventData)stage.rollData).factor == this) {
421// intel.resetHA_EVENT();
422// }
423 }
424 }
425
426 public void reportSaturationBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData) {
427
428 }
429
430 @Override
431 public void advance(float amount) {
432 super.advance(amount);
433
434// if (!Global.getSector().getListenerManager().hasListener(this)) {
435// Global.getSector().getListenerManager().addListener(this);
436// }
437
438 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
439 if (stage != null && stage.rollData instanceof HAERandomEventData &&
440 ((HAERandomEventData)stage.rollData).factor == this) {
441 MarketAPI kazeron = getKazeron(true);
442
443 if (kazeron == null || wasPLEverSatBombardedByPlayer()) {
445 }
446 }
447 }
448
449
450}
451
452
453
454
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)
void reportSaturationBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData)
void reportTacticalBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData)
MarketAPI getBlockadeSource(HostileActivityEventIntel intel, EventStageData stage, final StarSystemAPI target)
void reportRaidForValuablesFinishedBeforeCargoShown(InteractionDialogAPI dialog, MarketAPI market, TempData actionData, CargoAPI cargo)
void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info)
TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage)
static StarSystemAPI findBlockadeTarget(HostileActivityEventIntel intel, EventStageData stage)
void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
void reportRaidToDisruptFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData, Industry industry)
boolean startBlockade(MarketAPI source, StarSystemAPI target, EventStageData stage, Random random)
void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)