Starsector API
Loading...
Searching...
No Matches
KnightsOfLuddTakeoverExpedition.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.group;
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.FactionAPI;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.campaign.StarSystemAPI;
13import com.fs.starfarer.api.campaign.econ.MarketAPI;
14import com.fs.starfarer.api.campaign.listeners.EconomyTickListener;
15import com.fs.starfarer.api.campaign.rules.MemoryAPI;
16import com.fs.starfarer.api.combat.MutableStatWithTempMods;
17import com.fs.starfarer.api.impl.campaign.HasslePlayerScript;
18import com.fs.starfarer.api.impl.campaign.NPCHassler;
19import com.fs.starfarer.api.impl.campaign.econ.RecentUnrest;
20import com.fs.starfarer.api.impl.campaign.ids.Conditions;
21import com.fs.starfarer.api.impl.campaign.ids.Factions;
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.Ranks;
25import com.fs.starfarer.api.impl.campaign.ids.Skills;
26import com.fs.starfarer.api.impl.campaign.ids.Sounds;
27import com.fs.starfarer.api.impl.campaign.ids.Submarkets;
28import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel;
29import com.fs.starfarer.api.impl.campaign.intel.events.LuddicChurchHostileActivityFactor;
30import com.fs.starfarer.api.impl.campaign.intel.group.FGBlockadeAction.FGBlockadeParams;
31import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
32import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithTriggers.FleetQuality;
33import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithTriggers.FleetSize;
34import com.fs.starfarer.api.ui.Alignment;
35import com.fs.starfarer.api.ui.LabelAPI;
36import com.fs.starfarer.api.ui.TooltipMakerAPI;
37import com.fs.starfarer.api.util.Misc;
38
39
40
41public class KnightsOfLuddTakeoverExpedition extends BlockadeFGI implements EconomyTickListener {
42
43 public static int STABILITY_PER_MONTH_FULL = 2;
44 public static int STABILITY_PER_MONTH_PARTIAL = 1;
45
46 public static float NUM_OTHER_FLEETS_MULT = 0.25f;
47
48 public static final String STABILITY_UPDATE = "stability_update";
49 public static final String TAKEOVER_UPDATE = "takeover_update";
50
51 public static final String BLOCKADING = "$KOLT_isBlockading";
52
53 public static final String KOLT_FLEET = "$KOLT_fleet";
54 public static final String ARMADA = "$KOLT_armada";
55 public static final String PICKET = "$KOLT_picket";
56
57
58 public static String KEY = "$KOLT_ref";
59 public static KnightsOfLuddTakeoverExpedition get() {
60 return (KnightsOfLuddTakeoverExpedition) Global.getSector().getMemoryWithoutUpdate().get(KEY);
61 }
62
63
64 public KnightsOfLuddTakeoverExpedition(GenericRaidParams params, FGBlockadeParams blockadeParams) {
65 super(params, blockadeParams);
66
67 Global.getSector().getMemoryWithoutUpdate().set(KEY, this);
68 Global.getSector().getListenerManager().addListener(this);
69 }
70
71 @Override
72 protected void notifyEnding() {
73 super.notifyEnding();
74
75 Global.getSector().getMemoryWithoutUpdate().unset(KEY);
76 Global.getSector().getListenerManager().removeListener(this);
77 }
78
79 @Override
80 protected void notifyEnded() {
81 super.notifyEnded();
82 }
83
84 @Override
85 protected CampaignFleetAPI createFleet(int size, float damage) {
86
87 Random r = getRandom();
88
89 Vector2f loc = origin.getLocationInHyperspace();
90
91 FleetCreatorMission m = new FleetCreatorMission(r);
92
93 m.beginFleet();
94
95 m.createFleet(params.style, size, params.factionId, loc);
96
97 if (size == 10) {
98 m.triggerSetFleetDoctrineOther(5, 0);
99 m.triggerSetFleetSize(FleetSize.MAXIMUM);
100 m.triggerSetFleetSizeFraction(1.4f);
101
102 m.triggerSetFleetQuality(FleetQuality.HIGHER);
103 }
104
105
106 m.triggerSetFleetFlag(KOLT_FLEET);
107
108 m.setFleetSource(params.source);
109 m.setFleetDamageTaken(damage);
110
111 m.triggerSetWarFleet();
112 m.triggerMakeLowRepImpact();
113
114 //m.triggerMakeHostile();
115 m.triggerMakeAlwaysSpreadTOffHostility();
116
117 if (size >= 8) {
118 m.triggerFleetAddCommanderSkill(Skills.COORDINATED_MANEUVERS, 1);
119 m.triggerFleetAddCommanderSkill(Skills.TACTICAL_DRILLS, 1);
120 m.triggerFleetAddCommanderSkill(Skills.CARRIER_GROUP, 1);
121 } else {
122 // only set during the action phase, not here
123 //m.triggerSetFleetHasslePlayer(LuddicChurchHostileActivityFactor.HASSLE_REASON);
124 }
125
126 CampaignFleetAPI fleet = m.createFleet();
127
128 if (fleet != null) {
129 if (size >= 8) {
130 setNeverStraggler(fleet);
131 } else {
132 fleet.addScript(new NPCHassler(fleet, getTargetSystem()));
133 fleet.getMemoryWithoutUpdate().set(PICKET, true);
134
135 fleet.setName("Knights of Ludd Watchers");
136 fleet.setNoFactionInName(true);
137 }
138
139 if (size == 10) {
140 fleet.setName("Knights of Ludd Holy Armada");
141 fleet.setNoFactionInName(true);
142 fleet.getMemoryWithoutUpdate().set(ARMADA, true);
143 fleet.getCommander().setRankId(Ranks.SPACE_ADMIRAL);
144 }
145 }
146
147
148 return fleet;
149 }
150
151
152 @Override
153 public void advance(float amount) {
154 super.advance(amount);
155
156 if (isSpawnedFleets()) {
157 if (isEnded() || isEnding() || isAborted() || isCurrent(RETURN_ACTION)) {
158 for (CampaignFleetAPI curr : getFleets()) {
159 curr.getMemoryWithoutUpdate().set(BLOCKADING, false);
160 }
161 return;
162 }
163
165 for (CampaignFleetAPI curr : getFleets()) {
166 curr.getMemoryWithoutUpdate().set(BLOCKADING, true);
167 }
168 }
169 }
170 }
171
172 @Override
173 protected void periodicUpdate() {
174 super.periodicUpdate();
175
176 if ((isEnded() || isEnding() || isSucceeded() || isFailed() || isAborted())) {
177 return;
178 }
179
180 if (HostileActivityEventIntel.get() == null) { // possible if the player has no colonies
181 abort();
182 return;
183 }
184
185 MarketAPI target = blockadeParams.specificMarket;
186 if (target != null && !target.hasCondition(Conditions.LUDDIC_MAJORITY)) {
187 //setFailedButNotDefeated(true);
188 finish(false);
189 return;
190 }
191
192 FGAction action = getCurrentAction();
193 if (action instanceof FGBlockadeAction) {
194 MutableStatWithTempMods stat = HostileActivityEventIntel.get().getNumFleetsStat(getTargetSystem());
195 stat.addTemporaryModMult(1f, "KOLBlockade", null, NUM_OTHER_FLEETS_MULT);
196 }
197
198 if (!isSpawnedFleets() || isSpawning()) return;
199
200 int armada = 0;
201 for (CampaignFleetAPI curr : getFleets()) {
202 if (curr.getMemoryWithoutUpdate().getBoolean(ARMADA)) {
203 armada++;
204 }
205 }
206
207 if (armada <= 0) {
208 abort();
209 }
210
211 if (action instanceof FGBlockadePlanetAction) {
213 if (blockade.getPrimary() != null) {
214 for (CampaignFleetAPI curr : getFleets()) {
215 if (blockade.getPrimary().getContainingLocation() != curr.getContainingLocation()) {
216 continue;
217 }
218 if (!curr.getMemoryWithoutUpdate().getBoolean(PICKET)) {
219 curr.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_FLEET_DO_NOT_GET_SIDETRACKED, true, 0.4f);
220 }
221 }
222 }
223 }
224 }
225
226
227
228
229 protected String getOfString() {
230 return "targeting";
231 }
232
233 protected GenericPayloadAction createPayloadAction() {
236 return action;
237 }
238
239 protected void applyBlockadeCondition() {
240// int str = getRelativeFGStrength(getTargetSystem());
241// if (str < 0) {
242// unapplyBlockadeCondition();
243// return;
244// }
245//
246// for (MarketAPI market : Misc.getMarketsInLocation(getTargetSystem(), blockadeParams.targetFaction)) {
247// if (!market.hasCondition(Conditions.BLOCKADED)) {
248// market.addCondition(Conditions.BLOCKADED, this);
249// }
250// }
251 }
252
253 protected void unapplyBlockadeCondition() {
254// for (MarketAPI market : Misc.getMarketsInLocation(getTargetSystem(), blockadeParams.targetFaction)) {
255// market.removeCondition(Conditions.BLOCKADED);
256// }
257 }
258
259
260
261 @Override
262 protected void addUpdateBulletPoints(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode,
263 float initPad) {
264
265 Object p = getListInfoParam();
266 if (STABILITY_UPDATE.equals(p)) {
267 int penalty = getStabilityPenaltyPerMonth();
268 MarketAPI target = blockadeParams.specificMarket;
269 LabelAPI label = info.addPara(target.getName() + " stability reduced by %s", initPad, tc,
270 Misc.getHighlightColor(), "" + penalty);
271 label.setHighlightColors(target.getFaction().getBaseUIColor(), Misc.getHighlightColor());
272 label.setHighlight(target.getName(), "" + penalty);
273 } else if (TAKEOVER_UPDATE.equals(p)) {
274
275 } else {
276 super.addUpdateBulletPoints(info, tc, param, mode, initPad);
277 }
278 }
279
280
281 protected void addTargetingBulletPoint(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad) {
282 MarketAPI target = blockadeParams.specificMarket;
283// StarSystemAPI system = raidAction.getWhere();
284// Color s = raidAction.getSystemNameHighlightColor();
285 LabelAPI label = info.addPara("Targeting " + target.getName(), tc, initPad);
286 label.setHighlightColors(target.getFaction().getBaseUIColor());
287 label.setHighlight(target.getName());
288 }
289
290 @Override
291 protected void addBasicDescription(TooltipMakerAPI info, float width, float height, float opad) {
292 info.addImage(getFaction().getLogo(), width, 128, opad);
293
294 MarketAPI target = blockadeParams.specificMarket;
295
296 StarSystemAPI system = raidAction.getWhere();
297
298 String noun = getNoun();
299
300 LabelAPI label = info.addPara(
301 Misc.ucFirst(faction.getPersonNamePrefixAOrAn()) + " %s " + noun + " " + getOfString() + " "
302 + target.getName() + " in the " + system.getNameWithLowercaseType() + ".", opad,
303 faction.getBaseUIColor(), faction.getPersonNamePrefix());
304 label.setHighlightColors(faction.getBaseUIColor(), target.getFaction().getBaseUIColor());
305 label.setHighlight(faction.getPersonNamePrefix(), target.getName());
306 }
307
308 protected void addAssessmentSection(TooltipMakerAPI info, float width, float height, float opad) {
309 Color h = Misc.getHighlightColor();
310 Color bad = Misc.getNegativeHighlightColor();
311
312 FactionAPI faction = getFaction();
313 MarketAPI target = blockadeParams.specificMarket;
314
315 String noun = getNoun();
316 String forcesNoun = getForcesNoun();
317 if (!isEnding() && !isSucceeded() && !isFailed()) {
318
319 FactionAPI other = Global.getSector().getFaction(blockadeParams.targetFaction);
320 boolean hostile = getFaction().isHostileTo(blockadeParams.targetFaction);
321
322 info.addSectionHeading("Assessment",
323 faction.getBaseUIColor(), faction.getDarkUIColor(), Alignment.MID, opad);
324
325 boolean started = isCurrent(PAYLOAD_ACTION);
326 float remaining = getETAUntil(PAYLOAD_ACTION, true) - getETAUntil(TRAVEL_ACTION, true);
327 if (remaining > 0 && remaining < 1) remaining = 1;
328 String days = (int)remaining == 1 ? "day" : "days";
329
330 if (started) days = "more " + days;
331
332 LabelAPI label = info.addPara("The operation will last for approximately %s " + days
333 + ", causing a progressive loss of stability " + target.getOnOrAt() +
334 " %s. If stability reaches zero, %s will permanently fall under %s control." ,
335 opad, h,
336 "" + (int) remaining,
337 target.getName(), target.getName(),
338 faction.getDisplayName());
339 label.setHighlight("" + (int) remaining,
340 target.getName(), target.getName(),
341 "will permanently fall",
342 faction.getDisplayName());
343 label.setHighlightColors(h, other.getBaseUIColor(), Misc.getTextColor(),
344 Misc.getNegativeHighlightColor(), faction.getBaseUIColor());
345 //hostile = true;
346 if (!hostile) {
347 info.addPara("The " + forcesNoun + " are not nominally hostile, but will harass shipping and "
348 + "attempt to maintain control of the volume around the colony and undermine your "
349 + "authority.", opad,
350 Misc.getHighlightColor(), "not nominally hostile");
351 } else {
352 info.addPara("The " + forcesNoun + " are actively hostile, and will engage any orbital defenses, and "
353 + " conduct planetside operations to undermine your authority.",
354 opad, Misc.getNegativeHighlightColor(), "actively hostile");
355 }
356
357// addStrengthDesc(info, opad, getTargetSystem(), forcesNoun,
358// "the " + noun + " is unlikely to be effective",
359// "the " + noun + " is likely to only be partially effective",
360// "the " + noun + " is likely to be fully effective");
361
362 addStrengthDesc(info, opad, target, forcesNoun,
363 "the colony is unlikely to be in danger",
364 "the colony may be in danger",
365 "the colony is in danger");
366
367 addPostAssessmentSection(info, width, height, opad);
368 }
369 }
370
371 @Override
372 protected void addPostAssessmentSection(TooltipMakerAPI info, float width, float height, float opad) {
373 }
374
375
376 protected void addPayloadActionStatus(TooltipMakerAPI info, float width, float height, float opad) {
377 StarSystemAPI to = raidAction.getWhere();
378 info.addPara("Conducting operations in the " +
379 to.getNameWithLowercaseTypeShort() + ".", opad);
380
381 int penalty = getStabilityPenaltyPerMonth();
382 MarketAPI target = blockadeParams.specificMarket;
383 bullet(info);
384 if (penalty > 0) {
385 LabelAPI label = info.addPara(target.getName() + " stability: %s per month", opad,
386 Misc.getHighlightColor(), "-" + penalty);
387 label.setHighlightColors(target.getFaction().getBaseUIColor(), Misc.getHighlightColor());
388 label.setHighlight(target.getName(), "-" + penalty);
389 } else {
390 info.addPara("%s stability unaffected", opad,
391 target.getFaction().getBaseUIColor(), target.getName());
392
393 unindent(info);
394 }
395
396 }
397
398
401 if (str < 0) {
402 return 0;
403 } else if (str == 0) {
405 } else {
407 }
408 }
409
410 public void reportEconomyTick(int iterIndex) {
411 // do here so that it's not synched up with the month-end income report etc
412 if (iterIndex == 0) {
413 if (!isCurrent(PAYLOAD_ACTION)) return;
414
415 MarketAPI target = blockadeParams.specificMarket;
416
417 int penalty = getStabilityPenaltyPerMonth();
418 if (penalty > 0) {
419 RecentUnrest.get(target).add(penalty, "Luddic Church takeover operation");
420 target.reapplyConditions();
422 }
423
424 if (target.getStabilityValue() <= 0) {
425 performTakeover(false);
426 }
427 }
428 }
429
430
431 public void reportEconomyMonthEnd() {
432
433 }
434
435 protected boolean voluntary;
436 public void performTakeover(boolean voluntary) {
437 this.voluntary = voluntary;
438 MarketAPI target = blockadeParams.specificMarket;
439 target.setFactionId(Factions.LUDDIC_CHURCH);
440 target.setPlayerOwned(false);
441 target.setAdmin(null);
442 for (SectorEntityToken curr : target.getConnectedEntities()) {
443 curr.setFaction(Factions.LUDDIC_CHURCH);
444 }
445
446 if (!target.hasSubmarket(Submarkets.SUBMARKET_OPEN)) {
447 target.addSubmarket(Submarkets.SUBMARKET_OPEN);
448 }
449 if (!target.hasSubmarket(Submarkets.SUBMARKET_BLACK)) {
450 target.addSubmarket(Submarkets.SUBMARKET_BLACK);
451 }
452 if (Misc.isMilitary(target) ||
453 target.hasIndustry(Industries.MILITARYBASE) ||
454 target.hasIndustry(Industries.HIGHCOMMAND)) {
455 if (!target.hasSubmarket(Submarkets.GENERIC_MILITARY)) {
456 target.addSubmarket(Submarkets.GENERIC_MILITARY);
457 }
458 }
459
460 RecentUnrest.get(target).setPenalty(0);
461
462
463 if (getCurrentAction() instanceof FGBlockadePlanetAction) {
466 action.setActionFinished(true);
467 }
468
469
470 if (target.getStarSystem() != null) {
471 for (CampaignFleetAPI fleet : target.getStarSystem().getFleets()) {
472 MemoryAPI mem = fleet.getMemoryWithoutUpdate();
473 String type = mem.getString(MemFlags.HASSLE_TYPE);
474 if (LuddicChurchHostileActivityFactor.HASSLE_REASON.equals(type)) {
475 mem.unset(MemFlags.WILL_HASSLE_PLAYER);
476 mem.unset(MemFlags.HASSLE_TYPE);
478 fleet.removeScriptsOfClass(NPCHassler.class);
479 }
480 }
481 }
482 }
483
484 public String getCommMessageSound() {
485 if (isSendingUpdate() && isSucceeded() &&
487 return Sounds.REP_LOSS;
488 }
489 return super.getCommMessageSound();
490 }
491}
492
493
494
495
static SectorAPI getSector()
Definition Global.java:59
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
boolean addStrengthDesc(TooltipMakerAPI info, float opad, StarSystemAPI system, String forces, String outcomeFailure, String outcomeUncertain, String outcomeSuccess)
KnightsOfLuddTakeoverExpedition(GenericRaidParams params, FGBlockadeParams blockadeParams)
void addPostAssessmentSection(TooltipMakerAPI info, float width, float height, float opad)
void addPayloadActionStatus(TooltipMakerAPI info, float width, float height, float opad)
void addAssessmentSection(TooltipMakerAPI info, float width, float height, float opad)
void addUpdateBulletPoints(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad)
void addTargetingBulletPoint(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad)
void addBasicDescription(TooltipMakerAPI info, float width, float height, float opad)